diff --git a/tools/chatgui/src/streamplayer_window.cpp b/tools/chatgui/src/streamplayer_window.cpp index 407a34f9..e1e9d558 100644 --- a/tools/chatgui/src/streamplayer_window.cpp +++ b/tools/chatgui/src/streamplayer_window.cpp @@ -519,14 +519,15 @@ void StreamPlayerWindow::decode() { } if (record.kind == StreamRecordKind::VideoEnd || record.kind == StreamRecordKind::AudioEnd || record.kind == StreamRecordKind::End) { std::lock_guard guard(p.lock); - if (record.kind != StreamRecordKind::AudioEnd) { finishing = true; p.videoEnded = !decoder; } + if (record.kind != StreamRecordKind::AudioEnd && !finishing) { finishing = true; p.videoEnded = !decoder; } if (record.kind != StreamRecordKind::VideoEnd && !p.audioEnded) { p.audioEnded = true; if (p.sound) stream_playback_audio_finish(p.sound); } if (record.kind == StreamRecordKind::End) p.ended = true; - DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop track end id=%llu kind=%d video_input_end=%d audio_input_end=%d pending=%zu", - (unsigned long long)p.id, (int)record.kind, finishing, p.audioEnded, records.size()); + DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop track end id=%llu track=%s video_input_end=%d audio_input_end=%d pending=%zu", + (unsigned long long)p.id, record.kind == StreamRecordKind::VideoEnd ? "video" + : record.kind == StreamRecordKind::AudioEnd ? "audio" : "all", finishing, p.audioEnded, records.size()); continue; } observe(); diff --git a/tools/chatgui/tests/test_stream_view.cpp b/tools/chatgui/tests/test_stream_view.cpp index b27e4af7..ac8e8069 100644 --- a/tools/chatgui/tests/test_stream_view.cpp +++ b/tools/chatgui/tests/test_stream_view.cpp @@ -800,21 +800,24 @@ private slots: int16_t pcm[1920] = {}; uint8_t encoded[1275]; int audioSize = opus_codec_encode(opus.get(), pcm, 960, encoded, sizeof(encoded)); QVERIFY(audioSize > 0); struct Delay { Delay() { delayedDecoder = true; } ~Delay() { delayedDecoder = false; } } delay; - for (bool audio : {false, true}) for (unsigned count : {3u, 8u}) { - DEBUG_INFO(DEBUG_CATEGORY_STREAM, "fixture delayed decoder frames=%u audio=%d", count, audio); + struct Scenario { unsigned video, audio; }; + for (auto scenario : {Scenario{3, 0}, Scenario{8, 0}, Scenario{3, 6}, Scenario{8, 16}, Scenario{8, 4}, Scenario{3, 16}}) { + unsigned count = scenario.video; + bool audio = scenario.audio != 0; + DEBUG_INFO(DEBUG_CATEGORY_STREAM, "fixture delayed decoder frames=%u audio_packets=%u", count, scenario.audio); QCOMPARE(stream_publish_finish(publisher), STREAM_OK); stream_close(publisher); publisher = nullptr; QCOMPARE(stream_publish_open(inst, group, nullptr, &publisher), STREAM_OK); stream_info info{}; QCOMPARE(stream_get_info(publisher, &info), STREAM_OK); epoch = info.descriptor.source_epoch; StreamPlayerWindow window(group, inst->node_id, epoch, "Delayed decoder"); window.show(); QSignalSpy shown(&window, &StreamPlayerWindow::framePresented); - for (unsigned i = 0; i < count; i++) { + for (unsigned i = 0; i < std::max(count, scenario.audio / 2); i++) { QByteArray data = i ? access : QByteArray(4, '\0') + access; stream_media_block media{}; media.format = {160, 90, 0, STREAM_MEDIA_H264, (uint8_t)(audio ? STREAM_MEDIA_OPUS_STEREO : 0), 1}; - media.video_count = 1; + media.video_count = i < count ? 1 : 0; media.video[0] = {i + 1, i * 40000u, (uint32_t)data.size(), 0, (uint32_t)data.size(), (uint8_t)(i ? 0 : STREAM_MEDIA_KEY), reinterpret_cast(data.constData())}; - if (audio) { + if (i * 2 < scenario.audio) { media.audio_count = 2; for (unsigned j = 0; j < 2; j++) media.audio[j] = {i * 40000u + j * 20000u, (uint32_t)audioSize, 960, encoded}; } @@ -827,6 +830,7 @@ private slots: else QTRY_VERIFY_WITH_TIMEOUT(shown.count() > 0, 1500); QCOMPARE(stream_publish_finish(publisher), STREAM_OK); QTRY_COMPARE_WITH_TIMEOUT(shown.count(), (int)count, 2000); + QTRY_VERIFY_WITH_TIMEOUT(window.finished(), 2000); QTRY_VERIFY_WITH_TIMEOUT(stream_get_info(publisher, &info) == STREAM_OK && info.owners == 1, 2000); window.close(); QTest::qWait(10); }