How to get RTSP Headers C#

This description demonstrates how to get RTSP headers from IP cameras in C#.

What is RTSP Header?

The RTSP provides real-time transfer for media streams between a camera and the Ozeki Camera SDK software. In order that clients begin video and audio streams they get RTSP messages which include RTSP headers. Every headers have their own values and meanings.
RTSP headers:

  • Request: It contain the different RTSP protocol methods (e.g. option, describe, setup, teardown, play, pause).
  • Content-encoding: The Content-Encoding entity-header field is used as a modifier to the media-type.
  • CSeq: The CSeq field specifies the sequence number for an RTSP request- response pair. This field MUST be present in all requests and responses. For every RTSP request containing the given sequence number, there will be a corresponding response having the same number.
  • User agent: This field contain the name of the clint who connect to the software.
  • Date: This field contain the exact date and time.
  • Public: It contain the different RTSP protocol methods e.g. option, describe, setup, teardown, play, pause).
  • www- Authenticate: This field requests the client to to identify itself.
  • www- Authorization: This field allows the client to identify itself (or its user) which requires authentication.
  • How to get RTSP headers?

    To send a control request, the client constructs a line consisting of the method, the request URL, and the procol version number. Then it includes a general header, a request header and possibly an entity header, as for the http protocol. This is sent to the server, who executes the request if possible. It then returns a response containing a status-line and general, response and entity headers. The status line contains the protocol version, the numeric status code and a textual description.

    RTSP message is the basic unit of RTSP communication. RTSP messages contain RTSP headers which are used for defining request and response messages.

    Windows forms version

    Program.cs

    using System;
    using Ozeki.Media;
    using Ozeki.Camera;
    
    namespace RtspLog_Console
    {
        class Program
        {
            private static IIPCamera camera;
            static void Main(string[] args)
            {
                camera = new IPCamera("192.168.113.150:80", "root", "pass");
                if (camera != null)
                {
                    camera.CameraStateChanged += camera_CameraStateChanged;
                    camera.Start();
                }
    
                Console.ReadLine();
            }
    
            static void camera_CameraStateChanged(object sender, CameraStateEventArgs e)
            {
                Console.WriteLine(e.State);
    
                if (e.State == CameraState.Streaming)
                {
                    var messages = camera.RtspLog.GetHead();
    
                    foreach (var message in messages)
                    {
                        Console.WriteLine(message);
                    }
                }
            }
        }
    }
    		
    Code 1 - Rebooting an Onvif camera example in C#

    Please note that none of the cancel and disconnect methods are included in the example because of the demonstrating intent and briefness of the article.

    GUI

    graphical user interface
    Figure 1 - The graphical user interface of your application

    After the successful implementation of the functions and the GUI elements, the application will work properly. Pressing the connect button will load the image of the IP camera device connected to your PC into the panel that you can see on the picture. Besides this you can click on the reboot button which will reboot the camera.

    Related Pages

    FAQ

    Below you can find the answers for the most frequently asked questions related to this topic:

    1. I have not managed to build the solution. How to solve it?

      • Please set the Target framework property of the project to .NET 4.0.
      • You should add the OzekiSDK.dll to the references of the solution.
      • Please import the missing classes.
    2. Can I read the RTSP head request messages if I use IP Camera?

      Yes,you can read the RTSP head request messages.