rtmp-runtime 0.13.0

Sans-IO RTMP 1.0 (Adobe Real-Time Messaging Protocol) publish engine for both ends: a driveable ingest server state machine and a publish client over the handshake, chunk stream, AMF0, and message layers; optional tokio socket adapter.
Documentation
//! Sans-IO RTMP 1.0 (the Adobe RTMP specification): the simple handshake,
//! chunk-stream assembly and writing, protocol control and user control
//! messages, AMF0 commands, and the session engines for both ends of a live
//! push. [`server::ServerSession`] is an ingest server that accepts a publish
//! from OBS or ffmpeg (`connect`, `createStream`, `publish`) and hands the
//! audio, video and data back as FLV bytes; [`client::ClientSession`] publishes
//! to a remote server, or plays from one in [`client::ClientMode::Play`]. The
//! crate also owns the FLV tag syntax an RTMP message carries ([`flv`]).
//!
//! `transmux`'s streaming FLV demuxer reads the FLV the server emits;
//! `multimux` builds its RTMP input and push output, and `broadcast-client` its
//! RTMP play source, on this crate. The core is `no_std` + `alloc`, opens no
//! socket and reads no clock: bytes go in, bytes to write and events come out.
//! Every bound ([`chunk::ChunkLimits`], [`amf0::Amf0Limits`], the session
//! limits) is the caller's. A discarded or undecodable message is reported as
//! damage in order with the events around it; only a stream that cannot be
//! framed is an error. The optional `tokio` feature adds socket adapters and
//! `target` the `rtmp[s]://` URL grammar.
//!
//! # Quickstart
//!
//! Replay a real ffmpeg publish capture through the ingest server and collect
//! the FLV it produces. Every bound is the caller's:
//!
//! ```rust
//! use rtmp_runtime::amf0::Amf0Limits;
//! use rtmp_runtime::chunk::ChunkLimits;
//! use rtmp_runtime::server::{RtmpServerConfig, ServerEvent, ServerLimits, ServerSession};
//!
//! let limits = ServerLimits {
//!     chunk: ChunkLimits {
//!         max_chunk_size: 1 << 20,
//!         max_message_len: 1 << 20,
//!         max_csids: 64,
//!         max_in_progress_bytes: 1 << 22,
//!     },
//!     amf0: Amf0Limits { max_depth: 16, max_values: 1024 },
//!     max_command_len: 16 * 1024,
//!     max_failed_publish_attempts: 3,
//! };
//! let capture = test_fixtures::read("rtmp/obs-publish.bin");
//! let mut session = ServerSession::new(RtmpServerConfig::new(limits, 4096, 2_500_000, 2_500_000));
//! let mut flv = Vec::new();
//! let mut published = false;
//! for chunk in capture.chunks(1400) {
//!     let (_reply, events) = session.handle_data(chunk).unwrap();
//!     for ev in events {
//!         match ev {
//!             ServerEvent::Connected { app } => assert_eq!(app, "live"),
//!             ServerEvent::Publish { stream_key, .. } => {
//!                 assert_eq!(stream_key, "testkey");
//!                 published = true;
//!             }
//!             ServerEvent::Media { flv: bytes } => flv.extend_from_slice(&bytes),
//!             _ => {}
//!         }
//!     }
//! }
//! assert!(published && flv.starts_with(b"FLV"));
//! ```
//!
//! # How do I...
//!
//! - Ingest a publish and get FLV out: [`server::ServerSession`],
//!   [`server::ServerEvent::Media`], `examples/ingest_to_flv.rs`.
//! - Publish to a server: [`client::ClientSession`],
//!   [`client::ClientSession::send_video`],
//!   [`client::ClientSession::send_metadata`], `examples/publish_loopback.rs`.
//! - Accept publishers on a TCP port with tokio: [`io::AsyncRtmpServer`]
//!   (feature `tokio`), `examples/capture_publish.rs` (it waits for an
//!   external publisher such as ffmpeg).
//! - Read an `rtmp://` or `rtmps://` URL: [`target::RtmpTarget`] (feature
//!   `target`), `examples/parse_target.rs`.
//! - Admit only one stream key: [`server::RtmpServerConfig`]'s
//!   `expected_stream_key`; no example yet.
//! - Play a stream from a server: [`client::ClientMode::Play`],
//!   [`client::ClientEvent::Media`]; no example yet.
//! - Walk the tags of an FLV file: [`flv::tags`], [`flv::FlvHeader`]; no
//!   example yet.
//!
//! # Modules
//!
//! Sessions: [`server`] (the ingest state machine), [`client`] (publish and
//! play).
//!
//! Wire layer: [`handshake`] (C0/C1/C2 and S0/S1/S2), [`chunk`] (chunk stream
//! assembly and writing), [`message`] (message types, protocol and user
//! control), [`amf0`] (values and commands), [`ids`] (chunk stream, message
//! stream, sequence and timestamp identities), [`flv`] (FLV file, tag and
//! tag-body syntax).
//!
//! Sockets and URLs: [`io`] (feature `tokio`, the async server and client),
//! [`target`] (feature `target`, the `rtmp[s]://` URL).
//!
//! Errors: [`error`].
//!
//! # Feature flags
//!
//! - `serde`: serde on the events, the AMF0 values, the limits and the FLV wire
//!   types.
//! - `tokio`: [`io::AsyncRtmpServer`] and [`io::AsyncRtmpClient`]; implies
//!   `target`.
//! - `target`: [`target::RtmpTarget`], the URL grammar (no sockets).
//!
//! # Spec citations
//!
//! Adobe RTMP specification 1.0 §5.2 (handshake), §5.3 (chunk stream), §5.4
//! (protocol control), §6 (message format), §7.1 and §7.2 (message types and
//! commands), transcribed in `private/specs-verified/rtmp/rtmp-runtime/rtmp.md`;
//! AMF0 as the RTMP specification references it; the Adobe FLV and F4V file
//! format specification v10.1 for the FLV tags.
#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(not(any(feature = "tokio", feature = "target", test)), no_std)]

#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;

extern crate alloc;

pub mod amf0;
pub mod chunk;
pub mod client;
#[cfg(feature = "tokio")]
mod codec;
mod damage;
pub mod error;
pub mod flv;
pub mod handshake;
pub mod ids;
#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
pub mod io;
pub mod message;
pub mod server;
#[cfg(feature = "target")]
#[cfg_attr(docsrs, doc(cfg(feature = "target")))]
pub mod target;
#[cfg(test)]
mod test_support;

pub use error::RtmpError;
pub use message::ChunkSize;

/// The Adobe RTMP specification version this engine implements.
pub const RTMP_VERSION: &str = "RTMP 1.0";