diff --git a/tests/test_android_stream.c b/tests/test_android_stream.c index 0f97853b..8530af90 100644 --- a/tests/test_android_stream.c +++ b/tests/test_android_stream.c @@ -39,6 +39,7 @@ static void chat_event(struct UTUN_INSTANCE *inst, int type, const uint8_t *data static uint8_t *wait_event(uint64_t id, int kind, size_t *size) { for (unsigned i = 0; i < 1000; i++) { + if (id == 2 && kind == 5) CHECK(android_stream_read_request(id, 1000000, 80000, 80000) == 0); uint8_t *data = android_stream_pull(id, size); if (data && data[0] == kind) return data; u_free(data); test_clock_poll(ua, 100); @@ -90,6 +91,7 @@ int main(void) { CHECK(feed(1, 0, 100000, 0, (const uint8_t *)"ops", 3) == 1); uint8_t *output = NULL; int video_seen = 0, audio_seen = 0; for (unsigned i = 0; i < 1000 && (!video_seen || !audio_seen); i++) { + CHECK(android_stream_read_request(2, 100000, 80000, 80000) == 0); output = android_stream_pull(2, &size); if (output && output[0] == 1) { CHECK(size == sizeof(video) + ANDROID_STREAM_HEADER_SIZE && stream_read_be(output + 8, 8) == 100000 && !memcmp(output + ANDROID_STREAM_HEADER_SIZE, video, sizeof(video))); @@ -110,6 +112,7 @@ int main(void) { next_format.width--; video_seen = audio_seen = 0; for (unsigned i = 0; i < 1000 && (!video_seen || !audio_seen); i++) { + CHECK(android_stream_read_request(2, 300000, 80000, 80000) == 0); output = android_stream_pull(2, &size); if (output && output[0] == 1) { CHECK(stream_read_be(output + 8, 8) == 300000 && stream_read_be(output + 20, 4) == 2); @@ -129,6 +132,7 @@ int main(void) { CHECK(feed(1, 0, audio_pts, 0, (const uint8_t *)"ops", 3) == 1); video_seen = audio_seen = 0; for (unsigned i = 0; i < 1000 && (!video_seen || !audio_seen); i++) { + CHECK(android_stream_read_request(2, (int64_t)video_pts, 80000, 80000) == 0); output = android_stream_pull(2, &size); if (output && output[0] == 1) { CHECK(stream_read_be(output + 8, 8) == video_pts && stream_read_be(output + 20, 4) == next_format.revision); diff --git a/tools/chatgui/tests/test_stream_view.cpp b/tools/chatgui/tests/test_stream_view.cpp index 366acc5d..90cdde19 100644 --- a/tools/chatgui/tests/test_stream_view.cpp +++ b/tools/chatgui/tests/test_stream_view.cpp @@ -78,10 +78,10 @@ class StreamViewTest : public QObject { uint32_t revision = 1; uint16_t rotation = 90; - bool receive(uint64_t id, StreamRecord& record) { + bool receive(uint64_t id, StreamRecord& record, int64_t position = -1) { QElapsedTimer elapsed; elapsed.start(); while (elapsed.elapsed() < 1000) { - if (gui_stream_pull(id, record)) return true; + if (gui_stream_pull(id, record, position)) return true; QTest::qWait(1); } DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "desktop test missing record id=%llu", (unsigned long long)id); return false; @@ -151,16 +151,26 @@ private slots: QCOMPARE(event.format.rotation, uint16_t(90)); QVERIFY(receive(102, event)); QCOMPARE(event.kind, StreamRecordKind::Audio); QCOMPARE(event.data, audio); for (int i = 0; i < 270; i++) { publish(frame); uasync_poll(ua, 0); } - bool gap = false; unsigned records = 0; - while (gui_stream_pull(102, event)) { gap |= event.kind == StreamRecordKind::Gap; records++; } - QVERIFY(gap); QVERIFY(records <= 256); - publish(frame); QVERIFY(receive(102, event)); QCOMPARE(event.kind, StreamRecordKind::Video); + unsigned records = 0; + QElapsedTimer held; held.start(); + while (held.elapsed() < 30) { + if (gui_stream_pull(102, event, 100000, 0, 0)) { QVERIFY(event.kind != StreamRecordKind::Gap); records++; } + QTest::qWait(1); + } + QVERIFY(records <= 2); /* Накопленные 27 секунд остаются в RS, а не в очереди frontend. */ + QVERIFY(receive(102, event, 200000)); QCOMPARE(event.kind, StreamRecordKind::Video); + QCOMPARE(event.pts, uint64_t(200000)); QCOMPARE(event.data, frame); gui_stream_stop(102); QTest::qWait(20); stream_info info{}; QCOMPARE(stream_get_info(publisher, &info), STREAM_OK); QCOMPARE(info.owners, 1u); } void realH264RenderingAndClose() { #ifdef HAVE_FFMPEG + /* Фикстура протокола выше содержит фиктивный H264; реальный decoder получает отдельную эпоху. */ + QCOMPARE(stream_publish_finish(publisher), STREAM_OK); stream_close(publisher); publisher = nullptr; + QCOMPARE(stream_publish_open(inst, group, nullptr, &publisher), STREAM_OK); + stream_info fresh{}; QCOMPARE(stream_get_info(publisher, &fresh), STREAM_OK); epoch = fresh.descriptor.source_epoch; + mediaPts = 0; frameId = 0; revision = 1; const AVCodec* encoder = avcodec_find_encoder(AV_CODEC_ID_H264); if (!encoder) QSKIP("H264 encoder is unavailable for the decoder fixture"); AVCodecContext* context = avcodec_alloc_context3(encoder); QVERIFY(context);