Skip to main content

o_sfu_core/engine/media_transport/rtc/
mod.rs

1//! Private WebRTC backend below [`MediaTransport`](super::MediaTransport).
2//!
3//! Each [`RtcWorker`] drives its sessions through one shared UDP socket and
4//! bounded mailboxes. [`control`] and [`packet_loop`] share [`recovery`]:
5//!
6//! ```text
7//! worker
8//!   +-- commands ------> control ------+
9//!   |                                  +--> recovery
10//!   `-- media packets -> packet_loop --+
11//!                            |
12//!                            `--> consumer_egress
13//! ```
14//!
15//! [`state::PacketLoopState`] holds the sessions, media identity, routes and
16//! scheduling indexes used by these operations. Its lifecycle methods keep
17//! dependent indexes and stream retirement together. [`state::RtcSnapshotState`]
18//! exposes observations without granting access to that mutable state.
19//!
20//! [`worker::loop_driver`] governs turn ordering. [`consumer_egress`] provides
21//! receiver RTP writes. [`egress`] dispatches encoded transmits to network adapters
22//! after the worker releases mutable RTC state. Packet processing and recovery
23//! do not call command handlers.
24//!
25//! [`commands`] defines shared mailbox contracts, [`codec`] provides codec rules
26//! and [`bootstrap`] initializes sockets and sessions.
27
28use std::{sync::Arc, time::Duration};
29
30use crate::{SessionBitrateLimits, VideoBitrateLimits};
31
32#[cfg(test)]
33#[expect(non_snake_case, reason = "test modules map to local TESTS directories")]
34mod TESTS;
35#[cfg(feature = "internal-benchmarks")]
36#[path = "TESTS/benchmark_support/mod.rs"]
37pub mod benchmark_support;
38mod bootstrap;
39mod codec;
40mod commands;
41mod consumer_egress;
42mod control;
43mod egress;
44#[cfg(any(test, fuzzing))]
45#[path = "TESTS/fuzz_support/mod.rs"]
46pub(crate) mod fuzz_support;
47mod packet_loop;
48mod recovery;
49mod state;
50#[cfg(any(test, feature = "testing-transport", feature = "internal-benchmarks"))]
51#[path = "TESTS/test_support/mod.rs"]
52pub mod test_support;
53mod worker;
54
55pub(super) use codec::RtpProfile;
56#[cfg(any(test, fuzzing))]
57pub use codec::client_rtp_capabilities_from_answer;
58pub(super) use commands::{ParsedSessionAnswer, RtcSessionOffer};
59pub use commands::{
60    RtcWorkerCommand, RtcWorkerResponse, WorkerMediaControlBatch, WorkerMediaControlBatchOutcome,
61};
62pub use worker::RtcWorker;
63
64#[cfg(any(test, feature = "testing-transport"))]
65pub use self::packet_loop::forwarded_packet::ForwardedPacket;
66pub(super) use self::state::route_control::PacketLayerGate;
67
68#[derive(Clone, Debug)]
69struct RtcWorkerConfig {
70    bitrate_limits: SessionBitrateLimits,
71    video_bitrate_limits: VideoBitrateLimits,
72    profile: Arc<RtpProfile>,
73    media_quality_interval: Option<Duration>,
74    media_id_base: u64,
75}