Table of Contents

Class BufferSinkBlock

Namespace
VisioForge.Core.MediaBlocks.Sinks
Assembly
VisioForge.Core.dll

Implements a sink block that captures media data into memory buffers for processing or analysis. Provides frame-by-frame access to video, audio, or raw data through event callbacks.

public class BufferSinkBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

Implements

Inherited Members

Extension Methods

Remarks

The BufferSinkBlock is designed for scenarios where you need direct access to media frames in memory rather than writing to a file. It supports: - Video frame capture with format conversion - Audio frame capture with resampling - Raw data capture for custom media types - Frame dropping for performance optimization - Synchronization control for playback vs transcoding

Frame data is delivered through event callbacks, allowing real-time processing, analysis, or custom rendering. The block can be configured to drop frames when the processing cannot keep up with the media rate.

Common use cases include: - Video frame analysis and processing - Audio visualization - Custom rendering implementations - Media stream monitoring - Frame extraction for thumbnails

Constructors

BufferSinkBlock(VideoFormatX, bool)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.BufferSinkBlock class for video capture.

public BufferSinkBlock(VideoFormatX videoFormat, bool allowFrameDrop = false)

Parameters

videoFormat VideoFormatX

The desired video format for captured frames. Format conversion will be applied if needed.

allowFrameDrop bool

If set to true, allows dropping frames when processing cannot keep up.

Remarks

Use this constructor when you know you'll be capturing video frames and want to specify the output format. The sink will automatically convert incoming video to the specified format.

BufferSinkBlock(AudioFormatX, bool)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.BufferSinkBlock class for audio capture.

public BufferSinkBlock(AudioFormatX audioFormat, bool allowFrameDrop = false)

Parameters

audioFormat AudioFormatX

The desired audio format for captured frames. Resampling will be applied if needed.

allowFrameDrop bool

If set to true, allows dropping frames when processing cannot keep up.

Remarks

Use this constructor when you know you'll be capturing audio frames and want to specify the output format. The sink will automatically resample incoming audio to the specified format.

BufferSinkBlock()

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.BufferSinkBlock class with automatic format detection.

public BufferSinkBlock()

Remarks

Use this constructor when the media type is unknown or when you want to preserve the original format of the incoming media. The sink will adapt to whatever media type is connected to its input.

Fields

TAG

The logging tag used for error reporting and diagnostics.

protected const string TAG = "BufferSinkBlock"

Field Value

string

Properties

AllowFrameDrop

Gets or sets a value indicating whether frames can be dropped when processing cannot keep up.

public bool AllowFrameDrop { get; set; }

Property Value

bool

Remarks

Enable frame dropping when real-time processing is more important than capturing every frame. This is useful for live preview scenarios or when processing is computationally expensive.

Input

Gets the input pad for this sink.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets the inputs.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

IsSync

Gets or sets a value indicating whether media streams should be synchronized to real-time.

public bool IsSync { get; set; }

Property Value

bool

Remarks

When enabled, media is processed at its natural rate, maintaining proper timing for playback. When disabled, media is processed as fast as possible, which is ideal for transcoding or analysis.

Typical settings: - Playback/Preview: true (maintains proper frame timing) - Transcoding: false (processes as fast as possible) - Live capture: true (follows real-time constraints)

Output

Gets the output.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets the outputs.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Type

Gets the type of this media block.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Builds the buffer sink block and prepares it for capturing media frames.

public override bool Build()

Returns

bool

true if the build was successful; otherwise, false.

Remarks

This method:

  • Creates the appropriate buffer sink based on the media format
  • Registers event handlers for frame callbacks
  • Configures synchronization and frame dropping settings
  • Initializes the input pad for media reception

CleanUp()

Performs cleanup of resources used by the buffer sink.

public void CleanUp()

Remarks

This method releases the underlying GStreamer element and resets the build state. Any pending frames are discarded during cleanup.

Dispose(bool)

Releases unmanaged and - optionally - managed 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 core.

public BaseElement GetCore()

Returns

BaseElement

VisioForge.Core.GStreamer.Base.BaseElement.

GetElement()

Gets the element.

public Element GetElement()

Returns

Element

Gst.Element.

GetFilenameOrURL()

Gets the filename or URL for this sink.

public string GetFilenameOrURL()

Returns

string

Always returns null as buffer sinks don't write to files.

IsAvailable()

Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.

public static bool IsAvailable()

Returns

bool

true if this media block is available; otherwise, false.

SetFilenameOrURL(string)

Sets the filename or URL for this sink.

public void SetFilenameOrURL(string value)

Parameters

value string

The value to set (ignored).

Remarks

This method has no effect as buffer sinks capture to memory, not files. It exists to satisfy the IMediaBlockSink interface.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Sets the context.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The pipeline.

OnAudioFrameBuffer

Occurs when a new audio frame is captured and ready for processing.

public event EventHandler<AudioFrameBufferEventArgs> OnAudioFrameBuffer

Event Type

EventHandler<AudioFrameBufferEventArgs>

Remarks

The event provides access to the audio frame data in the specified format. Frame data includes audio samples, channel layout, sample rate, and timestamp. This event is only raised when the input is audio and OnSample is not subscribed.

OnDataFrameBuffer

Occurs when a new data frame is captured for non-audio/video media types.

public event EventHandler<DataFrameEventArgs> OnDataFrameBuffer

Event Type

EventHandler<DataFrameEventArgs>

Remarks

This event is used for custom media types like metadata, subtitles, or other data streams. The event provides raw access to the data buffer and timestamp information. This event is only raised when OnSample is not subscribed.

OnSample

Occurs when a new GStreamer sample is received, providing raw access to the media data.

public event EventHandler<Sample> OnSample

Event Type

EventHandler<Sample>

Remarks

This is a low-level event that provides direct access to GStreamer samples. When this event is subscribed, the higher-level events (OnVideoFrameBuffer, OnAudioFrameBuffer, OnDataFrameBuffer) will not be raised.

IMPORTANT: The sample must be disposed after processing to prevent memory leaks. Use this event only when you need direct GStreamer sample manipulation.

OnVideoFrameBuffer

Occurs when a new video frame is captured and ready for processing.

public event EventHandler<VideoFrameXBufferEventArgs> OnVideoFrameBuffer

Event Type

EventHandler<VideoFrameXBufferEventArgs>

Remarks

The event provides access to the video frame data in the specified format. Frame data includes pixel buffer, dimensions, format, and timestamp information. This event is only raised when the input is video and OnSample is not subscribed.

See Also