Skip to main content

MediaTransport

Struct MediaTransport 

Source
pub struct MediaTransport {
    workers: Arc<[RtcWorker]>,
    profile: Arc<RtpProfile>,
    metrics: Arc<RuntimeMetrics>,
    source_policy_signal: SourcePolicySignal,
}
Expand description

Opaque runtime media transport handle.

MediaTransport is the handle server code and crate::prelude::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

Coalesces transport observations for room policy.

Implementations§

Source§

impl MediaTransport

Source

pub fn build( config: MediaTransportConfig, deps: MediaTransportDeps, ) -> Result<Self, 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 or a worker cannot start

Source§

impl MediaTransport

Source

pub(in engine) fn schedule_source_policy_follow_up( &self, room: RoomInstanceId, )

Schedules another policy pass when adaptation hysteresis remains unresolved.

Source§

impl MediaTransport

Source

async fn execute_batch( &self, worker_index: usize, batch: WorkerBatch, ) -> TransportResult<WorkerBatchOutcome>

Source

pub(crate) 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.

Source§

impl MediaTransport

Source

pub(crate) async fn teardown( &self, teardowns: impl IntoIterator<Item = TransportTeardown>, )

Runs teardown idempotently and continues after terminal failures.

Each failed media or relay item escalates once to its session because partial worker state may remain. Errors are consumed so one failure cannot suppress later cleanup.

Source

async fn close_session( &self, session_key: &TransportSessionKey, ) -> Result<(), TransportAdapterError>

Source

pub(super) async fn remove_media( &self, session_key: &TransportSessionKey, transport_media_id: TransportMediaId, ) -> Result<(), TransportAdapterError>

Source

async fn release_relay_route( &self, source: &TransportSourceKey, target_media_worker_id: MediaWorkerId, ) -> Result<(), TransportAdapterError>

Source§

impl MediaTransport

Source

pub(super) fn worker_for_user( &self, session_key: &TransportSessionKey, ) -> Option<&RtcWorker>

Selects the worker that owns a transport session.

The mapping is deterministic and depends only on the runtime-assigned media-worker id in the session key. Room and signaling code must not infer topology from user identity.

Source

pub(super) fn relay_registration_workers( &self, consumer_session_key: &TransportSessionKey, source_session_key: &TransportSessionKey, ) -> Result<Option<(&'_ RtcWorker, &'_ RtcWorker)>, TransportAdapterError>

Returns the source and consumer workers needed for cross-worker relay.

None means both sessions are on the same worker and local routing is enough. A returned pair means the source worker must activate relay forwarding toward the consumer worker before the consumer route can be fully installed.

Source

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.

Source

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.

Source

pub fn transport_quality_snapshot( &self, session_keys: &[TransportSessionKey], ) -> TransportQualitySnapshot

Returns sampled transport-quality observations for the requested sessions.

Source

pub fn transport_health_snapshot( &self, session_keys: &[TransportSessionKey], ) -> TransportHealthSnapshot

Returns transport health for the requested sessions with one lock per worker.

Missing sessions and unavailable worker snapshots contribute no facts

Source

pub async fn source_diagnostics_snapshot( &self, sources: &[TransportSourceKey], ) -> TransportSourceDiagnosticsSnapshot

Returns source activity and active-speaker facts with one command per worker.

Missing sources and worker dispatch failures contribute no facts

Source

pub fn worker_pressure_snapshots(&self) -> Vec<TransportWorkerPressureSnapshot>

Returns transport pressure for every media worker.

Source

pub(crate) fn packet_loop_delays_ms(&self) -> Vec<Option<u64>>

Source

pub async fn active_speaker_source_snapshot(&self) -> Vec<ActiveSpeakerSource>

Returns each media source’s newest active-speaker observation in recency order, preferring its strongest audio level on timestamp ties.

Source

pub(super) async fn execute_relay_route_effect( &self, effect: &TransportRelayRouteEffect, ) -> Result<(), TransportAdapterError>

Applies one cross-worker relay mutation on the source worker.

The target worker contributes its relay identity and mailbox. The source packet loop owns registration and activity because it decides fanout before packets cross workers.

Source

pub(super) async fn execute_remote_source_activity_effect( &self, effect: &TransportSourceActivityEffect, ) -> Result<(), TransportAdapterError>

Source

pub(crate) async fn transport_media_mid( &self, session_key: &TransportSessionKey, transport_media_id: TransportMediaId, ) -> Option<String>

Returns the MID stored by the current transport media handle.

