-
Notifications
You must be signed in to change notification settings - Fork 192
Dynacast: keep SVC tracks active while any quality is subscribed #1214
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
Open
MaxHeimbrock
wants to merge
1
commit into
max/fix-dynacast-non-simulcast
Choose a base branch
from
max/dynacast-svc-any-enabled
base: max/fix-dynacast-non-simulcast
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| livekit: patch | ||
| --- | ||
|
|
||
| Dynacast: keep SVC (VP9/AV1) tracks active while any quality is subscribed - #1214 (@MaxHeimbrock) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ use { | |
| TestRoomOptions, | ||
| }, | ||
| livekit::{ | ||
| options::VideoCodec, | ||
| options::{TrackPublishOptions, VideoCodec}, | ||
| prelude::*, | ||
| track::{PublishingLayerQuality, VideoQuality}, | ||
| }, | ||
|
|
@@ -428,3 +428,110 @@ async fn test_dynacast_multiple_subscribers_only_publish_requested_tracks() -> R | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Verifies dynacast behavior for an SVC track (VP9, L3T3_KEY). | ||
| /// | ||
| /// SVC tracks carry all spatial layers in a single encoded stream and the SFU | ||
| /// selects layers server-side, so: | ||
| /// 1. Subscriber quality requests must never deactivate the encoding while at | ||
| /// least one quality is subscribed (any-enabled rule). | ||
| /// 2. Unsubscribing the last subscriber deactivates the encoding. | ||
| /// 3. Resubscribing reactivates it. | ||
| #[cfg(feature = "__lk-e2e-test")] | ||
| #[test_log::test(tokio::test)] | ||
| async fn test_dynacast_svc() -> Result<()> { | ||
| let mut pub_room_opts = RoomOptions::default(); | ||
| pub_room_opts.dynacast = true; | ||
| let pub_options = TestRoomOptions { room: pub_room_opts, ..Default::default() }; | ||
| let sub_options = TestRoomOptions::default(); | ||
|
|
||
| let mut rooms = test_rooms_with_options([pub_options, sub_options]).await?; | ||
| let (pub_room, _pub_events) = rooms.remove(0); | ||
|
Comment on lines
+446
to
+449
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. nitpick: You can use |
||
| let (_sub_room, mut sub_events) = rooms.remove(0); | ||
|
|
||
| let pub_room = Arc::new(pub_room); | ||
| let solid_params = SolidColorParams { width: 1280, height: 720, luma: 128 }; | ||
| let mut solid_track = SolidColorTrack::new(pub_room.clone(), solid_params); | ||
| solid_track | ||
| .publish_with_options(TrackPublishOptions { | ||
| video_codec: VideoCodec::VP9, | ||
| simulcast: false, | ||
| scalability_mode: Some("L3T3_KEY".to_string()), | ||
| ..Default::default() | ||
| }) | ||
| .await?; | ||
|
|
||
| let sub_publication: RemoteTrackPublication = timeout(Duration::from_secs(15), async { | ||
| loop { | ||
| let Some(event) = sub_events.recv().await else { | ||
| return Err(anyhow!("Event channel closed before TrackSubscribed")); | ||
| }; | ||
| if let RoomEvent::TrackSubscribed { publication, .. } = event { | ||
| return Ok(publication); | ||
| } | ||
| } | ||
| }) | ||
| .await??; | ||
|
|
||
| let pub_video_track = publisher_video_track(&pub_room)?; | ||
|
|
||
| // --- Baseline: the single SVC encoding is active --- | ||
| let layers = | ||
| wait_for_layers(&pub_video_track, "svc baseline", Duration::from_secs(15), |layers| { | ||
| layers.len() == 1 && layers[0].active | ||
| }) | ||
| .await?; | ||
| log::info!("dynacast svc baseline layers: {:?}", layers); | ||
|
|
||
| // --- Request LOW quality: the SVC encoding must stay active --- | ||
| log::info!("dynacast svc test: requesting LOW quality"); | ||
| sub_publication.set_video_quality(VideoQuality::Low); | ||
|
|
||
| // The resulting quality update arrives asynchronously; poll to make sure | ||
| // the encoding never gets deactivated by it. | ||
| let deadline = tokio::time::Instant::now() + Duration::from_secs(10); | ||
| while tokio::time::Instant::now() < deadline { | ||
| let layers = pub_video_track.publishing_layers(); | ||
| assert!( | ||
| !layers.is_empty() && layers.iter().all(|layer| layer.active), | ||
| "SVC encoding must stay active after LOW request, got {:?}", | ||
| layers | ||
| ); | ||
| time::sleep(Duration::from_millis(250)).await; | ||
| } | ||
|
|
||
| // --- Request HIGH quality again: still active --- | ||
| log::info!("dynacast svc test: requesting HIGH quality"); | ||
| sub_publication.set_video_quality(VideoQuality::High); | ||
|
|
||
| let deadline = tokio::time::Instant::now() + Duration::from_secs(10); | ||
| while tokio::time::Instant::now() < deadline { | ||
| let layers = pub_video_track.publishing_layers(); | ||
| assert!( | ||
| !layers.is_empty() && layers.iter().all(|layer| layer.active), | ||
| "SVC encoding must stay active after HIGH request, got {:?}", | ||
| layers | ||
| ); | ||
| time::sleep(Duration::from_millis(250)).await; | ||
| } | ||
|
|
||
| // --- Unsubscribe: with no subscribers left the encoding is deactivated --- | ||
| log::info!("dynacast svc test: unsubscribing"); | ||
| sub_publication.set_subscribed(false); | ||
|
|
||
| wait_for_layers(&pub_video_track, "svc unsubscribed", Duration::from_secs(30), |layers| { | ||
| !layers.is_empty() && layers.iter().all(|layer| !layer.active) | ||
| }) | ||
| .await?; | ||
|
|
||
| // --- Resubscribe: the encoding comes back --- | ||
| log::info!("dynacast svc test: resubscribing"); | ||
| sub_publication.set_subscribed(true); | ||
|
|
||
| wait_for_layers(&pub_video_track, "svc resubscribed", Duration::from_secs(30), |layers| { | ||
| !layers.is_empty() && layers.iter().all(|layer| layer.active) | ||
| }) | ||
| .await?; | ||
|
|
||
| Ok(()) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
suggestion(non-blocking): Consider breaking this out into a
consthelper function.