Skip to content
jesnil created page: RTSP_Presentation authored by Jesper Nilsson's avatar Jesper Nilsson
# RTSP.Presentation
## Constructor arguments
A single `System.Uri` with the Url of the presentation.
## Usage
Start by requesting the Session Description by calling
`GetSessionDescriptionAsync()`. It will return a `Task<SessionDescription>`.
This task will be completed when the `SessionDescription` is available.
Using the `SessionDescription` each media format (audio, video or other) that is
available can be examined. Each media format that is to be streamed can be set
up with a call to `SetupAsync()`. Each call will return a `Task<Session>` that
will be completed when the media stream has been set up. The task result
`Session` object is the source of the RTP packets that will be streamed for the
selected media format.
`Session`is an `IObservable<Packet>`source and the sink that is to consume the
RTP packets has to implement the `IObserver<Packet>` interface.
When all required sinks are set up streaming is started by calling
`PlayAsync()`. The task returned will be completed when a response has been
received to the RTSP PLAY request.
To stop all the streams call `StopAsync()`. The task returned will be completed
when a response has been received to the RTSP TEARDOWN request.
## Code example
An example to stream the video media only and checking if format/codec is
supported:
```c#
Uri url = new Uri("rtsp://server/presentation", UriKind.Absolute);
Presentation p = new Presentation(url);
SessionDescription sdp = await p.GetSessionDescriptionAsync();
// Process video media only.
Media media = sdp.MediaDescriptions
.Where(m => { return m.MediaType == SessionDescription.MediaType.video; })
.First();
// Is this video codec supported?
IObserver<Packet> mediaSink = CreateVideoSink(media);
if (mediaSink != null)
{
Session s = await p.SetupAsync(media);
s.Subscribe(mediaSink);
// Start playing the video.
await p.PlayAsync();
}
```
Stop the presentation started above.
```c#
await p.StopAsync();
```