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, IGetVideoStreamInfoInheritance
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
mainSourceSettingsIVideoSourceSettings-
The main source settings: RTSP, SRT, RTMP, HTTP or NDI.
fallbackSettingsFallbackSwitchSettings-
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
Input
Gets the primary input pad (none for source blocks).
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all input pads (none for source blocks).
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the primary output pad - the video output.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets all output pads: the video and the audio output, those that are enabled.
public override MediaBlockPad[] Outputs { get; }Property Value
Type
Gets the media block type identifier for fallback switch source operations.
public override MediaBlockType Type { get; }Property Value
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
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
disposingbool-
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
contextContextX-
The pipeline context used for logging. May be null.
cancellationTokenCancellationToken-
Cancelled by a stop or a dispose arriving mid-lookup.
Returns
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the pipeline context for this block.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The MediaBlocksPipeline that owns this block.