None means session_key selects no worker, the worker request failed or transport_media_id has no registered handle.

Source

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.

Source

fn worker_index_for_user( &self, session_key: &TransportSessionKey, ) -> Option<usize>

Source

pub(super) fn require_worker_for_user( &self, session_key: &TransportSessionKey, ) -> Result<&RtcWorker, TransportAdapterError>

Source

pub(super) fn require_worker_for_media_worker_id( &self, media_worker_id: MediaWorkerId, ) -> Result<&RtcWorker, TransportAdapterError>

Source

fn session_keys_by_worker( &self, session_keys: &[TransportSessionKey], ) -> BTreeMap<usize, Vec<TransportSessionKey>>

Source

fn for_session_workers( &self, session_keys: &[TransportSessionKey], visit: impl FnMut(&RtcWorker, &[TransportSessionKey]), )

Source

pub(super) fn ensure_same_room( consumer_session_key: &TransportSessionKey, source_session_key: &TransportSessionKey, ) -> Result<(), TransportAdapterError>

Enforces room isolation before worker or media lookup.

MediaWorkerId selects execution ownership only. It never authorizes a route between room instances.

Source

pub(super) fn worker_for_index(&self, worker_index: usize) -> Option<&RtcWorker>

Source§

impl MediaTransport

Source

pub fn cancel(&self)

Cancels every RTC worker without waiting for termination.

Source

pub async fn shutdown(&self)

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

Source

pub fn router_rtp_capabilities(&self) -> MediaCapabilities

returns the router capability snapshot compiled from the RTC wire profile

Source

async fn request_session_command<T>( &self, session_key: &TransportSessionKey, build: impl FnOnce(Sender<TransportResult<T>>) -> RtcWorkerCommand, log_error: impl FnOnce(TransportAdapterError), ) -> Result<T, TransportAdapterError>

Source

pub async fn create_initial_session_offer( &self, room_id: &str, session_key: &TransportSessionKey, ) -> 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.

§Errors

Returns TransportAdapterError when the session cannot be addressed or the active backend cannot create the offer.

Source

pub async fn create_session_renegotiation_offer( &self, session_key: &TransportSessionKey, ) -> Result<SessionOffer, TransportAdapterError>

Creates a new SDP offer after transport media state changed.

Backends reject sessions that cannot renegotiate in their current state. Callers should treat the returned offer as replacing any older pending transport offer for the same session.

§Errors

Returns TransportAdapterError when the session cannot be addressed or the active backend cannot create a renegotiation offer.

Source

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 when the session cannot be addressed, the answer is invalid or the active backend cannot apply it.

Source

pub async fn publish_media( &self, session_key: &TransportSessionKey, media_kind: MediaKind, rtp_parameters: &RouterRtpParameters, ) -> 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.

§Errors

Returns TransportAdapterError when the session cannot be addressed, the RTP parameters are invalid or the active backend cannot create the producer.

Source

pub async fn consume_media( &self, consumer_session_key: &TransportSessionKey, media_kind: MediaKind, source_session_key: &TransportSessionKey, source_media_id: TransportMediaId, consumer_rtp_parameters: &RouterRtpParameters, initial_activity: ConsumerActivity, ) -> Result<TransportMediaId, TransportAdapterError>

Declares a new consumer route from a source session to a consumer session.

The source and consumer sessions must belong to the same room instance. Cross-worker routing is an implementation detail hidden behind this method. The initial activity controls whether the packet loop can forward packets before later room policy updates arrive.

§Errors

Returns TransportAdapterError when either session cannot be addressed, the source media id is unknown or the active backend cannot create the consumer.

Source

pub(crate) async fn apply_relay_route_effect( &self, effect: &TransportRelayRouteEffect, ) -> Result<(), TransportAdapterError>

Applies a room relay route mutation.

The transport may install, release or gate the packet-loop relay target. Room state remains the lifecycle owner.

§Errors

Returns TransportAdapterError when the referenced route cannot be addressed or the active backend cannot apply the relay mutation.

Source

pub(crate) async fn apply_remote_source_activity_effect( &self, effect: &TransportSourceActivityEffect, ) -> Result<(), TransportAdapterError>

Applies one activity revision to a remote source.

§Errors

Returns TransportAdapterError when the target worker is unavailable or rejects the update.

Source

pub fn source_policy_subscription(&self) -> SourcePolicyUpdateSubscription

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

Trait Implementations§

Source§

impl Clone for MediaTransport

Source§

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

impl Debug for MediaTransport

Source§

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

Formats the value using the given formatter. Read more

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,