-
Notifications
You must be signed in to change notification settings - Fork 168
Add dynacast support #1003
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?
Add dynacast support #1003
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| libwebrtc: patch | ||
| livekit: patch | ||
| livekit-ffi: patch | ||
| --- | ||
|
|
||
| Add dynacast support - #1003 (@chenosaurus) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1030,6 +1030,9 @@ impl RoomSession { | |
| EngineEvent::TrackMuted { sid, muted } => { | ||
| self.handle_server_initiated_mute_track(sid, muted); | ||
| } | ||
| EngineEvent::SubscribedQualityUpdate { update } => { | ||
| self.handle_subscribed_quality_update(update); | ||
| } | ||
| EngineEvent::LocalDataTrackInput(event) => { | ||
| _ = self.local_dt_input.send(event); | ||
| } | ||
|
|
@@ -1814,6 +1817,94 @@ impl RoomSession { | |
| log::warn!("Track not found in mute request: {}", sid_for_log); | ||
| } | ||
|
|
||
| #[allow(deprecated)] | ||
| fn handle_subscribed_quality_update(&self, update: proto::SubscribedQualityUpdate) { | ||
| if !self.options.dynacast { | ||
| return; | ||
| } | ||
|
|
||
| let track_sid: TrackSid = match update.track_sid.clone().try_into() { | ||
| Ok(sid) => sid, | ||
| Err(_) => { | ||
| log::warn!( | ||
| "dynacast: invalid track sid in subscribed quality update: {}", | ||
| update.track_sid | ||
| ); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| let publication = match self.local_participant.get_track_publication(&track_sid) { | ||
| Some(pub_) => pub_, | ||
| None => { | ||
| log::warn!("dynacast: local track publication not found for sid {}", track_sid); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| let video_track = match publication.track() { | ||
| Some(LocalTrack::Video(vt)) => vt, | ||
| _ => { | ||
| log::debug!( | ||
| "dynacast: track {} is not a local video track, ignoring quality update", | ||
| track_sid | ||
| ); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| let qualities: Vec<proto::SubscribedQuality> = if !update.subscribed_codecs.is_empty() { | ||
| let codec = publication.publish_options().video_codec.as_str().to_lowercase(); | ||
|
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. curiously, is publication.publish_options().video_codec the codec that being used ? or the codec that is preferred or requested ? I wonder if there is any chance that the actual codec is not publication.publish_options().video_codec ? in that case, there might be a mismatch |
||
| log::info!( | ||
| "dynacast: SFU quality update for {}: subscribed_codecs={:?}, looking for codec '{}'", | ||
| track_sid, | ||
| update.subscribed_codecs.iter().map(|sc| { | ||
| let qs: Vec<String> = sc.qualities.iter().map(|q| { | ||
| format!("{:?}={}", proto::VideoQuality::try_from(q.quality).unwrap_or(proto::VideoQuality::High), q.enabled) | ||
| }).collect(); | ||
| format!("{}:[{}]", sc.codec, qs.join(", ")) | ||
| }).collect::<Vec<_>>().join("; "), | ||
| codec, | ||
| ); | ||
| update | ||
| .subscribed_codecs | ||
| .iter() | ||
| .find(|sc| sc.codec.to_lowercase() == codec) | ||
| .map(|sc| sc.qualities.clone()) | ||
| .unwrap_or_else(|| { | ||
| log::warn!("dynacast: codec '{}' not found in subscribed_codecs, falling back to first", codec); | ||
| update | ||
| .subscribed_codecs | ||
| .first() | ||
| .map(|sc| sc.qualities.clone()) | ||
| .unwrap_or_default() | ||
| }) | ||
| } else { | ||
| let qs: Vec<String> = update | ||
| .subscribed_qualities | ||
| .iter() | ||
| .map(|q| { | ||
| format!( | ||
| "{:?}={}", | ||
| proto::VideoQuality::try_from(q.quality) | ||
| .unwrap_or(proto::VideoQuality::High), | ||
|
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. It looks like we have multiple places to default the quality to proto::VideoQuality::High when things are unset ? Should we make a flag or macro instead ? and please add comments to explain why proto::VideoQuality::High is preferred |
||
| q.enabled | ||
| ) | ||
| }) | ||
| .collect(); | ||
| log::info!( | ||
| "dynacast: SFU quality update for {} (legacy): [{}]", | ||
| track_sid, | ||
| qs.join(", "), | ||
| ); | ||
| update.subscribed_qualities.clone() | ||
| }; | ||
|
|
||
| if let Err(e) = video_track.set_publishing_layers(&qualities) { | ||
| log::error!("dynacast: failed to set publishing layers for {}: {}", track_sid, e); | ||
| } | ||
| } | ||
|
|
||
| /// Create a new participant | ||
| /// Also add it to the participants list | ||
| fn create_participant( | ||
|
|
||
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: This can be done without unsafe using
value.degradation_preference.repr. This applies in a few other places too.