rtmp_rs/registry/config.rs
1//! Registry configuration
2//!
3//! Configuration for the stream registry including broadcast capacity,
4//! grace periods, and buffer sizes.
5
6use std::time::Duration;
7
8/// Configuration for the stream registry
9#[derive(Debug, Clone)]
10pub struct RegistryConfig {
11 /// Capacity of the broadcast channel per stream
12 ///
13 /// At 30fps, 128 frames is about 4 seconds of video buffer.
14 /// If subscribers fall behind more than this, they'll receive a Lagged error.
15 pub broadcast_capacity: usize,
16
17 /// Grace period to keep stream alive after publisher disconnects
18 ///
19 /// If the publisher reconnects within this period, subscribers continue
20 /// without interruption. This handles brief network hiccups.
21 pub publisher_grace_period: Duration,
22
23 /// Timeout for idle streams with no publisher and no subscribers
24 pub idle_stream_timeout: Duration,
25
26 /// Maximum GOP buffer size in bytes per stream
27 pub max_gop_size: usize,
28
29 /// Interval for running cleanup tasks
30 pub cleanup_interval: Duration,
31
32 /// Number of lag events before disconnecting a slow subscriber
33 pub max_consecutive_lag_events: u32,
34
35 /// Lag threshold (frames) below which we continue normally
36 pub lag_threshold_low: u64,
37}
38
39impl Default for RegistryConfig {
40 fn default() -> Self {
41 Self {
42 broadcast_capacity: 128, // ~4 seconds @ 30fps
43 publisher_grace_period: Duration::from_secs(10),
44 idle_stream_timeout: Duration::from_secs(30),
45 max_gop_size: 4 * 1024 * 1024, // 4MB
46 cleanup_interval: Duration::from_secs(5),
47 max_consecutive_lag_events: 10,
48 lag_threshold_low: 30, // ~1 second @ 30fps
49 }
50 }
51}
52
53impl RegistryConfig {
54 /// Create a new registry config with default values
55 pub fn new() -> Self {
56 Self::default()
57 }
58
59 /// Set the broadcast channel capacity
60 pub fn broadcast_capacity(mut self, capacity: usize) -> Self {
61 self.broadcast_capacity = capacity;
62 self
63 }
64
65 /// Set the publisher grace period
66 pub fn publisher_grace_period(mut self, duration: Duration) -> Self {
67 self.publisher_grace_period = duration;
68 self
69 }
70
71 /// Set the idle stream timeout
72 pub fn idle_stream_timeout(mut self, duration: Duration) -> Self {
73 self.idle_stream_timeout = duration;
74 self
75 }
76
77 /// Set the maximum GOP buffer size
78 pub fn max_gop_size(mut self, size: usize) -> Self {
79 self.max_gop_size = size;
80 self
81 }
82}