Table of Contents

VAST.SRT Library

The VAST.SRT library provides Secure Reliable Transport (SRT) protocol support for VASTreaming applications. It enables receiving streams from SRT sources, publishing streams to SRT servers, running an SRT server to accept incoming connections, transferring files over SRT, and bidirectional messaging between peers.

Overview

Feature Description
SRT Client Pull streams from SRT servers
SRT Publisher Push streams to SRT servers
SRT Server Accept incoming publisher and client connections
Encryption AES-128/192/256 passphrase-based encryption
Latency Control Fixed, Minimal, and Zero latency strategies
File Transfer Send and receive files over SRT
Messaging Bidirectional text and binary messaging between peers

Requirements

Supported Codecs

The SRT library is codec-agnostic. Media is transported using MPEG-2 Transport Stream (TS) encapsulation by default, so any codec supported by the VAST.TS library can be used.

Media Formats

Format Value Description
Transport Stream ts MPEG-2 TS encapsulation (default, widest compatibility)
VersatileBuffer vb VASTreaming native format for lowest overhead and latency (custom VASTreaming extension)
Opaque Data bin Raw binary data passthrough (custom VASTreaming extension)

URI Format

VASTreaming URI Format

VASTreaming objects use an extended URI format where the stream ID is specified as a URI path:

srt://<host>:<port>[/<stream-id>][?<parameters>]
Component Description
host Server hostname or IP address
port Server port (mandatory; there is no standard default port for SRT)
stream-id Stream identifier on the server
parameters Optional query parameters

General URI Format

Third-party SRT players and publishers typically use a URI format where the stream ID is specified as a query parameter:

srt://<host>:<port>[?<parameters>]

The stream ID is passed via the streamid query parameter. For example:

srt://server.example.com:21330?streamid=stream1

URI Examples

Standard SRT:

srt://server.example.com:21330?streamid=stream1

Standard SRT, VASTreaming style:

srt://server.example.com:21330/stream1

SRT with encryption:

srt://server.example.com:21330/stream1?passphrase=mysecretpassphrase

SRT with VASTreaming parameters:

srt://server.example.com:21330/stream1?vast-latency-ms=200&vast-latency-strategy=minimal

SRT with rendezvous handshake:

srt://peer.example.com:21330/stream1?vast-handshake-mode=rendezvous&vast-local-port=21330

SRT Client

The SrtClientSource class pulls media streams from SRT servers.

Usage

var source = new VAST.SRT.SrtClientSource();
source.Uri = "srt://server.example.com/live/stream1";

source.NewStream += (sender, e) =>
{
    Console.WriteLine($"Stream {e.StreamIndex}: {e.MediaType}");
};

source.NewSample += (sender, e) =>
{
    ProcessSample(e.Sample);
};

source.StateChanged += (sender, state) =>
{
    if (state == MediaState.Opened)
    {
        source.Start();
    }
};

source.Open();

URI Parameters

Parameter Default Description
passphrase or vast-passphrase none Encryption passphrase (10-79 characters)
streamid none Alternative stream ID specification (instead of URI path)
vast-latency-ms 120 Receiver latency in milliseconds
vast-local-ip auto Local IP address to bind the socket to
vast-local-port auto Local port to bind the socket to
vast-encryption-key-length 16 Encryption key length in bytes: 16, 24, or 32
vast-max-bandwidth 0 Maximum bandwidth in bits per second; 0 means no limit
vast-handshake-mode CallerListener Handshake mode: rendezvous
vast-send-buffer-duration 0 Send buffer duration in 100 ns units for smoothing delivery (max 10 seconds)
vast-stream-id-composition full Stream ID composition: full (use SRT metadata format) or simple (stream ID only)
vast-allow-custom-packets 0 Enable VASTreaming custom packets for extended features (0 or 1)
vast-media-format ts Media format: ts (Transport Stream), vb (VersatileBuffer), bin (Opaque Data); requires custom packets enabled
vast-latency-strategy Fixed Latency strategy: fixed, minimal, or zero; requires custom packets enabled
vast-allow-crc 0 Enable CRC on data packets; requires custom packets enabled (0 or 1)

Example:

source.Uri = "srt://server.example.com/live/stream1?vast-latency-ms=200&vast-latency-strategy=Minimal";

Interactive Playback

SrtClientSource implements IInteractiveMediaSource for interactive playback of VOD streams:

// Seek to position
source.Position = TimeSpan.FromMinutes(5);

// Pause and resume
source.Pause();
source.Start();

// Playback rate control
source.PlaybackRate = 2.0;   // Fast forward (2x)
source.PlaybackRate = 0.5;   // Slow motion (0.5x)

// Check duration and capabilities
Console.WriteLine($"Duration: {source.Duration}");
Console.WriteLine($"Can seek: {source.CanSeek}");
Console.WriteLine($"Can pause: {source.CanPause}");
Warning

