Table of Contents

Interface ICustomVideoSource

Namespace
VisioForge.Core.Types.VideoCapture
Assembly
VisioForge.Core.dll

Defines the interface for custom video sources that can provide video frames to the capture pipeline.

[JsonInterfaceConverter(typeof(JsonInterfaceConverter<ICustomVideoSource>))]
public interface ICustomVideoSource

Remarks

This interface enables developers to create custom video sources from various inputs such as IP cameras, screen capture, generated graphics, or any other video data source. Implementations must handle frame generation, format specification, and event notification. The video source can be used as an input device in video capture and processing scenarios.

Properties

VideoFrameRate

Gets or sets the frame rate of the video stream in frames per second.

float VideoFrameRate { get; set; }

Property Value

float

Remarks

Common frame rates include 15, 24, 25, 29.97, 30, 50, 59.94, and 60 fps. The actual frame rate may vary depending on the source's capabilities and system performance.

VideoHeight

Gets or sets the height of the video frames in pixels.

int VideoHeight { get; set; }

Property Value

int

Remarks

This value should be set before starting the video source and should remain constant during capture. Common values include 480, 720, 1080, etc.

VideoWidth

Gets or sets the width of the video frames in pixels.

int VideoWidth { get; set; }

Property Value

int

Remarks

This value should be set before starting the video source and should remain constant during capture. Common values include 640, 1280, 1920, etc.

Methods

GetCameraInfo(string, string, string, out string, out Size)

Retrieves information about a camera or video source from the specified URL.

bool GetCameraInfo(string url, string username, string password, out string error, out Size videoSize)

Parameters

url string

The URL or connection string for the video source (e.g., RTSP URL, HTTP stream URL).

username string

The username for authentication, if required by the video source. Pass null or empty string if authentication is not needed.

password string

The password for authentication, if required by the video source. Pass null or empty string if authentication is not needed.

error string

When the method returns false, contains an error message describing the connection or authentication failure. When successful, this is set to null or empty string.

videoSize Size

When successful, contains the native video size reported by the source. This helps in configuring the VideoWidth and VideoHeight properties appropriately.

Returns

bool

true if the camera information was successfully retrieved; otherwise, false.

Remarks

This method is typically used to validate connection parameters and retrieve source capabilities before starting the video stream. It's particularly useful for IP cameras and network video sources that require authentication.

Start()

Starts the video source and begins generating or capturing video frames.

void Start()

Remarks

This method should initialize any necessary resources, establish connections, and begin the frame generation process. After calling this method, the source should either respond to VideoFillBuffer calls or raise OnVideoBuffer events with video frame data. The VideoWidth, VideoHeight, and VideoFrameRate properties should be properly configured before calling this method.

VideoFillBuffer(RAWVideoFrame)

Fills the provided frame buffer with video data.

void VideoFillBuffer(RAWVideoFrame frame)

Parameters

frame RAWVideoFrame

The RAWVideoFrame object to be filled with video data.

Remarks

This method is called by the framework to retrieve video frames from the custom source. The implementation should copy the current video frame data into the provided buffer, respecting the frame's format and dimensions. This method should be thread-safe and performant as it may be called frequently based on the frame rate.

OnVideoBuffer

Occurs when a new video frame is available from the source.

event EventHandler<VideoFrameBufferEventArgs> OnVideoBuffer

Event Type

EventHandler<VideoFrameBufferEventArgs>

Remarks

This event allows the custom video source to push frames to the pipeline instead of being polled via VideoFillBuffer. Subscribers can process the frame data provided in the VideoFrameBufferEventArgs. This is useful for sources that generate frames asynchronously or at irregular intervals.