From a68a7b611952b14fc2c22d6cbf4bdc952d58ac4c Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Thu, 5 Sep 2019 19:45:06 +0200 Subject: [PATCH] Added a few new methods --- .../src/connection/audio/AudioSender.cpp | 2 - .../src/connection/audio/VoiceConnection.cpp | 45 ++++++++++++++++++- .../src/connection/audio/VoiceConnection.h | 6 +++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/native/serverconnection/src/connection/audio/AudioSender.cpp b/native/serverconnection/src/connection/audio/AudioSender.cpp index 15c5da1..161da1c 100644 --- a/native/serverconnection/src/connection/audio/AudioSender.cpp +++ b/native/serverconnection/src/connection/audio/AudioSender.cpp @@ -196,8 +196,6 @@ void VoiceSender::encode_raw_frame(const std::unique_ptr &frame) { return; } - log_trace(category::voice_connection, tr("Encode buffer size: {}"), this->_buffer_size); - char _packet_buffer[512]; auto encoded_bytes = codec_data->converter->encode(error, this->_buffer, _packet_buffer, 512); if(encoded_bytes <= 0) { diff --git a/native/serverconnection/src/connection/audio/VoiceConnection.cpp b/native/serverconnection/src/connection/audio/VoiceConnection.cpp index eb250d8..c57d92d 100644 --- a/native/serverconnection/src/connection/audio/VoiceConnection.cpp +++ b/native/serverconnection/src/connection/audio/VoiceConnection.cpp @@ -153,8 +153,9 @@ NAN_METHOD(VoiceConnectionWrap::_audio_source) { } NAN_METHOD(VoiceConnectionWrap::_set_audio_source) { - return ObjectWrap::Unwrap(info.Holder())->set_audio_source(info); + ObjectWrap::Unwrap(info.Holder())->set_audio_source(info); } + NAN_METHOD(VoiceConnectionWrap::set_audio_source) { if(info.Length() != 1) { Nan::ThrowError("invalid argument count"); @@ -205,6 +206,35 @@ NAN_METHOD(VoiceConnectionWrap::set_audio_source) { } } +NAN_METHOD(VoiceConnectionWrap::_get_encoder_codec) { + auto _this = ObjectWrap::Unwrap(info.Holder()); + auto handle = _this->handle.lock(); + if(!handle) { + Nan::ThrowError("handle has been deallocated"); + return; + } + + info.GetReturnValue().Set(handle->get_encoder_codec()); +} + +NAN_METHOD(VoiceConnectionWrap::_set_encoder_codec) { + auto _this = ObjectWrap::Unwrap(info.Holder()); + auto handle = _this->handle.lock(); + if(!handle) { + Nan::ThrowError("handle has been deallocated"); + return; + } + + + if(info.Length() != 1 || !info[0]->IsNumber()) { + Nan::ThrowError("Invalid arguments"); + return; + } + + handle->set_encoder_codec(info[0]->NumberValue(Nan::GetCurrentContext()).FromMaybe(0)); +} + + void VoiceConnectionWrap::release_recorder() { if(!this->_voice_recoder_handle.IsEmpty()) { assert(v8::Isolate::GetCurrent()); @@ -313,4 +343,17 @@ void VoiceConnection::process_packet(const std::shared_ptr codec::MAX) return; + + auto vs = this->_voice_sender; + if(vs) + vs->set_codec((codec::value) codec); +} + +uint8_t VoiceConnection::get_encoder_codec() { + auto vs = this->_voice_sender; + return vs ? vs->get_codec() : 0; } \ No newline at end of file diff --git a/native/serverconnection/src/connection/audio/VoiceConnection.h b/native/serverconnection/src/connection/audio/VoiceConnection.h index 34241ea..9f0054e 100644 --- a/native/serverconnection/src/connection/audio/VoiceConnection.h +++ b/native/serverconnection/src/connection/audio/VoiceConnection.h @@ -48,6 +48,9 @@ namespace tc { static NAN_METHOD(_set_audio_source); NAN_METHOD(set_audio_source); + static NAN_METHOD(_get_encoder_codec); + static NAN_METHOD(_set_encoder_codec); + void release_recorder(); std::function _read_callback; @@ -87,6 +90,9 @@ namespace tc { void delete_client(const std::shared_ptr&); void process_packet(const std::shared_ptr&); + + void set_encoder_codec(const uint8_t& /* codec */); + uint8_t get_encoder_codec(); private: ServerConnection* _handle; std::weak_ptr _ref;