Table of Contents

Class UniversalDemuxDecoderBlock

Namespace
VisioForge.Core.MediaBlocks.Special
Assembly
VisioForge.Core.dll

A unified demuxer and decoder block that handles the complete pipeline from source to decoding. This block uses UniversalSourceSettings and automatically selects appropriate demuxers, parsers, and decoders based on the actual capabilities reported by GStreamer elements.

public class UniversalDemuxDecoderBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

Implements

Inherited Members

Extension Methods

Constructors

UniversalDemuxDecoderBlock(UniversalSourceSettings)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Special.UniversalDemuxDecoderBlock class.

public UniversalDemuxDecoderBlock(UniversalSourceSettings settings)

Parameters

settings UniversalSourceSettings

The UniversalSourceSettings containing source URI and rendering options.

Properties

AudioOutput

Gets the output pad that delivers decoded audio samples, or null if audio rendering is disabled.

public MediaBlockPad AudioOutput { get; }

Property Value

MediaBlockPad

Input

Gets the primary input pad. Always null because this block reads directly from a file or URI.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets all input pads. Returns an empty array because this block sources data from a file.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the first available output pad in priority order: video, then audio, then subtitle.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets all output pads that were enabled via the settings passed to the constructor.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Settings

Gets the UniversalSourceSettings used for this block.

public UniversalSourceSettings Settings { get; }

Property Value

UniversalSourceSettings

SubtitleOutput

Gets the output pad that delivers subtitle data, or null if subtitle rendering is disabled.

public MediaBlockPad SubtitleOutput { get; }

Property Value

MediaBlockPad

Type

Gets the media block type identifier for this demux/decoder block.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

VideoOutput

Gets the output pad that delivers decoded video frames, or null if video rendering is disabled.

public MediaBlockPad VideoOutput { get; }

Property Value

MediaBlockPad

Methods

Build()

Builds the demux/decoder pipeline by creating the file source, typefind, and output queue elements. Actual demuxer and decoder creation happens asynchronously when the typefind element reports the stream type.

public override bool Build()

Returns

bool

true if the initial pipeline graph was constructed successfully; false otherwise.

CreateAsync(Uri, bool, bool, bool)

Creates a UniversalDemuxDecoderBlock from a URI.

public static Task<UniversalDemuxDecoderBlock> CreateAsync(Uri uri, bool renderVideo = true, bool renderAudio = true, bool renderSubtitle = false)

Parameters

uri Uri
renderVideo bool
renderAudio bool
renderSubtitle bool

Returns

Task<UniversalDemuxDecoderBlock>

CreateAsync(string, bool, bool, bool)

Creates a UniversalDemuxDecoderBlock from a file path.

public static Task<UniversalDemuxDecoderBlock> CreateAsync(string filePath, bool renderVideo = true, bool renderAudio = true, bool renderSubtitle = false)

Parameters

filePath string
renderVideo bool
renderAudio bool
renderSubtitle bool

Returns

Task<UniversalDemuxDecoderBlock>

Dispose(bool)

Releases unmanaged and - optionally - managed resources. Override this method in derived classes to implement block-specific cleanup logic.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

An override must call its CleanUp() only under disposing. VisioForge.Core.MediaBlocks.MediaBlock.Finalize reaches this method with false, and a block's CleanUp() releases GstSharp wrappers - which takes GStreamer locks and can block - on the finalizer thread, which must never do either. A block that is never disposed leaves its elements to the pipeline that owns them; that is what their toggle refs are for. base.Dispose(disposing) stays outside the guard, because the latch below has to be set on both paths. The one carve-out is a block holding a resource nothing else can release - a device handle, say, which no pipeline owns and no toggle ref reclaims; such a block may run its CleanUp() on the finalizer path, guarded against throwing, and has to say why at the call site (see AndroidUVCSourceBlock). GitHub issue #958.

IMediaBlockInternals.Build()

Constructs and initializes the underlying GStreamer elements for this MediaBlock. This method creates the necessary GStreamer components, configures their properties, and prepares the block for integration into the pipeline. Must be called before the block can process media.

bool IMediaBlockInternals.Build()

Returns

bool

True if the block was successfully built and all required elements were created; false if construction failed.

IMediaBlockInternals.CleanUp()

Releases the GStreamer elements this MediaBlock created in VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build and returns the block to a re-buildable state. Called automatically during pipeline teardown.

void IMediaBlockInternals.CleanUp()

Remarks

A stopped pipeline can be started again on the same instance, in which case VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build runs a second time on this very block. So the contract is:

  • clear the build latch, so VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build does not short-circuit;
  • release everything VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build created, since VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build will create it again;
  • do NOT release anything VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build cannot recreate - state built in the constructor, user configuration, and event subscriptions belong to Dispose(bool).
Releasing constructor-owned state here makes the second run silently produce no data: the null-conditional code in VisioForge.Core.MediaBlocks.IMediaBlockInternals.Build succeeds while owning nothing.

IMediaBlockInternals.GetCore()

Retrieves the core BaseElement wrapper that provides additional functionality around the GStreamer element. This wrapper adds VisioForge-specific features and simplifies common operations on the underlying GStreamer element.

BaseElement IMediaBlockInternals.GetCore()

Returns

BaseElement

The BaseElement wrapper instance that encapsulates the GStreamer element.

IMediaBlockInternals.GetElement()

Retrieves the primary GStreamer element that represents this MediaBlock in the pipeline. This element is the main component that performs the actual media processing and is connected to other elements in the GStreamer pipeline.

Element IMediaBlockInternals.GetElement()

Returns

Element

The GStreamer Element instance, or null if the block hasn't been built yet.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Associates this MediaBlock with a pipeline and initializes its internal context. This method is called automatically when the block is added to a pipeline, providing access to shared resources and pipeline-wide configuration.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The MediaBlocksPipeline instance that will manage this block.