SRTKit

When you broadcast a live video feed over an unreliable network — a field contribution, a satellite link, a 4G connection from a stadium — the transport protocol makes all the difference. TCP is reliable but adds latency, UDP is fast but drops packets without warning. SRT (Secure Reliable Transport) combines the best of both: UDP transport with reliability, low latency, AES encryption, and forward error correction.

Created by Haivision and turned into an open standard through the SRT Alliance, SRT is now used by broadcasters worldwide — from live contribution to broadcast workflows and cloud media. The protocol handles handshakes in three modes (Caller, Listener, Rendezvous), end-to-end AES-CTR and AES-GCM encryption, XOR-based forward error correction (FEC), connection bonding for failover, and adaptive congestion control.

While building the Atelier Socle streaming ecosystem — HLSKit for HTTP Live Streaming, IcecastKit for Icecast/SHOUTcast, RTMPKit for RTMP — the last missing piece was SRT. And not a wrapper around C's libsrt — a pure Swift implementation, from UDP transport up to AES encryption, with Swift 6.2 structured concurrency, zero C dependencies, and bidirectional interoperability validated with libsrt 1.5.4.

I looked. Nothing existed in pure Swift. SRTKit was born from that need.

0.2.0 adds native IPv6 support and fixes the StreamID wire format — bytes must be inverted per 4-byte chunk (each chunk is treated as a UInt32 with the first string byte in LSB position). Without this inversion, no libsrt-based server (OBS, FFmpeg, MediaMTX, srt-live-transmit) could read the StreamID correctly.

0.3.0 fixes three fundamental protocol compliance issues. The data packet messageNumber counter — which was fixed at 0 — is now incremented on 26 bits (2²⁶ − 1, value 0 reserved for FEC), resolving the "opened but never publishing" issue with MediaMTX. ACK handling is implemented: the CIF is parsed to extract the last acknowledged sequence number, RTT and link capacity, acknowledged packets are released from the send buffer, and an ACKACK is sent in response. Finally, the Initial Sequence Number (ISN) is generated randomly and independently per direction (local for sending, peer for receiving), per IETF draft §4.3.

What SRTKit does

SRTKit is a pure Swift implementation of the SRT protocol. It covers the entire protocol: connection in three modes, AES encryption, FEC error correction, connection bonding, congestion control, real-time statistics, stream recording, access control, and auto-reconnection. All with strict Sendable conformance end to end. This is NOT a libsrt wrapper — it's a complete implementation from scratch.

  • Caller/Listener/Rendezvous — Three connection modes for any SRT topology with full handshake negotiation (induction, conclusion, cookie exchange), native IPv4 and IPv6 support

  • AES-CTR + AES-GCM encryption — End-to-end encryption with PBKDF2 key derivation (RFC 2898), RFC 3394 key wrap, configurable key sizes (128/192/256), and automatic key rotation with pre-announce

  • Forward Error Correction — XOR-based row, column, and matrix FEC with staircase/even layouts, configurable ARQ modes (always, onreq, never), and SRTO_PACKETFILTER format parsing

  • Connection Bonding — Broadcast (all links), main/backup (automatic failover), and balancing (weighted aggregate) groups with packet deduplication and stability monitoring

  • Congestion Control — LiveCC (packet pacing), FileCC (AIMD with slow start), AdaptiveCC (pattern detection), pluggable architecture via CongestionControllerPlugin protocol

  • Bandwidth Probing — Stepped probe engine with quick/standard/thorough presets, auto-configuration generation, and bitrate monitoring with hysteresis

  • TSBPD Timing — Time-Based Sender/Buffer/Delivery with clock drift correction, too-late packet drop, and configurable latency

  • Real-time Statistics — Comprehensive metrics (packets, bytes, RTT, bandwidth, buffers, congestion, FEC, encryption), quality scoring with 5 weighted metrics, Prometheus text exposition, and StatsD datagram export

  • Stream Recording — Buffered recording with size/duration-based rotation in MPEG-TS or raw format

  • Access Control — StreamID-based access control with #!:: format parsing and generation (resource, mode, session, user, content type, custom keys)

  • Auto-reconnect — Exponential backoff with configurable jitter and four presets (default, aggressive, conservative, disabled)

  • Multi-stream / Multi-caller — Route multiple streams over a single listener, manage multiple destinations with enable/disable control

  • Server Presets — One-line configuration for AWS MediaConnect, Nimble Streamer, Haivision SRT Gateway, OBS Studio, Wowza, vMix, and SRT Live Server

  • Cross-platform — macOS 14+, iOS 17+, tvOS 17+, watchOS 10+, visionOS 1+, and Linux (Ubuntu 22.04+ with Swift 6.2)

  • CLI toolsrt-cli for sending, receiving, probing, statistics, loopback testing, and diagnostics

  • Swift 6.2 strict concurrency — Actors for stateful types, Sendable everywhere, async/await throughout, zero @unchecked Sendable or nonisolated(unsafe)

  • Interop with libsrt — Bidirectional interoperability with libsrt 1.5.4 and MediaMTX 1.16.3 validated for both encrypted and unencrypted connections, MPEG-TS H.264+AAC streams

