Table of Contents

Multi-Protocol Server

The ServerPage2 demonstrates a multi-protocol streaming server running within the MAUI application. Unlike the Simple RTSP Server which uses a single-protocol RtspServer, this page uses StreamingServer — a unified server that manages multiple streaming protocols simultaneously. It captures video and audio from local devices and serves the stream over RTMP, RTSP, SRT, HLS, and MPEG-DASH.

Overview

The ServerPage2 performs the following:

  1. Enumerates video and audio capture devices
  2. Creates a StreamingServer with multiple protocols enabled
  3. Captures from camera and microphone, encoding as H.264 video and AAC audio
  4. Creates a camera publishing point using AggregatedNetworkSource
  5. Serves the stream simultaneously over RTMP, RTSP, SRT, HLS, and MPEG-DASH
  6. Handles server lifecycle events (authorization, connections, errors, disconnections)

Creating the Server

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

The constructor parameter specifies the maximum number of concurrent connections. After creation, individual protocols are enabled and configured before calling Start().

Protocol Configuration

Each protocol is guarded by a compilation symbol and configured independently:

#if VAST_FEATURE_RTMP
server.EnableRtmp = true;
server.RtmpServerParameters.RtmpEndPoints.Add(new IPEndPoint(IPAddress.Any, 1935));
server.RtmpServerParameters.RtmpApplication = "live";
#endif

#if VAST_FEATURE_RTSP
server.EnableRtsp = true;
server.RtspServerParameters.AllowedRtpTransports = VAST.RTP.RtpTransportType.Any;
server.RtspServerParameters.RtspEndPoints.Add(new IPEndPoint(IPAddress.Any, 10554));
#endif

#if VAST_FEATURE_SRT
server.EnableSrt = true;
VAST.SRT.SrtServerInstanceParameters srtInstancePars = new VAST.SRT.SrtServerInstanceParameters
{
    IsSimpleInstance = true,
    PublishingPath = "camera",
    FlowDirection = VAST.Common.MediaFlowDirection.Output
};
srtInstancePars.EndPoints.Add(new IPEndPoint(IPAddress.Any, VAST.SRT.SrtGlobal.DefaultSrtPort));
server.SrtServerParameters.Instances.Add(srtInstancePars);
#endif

HTTP-based protocols (HLS, MPEG-DASH) share a common HTTP server:

server.EnableHttp = true;
server.HttpServerParameters = new VAST.HTTP.HttpServerParameters
{
    HttpPorts = { 8888 },
};

server.EnableHls = true;
server.HlsServerParameters = new VAST.HLS.HlsServerParameters
{
    HlsPath = "/hls",
    EnableLowLatency = false
};

server.EnableMpegDash = true;
server.DashServerParameters = new VAST.DASH.DashServerParameters
{
    MpegDashPath = "/dash"
};
Protocol Port URI Pattern Feature Flag
RTMP 1935 rtmp://{ip}:1935/live/camera VAST_FEATURE_RTMP
RTSP 10554 rtsp://{ip}:10554/camera VAST_FEATURE_RTSP
SRT 21330 srt://{ip}:21330 VAST_FEATURE_SRT
HLS 8888 http://{ip}:8888/hls/camera VAST_FEATURE_HLS
MPEG-DASH 8888 http://{ip}:8888/dash/camera VAST_FEATURE_MPEG_DASH

JSON API

The server can optionally expose a JSON management API:

server.EnableJsonApi = true;
server.ApiServerParameters.Users.Add("admin", "admin");

The API shares the HTTP server port and provides administrative access to manage publishing points at runtime.

Server Events

The server raises events for connection lifecycle management:

server.PublishingPointRequested += Server_PublishingPointRequested;
server.Authorize += Server_Authorize;
server.PublisherConnected += Server_PublisherConnected;
server.ClientConnected += Server_ClientConnected;
server.Error += Server_Error;
server.Disconnected += Server_Disconnected;
Event Description
PublishingPointRequested A client requested a publishing point that doesn't exist — user code can create on-demand publishing points here
Authorize Connection type has been detected — set ConnectionInfo.IsValid to accept or reject
PublisherConnected A publisher or pull source is ready — the publishing point can start forwarding or recording
ClientConnected A new viewer has connected
Error A session encountered an unrecoverable error and will be closed
Disconnected A connection has been closed

Creating the Capture Publishing Point

After the server starts, a capture source publishing point named camera is created on a background thread:

VAST.Network.AggregatedNetworkSource source = new VAST.Network.AggregatedNetworkSource();

VAST.Capture.IVideoCaptureSource2 videoSource =
    VAST.Media.SourceFactory.CreateVideoCapture(this.videoDevice.DeviceId, this.videoCaptureMode);
videoSource.Rotation = this.videoRotation;

VAST.Common.MediaType mt = new VAST.Common.MediaType
{
    ContentType = VAST.Common.ContentType.Video,
    CodecId = VAST.Common.Codec.H264,
    Bitrate = videoBitrate,
    Width = width,
    Height = height,
    Framerate = new VAST.Common.Rational(framerate),
};
mt.Metadata.Add("KeyframeInterval", videoKeyframeInterval.ToString());
await videoSource.SetDesiredOutputType(0, mt);
source.AddSource(videoSource);

// ... audio capture source configured similarly with AAC encoding ...

this.server.CreatePublishingPoint("camera", source);

The key difference from Simple RTSP Server is that CreatePublishingPoint hands off the source to the StreamingServer, which manages distribution to clients across all enabled protocols. There is no need to manually track connected clients or distribute media samples — the server handles this internally.

Video encoding parameters (resolution, bitrate, profile, level, keyframe interval) and audio encoding parameters (sample rate, channels, bitrate) are configurable through the UI. The encoding framework options are the same as in the Simple Capture page.

Advanced Publishing Point Scenarios

The startServer() method includes commented-out examples of additional publishing point types:

Scenario Description
Pull source Creates a publishing point that pulls from a remote URI
VOD file Serves a single MP4 file for on-demand playback via HLS or MPEG-DASH
VOD directory Serves all MP4 files from a directory
File loop Loops a single file as a continuous live stream
Image source Generates a live stream from a still image
Pre-encoded push Accepts pre-encoded media data from user code
Mixing Creates a transcoding publishing point with multiple video quality tracks
Proxy transcode Re-encodes a pull stream to a different codec or quality

Device Orientation

On mobile devices, the camera rotation is adjusted when the device orientation changes. The page monitors orientation via OnSizeAllocated and restarts the server with the updated rotation.

Send Log

The page includes a Send Log button that uploads the application log file to VASTreaming support for diagnostics:

await VAST.Common.License.SendLog("MAUI server #2 issue");

SendLog sends the current log file to the support server. A valid license key must be configured for this feature to work.

See Also