Table of Contents

Simple Capture

The SimpleCapturePage demonstrates camera and microphone capture with local video preview and live streaming to a remote server. It covers device enumeration, capture mode selection, encoding configuration, device orientation handling, and audio level monitoring.

Overview

The SimpleCapturePage performs the following:

  1. Enumerates available video and audio capture devices on the current platform
  2. Displays capture mode options (resolution, framerate, sample rate, channels) for the selected devices
  3. Starts a local preview using VideoPreviewControl with configurable rendering strategy
  4. Streams captured media to a remote server (RTMP, RTSP, etc.) via MediaSession
  5. Monitors audio input levels using DeviceMonitor
  6. Handles device orientation changes by recreating capture sources with the correct rotation

Device Enumeration

this.videoDevices = await VAST.Capture.VideoDeviceEnumerator.Enumerate(
    VAST.Common.MediaFramework.Unknown);

this.audioDevices = await VAST.Capture.AudioDeviceEnumerator.Enumerate(
    VAST.Common.MediaFramework.Unknown);

Passing MediaFramework.Unknown enumerates devices from all available frameworks. Devices are prefixed with their framework type in the UI:

Prefix Framework
[MF] Media Foundation (Windows)
[DS] DirectShow (Windows)
[WASAPI] WASAPI (Windows audio)
[ASIO] ASIO (Windows audio)
[NDI] NDI

On mobile platforms (iOS, Android), devices are enumerated using the built-in framework and no prefix is shown. The "Front Camera" device is automatically selected if available.

Each video device exposes a list of capture modes with resolution, framerate, and pixel format. Each audio device exposes capture modes with sample rate, channels, and sample format.

Creating Capture Sources

this.activeVideoCaptureSource = VAST.Media.SourceFactory.CreateVideoCapture(
    this.videoDevice.DeviceId, this.videoCaptureMode);
this.activeVideoCaptureSource.Rotation = this.videoRotation;
this.activeVideoCaptureSource.AddRef();

this.activeAudioCaptureSource = VAST.Media.SourceFactory.CreateAudioCapture(
    this.audioDevice.DeviceId, this.audioCaptureMode);
this.activeAudioCaptureSource.AddRef();

Capture sources are created via SourceFactory with the selected device ID and capture mode. AddRef() is called because sources are shared between the preview and streaming sessions — both hold a reference, and the source is released only when both sessions are stopped.

Encoding Framework

The encoding framework can be configured:

Option Framework Description
Media Foundation MediaFoundation Windows built-in framework (Windows only)
FFmpeg FFmpeg FFmpeg encoders (all platforms)
Nvidia CUDA Nvidia NVENC (Windows only, requires Nvidia GPU)
Builtin Builtin Built-in framework (non-Windows platforms)

The selected framework is applied to both video and audio encoder parameters:

this.activeVideoCaptureSource.Parameters.VideoEncoderParameters.PreferredMediaFramework =
    VAST.Common.MediaFramework.MediaFoundation;
this.activeVideoCaptureSource.Parameters.VideoEncoderParameters.AllowHardwareAcceleration = true;

Local Preview

this.previewSession = new VAST.Media.MediaSession();
if (this.activeVideoCaptureSource != null) this.previewSession.AddSource(this.activeVideoCaptureSource);
if (this.activeAudioCaptureSource != null) this.previewSession.AddSource(this.activeAudioCaptureSource);
this.previewSession.Start();

this.activeVideoCaptureSource.Renderer = this.videoPreview.Renderer;

The preview session uses MediaSession with capture sources. The video is rendered by connecting the capture source's Renderer property to the VideoPreviewControl's renderer.

Rendering Strategy

Strategy Description
Low Latency Minimal latency at the expense of smoothness
Smooth Smooth playback at the expense of latency (can be several seconds)

Streaming

this.streamingSession = new VAST.Media.MediaSession();
if (this.activeVideoCaptureSource != null) this.streamingSession.AddSource(this.activeVideoCaptureSource);
if (this.activeAudioCaptureSource != null) this.streamingSession.AddSource(this.activeAudioCaptureSource);

VAST.Media.IMediaSink sink = VAST.Media.SinkFactory.Create(tboxServerUri.Text);
sink.Uri = tboxServerUri.Text;
this.streamingSession.AddSink(sink);
this.streamingSession.Start();

The streaming session connects the same capture sources to a network sink created by SinkFactory. The URI determines the protocol (RTMP, RTSP, SRT, etc.).

Output Type Switching

When streaming starts, the capture output is switched from uncompressed (preview-only) to encoded (H.264 video, AAC audio):

var mt = new VAST.Common.MediaType
{
    ContentType = VAST.Common.ContentType.Video,
    CodecId = VAST.Common.Codec.H264,
    Width = outputWidth,
    Height = outputHeight,
    Framerate = new VAST.Common.Rational(framerate),
    Bitrate = videoBitrate,
};
mt.Metadata.Add("KeyframeInterval", keyframeInterval.ToString());
mt.Metadata.Add("Profile", "66"); // baseline

await captureSource.SetDesiredOutputType(0, mt);

When streaming stops while preview remains active, the output switches back to uncompressed to save encoding resources. Video encoding parameters (bitrate, profile, level, keyframe interval) and audio encoding parameters (bitrate, sample rate, channels) are configurable through the UI.

Audio Level Monitoring

this.deviceMonitor = new VAST.Capture.DeviceMonitor(this.activeAudioCaptureSource);
this.deviceMonitor.MeterUpdated += DeviceMonitor_MeterUpdated;
this.deviceMonitor.Start();

DeviceMonitor monitors the audio input level and fires MeterUpdated events with a value from 0.0 to 1.0, which is displayed as a progress bar in the UI.

Device Orientation Handling

On mobile devices, the camera rotation must be adjusted when the device orientation changes. The page monitors orientation via OnSizeAllocated and recreates capture sources with the updated rotation:

this.activeVideoCaptureSource.Rotation = this.videoRotation;

The rotation mapping differs between platforms — on Windows, iOS, and Android, Rotation0 means portrait mode, while on macOS (Mac Catalyst), Rotation0 means landscape right.

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 simple capture 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