Quick start

Connect to an SRT listener, send data, check statistics, and disconnect:

Installation

Via Swift Package Manager, by adding the dependency to your Package.swift:

Then add it to your target:

Platform support

PlatformMinimum version

macOS

14+

iOS

17+

tvOS

17+

watchOS

10+

visionOS

1+

Linux

Swift 6.2 (Ubuntu 22.04+)

Implemented standards

StandardReference

SRT Protocol

SRT Handshake

AES Key Wrap

PBKDF2

AES-CTR

AES-GCM

Encrypted caller

AES-256 encrypted connection in CTR mode with passphrase:

Listener

Start an SRT listener and accept incoming connections:

Configuration with Builder

The builder lets you construct a complete configuration with mode, latency and encryption in a fluent way:

Presets

Six built-in presets cover common use cases. Each automatically configures latency, congestion control and socket options:

Server presets

One-line configuration for common streaming servers and software. Each preset automatically configures latency, encryption, buffer sizes, and StreamID format for optimal compatibility with the target product:

AES-CTR encryption

Packet-level encryption and decryption with AES-CTR. The session encryption key (SEK) and salt are used to encrypt each payload independently, using the sequence number as part of the IV:

Forward Error Correction

XOR-based row, column and matrix FEC to recover lost packets without retransmission. Staircase and even layouts, with configurable ARQ modes:

Connection Bonding

Connection bonding lets you aggregate or failover between multiple network links. Three modes are available: broadcast (send on all links), main/backup (automatic failover), and balancing (weighted aggregate):

Statistics and quality scoring

Comprehensive metrics with automatic quality scoring (0.0–1.0, five grades), Prometheus and StatsD export:

Access control

StreamID-based access control with #!:: format for stream routing and authentication:

Auto-reconnection

SRTKit handles automatic reconnection with exponential backoff. Four presets are available, plus custom policies with jitter:

IPv6 & Interoperability (0.2.0)

The SRT caller now binds :: for IPv6 and 0.0.0.0 for IPv4, with correct peer address extraction via SRTPeerAddress — an enum that encapsulates both address families, including IPv4-mapped IPv6 format (::ffff:a.b.c.d).

The StreamID wire format is fixed to match the SRT specification: each 4-byte block is treated as a UInt32 with the first string byte in LSB (least-significant byte) position. This inversion was required for interoperability with any libsrt-based implementation — OBS, FFmpeg, MediaMTX, srt-live-transmit.

Protocol Compliance & MediaMTX (0.3.0)

Three protocol compliance fixes make the connection reliable with third-party implementations.

The data packet messageNumber counter is now incremented on 26 bits (SRT spec field), with wraparound at 0x03FFFFFF and value 0 reserved for FEC control packets. Before, all packets were sent with messageNumber = 0, triggering deduplication on the receiver side.

ACK handling is implemented: the CIF (Control Information Field) is parsed to extract the acknowledged sequence number, RTT, estimated link capacity and available buffer size. Acknowledged packets are released from the send buffer, and an ACKACK (type 0x0006) is sent back to the peer.

The Initial Sequence Number is generated randomly per direction — a local ISN for outgoing packets, a peer ISN for the receive buffer — per IETF SRT draft §4.3.

Interoperability is validated with MediaMTX 1.16.3 — a 3-minute H.264+AAC MPEG-TS stream published from SRTKit caller to MediaMTX listener, 0 errors, 0 buffer overflow. Both StreamID formats are supported: SRT Access Control format (#!::r=live/test,m=publish) used by libsrt and Haivision, and the short format (publish:live/test) used by MediaMTX.

Architecture

SRTKit architecture — AccessControl, Bonding, Congestion, Connection, Encryption, FEC, Handshake, Packet, Probing, Recording, Reliability, Statistics, Timing, Transport
Overview of SRTKit's modular architecture

The library is organized into clearly separated modules, each with a well-defined responsibility:

CLI tool

srt-cli provides command-line sending, receiving, probing, statistics, loopback testing, and diagnostics with progress display and structured output.

CommandDescription

send

Send data to an SRT listener

receive

Receive data from an SRT caller

probe

Probe available bandwidth and get recommendations

stats

Display real-time connection statistics

test

Run a loopback performance test

info

Display version and feature information

Ecosystem

SRTKit is part of the Atelier Socle streaming ecosystem:

Links

GitHub - atelier-socle/swift-srt-kit: Pure Swift implementation of the SRT protocol. Caller, listener, rendezvous modes with AES encryption, FEC, connection bonding, congestion control, bandwidth probing, and real-time statistics. No C dependencies. macOS · iOS · tvOS · watchOS · visionOS · Linux.

GitHub - atelier-socle/swift-srt-kit: Pure Swift implementation of the SRT protocol. Caller, listener, rendezvous modes with AES encryption, FEC, connection bonding, congestion control, bandwidth probing, and real-time statistics. No C dependencies. macOS · iOS · tvOS · watchOS · visionOS · Linux.

Pure Swift implementation of the SRT protocol. Caller, listener, rendezvous modes with AES encryption, FEC, connection bonding, congestion control, ba…

GitHub