Skip to main content

MediaTransport

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

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

pub fn schedule_source_policy_retry(&self, room: RoomInstanceId)

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

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

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

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

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>

Returns sampled transport-quality observations for the requested sessions.

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>

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>

Returns transport pressure for every media worker.

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>

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>

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>

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>

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

pub fn cancel(&self)

Cancels every RTC worker without waiting for termination.

pub async fn shutdown(&self)

Cancels every RTC worker and waits for its thread to terminate.

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>

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>

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>

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>

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>

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

Subscribes to source-policy invalidation signals emitted by transport workers.

Trait Implementations§

§

impl Clone for MediaTransport

§

fn clone(&self) -> MediaTransport

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for MediaTransport

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Execute<&MediaTransport> for TransportTeardownAction

§

type Output = ()

§

async fn execute(self, transport: &MediaTransport)

Must finish the work or handle its failure, including fallback, before returning.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> CryptoSafe for T
where T: Send + Sync + Debug,

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,