Also use the fixed size audio buffer for decoding -- audio always works in packets of the same size, so we should always get the same amount out of decoding.
Showing the changes to plugins/opusCodec/src/OpusDecoder.cpp (1 of 3 files). Show all
Unified · Split
| @@ -1,5 +1,6 @@ | |||
| 1 | #include <PerfStat.h> | 1 | #include <PerfStat.h> |
| 2 | #include <QtCore/QLoggingCategory> | 2 | #include <QtCore/QLoggingCategory> |
| 3 | #include <AudioConstants.h> | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | ||
| @@ -45,7 +46,7 @@ AthenaOpusDecoder::AthenaOpusDecoder(int sampleRate, int numChannels) · 39 unmodified lines | |||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | 48 | ||
| 48 | qCDebug(decoder) << "Opus decoder initialized"; | 49 | qCDebug(decoder) << "Opus decoder initialized, sampleRate = " << sampleRate << "; numChannels = " << numChannels; |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | AthenaOpusDecoder::~AthenaOpusDecoder() | 52 | AthenaOpusDecoder::~AthenaOpusDecoder() |
| @@ -61,10 +62,14 @@ void AthenaOpusDecoder::decode(const QByteArray &encodedBuffer, QByteArray &deco · 9 unmodified lines | |||
| 61 | 62 | ||
| 62 | PerformanceTimer perfTimer("AthenaOpusDecoder::decode"); | 63 | PerformanceTimer perfTimer("AthenaOpusDecoder::decode"); |
| 63 | 64 | ||
| 64 | decodedBuffer.resize( 65536 ); // Brute force, yeah! | 65 | |
| 66 | int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast<int>(sizeof(int16_t)) * _opus_num_channels; | ||
| 67 | |||
| 68 | decodedBuffer.resize( buffer_size ); | ||
| 65 | int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); | 69 | int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); |
| 66 | 70 | ||
| 67 | int frames = opus_decode( _decoder, reinterpret_cast<const unsigned char*>(encodedBuffer.data()), encodedBuffer.length(), reinterpret_cast<opus_int16*>(decodedBuffer.data()), frame_size, 1 ); | 71 | qCDebug(decoder) << "Opus decode: encodedBytes = " << encodedBuffer.length() << "; decodedBufferBytes = " << decodedBuffer.size() << "; frameCount = " << frame_size; |
| 72 | int frames = opus_decode( _decoder, reinterpret_cast<const unsigned char*>(encodedBuffer.data()), encodedBuffer.length(), reinterpret_cast<opus_int16*>(decodedBuffer.data()), frame_size, 0 ); | ||
| 68 | 73 | ||
| 69 | if ( frames >= 0 ) { | 74 | if ( frames >= 0 ) { |
| 70 | qCDebug(decoder) << "Decoded " << frames << " Opus frames"; | 75 | qCDebug(decoder) << "Decoded " << frames << " Opus frames"; |
| @@ -81,7 +86,8 @@ void AthenaOpusDecoder::lostFrame(QByteArray &decodedBuffer) · 10 unmodified lines | |||
| 81 | 86 | ||
| 82 | PerformanceTimer perfTimer("AthenaOpusDecoder::lostFrame"); | 87 | PerformanceTimer perfTimer("AthenaOpusDecoder::lostFrame"); |
| 83 | 88 | ||
| 84 | decodedBuffer.resize( 65536 ); // Brute force, yeah! | 89 | int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast<int>(sizeof(int16_t)) * _opus_num_channels; |
| 90 | decodedBuffer.resize( buffer_size ); | ||
| 85 | int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); | 91 | int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); |
| 86 | 92 | ||
| 87 | int frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast<opus_int16*>(decodedBuffer.data()), frame_size, 1 ); | 93 | int frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast<opus_int16*>(decodedBuffer.data()), frame_size, 1 ); |