diff --git a/plugins/opusCodec/CMakeLists.txt b/plugins/opusCodec/CMakeLists.txt index 761e275929..176c311fe8 100644 --- a/plugins/opusCodec/CMakeLists.txt +++ b/plugins/opusCodec/CMakeLists.txt @@ -8,7 +8,7 @@ set(TARGET_NAME opusCodec) setup_hifi_client_server_plugin() -link_hifi_libraries(shared plugins) +link_hifi_libraries(shared audio plugins) if (BUILD_SERVER) install_beside_console() diff --git a/plugins/opusCodec/src/OpusDecoder.cpp b/plugins/opusCodec/src/OpusDecoder.cpp index d47274e523..080742a127 100644 --- a/plugins/opusCodec/src/OpusDecoder.cpp +++ b/plugins/opusCodec/src/OpusDecoder.cpp @@ -1,5 +1,6 @@ #include #include +#include @@ -45,7 +46,7 @@ AthenaOpusDecoder::AthenaOpusDecoder(int sampleRate, int numChannels) } - qCDebug(decoder) << "Opus decoder initialized"; + qCDebug(decoder) << "Opus decoder initialized, sampleRate = " << sampleRate << "; numChannels = " << numChannels; } AthenaOpusDecoder::~AthenaOpusDecoder() @@ -61,10 +62,14 @@ void AthenaOpusDecoder::decode(const QByteArray &encodedBuffer, QByteArray &deco PerformanceTimer perfTimer("AthenaOpusDecoder::decode"); - decodedBuffer.resize( 65536 ); // Brute force, yeah! + + int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast(sizeof(int16_t)) * _opus_num_channels; + + decodedBuffer.resize( buffer_size ); int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast(sizeof( opus_int16 )); - int frames = opus_decode( _decoder, reinterpret_cast(encodedBuffer.data()), encodedBuffer.length(), reinterpret_cast(decodedBuffer.data()), frame_size, 1 ); + qCDebug(decoder) << "Opus decode: encodedBytes = " << encodedBuffer.length() << "; decodedBufferBytes = " << decodedBuffer.size() << "; frameCount = " << frame_size; + int frames = opus_decode( _decoder, reinterpret_cast(encodedBuffer.data()), encodedBuffer.length(), reinterpret_cast(decodedBuffer.data()), frame_size, 0 ); if ( frames >= 0 ) { qCDebug(decoder) << "Decoded " << frames << " Opus frames"; @@ -81,7 +86,8 @@ void AthenaOpusDecoder::lostFrame(QByteArray &decodedBuffer) PerformanceTimer perfTimer("AthenaOpusDecoder::lostFrame"); - decodedBuffer.resize( 65536 ); // Brute force, yeah! + int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast(sizeof(int16_t)) * _opus_num_channels; + decodedBuffer.resize( buffer_size ); int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast(sizeof( opus_int16 )); int frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast(decodedBuffer.data()), frame_size, 1 ); diff --git a/plugins/opusCodec/src/OpusDecoder.h b/plugins/opusCodec/src/OpusDecoder.h index d6b869695e..0aaadedc7a 100644 --- a/plugins/opusCodec/src/OpusDecoder.h +++ b/plugins/opusCodec/src/OpusDecoder.h @@ -22,6 +22,7 @@ private: OpusDecoder *_decoder = nullptr; int _opus_sample_rate = 0; int _opus_num_channels = 0; + int _decoded_size = 0; };