Table of Contents

Class VirtualNetworkSource

Namespace
VAST.Network
Assembly
VAST.Common.dll

Represents a virtual network source that allows programmatic injection of media samples.

public class VirtualNetworkSource : INetworkSource, IMediaSource, IReferenceable, IDisposable, INetworkEndPoint
Inheritance
VirtualNetworkSource
Implements
Inherited Members

Remarks

This class enables third-party code to push media data into the streaming pipeline by adding streams and pushing media samples with timestamps.

Constructors

VirtualNetworkSource()

Initializes a new instance of the VirtualNetworkSource class.

public VirtualNetworkSource()

Properties

Accept

Gets or sets a value indicating whether the source is accepted.

public bool Accept { get; set; }

Property Value

bool

Capabilities

Gets the list of capabilities supported by this source.

public List<SourceCapability> Capabilities { get; }

Property Value

List<SourceCapability>

EndPoint

Gets the connected endpoint information.

public IPProtoEndPoint EndPoint { get; }

Property Value

IPProtoEndPoint

IsDisposed

Gets a value indicating whether this object has been disposed and can no longer be used.

public bool IsDisposed { get; }

Property Value

bool

IsNetworkSource

Gets a value indicating whether this is a network source rather than a local source.

public bool IsNetworkSource { get; }

Property Value

bool

Parameters

Gets or sets the source configuration parameters.

public SourceParameters Parameters { get; set; }

Property Value

SourceParameters

PublishingPath

Gets or sets the publishing path extracted from the source URI or by other means.

public string PublishingPath { get; set; }

Property Value

string

ReceivedUri

Gets or sets the source URI when present.

public string ReceivedUri { get; set; }

Property Value

string

RefCount

Gets the current reference count of the object.

public int RefCount { get; }

Property Value

int

SocketError

Gets the socket error received on disconnection.

public ExtendedSocketError SocketError { get; }

Property Value

ExtendedSocketError

State

Gets the current source state.

public MediaState State { get; }

Property Value

MediaState

StreamCount

Gets the total number of streams in the source.

public int StreamCount { get; }

Property Value

int

UniqueId

Gets or sets the unique identifier for this source.

public Guid UniqueId { get; set; }

Property Value

Guid

Uri

Gets or sets the source URI.

public string Uri { get; set; }

Property Value

string

Remarks

Setting this property is not supported and will throw NotSupportedException.

Methods

AddRef()

Adds a reference to this object.

public void AddRef()

AddStream(MediaType)

Adds a media stream with the specified media type.

public int AddStream(MediaType mediaType)

Parameters

mediaType MediaType

The media type of the stream to add.

Returns

int

The stream index to use when pushing media samples for this stream.

Remarks

At least one media stream must be added before starting the source. Typically, one video and/or one audio stream should be added. Multiple video or audio streams are supported, but whether they all appear in the output depends on the sink implementation.

Exceptions

Exception

Thrown if the source is already in a running state.

Dispose()

Releases all resources used by this virtual network source.

public void Dispose()

GetMediaType(int)

Gets the media type of the specified stream.

public MediaType GetMediaType(int streamIndex)

Parameters

streamIndex int

The index of the stream to get the media type for.

Returns

MediaType

The media type of the requested stream, or null if the index is out of range.

OnError(string)

Raises an error event with the specified error description.

public void OnError(string errorDescription)

Parameters

errorDescription string

The description of the error that occurred.

Open()

Opens the source and prepares it for streaming.

public void Open()

Remarks

For this virtual source, this method transitions the state to Opened and locks the parameters.

PushMedia(int, byte[], int, int, long, long, VersatileBufferFlag)

Pushes a new media sample from a byte array into the source.

public void PushMedia(int streamIndex, byte[] buffer, int offset, int size, long dts = -9223372036854775808, long pts = -9223372036854775808, VersatileBufferFlag flags = VersatileBufferFlag.None)

Parameters

streamIndex int

The stream index for the new sample.

buffer byte[]

The byte array containing the media data.

offset int

The zero-based offset in the buffer at which to begin reading.

size int

The number of bytes to read from the buffer.

dts long

The decoding timestamp, or MinValue to use the current system time.

pts long

The presentation timestamp, or MinValue to use the DTS value.

flags VersatileBufferFlag

Additional buffer flags.

Remarks

It is highly recommended to provide proper timestamps. Using the current system time as a fallback is strongly discouraged as it may cause timing issues.

PushMedia(VersatileBuffer)

Pushes a new media sample into the source.

public void PushMedia(VersatileBuffer sample)

Parameters

sample VersatileBuffer

The media sample to push.

Remarks

The sample's StreamIndex must be set to a valid stream index. The Dts and Pts properties must also be initialized. The KeyFrame and CleanPoint properties will be automatically detected for supported video codecs.

Release()

Releases a reference to this object.

public void Release()

Remarks

If the reference count reaches zero, Dispose() is called automatically. The caller must not use this object after calling this method.

SetDesiredOutputType(int, MediaType)

Sets the desired output media type for the specified stream.

public Task SetDesiredOutputType(int streamIndex, MediaType mediaType)

Parameters

streamIndex int

The index of the stream to set the desired output type for.

mediaType MediaType

The desired media type.

Returns

Task

A task representing the asynchronous operation, or null if the type matches.

Remarks

This virtual source does not support transcoding. If the requested media type differs from the stream's current type, a NotImplementedException is thrown.

Exceptions

ArgumentOutOfRangeException

Thrown if the stream index is out of range.

NotImplementedException

Thrown if the requested media type differs from the current type.

Start()

Starts the source and begins accepting media data.

public void Start()

Stop()

Stops the source and releases associated resources.

public void Stop()

Events

Error

Occurs when an error is encountered.

public event EventHandler<ErrorEventArgs> Error

Event Type

EventHandler<ErrorEventArgs>

NewSample

Occurs when a new sample is ready to be consumed.

public event EventHandler<NewSampleEventArgs> NewSample

Event Type

EventHandler<NewSampleEventArgs>

NewStream

Occurs when a new stream is created or stream information becomes available.

public event EventHandler<NewStreamEventArgs> NewStream

Event Type

EventHandler<NewStreamEventArgs>

StateChanged

Occurs when the source state changes.

public event EventHandler<MediaState> StateChanged

Event Type

EventHandler<MediaState>