Struct MediaTransport
pub struct MediaTransport {
pub(crate) workers: Arc<[RtcWorker]>,
pub(crate) profile: Arc<RtpProfile>,
pub(crate) metrics: Arc<RuntimeMetrics>,
pub(crate) source_policy_signal: SourcePolicySignal,
pub(crate) _tcp_acceptor: Option<Arc<TcpAcceptor>>,
}Expand description
Opaque runtime media transport handle.
MediaTransport is the handle server code and SfuCore
should hold.
It hides the production RTC worker topology. Callers express intent through
inherent methods and must not branch on concrete worker internals.
The handle also centralizes warning logs for failed transport effects. Inner backends return typed errors, while this boundary adds stable diagnostic context such as session keys, media ids and SDP lengths.
Fields§
§workers: Arc<[RtcWorker]>§profile: Arc<RtpProfile>§metrics: Arc<RuntimeMetrics>§source_policy_signal: SourcePolicySignal§_tcp_acceptor: Option<Arc<TcpAcceptor>>Implementations§
§impl MediaTransport
impl MediaTransport
pub fn build(
config: MediaTransportConfig,
deps: MediaTransportDeps,
) -> Result<MediaTransport, MediaTransportBuildError>
pub fn build( config: MediaTransportConfig, deps: MediaTransportDeps, ) -> Result<MediaTransport, MediaTransportBuildError>
builds the runtime media transport from owner configuration and process services
validation completes before worker startup and every worker has a bound socket when this function returns
§Errors
returns MediaTransportBuildError when worker topology or the
code-controlled RTP profile is invalid, the selected UDP backend is
unavailable, the media-quality interval exceeds 24 hours or a worker
cannot start
§impl MediaTransport
impl MediaTransport
pub fn schedule_source_policy_retry(&self, room: RoomInstanceId)
pub fn set_source_policy_deadline(
&self,
room: RoomInstanceId,
deadline: Option<Instant>,
)
pub fn set_source_policy_deadline( &self, room: RoomInstanceId, deadline: Option<Instant>, )
Replaces or cancels the room deadline recomputed by its ordered policy turn.
§impl MediaTransport
impl MediaTransport
pub async fn apply_media_control<P, C>(
&self,
plan: MediaControlPlan<P, C>,
) -> MediaControlOutcome<P, C>
pub async fn apply_media_control<P, C>( &self, plan: MediaControlPlan<P, C>, ) -> MediaControlOutcome<P, C>
Applies a media-control plan and returns completions in insertion order.
§impl MediaTransport
impl MediaTransport
pub async fn teardown(
&self,
teardowns: impl IntoIterator<Item = TransportTeardown>,
)
pub async fn teardown( &self, teardowns: impl IntoIterator<Item = TransportTeardown>, )
Runs teardown idempotently and continues after terminal failures.
Each failed media item escalates once to its session because partial worker state may remain. Errors are consumed so one failure cannot suppress later cleanup. Obligations remain unfinished across worker awaits so dropping the future diagnoses cancellation before the terminal outcome.
§impl MediaTransport
impl MediaTransport
pub fn transport_bitrate_snapshot(
&self,
session_keys: &[TransportSessionKey],
) -> TransportBitrateSnapshot
pub fn transport_bitrate_snapshot( &self, session_keys: &[TransportSessionKey], ) -> TransportBitrateSnapshot
Returns the latest bitrate estimates for the requested sessions.
Missing sessions are omitted from the snapshot. Estimates are suitable for diagnostics and policy input, not for accounting.
pub fn receiver_bandwidth_snapshot(
&self,
session_keys: &[TransportSessionKey],
) -> ReceiverBandwidthSnapshot
pub fn receiver_bandwidth_snapshot( &self, session_keys: &[TransportSessionKey], ) -> ReceiverBandwidthSnapshot
Returns receiver-side bandwidth estimates for the requested sessions.
Room policy may use these estimates as source-selection input. They are best-effort observations from the transport backend.
pub fn transport_quality_snapshot(
&self,
session_keys: &[TransportSessionKey],
) -> BTreeMap<TransportSessionKey, TransportQualitySample>
pub fn transport_quality_snapshot( &self, session_keys: &[TransportSessionKey], ) -> BTreeMap<TransportSessionKey, TransportQualitySample>
Returns sampled transport-quality observations for the requested sessions.
pub fn transport_health_snapshot(
&self,
session_keys: &[TransportSessionKey],
) -> BTreeMap<TransportSessionKey, TransportSessionHealth>
pub fn transport_health_snapshot( &self, session_keys: &[TransportSessionKey], ) -> BTreeMap<TransportSessionKey, TransportSessionHealth>
Returns transport health for the requested sessions with one lock per worker.
Missing sessions and unavailable worker snapshots contribute no facts
pub async fn source_diagnostics_snapshot(
&self,
sources: &[TransportSourceKey],
) -> Result<TransportSourceDiagnosticsSnapshot, TransportAdapterError>
pub async fn source_diagnostics_snapshot( &self, sources: &[TransportSourceKey], ) -> Result<TransportSourceDiagnosticsSnapshot, TransportAdapterError>
Returns source activity and active-speaker facts with one command per worker.
§Errors
Returns TransportAdapterError::TransportUnavailable if any source
selects an unavailable worker or its observation does not complete.
pub fn worker_pressure_snapshots(&self) -> Vec<TransportWorkerPressureSnapshot>
pub fn worker_pressure_snapshots(&self) -> Vec<TransportWorkerPressureSnapshot>
Returns transport pressure for every media worker.
pub fn worker_is_usable(&self, worker_index: usize) -> bool
pub fn worker_is_usable(&self, worker_index: usize) -> bool
Reports whether the worker still owns usable transport sessions.
pub fn worker_placement_states(&self) -> Vec<WorkerPlacementState>
pub async fn active_speaker_source_snapshot_for_worker(
&self,
worker_index: usize,
) -> Result<Vec<ActiveSpeakerSource>, TransportAdapterError>
pub async fn active_speaker_source_snapshot_for_worker( &self, worker_index: usize, ) -> Result<Vec<ActiveSpeakerSource>, TransportAdapterError>
Returns one worker’s active-speaker inventory.
§Errors
Returns TransportAdapterError::TransportUnavailable when the worker
is missing or cannot answer before the observation deadline.
pub async fn active_speaker_source_snapshot_for_workers(
&self,
worker_indices: &[usize],
) -> Result<Vec<ActiveSpeakerSource>, TransportAdapterError>
pub async fn active_speaker_source_snapshot_for_workers( &self, worker_indices: &[usize], ) -> Result<Vec<ActiveSpeakerSource>, TransportAdapterError>
Returns one observation from each requested worker before merging relayed sources.
§Errors
Returns TransportAdapterError::TransportUnavailable if a requested
worker is unavailable. Callers must retry rather than use partial facts.
pub async fn active_speaker_source_snapshot(
&self,
) -> Result<Vec<ActiveSpeakerSource>, TransportAdapterError>
pub async fn active_speaker_source_snapshot( &self, ) -> Result<Vec<ActiveSpeakerSource>, TransportAdapterError>
Returns active-speaker observations from all workers.
§Errors
Returns TransportAdapterError::TransportUnavailable if any worker
observation fails. No partial observation is returned to policy.
pub fn session_transport_health(
&self,
session_key: &TransportSessionKey,
) -> Option<TransportSessionHealth>
pub fn session_transport_health( &self, session_key: &TransportSessionKey, ) -> Option<TransportSessionHealth>
Returns the latest known transport health for one session.
Health is connectivity evidence only. It should not be used as the source of truth for whether a participant belongs to a room.
§impl MediaTransport
impl MediaTransport
pub fn cancel(&self)
pub fn cancel(&self)
Cancels every RTC worker without waiting for termination.
pub async fn shutdown(&self)
pub async fn shutdown(&self)
Cancels every RTC worker and waits for its thread to terminate.
pub fn router_rtp_capabilities(&self) -> MediaCapabilities
pub fn router_rtp_capabilities(&self) -> MediaCapabilities
returns the router capability snapshot compiled from the RTC wire profile
pub async fn create_initial_session_offer(
&self,
room_id: &str,
session_key: &TransportSessionKey,
mid_reuse: bool,
) -> Result<SessionOffer, TransportAdapterError>
pub async fn create_initial_session_offer( &self, room_id: &str, session_key: &TransportSessionKey, mid_reuse: bool, ) -> Result<SessionOffer, TransportAdapterError>
Creates the first SDP offer for a transport session.
The session must already be assigned to a transport worker by its
TransportSessionKey. The returned offer is transport state that
callers should send to the browser unchanged.
With mid_reuse a consumer of the session takes the MID a removed
consumer left. Without it every consumer gets a MID of its own, for a
client that cannot give a MID to another track.
§Errors
Returns TransportAdapterError when the session cannot be addressed or
the active backend cannot create the offer.
pub async fn create_session_renegotiation_offer(
&self,
session_key: &TransportSessionKey,
committed_consumers: Vec<TransportMediaId>,
) -> Result<SessionOffer, TransportAdapterError>
pub async fn create_session_renegotiation_offer( &self, session_key: &TransportSessionKey, committed_consumers: Vec<TransportMediaId>, ) -> Result<SessionOffer, TransportAdapterError>
Creates the SDP offer for the media changes queued since the last one.
A session has one offer outstanding. Media published, consumed or
removed while it awaits its answer goes into the next offer. A queued
consumer joins an offer only when committed_consumers lists it, so
the caller can name every consumer MID the offer adds.
§Errors
Returns TransportAdapterError::TransportUnavailable when the session
cannot be addressed. Returns TransportAdapterError::InvalidInput
before the initial answer or while an offer awaits its answer. Returns
TransportAdapterError::UnsupportedFeature when no queued change
needs an offer.
pub async fn apply_session_answer(
&self,
session_key: &TransportSessionKey,
answer_sdp: &str,
) -> Result<AppliedSessionAnswer, TransportAdapterError>
pub async fn apply_session_answer( &self, session_key: &TransportSessionKey, answer_sdp: &str, ) -> Result<AppliedSessionAnswer, TransportAdapterError>
Applies a browser SDP answer to a pending transport offer.
The answer can reveal transport-derived producer facts such as mapped RTP parameters. Those facts are returned so room code can commit staged media using values observed by the transport.
§Errors
Returns TransportAdapterError::TransportUnavailable when the session
or its worker is unavailable, or TransportAdapterError::InvalidInput
when no offer is pending or answer preflight rejects the input.
Returns TransportAdapterError::AnswerApplicationFailed when str0m
rejects the answer after consuming the offer token. The caller must close
the session because its transport state cannot be restored for a retry.
pub async fn publish_media(
&self,
session_key: &TransportSessionKey,
media_kind: MediaKind,
rtp_parameters: &MediaStream,
) -> Result<TransportMediaId, TransportAdapterError>
pub async fn publish_media( &self, session_key: &TransportSessionKey, media_kind: MediaKind, rtp_parameters: &MediaStream, ) -> Result<TransportMediaId, TransportAdapterError>
Declares a new producer on a transport session.
rtp_parameters must come from router media state accepted by the core.
The returned TransportMediaId addresses the backend-local producer
for later route, activity and cleanup operations. On a negotiated
session the producer waits for the next offer, whose upload slot names
its MID.
§Errors
Returns TransportAdapterError when the session cannot be addressed,
the RTP parameters are invalid or the active backend cannot create the
producer.
pub async fn consume_media(
&self,
consumer_session_key: &TransportSessionKey,
media_kind: MediaKind,
source: &TransportSourceKey,
sync: SourceSyncPolicy,
consumer_rtp_parameters: &MediaStream,
initial_activity: ConsumerActivity,
) -> Result<TransportMediaId, TransportAdapterError>
pub async fn consume_media( &self, consumer_session_key: &TransportSessionKey, media_kind: MediaKind, source: &TransportSourceKey, sync: SourceSyncPolicy, consumer_rtp_parameters: &MediaStream, initial_activity: ConsumerActivity, ) -> Result<TransportMediaId, TransportAdapterError>
Declares consumer media on a transport session.
A negotiated session queues the media and names its MID in
[SessionOffer::consumer_mids] of the first offer created after the
caller lists the consumer as committed.
§Errors
Returns TransportAdapterError when either session is unavailable,
the source is unknown or the worker cannot create the consumer.
pub fn source_policy_subscription(&self) -> SourcePolicyUpdateSubscription
pub fn source_policy_subscription(&self) -> SourcePolicyUpdateSubscription
Subscribes to source-policy invalidation signals emitted by transport workers.
Trait Implementations§
§impl Clone for MediaTransport
impl Clone for MediaTransport
§fn clone(&self) -> MediaTransport
fn clone(&self) -> MediaTransport
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for MediaTransport
impl Debug for MediaTransport
§impl Execute<&MediaTransport> for TransportTeardownAction
impl Execute<&MediaTransport> for TransportTeardownAction
Auto Trait Implementations§
impl Freeze for MediaTransport
impl !RefUnwindSafe for MediaTransport
impl Send for MediaTransport
impl Sync for MediaTransport
impl Unpin for MediaTransport
impl UnsafeUnpin for MediaTransport
impl !UnwindSafe for MediaTransport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more