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//! Build a [`Server`] over your own
20//! [`OriginProducer`](moq_net::OriginProducer) /
21//! [`OriginConsumer`](moq_net::OriginConsumer) and merge
22//! [`Server::publish_router`] / [`Server::subscribe_router`] into your own axum
23//! app, or dial out with [`Client`]. A command-line interface is provided by the
24//! `moq-cli` binary, on top of this library.
25//!
26//! The bundled routers are unauthenticated: they derive the broadcast name from
27//! the request path. To own the HTTP route and authorize requests yourself
28//! (resolving the broadcast name from a verified token), skip the routers and
29//! call [`whip::accept`] (ingest) / [`whep::accept`] (egress) from your own
30//! handler. Return the [`Response::answer`] in your HTTP response, then run
31//! [`Response::run`] to drive the media session for its lifetime.
32//!
33//! ## Bitstream gotcha
34//!
35//! The WebRTC ↔ MoQ shape conversion for H.264 is handled by `moq-mux`'s
36//! `Avc3` importer: str0m hands us Annex-B (start-code NALs with inline
37//! SPS/PPS) and that's exactly what the importer wants, so no extra
38//! transform is needed in the gateway. Opus, VP8, and VP9 pass through.
39
40pub mod client;
41pub mod codec;
42pub mod egress;
43mod error;
44pub mod ingest;
45pub mod sdp;
46pub mod server;
47pub mod session;
48
49pub use client::Client;
50pub use error::*;
51pub use server::{Response, Server, whep, whip};