Class VideoFrameX
- Namespace
- VisioForge.Core.Types.X
- Assembly
- VisioForge.Core.dll
Represents a single video frame within the VisioForge MediaBlocks framework. This class extends VisioForge.Core.Types.X.VideoFrameInfoX to include the actual pixel data, timestamp, and duration.
public class VideoFrameX : VideoFrameInfoXInheritance
Inherited Members
Extension Methods
Examples
// Create a new VideoFrameX instance and allocate memory for a 1280x720 RGB frame.
var frame = VideoFrameX.Alloc(1280, 720, 1280 * 3, VideoFormatX.RGB);
try
{
// Set timestamp and duration
frame.Timestamp = TimeSpan.FromSeconds(10);
frame.Duration = TimeSpan.FromMilliseconds(40);
// Fill the frame with some data (e.g., a solid color)
byte[] pixelData = new byte[frame.DataSize];
// ... populate pixelData ...
System.Runtime.InteropServices.Marshal.Copy(pixelData, 0, frame.Data, frame.DataSize);
Console.WriteLine($"Created VideoFrameX: {frame.Width}x{frame.Height} {frame.Format} at {frame.Timestamp}");
// Convert to a legacy VideoFrame type
VideoFrame legacyFrame = frame.ToVideoFrame();
// Create a clone of the frame
VideoFrameX clonedFrame = frame.Clone();
}
finally
{
frame.Free(); // Always free allocated unmanaged memory
}
Remarks
VideoFrameX is designed for efficient handling of video frames in a pipeline, supporting direct memory access for performance.
It provides methods for memory allocation, deallocation, data copying, and conversion to other frame types.
Proper memory management using VisioForge.Core.Types.X.VideoFrameX.Alloc and VisioForge.Core.Types.X.VideoFrameX.Free is crucial to prevent memory leaks.
Constructors
VideoFrameX(byte[], int, int, int, VideoFormatX)
Initializes a new instance of the VisioForge.Core.Types.X.VideoFrameX class with a byte array of data. Memory is allocated and data is copied from the provided byte array.
public VideoFrameX(byte[] data, int width, int height, int stride, VideoFormatX format)Parameters
databyte[]-
The byte array containing the video data.
widthint-
The width of the video frame.
heightint-
The height of the video frame.
strideint-
The stride (bytes per row) of the video frame.
formatVideoFormatX-
The VisioForge.Core.Types.X.VideoFormatX of the video frame.
VideoFrameX(int[], int, int, int, VideoFormatX)
Initializes a new instance of the VisioForge.Core.Types.X.VideoFrameX class with an integer array of data. Memory is allocated and data is copied from the provided integer array.
public VideoFrameX(int[] data, int width, int height, int stride, VideoFormatX format)Parameters
dataint[]-
The integer array containing the video data.
widthint-
The width of the video frame.
heightint-
The height of the video frame.
strideint-
The stride (bytes per row) of the video frame.
formatVideoFormatX-
The VisioForge.Core.Types.X.VideoFormatX of the video frame.
VideoFrameX(nint, int, int, int, int, VideoFormatX)
Initializes a new instance of the VisioForge.Core.Types.X.VideoFrameX class with an existing unmanaged data pointer. This constructor does not allocate new memory; it uses the provided pointer directly.
public VideoFrameX(nint data, int dataSize, int width, int height, int stride, VideoFormatX format)Parameters
datanint-
A pointer to the raw video data buffer.
dataSizeint-
The size of the data buffer in bytes.
widthint-
The width of the video frame.
heightint-
The height of the video frame.
strideint-
The stride (bytes per row) of the video frame.
formatVideoFormatX-
The VisioForge.Core.Types.X.VideoFormatX of the video frame.
VideoFrameX()
Initializes a new instance of the VisioForge.Core.Types.X.VideoFrameX class with default values. No memory is allocated by this constructor.
public VideoFrameX()Properties
Caps
Gets or sets the GStreamer caps string that describes the media format of this frame.
public string Caps { get; set; }Property Value
Data
Gets or sets a pointer to the unmanaged memory buffer containing the raw video data.
public nint Data { get; set; }Property Value
DataSize
Gets or sets the total size of the video data buffer in bytes.
public int DataSize { get; set; }Property Value
Duration
Gets or sets the duration of the video frame.
public TimeSpan Duration { get; set; }Property Value
Timestamp
Gets or sets the presentation timestamp of the video frame.
public TimeSpan Timestamp { get; set; }Property Value
Methods
Alloc()
Allocates unmanaged memory for the video data buffer based on the VisioForge.Core.Types.X.VideoFrameInfoX.Stride and VisioForge.Core.Types.X.VideoFrameInfoX.Height. The VisioForge.Core.Types.X.VideoFrameX.DataSize field is updated accordingly.
public void Alloc()Remarks
This method should be called before writing pixel data to the VisioForge.Core.Types.X.VideoFrameX.Data pointer. It is crucial to call VisioForge.Core.Types.X.VideoFrameX.Free when the allocated memory is no longer needed.
Alloc(int, int, int, VideoFormatX)
Allocates unmanaged memory for the video data buffer with a specified size.
public static VideoFrameX Alloc(int width, int height, int stride, VideoFormatX format)Parameters
widthintheightintstrideintformatVideoFormatX
Returns
Alloc(int)
public void Alloc(int size)Parameters
sizeint-
The number of bytes to allocate for the video data.
Remarks
This overload allows for direct control over the allocated buffer size, which can be useful for custom formats.
ClearPixels()
Clears the pixel data of the video frame by setting all bytes in the data buffer to zero.
public void ClearPixels()Clone()
Creates a deep copy of the current VisioForge.Core.Types.X.VideoFrameX instance. This involves allocating new memory for the data and copying all frame properties and pixel data.
public VideoFrameX Clone()Returns
- VideoFrameX
-
A new VisioForge.Core.Types.X.VideoFrameX instance that is a clone of the current one.
CopyFrom(VideoFrameX)
Copies all information and pixel data from a source VisioForge.Core.Types.X.VideoFrameX to the current instance. If the data buffer size differs, the current instance's buffer will be reallocated.
public void CopyFrom(VideoFrameX frame)Parameters
frameVideoFrameX-
The source VisioForge.Core.Types.X.VideoFrameX to copy from.
CopyInfoFrom(VideoFrameX)
Copies the metadata (dimensions, format, timing, caps) from another VisioForge.Core.Types.X.VideoFrameX instance to the current VisioForge.Core.Types.X.VideoFrameX instance. This method does not copy the actual pixel data.
public void CopyInfoFrom(VideoFrameX frame)Parameters
frameVideoFrameX-
The source VisioForge.Core.Types.X.VideoFrameX instance to copy information from.
CopyInfoTo(ref VideoFrameX)
Copies the metadata (dimensions, format, timing, caps) from the current VisioForge.Core.Types.X.VideoFrameX instance to another VisioForge.Core.Types.X.VideoFrameX instance. This method does not copy the actual pixel data.
public void CopyInfoTo(ref VideoFrameX frame)Parameters
frameVideoFrameX-
The target VisioForge.Core.Types.X.VideoFrameX instance to copy information to.
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 VideoFrameX instance is no longer needed,
especially if VisioForge.Core.Types.X.VideoFrameX.Alloc or VisioForge.Core.Types.X.VideoFrameX.Alloc(System.Int32) was used.
IsEmpty()
Determines whether this VisioForge.Core.Types.X.VideoFrameX instance is empty (i.e., its VisioForge.Core.Types.X.VideoFrameX.Data pointer is Zero).
public bool IsEmpty()Returns
- bool
-
trueif this instance is empty; otherwise,false.
ToArray()
Converts the raw video data from the unmanaged buffer into a new managed byte array.
public byte[] ToArray()Returns
- byte[]
-
A new byte array containing the frame's video data.
ToVideoFrame()
Converts the current VisioForge.Core.Types.X.VideoFrameX instance into a legacy VisioForge.Core.Types.VideoFrame object. This conversion is useful for compatibility with older parts of the framework or external components.
public VideoFrame ToVideoFrame()Returns
- VideoFrame
-
A new VisioForge.Core.Types.VideoFrame instance populated with data from the current frame.