Repository navigation
Expose subscriber-side remote track enable/disable in Python #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,20 @@ def set_subscribed(self, subscribed: bool) -> None: | |
| req.set_subscribed.publication_handle = self._ffi_handle.handle | ||
| FfiClient.instance.request(req) | ||
|
|
||
| def set_enabled(self, enabled: bool) -> None: | ||
| """Enable or disable media delivery for this subscribed remote track. | ||
|
|
||
| Unlike changing the subscription, this retains the subscription and | ||
| requests a media delivery change without renegotiation. It does not | ||
| change the publisher's mute state or affect other subscribers. | ||
| Call this after the track is subscribed. The request is not a guarantee | ||
| that in-flight media has drained or that resumed media has arrived. | ||
| """ | ||
| req = proto_ffi.FfiRequest() | ||
| req.enable_remote_track_publication.track_publication_handle = self._ffi_handle.handle | ||
| req.enable_remote_track_publication.enabled = enabled | ||
| FfiClient.instance.request(req) | ||
|
Comment on lines
+133
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Stale pause overrides track resume Successive Learn moreThe native toggle changes the local track synchronously but spawns each server update independently. The tasks run on a multi-threaded runtime. The signaling writer sends requests in channel arrival order, not in Python call order. If the earlier task reaches that channel last, the media server applies the older value. A repeat call requesting the current local value is a no-op. Example: An agent calls Recommended fix: Serialize settings updates per publication in the native SDK, or coalesce pending updates into a single ordered sender that always transmits the newest desired settings last. Test two sequential API calls with the first send deliberately delayed. Was this helpful? React with 👍 or 👎 to provide feedback.
Comment on lines
+132
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Media toggles overwrite simulcast settings On a simulcast track, Learn moreBoth operations send the same subscriber-settings message to the media server. The native enable callback fills in Example: A subscriber selects High for a simulcast camera, pauses it, then resumes it. The resume request carries Low, so the server switches to the lowest layer. If the subscriber selects High during the pause instead, the settings request clears the server pause even though the local track stays disabled. Recommended fix: Keep a single set of desired subscriber settings in the Rust SDK and send the full set on either update, preserving both the requested layer and whether forwarding is paused. Cover each call order with a server-backed simulcast test. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| def set_video_quality(self, quality: "VideoQuality.ValueType") -> None: | ||
| """For simulcasted video tracks, request a specific simulcast layer | ||
| from the server. Use one of `rtc.VideoQuality.VIDEO_QUALITY_LOW` (q), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Copyright 2026 LiveKit, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from livekit.rtc import RemoteTrackPublication | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("enabled", [False, True]) | ||
| def test_set_enabled_sends_publication_request(enabled: bool) -> None: | ||
| publication = object.__new__(RemoteTrackPublication) | ||
| publication._ffi_handle = SimpleNamespace(handle=123) # type: ignore[assignment] | ||
| publication._subscribed = True | ||
|
|
||
| with patch("livekit.rtc.track_publication.FfiClient") as ffi: | ||
| publication.set_enabled(enabled) | ||
|
|
||
| ffi.instance.request.assert_called_once() | ||
| request = ffi.instance.request.call_args.args[0] | ||
| assert request.WhichOneof("message") == "enable_remote_track_publication" | ||
| assert request.enable_remote_track_publication.track_publication_handle == 123 | ||
| assert request.enable_remote_track_publication.enabled is enabled | ||
| assert publication.subscribed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Track toggle crashes during unpublish
When a publisher removes a track during
set_enabled, the native toggle can unwrap a track that no longer exists. The FFI panic callback terminates the Python process.Learn more
The native request handler forwards the toggle to the Rust publication. The Rust method checks for an attached media track, checks whether that track is enabled, then reads the track again and unwraps it. Each lookup takes a separate read lock in track. A publisher can unpublish concurrently, and unpublish_track_inner clears the track. The native C bridge catches the resulting panic and forwards it to the Python callback, which sends SIGTERM.
Example: An agent pauses an incoming microphone while the other participant stops publishing it. If the unpublish clears the track after the enabled check but before the final lookup, the agent process exits instead of ignoring the toggle on the removed track.
Recommended fix: Fix the pinned Rust implementation to take one optional track snapshot, return if it is absent, and compare and update that snapshot with the requested value. Verify whether signaling also needs synchronization with detach. A Python
subscribedcheck cannot close the native race.Was this helpful? React with 👍 or 👎 to provide feedback.