More debug output.
Showing the changes to plugins/opusCodec/src/OpusDecoder.cpp (1 of 1 file). Show all
Unified · Split
| @@ -59,23 +59,32 @@ AthenaOpusDecoder::~AthenaOpusDecoder() · 58 unmodified lines | ||
| 59 | 59 | void AthenaOpusDecoder::decode(const QByteArray &encodedBuffer, QByteArray &decodedBuffer) |
| 60 | 60 | { |
| 61 | 61 | assert(_decoder); |
| 62 | − | |
| 63 | 62 | PerformanceTimer perfTimer("AthenaOpusDecoder::decode"); |
| 64 | 63 | |
| 65 | − | |
| 64 | + // The audio system encodes and decodes always in fixed size chunks | |
| 66 | 65 | int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast<int>(sizeof(int16_t)) * _opus_num_channels; |
| 67 | 66 | |
| 68 | 67 | decodedBuffer.resize( buffer_size ); |
| 69 | − int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); | |
| 68 | + int buffer_frames = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); | |
| 69 | + | |
| 70 | + qCDebug(decoder) << "Opus decode: encodedBytes = " << encodedBuffer.length() << "; decodedBufferBytes = " << decodedBuffer.size() << "; frameCount = " << buffer_frames; | |
| 71 | + int decoded_frames = opus_decode( _decoder, reinterpret_cast<const unsigned char*>(encodedBuffer.data()), encodedBuffer.length(), reinterpret_cast<opus_int16*>(decodedBuffer.data()), buffer_frames, 0 ); | |
| 72 | + | |
| 73 | + if ( decoded_frames >= 0 ) { | |
| 74 | + qCDebug(decoder) << "Decoded " << decoded_frames << " Opus frames, " << buffer_frames << " expected"; | |
| 70 | 75 | |
| 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 ); | |
| 76 | + if ( decoded_frames < buffer_frames ) { | |
| 77 | + qCWarning(decoder) << "Opus decoder returned " << decoded_frames << ", but " << buffer_frames << " were expected!"; | |
| 73 | 78 | |
| 74 | − if ( frames >= 0 ) { | |
| 75 | − qCDebug(decoder) << "Decoded " << frames << " Opus frames"; | |
| 76 | − decodedBuffer.resize( frames * static_cast<int>(sizeof( opus_int16 )) * _opus_num_channels ); | |
| 79 | + int start = decoded_frames * static_cast<int>(sizeof(int16_t)) * _opus_num_channels; | |
| 80 | + memset( &decodedBuffer.data()[start], 0, static_cast<size_t>(decodedBuffer.length() - start)); | |
| 81 | + } else if ( decoded_frames > buffer_frames ) { | |
| 82 | + // This should never happen | |
| 83 | + qCCritical(decoder) << "Opus decoder returned " << decoded_frames << ", but only " << buffer_frames << " were expected! Buffer overflow!?"; | |
| 84 | + } | |
| 77 | 85 | } else { |
| 78 | − qCCritical(decoder) << "Failed to decode audio: " << error_to_string(frames); | |
| 86 | + qCCritical(decoder) << "Failed to decode audio: " << error_to_string(decoded_frames); | |
| 87 | + decodedBuffer.fill('\0'); | |
| 79 | 88 | } |
| 80 | 89 | |
| 81 | 90 | } |
| @@ -88,15 +97,26 @@ void AthenaOpusDecoder::lostFrame(QByteArray &decodedBuffer) · 6 unmodified lines | ||
| 88 | 97 | |
| 89 | 98 | int buffer_size = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * static_cast<int>(sizeof(int16_t)) * _opus_num_channels; |
| 90 | 99 | decodedBuffer.resize( buffer_size ); |
| 91 | − int frame_size = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); | |
| 100 | + int buffer_frames = decodedBuffer.size() / _opus_num_channels / static_cast<int>(sizeof( opus_int16 )); | |
| 101 | + | |
| 102 | + int decoded_frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast<opus_int16*>(decodedBuffer.data()), buffer_frames, 1 ); | |
| 103 | + | |
| 104 | + if ( decoded_frames >= 0 ) { | |
| 105 | + | |
| 106 | + qCDebug(decoder) << "Produced " << decoded_frames << " opus frames from a lost frame, " << buffer_frames << " expected"; | |
| 92 | 107 | |
| 93 | − int frames = opus_decode( _decoder, nullptr, 0, reinterpret_cast<opus_int16*>(decodedBuffer.data()), frame_size, 1 ); | |
| 108 | + if ( decoded_frames < buffer_frames ) { | |
| 109 | + qCWarning(decoder) << "Opus decoder returned " << decoded_frames << ", but " << buffer_frames << " were expected!"; | |
| 94 | 110 | |
| 95 | − if ( frames >= 0 ) { | |
| 96 | − qCDebug(decoder) << "Produced " << frames << " opus frames from a lost frame"; | |
| 97 | − decodedBuffer.resize( frames * static_cast<int>(sizeof( opus_int16 )) * _opus_num_channels ); | |
| 111 | + int start = decoded_frames * static_cast<int>(sizeof(int16_t)) * _opus_num_channels; | |
| 112 | + memset( &decodedBuffer.data()[start], 0, static_cast<size_t>(decodedBuffer.length() - start)); | |
| 113 | + } else if ( decoded_frames > buffer_frames ) { | |
| 114 | + // This should never happen | |
| 115 | + qCCritical(decoder) << "Opus decoder returned " << decoded_frames << ", but only " << buffer_frames << " were expected! Buffer overflow!?"; | |
| 116 | + } | |
| 98 | 117 | } else { |
| 99 | − qCCritical(decoder) << "Failed to decode lost frame: " << error_to_string(frames); | |
| 118 | + qCCritical(decoder) << "Failed to decode lost frame: " << error_to_string(decoded_frames); | |
| 119 | + decodedBuffer.fill('\0'); | |
| 100 | 120 | } |
| 101 | 121 | } |
| 102 | 122 | |