diff --git a/client-sdk-rust b/client-sdk-rust index 2811b4be..84a7d969 160000 --- a/client-sdk-rust +++ b/client-sdk-rust @@ -1 +1 @@ -Subproject commit 2811b4be194b091868ed83cca0603842179fed36 +Subproject commit 84a7d969ffe0929621fe709808cb616bf6c1bc45 diff --git a/cpp-example-collection b/cpp-example-collection index 7abd4b97..a468b1dc 160000 --- a/cpp-example-collection +++ b/cpp-example-collection @@ -1 +1 @@ -Subproject commit 7abd4b97aebd33a681cfbbed9b739fdc5c2c17e3 +Subproject commit a468b1dcdb4460f69188c04ae2e46f63e5e50f63 diff --git a/data-track-dynacast-plan.md b/data-track-dynacast-plan.md new file mode 100644 index 00000000..859f0b8b --- /dev/null +++ b/data-track-dynacast-plan.md @@ -0,0 +1,57 @@ +# Data track dynacast in the C++ SDK + +A data track carries a stream of application data. A subscriber is a participant who requests that stream. See the [LiveKit data track guide](https://docs.livekit.io/transport/data/data-tracks/). + +Dynacast pauses sending when the server reports zero subscribers. The track stays published, so participants can still find it and subscribe. Rust rejects new frames while sending is paused. + +## Match the upstream behavior + +The C++ SDK currently pins Rust commit `2811b4be`. The local Rust branch `ladvoc/data-track-dynacast` adds `NO_SUBSCRIBERS` to the protocol in `b4ef0127`. The corresponding server branch sends a Boolean that reports whether a track has any subscribers. Rust accepts pushes until the server reports that the track has zero subscribers. A server that sends no updates keeps the existing behavior. + +Use a released Rust revision that includes the demand update and the new error code. The demand update is the server message about subscribers. Use a compatible LiveKit Server release for the end-to-end test. The current test server pin, `v1.13.3`, lacks the demand update in the local server source. Record both release versions before enabling the new test in CI. + +## Change the C++ SDK + +Add `LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS = 5` in `include/livekit/data_track_error.h`. Keep the existing numeric values. Map the new protocol code in `src/data_track_error.cpp` and preserve the message from Rust. Let the SDK build generate the C++ protocol code from the Rust revision. + +Keep the subscriber state and the decision to accept frames in Rust. Keep `RoomOptions::dynacast` for video. Document the new error on all three `LocalDataTrack::tryPush()` overloads. Explain that callers can drop that frame and try again with a fresh frame. Preserve the success result for an empty payload on a valid handle. + +## Test the behavior + +### Unit test + +A unit test exercises one function without a server. Add one case to `src/tests/unit/test_data_track_error.cpp`. Pass the new protocol error to `LocalDataTrackTryPushError::fromProto()`. Make sure that it returns `NO_SUBSCRIBERS` and preserves the message. Keep the existing test for the `UNKNOWN` fallback. + +### Integration test + +An integration test exercises the C++ and Rust boundary. Extend `UnpublishUpdatesPublishedStateEndToEnd` in `src/tests/integration/test_data_track.cpp`. After unpublish, make sure that a nonempty `tryPush()` returns `TRACK_UNPUBLISHED`. Make sure that an empty `tryPush()` still succeeds on the same handle. Retain the published-state assertions and remove the fixed delay before unpublish. + +### End-to-end test + +An end-to-end test exercises two SDK clients through a live server. Extend `CanResubscribeToRemoteDataTrack` in the same file. Use one publisher and one subscriber. After publication, wait for `NO_SUBSCRIBERS` and make sure that the track stays published. Subscribe and make sure that the receiver gets a fresh frame with the expected data. Close the subscription and wait for `NO_SUBSCRIBERS` again. Subscribe again and make sure that the receiver gets a frame with a different marker. + +Use the existing fixture and a bounded wait for each state change. During subscription changes, allow `NO_SUBSCRIBERS` while waiting for the next frame. Fail on any other push error. Use one thread to call `tryPush()` and close streams on timeout to release blocked readers. Run this case in the existing `e2e-testing` jobs with the compatible server pin. + +## Update callers and measure cost + +Keep `PublishManyTracks` focused on publication and unpublication. Use an active subscriber in the memory test to preserve its coverage of frame enqueueing. In delivery tests, retry with fresh frames if `NO_SUBSCRIBERS` occurs before subscription takes effect. Keep other push failures visible. + +Use `benchmarks/data_track_throughput` to compare the current and updated SDK with one active subscriber. Measure accepted frames per second and the time from send to receipt under the same load. Use the same payload size and push rate with zero subscribers. Count `NO_SUBSCRIBERS` separately from queue-full errors and record the time per push. Disable per-frame error logging for the expected no-subscriber result during the measurement. + +## Verify before merging + +Initialize the shared tools with `git submodule update --init cpp-tools`. If the root `.clang-format` and `.clang-tidy` links are missing, run `./cpp-tools/install.sh`. Initialize the Rust submodule and its dependencies at the selected revision. Build with `./build.sh debug-tests` or `build.cmd debug-tests` on Windows. Run `source scripts/set-test-tokens.sh` before the test commands. Run the targeted tests and the existing supported-platform test matrix. + +Run `./scripts/generate-docs.sh` to build the API reference. Run the formatter and static analysis commands in `docs/tools.md`. + +With the updated SDK, run the existing data track delivery test once against `v1.13.3`. Use this run to make sure that delivery still works on a server that sends no demand updates. Record the server version, test results, and benchmark results in the pull request. + +## Local verification results + +On macOS, the pinned Rust build passed 364 unit tests and skipped the new protocol mapping test. LiveKit Server `v1.13.3` passed all 27 data track integration tests in that build. The preview Rust build passed all 365 unit tests and three compatibility tests against `v1.13.3`. The preview pair passed 28 data track integration tests, including the dynacast test. The dynacast test also passed five consecutive runs. The memory tester passed a syntax build, and its runtime test still needs Linux. + +The preview used Rust `84a7d969` and LiveKit Server `50304fd0`. Both upstream changes still need releases before the default build and CI can enable dynacast. [Rust change](https://github.com/livekit/rust-sdks/pull/1696) ยท [Server change](https://github.com/livekit/livekit/pull/4656) + +The benchmark sent 300 frames of 1 KiB at 100 frames per second on the preview server. With one subscriber, both builds accepted about 100 frames per second. The pinned build delivered 300 frames, and the preview delivered 299 frames. Median delivery time was 1.82 ms for the pinned build and 2.04 ms for the preview. The 95th percentile was 2.89 ms for the pinned build and 3.23 ms for the preview. + +With zero subscribers, the pinned build accepted all 300 pushes and averaged 133 microseconds per push. The preview returned `NO_SUBSCRIBERS` for all 300 pushes and averaged 119 microseconds per push. Neither run returned `QUEUE_FULL`. diff --git a/docs/testing.md b/docs/testing.md index 09525611..475d4d1b 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -65,6 +65,20 @@ LIVEKIT_CONFIG="enable_participant_data_blob: true" livekit-server --dev ``` +### Data track dynacast + +The dynacast test needs a Rust core with `NO_SUBSCRIBERS` and a server that +sends data track demand updates. The current release pins lack this support. +With compatible builds, run the test from the repository root. + +```bash +source scripts/set-test-tokens.sh +LIVEKIT_TEST_DATA_TRACK_DYNACAST=1 ./build-debug/bin/livekit_integration_tests \ + --gtest_filter=DataTrackE2ETest.DynacastPausesAndResumesDataTrack +``` + +The test fails if the publisher never reports `NO_SUBSCRIBERS`. + ## Environment variables The integration and stress test suites (data tracks, RPC, media multistream, @@ -196,8 +210,9 @@ or groups of scenarios: track, captures synthetic PCM frames, unpublishes, disconnects, and shuts down. - `video-track` repeatedly initializes the SDK, connects, publishes a video track, captures synthetic I420 frames, unpublishes, disconnects, and shuts down. -- `data-track` repeatedly connects, publishes a data track, pushes synthetic - payloads, unpublishes it, and disconnects. +- `data-track` connects a publisher and a subscriber for each cycle. The + publisher pushes synthetic frames and unpublishes the track. The subscriber + uses `LIVEKIT_TOKEN_B`. - `room-reuse` repeatedly connects and disconnects the same room object. - `room-client-leave` repeatedly connects, disconnects, and destroys a room. - `room-server-delete` repeatedly connects, publishes one synthetic video diff --git a/include/livekit/data_track_error.h b/include/livekit/data_track_error.h index ac485a1d..a3c350c4 100644 --- a/include/livekit/data_track_error.h +++ b/include/livekit/data_track_error.h @@ -59,6 +59,8 @@ enum class LocalDataTrackTryPushErrorCode : std::uint32_t { TRACK_UNPUBLISHED = 2, QUEUE_FULL = 3, INTERNAL = 4, + /// The server reports that the published track has no subscribers. + NO_SUBSCRIBERS = 5, }; /// @brief Error details returned when pushing a frame to a local data track fails. diff --git a/include/livekit/local_data_track.h b/include/livekit/local_data_track.h index 9c4a2bfe..29f7ee97 100644 --- a/include/livekit/local_data_track.h +++ b/include/livekit/local_data_track.h @@ -65,32 +65,36 @@ class LIVEKIT_API LocalDataTrack { /// Metadata about this data track. const DataTrackInfo& info() const noexcept { return info_; } - /// Try to push a frame to all subscribers of this track. + /// @brief Try to push a frame to all subscribers of this track. /// /// An empty payload succeeds without sending a frame to subscribers. + /// If the server reports that no one subscribes, the track stays published. + /// Drop the rejected frame and try again with a fresh frame. /// /// @param frame The frame to push. - /// @return Success on delivery acceptance, or a typed error describing why - /// the frame could not be queued. + /// @return Success if accepted, @c NO_SUBSCRIBERS if the server reports no + /// subscribers, or another error if the frame could not be queued. Result tryPush(const DataTrackFrame& frame); - /// Try to push a frame to all subscribers of this track. + /// @brief Try to push a frame to all subscribers of this track. /// /// An empty payload succeeds without sending a frame to subscribers. + /// Drop a frame rejected with @c NO_SUBSCRIBERS and try again with a fresh frame. /// /// @param payload The payload to push. /// @param user_timestamp Optional application-defined timestamp. The unit is /// caller-defined. - /// @return Success on delivery acceptance, or a typed error describing why - /// the frame could not be queued. + /// @return Success if accepted, @c NO_SUBSCRIBERS if the server reports no + /// subscribers, or another error if the frame could not be queued. Result tryPush(std::vector&& payload, std::optional user_timestamp = std::nullopt); - /// Try to push a frame from a borrowed byte buffer. + /// @brief Try to push a frame from a borrowed byte buffer. /// /// Copies @p size bytes from @p data into an FFI request before returning; /// the SDK does not retain the buffer. /// An empty payload succeeds without sending a frame to subscribers. + /// Drop a frame rejected with @c NO_SUBSCRIBERS and try again with a fresh frame. /// /// @note This avoids an intermediate copy when the caller already owns a byte /// buffer, but it is not a zero-copy send. @@ -101,8 +105,8 @@ class LIVEKIT_API LocalDataTrack { /// no-op. /// @param user_timestamp Optional application-defined timestamp. The unit is /// caller-defined. - /// @return Success on delivery acceptance, or a typed error describing why - /// the frame could not be queued. + /// @return Success if accepted, @c NO_SUBSCRIBERS if the server reports no + /// subscribers, or another error if the frame could not be queued. Result tryPush(const std::uint8_t* data, std::size_t size, std::optional user_timestamp = std::nullopt); diff --git a/src/data_track_error.cpp b/src/data_track_error.cpp index d077dc83..16a61b26 100644 --- a/src/data_track_error.cpp +++ b/src/data_track_error.cpp @@ -52,7 +52,9 @@ PublishDataTrackErrorCode fromProtoCode(proto::PublishDataTrackErrorCode code) { } LocalDataTrackTryPushErrorCode fromProtoCode(proto::LocalDataTrackTryPushErrorCode code) { - switch (code) { + // The pinned Rust schema predates NO_SUBSCRIBERS. Use its protocol value + // until we can build against a published Rust release that names it. + switch (static_cast(code)) { case proto::LOCAL_DATA_TRACK_TRY_PUSH_ERROR_CODE_INVALID_HANDLE: return LocalDataTrackTryPushErrorCode::INVALID_HANDLE; case proto::LOCAL_DATA_TRACK_TRY_PUSH_ERROR_CODE_TRACK_UNPUBLISHED: @@ -61,6 +63,8 @@ LocalDataTrackTryPushErrorCode fromProtoCode(proto::LocalDataTrackTryPushErrorCo return LocalDataTrackTryPushErrorCode::QUEUE_FULL; case proto::LOCAL_DATA_TRACK_TRY_PUSH_ERROR_CODE_INTERNAL: return LocalDataTrackTryPushErrorCode::INTERNAL; + case 5: + return LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS; case proto::LOCAL_DATA_TRACK_TRY_PUSH_ERROR_CODE_UNKNOWN: default: return LocalDataTrackTryPushErrorCode::UNKNOWN; diff --git a/src/tests/integration/test_data_track.cpp b/src/tests/integration/test_data_track.cpp index d584c551..e580306d 100644 --- a/src/tests/integration/test_data_track.cpp +++ b/src/tests/integration/test_data_track.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "../common/test_common.h" #include "ffi_client.h" @@ -37,7 +38,6 @@ namespace { constexpr char kTrackNamePrefix[] = "data_track_e2e"; constexpr auto kTrackWaitTimeout = 10s; constexpr auto kPollingInterval = 10ms; -constexpr int kResubscribeIterations = 10; constexpr std::size_t kSinglePacketPayloadBytes = 8192; constexpr int kPublishManyTrackCount = 256; constexpr auto kPublishManyTimeout = 5s; @@ -137,6 +137,12 @@ void requirePushSuccess(const Result& result, } } +void requirePushWhileSubscribed(const Result& result) { + if (!result && result.error().code != LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS) { + requirePushSuccess(result, "Failed to push data frame"); + } +} + class DataTrackPublishedDelegate : public RoomDelegate { public: void onDataTrackPublished(Room&, const DataTrackPublishedEvent& event) override { @@ -334,7 +340,7 @@ TEST_P(DataTrackTransportTest, PublishesAndReceivesFramesEndToEnd) { DataTrackFrame frame; frame.payload.assign(payload_len, kTransportPayloadValue); while (keep_publishing.load()) { - requirePushSuccess(local_track->tryPush(frame), "Failed to push data frame"); + requirePushWhileSubscribed(local_track->tryPush(frame)); std::this_thread::sleep_for(50ms); } }); @@ -406,7 +412,7 @@ TEST_F(DataTrackE2ETest, ReceivesFramesWithCustomPipelineOptionsEndToEnd) { DataTrackFrame frame; frame.payload.assign(payload_len, kTransportPayloadValue); while (keep_publishing.load()) { - requirePushSuccess(local_track->tryPush(frame), "Failed to push data frame"); + requirePushWhileSubscribed(local_track->tryPush(frame)); std::this_thread::sleep_for(50ms); } }); @@ -457,10 +463,13 @@ TEST_F(DataTrackE2ETest, UnpublishUpdatesPublishedStateEndToEnd) { ASSERT_NE(remote_track, nullptr) << "Timed out waiting for remote data track"; EXPECT_TRUE(remote_track->isPublished()); - std::this_thread::sleep_for(500ms); local_track->unpublishDataTrack(); EXPECT_FALSE(local_track->isPublished()); + const auto push = local_track->tryPush(std::vector{0xFA}); + ASSERT_FALSE(push); + EXPECT_EQ(push.error().code, LocalDataTrackTryPushErrorCode::TRACK_UNPUBLISHED); + EXPECT_TRUE(local_track->tryPush(nullptr, 0)); EXPECT_TRUE(waitForCondition([&]() { return !remote_track->isPublished(); }, 2s)) << "Remote track did not report unpublished state"; } @@ -545,21 +554,6 @@ TEST_F(DataTrackE2ETest, PublishManyTracks) { << std::chrono::duration_cast(elapsed).count() << " ms" << std::endl; EXPECT_LT(elapsed, kPublishManyTimeout); - // This test intentionally creates bursty data-track traffic by pushing a - // large frame on every published track in quick succession. The RTC sender - // path uses bounded queues, so under this load not every packet is expected - // to make it onto the transport and "Failed to enqueue data track packet" - // logs are expected. The purpose of this test is to verify publish/push - // behavior and local track state, not end-to-end delivery of every packet. - for (const auto& track : tracks) { - auto push_result = track->tryPush(std::vector(kLargeFramePayloadBytes, 0xFA)); - if (!push_result) { - ADD_FAILURE() << "Failed to push large frame on track " << track->info().name << ": " - << describeDataTrackError(push_result.error()); - } - std::this_thread::sleep_for(50ms); - } - for (const auto& track : tracks) { track->unpublishDataTrack(); EXPECT_FALSE(track->isPublished()); @@ -755,7 +749,7 @@ TEST_F(DataTrackE2ETest, PublishWithCustomSchemaAndFrameEncodingMetadata) { local_track->unpublishDataTrack(); } -TEST_F(DataTrackE2ETest, CanResubscribeToRemoteDataTrack) { +static void exerciseDataTrackResubscribe(bool expect_dynacast) { const auto track_name = makeTrackName("resubscribe"); DataTrackPublishedDelegate subscriber_delegate; @@ -763,52 +757,77 @@ TEST_F(DataTrackE2ETest, CanResubscribeToRemoteDataTrack) { room_configs[1].delegate = &subscriber_delegate; auto rooms = testRooms(room_configs); - auto& publisher_room = rooms[0]; - - std::atomic keep_publishing{true}; - std::exception_ptr publish_error; - std::thread publisher([&]() { - try { - auto track = requirePublishedTrack(publisher_room->localParticipant(), track_name); - if (!track->isPublished()) { - throw std::runtime_error("Publisher failed to publish data track"); - } - - while (keep_publishing.load()) { - requirePushSuccess(track->tryPush(std::vector(64, 0xFA)), - "Failed to push resubscribe test frame"); - std::this_thread::sleep_for(50ms); - } - - track->unpublishDataTrack(); - } catch (...) { - publish_error = std::current_exception(); - } - }); + auto local_track = requirePublishedTrack(rooms[0]->localParticipant(), track_name); + ASSERT_TRUE(local_track->isPublished()); auto remote_track = subscriber_delegate.waitForTrack(kTrackWaitTimeout); ASSERT_NE(remote_track, nullptr) << "Timed out waiting for remote data track"; - for (int iteration = 0; iteration < kResubscribeIterations; ++iteration) { - auto subscribe_result = remote_track->subscribe(); + for (const std::uint8_t marker : {std::uint8_t{0xFA}, std::uint8_t{0xFB}}) { + SCOPED_TRACE(static_cast(marker)); + const std::vector payload(64, marker); + if (expect_dynacast) { + ASSERT_TRUE(waitForCondition( + [&]() { + const auto result = local_track->tryPush(std::vector{0}); + if (!result && result.error().code == LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS) { + return true; + } + requirePushSuccess(result, "Unexpected error while waiting for dynacast to pause"); + return false; + }, + 5s, 50ms)) + << "The publisher did not report NO_SUBSCRIBERS"; + EXPECT_TRUE(local_track->isPublished()); + } + + const auto subscribe_result = remote_track->subscribe(); if (!subscribe_result) { FAIL() << describeDataTrackError(subscribe_result.error()); } - auto subscription = subscribe_result.value(); - - auto frame = readFrameWithTimeout(subscription, 5s); - EXPECT_FALSE(frame.payload.empty()) << "Iteration " << iteration; - + const auto& subscription = subscribe_result.value(); + auto reader = std::async(std::launch::async, [&]() { + DataTrackFrame frame; + if (!subscription->read(frame)) { + throw std::runtime_error("Subscription ended before a frame arrived"); + } + return frame; + }); + + std::string push_error; + const bool finished = waitForCondition( + [&]() { + if (reader.wait_for(0ms) == std::future_status::ready) { + return true; + } + const auto result = local_track->tryPush(payload.data(), payload.size()); + if (!result && result.error().code != LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS) { + push_error = describeDataTrackError(result.error()); + } + return !push_error.empty(); + }, + 5s, 50ms); subscription->close(); - std::this_thread::sleep_for(50ms); + ASSERT_TRUE(push_error.empty()) << push_error; + ASSERT_TRUE(finished) << "Timed out waiting for a frame"; + EXPECT_EQ(reader.get().payload, payload); + if (!expect_dynacast && marker == 0xFA) { + // Legacy servers can coalesce the unsubscribe and immediate resubscribe. + std::this_thread::sleep_for(50ms); + } } + local_track->unpublishDataTrack(); +} - keep_publishing.store(false); - publisher.join(); +TEST_F(DataTrackE2ETest, CanResubscribeToRemoteDataTrack) { exerciseDataTrackResubscribe(false); } - if (publish_error) { - std::rethrow_exception(publish_error); +TEST_F(DataTrackE2ETest, DynacastPausesAndResumesDataTrack) { + const char* enabled = std::getenv("LIVEKIT_TEST_DATA_TRACK_DYNACAST"); + if (enabled == nullptr || std::string_view(enabled) != "1") { + GTEST_SKIP() + << "Set LIVEKIT_TEST_DATA_TRACK_DYNACAST=1 with a Rust core and server that support data track dynacast"; } + exerciseDataTrackResubscribe(true); } TEST_F(DataTrackE2ETest, FfiClientSubscribeDataTrackReturnsSyncResult) { diff --git a/src/tests/memory/memory_tester.cpp b/src/tests/memory/memory_tester.cpp index f8c2cdee..94658cb6 100644 --- a/src/tests/memory/memory_tester.cpp +++ b/src/tests/memory/memory_tester.cpp @@ -16,6 +16,7 @@ #include #include +#include #if LIVEKIT_CAPTURE_ENABLED #include @@ -492,6 +493,36 @@ void runVideoTrackCycle(const RoomCredentials& credentials) { // Exercises data-track publication, payload enqueueing, explicit unpublication, // and room teardown while the SDK remains initialized across cycles. void runDataTrackCycle(const RoomCredentials& credentials) { + class SubscriberDelegate final : public livekit::RoomDelegate { + public: + void onDataTrackPublished(livekit::Room&, const livekit::DataTrackPublishedEvent& event) override { + if (event.track && event.track->info().name == "memory-data") { + std::lock_guard lock(mutex_); + track_ = event.track; + published_.notify_one(); + } + } + + std::shared_ptr waitForTrack() { + std::unique_lock lock(mutex_); + published_.wait_for(lock, 5s, [&]() { return track_ != nullptr; }); + return track_; + } + + private: + std::mutex mutex_; + std::condition_variable published_; + std::shared_ptr track_; + } subscriber_delegate; + + const char* subscriber_token = std::getenv("LIVEKIT_TOKEN_B"); + if (subscriber_token == nullptr || *subscriber_token == '\0') { + throw std::runtime_error("the data track memory scenario requires LIVEKIT_TOKEN_B"); + } + livekit::Room subscriber; + subscriber.setDelegate(&subscriber_delegate); + connectRoom(subscriber, {credentials.url, subscriber_token}); + DisconnectTrackingDelegate delegate; livekit::Room room; room.setDelegate(&delegate); @@ -507,12 +538,28 @@ void runDataTrackCycle(const RoomCredentials& credentials) { } const auto& track = publish_result.value(); + const auto remote_track = subscriber_delegate.waitForTrack(); + if (!remote_track) { + throw std::runtime_error("subscriber did not discover the memory data track"); + } + const auto subscription = remote_track->subscribe(); + if (!subscription) { + throw std::runtime_error("failed to subscribe to the memory data track: " + subscription.error().message); + } + livekit::DataTrackFrame frame; frame.payload.assign(256, 0xFA); + const auto deadline = std::chrono::steady_clock::now() + 5s; for (int frame_index = 0; frame_index < kFramesPerCycle; ++frame_index) { frame.user_timestamp = static_cast(frame_index); - if (!track->tryPush(frame)) { - throw std::runtime_error("failed to push local data track frame"); + auto result = track->tryPush(frame); + while (!result && result.error().code == livekit::LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS && + std::chrono::steady_clock::now() < deadline) { + std::this_thread::sleep_for(10ms); + result = track->tryPush(frame); + } + if (!result) { + throw std::runtime_error("failed to push local data track frame: " + result.error().message); } } diff --git a/src/tests/unit/test_data_track_error.cpp b/src/tests/unit/test_data_track_error.cpp index 418b113f..ba6fff9e 100644 --- a/src/tests/unit/test_data_track_error.cpp +++ b/src/tests/unit/test_data_track_error.cpp @@ -43,6 +43,20 @@ TEST(DataTrackErrorTest, TryPushErrorFromEmptyProto) { EXPECT_EQ(err.code, LocalDataTrackTryPushErrorCode::UNKNOWN); } +TEST(DataTrackErrorTest, TryPushNoSubscribersErrorFromProto) { + proto::LocalDataTrackTryPushErrorCode code; + if (!proto::LocalDataTrackTryPushErrorCode_Parse("LOCAL_DATA_TRACK_TRY_PUSH_ERROR_CODE_NO_SUBSCRIBERS", &code)) { + GTEST_SKIP() << "The pinned Rust protocol does not include NO_SUBSCRIBERS"; + } + proto::LocalDataTrackTryPushError proto_err; + proto_err.set_code(code); + proto_err.set_message("no remote subscribers"); + + const auto error = LocalDataTrackTryPushError::fromProto(proto_err); + EXPECT_EQ(error.code, LocalDataTrackTryPushErrorCode::NO_SUBSCRIBERS); + EXPECT_EQ(error.message, "no remote subscribers"); +} + TEST(DataTrackErrorTest, SubscribeErrorFromEmptyProto) { proto::SubscribeDataTrackError proto_err; SubscribeDataTrackError err = SubscribeDataTrackError::fromProto(proto_err);