Skip to content
KSAH-42 edited this page Mar 20, 2024 · 23 revisions

Welcome to the Rabbit Hole wiki dedicated for streaming !

This project has been created to help people to use RTSP protocol very quickly and with less effort in order to have a direct access to the raw binary stream push by a rtsp server. The other reason is to improve a legacy rtsp player written few years ago that perform also a rendering using differents types of codecs.

Actually, this library has been tested with :

  • 20 security cameras types (from hik, axis, sony, etc...)
  • some a rtsp server softwares.

But not at all, it may be possible that the generic rtsp client will not be able to received stream, or lose the connection during the streaming process.

In this scenerio, the generic rtsp client afford somes features to fix heatbeat/keepalive problems which are some times more specifics depending to a vendor. For other types of issues, don't hesitate to create issues to improve the quality of this library if you want.

And so, thank you for using this library !

About Async methods

You probably notice, that the client implementation used thread objects instead of async methods.

So why ?

The reason comes when I was working for a specific project using a vendor libray that just affect the behavior of a .net task scheduler. After an investigation, i have discovered that this vendor library introduce iusses on classes which used tasks. Because this external library set a specific size of the ThreadPool and don't allow other application to make frequent call on methods that used Task. So I decide to remove temporary this dependency. And the project begins to work normaly. Then when I have restore this dependency and change the size of the ThreadPool, issues was solves except that the vendor libray cease to work and this dependency was required for a project ... and to wrap this dependency into a WebAPI as increased the excepted developpement times. So the main reason comes from this story.

How Real Time Streaming Protocol protocol works ?

Few things to know about the rtsp protocol before starting to use this library

Introduction

RTSP is a protocol used to control and to receive video/audio streams. RTSP is very similar to the HTTP protocol. For instance HTTP protocol expose some methods like GET / POST / TRACE / DELETE / PUT and so on, and somes headers separated by carriage returns and a message body. Here it is exactly the same thing except that the methods are dedicated for the streaming operations. Here, RTSP proposed the following methods:

Methods Description
OPTIONS List the supported methods (OPTIONS/DESCRIBE/PLAY/SETUP,etc...)
DESCRIBE Retrive the SDP that contains settings used by the decoder
SETUP Ask for creating a transport layer used to stream something and create a session or bundle to an existing session
PLAY Start the streaming
PAUSE Pause the streaming
STOP Stop the streaming
GET_PARAMETER List customs parameters
SET_PARAMETER Change customs parameters
TEARDOWN Stop the streaming and destroy the session.
ANNOUNCE Posts the description of a media
RECORD Ask for recording
REDIRECT This method is used to redirects the traffic

Where RTSP are used ?

Before to enter in details, I thinks it's important to know where this protocol is used. So RTSP are used mainly by security cameras and also used by Miracast technology. And also a SmartTV can start a RTSP client and connect to RTSP server that run on your local machine in order to receive the video of your desktop.

KeepAlive considerations / How to maintain a continuous flow of data ?

Depending of yours cameras, you MUST send periodically a heart beat message using a particular message, otherwise the streaming will be closed by the server. Please notes also, to maintain a session active you must read the documentation of the camera to know which RTSP method is need to keep alive a session. There is no predefined method for all cameras. If you are using Onvif protocol, the Onvif tells that the GetParameter must be used, but in the real world some manufacturer used the GET_PARAMETER or the SET_PARAMETER or the OPTIONS methods. It's depends of the product.

AFAIK, some standards/RFC ask to use GET_PARAMETER for a keepalive/ping and not using the options. I see manufacturer that use the OPTIONS method, because OPTIONS must be implemented unlike the GET_PARAMETER and SET_PARAMETER are optional. So I recommand to ask to the camera manufacturer to be sure about the keepalive method.

⚠️ So before to start to use the .net library, please notes that you must read the documentation from the manufacturer, the heart beat mecanism are not standard from one manufacturer to an another one.

The messaging layer

By essence, RTSP is very similar to http message except important things:

  • RTSP has some proprietary and mandatory header like CSeq header

  • RTSP works asynchonously. RTSP used message correlation identifier stored on CSeq header used on each request and response and must have the same message identifier. Message identifier increment after each remote method invocation, not during a retry. So, depending to the server, it is possible that you can receive a response of a previous request after receiving a response of the new / actual request.

  • Unlike HTTP, the RTSP server can send spontaneously a request to the client ON THE SAME TCP Channel, it means when you open a tcp socket client and you send a request it may possible that the server can send a request to the client on the same socket during you request operation. And depending on how you create transport, it may possible that the server push video/audio stream on the same tcp change where requests and responses are send: this special mode is called interleaved. On the same tcp change, requests and responses can be transmitted on the same tcp changed where streams are sended by the server.

All these things are handle by this implementation.

About Session Description Protocol

What is SDP ?

SDP is a protocol used to describe a streaming session configuration, and contains important informations like the control/track uri and the keys/parameterSet used by Codecs, which are NOT accessible using Onvif protocols. Theses keys like VPS, PPS, SPS are mandatories. You can NOT decode video streams just be receiving data from a RTP channel. And theses keys are stored inside the SDP "document" where the SDP are only exchanged during a RTSP session. The SDP protocol are used not only by security cameras but also used by device that support SIP protocols like VoIP systems.

RabbitOM library

About the Alpha namespace

This namepsace contains classes for experimentations. And theses classes will replace all classes present in the clients namespaces.

Projects structures

TODO