pub struct StreamRegistry { /* private fields */ }Expand description
Central registry for all active streams
Thread-safe via RwLock. Read-heavy workloads (subscriber count checks,
broadcasting) benefit from the concurrent read access.
Implementations§
Source§impl StreamRegistry
impl StreamRegistry
Sourcepub fn with_config(config: RegistryConfig) -> Self
pub fn with_config(config: RegistryConfig) -> Self
Create a new stream registry with custom configuration
Sourcepub fn config(&self) -> &RegistryConfig
pub fn config(&self) -> &RegistryConfig
Get the registry configuration
Sourcepub async fn register_publisher(
&self,
key: &StreamKey,
session_id: u64,
) -> Result<(), RegistryError>
pub async fn register_publisher( &self, key: &StreamKey, session_id: u64, ) -> Result<(), RegistryError>
Register a publisher for a stream
If the stream doesn’t exist, it will be created. If the stream exists and is in grace period, the publisher reclaims it. Returns an error if the stream already has an active publisher.
Sourcepub async fn unregister_publisher(&self, key: &StreamKey, session_id: u64)
pub async fn unregister_publisher(&self, key: &StreamKey, session_id: u64)
Unregister a publisher from a stream
The stream enters grace period if there are active subscribers, allowing the publisher to reconnect.
Sourcepub async fn subscribe(
&self,
key: &StreamKey,
) -> Result<(Receiver<BroadcastFrame>, Vec<BroadcastFrame>), RegistryError>
pub async fn subscribe( &self, key: &StreamKey, ) -> Result<(Receiver<BroadcastFrame>, Vec<BroadcastFrame>), RegistryError>
Subscribe to a stream
Returns a broadcast receiver and catchup frames for the subscriber. The catchup frames contain sequence headers and recent GOP data.
Sourcepub async fn unsubscribe(&self, key: &StreamKey)
pub async fn unsubscribe(&self, key: &StreamKey)
Unsubscribe from a stream
Sourcepub async fn broadcast(&self, key: &StreamKey, frame: BroadcastFrame)
pub async fn broadcast(&self, key: &StreamKey, frame: BroadcastFrame)
Broadcast a frame to all subscribers of a stream
Also updates the GOP buffer and sequence headers as needed.
Sourcepub async fn get_sequence_headers(&self, key: &StreamKey) -> Vec<BroadcastFrame>
pub async fn get_sequence_headers(&self, key: &StreamKey) -> Vec<BroadcastFrame>
Get sequence headers for a stream (video and audio decoder config)
Used when resuming playback after pause to reinitialize decoders.
Sourcepub async fn has_active_stream(&self, key: &StreamKey) -> bool
pub async fn has_active_stream(&self, key: &StreamKey) -> bool
Check if a stream exists and has an active publisher
Sourcepub async fn stream_exists(&self, key: &StreamKey) -> bool
pub async fn stream_exists(&self, key: &StreamKey) -> bool
Check if a stream exists (active or in grace period)
Sourcepub async fn get_stream_stats(&self, key: &StreamKey) -> Option<StreamStats>
pub async fn get_stream_stats(&self, key: &StreamKey) -> Option<StreamStats>
Get stream statistics
Sourcepub async fn stream_count(&self) -> usize
pub async fn stream_count(&self) -> usize
Get total number of streams
Sourcepub async fn cleanup(&self)
pub async fn cleanup(&self)
Run cleanup task once
Removes streams that have:
- Been in grace period longer than
publisher_grace_period - Been idle longer than
idle_stream_timeout
Sourcepub fn spawn_cleanup_task(self: &Arc<Self>) -> JoinHandle<()>
pub fn spawn_cleanup_task(self: &Arc<Self>) -> JoinHandle<()>
Spawn background cleanup task
Returns a handle that can be used to abort the task.