rtsp_runtime/lib.rs
1//! Sans-IO RTSP 1.0 session engine — RFC 2326 (Real Time Streaming Protocol).
2//!
3//! This crate fills the gap the ecosystem leaves: a **driveable** RTSP session
4//! engine, a client *and* a server. Message parse/serialize is delegated to the
5//! mature [`rtsp_types`] and [`sdp_types`] codecs; authentication (Basic/Digest/
6//! Bearer) to the shared [`broadcast_auth`] crate (which itself wraps
7//! `http-auth` for Basic/Digest). What lives here is the part nothing else
8//! provides — the client and server **session state machines** (RFC 2326
9//! Appendix A), `CSeq` correlation, `Transport` negotiation (§12.39),
10//! interleaved RTP/RTCP framing (§10.12), and RTSP's auth wiring (§14).
11//!
12//! # The sans-IO contract
13//!
14//! No sockets live in the core. You drive the engine with bytes and read back
15//! bytes + typed events:
16//!
17//! - [`ClientSession`] — request-builder methods (`options`/`describe`/`setup`/
18//! `play`/`pause`/`teardown`/`get_parameter`) return the outbound request
19//! bytes to write; [`ClientSession::handle_data`] consumes inbound bytes
20//! (responses and interleaved `$` frames) and returns [`ClientEvent`]s. It
21//! correlates `CSeq`, advances the state machine on `2xx`, resets to `Init` on
22//! `3xx`, transparently answers `401` challenges, and captures the `Session`
23//! id/timeout from the SETUP response.
24//! - [`ServerSession`] — [`ServerSession::handle_request`] takes inbound request
25//! bytes and returns the response bytes plus [`ServerEvent`]s, validating the
26//! method against the server state table (`455` otherwise), allocating a
27//! session on SETUP, and negotiating `Transport`.
28//!
29//! An optional `tokio` socket adapter (feature `tokio`) drives real connections
30//! over this same core: the `io::AsyncRtspClient` and `io::AsyncRtspServer`
31//! types own a `tokio::net::TcpStream`, move the bytes the session
32//! produces/consumes, and surface the same [`ClientEvent`]/[`ServerEvent`]s.
33//! With the `tls` feature the adapter also speaks `rtsps://` (RTSP over TLS,
34//! default port 322) by wrapping the stream in a `tokio-rustls` session before
35//! the RTSP exchange. Both are generic over the stream type, so identical logic
36//! runs over TCP and TLS.
37//!
38//! # Module map
39//!
40//! - [`state`] — [`SessionState`] and the client/server transition functions
41//! (RFC 2326 Appendix A; `docs/state-machines.md`).
42//! - [`transport`] — the typed [`Transport`] header (§12.39;
43//! `docs/transport-header.md`).
44//! - [`interleaved`] — [`InterleavedFrame`] and the streaming demultiplexer
45//! (§10.12; `docs/interleaved-framing.md`).
46//! - [`auth`] — [`Credentials`] and the [`Authenticator`], re-exported from the
47//! shared [`broadcast_auth`] crate (§14; `docs/auth.md`).
48//! - [`client`] — [`ClientSession`] and [`ClientEvent`].
49//! - [`server`] — [`ServerSession`] and [`ServerEvent`].
50//! - `io` (feature `tokio`) — the async socket adapter `AsyncRtspClient` /
51//! `AsyncRtspServer`, with `rtsps://` TLS entry points under the `tls`
52//! feature.
53//! - [`error`] — the [`Error`] enum and [`Result`] alias.
54//!
55//! Methods, status codes, and their state effects are catalogued in
56//! `docs/methods-and-status.md`.
57
58#![forbid(unsafe_code)]
59
60pub mod auth;
61pub mod client;
62pub mod error;
63pub mod interleaved;
64#[cfg(feature = "tokio")]
65pub mod io;
66pub mod server;
67pub mod state;
68pub mod transport;
69
70pub use auth::{Authenticator, Credentials};
71pub use client::{ClientEvent, ClientSession};
72pub use error::{Error, Result};
73pub use interleaved::InterleavedFrame;
74#[cfg(feature = "tokio")]
75pub use io::{AsyncRtspClient, AsyncRtspServer, RTSP_DEFAULT_PORT, RTSPS_DEFAULT_PORT};
76pub use server::{ServerEvent, ServerSession};
77pub use state::SessionState;
78pub use transport::{Delivery, LowerTransport, Transport, TransportSpec};
79
80// Re-export the underlying codec types callers need to inspect events.
81pub use rtsp_types::{Method, StatusCode};
82
83/// The RFC this engine implements.
84pub const RFC: &str = "RFC 2326";