Table of Contents

WinForms App Demo

The Demo.Streaming.WinForms project is a Windows Forms desktop application that demonstrates capture, playback, mixing, WebRTC communication, ONVIF device discovery, and PTZ camera control using the VASTreaming SDK.

Application Initialization

Program

static void Main()
{
    VAST.Common.License.Key = "YOUR_LICENSE_KEY";

    string appFolderPath = System.IO.Path.GetDirectoryName(
        new Uri(AppContext.BaseDirectory).LocalPath);
    VAST.Common.Log.LogLevel = VAST.Common.Log.Level.Debug;
    VAST.Common.Log.LogFileName = System.IO.Path.Combine(
        appFolderPath, "VAST.Demo.Streaming.log");

    VAST.Common.NtpTime.Sync().Wait();

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Startup());

    VAST.Media.MediaGlobal.Uninitialize();
}

The initialization performs the following:

  1. License — the license key must be set before any other VASTreaming operation
  2. Logging — configures the log file in the application folder
  3. NTP syncNtpTime.Sync() synchronizes the internal clock for accurate timestamp generation and sources synchronization
  4. Startup form — the Startup form is a launcher menu with buttons for each demo page
  5. CleanupMediaGlobal.Uninitialize() is called on exit to stop internal monitoring threads and release resources

Startup

The Startup form provides a button for each demo:

private void btnDemo1_Click(object sender, EventArgs e)
{
    var dialog = new Form1();
    dialog.ShowDialog();
}

Some demos require specific compilation symbols:

private void btnDemo2_Click(object sender, EventArgs e)
{
#if VAST_FEATURE_MIXING
    var dialog = new Form2();
    dialog.ShowDialog();
#endif
}

Demo Pages

The application provides the following demo pages, which cover the same functionality as the corresponding MAUI App Demo pages:

Form Description MAUI Equivalent
Form1 Camera/microphone capture and streaming Simple Capture
Form2 Advanced capture with video mixing and compositing Advanced Capture and Mixing
Form3 Basic media playback Simple Playback
Form4 Advanced playback with recording, snapshots, and ONVIF Advanced Playback
Form5 WebRTC playback from a server One-Way WebRTC

Form2 requires the VAST_FEATURE_MIXING compilation symbol. Form5 requires the VAST_FEATURE_WEBRTC compilation symbol.

The WinForms demo does not include equivalents for the Two-Way WebRTC and Embedded Server pages.

ONVIF Discovery and PTZ

The WinForms demo includes an ONVIF page (FormOnvif) accessible from Form4 (Advanced Playback). This page provides IP camera discovery and PTZ (Pan-Tilt-Zoom) control.

Device Discovery

this.discoveredDevices = await VAST.ONVIF.OnvifDiscovery.SearchAsync(5000);

SearchAsync scans the local network for ONVIF-compatible devices with a 5-second timeout. Discovered devices are displayed by IP address.

Connecting to a Device

After selecting a discovered device, the user provides credentials and scans for available services:

this.onvifClient = new VAST.ONVIF.OnvifClient2(device.OnvifAddress, username, password);
await this.onvifClient.OpenAsync();

The page first attempts to connect using ONVIF Profile 2 (OnvifClient2). If that fails, it falls back to Profile 1 (OnvifClient1). After a successful connection, the available stream URIs are listed. Double-clicking a stream URI loads it into the player for playback.

PTZ Control

The PTZ panel provides continuous movement controls via mouse press-and-hold:

this.cameraControl = this.onvifClient.CameraControl;

// Pan/Tilt — continuous movement while button is held
this.cameraControl.SetPanTiltSpeed(panSpeed, 0);   // left/right
this.cameraControl.SetPanTiltSpeed(0, panSpeed);    // up/down
this.cameraControl.StopPanTilt();                    // on mouse up

// Zoom — continuous zoom while button is held
this.cameraControl.SetZoomSpeed(zoomSpeed);          // zoom in
this.cameraControl.SetZoomSpeed(-zoomSpeed);         // zoom out
this.cameraControl.StopSmoothZoom();                 // on mouse up

PTZ features are enabled based on camera capabilities reported by the ICameraControl interface:

Feature Check Controls
Pan/Tilt IsPanTiltSupported Left, Right, Up, Down
Zoom IsZoomSpeedSupported Zoom In, Zoom Out
Presets IsPresetSupported Save Home, Recall Home, Save Preset, Recall Preset

ONVIF Snapshot

The page can capture a JPEG snapshot directly from the camera via ONVIF:

using (var jpegStream = await this.onvifClient.TakeSnapshot())
{
    // save jpegStream to file
}

Setup

  1. Set the license key in Program.cs:

    VAST.Common.License.Key = "YOUR_LICENSE_KEY";
    
  2. Run the application

See Also