Getting started with RtspClient

Topics: Question
Feb 18, 2016 at 9:43 AM
Edited Feb 18, 2016 at 10:16 AM

I am new to the subject of Rtsp and am trying to use this library to establish a simple connection to a network camera and receive a H.264 encoded video stream from the camera.

Below is my code so far. The Rtsp connection to the camera is successfully established, it seems.

My question is: how do I now get the actual Rtp payload data?

Thanks in advance!
using System;
using System.Diagnostics;
using Media.Rtsp;
using Media.Sdp;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            try {
                RtspClient client = new RtspClient("rtsp://");


            catch (Exception e) {
Feb 18, 2016 at 10:11 AM
Edited Feb 18, 2016 at 10:17 AM
I suspect that I need to go through RtspClient.Client somehow...
Feb 19, 2016 at 8:05 AM
I have added the following code and it seems that I am now able to receive data:
               client.Client.RtpFrameChanged += (sender, sender2, rtpPacket, tc) =>
                    Console.WriteLine("rtp frame changed: " + rtpPacket.CurrentFrame);
I would now like to put this data into the H264 Decoder. How do I go about this?
Feb 19, 2016 at 1:42 PM
Edited Feb 19, 2016 at 1:46 PM
Sorry for missing this, the UnitTest project tests almost every class, there's an effort to create more tests and separation of the tests into only the UnitTest project, for now most tests are defined in the same file as the code but there are some separated.

If you check out the unit tests you will see examples of Rtp alone, Rtsp client and server and various other tests.

The specific test your looking for is TestRFC6184VideoFrame, that is how you would prepare a stream to pass it to a decoder.

There's some minor additional differences which need to be addressed for the emulation prevention byte but a well designed decoder should be accounting for such anyway.

I have plans to implement more of the H.264 standard as well as providing a more complete elementary stream writer but they are not yet ready.

If you need something specific let me know and I will see about getting it added.
Marked as answer by juliusfriedman on 2/19/2016 at 5:42 AM
Feb 19, 2016 at 1:55 PM
Edited Feb 19, 2016 at 1:58 PM
Thank you.

I took some code from the TestRFC6184VideoFrame example. This is how my own code looks now:
rtspclient.Client.RtpFrameChanged += (sender, sender2, rtpPacket, transportContext) =>

                //Create a RFC6184Frame
                using (Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame profileFrame = new Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame(97))
                    //Take each packet in the examples
                    foreach (byte[] packet in packetBytes)
Now this of course won't complie because packetBytes is undefined.

I assume I need to get the packetBytes from the rtpPacket somehow? If so, how do I do that?
Feb 19, 2016 at 2:02 PM
Edited Feb 19, 2016 at 2:02 PM
The code is using an example of hard coded packets and creating a frame, you would already have a RtpFrame....

You would look at the FrameChanged event, you would ensure that the packet corresponds to the TransportContext for the stream you intend by inspecting the MediaDescription of the TransportContext.
            void Client_RtpFrameChanged(object sender, Media.Rtp.RtpFrame frame, Media.Rtp.RtpClient.TransportContext tc = null, bool final = false){

            if (frame.IsDisposed || false == frame.IsComplete && false == final) return;

            var context = tc ?? ((Media.Rtp.RtpClient)sender).GetContextByPayloadType(frame.PayloadTypeByte);

            if (context == null || context.MediaDescription.MediaType != return;

            using (Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame hframe = new Media.Rtsp.Server.MediaTypes.RFC6184Media.RFC6184Frame(frame))

                //.... Rest of the example

If you need anything else please let me know!
Marked as answer by juliusfriedman on 2/19/2016 at 6:05 AM