From 81c83357f2e421adf474c778906975b12ca147ce Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Wed, 10 Nov 2021 17:44:33 +0000 Subject: [PATCH 1/2] Catch exception in opus_decode --- audiohandler.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index 77bde33..82bbd79 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -575,7 +575,6 @@ qint64 audioHandler::writeData(const char* data, qint64 nBytes) #endif } - void audioHandler::incomingAudio(audioPacket inPacket) { // No point buffering audio until stream is actually running. @@ -594,8 +593,17 @@ void audioHandler::incomingAudio(audioPacket inPacket) /* Decode the frame. */ QByteArray outPacket((setup.samplerate / 50) * sizeof(qint16) * setup.radioChan, (char)0xff); // Preset the output buffer size. qint16* out = (qint16*)outPacket.data(); + + std::exception_ptr eptr; + int nSamples = 0; - int nSamples = opus_decode(decoder, in, inPacket.data.size(), out, (setup.samplerate / 50), 0); + try { + nSamples = opus_decode(decoder, in, inPacket.data.size(), out, (setup.samplerate / 50), 0); + } + catch (...) { + qInfo(logAudio()) << "Exception occurred in opus_decode: nSamples=" << nSamples << + "in=" < Date: Wed, 10 Nov 2021 18:07:48 +0000 Subject: [PATCH 2/2] Check number of samples in opus packet before attempting decode --- audiohandler.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/audiohandler.cpp b/audiohandler.cpp index 82bbd79..dc35900 100644 --- a/audiohandler.cpp +++ b/audiohandler.cpp @@ -593,17 +593,13 @@ void audioHandler::incomingAudio(audioPacket inPacket) /* Decode the frame. */ QByteArray outPacket((setup.samplerate / 50) * sizeof(qint16) * setup.radioChan, (char)0xff); // Preset the output buffer size. qint16* out = (qint16*)outPacket.data(); - - std::exception_ptr eptr; - int nSamples = 0; - - try { - nSamples = opus_decode(decoder, in, inPacket.data.size(), out, (setup.samplerate / 50), 0); - } - catch (...) { - qInfo(logAudio()) << "Exception occurred in opus_decode: nSamples=" << nSamples << - "in=" <