File / Stream Playback and KLV Extraction
File / Stream Playback
STANAG Player SDK supports playback from local files, low-latency streams, and HLS (HTTP Live Streaming) sources. HLS playback works with segment files stored either locally or on an HTTP server.
Below is an example of how to use the STANAG Player SDK in a STANAG 4609-compliant file or stream player application.
Playback Workflow
The playback process involves the following four steps:
| Phase | Description |
|---|---|
| Creating Instance | Create an instance of the player. |
| Setting Events | Register event handlers for playback, detection, frames, data, and errors. |
| Configure Params | Set the operational mode and other relevant configuration parameters. |
| Call Commands | Use commands such as Start, Stop, etc., to control playback. |
Use Case
The demo application accepts a stream URL or file path as an input parameter. It detects both video and KLV metadata and plays the video accordingly.
To perform this task, an instance of KlvPlayerLib is used.
Creating a Player Instance
Before creating the player, ensure all prerequisites are met.
To create a player instance, use the following code:
// Create Player instance
CKlvPlayer m_KlvPlayer = new CKlvPlayer();
Configuring Events
Set up event handlers to receive notifications from the player:
// Setup events
m_KlvPlayer.PlayerEvent += new NotifyPlayerEvent(OnPlayerEvent); // General player events notification
m_KlvPlayer.ErrorEvent += new NotifyError(OnErrorEvent); // Error notifications
m_KlvPlayer.PidDetectionEvent += new NotifyPidDetection(OnPidDetectionEvent); // PID detection for video, KLV, audio, or other data
m_KlvPlayer.SyncFrameEvent += new NotifySyncFrame(OnSyncFrameEvent); // Synchronized video frames, KLV, or private data
Initializing the Player
To initialize the player, follow the example below:
// Setup URL for network playback. You can pass multiple parameters via the URL.
// For example:
// udp://227.1.1.1:30120/nic=172.16.106.10/timeout=10000
// This allows setting the network interface (nic) and timeout in addition to the IP address and port.
Uri Url = new Uri(@"udp://227.1.1.1:30120");
// Configure caching time (in milliseconds).
// This controls the initial buffer duration:
// - Increase the value for smoother playback on unstable networks.
// - Decrease the value for lower latency.
m_KlvPlayer.Caching = 300;
// Initialize the player with the URL.
m_KlvPlayer.Init(Url.OriginalString);
Optional parameters:
m_KlvPlayer.RenderVideo - true / false // Set to true if you want to render the video, false if you don't need it (when you only need metadata or decoder frames)
m_KlvPlayer.RenderAudio - true / false // Set to true if you need audio processing.
m_KlvPlayer.VideoCaptureMode.uncompressedVideo -
UncompressedVideoMode_None
UncompressedVideoMode_Rgb
UncompressedVideoMode_Yuv
UncompressedVideoMode_Grayscale
m_KlvPlayer.VideoCaptureMode.fCompressedVideo - true / false // set to true if you don't need an uncompressed frame, but still want to get video timing info.
m_KlvPlayer.Hwnd // Window handle to render video to. If set to 0, the window will be created internally.
m_KlvPlayer.Caching - buffer size in ms // Caching for dejitter buffer. Set to minimal possible value to get a low latency stream playback,
m_KlvPlayer.MaxSyncDelay - buffer size in ms // Allowed Sync time for video / data synchronization
m_KlvPlayer.CalculatePacketRate - true / false // Enable / disable Calculation of average rate for received packets
Starting Playback
Once the player is initialized, you can start playback with a simple command:
// Start Playback
m_KlvPlayer.Start();
The video will be rendered in the window provided during the initialization phase. Additionally, the OnKlvDataEvent method will be triggered whenever KLV data is received.
Playback Events
During playback, any configured event handlers will be triggered as appropriate.
For a detailed list of playback events, see Playback Events