Skip to main content

MediaTransport

Struct MediaTransport 

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

Implementations§

Source§

impl MediaTransport

Source

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 or a worker cannot start

Source§

impl MediaTransport

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], ) -> BTreeMap<TransportSessionKey, TransportQualitySample>

Returns sampled transport-quality observations for the requested sessions.

Source

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

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

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

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: &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.

§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: &MediaStream, 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 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<(), Error>

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> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

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,