Class MediaSession
Media session connects one or more media sources to one or more media sinks and maintains media flow.
public class MediaSession : IDisposable
- Inheritance
-
MediaSession
- Implements
- Inherited Members
Constructors
MediaSession()
Initializes a new instance of the MediaSession class.
public MediaSession()
Properties
AllowStoppingSources
Gets or sets a value indicating whether the media session is allowed to stop the sources when it stops or encounters an error.
public bool AllowStoppingSources { get; set; }
Property Value
Remarks
The default value is true, meaning the media session stops all sources.
Set to false when sources are shared by multiple media sessions or other objects and stopping them is not desirable.
IsDrained
Gets a value indicating whether the media session is completely drained and has no more samples to process.
public bool IsDrained { get; }
Property Value
NoCaptureTimeout
Gets or sets the no-capture timeout to override the default timeout settings.
public TimeSpan? NoCaptureTimeout { get; set; }
Property Value
Remarks
This timeout specifies how long the session waits without receiving samples before considering it an error.
SinkOpenTimeout
Gets or sets the sink open timeout to override the default timeout settings.
public TimeSpan? SinkOpenTimeout { get; set; }
Property Value
SourceOpenTimeout
Gets or sets the source open timeout to override the default timeout settings.
public TimeSpan? SourceOpenTimeout { get; set; }
Property Value
Methods
AddSink(IMediaSink)
Adds a media sink to the session.
public void AddSink(IMediaSink sink)
Parameters
sinkIMediaSinkThe media sink to add.
Remarks
At least one media sink must be added before starting the session. Each media sink receives samples from all media sources.
Exceptions
- Exception
Thrown if the session is already running.
AddSource(IMediaSource)
Adds a media source to the session.
public void AddSource(IMediaSource source)
Parameters
sourceIMediaSourceThe media source to add.
Remarks
At least one media source must be added before starting the session. Typically, one video and/or one audio source should be added. Multiple video or audio sources are supported, but whether they all appear in the output depends on the sink implementation.
Exceptions
- Exception
Thrown if the session is already running.
Dispose()
Releases all resources used by this media session.
public void Dispose()
Start()
Starts the media session.
public void Start()
Remarks
This method starts all underlying sources and sinks and begins media flow. If StartBuffering(int, BufferingType) was called previously, this method also flushes the buffered data to the sinks.
StartBuffering(int, BufferingType)
Starts buffering media data without pushing to sinks.
public void StartBuffering(int durationSec, MediaSession.BufferingType bufferingType)
Parameters
durationSecintThe buffering duration in seconds. Only the last
durationSecseconds are kept in the buffer.bufferingTypeMediaSession.BufferingTypeThe type of buffering to use (memory or disk).
Remarks
Calling this method starts the sources and opens sinks, but media data is only buffered according to the specified parameters. Nothing is pushed to sinks until the Start() method is called.
Exceptions
- ArgumentOutOfRangeException
Thrown if
durationSecis less than or equal to zero, or ifbufferingTypeis None.
Stop()
Stops the media session.
public void Stop()
Remarks
This method stops all underlying sources and sinks and terminates media flow.
Sources are stopped only if AllowStoppingSources is true.
Events
Error
Occurs when an error is encountered during media session processing.
public event EventHandler<ErrorEventArgs> Error