SRT interactive features is a custom VASTreaming extension and works only between VASTreaming peers.

Playback Features

Feature Support
Seeking Timestamp-based positioning
Pause/Resume Full support
Playback Rate Variable speed playback
Looping Continuous playback
Multi-track Video, audio, subtitles/metadata

Playback Rates

Rate Description
double.MinValue As fast as possible in backward direction (no pacing)
-32 to -1 Rewind (backward playback)
0 to 1 (exclusive) Slow motion
1 Normal speed
1 to 32 Fast forward
double.MaxValue As fast as possible (no pacing)

Messaging

SrtClientSource implements IMessaging for exchanging text and binary messages with the remote peer.

Warning

Messaging is a custom VASTreaming extension and works only between VASTreaming peers.

source.MessagingSupportDetermined += (sender, supported) =>
{
    if (supported)
    {
        source.SendMessage("Hello from client");
    }
};

source.NewMessage += (sender, e) =>
{
    Console.WriteLine($"Message received: {e.Text}");
};

SRT Publisher

The SrtPublisherSink class pushes media streams to SRT servers.

Usage

var sink = new VAST.SRT.SrtPublisherSink();
sink.Uri = "srt://server.example.com/live/stream1";

sink.AddStream(0, videoMediaType);
sink.AddStream(1, audioMediaType);

sink.StateChanged += (sender, state) =>
{
    if (state == MediaState.Opened)
    {
        sink.Start();
    }
};

sink.Open();

// Push media samples
sink.PushMedia(0, videoSample);
sink.PushMedia(1, audioSample);

// When done
sink.Stop();

URI Parameters

The SRT publisher supports the same URI parameters as the SRT client.

Messaging

SrtPublisherSink implements IMessaging for exchanging text and binary messages with the remote peer.

Warning

Messaging is a custom VASTreaming extension and works only between VASTreaming peers.

sink.MessagingSupportDetermined += (sender, supported) =>
{
    if (supported)
    {
        sink.SendMessage("Hello from publisher");
    }
};

sink.NewMessage += (sender, e) =>
{
    Console.WriteLine($"Message received: {e.Text}");
};

File Transfer

The SRT library supports file transfers over SRT connections. Both SrtFileSender and SrtFileReceiver implement the IFileTransfer interface.

Note

File transfers must be enabled on the server side via AllowFileTransfers.

IFileTransfer Properties

Property Type Description
Uri string Server URI for the file transfer
FilePath string Local file path to send from or receive to. Either FilePath or Stream must be set, but not both
Stream Stream Stream to read from or write to. Either FilePath or Stream must be set, but not both
FileCreatedAt DateTime? For senders: set the creation date when using a user-defined stream; ignored when FilePath is set. For receivers: exposes the received file's creation date when present
FileModifiedAt DateTime? For senders: set the modification date when using a user-defined stream; ignored when FilePath is set. For receivers: exposes the received file's modification date when present
State MediaState Current file transfer state
Direction MediaFlowDirection Data flow direction (sending or receiving)
ErrorDescription string Error description; meaningful when ExecuteAsync returned false or the state is Error
EndPoint IPProtoEndPoint Remote endpoint information
InstanceId Guid Unique identifier for this transfer instance

IFileTransfer Events

Event Description
StateChanged Occurs when the transfer state changes

IFileTransfer Methods

Method Description
ExecuteAsync(CancellationToken?) Executes the file transfer asynchronously. Returns true if the transfer completed successfully; otherwise false. Accepts an optional CancellationToken to cancel the transfer

Sending Files

var sender = new VAST.SRT.SrtFileSender();
sender.Uri = "srt://server.example.com/files";
sender.FilePath = "C:\path\to\file.mp4";
bool result = await sender.ExecuteAsync();
if (result == false)
{
    Console.WriteLine($"Send failed: {sender.ErrorDescription}");
}

Receiving Files

var receiver = new VAST.SRT.SrtFileReceiver();
receiver.Uri = "srt://server.example.com/files";
receiver.FilePath = "C:\path\to\file.mp4";
bool result = await receiver.ExecuteAsync();
if (result == false)
{
    Console.WriteLine($"Receive failed: {receiver.ErrorDescription}");
}

Network Statistics

All SRT sources, sinks and file transfer objects implement INetworkStat for monitoring connection health and transfer metrics. Statistics are updated once per second, so polling more frequently will return the same data.

var stat = source.CurrentStat;
if (stat != null)
{
    Console.WriteLine($"Source stat: {stat}");
}
var stat = sink.CurrentStat;
if (stat != null)
{
    Console.WriteLine($"Sink stat: {stat}");
}

SRT Server

The SrtServer class accepts incoming SRT connections from both publishers (sending streams) and clients (receiving streams).

Note

SrtServer is not available as a standalone server. It operates as part of the VAST.Network.StreamingServer infrastructure and is instantiated by the StreamingServer automatically when enabled.

