Class VideoRendererBlock
- Assembly
- VisioForge.Core.dll
Cross-platform video renderer block providing display output for video streams. This block serves as the final destination for video in a media pipeline, rendering frames to various display surfaces across different platforms and UI frameworks. Features include hardware-accelerated rendering using platform-specific APIs (Direct3D 11 on Windows, OpenGL ES on mobile, Metal on Apple platforms), support for multiple UI frameworks (WPF, WinForms, MAUI, WinUI, Android Views, iOS/macOS views), subtitle overlay rendering, snapshot capture functionality, frame stepping, and playback rate control. The renderer automatically selects the optimal rendering path based on the platform and UI framework, providing native performance while maintaining a consistent API. Essential for media players, video editors, streaming clients, video conferencing apps, and any application requiring high-quality video display with minimal latency. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.
public class VideoRendererBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals, IMediaBlockRenderer, IGetVideoStreamInfoInheritance
Implements
Inherited Members
Extension Methods
Constructors
VideoRendererBlock(MediaBlocksPipeline, IVideoView)
Initializes a new instance of the VisioForge.Core.MediaBlocks.VideoRendering.VideoRendererBlock class.
public VideoRendererBlock(MediaBlocksPipeline pipeline, IVideoView videoView)Parameters
pipelineMediaBlocksPipeline-
Tthe pipeline.
videoViewIVideoView-
The video view.
VideoRendererBlock(MediaBlocksPipeline, nint)
Initializes a new instance of the VisioForge.Core.MediaBlocks.VideoRendering.VideoRendererBlock class.
public VideoRendererBlock(MediaBlocksPipeline pipeline, nint windowHandle)Parameters
pipelineMediaBlocksPipeline-
Tthe pipeline.
windowHandlenint-
The window handle.
Properties
Input
Gets the input.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets the inputs.
public override MediaBlockPad[] Inputs { get; }Property Value
IsLive
Gets or sets a value indicating whether the upstream source is inherently live
(e.g. NDI capture on Android driving an appsrc, or any other live appsrc-based source).
When true, the underlying appsink is configured with async=false so the
pipeline does not deadlock waiting for a preroll buffer that a live source will never
deliver. Default is false to preserve the standard preroll behaviour required
for file playback (start-position seek, snapshot/preload).
public bool IsLive { get; set; }Property Value
Remarks
Backed by an Int32 field with Volatile.Read /
Volatile.Write rather than a plain auto-property
because IsLive is read on the build thread (during Init) while sometimes set
on a different thread (caller flips it from a callback after construction).
On ARM/ARM64 a torn-bool read is observable; using volatile int with explicit
0/1 sentinel guarantees acquire/release semantics across cores.
IsSync
Gets or sets a value indicating whether to synchronize video rendering with the pipeline clock. Should be true for real-time playback to maintain audio/video sync, false for offline processing or transcoding where maximum throughput is desired.
public bool IsSync { get; set; }Property Value
Output
Gets the output.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets the outputs.
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets or sets the video renderer configuration settings. Contains platform-specific rendering options, performance tuning parameters, and display preferences such as aspect ratio handling and scaling mode.
public VideoRendererSettingsX Settings { get; set; }Property Value
SubtitleEnabled
Gets or sets a value indicating whether subtitle rendering is enabled. When enabled, subtitles from the stream or external file will be overlaid on the video.
public bool SubtitleEnabled { get; set; }Property Value
SubtitleExternalFile
Gets or sets the path to an external subtitle file (optional). Supports common subtitle formats like SRT, ASS, VTT. Takes precedence over embedded subtitles.
public string SubtitleExternalFile { get; set; }Property Value
SubtitleSettings
Gets or sets the subtitle overlay configuration settings. Contains font, color, position, and styling options for subtitle rendering.
public SubtitleOverlaySettings SubtitleSettings { get; set; }Property Value
Type
Gets the type.
public override MediaBlockType Type { get; }Property Value
Methods
Build()
Builds this instance.
public override bool Build()Returns
- bool
-
trueif successfull,falseotherwise.
CleanUp()
Releases all resources and performs cleanup operations for this video renderer block. This method disposes of rendering elements, clears frame buffers, and releases display resources.
public void CleanUp()ClearHandle()
Clears the window handle or display surface association. Call this before changing the rendering target or when the display window is destroyed.
public void ClearHandle()Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
FrameStep(int, double)
Advances the video by a specified number of frames. Useful for frame-accurate seeking and video analysis applications.
public bool FrameStep(int framesCount, double rate)Parameters
framesCountint-
The number of frames to advance.
ratedouble-
The rate at which to perform the frame step.
Returns
- bool
-
trueif frame stepping was successful;falseotherwise.
GetCore()
Gets the core BaseElement wrapper that provides additional functionality around the platform-specific video renderer element.
public BaseElement GetCore()Returns
- BaseElement
-
The BaseElement wrapper instance that encapsulates the video renderer.
GetElement()
Gets the underlying GStreamer element that performs video rendering.
public Element GetElement()Returns
- Element
-
The GStreamer Element instance representing the video renderer, or the BufferSink element when the renderer is operating in callback/buffer-sink mode (e.g. CallbackVideoView). Returns null only if neither path is initialised.
GetVideoStreamInfo()
Gets detailed information about the current video stream being rendered. Includes resolution, frame rate, pixel format, and codec information.
public VideoStreamInfo GetVideoStreamInfo()Returns
- VideoStreamInfo
-
VideoStreamInfo containing stream metadata, or null if no stream is active.
GetVideoView()
Gets the video view interface associated with this renderer.
public IVideoView GetVideoView()Returns
- IVideoView
-
The IVideoView instance used for rendering, or null if using window handle.
IsAvailable()
Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.
public static bool IsAvailable()Returns
- bool
-
trueif this media block is available; otherwise,false.
SetLetterbox(bool)
Sets the letterbox (force-aspect-ratio) mode at runtime. When enabled, the video maintains its original aspect ratio by adding black bars if necessary. When disabled, the video is stretched to fill the display area.
public void SetLetterbox(bool letterbox)Parameters
letterboxbool-
trueto preserve aspect ratio (letterbox);falseto stretch to fill.
SetOutputSize(int, int)
Updates the output size requested by the attached view without rebuilding the pipeline.
public void SetOutputSize(int width, int height)Parameters
SetRate(double, Pipeline)
Sets the playback rate for the video renderer. Supports variable speed playback including slow motion and fast forward.
public bool SetRate(double rate, Pipeline pipeline)Parameters
ratedouble-
The playback rate (1.0 = normal, 0.5 = half speed, 2.0 = double speed).
pipelinePipeline-
The GStreamer pipeline containing this renderer.
Returns
- bool
-
trueif the rate was successfully set;falseotherwise.
Snapshot_Get()
Gets the snapshot as SKBitmap.
public SKBitmap Snapshot_Get()Returns
- SKBitmap
-
SKBitmap.
Snapshot_GetAsync()
Gets the snapshot as SKBitmap (async).
public Task<SKBitmap> Snapshot_GetAsync()Returns
Snapshot_Save(string, SKEncodedImageFormat, int)
Saves snapshot to a file.
public bool Snapshot_Save(string filename, SKEncodedImageFormat format, int quality = 85)Parameters
filenamestring-
File name.
formatSKEncodedImageFormat-
Format.
qualityint-
Quality.
Returns
- bool
-
trueif successful,falseotherwise.
Snapshot_SaveAsync(string, SKEncodedImageFormat, int)
Saves snapshot to a file (async).
public Task<bool> Snapshot_SaveAsync(string filename, SKEncodedImageFormat format, int quality = 85)Parameters
filenamestring-
File name.
formatSKEncodedImageFormat-
Format.
qualityint-
Quality.
Returns
UpdateSubtitleOverlay(SubtitleOverlaySettings)
Updates the subtitle overlay settings in real-time. Changes take effect immediately without interrupting video playback.
public void UpdateSubtitleOverlay(SubtitleOverlaySettings settings)Parameters
settingsSubtitleOverlaySettings-
The new subtitle overlay settings to apply.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Associates this video renderer block with a pipeline and initializes its internal context. This method is called internally when the block is added to a pipeline.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The MediaBlocksPipeline instance that will manage this block.