Class StreamSourceBlockWithDecoder
- Namespace
- VisioForge.Core.MediaBlocks.Sources
- Assembly
- VisioForge.Core.dll
Composite media source block that combines stream reading with automatic decoding for complete media playback. This high-level block encapsulates the complexity of reading from .NET Stream objects, automatically detecting media formats, demuxing container formats, and decoding compressed streams into raw video and audio data. Provides a simplified API for applications that need to play media from memory without manual pipeline construction.
Key features:
- Automatic format detection for all supported container formats
- Integrated demuxing of multi-stream containers (MP4, MKV, AVI, etc.)
- Hardware-accelerated decoding when available
- Support for any .NET Stream implementation (MemoryStream, FileStream, NetworkStream)
- Seamless handling of variable bitrate and adaptive streams
- Automatic audio/video synchronization
- Zero-copy streaming from memory buffers when possible
Common use cases:
- Playing media from memory buffers or byte arrays
- Streaming from encrypted or compressed archives
- Processing media from network streams without temporary files
- Embedding media playback in memory-constrained environments
- Custom stream implementations for DRM or proprietary formats
The block internally manages a StreamSourceBlock for reading and a DecodeBinBlock for automatic format detection and decoding, presenting a simple interface with separate video and audio outputs ready for rendering or further processing. Implements the VisioForge.Core.MediaBlocks.Special.SuperMediaBlock
public class StreamSourceBlockWithDecoder : SuperMediaBlock, IMediaBlock, IDisposable, IMediaBlockInternalsInheritance
Implements
Inherited Members
Extension Methods
Constructors
StreamSourceBlockWithDecoder(Stream, bool, bool, bool)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sources.StreamSourceBlockWithDecoder class with an existing stream. Creates a complete media playback pipeline from stream reading through decoding in a single block. The stream position should be at the beginning of valid media data for proper format detection.
public StreamSourceBlockWithDecoder(Stream stream, bool renderVideo = true, bool renderAudio = true, bool renderSubtitle = false)Parameters
streamStream-
The .NET Stream object containing encoded media data to be read, demuxed, and decoded. The stream must be readable and seekable for most media formats.
renderVideobool-
Whether to expose a decoded video output pad. Default
true. renderAudiobool-
Whether to expose a decoded audio output pad. Default
true. renderSubtitlebool-
Whether to expose a decoded subtitle output pad. Default
false.
Remarks
The stream is not disposed when this block is disposed - the caller retains ownership and responsibility for the stream's lifecycle. Ensure the stream remains valid for the duration of playback.
StreamSourceBlockWithDecoder(string, bool, bool, bool)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sources.StreamSourceBlockWithDecoder class from a file path. Opens the file as a stream and creates a complete playback pipeline with automatic decoding. This constructor manages the file stream internally and will close it when disposed.
public StreamSourceBlockWithDecoder(string filename, bool renderVideo = true, bool renderAudio = true, bool renderSubtitle = false)Parameters
filenamestring-
The path to the media file to open, read, demux, and decode. Supports both absolute and relative paths.
renderVideobool-
Whether to expose a decoded video output pad. Default
true. renderAudiobool-
Whether to expose a decoded audio output pad. Default
true. renderSubtitlebool-
Whether to expose a decoded subtitle output pad. Default
false.
Exceptions
- FileNotFoundException
-
Thrown when the specified file does not exist.
- UnauthorizedAccessException
-
Thrown when the file cannot be accessed due to permissions.
Properties
AudioOutput
Gets the audio output pad that provides decoded audio samples from the stream.
public MediaBlockPad AudioOutput { get; }Property Value
SubtitleOutput
Gets the subtitle output pad that provides decoded subtitle data from the stream.
public MediaBlockPad SubtitleOutput { get; }Property Value
VideoOutput
Gets the video output pad that provides decoded video frames from the stream.
public MediaBlockPad VideoOutput { get; }Property Value
Methods
Build()
Builds the composite block. In addition to the base no-op, this override invokes
pipeline.Connect for the source -> decoder link so the link is explicitly
registered with the pipeline (rather than relying solely on the pad-level
_connectedTo bookkeeping established in VisioForge.Core.MediaBlocks.Sources.StreamSourceBlockWithDecoder.Init).
public override bool Build()Returns
- bool
-
truewhen build succeeds.
IsSubtitlesAvailable()
Indicates whether this block will expose a subtitle output pad. Exposed as a method (not a property) to mirror VisioForge.Core.MediaBlocks.Sources.SourceMediaBlock.IsSubtitlesAvailable, so callers that accept either block shape can use the same name.
public bool IsSubtitlesAvailable()Returns
- bool
-
truewhenrenderSubtitlewas enabled in the constructor.