Class NDISourceBlock
- Namespace
- VisioForge.Core.MediaBlocks.Sources
- Assembly
- VisioForge.Core.dll
NDI (Network Device Interface) source block for professional IP-based video streaming. Provides low-latency, high-quality video and audio streaming over IP networks for broadcast production, live events, and multi-camera setups with automatic source discovery and synchronization capabilities. Implements the VisioForge.Core.MediaBlocks.Sources.SourceMediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.
public sealed class NDISourceBlock : SourceMediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals, IGetVideoStreamInfoInheritance
Implements
Inherited Members
Extension Methods
Constructors
NDISourceBlock(NDISourceSettings)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sources.NDISourceBlock class with custom NDI settings. Configures the NDI source for professional IP video streaming with specified parameters.
public NDISourceBlock(NDISourceSettings settings)Parameters
settingsNDISourceSettings-
The NDI settings controlling source selection, bandwidth, and connection parameters. Must not be null.
Remarks
Round-3 LOW #376: validate settings in the ctor instead of
deferring to Build. The previous behaviour silently accepted null and
allocated VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.VideoOutput, VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.AudioOutput, and the
_outputs cache for a block that Build would later refuse to
initialise — wasting work and leaving the block in an obviously unusable
state with no early failure signal. Failing fast in the ctor surfaces the
misuse at the call site rather than at the (much later) Build call.
Exceptions
- ArgumentNullException
-
Thrown when
settingsis null.
Properties
AudioOutput
Gets the audio output pad that provides NDI audio stream to downstream blocks.
public MediaBlockPad AudioOutput { get; }Property Value
Input
Gets the primary input pad (none for source blocks that receive network streams).
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all input pads available on this block (none for source blocks).
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the primary output pad — video when present, otherwise audio for audio-only NDI sources. Returning VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.VideoOutput unconditionally gave audio-only sources a useless dangling pad and broke single-output callers that expected the primary pad to actually carry data.
public override MediaBlockPad Output { get; }Property Value
Remarks
Thread-safety contract (Round-3 MEDIUM #258): this getter is NOT
synchronised against a concurrent VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.CleanUp. The
VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.VideoOutput / VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.AudioOutput property references
are immutable for the block's lifetime, but the Gst.Pad inside each
MediaBlockPad is mutated by SetInternalPad from
VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.Build / VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.CleanUp. A reader that observes
!IsInternalPadNull() here can race a concurrent CleanUp
that nulls the internal pad before the caller links into it. Callers
MUST re-check IsInternalPadNull() on the returned pad themselves
(and treat null-pad as a no-op) when concurrent CleanUp is possible —
or hold whatever pipeline-level lock guards their build/teardown ordering.
Outputs
Gets all output pads available on this block (video and audio outputs).
public override MediaBlockPad[] Outputs { get; }Property Value
Remarks
Backed by VisioForge.Core.MediaBlocks.Sources.NDISourceBlock._outputs — populated once in the ctor (after VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.VideoOutput/VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.AudioOutput are assigned) and returned on every read so we don't allocate a new array per call. The pad references themselves are immutable for the block's lifetime (the underlying Gst.Pad inside each MediaBlockPad swaps via SetInternalPad, but the pad wrapper instances do not), so the cached array stays valid across Build / CleanUp cycles.
Round-3 MEDIUM #260: outside the built state we return
Empty<T>() instead of the cached array. The cached
pads still exist but their internal Gst.Pad has been nulled by
VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.CleanUp; pipeline traversal that links them post-CleanUp
would silently fail because GetInternalPad() returns null.
Returning an empty array makes the post-CleanUp / pre-Build state
observable to callers without exposing stale pads.
Settings
Gets or sets the NDI configuration settings that control source selection and stream parameters.
public NDISourceSettings Settings { get; set; }Property Value
Remarks
Round-3 MEDIUM #259: the setter throws InvalidOperationException
when invoked after VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.Build has succeeded. The underlying
NDISource (desktop) or NDIAndroidReceiver (Android) is
constructed against the snapshot of Settings at Build-time and does
not pick up post-Build mutations. Allowing the property to be
reassigned silently kept the receiver capturing from the old source
while the property reported the new one — a confusing diagnosis trap.
To change settings on a built block, dispose it and create a new one.
Type
Gets the media block type identifier for NDI source operations.
public override MediaBlockType Type { get; }Property Value
VideoOutput
Gets the video output pad that provides NDI video stream to downstream blocks.
public MediaBlockPad VideoOutput { get; }Property Value
Methods
Build()
Builds and initializes the NDI source within the pipeline context. Connects to NDI stream, configures video/audio outputs, and prepares synchronized playback for downstream processing.
public override bool Build()Returns
- bool
-
trueif the NDI source was successfully built and configured; otherwise,false.
CleanUp()
Cleans up all resources associated with the NDI operations, including network connections and stream buffers.
public void CleanUp()Dispose(bool)
Releases unmanaged and managed resources used by the NDI source. Properly closes network connections and disposes of GStreamer elements and streaming resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
GetCore()
Gets the core GStreamer element wrapper for advanced configuration and monitoring.
public BaseElement GetCore()Returns
- BaseElement
-
The underlying VisioForge.Core.GStreamer.Sources.NDISource wrapper on desktop, or null on Android (composite block) and before VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.Build / after VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.CleanUp.
Remarks
Round-3 MEDIUM #264: returns the underlying VisioForge.Core.GStreamer.Sources.NDISource on desktop platforms (it is a single-element source so the wrapper is the well-defined "core") and null on Android, where the block is composed of a VisioForge.Core.MediaBlocks.Sources.CustomMixerSourceBlock plus a native receiver thread and has no single underlying element. The previous implementation returned null on every platform, which broke the documented contract that source blocks expose their underlying element for advanced configuration.
GetElement()
Gets the native GStreamer element for direct GStreamer pipeline integration.
public Element GetElement()Returns
- Element
-
The NDI source GStreamer element on desktop platforms (or null when the block is not in the built state), or null on Android.
Remarks
Platform contract:
-
Desktop (Windows / Linux / macOS / iOS): returns the underlying
ndisrcGStreamer element after a successful VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.Build. Returns null before VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.Build has run or after VisioForge.Core.MediaBlocks.Sources.NDISourceBlock.CleanUp has torn the source down (Round-3 MEDIUM #263). -
Android: ALWAYS returns null. The Android implementation is a
composite of VisioForge.Core.MediaBlocks.Sources.CustomMixerSourceBlock (two appsrc elements) plus a native
NDI receiver thread; there is no single
Gst.Elementthat represents the whole block. Callers MUST null-check the return value or branch onOperatingSystem.IsAndroid()/#if __ANDROID__before dereferencing.
GetVideoStreamInfo()
Returns the probed NDI video stream info when available.
public VideoStreamInfo GetVideoStreamInfo()Returns
- VideoStreamInfo
-
Video stream metadata, or null when the source has no video info yet.
IsAvailable()
Determines whether NDI support is available on the current system.
Requires NDI runtime and GStreamer NDI plugins to be installed and licensed.
On Android availability depends on libndi.so being shipped with the app
AND the appsrc GStreamer factory being registered. The libndi presence
check is cached after the first call so subsequent calls are free.
public static bool IsAvailable()Returns
- bool
-
trueif NDI support is available; otherwise,false.
Stop()
Stops the desktop NDI source. Round-3 MEDIUM #143: desktop ndisrc element auto-stops via the GStreamer state change, but providing an override gives MediaBlocksPipeline.Stop a hook for future bookkeeping symmetric with the Android path. Currently routes straight to base.Stop().
public override bool Stop()Returns
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the pipeline context for this NDI source, providing access to the parent pipeline and logging context.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The parent MediaBlocks pipeline containing this NDI source.