Skip to main content

o_sfu_core/engine/media_transport/
config.rs

1//! Construction inputs for the media transport boundary.
2//!
3//! These types are cold-path configuration and dependency carriers. They are
4//! consumed when the runtime builds the transport service and must not be
5//! consulted by packet-loop code after startup. The split keeps startup policy
6//! separate from long-lived service handles:
7//! transport config describes operator policy, while transport deps describe
8//! process services shared with metrics and recording.
9
10use std::{net::IpAddr, sync::Arc, time::Duration};
11
12use crate::{
13    CodecPreferences, MediaCodecFlags, RtcPortRange, RtcUdpIoBackend, SessionBitrateLimits,
14    VideoBitrateLimits,
15    engine::{metrics::RuntimeMetrics, packet_sink_registry::RoomPacketSinkRegistry},
16};
17
18/// operator-facing RTC transport policy used to build each RTC worker
19///
20/// values are immutable after construction with each worker receiving only its
21/// UDP sub-range while sharing bitrate, codec and announced IP policy
22#[derive(Copy, Clone, Debug)]
23pub struct MediaTransportConfig {
24    /// number of process-local RTC workers owned by this transport
25    pub worker_count: usize,
26    /// client-routable address advertised in ICE candidates
27    ///
28    /// This is deployment policy, not a local bind address. A wrong value can
29    /// make otherwise valid sessions unreachable from browsers.
30    pub announced_ip: IpAddr,
31    /// Per-user ingress and egress bitrate ceilings enforced by the transport.
32    pub bitrate_limits: SessionBitrateLimits,
33    /// Default video bitrate policy used while building negotiated offers.
34    pub video_bitrate_limits: VideoBitrateLimits,
35    /// UDP port range available to this transport config.
36    ///
37    /// The top-level config covers the whole process. Worker configs carry only
38    /// the sub-range assigned to one media worker.
39    pub rtc_port_range: RtcPortRange,
40    /// UDP I/O implementation used by RTC packet-loop workers.
41    pub rtc_udp_io_backend: RtcUdpIoBackend,
42    /// Enabled codec set for offer generation and capability projection.
43    pub codec_flags: MediaCodecFlags,
44    /// Codec preference order preserved while constructing router capabilities.
45    pub codec_preferences: CodecPreferences,
46    /// str0m stats interval for transport-quality events, at most 24 hours.
47    ///
48    /// `None` or zero disables sampling. Construction rejects larger intervals.
49    pub media_quality_interval: Option<Duration>,
50}
51
52impl MediaTransportConfig {
53    /// Largest sampling interval accepted before constructing str0m timers.
54    pub const MAX_MEDIA_QUALITY_INTERVAL: Duration = Duration::from_hours(24);
55}
56
57/// Long-lived services injected into media transport construction.
58///
59/// # Resource split
60///
61/// The transport owns no global telemetry registry or recording service by
62/// itself. It receives handles to the process stores it must update while
63/// executing media work.
64#[derive(Debug, Clone)]
65pub struct MediaTransportDeps {
66    /// Room packet-sink registry used by the packet path to fan out recording
67    /// and non-local destinations.
68    pub packet_sink_registry: Arc<RoomPacketSinkRegistry>,
69    /// Process-local metrics catalog updated by transport lifecycle and media
70    /// counters.
71    pub metrics: Arc<RuntimeMetrics>,
72}