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//! internal session driver and the same per-codec adapters; the per-direction
14//! split lives in the (crate-private) ingest and egress sources.
15//!
16//! ## Embedding
17//!
18//! Build a [`Server`] over your own
19//! [`OriginProducer`](moq_net::origin::Producer) /
20//! [`OriginConsumer`](moq_net::origin::Consumer) and merge
21//! [`Server::publish_router`] / [`Server::subscribe_router`] into your own axum
22//! app, or dial out with [`Client`]. A command-line interface is provided by the
23//! `moq-cli` binary, on top of this library.
24//!
25//! The bundled routers are unauthenticated: they derive the broadcast name from
26//! the request path. To own the HTTP route and authorize requests yourself
27//! (resolving the broadcast name from a verified token), skip the routers and
28//! call [`whip::accept`] (ingest) / [`whep::accept`] (egress) from your own
29//! handler. Return the [`Response::answer`] in your HTTP response, then run
30//! [`Response::run`] to drive the media session for its lifetime.
31//!
32//! ## Bitstream gotcha
33//!
34//! The WebRTC ↔ MoQ shape conversion for H.264 and H.265 is handled by
35//! `moq-mux` importers: str0m hands us Annex-B (start-code NALs with inline
36//! parameter sets) and that's exactly what the importers want. AV1 uses the
37//! shared OBU splitter/importer. Opus, VP8, and VP9 pass through.
38
39#![warn(missing_docs)]
40
41pub mod client;
42pub mod server;
43
44// Implementation detail modules: these carry the WebRTC/str0m plumbing (str0m
45// `Rtc`, `Mid`/`Pt`, tokio channels, raw packet buffers) and are deliberately
46// crate-private, so the public surface stays `Client`, `Server`,
47// `whip`/`whep::accept`, and `Response`.
48mod codec;
49mod egress;
50mod error;
51mod ingest;
52mod net;
53mod sdp;
54mod session;
55
56/// Re-export of the underlying WebRTC stack, so consumers can name the str0m
57/// types that surface through [`Error::Rtc`] / [`Error::RtcInput`] without adding
58/// their own str0m dependency (and risking a version mismatch). A major str0m
59/// bump is therefore a breaking change for this crate.
60pub use str0m;
61
62/// Re-export of the HTTP router stack, so consumers can merge the [`axum::Router`]
63/// returned by [`Server::publish_router`] / [`Server::subscribe_router`] (and by
64/// [`whip::router`] / [`whep::router`]) into their own app without adding their own
65/// axum dependency (and risking a version mismatch). A major axum bump is therefore
66/// a breaking change for this crate.
67pub use axum;
68
69/// Re-export of the URL type, so consumers can build the [`url::Url`] that
70/// [`Client::subscribe`] / [`Client::publish`] dial without adding their own url
71/// dependency (and risking a version mismatch). A major url bump is therefore a
72/// breaking change for this crate.
73pub use url;
74
75pub use client::Client;
76pub use error::*;
77pub use server::{Response, Server, whep, whip};