Skip to main content

RoomTopology

Struct RoomTopology 

Source
pub struct RoomTopology {
    instance: RoomInstanceId,
    sources: PublishedSources,
    route_graph: RouteGraph,
    router: Router,
    next_producer_id: u64,
}
Expand description

Keeps source records and route realization beside Router so transport effects resolve from the same committed placement.

Transport-facing mutations return resolved work for execution after the room state lock is released.

Fields§

§instance: RoomInstanceId§sources: PublishedSources§route_graph: RouteGraph§router: Router§next_producer_id: u64

Implementations§

Source§

impl RoomTopology

Source

pub fn new( runtime_context: &RoomRuntimeContext, router_rtp_capabilities: MediaCapabilities, ) -> Self

Source

pub(in engine::room) fn router( &self, ) -> &Router

Source

pub fn committed_transport_user_key( &self, user_id: impl Into<Arc<UserId>>, connection_id: ConnectionId, ) -> Option<TransportSessionKey>

Returns None unless the exact user connection remains committed.

Source

pub fn transport_user_key( &self, user_id: impl Into<Arc<UserId>>, connection_id: ConnectionId, ) -> TransportSessionKey

Requires the exact user connection to remain committed.

Use Self::committed_transport_user_key for stale callbacks or teardown races where the placement may already be retired.

§Lookup choice

Receiver work may carry a stale connection while relay effects from committed graph state use the strict lookup:

let Some(consumer_session) =
    topology.committed_transport_user_key(user_id.clone(), connection_id)
else {
    return Vec::new();
};

let source_session =
    topology.transport_user_key(route.source_user, route.source_connection);
§Panics

Panics when no committed router placement exists.

Source

fn transport_session_key( &self, user_id: Arc<UserId>, connection_id: ConnectionId, media_worker_id: MediaWorkerId, ) -> TransportSessionKey

Source

pub fn retire_committed_placement( &mut self, user_id: &UserId, connection_id: ConnectionId, ) -> Option<TransportSessionKey>

Returns None when connection_id is not the user’s committed placement.

Source

pub fn media_counts(&self) -> RoomMediaCounts

Counts each logical subscription once while pending or committed.

Source

pub(in engine::room) fn source_descriptor( &self, source_id: PublishedSourceId, ) -> Option<&PublishedSourceDescriptor>

Source

pub(in engine::room) fn source_for_transport_media( &self, transport_media_id: TransportMediaId, ) -> Option<&PublishedSource>

Source

pub(in engine::room) fn source_id_for_owner_stream( &self, owner_user_id: &UserId, stream_id: &UserStreamId, ) -> Option<PublishedSourceId>

Source

pub(in engine::room) fn published_source_id( &self, owner: &UserId, connection: ConnectionId, stream_id: &UserStreamId, ) -> Option<PublishedSourceId>

Returns the source ID only when owner, connection and stream remain current.

Source

pub(in engine::room) fn published_sources( &self, ) -> impl Iterator<Item = &PublishedSource>

Iterates committed sources in source-ID order.

Source

pub(in engine::room) fn active_stream_user_counts( &self, ) -> BTreeMap<UserStreamId, u64>

Counts distinct users with active publications for each logical stream.

Source

pub(in engine::room) fn active_speaker_detector_owner( &self, transport_media_id: TransportMediaId, ) -> Option<UserId>

Returns a detector owner with an active promotable source in the same group.

Source

pub(in engine::room) fn committed_consumer_routes( &self, ) -> impl Iterator<Item = ConsumerRouteView<'_>>

Source

pub(in engine::room) fn committed_consumer_routes_for_user( &self, user_id: &UserId, ) -> impl Iterator<Item = ConsumerRouteView<'_>>

Source

pub(super) fn detach_declined_consumers( &mut self, session: &TransportSessionKey, declined: &[TransportMediaId], ) -> (Vec<TransportRelayRouteEffect>, Vec<TransportTeardown>, bool)

Source

pub(in engine::room) fn pending_consumer_routes_for_user( &self, user_id: &UserId, ) -> impl Iterator<Item = PendingConsumerRouteView<'_>>

Source

pub(in engine::room) fn consumer_source_selection( &self, key: &SubscriptionKey, source_id: PublishedSourceId, ) -> Option<ConsumerSourceSelection>

Returns None when the attached source differs from source_id.

Source

pub(in engine::room) fn merge_subscription_intent( &mut self, key: SubscriptionKey, intent: SourceSubscriptionIntent, )

Ignores empty updates and applies active to an attached selection.

Source

pub(in engine::room) fn subscription_intent( &self, key: &SubscriptionKey, ) -> SourceSubscriptionIntent

Returns merged receiver intent or the default for a missing subscription.

Source

pub(in engine::room) fn committed_consumer_user_ids_for_source( &self, source_id: PublishedSourceId, ) -> BTreeSet<UserId>

Source

pub(in engine::room) fn committed_consumer_user_ids_for_owner_sources( &self, user_id: &UserId, ) -> BTreeSet<UserId>

Source

pub(in engine::room) fn committed_consumer_route_for_key( &self, key: &SubscriptionKey, ) -> Option<ConsumerRouteView<'_>>

Source

pub(in engine::room) fn published_source( &self, source_id: PublishedSourceId, ) -> Option<&PublishedSource>

Source

pub(super) fn missing_consumer_targets_for_source<'a>( &mut self, source_id: PublishedSourceId, receivers: impl IntoIterator<Item = (&'a UserId, ConnectionId)>, ) -> Vec<ConsumerSetupTarget>

Attaches source_id to each eligible receiver lacking a route realization.

