Table of Contents

Class SystemVideoSourceBlock

Namespace
VisioForge.Core.MediaBlocks.Sources
Assembly
VisioForge.Core.dll

System video source block for native camera and video capture device access across platforms. Provides unified video capture from webcams, built-in cameras, and professional capture devices using platform-specific APIs (Camera2, DirectShow, Media Foundation, V4L2, AVFoundation) for live streaming, video recording, and real-time video processing applications. Implements the VisioForge.Core.MediaBlocks.Sources.SourceMediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.

public class SystemVideoSourceBlock : SourceMediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

Implements

Inherited Members

Extension Methods

Constructors

SystemVideoSourceBlock(VideoCaptureDeviceSourceSettings)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sources.SystemVideoSourceBlock class with custom capture settings. Configures the system video source for camera capture with specified device and format parameters.

public SystemVideoSourceBlock(VideoCaptureDeviceSourceSettings settings)

Parameters

settings VideoCaptureDeviceSourceSettings

The video capture settings controlling device selection, resolution, frame rate, and format parameters.

Remarks

The constructor does not verify that the specified device exists. On Android, prefer VisioForge.Core.MediaBlocks.Sources.SystemVideoSourceBlock.CreateWithDefaultDeviceAsync for reliable device selection.

Properties

Input

Gets the primary input pad (none for source blocks that capture from devices).

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets all input pads available on this block (none for source blocks).

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the primary video output pad for the captured video stream.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets all output pads available on this block (single video output for camera).

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Settings

Gets or sets the video capture device configuration settings that control device selection and capture parameters.

public VideoCaptureDeviceSourceSettings Settings { get; set; }

Property Value

VideoCaptureDeviceSourceSettings

Type

Gets the media block type identifier for system video source operations.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Builds and initializes the system video source within the pipeline context. Creates platform-specific video capture source, configures device parameters, and prepares video output for downstream processing.

public override bool Build()

Returns

bool

true if the system video source was successfully built and configured; otherwise, false.

CleanUp()

Cleans up all resources associated with the video capture operations, including device handles and capture buffers.

public void CleanUp()

CreateWithDefaultDeviceAsync()

Creates a new VisioForge.Core.MediaBlocks.Sources.SystemVideoSourceBlock configured with the first available video capture device.

public static Task<SystemVideoSourceBlock> CreateWithDefaultDeviceAsync()

Returns

Task<SystemVideoSourceBlock>

A configured VisioForge.Core.MediaBlocks.Sources.SystemVideoSourceBlock instance.

Dispose(bool)

Releases unmanaged and managed resources used by the system video source. Properly closes video device handles and disposes of GStreamer elements and capture resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetCore()

Gets the core GStreamer element wrapper for advanced configuration and monitoring.

public BaseElement GetCore()

Returns

BaseElement

Always null for composite source blocks with multiple internal elements.

GetDevicesAsync()

Gets the list of available video capture devices asynchronously. Enumerates all connected cameras, webcams, and capture devices on the current system with their capabilities.

public static Task<VideoCaptureDeviceInfo[]> GetDevicesAsync()

Returns

Task<VideoCaptureDeviceInfo[]>

A task that represents the asynchronous operation returning an array of VideoCaptureDeviceInfo containing device names, IDs, and supported formats.

GetElement()

Gets the native GStreamer element for direct GStreamer pipeline integration.

public Element GetElement()

Returns

Element

The system video source GStreamer element.

IsAvailable(VideoCaptureDeviceAPI)

Determines whether video capture support is available for the specified API on the current system. Requires platform-specific capture APIs and drivers to be available and functional.

public static bool IsAvailable(VideoCaptureDeviceAPI api)

Parameters

api VideoCaptureDeviceAPI

The video capture API to check (DirectShow, Media Foundation, V4L2, AVFoundation, etc.).

Returns

bool

true if video capture support is available for the specified API; otherwise, false.

TakePhotoAsync(FlashMode, bool)

Takes a still photo from the running camera into memory. iOS and Android, with VideoCaptureDeviceSourceSettings.EnablePhotoCapture set before the block is built.

public Task<byte[]> TakePhotoAsync(FlashMode flashMode = FlashMode.Disabled, bool duringRecording = false)

Parameters

flashMode FlashMode

Whether the flash fires. A camera without a flash unit takes the photo without it; on Android the torch, when on, stays on instead. On iOS the front camera lights the screen as its flash where the device has Retina Flash.

duringRecording bool

Android: true takes the photo as a video snapshot, which leaves a running recording undisturbed but may come from the video pipeline, at no better than the video quality on some devices; false (the default) uses the full still photo pipeline, which may delay one recorded frame at the moment of the photo. A flash photo always uses the still pipeline. iOS ignores it: a photo without the flash never disturbs the video.

Returns

Task<byte[]>

The encoded JPEG file bytes, or null if EnablePhotoCapture was not set, the block is not running, the camera cannot take a photo beside its video format, the capture failed or timed out (10 seconds), the camera was stopped, switched or resumed before the photo arrived (Android), or the platform has no still capture (every platform but iOS and Android).

Remarks

The photo comes from the photo pipeline of the camera the block already runs - an AVCapturePhotoOutput on the video's capture session on iOS, a JPEG ImageReader in the Camera2 capture session on Android - not from a video frame, at the largest size the camera supports beside the video format. The zoom, lens and torch set on the source apply. The video keeps running, so this works while previewing and while recording (on Android, see duringRecording). The bytes are only returned: nothing is written to a file or the photo library.

The photo is oriented from the orientation the source last applied (UpdateOrientation, or on its own with AutoUpdateOrientation); a front-camera photo is not mirrored. The orientation may be only the JPEG's EXIF Orientation tag, with the pixels left in sensor orientation - always on iOS, and on Android when the camera chooses so - so decode the bytes with a decoder that applies it (SkiaSharp's SKCodec.EncodedOrigin, for example), or the photo comes out sideways. On Android a flash photo first runs the auto-exposure precapture sequence, which takes up to 1.5 seconds longer, and is taken without the flash while the exposure is manual. While recording, the flash firing can drop a few recorded frames on both platforms (five over about a second on a Galaxy M55, two on an iPhone 16 Pro); a photo without the flash drops none.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Sets the pipeline context for this system video source, providing access to the parent pipeline and logging context.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The parent MediaBlocks pipeline containing this system video source.

See Also