pub struct RoomTopology {
instance: RoomInstanceId,
sources: PublishedSources,
route_graph: RouteGraph,
router: Router,
video_allocation_revision: u64,
}Expand description
Keeps source records and route realization beside Router so transport
effects resolve from the same committed placement.
Only RoomTopology mutates router, sources and route_graph, so it
alone decides which changes advance the video allocation revision and
keeps routes attached to current sources and placements. Readers borrow
them through Self::router, Self::sources and Self::route_graph.
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§video_allocation_revision: u64Implementations§
Source§impl RoomTopology
impl RoomTopology
pub fn new( runtime_context: &RoomRuntimeContext, router_rtp_capabilities: MediaCapabilities, pending_target_limit: usize, ) -> Self
pub(in engine) const fn video_allocation_revision( &self, ) -> u64
fn invalidate_video_allocation(&mut self)
pub(in engine::room) fn router( &self, ) -> &Router
pub(in engine) fn sources( &self, ) -> &PublishedSources
pub(in engine) fn route_graph( &self, ) -> &RouteGraph
Sourcepub fn committed_transport_user_key(
&self,
user_id: impl Into<Arc<UserId>>,
connection_id: ConnectionId,
) -> Option<TransportSessionKey>
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.
Sourcepub fn transport_user_key(
&self,
user_id: impl Into<Arc<UserId>>,
connection_id: ConnectionId,
) -> TransportSessionKey
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.
§Panics
Panics when no committed router placement exists.
fn transport_session_key( &self, user_id: Arc<UserId>, connection_id: ConnectionId, media_worker_id: MediaWorkerId, ) -> TransportSessionKey
Sourcepub fn retire_committed_placement(
&mut self,
user_id: &UserId,
connection_id: ConnectionId,
) -> Option<TransportSessionKey>
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.
Sourcepub fn media_counts(&self) -> RoomMediaCounts
pub fn media_counts(&self) -> RoomMediaCounts
Counts each logical subscription once while pending or committed.
Sourcepub(in engine::room) fn published_source_id(
&self,
owner: &UserId,
connection: ConnectionId,
stream_id: &UserStreamId,
) -> Option<PublishedSourceId>
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.
Sourcepub(in engine::room) fn active_stream_user_counts(
&self,
) -> BTreeMap<UserStreamId, u64>
pub(in engine::room) fn active_stream_user_counts( &self, ) -> BTreeMap<UserStreamId, u64>
Counts distinct users with active publications for each logical stream.
Sourcepub(in engine) fn active_speaker_detector_owner(
&self,
transport_media_id: TransportMediaId,
) -> Option<UserId>
pub(in engine) 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.
pub(in engine::room) fn committed_consumer_routes( &self, ) -> impl Iterator<Item = ConsumerRouteView<'_>>
pub(in engine) fn committed_consumer_routes_for_user( &self, user_id: &UserId, ) -> impl Iterator<Item = ConsumerRouteView<'_>>
pub(super) fn detach_declined_consumers( &mut self, session: &TransportSessionKey, declined: &[TransportMediaId], ) -> (Vec<TransportTeardown>, bool)
pub(in engine::room) fn pending_consumer_routes_for_user( &self, user_id: &UserId, ) -> impl Iterator<Item = PendingConsumerRouteView<'_>>
pub(in engine::room) fn committed_consumer_user_ids_for_source( &self, source_id: PublishedSourceId, ) -> BTreeSet<UserId>
pub(in engine::room) fn committed_consumer_user_ids_for_owner_sources( &self, user_id: &UserId, ) -> BTreeSet<UserId>
pub(in engine) fn committed_consumer_route_for_key( &self, key: &SubscriptionKey, ) -> Option<ConsumerRouteView<'_>>
Sourcepub(super) fn missing_consumer_targets_for_source<'a>(
&mut self,
source_id: PublishedSourceId,
receivers: impl IntoIterator<Item = (&'a UserId, ConnectionId)>,
) -> Vec<ConsumerSetupTarget>
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.
fn consumer_target( &mut self, user_id: &UserId, connection_id: ConnectionId, source_id: PublishedSourceId, ) -> Option<ConsumerSetupTarget>
Sourcefn attach_consumer_target(
route_graph: &mut RouteGraph,
consumer_session: &TransportSessionKey,
source: &PublishedSource,
) -> Option<ConsumerSetupTarget>
fn attach_consumer_target( route_graph: &mut RouteGraph, consumer_session: &TransportSessionKey, source: &PublishedSource, ) -> Option<ConsumerSetupTarget>
Skips self-consumption and attaches only an absent realization.
Sourcepub(super) fn missing_consumer_targets(
&mut self,
user_id: &UserId,
connection_id: ConnectionId,
include_source: impl Fn(&PublishedSource) -> bool,
) -> Vec<ConsumerSetupTarget>
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.
Sourcepub(in engine) fn update_consumer_allocation(
&mut self,
key: &SubscriptionKey,
source_id: PublishedSourceId,
route: &TransportConsumerRoute,
update: impl FnOnce(&mut RouteAllocation),
) -> bool
pub(in engine) fn update_consumer_allocation( &mut self, key: &SubscriptionKey, source_id: PublishedSourceId, route: &TransportConsumerRoute, update: impl FnOnce(&mut RouteAllocation), ) -> bool
Updates the allocation while subscription, source and exact route still match.
Returns false when async transport work refers to a displaced route.
Sourcepub(in engine) fn update_consumer_upgrade(
&mut self,
key: &SubscriptionKey,
source_id: PublishedSourceId,
route: &TransportConsumerRoute,
pending_upgrade: Option<PendingUpgrade>,
) -> bool
pub(in engine) fn update_consumer_upgrade( &mut self, key: &SubscriptionKey, source_id: PublishedSourceId, route: &TransportConsumerRoute, pending_upgrade: Option<PendingUpgrade>, ) -> bool
Commits a hold only for the active source, subscription and exact route.
fn detach_user_sources( &mut self, user_id: &UserId, ) -> (Vec<TransportSourceKey>, Vec<TransportConsumerRoute>)
fn remove_source( &mut self, source_id: PublishedSourceId, ) -> Option<(PublishedSource, Vec<TransportConsumerRoute>)>
fn consumer_route<'a>( &'a self, (key, intent, current): (&'a SubscriptionKey, SourceSubscriptionIntent, &'a CurrentPublication), ) -> Option<ConsumerRouteView<'a>>
Sourcepub(in engine::room) fn commit_publication(
&mut self,
publish: ValidatedPublish,
rtp: RouterRtpParameters,
encodings: &[SessionUploadEncoding],
media: TransportMediaId,
) -> Result<PublishedSourceId, SourceModelError>
pub(in engine::room) fn commit_publication( &mut self, publish: ValidatedPublish, rtp: RouterRtpParameters, encodings: &[SessionUploadEncoding], media: TransportMediaId, ) -> Result<PublishedSourceId, SourceModelError>
§Errors
Returns SourceModelError when descriptor allocation or validation fails.
fn media_teardowns( sources: impl IntoIterator<Item = TransportSourceKey>, routes: impl IntoIterator<Item = TransportConsumerRoute>, ) -> impl Iterator<Item = TransportTeardown>
Sourcepub fn set_published_source_activity(
&mut self,
source_id: PublishedSourceId,
connection_id: ConnectionId,
active: bool,
) -> Option<SourceActivityRevision>
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.
Sourcepub fn commit_session_placement(
&mut self,
user_id: &UserId,
connection_id: ConnectionId,
previous_connection: Option<ConnectionId>,
home_placement: RouterPlacement,
) -> Result<SessionPlacementCommit, SessionPlacementRejection>
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.
Sourcepub fn remove_session(&mut self, user_id: &UserId) -> (RoomTransportPlan, usize)
pub fn remove_session(&mut self, user_id: &UserId) -> (RoomTransportPlan, usize)
Returns the cleanup plan even if router removal fails.
Sourcepub(super) fn commit_consumer_setup(
&mut self,
setup: DeclaredConsumerSetup,
allocation: RouteAllocation,
) -> Result<CommittedConsumerSetup, TransportConsumerRoute>
pub(super) fn commit_consumer_setup( &mut self, setup: DeclaredConsumerSetup, allocation: RouteAllocation, ) -> Result<CommittedConsumerSetup, TransportConsumerRoute>
§Errors
Returns the declared route when the reservation is stale.
Sourcepub(super) fn reserve_consumer_setup(
&mut self,
target: ConsumerSetupTarget,
allocation: RouteAllocation,
sender: UserOutboundSender,
rtp: RouterRtpParameters,
) -> Option<PendingConsumerSetup>
pub(super) fn reserve_consumer_setup( &mut self, target: ConsumerSetupTarget, allocation: RouteAllocation, sender: UserOutboundSender, rtp: RouterRtpParameters, ) -> Option<PendingConsumerSetup>
Returns None unless the route realization remains absent.
pub(super) fn release_consumer_setup(&mut self, setup: &PendingConsumerSetup)
Sourcepub(in engine::room) fn apply_subscription_intent(
&mut self,
key: &SubscriptionKey,
connection_id: ConnectionId,
intent: SourceSubscriptionIntent,
receiver_deafened: bool,
publisher_present: bool,
) -> ConsumerActivityCommit
pub(in engine::room) fn apply_subscription_intent( &mut self, key: &SubscriptionKey, connection_id: ConnectionId, intent: SourceSubscriptionIntent, receiver_deafened: bool, publisher_present: bool, ) -> ConsumerActivityCommit
Merges sparse intent before projecting activity to an attached route.
Empty updates have no effect. Intent survives absent publications and unready receivers. Returns no activity work for layout-only updates, missing sources, changed attachments or displaced consumer connections.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RoomTopology
impl RefUnwindSafe for RoomTopology
impl Send for RoomTopology
impl Sync for RoomTopology
impl Unpin for RoomTopology
impl UnsafeUnpin for RoomTopology
impl UnwindSafe for RoomTopology
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
§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