Skip to content
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

Extended consumer options to provide way to override MID. #586

Merged
merged 9 commits into from
Jun 21, 2021
Next Next commit
Extended consumer options to provide way to override MID.
  • Loading branch information
mstyura committed Jun 15, 2021
commit d6b8bdc66d539bd1122bc8fc4c5c8b34fb76d899
4 changes: 4 additions & 0 deletions rust/src/router/consumer.rs
Original file line number Diff line number Diff line change
@@ -76,6 +76,9 @@ pub struct ConsumerOptions {
/// consuming endpoint even before it's ready to consume it, generating “black” video until the
/// device requests a keyframe by itself.
pub paused: bool,
/// The preferred MID for consumer created. If not specified will be assigned automatically
/// to sequentlially growing number serialized to string.
mstyura marked this conversation as resolved.
Show resolved Hide resolved
pub preferred_mid: Option<String>,
/// Preferred spatial and temporal layer for simulcast or SVC media sources.
/// If `None`, the highest ones are selected.
pub preferred_layers: Option<ConsumerLayers>,
@@ -95,6 +98,7 @@ impl ConsumerOptions {
paused: false,
preferred_layers: None,
pipe: false,
preferred_mid: None,
app_data: AppData::default(),
}
}
16 changes: 9 additions & 7 deletions rust/src/router/transport.rs
Original file line number Diff line number Diff line change
@@ -569,6 +569,7 @@ pub(super) trait TransportImpl: TransportGeneric {
producer_id,
rtp_capabilities,
paused,
preferred_mid,
preferred_layers,
pipe,
app_data,
@@ -594,14 +595,15 @@ pub(super) trait TransportImpl: TransportGeneric {
.map_err(ConsumeError::BadConsumerRtpParameters)?;

if !pipe {
// We use up to 8 bytes for MID (string).
let next_mid_for_consumers = self
.next_mid_for_consumers()
.fetch_add(1, Ordering::Relaxed);
let mid = next_mid_for_consumers % 100_000_000;

// Set MID.
rtp_parameters.mid = Some(format!("{}", mid));
rtp_parameters.mid = preferred_mid.or_else(|| {
// We use up to 8 bytes for MID (string).
let next_mid_for_consumers = self
.next_mid_for_consumers()
.fetch_add(1, Ordering::Relaxed);
let mid = next_mid_for_consumers % 100_000_000;
Some(format!("{}", mid))
})
}

rtp_parameters