Skip to main content

rtmp_runtime/
lib.rs

1//! Sans-IO RTMP 1.0 **ingest** (publish) session engine — Adobe Real-Time
2//! Messaging Protocol.
3//!
4//! Spec grounding: Adobe RTMP 1.0, transcribed at
5//! [`docs/rtmp.md`](../docs/rtmp.md) (handshake §5.2, chunk stream §5.3,
6//! protocol control messages §5.4, message format §6, message types §7.1,
7//! command messages §7.2). AMF0 encoding (used by command/data messages) is
8//! `[AMF0]` per that same document's provenance section.
9//!
10//! # Scope of this release
11//!
12//! This crate implements two roles, both **publish** (ingest) only:
13//!
14//! - An **ingest server** ([`server::ServerSession`]): a broadcaster pushes a
15//!   stream in via `connect`/`createStream`/`publish`; this engine drives the
16//!   handshake and session state machine and hands back typed audio/video/
17//!   metadata messages as FLV bytes.
18//! - A **publish client** ([`client::ClientSession`]): the other end of that
19//!   same exchange — it drives the client-side handshake, auto-advances
20//!   `connect` → `createStream` → `publish`, and offers
21//!   `send_audio`/`send_video`/`send_metadata` once publishing. With feature
22//!   `tokio` it also gets a socket adapter (`io::AsyncRtmpClient`, built from a
23//!   `target::RtmpTarget` URL); without it callers drive its sans-IO
24//!   `handle_data`/`start` directly over their own transport.
25//!
26//! An egress (play) role — pulling a stream, on either the client or server
27//! side — is on the roadmap but not implemented yet.
28//!
29//! # The sans-IO contract
30//!
31//! No sockets live in the core. You drive the engine with bytes and read back
32//! bytes + typed events: feed inbound bytes in, get outbound bytes to write
33//! plus a stream of typed events out — mirroring the
34//! [`rtsp_runtime`](https://docs.rs/rtsp-runtime) sans-IO client/server split
35//! in this same workspace.
36//!
37//! An optional `tokio` socket adapter (feature `tokio`) drives real
38//! connections over this same core.
39//!
40//! # Module map
41//!
42//! - [`handshake`] — the C0/C1/C2 + S0/S1/S2 handshake (§5.2).
43//! - [`chunk`] — the chunk stream: basic header, message header (4 `fmt`
44//!   variants), extended timestamp (§5.3).
45//! - [`message`] — RTMP message assembly from chunks, protocol control
46//!   messages (§5.4), and the message type catalogue (§6, §7.1).
47//! - [`amf0`] — AMF0 value encoding/decoding, used by command and data
48//!   messages (`[AMF0]`).
49//! - [`server`] — the ingest server session state machine (`connect` →
50//!   `createStream` → `publish`, §7.2).
51//! - [`client`] — the publish client session state machine, the other end of
52//!   that same exchange (issue #744).
53//! - `io` (feature `tokio`) — the async socket adapters over
54//!   `tokio_util::codec::Framed`: `io::AsyncRtmpServer`/`io::RtmpConnection`
55//!   drive the sans-IO server session, `io::AsyncRtmpClient` drives
56//!   [`client::ClientSession`]; every awaited IO is bounded by
57//!   `io::RtmpTimeouts`.
58//! - `target` (feature `tokio`) — `target::RtmpTarget`: an
59//!   `rtmp://host[:port]/app/key` URL parsed with the `url` crate (IPv6
60//!   brackets kept in `tcUrl`, userinfo/query stripped).
61//! - [`error`] — the [`RtmpError`] type.
62//!
63//! The handshake/chunk/message/amf0/server sans-IO engine and the `tokio`
64//! adapter (feature `tokio`) are all implemented (#738 Tasks 1-9); the
65//! publish client engine (#744) is implemented on top of the same core.
66
67#![forbid(unsafe_code)]
68#![warn(missing_docs)]
69#![cfg_attr(docsrs, feature(doc_cfg))]
70
71pub mod amf0;
72pub mod chunk;
73pub mod client;
74#[cfg(feature = "tokio")]
75mod codec;
76pub mod error;
77pub mod handshake;
78#[cfg(feature = "tokio")]
79#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
80pub mod io;
81pub mod message;
82pub mod server;
83#[cfg(feature = "tokio")]
84#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
85pub mod target;
86
87pub use error::RtmpError;
88
89/// The Adobe RTMP specification version this engine implements.
90pub const RTMP_VERSION: &str = "RTMP 1.0";