RTSP (Real-Time Stream Protocol) is a text-based multimedia playback control protocol, belonging to the application layer. RTSP works in client mode and provides operations such as play, pause, rewind, and forward for streaming media. The standard is specified by IETF, and the corresponding protocol is RFC2326. As an application layer protocol, RTSP provides an extensible framework that makes it possible to control and broadcast streaming media on demand. It is mainly used to control the transmission of data with real-time characteristics, but it is not used to transmit streaming media data. Instead, it must rely on the services provided by the lower layer transmission protocol (such as RTP/RTCP) to complete the transmission of streaming media data. RTSP is responsible for defining specific control information, operation methods, status codes, and describing the interactive operations with RTP. The RTSP media service protocol framework is as follows: To play RTSP media streams, the client needs to know the URL of the media source. The RTSP URL format is generally as follows:
For example, a complete RTSP URL can be written as:
For example, the RTSP address format of the commonly used Hikvision network cameras on the market is:
Example:
RTSP message After having a general understanding of the use of the RTSP protocol, let's take a look at the RTSP message structure. RTSP is a text-based protocol that uses CRLF (Carriage Return Line Feed) as the end of each line. Its advantage is that it is easy to add custom parameters during use and also convenient for packet capture analysis. From the perspective of message transmission direction, RTSP messages are divided into two categories: request messages and response messages. Request messages refer to requests sent from the client to the server (there are also a small number of requests sent from the server to the client), and response messages refer to responses from the server to the client. Common methods and functions of RTSP request messages: A basic RTSP interaction process is as follows, C represents the client and S represents the server. First, the client connects to the streaming server and sends an RTSP description request (DESCRIBE request). The server responds (DESCRIBE response) through an SDP (Session Description Protocol) description. The feedback information includes the number of streams, media type, and other information. The client analyzes the SDP description and sends an RTSP connection establishment request (SETUP request) for each stream in the session. This command tells the server the port used to receive media data. After the server responds to the request (SETUP response) and establishes a connection, it starts to transmit the media stream (RTP packet) to the client. During the playback process, the client can also send requests to the server to control fast forward, fast rewind, and pause, etc. Finally, the client can send a termination request (TEARDOWN request) to end the streaming session. Let's take a closer look at the working process of RTSP through a specific message example: (1) OPTIONS The OPTIONS request is a request from the client to the server to ask for available methods. The request and response examples are as follows:
(2) DESCRIBE The client requests a media resource description from the server, and the server responds to the client's request in the SDP (Session Description Protocol) format. The resource description lists the media streams of the requested media and their related information. Typically, audio and video are transmitted as one media stream each. The following is an example:
(3) SETUP The SETUP request determines how the specific media stream is transmitted and must be sent before the PLAY request. The SETUP request contains the URL of the media stream and the port used by the client to receive RTP data (audio or video) and the port used to receive RTCP data (meta information). The server's reply usually contains a confirmation of the client's request parameters and will supplement the missing parts, such as the sending port selected by the server. Each media stream must first be configured through a SETUP request before sending a PLAY request.
(4) PLAY The client plays one or all media streams through a PLAY request. The PLAY request can be sent once or multiple times. When sent once, the URL is the address containing all media streams. When sent multiple times, the URL carried in each request only contains one corresponding media stream. The PLAY request can specify the playback range. If not specified, the media stream is played from the beginning to the end. If the media stream is paused during playback, the playback of the stream can be restarted at the pause point.
(5) PAUSE A PAUSE request will pause one or all media streams, which can be resumed later with a PLAY request. The PAUSE request carries the URL of the requested media stream. If the parameter range exists, it indicates where to pause. If the parameter does not exist, the pause takes effect immediately, and the duration of the pause is indefinite.
(6) TEARDOWN End session request, which stops all media streams and releases related session data on the server.
(7) GET_PARAMETER Retrieve the parameter value in the specified URI data. GET_PARAMETER without a message body can be used to test whether the server or client is accessible (similar to the ping function).
(8) SET_PARAMETER Used to set the parameters of the specified media stream.
(9) REDIRECT Redirect request is used by the server to inform the client of the new service address. The client needs to re-initiate a request to this new address. The redirect request may contain a Range parameter to indicate the time when the redirection takes effect. If the client needs to initiate a request to the new service address, it must first tear down the current session and then set up a new session to the specified new host.
(10) ANNOUNCE The ANNOUNCE request has two purposes: (1) C->S: the client publishes the media information description specified by the URL to the server; (2) S->C: real-time update of the conversation description. If a new media stream is added to the media representation, such as during a live broadcast, the entire media representation description must be resent, rather than just the new part.
(11) RECORD Request to record a specified range of media data. The request can specify the start and end timestamps of the recording. If the time range is not specified, the start and end times in the presentation description are used. In this case, if the session has already started, the recording operation is started immediately.
The above is an introduction to the commonly used commands and examples in RTSP. Finally, let's take a look at an actual RTSP command interaction process, which is obtained by pulling and playing the video stream of the Hikvision camera through a PC and capturing the client data through Wireshark:
|
<<: Unveiling the mystery of MPLS, do you know all this?
>>: In the 5G era, virtual operators “disappear”
The case shared in this issue is related to VRRP ...
CloudCone's [2021 Flash Sale] event is still ...
ChangeIP is a site under Sharktech's data cen...
[[420040]] Before we knew it, 5G has been officia...
Speed, speed, and speed. If a website wants to pr...
[51CTO.com original article] In late summer 2017,...
At present, 5G communication technology has cause...
[[183847]] There is a distinct difference between...
Making machines communicate with humans is the be...
On April 20, 1994, China gained full access to th...
As we all know, WiFi has penetrated into various ...
This article is reproduced from Leiphone.com. If ...
1. Introduction The solution is suitable for tech...
Two years ago, 5G was still far away from us; two...
While cellular technology is often thought of as ...