Table of Contents

Class StreamSinkBlock

Namespace
VisioForge.Core.MediaBlocks.Sinks
Assembly
VisioForge.Core.dll

Provides a media sink that writes data directly to a .NET Stream object.

public class StreamSinkBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

Implements

Inherited Members

Extension Methods

Examples

// Write to memory stream
var memoryStream = new MemoryStream();
var streamSink = new StreamSinkBlock(memoryStream);

// Write to file stream with buffering
var fileStream = new FileStream("output.data", FileMode.Create, 
    FileAccess.Write, FileShare.None, 4096, useAsync: true);
var streamSink = new StreamSinkBlock(fileStream);

// Write to network stream
var tcpClient = new TcpClient("server.com", 8080);
var networkStream = tcpClient.GetStream();
var streamSink = new StreamSinkBlock(networkStream);

// Connect to pipeline
pipeline.Connect(encoder.Output, streamSink.Input);

Remarks

The StreamSinkBlock enables writing media data to any .NET Stream implementation, providing flexible output options for custom storage, network transmission, or in-memory processing. It bridges the GStreamer pipeline with .NET I/O abstractions.

Key features include:

  • Direct writing to any Stream implementation
  • Support for memory streams, file streams, network streams
  • Zero-copy data transfer when possible
  • Automatic buffer management
  • Thread-safe stream writing
  • Compatible with any media format

Common use cases:

  • Writing to cloud storage via stream APIs
  • In-memory media processing and analysis
  • Custom network protocols via NetworkStream
  • Encrypted storage via CryptoStream
  • Compressed output via compression streams

Important: The provided stream must remain valid and writable throughout the pipeline's lifetime. The stream is not disposed by this block - the caller is responsible for proper stream lifecycle management.

Constructors

StreamSinkBlock(Stream)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.StreamSinkBlock class with the specified stream.

public StreamSinkBlock(Stream stream)

Parameters

stream Stream

The writable stream to which media data will be written.

Remarks

The provided stream must support writing and remain valid throughout the pipeline's lifetime. The stream will not be disposed by this block - the caller retains ownership and must handle proper disposal.

The input pad is configured to accept any media type, allowing flexible use with different data formats. The block name is automatically set to "StreamSink".

Exceptions

ArgumentNullException

Thrown when stream is null.

ArgumentException

Thrown when stream is not writable.

Fields

TAG

The tag.

protected const string TAG = "StreamSinkBlock"

Field Value

string

Properties

Input

Gets the input.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets the inputs.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the output.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets the outputs.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Type

Gets the type.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Builds the stream sink block and configures the stream output.

public override bool Build()

Returns

bool

true if the block was successfully built; otherwise, false.

Remarks

This method initializes the underlying custom GStreamer sink element that writes data to the provided .NET Stream. The sink implements efficient data transfer from GStreamer buffers to the stream.

The build process:

  1. Creates the custom stream sink element
  2. Associates it with the provided stream
  3. Retrieves and assigns the static sink pad

Data written to the stream is buffered internally by GStreamer and flushed according to the pipeline's data flow. The stream should support asynchronous writes for optimal performance.

CleanUp()

Cleans up.

public void CleanUp()

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetCore()

Gets core.

public BaseElement GetCore()

Returns

BaseElement

VisioForge.Core.GStreamer.Base.BaseElement.

GetElement()

Gets the element.

public Element GetElement()

Returns

Element

Gst.Element.

GetFilenameOrURL()

Gets the filename or URL for this stream sink.

public string GetFilenameOrURL()

Returns

string

Always returns null as stream sinks do not have associated filenames.

Remarks

This method implements the IMediaBlockSink interface requirement. Since StreamSinkBlock writes to an arbitrary stream rather than a file, it returns null to indicate no filename is applicable.

IsAvailable()

Determines whether the stream sink functionality is available in the current environment.

public static bool IsAvailable()

Returns

bool

true if stream output is supported; otherwise, false.

Remarks

Availability depends on the presence of required GStreamer components for custom sink implementations. The correct NuGet SDK redistribution package must be included in your project for this block to function.

SetFilenameOrURL(string)

Sets the filename or URL for this stream sink.

public void SetFilenameOrURL(string value)

Parameters

value string

The filename value (ignored).

Remarks

This method implements the IMediaBlockSink interface requirement but has no effect for StreamSinkBlock, as the output destination is determined by the stream provided in the constructor. The stream cannot be changed after construction.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Sets the context.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The pipeline.

See Also