Integration with StreamingServer

When used as part of StreamingServer, the SRT server shares the network transport with other streaming protocols:

var server = new VAST.Network.StreamingServer();

// Enable SRT
server.EnableSrt = true;
server.SrtServerParameters = new VAST.SRT.SrtServerParameters();
server.SrtServerParameters.Instances.Add(new VAST.SRT.SrtServerInstanceParameters());

server.Start();

Server Parameters

Configure server behavior using SrtServerInstanceParameters:

Parameter Default Description
EndPoints Any:21330, IPv6Any:21330 Network endpoints to listen on for incoming connections
Passphrase null Encryption passphrase (10-79 characters); null disables encryption
EncryptionKeyLength 16 Encryption key length in bytes: 16, 24, or 32 (128/192/256-bit AES)
HandshakeMode CallerListener Handshake mode: CallerListener or Rendezvous
RemoteEndPoint null Remote endpoint for rendezvous handshakes; required when HandshakeMode is Rendezvous
LatencyStrategy Fixed Default latency strategy for receiver sessions: Fixed, Minimal, or Zero
AllowFileTransfers true Allow file transfers over SRT connections
IsSimpleInstance false Simple instance handles a single pre-defined publishing path and flow direction; can be used to serve primitive publishers and clients that do not support the stream ID concept
PublishingPath null Publishing path for simple instances; must be set when IsSimpleInstance is true
FlowDirection Unspecified Media flow direction: Input, Output, or Unspecified; must be set when IsSimpleInstance is true

Multiple Server Instances

Configure multiple SRT server instances with different settings (e.g., separate encrypted and unencrypted endpoints):

var parameters = new VAST.SRT.SrtServerParameters();

// Unencrypted instance
var instance1 = new VAST.SRT.SrtServerInstanceParameters();
instance1.EndPoints.Clear();
instance1.EndPoints.Add(new IPEndPoint(IPAddress.Any, 21330));

// Encrypted instance on a different port
var instance2 = new VAST.SRT.SrtServerInstanceParameters();
instance2.EndPoints.Clear();
instance2.EndPoints.Add(new IPEndPoint(IPAddress.Any, 21331));
instance2.Passphrase = "mysecretpassphrase";
instance2.EncryptionKeyLength = 32; // 256-bit AES

parameters.Instances.Add(instance1);
parameters.Instances.Add(instance2);

Encryption

Enable AES encryption by specifying a passphrase:

var instance = new VAST.SRT.SrtServerInstanceParameters();
instance.Passphrase = "mysecretpassphrase";
instance.EncryptionKeyLength = 16; // 128-bit (default), 24 (192-bit), or 32 (256-bit)

The passphrase must be between 10 and 79 characters. Encryption keys are derived using PBKDF2 and automatically refreshed during the session.

Latency Strategies

Strategy Description
Fixed Maintains the specified latency for smooth, consistent frame delivery (default)
Minimal Delivers frames as soon as possible after the last consecutive packet arrives
Zero Gives up lost packet retransmission for the lowest possible latency; can achieve lower than 100 ms latency on LAN
var instance = new VAST.SRT.SrtServerInstanceParameters();
instance.LatencyStrategy = SrtLatencyStrategy.Minimal;
Warning

Latency strategy Zero is a custom VASTreaming extension and requires VASTreaming peers on both sides.

Handshake Modes

Mode Description
CallerListener Standard client-server topology where the caller connects to the listener (default)
Rendezvous Both peers initiate connections simultaneously; useful for peer-to-peer scenarios with bidirectional NAT

For rendezvous mode, specify the remote endpoint:

var instance = new VAST.SRT.SrtServerInstanceParameters();
instance.IsSimpleInstance = true;
instance.PublishingPath = "/stream1";
instance.FlowDirection = MediaFlowDirection.Input;
instance.HandshakeMode = SrtHandshakeMode.Rendezvous;
instance.RemoteEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.200"), 21330);

Global Configuration

Configure library-wide settings using SrtGlobal:

Setting Default Description
TransferStatFrequencyUs 60000000 Transfer statistics reporting frequency in microseconds
RecvSocketBufferSize null Receive socket buffer size; null uses system default
SendSocketBufferSize null Send socket buffer size; null uses system default
DefaultSrtPort 21330 Default SRT port used by the library when not explicitly specified

Troubleshooting

Common Issues

Issue Cause Solution
Connection refused Wrong port or firewall Check if port is accessible
Encryption mismatch Different passphrases Verify passphrase matches on both sides
High latency Fixed strategy with high value Reduce vast-latency-ms or use Minimal strategy
Packet loss Network congestion Increase latency or reduce bitrate
File transfer rejected Transfers disabled on server Set AllowFileTransfers to true
Messaging not working Non-VASTreaming peer Messaging requires VASTreaming on both sides

See Also