Skip to main content

moq_rtc/
lib.rs

1//! WebRTC ↔ MoQ gateway.
2//!
3//! Bridges WHIP (RFC 9725) and WHEP between WebRTC peers and
4//! [`moq_net`] broadcasts. The crate is split along two orthogonal axes
5//! so all four combinations can land independently:
6//!
7//! | | RTP-in (ingest into MoQ) | RTP-out (egress from MoQ) |
8//! |---|---|---|
9//! | HTTP server | [`Server::publish_router`] (WHIP server) | [`Server::subscribe_router`] (WHEP server) |
10//! | HTTP client | [`Client::subscribe`] (WHEP client) | [`Client::publish`] (WHIP client) |
11//!
12//! The two HTTP-client paths and the two HTTP-server paths share a single
13//! [`session::Session`] driver and the same per-codec adapters in [`codec`];
14//! the per-direction split lives in [`session::MediaSink`] (ingest) /
15//! [`egress::EgressSource`] (egress).
16//!
17//! ## Embedding
18//!
19//! Depend on this crate with `default-features = false` to embed the gateway
20//! in another process: build a [`Server`] over your own
21//! [`OriginProducer`](moq_net::OriginProducer) /
22//! [`OriginConsumer`](moq_net::OriginConsumer) and merge
23//! [`Server::publish_router`] / [`Server::subscribe_router`] into your own axum
24//! app, or dial out with [`Client`]. That lean build skips the standalone
25//! binary's deps (axum-server, clap, moq-native, rustls, sd-notify, tower-http),
26//! which the `server` feature (on by default) pulls back in for the `moq-rtc`
27//! binary.
28//!
29//! The bundled routers are unauthenticated: they derive the broadcast name from
30//! the request path. To own the HTTP route and authorize requests yourself
31//! (resolving the broadcast name from a verified token), skip the routers and
32//! call [`whip::accept`] (ingest) / [`whep::accept`] (egress) from your own
33//! handler. Return the [`Response::answer`] in your HTTP response, then run
34//! [`Response::run`] to drive the media session for its lifetime.
35//!
36//! ## Bitstream gotcha
37//!
38//! The WebRTC ↔ MoQ shape conversion for H.264 is handled by `moq-mux`'s
39//! `Avc3` importer: str0m hands us Annex-B (start-code NALs with inline
40//! SPS/PPS) and that's exactly what the importer wants, so no extra
41//! transform is needed in the gateway. Opus, VP8, and VP9 pass through.
42
43pub mod client;
44pub mod codec;
45pub mod egress;
46mod error;
47pub mod ingest;
48pub mod sdp;
49pub mod server;
50pub mod session;
51
52pub use client::Client;
53pub use error::*;
54pub use server::{Response, Server, whep, whip};