1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//! SRT (Secure Reliable Transport) as specified by the Internet-Draft
//! `draft-sharabayko-srt-01`: byte-exact codecs for every data and control
//! packet, and sans-IO engines for the HSv5 Caller/Listener and Rendezvous
//! handshakes, the ARQ reliability loop (loss detection, NAK, ACK/ACKACK,
//! RTT), TSBPD delivery with too-late drop, and LiveCC and FileCC congestion
//! control. Behind features it adds the §6 payload encryption (AES-CTR, RFC 3394
//! key wrap, PBKDF2 key derivation, KM refresh), the one-connection
//! [`Link`] engine, and a `tokio` UDP adapter that has been checked against
//! a real libsrt 1.5.5 peer.
//!
//! The core is `no_std` + `alloc` and reads no clock: every engine takes the
//! caller's time (`tick`, `set_elapsed`, a `broadcast_core::stage::Instant`), and
//! every bound, timeout and cadence ([`arq::ArqBounds`], `io::IoConfig`,
//! `link::LinkCadence`) is the caller's. Packets the delivery engine gives up
//! on are reported as damage, coalesced per sequence run ([`damage`]); a
//! handshake that is rejected or never completes stays an error. It builds on
//! `broadcast-core`, `broadcast-common` and `broadcast-net`; `broadcast-client`
//! (the SRT caller source) and `multimux` (SRT input and push) build on it.
//!
//! # 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: [`arq::ArqBounds`], [`arq::ReceiverBounds`], [`arq::SenderBounds`],
//! [`io::ListenerLimits`], [`handshake_sm::HandshakeConfig`]. A preset delivers
//! a damaged unit flagged; dropping it is the caller's opt-in.
//!
//! # Quickstart
//!
//! Run a Caller/Listener handshake in memory: the bytes one side emits are
//! parsed and fed to the other, as a transport would.
//!
//! ```rust
//! use core::time::Duration;
//!
//! use srt_runtime::HandshakeConfig;
//! use srt_runtime::caller::{CallerHandshake, CallerHandshakeState};
//! use srt_runtime::handshake_sm::HandshakeOutput;
//! use srt_runtime::listener::{ListenerHandshake, ListenerHandshakeState};
//! use srt_runtime::packet::ControlPacket;
//!
//! fn first_send(outputs: Vec<HandshakeOutput>) -> Option<Vec<u8>> {
//! outputs.into_iter().find_map(|o| match o {
//! HandshakeOutput::Send(bytes) => Some(bytes),
//! _ => None,
//! })
//! }
//!
//! let mut caller = CallerHandshake::new(
//! 0x1111_1111,
//! HandshakeConfig::new(
//! Duration::from_millis(120),
//! 1500,
//! 8192,
//! Duration::from_millis(250),
//! 12,
//! )
//! .with_latency(Duration::from_millis(180))
//! .with_stream_id(Some("live/camera-1".into())),
//! );
//! // A real listener derives the SYN cookie from the peer address and a secret.
//! let mut listener = ListenerHandshake::new(
//! 0x2222_2222,
//! 0xC0FF_EE42,
//! HandshakeConfig::new(
//! Duration::from_millis(120),
//! 1500,
//! 8192,
//! Duration::from_millis(250),
//! 12,
//! ).with_latency(Duration::from_millis(250)),
//! );
//!
//! let mut to_listener = caller.start().unwrap();
//! for _ in 0..10 {
//! let pkt = ControlPacket::parse(&to_listener).unwrap();
//! let Some(reply) = first_send(listener.feed(&pkt).unwrap()) else { break };
//! let pkt = ControlPacket::parse(&reply).unwrap();
//! match first_send(caller.feed(&pkt).unwrap()) {
//! Some(next) => to_listener = next,
//! None => break,
//! }
//! }
//! assert_eq!(caller.state(), CallerHandshakeState::Connected);
//! assert_eq!(listener.state(), ListenerHandshakeState::Connected);
//! // Both sides agree on the greater of the two latencies.
//! assert_eq!(caller.negotiated().unwrap().latency, Duration::from_millis(250));
//! ```
//!
//! # How do I...
//!
//! - Parse and re-serialize an SRT packet: [`SrtPacket`],
//! [`packet::ControlPacket`], `examples/packet_round_trip.rs`.
//! - Run a Caller/Listener handshake without sockets: [`CallerHandshake`],
//! [`ListenerHandshake`], [`HandshakeConfig`],
//! `examples/handshake_loopback.rs`.
//! - Recover lost packets with NAK and retransmission: [`arq::Sender`],
//! [`arq::Receiver`], `examples/arq_loss_recovery.rs`.
//! - Read an `srt://` URL (stream id, latency, mode, passphrase): [`SrtUrl`],
//! `examples/parse_url.rs`.
//! - Connect over UDP with tokio: [`io::SrtListener`], [`io::SrtSocket`],
//! [`io::SrtSocketConfig`], `examples/udp_loopback.rs`.
//! - Encrypt the payload with a passphrase: [`handshake_sm::CryptoConfig`],
//! [`HandshakeConfig::with_crypto`], `examples/udp_loopback.rs`.
//! - Size the socket receive buffer: `broadcast_net::net::UdpOptions`,
//! [`io::SrtSocket::recv_buffer_size`]; no example yet (the README section
//! "Sizing the receive buffer" gives the rule).
//! - Connect two peers in Rendezvous mode: [`RendezvousHandshake`],
//! [`RendezvousRole`]; no example yet.
//! - Drive one connection from your own socket loop: [`Link`], [`CallerLink`],
//! [`Delivered`]; no example yet.
//! - Release data on its delivery time: [`tsbpd::TsbpdScheduler`]; no example
//! yet.
//! - Pace a sender: [`livecc::LiveCC`], [`filecc::FileCc`]; no example yet.
//!
//! # Modules
//!
//! Wire format: [`packet`] (every data and control packet and handshake
//! extension), [`url`] (feature `std`, the `srt://` URL).
//!
//! Handshakes: [`handshake_sm`] (the shared configuration, outputs and
//! negotiated parameters), [`caller`], [`listener`], [`rendezvous`], [`cookie`]
//! (feature `link`, the Listener's SYN cookie).
//!
//! Reliability and timing: [`arq`] (sender, receiver, sequence arithmetic,
//! RTT), [`tsbpd`] (delivery scheduler), [`livecc`] and [`filecc`]
//! (congestion control), [`damage`] (drops as damage reports).
//!
//! Encryption (feature `crypto`): [`crypto`] (AES-CTR, key wrap, key
//! derivation), [`km_refresh`] (SEK rotation).
//!
//! Connections: [`link`] (feature `link`, one connection as a sans-IO engine),
//! [`io`] (feature `tokio`, the UDP adapter).
//!
//! Errors: [`error`].
//!
//! # Feature flags
//!
//! - `std` (default): the standard library and [`SrtUrl`]; without it the
//! crate is `no_std` + `alloc`.
//! - `serde`: `Serialize` on the public wire types.
//! - `crypto`: payload encryption, the handshake key exchange and KM refresh.
//! - `link`: the [`Link`] and [`CallerLink`] engines and the SYN cookie;
//! implies `crypto`.
//! - `tokio`: the [`io`] UDP adapter; implies `std` and `link`.
//!
//! # Spec citations
//!
//! `draft-sharabayko-srt-01` §3 (packet structure), §4.3.1 (Caller/Listener),
//! §4.3.2 (Rendezvous), §4.5 to §4.7 (TSBPD and too-late drop), §4.8 and §4.10
//! (ARQ and RTT), §5.1 (LiveCC), §5.2 (FileCC), §6 (encryption)
//! (`private/specs-verified/ietf/specs/ietf_draft_sharabayko_srt_01.txt`); RFC
//! 3394 (`private/specs-verified/ietf/srt-runtime/rfc3394-aes-key-wrap.md`);
//! RFC 8018 PBKDF2 (`private/specs-verified/ietf/srt-runtime/rfc8018-pbkdf2.md`).
;
extern crate alloc;
/// Key lengths (bytes) AES key wrap accepts: AES-128/192/256 (FIPS 197).
pub const AES_KEY_LENS: = ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SrtPacket;
pub use ;
pub use SrtUrl;
/// The Internet-Draft this crate implements packet structure from.
pub const SPEC: &str = "draft-sharabayko-srt-01";