Table of Contents

Class FallbackSwitchSourceBlock

Namespace
VisioForge.Core.MediaBlocks.Sources
Assembly
VisioForge.Core.dll

Fallback switch source block that wraps a live source with automatic failover capability. Uses GStreamer's fallbacksrc element to switch between the main source and fallback content (static text, image, or media URI) when the main source fails, and back when it recovers.

public class FallbackSwitchSourceBlock : SourceMediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals, IMediaBlockAsyncPrepare, IGetVideoStreamInfo

Inheritance

Implements

Inherited Members

Extension Methods

Remarks

The outputs carry decoded video and audio. fallbacksrc opens and decodes the main source itself: RTSP, SRT, RTMP and HTTP sources are opened from their URI, and the connection settings of the source settings object (credentials, latency, transport and similar) are applied to the network element fallbacksrc creates; NDI sources are received through ndisrc. Settings that are not about the connection are not applied: on the RTSP and RTMP settings that is AudioEnabled, CompatibilityMode, UseGPUDecoder and CustomVideoDecoder, and on RTSP also EnableRAWVideoAudioEvents and ForceCustomKeepAlive. Which outputs exist follows VisioForge.Core.Types.X.Sources.FallbackSwitchSettings.EnableVideo and VisioForge.Core.Types.X.Sources.FallbackSwitchSettings.EnableAudio.

The output takes the size and format of whichever source is active, so the caps change on every switch. A consumer that needs fixed caps - an encoder feeding a file - should put a scaler and converter with fixed caps after the block.

Constructors

FallbackSwitchSourceBlock(IVideoSourceSettings, FallbackSwitchSettings)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sources.FallbackSwitchSourceBlock class.

public FallbackSwitchSourceBlock(IVideoSourceSettings mainSourceSettings, FallbackSwitchSettings fallbackSettings)

Parameters

mainSourceSettings IVideoSourceSettings

The main source settings: RTSP, SRT, RTMP, HTTP or NDI.

fallbackSettings FallbackSwitchSettings

The fallback switch configuration.

Properties

AudioOutput

Gets the audio output pad that provides the active audio stream (main or fallback). null when VisioForge.Core.Types.X.Sources.FallbackSwitchSettings.EnableAudio is off; silence while neither source has audio.

public MediaBlockPad AudioOutput { get; }

Property Value

MediaBlockPad

Input

Gets the primary input pad (none for source blocks).

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets all input pads (none for source blocks).

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the primary output pad - the video output.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets all output pads: the video and the audio output, those that are enabled.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Type

Gets the media block type identifier for fallback switch source operations.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

VideoOutput

Gets the video output pad that provides the active video stream (main or fallback). null when VisioForge.Core.Types.X.Sources.FallbackSwitchSettings.EnableVideo is off.

public MediaBlockPad VideoOutput { get; }

Property Value

MediaBlockPad

Methods

Build()

Builds and initializes the fallback switch source and its internal components. Creates the GStreamer fallbacksrc element and establishes connections.

public override bool Build()

Returns

bool

True if the block was successfully built; false if initialization failed.

CleanUp()

Cleans up and releases all resources used by this block.

public void CleanUp()

Dispose(bool)

Releases all resources used by the fallback switch source block.

protected override void Dispose(bool disposing)

Parameters

disposing bool

True if disposing; false if finalizing.

GetCore()

Gets the core BaseElement wrapper. Not used for this block type.

public BaseElement GetCore()

Returns

BaseElement

Always returns null.

GetElement()

Gets the GStreamer element for IMediaBlockInternals.

public Element GetElement()

Returns

Element

The fallbacksrc element.

GetStatistics()

Gets statistics from the fallback source.

public Dictionary<string, object> GetStatistics()

Returns

Dictionary<string, object>

Dictionary containing statistics like retry counts and buffering percentages.

GetStatus()

Gets the current status of the fallback source.

public string GetStatus()

Returns

string

Status string from the fallbacksrc element.

GetVideoStreamInfo()

Gets the size and frame rate of the video the block currently outputs (main or fallback).

public VideoStreamInfo GetVideoStreamInfo()

Returns

VideoStreamInfo

The video stream information, or null before the first frame.

Unblock()

Manually unblocks the fallback source when manual-unblock is enabled.

public void Unblock()

IMediaBlockAsyncPrepare.PrepareAsync(ContextX, CancellationToken)

Resolves an ONVIF device-service address of an RTSP main source to the camera's RTSP URL; fallbacksrc opens the main source itself when the pipeline starts.

Task<bool> IMediaBlockAsyncPrepare.PrepareAsync(ContextX context, CancellationToken cancellationToken)

Parameters

context ContextX

The pipeline context used for logging. May be null.

cancellationToken CancellationToken

Cancelled by a stop or a dispose arriving mid-lookup.

Returns

Task<bool>

false only when the start was cancelled: a failed lookup still starts, on the fallback.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Sets the pipeline context for this block.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The MediaBlocksPipeline that owns this block.