SRT Streaming from Mobile Device
SRT (Secure Reliable Transport) — protocol for professional streaming over unreliable networks. Unlike RTMP it runs over UDP with error correction mechanism (ARQ/FEC), withstands up to 30% packet loss, and automatically recovers stream without restart. For mobile streaming from unstable LTE or public Wi-Fi — this is a principle advantage.
Where SRT Better than RTMP
RTMP at 5% packet loss starts buffering and falls apart. SRT with latency=500ms buffer holds at 20–25% loss. For on-location reporting, video production field shoots, remote broadcasts — SRT became standard in professional segment (OBS, vMix, Blackmagic accept SRT natively).
Latency: configurable via latency parameter. 200 ms — minimum for good network. 500–2000 ms — for mobile networks with jitter. Bigger buffer — more stability, more latency.
iOS: HaishinKit with SRT
HaishinKit supports SRT from version 2.x via SRTConnection:
import HaishinKit
let srtConnection = SRTConnection()
let srtStream = SRTStream(connection: srtConnection)
srtStream.videoSettings = VideoCodecSettings(
videoSize: CGSize(width: 1920, height: 1080),
bitRate: 5_000_000,
profileLevel: kVTProfileLevel_H264_High_AutoLevel as String
)
srtStream.audioSettings = AudioCodecSettings(bitRate: 192_000)
try srtStream.attachCamera(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back))
try srtStream.attachAudio(AVCaptureDevice.default(for: .audio))
// Caller mode: we initiate connection
srtConnection.connect("srt://media-server.example.com:9998?latency=500&streamid=live/stream1")
srtStream.publish()
streamid — stream identifier on server (MediaMTX, SRT Live Server use it for routing). latency in milliseconds.
Reconnect on break: SRT can auto-reconnect within connectionTimeout. HaishinKit exposes SRTConnection.Event.connect with reason — handle in delegate.
Android: rtmp-rtsp-stream-client-java with SRT
Library rtmp-rtsp-stream-client-java supports SRT via SrtCamera2:
val srtCamera = SrtCamera2(binding.surfaceView, connectChecker)
srtCamera.prepareVideo(
width = 1920, height = 1080, fps = 30,
bitrate = 5_000_000,
rotation = 0,
profile = CodecUtil.H264_BASELINE
)
srtCamera.prepareAudio(bitrate = 192_000, sampleRate = 44100, isStereo = true)
srtCamera.startStream("srt://media-server.example.com:9998?streamid=live/stream1&latency=500")
Under the hood — native libsrt (C++), compiled for Android ABIs (arm64-v8a, armeabi-v7a, x86_64).
Alternative: FFmpegKit with libsrt
FFmpegKit compiled with libsrt — can use directly:
-f avfoundation -i 0:0 -c:v h264_videotoolbox -b:v 5M -f mpegts "srt://server:9998?latency=500&streamid=live/test"
Advantage: H.265 support (hevc_videotoolbox), more parameter control. Downside: FFmpegKit process doesn't manage camera directly — need separate capture via AVCaptureVideoDataOutput + pipe.
Listener vs Caller Mode
SRT supports two modes:
- Caller — mobile device initiates connection to server. Most common scenario.
- Listener — device listens for incoming connection. Useful for p2p without server or when server behind NAT.
- Rendezvous — both ends simultaneously initiate connection. For p2p through NAT without relay.
For mobile streaming Caller is used. Listener on mobile — rare scenario (IoT device on mobile network without public IP).
Encryption
SRT supports AES-128/256 encryption out of the box: passphrase and pbkeylen parameters in URL. This distinguishes SRT from RTMP — encryption built into protocol, not TLS wrapper.
srt://server:9998?passphrase=MySuperSecret&pbkeylen=32
Connection Quality Monitoring
SRT API provides statistics via srt_bistats(): pktSndLoss, pktRcvLoss, pktRetrans, mbpsSendRate, msRTT. HaishinKit exposes some stats in SRTStream.info. Display in UI: bitrate, RTT, packet loss — professional users appreciate this.
On high pktSndLoss (>5%) — automatically reduce videoBitrate and increase latency parameter (requires reconnection).
Server Compatibility
| Server | SRT Support |
|---|---|
| MediaMTX | Native, no extra setup |
| Nginx + nginx-srt-module | Yes |
| Ant Media Server | Yes |
| Wowza Streaming Engine | Yes (4.8+) |
| OBS Studio | As receiver via srt://listen |
| FFmpeg | libsrt option when building |
Timeline: integrate SRT streaming on one platform with connection quality monitoring — 2–4 work days.







