Expand description
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.
§Choosing limits
No limit struct here has a Default. Each one offers
for_profile(broadcast_core::Profile), a complete preset whose every
number is a documented constant, and a typed with_* setter per field:
| Profile | Sized for |
|---|---|
Embedded | one program, a few hundred MB of memory, 32-bit or wasm32, few elementary streams (values checked against the 256 MiB budget where exercised, #4834) |
Device | single-service playback on a phone, tablet, TV or desktop, about 30 s of read-ahead |
Server | a live origin or HLS server carrying several programs |
Headend | a whole multiplex with full SI/EPG, up to 2048 PIDs |
The presets: chunk::ChunkLimits, amf0::Amf0Limits,
client::ClientLimits and server::ServerLimits. A preset delivers a
damaged unit flagged; dropping it is the caller’s opt-in.
§Quickstart
Replay a real ffmpeg publish capture through the ingest server and collect the FLV it produces. Every bound is the caller’s:
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(featuretokio),examples/capture_publish.rs(it waits for an external publisher such as ffmpeg). - Read an
rtmp://orrtmps://URL:target::RtmpTarget(featuretarget),examples/parse_target.rs. - Admit only one stream key:
server::RtmpServerConfig’sexpected_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::AsyncRtmpServerandio::AsyncRtmpClient; impliestarget.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.
Re-exports§
Modules§
- amf0
- AMF0 (Action Message Format 0) value encoding/decoding, used by RTMP command and data messages.
- chunk
- RTMP chunk stream — basic header, message header, extended timestamp (Adobe RTMP 1.0 §5.3).
- client
- RTMP client session engine —
connect→createStream→publish(Adobe RTMP 1.0 §7.2,NetConnection/NetStreamcommands). - error
- Error type for the RTMP ingest session engine.
- flv
- FLV (Flash Video) tag framing — Adobe Flash Video File Format Specification v10.1, Annex E: the file header of §E.2 and the tag of §E.4.1.
- handshake
- RTMP handshake — C0/C1/C2 and S0/S1/S2 (Adobe RTMP 1.0 §5.2).
- ids
- The RTMP wire identities — §5.1.2
chunk stream id, §5.1.3message stream idandtimestamp, §5.3.1.1’s basic-header encodability rule (referenceprivate/specs-verified/rtmp/rtmp-runtime/rtmp.md). - io
tokio - Async
tokiosocket adapter driving the sans-IO ingest server session over a realtokio::net::TcpStream— the Layer-2 adapter (seeprivate/specs-verified/rtmp/rtmp-runtime/rtmp.md§ Layer-2 adapter; mirrors thertsp_runtime::iotokio adapter shape in this same workspace). - message
- RTMP message assembly from chunks, protocol control messages, and the message type catalogue (Adobe RTMP 1.0 §5.4, §6, §7.1).
- presets
- The
broadcast_core::Profilepresets of this crate’s bounds. Every number is a documented constant used only by afor_profilebody; the caller replaces any field through its typedwith_*setter. No preset refuses a message a real encoder sends. - server
- RTMP ingest server session state machine —
connect→createStream→publish(Adobe RTMP 1.0 §7.2,NetConnection/NetStreamcommands). - target
target rtmp[s]://host[:port]/app/stream-key-> typed target, built with theurlcrate. Replacesformat!("rtmp://{host}:{port}/{app}"), which producesrtmp://::1:1935/livefor an IPv6 address (defect 8) and leaks userinfo/query intotcUrl.
Constants§
- RTMP_
VERSION - The Adobe RTMP specification version this engine implements.