diff --git a/tools/chatgui/src/streamplayer_window.cpp b/tools/chatgui/src/streamplayer_window.cpp index 1c5bf393..769ab689 100644 --- a/tools/chatgui/src/streamplayer_window.cpp +++ b/tools/chatgui/src/streamplayer_window.cpp @@ -186,7 +186,7 @@ void StreamPlayerWindow::decode() { uint32_t videoRevision = 0; auto reset = [&] { avcodec_free_context(&decoder); - opus_codec_decoder_destroy(opus); opus = nullptr; expectedAudio = -1; waitKey = true; + opus_codec_decoder_destroy(opus); opus = nullptr; expectedAudio = -1; waitKey = true; prerollSamples = 0; std::lock_guard guard(p.lock); p.videos.clear(); p.videoBytes = 0; p.audios.clear(); p.prefillUntil = 0; p.videoBase = p.audioPts = -1; emit statusChanged(text("Waiting for a key frame…")); @@ -213,7 +213,11 @@ void StreamPlayerWindow::decode() { : record.reason == STREAM_CLOSE_GROUP ? "The channel is closed" : "Could not continue the stream"; fail(text(reason)); break; } - if (record.kind == StreamRecordKind::End) { std::lock_guard guard(p.lock); p.ended = true; break; } + if (record.kind == StreamRecordKind::End) { + std::lock_guard guard(p.lock); p.ended = true; + if (p.videoBase < 0) p.audios.clear(); + break; + } if (record.pts > INT64_MAX) { fail(text("Invalid stream timestamp")); break; } if (record.kind == StreamRecordKind::Audio) { if (!p.audioAvailable) continue; diff --git a/tools/chatgui/tests/test_stream_view.cpp b/tools/chatgui/tests/test_stream_view.cpp index 81142ec7..366acc5d 100644 --- a/tools/chatgui/tests/test_stream_view.cpp +++ b/tools/chatgui/tests/test_stream_view.cpp @@ -196,7 +196,11 @@ private slots: pcm[2 * i + 1] = static_cast(1500 * std::sin((sampleFrame + i) * 0.13)); } sampleFrame += 960; - int length = opus_codec_encode(opus.get(), pcm, 960, encoded, sizeof(encoded)); QVERIFY(length > 0); + int length = opus_codec_encode(opus.get(), pcm, 960, encoded, sizeof(encoded)); + if (length <= 0) { + DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "desktop startup fixture Opus encode failed result=%d", length); + return QList{}; + } packets.append(QByteArray(reinterpret_cast(encoded), length)); } return packets;