Struct RAWVideoFrame
- Namespace
- VisioForge.Core.Types
- Assembly
- VisioForge.Core.dll
Represents a raw video frame, designed for direct memory manipulation and interop scenarios. This struct holds a pointer to the raw video data, its size, and basic video format information, along with timing details.
public struct RAWVideoFrameInherited Members
Remarks
This struct is marked with [StructLayout(LayoutKind.Sequential)] to ensure its memory layout is compatible with unmanaged code.
It is primarily used for high-performance video processing where direct access to video buffers is required.
The VisioForge.Core.Types.RAWVideoFrame.Data field is an IntPtr, meaning memory management (allocation and deallocation) for the video data buffer
must be handled externally or by converting to VisioForge.Core.Types.VideoFrame which manages its own data.
This struct is commonly used in callbacks from native video components, video processing pipelines, or when interfacing with hardware encoders/decoders.
The timing fields (Timestamp and Duration) are in milliseconds for compatibility with native code, unlike the managed VideoFrame which uses TimeSpan.
The Alloc and Free methods provide manual memory management for scenarios where you need to create and populate frames from scratch.
When receiving a RAWVideoFrame from native code, ensure that the memory pointed to by Data remains valid for the duration of processing.
The ToVideoFrame method provides conversion to the managed VideoFrame type for easier manipulation in C# code.
Fields
Data
A pointer to the unmanaged memory buffer containing the raw video data.
public nint DataField Value
DataSize
The size of the raw video data buffer in bytes.
public int DataSizeField Value
Duration
The duration of the video frame in milliseconds.
public long DurationField Value
Info
Contains detailed information about the raw video format, such as width, height, color space, and stride.
public RAWBaseVideoInfo InfoField Value
Timestamp
The presentation timestamp of the video frame in milliseconds.
public long TimestampField Value
Methods
Alloc()
Allocates unmanaged memory for the video data buffer based on the Info.Stride and Info.Height. The VisioForge.Core.Types.RAWVideoFrame.DataSize field is updated accordingly.
public void Alloc()Remarks
This method should be called before writing pixel data to the VisioForge.Core.Types.RAWVideoFrame.Data pointer. It is crucial to call VisioForge.Core.Types.RAWVideoFrame.Free when the allocated memory is no longer needed.
Free()
Frees the unmanaged memory previously allocated for the video data buffer.
public void Free()Remarks
This method should always be called to prevent memory leaks when the RAWVideoFrame instance is no longer needed,
especially if VisioForge.Core.Types.RAWVideoFrame.Alloc was used.
ToVideoFrame()
Converts the current VisioForge.Core.Types.RAWVideoFrame instance into a VisioForge.Core.Types.VideoFrame object. This conversion facilitates working with the video frame in a more managed and object-oriented way.
public VideoFrame ToVideoFrame()Returns
- VideoFrame
-
A new VisioForge.Core.Types.VideoFrame instance populated with data from the raw frame.