Skip to main content

Crate srt_runtime

Crate srt_runtime 

Source
Expand description

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:

ProfileSized for
Embeddedone program, a few hundred MB of memory, 32-bit or wasm32, few elementary streams (values checked against the 256 MiB budget where exercised, #4834)
Devicesingle-service playback on a phone, tablet, TV or desktop, about 30 s of read-ahead
Servera live origin or HLS server carrying several programs
Headenda 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.

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…

§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).

Re-exports§

pub use caller::CallerHandshake;
pub use caller::CallerHandshakeState;
pub use error::Error;
pub use error::Result;
pub use handshake_sm::HandshakeConfig;
pub use handshake_sm::HandshakeOutput;
pub use handshake_sm::NegotiatedParams;
pub use handshake_sm::RejectionReason;
pub use link::CallerParams;link
pub use link::Delivered;link
pub use link::DeliveredItem;link
pub use link::LinkCounts;link
pub use link::LinkEnd;link
pub use link::LinkSetup;link
pub use link::Payload;link
pub use listener::ListenerHandshake;
pub use listener::ListenerHandshakeState;
pub use packet::SrtPacket;
pub use rendezvous::RendezvousHandshake;
pub use rendezvous::RendezvousHandshakeState;
pub use rendezvous::RendezvousRole;
pub use url::SrtUrl;std

Modules§

arq
SRT ARQ (Automatic Repeat reQuest) reliability engine — draft-sharabayko-srt-01 §4.8 (Acknowledgement and Lost Packet Handling), §4.8.1 (Packet Acknowledgement — ACKs, ACKACKs), §4.8.2 (Packet Retransmission — NAKs), §4.10 (Round-Trip Time Estimation). Curated behavioural rules: private/specs-verified/rules/srt-arq.md. The wire field layouts this module drives (ACK/NAK/ACKACK) are the existing crate::packet codecs — this module never re-encodes them, it only decides when to build one and what to do with one received.
caller
Caller-side handshake engine — draft-sharabayko-srt-01 §4.3.1 (Caller-Listener Handshake), Caller role.
cookielink
The SYN Cookie and the Listener’s stateless identifiers — draft-sharabayko-srt-01 §4.3.1.1 (“a cookie that is crafted based on host, port and current time with 1 minute accuracy”; private/specs-verified/rules/srt-rules.md).
cryptocrypto
SRT payload encryption — draft-sharabayko-srt-01 §6 (“Encryption”).
damage
Turning the delivery engine’s drops into the workspace’s one damage report.
error
Error type for SRT packet parsing and serialization.
filecc
SRT File Transfer Congestion Control (FileCC) — window-based congestion control, draft-sharabayko-srt-01 §5.2 (curated at private/specs-verified/rules/srt-congestion.md).
handshake_sm
Shared types for the sans-IO HSv5 handshake state machine — draft-sharabayko-srt-01 §4.3 (Handshake Messages) / §4.3.1 (Caller-Listener Handshake).
iotokio
Async real-socket UDP adapter over the sans-IO SRT engine.
km_refreshcrypto
SEK-rotation (“KM Refresh”) driver — draft-sharabayko-srt-01 §6.1.6 (KM Refresh), curated at private/specs-verified/rules/srt-crypto.md (“KM Refresh — §6.1.6”).
linklink
One SRT connection as a sans-IO link: datagrams and the caller’s now in, datagrams to send and delivered payloads out.
listener
Listener-side handshake engine — draft-sharabayko-srt-01 §4.3.1 (Caller-Listener Handshake), Listener role.
livecc
SRT Live Congestion Control — packet pacing (draft-sharabayko-srt-01 §5.1, curated at private/specs-verified/rules/srt-livecc.md).
packet
SRT packet structure — draft-sharabayko-srt-01 §3 (Packet Structure).
presets
The broadcast_core::Profile presets of this crate’s bounds. Every number is a documented constant used only by a for_profile body; the caller replaces any field through its typed with_* setter.
rendezvous
Rendezvous handshake engine — draft-sharabayko-srt-01 §4.3.2 (Rendezvous Handshake), curated at private/specs-verified/rules/srt-rendezvous.md. Line cites below (LNNNN) are the source draft’s line numbers, exactly as recorded in that curation.
tsbpd
Instant-Based Packet Delivery (TSBPD) + Too-Late Packet Drop — SRT receiver-side delivery scheduling.
urlstd
The srt:// URL a caller dials (draft-sharabayko-srt-01 §3.2.1.3 Stream ID; the scheme itself is SRT’s registered URL form).

Constants§

SPEC
The Internet-Draft this crate implements packet structure from.