Source

fn consumer_target( &mut self, user_id: &UserId, connection_id: ConnectionId, source_id: PublishedSourceId, ) -> Option<ConsumerSetupTarget>

Source

fn attach_consumer_target( route_graph: &mut RouteGraph, consumer_session: &TransportSessionKey, source: &PublishedSource, ) -> Option<ConsumerSetupTarget>

Skips self-consumption and attaches only an absent realization.

Source

pub(super) fn missing_consumer_targets( &mut self, user_id: &UserId, connection_id: ConnectionId, include_source: impl Fn(&PublishedSource) -> bool, ) -> Vec<ConsumerSetupTarget>

Attaches each matching source with no realization to the exact committed receiver.

Returns an empty list when connection_id is stale.

Source

pub fn update_consumer_source_selection( &mut self, key: &SubscriptionKey, source_id: PublishedSourceId, route: &TransportConsumerRoute, update: impl FnOnce(&mut ConsumerSourceSelection), ) -> bool

Updates selection while subscription, source and exact route still match.

Returns false when async transport work refers to a displaced route.

Source

fn detach_user_sources( &mut self, user_id: &UserId, ) -> (Vec<TransportSourceKey>, RemovedRoutes)

Source

fn remove_source( &mut self, source_id: PublishedSourceId, ) -> Option<(PublishedSource, RemovedRoutes)>

Source

fn consumer_route<'a>( &'a self, key: &'a SubscriptionKey, current: &'a CurrentPublication, ) -> Option<ConsumerRouteView<'a>>

Source

pub(in engine::room) fn commit_publication( &mut self, publish: ValidatedPublish, rtp: RouterRtpParameters, encodings: &[SessionUploadEncoding], media: TransportMediaId, ) -> Result<PublishedSourceId, PublicationCommitError>

Commits a negotiated source only after its router producer succeeds.

§Errors

Returns PublicationCommitError::Source when descriptor allocation or validation fails. Returns PublicationCommitError::Router when the router rejects the producer dependency.

Source

fn media_teardowns( sources: impl IntoIterator<Item = TransportSourceKey>, routes: impl IntoIterator<Item = TransportConsumerRoute>, ) -> impl Iterator<Item = TransportTeardown>

Source

fn resolve_relay_effects( &self, effects: impl IntoIterator<Item = RelayRouteEffect>, ) -> Vec<TransportRelayRouteEffect>

§Panics

Panics if effects violates the topology invariant that every relay source has a committed router placement.

Source

fn resolve_relay_effects_with_displaced( &self, effects: impl IntoIterator<Item = RelayRouteEffect>, user_id: &UserId, session_key: &TransportSessionKey, ) -> Vec<TransportRelayRouteEffect>

Resolves relay effects while retaining a displaced source’s transport key.

§Panics

Panics if any non-displaced relay source lacks a committed placement.

Source

pub fn set_published_source_activity( &mut self, source_id: PublishedSourceId, connection_id: ConnectionId, active: bool, ) -> Option<SourceActivityRevision>

Advances the revision only when the exact source connection changes activity.

Returns None when the source is missing, the connection is stale or the requested activity already matches.

Source

pub(super) fn source_activity_effects( &self, source: &TransportSourceKey, update: SourceActivityUpdate, ) -> Vec<TransportSourceActivityEffect>

Source

pub fn commit_session_placement( &mut self, user_id: &UserId, connection_id: ConnectionId, previous_connection: Option<ConnectionId>, home_placement: RouterPlacement, ) -> Result<SessionPlacementCommit, SessionPlacementRejection>

Commits the new placement before returning cleanup for previous_connection.

Replacement joins must pass the currently committed previous_connection.

§Errors

Returns SessionPlacementRejection::MissingPreviousSession when the expected replacement target is no longer committed. Returns SessionPlacementRejection::Router when the router rejects the new connection or placement.

§Panics

Panics when existing relay state refers to another uncommitted source placement.

Source

pub fn remove_session(&mut self, user_id: &UserId) -> RoomTransportPlan

Returns the cleanup plan even if router removal fails.

§Panics

Panics when detached relay state refers to an uncommitted source placement.

Source

pub(super) fn commit_consumer_setup( &mut self, setup: DeclaredConsumerSetup, selection: ConsumerSourceSelection, ) -> Result<CommittedConsumerSetup, (TransportConsumerRoute, Vec<TransportRelayRouteEffect>)>

Selects MID from the transport declaration, negotiated RTP MID then the consumer identity.

§Errors

Returns the declared route and relay release effects when the reservation is stale or the router rejects the consumer dependency.

Source

pub(super) fn reserve_consumer_setup( &mut self, target: ConsumerSetupTarget, consumer: ConsumerId, selection: ConsumerSourceSelection, sender: UserOutboundSender, rtp: RouterRtpParameters, ) -> Option<PendingConsumerSetup>

Returns None unless the route realization remains absent.

A cross-worker reservation also claims relay ownership.

Source

pub(super) fn release_consumer_setup( &mut self, setup: PendingConsumerSetup, ) -> Vec<TransportRelayRouteEffect>

A stale reservation releases no relay ownership.

Source

pub(super) fn set_consumer_activity( &mut self, user_id: &UserId, connection_id: ConnectionId, target_user_id: &UserId, stream_id: &UserStreamId, active: bool, receiver_deafened: bool, ) -> Option<ConsumerActivityCommit>

Returns None when the source is missing, its attachment changed or the committed consumer belongs to another receiver connection.

Trait Implementations§

Source§

impl Debug for RoomTopology

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> 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, 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<T> CryptoSafe for T

§

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

§

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