Class VirtualNetworkSource
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
Capabilities
Gets the list of capabilities supported by this source.
public List<SourceCapability> Capabilities { get; }
Property Value
EndPoint
Gets the connected endpoint information.
public IPProtoEndPoint EndPoint { get; }
Property Value
IsDisposed
Gets a value indicating whether this object has been disposed and can no longer be used.
public bool IsDisposed { get; }
Property Value
IsNetworkSource
Gets a value indicating whether this is a network source rather than a local source.
public bool IsNetworkSource { get; }
Property Value
Parameters
Gets or sets the source configuration parameters.
public SourceParameters Parameters { get; set; }
Property Value
PublishingPath
Gets or sets the publishing path extracted from the source URI or by other means.
public string PublishingPath { get; set; }
Property Value
ReceivedUri
Gets or sets the source URI when present.
public string ReceivedUri { get; set; }
Property Value
RefCount
Gets the current reference count of the object.
public int RefCount { get; }
Property Value
SocketError
Gets the socket error received on disconnection.
public ExtendedSocketError SocketError { get; }
Property Value
State
Gets the current source state.
public MediaState State { get; }
Property Value
StreamCount
Gets the total number of streams in the source.
public int StreamCount { get; }
Property Value
UniqueId
Gets or sets the unique identifier for this source.
public Guid UniqueId { get; set; }
Property Value
Uri
Gets or sets the source URI.
public string Uri { get; set; }
Property Value
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
mediaTypeMediaTypeThe 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
streamIndexintThe index of the stream to get the media type for.
Returns
- MediaType
The media type of the requested stream, or
nullif the index is out of range.
OnError(string)
Raises an error event with the specified error description.
public void OnError(string errorDescription)
Parameters
errorDescriptionstringThe 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
streamIndexintThe stream index for the new sample.
bufferbyte[]The byte array containing the media data.
offsetintThe zero-based offset in the buffer at which to begin reading.
sizeintThe number of bytes to read from the buffer.
dtslongThe decoding timestamp, or MinValue to use the current system time.
ptslongThe presentation timestamp, or MinValue to use the DTS value.
flagsVersatileBufferFlagAdditional 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
sampleVersatileBufferThe 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
streamIndexintThe index of the stream to set the desired output type for.
mediaTypeMediaTypeThe desired media type.
Returns
- Task
A task representing the asynchronous operation, or
nullif 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
NewSample
Occurs when a new sample is ready to be consumed.
public event EventHandler<NewSampleEventArgs> NewSample
Event Type
NewStream
Occurs when a new stream is created or stream information becomes available.
public event EventHandler<NewStreamEventArgs> NewStream
Event Type
StateChanged
Occurs when the source state changes.
public event EventHandler<MediaState> StateChanged