Exercise audio continuity during video stalls and generation changes

This commit is contained in:
evgeny committed 2026-10-21 01:03:19 +02:00
1 parent 1764603977
commit c6ed01110e
2 files changed
+27 -5

No files matched your search

+15
View File
@@ -24,6 +24,7 @@
#include <cmath>
#include <chrono>
#include <deque>
#include <thread>
extern "C" {
#include "utun_instance.h"
@@ -82,6 +83,7 @@ static QImage nativeCrop(const QImage& frame, const VideoRenderWidget& view, QPo
}
#if defined(TEST_NULL_AUDIO) && defined(HAVE_FFMPEG)
static std::atomic<bool> delayedDecoder{false};
static std::atomic<unsigned> videoPauseMs{0}, videoPauses{0};
static AVCodecContext* delayedContext = nullptr;
static std::deque<AVFrame*> delayedFrames;
static bool delayedDraining = false;
@@ -96,6 +98,11 @@ extern "C" int __wrap_avcodec_open2(AVCodecContext* context, const AVCodec* code
}
extern "C" int __real_avcodec_receive_frame(AVCodecContext*, AVFrame*);
extern "C" int __wrap_avcodec_receive_frame(AVCodecContext* context, AVFrame* frame) {
if (unsigned pause = videoPauseMs.exchange(0)) {
++videoPauses;
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "fixture video decoder stall=%ums; audio worker must continue", pause);
std::this_thread::sleep_for(std::chrono::milliseconds(pause));
}
if (context != delayedContext) return __real_avcodec_receive_frame(context, frame);
int result = __real_avcodec_receive_frame(context, frame);
if (!result) {
@@ -687,6 +694,14 @@ private slots:
QVERIFY2(shown.count() >= beforeSteady + 30, "30fps video must keep advancing with 200ms physical audio latency");
#ifdef TEST_NULL_AUDIO
QCOMPARE(silenceGaps.load(), gapsBefore);
uint64_t beforePause = nonzeroSamples.load(); unsigned pausesBefore = videoPauses.load();
videoPauseMs = 500;
QTest::qWait(650);
QCOMPARE(videoPauses.load(), pausesBefore + 1);
QCOMPARE(silenceGaps.load(), gapsBefore);
QVERIFY(nonzeroSamples.load() > beforePause + 40000);
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "[PASS] video stalled 500ms: audio continued samples=%llu new_gaps=0",
(unsigned long long)(nonzeroSamples.load() - beforePause));
#endif
{
StreamPlayerWindow second(group, inst->node_id, epoch, "Second reader"); second.show();