|
|
|
|
@ -35,6 +35,15 @@ class StreamViewTest : public QObject {
|
|
|
|
|
QTimer poll; |
|
|
|
|
size_t allocations = 0; |
|
|
|
|
|
|
|
|
|
bool receive(uint64_t id, StreamRecord& record) { |
|
|
|
|
QElapsedTimer elapsed; elapsed.start(); |
|
|
|
|
while (elapsed.elapsed() < 1000) { |
|
|
|
|
if (gui_stream_pull(id, record)) return true; |
|
|
|
|
QTest::qWait(1); |
|
|
|
|
} |
|
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "desktop test missing record id=%llu", (unsigned long long)id); return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void publish(const QByteArray& video, const QByteArray& audio = {}) { |
|
|
|
|
stream_media_block media{}; media.format = {160, 90, 90, STREAM_MEDIA_H264, static_cast<uint8_t>(audio.isEmpty() ? 0 : STREAM_MEDIA_OPUS)}; |
|
|
|
|
media.first_frame_offset = 0; media.video_count = 1; |
|
|
|
|
@ -53,6 +62,7 @@ class StreamViewTest : public QObject {
|
|
|
|
|
private slots: |
|
|
|
|
void initTestCase() { |
|
|
|
|
debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); debug_set_category_level(DEBUG_CATEGORY_STREAM, DEBUG_LEVEL_INFO); |
|
|
|
|
debug_set_category_level(DEBUG_CATEGORY_SYS, DEBUG_LEVEL_ERROR); |
|
|
|
|
allocations = u_get_allocated_count(); ua = uasync_create(); QVERIFY(ua); |
|
|
|
|
inst = utun_instance_create_from_str(ua, |
|
|
|
|
"[global]\nauto_sockets=no\n[chatserver]\ngroup_autoconnect=0\nstorage_autoload=0\nmember_files_enabled=0\n"); |
|
|
|
|
@ -81,7 +91,7 @@ private slots:
|
|
|
|
|
void staleSelectionAndCancellation() { |
|
|
|
|
QVERIFY(gui_stream_open(100, group, inst->node_id, epoch ^ 1)); |
|
|
|
|
StreamRecord event; |
|
|
|
|
QTRY_VERIFY(gui_stream_pull(100, event)); QCOMPARE(event.kind, StreamRecordKind::Closed); |
|
|
|
|
QVERIFY(receive(100, event)); QCOMPARE(event.kind, StreamRecordKind::Closed); |
|
|
|
|
QCOMPARE(event.reason, STREAM_CLOSE_SOURCE_CHANGED); |
|
|
|
|
QVERIFY(gui_stream_open(101, group, inst->node_id, epoch)); gui_stream_stop(101); QTest::qWait(20); |
|
|
|
|
stream_info info{}; QCOMPARE(stream_get_info(publisher, &info), STREAM_OK); QCOMPARE(info.owners, 1u); |
|
|
|
|
@ -89,16 +99,16 @@ private slots:
|
|
|
|
|
|
|
|
|
|
void mediaAndPressure() { |
|
|
|
|
QVERIFY(gui_stream_open(102, group, inst->node_id, epoch)); StreamRecord event; |
|
|
|
|
QTRY_VERIFY(gui_stream_pull(102, event)); QCOMPARE(event.kind, StreamRecordKind::Opened); |
|
|
|
|
QVERIFY(receive(102, event)); QCOMPARE(event.kind, StreamRecordKind::Opened); |
|
|
|
|
const QByteArray frame(1500, 'k'); const QByteArray audio("opus"); publish(frame, audio); |
|
|
|
|
QTRY_VERIFY(gui_stream_pull(102, event)); QCOMPARE(event.kind, StreamRecordKind::Video); QCOMPARE(event.data, frame); |
|
|
|
|
QVERIFY(receive(102, event)); QCOMPARE(event.kind, StreamRecordKind::Video); QCOMPARE(event.data, frame); |
|
|
|
|
QCOMPARE(event.format.rotation, uint16_t(90)); |
|
|
|
|
QTRY_VERIFY(gui_stream_pull(102, event)); QCOMPARE(event.kind, StreamRecordKind::Audio); QCOMPARE(event.data, audio); |
|
|
|
|
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); QTRY_VERIFY(gui_stream_pull(102, event)); QCOMPARE(event.kind, StreamRecordKind::Video); |
|
|
|
|
publish(frame); QVERIFY(receive(102, event)); QCOMPARE(event.kind, StreamRecordKind::Video); |
|
|
|
|
gui_stream_stop(102); QTest::qWait(20); |
|
|
|
|
stream_info info{}; QCOMPARE(stream_get_info(publisher, &info), STREAM_OK); QCOMPARE(info.owners, 1u); |
|
|
|
|
} |
|
|
|
|
@ -137,7 +147,7 @@ private slots:
|
|
|
|
|
QCOMPARE(stream_publish_open(inst, group, nullptr, &publisher), STREAM_OK); |
|
|
|
|
stream_info info{}; QCOMPARE(stream_get_info(publisher, &info), STREAM_OK); QVERIFY(info.descriptor.source_epoch != epoch); |
|
|
|
|
QVERIFY(gui_stream_open(103, group, inst->node_id, epoch)); StreamRecord event; |
|
|
|
|
QTRY_VERIFY(gui_stream_pull(103, event)); QCOMPARE(event.reason, STREAM_CLOSE_SOURCE_CHANGED); |
|
|
|
|
QVERIFY(receive(103, event)); QCOMPARE(event.reason, STREAM_CLOSE_SOURCE_CHANGED); |
|
|
|
|
QVERIFY(gui_stream_open(104, group, inst->node_id, info.descriptor.source_epoch)); |
|
|
|
|
gui_stream_detach(inst); QVERIFY(!gui_stream_ready()); QTest::qWait(20); |
|
|
|
|
QCOMPARE(stream_get_info(publisher, &info), STREAM_OK); QCOMPARE(info.owners, 1u); |
|
|
|
|
|