|
25 | 25 | #include <livekit/e2ee.h> |
26 | 26 | #include <livekit/remote_data_track.h> |
27 | 27 |
|
28 | | -#include <cmath> |
29 | 28 | #include <condition_variable> |
30 | 29 | #include <exception> |
31 | 30 | #include <future> |
32 | | -#include <tuple> |
33 | 31 |
|
34 | 32 | #include "../common/test_common.h" |
35 | 33 | #include "ffi_client.h" |
36 | | -#include "lk_log.h" |
37 | 34 |
|
38 | 35 | namespace livekit::test { |
39 | 36 |
|
@@ -287,135 +284,9 @@ void runEncryptedDataTrackRoundTrip(KeyDerivationFunction key_derivation_functio |
287 | 284 |
|
288 | 285 | class DataTrackE2ETest : public LiveKitTestBase {}; |
289 | 286 |
|
290 | | -class DataTrackTransportTest : public DataTrackE2ETest, |
291 | | - public ::testing::WithParamInterface<std::tuple<double, size_t>> {}; |
292 | | - |
293 | 287 | class DataTrackKeyDerivationTest : public DataTrackE2ETest, |
294 | 288 | public ::testing::WithParamInterface<KeyDerivationFunction> {}; |
295 | 289 |
|
296 | | -TEST_P(DataTrackTransportTest, PublishesAndReceivesFramesEndToEnd) { |
297 | | - const auto publish_fps = std::get<0>(GetParam()); |
298 | | - const auto payload_len = std::get<1>(GetParam()); |
299 | | - const auto track_name = makeTrackName("transport"); |
300 | | - |
301 | | - // How long to publish frames for. |
302 | | - constexpr auto PUBLISH_DURATION = 10s; |
303 | | - |
304 | | - // Percentage of total frames that must be received on the subscriber end in |
305 | | - // order for the test to pass. |
306 | | - constexpr float MIN_PERCENTAGE = 0.90f; |
307 | | - |
308 | | - std::vector<TestRoomConnectionOptions> room_configs(2); |
309 | | - room_configs[0].room_options.single_peer_connection = false; |
310 | | - room_configs[1].room_options.single_peer_connection = false; |
311 | | - |
312 | | - DataTrackPublishedDelegate subscriber_delegate; |
313 | | - room_configs[1].delegate = &subscriber_delegate; |
314 | | - |
315 | | - auto rooms = testRooms(room_configs); |
316 | | - auto& publisher_room = rooms[0]; |
317 | | - const auto publisher_identity = publisher_room->localParticipant()->identity(); |
318 | | - |
319 | | - auto track = requirePublishedTrack(publisher_room->localParticipant(), track_name); |
320 | | - std::cerr << "Track published\n"; |
321 | | - |
322 | | - auto remote_track = subscriber_delegate.waitForTrack(kTrackWaitTimeout); |
323 | | - std::cerr << "Got remote track: " << remote_track->info().sid << "\n"; |
324 | | - |
325 | | - ASSERT_NE(remote_track, nullptr) << "Timed out waiting for remote data track"; |
326 | | - EXPECT_TRUE(remote_track->isPublished()); |
327 | | - EXPECT_FALSE(remote_track->info().uses_e2ee); |
328 | | - EXPECT_EQ(remote_track->info().name, track_name); |
329 | | - EXPECT_EQ(remote_track->publisherIdentity(), publisher_identity); |
330 | | - |
331 | | - const auto frame_count = |
332 | | - static_cast<size_t>(std::llround(std::chrono::duration<double>(PUBLISH_DURATION).count() * publish_fps)); |
333 | | - |
334 | | - auto publish = [&]() { |
335 | | - if (!track->isPublished()) { |
336 | | - throw std::runtime_error("Publisher failed to publish data track"); |
337 | | - } |
338 | | - if (track->info().uses_e2ee) { |
339 | | - throw std::runtime_error("Unexpected E2EE on test data track"); |
340 | | - } |
341 | | - if (track->info().name != track_name) { |
342 | | - throw std::runtime_error("Published track name mismatch"); |
343 | | - } |
344 | | - |
345 | | - const auto frame_interval = std::chrono::duration_cast<std::chrono::steady_clock::duration>( |
346 | | - std::chrono::duration<double>(1.0 / publish_fps)); |
347 | | - auto next_send = std::chrono::steady_clock::now(); |
348 | | - |
349 | | - std::cout << "Publishing " << frame_count << " frames with payload length " << payload_len << '\n'; |
350 | | - for (size_t index = 0; index < frame_count; ++index) { |
351 | | - std::vector<std::uint8_t> payload(payload_len, static_cast<std::uint8_t>(index)); |
352 | | - requirePushSuccess(track->tryPush(std::move(payload)), "Failed to push data frame"); |
353 | | - |
354 | | - next_send += frame_interval; |
355 | | - std::this_thread::sleep_until(next_send); |
356 | | - } |
357 | | - |
358 | | - track->unpublishDataTrack(); |
359 | | - }; |
360 | | - |
361 | | - auto subscribe_result = remote_track->subscribe(); |
362 | | - if (!subscribe_result) { |
363 | | - FAIL() << describeDataTrackError(subscribe_result.error()); |
364 | | - } |
365 | | - auto subscription = subscribe_result.value(); |
366 | | - |
367 | | - std::promise<size_t> receive_count_promise; |
368 | | - auto receive_count_future = receive_count_promise.get_future(); |
369 | | - |
370 | | - auto subscribe = [&]() { |
371 | | - size_t received_count = 0; |
372 | | - DataTrackFrame frame; |
373 | | - while (subscription->read(frame) && received_count < frame_count) { |
374 | | - if (frame.payload.empty()) { |
375 | | - throw std::runtime_error("Received empty data frame"); |
376 | | - } |
377 | | - |
378 | | - const auto first_byte = frame.payload.front(); |
379 | | - if (!std::all_of(frame.payload.begin(), frame.payload.end(), |
380 | | - [first_byte](std::uint8_t byte) { return byte == first_byte; })) { |
381 | | - throw std::runtime_error("Received frame with inconsistent payload"); |
382 | | - } |
383 | | - if (frame.user_timestamp.has_value()) { |
384 | | - throw std::runtime_error("Received unexpected user timestamp in transport test"); |
385 | | - } |
386 | | - |
387 | | - ++received_count; |
388 | | - } |
389 | | - |
390 | | - receive_count_promise.set_value(received_count); |
391 | | - }; |
392 | | - |
393 | | - // Launch both publisher and subscriber |
394 | | - auto pub_fut = std::async(std::launch::async, publish); |
395 | | - auto sub_fut = std::async(std::launch::async, subscribe); |
396 | | - |
397 | | - // Wait for both, with a combined deadline (the timeout(...) wrapper). |
398 | | - const auto deadline = std::chrono::steady_clock::now() + PUBLISH_DURATION + 25s; |
399 | | - |
400 | | - const bool pub_ok = pub_fut.wait_until(deadline) == std::future_status::ready; |
401 | | - const bool sub_ok = sub_fut.wait_until(deadline) == std::future_status::ready; |
402 | | - |
403 | | - if (!pub_ok || !sub_ok) { |
404 | | - ADD_FAILURE() << "Timed out waiting for data frames"; |
405 | | - } |
406 | | - |
407 | | - // Equivalent of `try_join!`'s ? — re-throws any exception from either task |
408 | | - pub_fut.get(); |
409 | | - sub_fut.get(); |
410 | | - |
411 | | - const auto received_count = receive_count_future.get(); |
412 | | - const auto received_percent = static_cast<float>(received_count) / static_cast<float>(frame_count); |
413 | | - std::cout << "Received " << received_count << "/" << frame_count << " frames (" << received_percent * 100.0f << "%)" |
414 | | - << '\n'; |
415 | | - |
416 | | - EXPECT_GE(received_percent, MIN_PERCENTAGE) << "Received " << received_count << "/" << frame_count << " frames"; |
417 | | -} |
418 | | - |
419 | 290 | TEST_F(DataTrackE2ETest, UnpublishUpdatesPublishedStateEndToEnd) { |
420 | 291 | const auto track_name = makeTrackName("published_state"); |
421 | 292 |
|
@@ -853,21 +724,10 @@ TEST_F(DataTrackE2ETest, PreservesUserTimestampOnEncryptedDataTrack) { |
853 | 724 | local_track->unpublishDataTrack(); |
854 | 725 | } |
855 | 726 |
|
856 | | -std::string dataTrackParamName(const ::testing::TestParamInfo<std::tuple<double, size_t>>& info) { |
857 | | - if (std::get<0>(info.param) > 100.0) { |
858 | | - return "HighFpsSinglePacket"; |
859 | | - } |
860 | | - return "LowFpsMultiPacket"; |
861 | | -} |
862 | | - |
863 | 727 | std::string keyDerivationParamName(const ::testing::TestParamInfo<KeyDerivationFunction>& info) { |
864 | 728 | return keyDerivationFunctionName(info.param); |
865 | 729 | } |
866 | 730 |
|
867 | | -INSTANTIATE_TEST_SUITE_P(DataTrackScenarios, DataTrackTransportTest, |
868 | | - ::testing::Values(std::make_tuple(120.0, size_t{8192}), std::make_tuple(10.0, size_t{196608})), |
869 | | - dataTrackParamName); |
870 | | - |
871 | 731 | INSTANTIATE_TEST_SUITE_P(KeyDerivationFunctions, DataTrackKeyDerivationTest, |
872 | 732 | ::testing::Values(KeyDerivationFunction::PBKDF2, KeyDerivationFunction::HKDF), |
873 | 733 | keyDerivationParamName); |
|
0 commit comments