Class HLSSinkBlock
- Namespace
- VisioForge.Core.MediaBlocks.Sinks
- Assembly
- VisioForge.Core.dll
HLS (HTTP Live Streaming) sink block for creating segmented streaming content.
public class HLSSinkBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals, IMediaBlockDynamicInputsInheritance
Implements
Inherited Members
Extension Methods
Remarks
The HLS sink block generates HTTP Live Streaming content, Apple's adaptive bitrate streaming protocol that has become an industry standard. HLS works by breaking the overall stream into a sequence of small HTTP-based file downloads, each containing a segment of the stream. This enables adaptive streaming, VOD, and live broadcasts.
Key Features:
- Adaptive bitrate streaming support
- Automatic generation of .m3u8 playlist files
- Configurable segment duration and playlist length
- Support for encrypted segments (AES-128)
- Compatible with all major browsers and devices
- Live streaming and VOD (Video on Demand) modes
- Multi-variant playlist support for different quality levels
Typical Use Cases:
- Live streaming to iOS devices and Safari browsers
- Creating VOD content for web-based video players
- Building adaptive streaming solutions
- Streaming to smart TVs and set-top boxes
- CDN-friendly content distribution
Technical Specifications:
- Segment format: MPEG-TS (.ts files) or fragmented MP4 (.m4s files)
- Video codecs: H.264/AVC, H.265/HEVC
- Audio codecs: AAC, MP3
- Playlist format: M3U8 (Extended M3U)
- Default segment duration: 10 seconds (configurable)
Output Structure: The sink creates a directory structure with playlist files (.m3u8) and segment files (.ts/.m4s). For live streaming, old segments are automatically removed based on playlist settings.
Constructors
HLSSinkBlock(HLSSinkSettings)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.HLSSinkBlock class with the specified settings.
public HLSSinkBlock(HLSSinkSettings settings)Parameters
settingsHLSSinkSettings-
The VisioForge.Core.Types.X.Sinks.HLSSinkSettings object containing configuration for HLS output, including the target directory, segment parameters, and playlist options.
Properties
Input
Gets the first input pad from the collection of available inputs.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all available input pads for connecting multiple media streams.
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the output pad for this sink block.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets all output pads for this sink block.
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets or sets the HLS sink configuration settings.
public HLSSinkSettings Settings { get; set; }Property Value
Type
Gets the media block type identifier for the HLS sink.
public override MediaBlockType Type { get; }Property Value
Methods
Build()
Builds and initializes the HLS sink pipeline components.
public override bool Build()Returns
- bool
-
trueif the sink was successfully built and configured;falseif initialization failed or required pads couldn't be allocated.
Remarks
This method creates the underlying GStreamer HLS sink element and configures separate video and audio input pads. The sink will create the output directory structure and begin generating playlist files when the pipeline starts.
CleanUp()
Cleans up resources and resets the sink block to an unbuilt state.
public void CleanUp()Remarks
This method disposes of the underlying GStreamer HLS sink element. Any incomplete segments may be finalized and the playlist updated before cleanup.
CreateNewInput(MediaBlockPadMediaType)
Creates a new input pad for connecting a media stream of the specified type.
public MediaBlockPad CreateNewInput(MediaBlockPadMediaType mediaType)Parameters
mediaTypeMediaBlockPadMediaType-
The type of media stream to accept. HLS supports: VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Video for video streams (H.264/H.265) and VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Audio for audio streams (AAC/MP3).
Returns
- MediaBlockPad
-
A new VisioForge.Core.MediaBlocks.MediaBlockPad configured for the specified media type, ready to receive encoded streams for HLS segmentation.
Dispose(bool)
Releases unmanaged and - optionally - managed 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 wrapper element for advanced pipeline integration.
public BaseElement GetCore()Returns
- BaseElement
-
The VisioForge.Core.GStreamer.Base.BaseElement wrapper providing access to the underlying GStreamer HLS sink element for advanced configuration.
GetElement()
Gets the native GStreamer element for direct GStreamer API access.
public Element GetElement()Returns
- Element
-
The underlying Gst.Element representing the HLS sink, allowing direct access to properties like segment duration and playlist settings.
GetFilenameOrURL()
Gets the output location where HLS segments and playlists will be written.
public string GetFilenameOrURL()Returns
- string
-
The directory path or URL prefix specified in the settings. This location will contain the master playlist and segment files.
GetInput(MediaBlockPadMediaType)
Gets an existing input pad that matches the specified media type.
public MediaBlockPad GetInput(MediaBlockPadMediaType mediaType)Parameters
mediaTypeMediaBlockPadMediaType-
The media type to search for among existing input pads.
Returns
- MediaBlockPad
-
The first VisioForge.Core.MediaBlocks.MediaBlockPad that matches the specified media type, or
nullif no matching input pad exists.
IsAvailable()
Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.
public static bool IsAvailable()Returns
- bool
-
trueif this media block is available; otherwise,false.
SetFilenameOrURL(string)
Sets the output location for HLS segments and playlists.
public void SetFilenameOrURL(string value)Parameters
valuestring-
The directory path where HLS files should be written. The directory will be created if it doesn't exist.
Exceptions
- NotImplementedException
-
This method is not currently implemented. Configure the location through settings instead.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the pipeline context for this media block.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The VisioForge.Core.MediaBlocks.MediaBlocksPipeline that owns this sink block, providing access to the pipeline context and logging facilities.
Remarks
This method is called internally by the pipeline during initialization and should not be called directly by user code.