From 66d7189be9cdecc3189ac18e4628b549efeacced Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 19 Oct 2026 21:16:55 +0200 Subject: [PATCH] Check video queue publication and nonblocking audio clock parity --- tools/chatgui/tests/test_call_jitter.cpp | 5 +++ tools/chatgui/tests/test_call_video_clock.cpp | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/chatgui/tests/test_call_jitter.cpp b/tools/chatgui/tests/test_call_jitter.cpp index f28599417..8b9d98b6f 100644 --- a/tools/chatgui/tests/test_call_jitter.cpp +++ b/tools/chatgui/tests/test_call_jitter.cpp @@ -83,6 +83,10 @@ static void test_audio_clock() { int64_t now = tick * 10000ll; call_audio_playback_progress(id, epoch, written, now, now, 1); CHECK(call_audio_get_clock(id, now, &clock) == 0 && clock.written_samples == written); + call_clock_snapshot nonblocking{}; + CHECK(call_audio_try_clock(id, now, &nonblocking) == 1); + CHECK(nonblocking.valid == clock.valid && nonblocking.pts_us == clock.pts_us && nonblocking.epoch == clock.epoch); + CHECK(nonblocking.rate_ppm == clock.rate_ppm && nonblocking.written_samples == clock.written_samples); if (clock.valid) { valid++; CHECK(clock.source_epoch == 9 && clock.pts_us >= previous); @@ -106,6 +110,7 @@ static void test_audio_clock() { call_audio_playback_progress(id, epoch, written, 43000000, 43000000, 1); CHECK(call_audio_get_clock(id, 43000000, &clock) == 0 && !clock.valid); call_audio_stop(); opus_codec_encoder_destroy(encoder); + CHECK(call_audio_try_clock(id, 43000000, &clock) == -1 && !clock.valid); std::printf("audio clock: real Opus, burst/tempo, device progress, local tones and reset checked\n"); } int main() { diff --git a/tools/chatgui/tests/test_call_video_clock.cpp b/tools/chatgui/tests/test_call_video_clock.cpp index 88f856aba..8d8d99d22 100644 --- a/tools/chatgui/tests/test_call_video_clock.cpp +++ b/tools/chatgui/tests/test_call_video_clock.cpp @@ -1,6 +1,7 @@ /* Реальный RX worker и decoder: коррекции аудиочасов не разрывают цепочку P-кадров. */ #include "../src/call_video_engine.h" #include "../src/call_video_encoder.h" +#include "../src/call_video_queue.h" #include "../../../src/call/call_video_port.h" #include "../../../src/call/call_audio.h" #include @@ -74,9 +75,39 @@ extern "C" int __wrap_call_video_port_pull(uint64_t id, call_video_frame* out) { out->size = out->length = f.data.size(); auto* data = static_cast(u_malloc(out->size)); memcpy(data, f.data.constData(), out->size); out->data = data; return 1; } +static bool queuePressure() { + struct Payload { uint64_t serial = 0; std::array pixels{}; }; + CallVideoQueue queue; + constexpr uint64_t count = 100000; + std::atomic stop{false}; + std::thread producer([&] { + for (uint64_t i = 1; i <= count && !stop.load(); ) { + if (auto* slot = queue.writeSlot()) { + slot->serial = i; + for (unsigned j = 0; j < slot->pixels.size(); ++j) slot->pixels[j] = i ^ (j + 1); + queue.publish(); ++i; + } else std::this_thread::yield(); + } + }); + bool valid = true; uint64_t received = 0; + const int64_t deadline = nowUs() + 5000000; + while (received < count && nowUs() < deadline) { + if (const auto* slot = queue.readSlot()) { + if (received % 1000 == 0) QThread::usleep(100); // Producer упирается в занятые, ещё не подтверждённые слоты. + if (slot->serial != received + 1) valid = false; + for (unsigned j = 0; j < slot->pixels.size(); ++j) if (slot->pixels[j] != (slot->serial ^ (j + 1))) valid = false; + queue.release(); ++received; + } else std::this_thread::yield(); + } + stop = true; producer.join(); + if (!valid || received != count) DEBUG_ERROR(DEBUG_CATEGORY_CALL, "video queue stress failed received=%llu valid=%d", + (unsigned long long)received, valid); + return valid && received == count; +} int main(int argc, char** argv) { QCoreApplication app(argc, argv); debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); debug_set_category_level(DEBUG_CATEGORY_CALL, DEBUG_LEVEL_DEBUG); + if (!queuePressure()) return 1; CallVideoEncoder encoder; if (!encoder.open(format, 1000000, "libx264")) return 2; QImage image(640, 360, QImage::Format_RGB32); image.fill(Qt::blue); for (int i = 0; i < 90; ++i) {