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