Rtsp protocol interaction process

Real Time Streaming Protocol or RTSP (Real Time Streaming Protocol) is an application layer protocol proposed by Real network and Netscape to effectively transmit streaming media data on an IP network. RTSP provides an extensible framework that enables controllable, on-demand transmission of real-time data, such as audio and video files. The source data may include feedback of on-site data and stored files. rtsp provides controls such as pause and fast forward for streaming media, but it does not transmit data itself. rtsp functions as a remote control of the streaming media server. Transmission of data can be done through the tcp and udp protocols in the transport layer. Rtsp also provides some effective methods based on the rtp transmission mechanism.

Directory [hide]

1 RTSP message format
2 Simple rtsp interactive process
3 Common methods in rtsp
3.1 OPTION
3.2 DESCRIBE
3.3 SETUP
3.4 PLAY
3.5 PAUSE
3.6 TEARDOWN
3.7 Other methods
4 sdp format
5 RTSP on-demand message process example


RTSP message format


There are two types of RTSP messages, one is a request message and the other is a response message. The two messages have different formats.
Request messages:

Method URI RTSP version CR LF 
message header CR LF CR LF 
message body CR LF 

The method includes all commands in the OPTION response, URI is the address of the recipient, for example
rtsp: //192.168.20.136

The RTSP version is generally RTSP / 1.0. The CR LF at the back of each line indicates carriage return and line feed, and the corresponding analysis is required at the receiving end. The last message header needs two CR LF
response messages:

RTSP version status code interpretation CR LF 
message header CR LF CR LF 
message body CR LF

where RTSP version is generally RTSP / 1.0, the status code is a value, 200 means success, and the interpretation is the text interpretation corresponding to the status code.

Simple rtsp interaction process

C means rtsp client, S means rtsp server

1.C-> S: OPTION request // Ask S what methods are available 
1.S-> C: OPTION response // S response information includes all available methods provided 
2.C-> S: DESCRIBE request // require Get the media initialization description information provided by S 
2.S-> C: DESCRIBE response // S responds to the media initialization description information, mainly sdp 
3.C-> S: SETUP request // Set session attributes, and transmission mode, reminder S establishes a session 
3. S-> C: SETUP response // S establishes a session, returns the session identifier, and session related information 
4.C-> S: PLAY request // C requests to play 
4.S-> C: PLAY response // S response information that should be requested 
5.S-> C: send streaming data 
6.C-> S: TEARDOWN request // C request to close the session 
6.S-> C: TEARDOWN response // S response should request the 
above The process is a standard and friendly rtsp process, but the actual demand does not necessarily come step by step.
Steps 3 and 4 are required!
In the first step, as long as the server client agrees and which methods are available, the option request can be omitted. The second step, if we have other ways to obtain the media initialization description information (such as http request, etc.), then we do not need to complete the describe request in rtsp. In the fifth step, you can decide whether you need it based on the design of the system requirements.

Common methods in rtsp

OPTION

The purpose is to get the available methods provided by the server:

OPTIONS rtsp: //192.168.20.136: 5000 / xxx666 RTSP / 1.0 
CSeq: 1 // Each message is marked with a serial number, the first packet is usually an option request message 
User-Agent: VLC media player (LIVE555 Streaming Media v2005 .11.10) The 
server's response information includes some methods provided, such as:

 
RTSP / 1.0 200 OK 
Server: UServer 0.9.7_rc1 
Cseq: 1 // The cseq value of each response message corresponds to the cseq of the request message 
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, SCALE, 
GET_PARAMETER // Server Available methods 


DESCRIBE

C initiates a DESCRIBE request to S in order to obtain the session description information (SDP):

 
DESCRIBE rtsp://192.168.20.136:5000/xxx666 RTSP/1.0 

CSeq: 2 
token: 
Accept: application / sdp 
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10) The 
server responds with some descriptive information about this session (sdp):

RTSP/1.0 200 OK 
Server: UServer 0.9.7_rc1 
Cseq: 2 
x-prev-url: rtsp://192.168.20.136:5000 
x-next-url: rtsp://192.168.20.136:5000 
x-Accept-Retransmit: our-retransmit 
x-Accept-Dynamic-Rate: 1 
Cache-Control: must-revalidate 
Last-Modified: Fri, 10 Nov 2006 12:34:38 GMT 
Date: Fri, 10 Nov 2006 12:34:38 GMT 
Expires: Fri, 10 Nov 2006 12:34:38 GMT 
Content-Base: rtsp://192.168.20.136:5000/xxx666/ 
Content-Length: 344 
Content-Type: application/sdp 

v = 0 // The following is the sdp information 
o = OnewaveUServerNG 1451516402 1025358037 IN IP4 192.168.20.136 
s = / xxx666 
u = http: /// 
e = admin @ 
c = IN IP4 0.0.0.0 
t = 0 0 
a = isma- compliance: 1,1.0,1 

a = range: npt = 0- 
m = video 0 RTP / AVP 96 // m represents the media description, the following is the media description of the video channel in the session 
a = rtpmap: 96 MP4V-ES / 90000 
a = fmtp: 96 
profile- level-id = 245; config = 000001B0F5000001B509000001000000012000C888B0E0E0FA62D089028307 

a = control: trackID = 0 // trackID = 0 indicates that the video stream uses channel 0 


SETUP

The client reminds the server to establish a session and determine the transmission mode:

SETUP rtsp: //192.168.20.136: 5000 / xxx666 / trackID = 0 RTSP / 1.0 
CSeq: 3 
Transport: RTP / AVP / TCP; unicast; interleaved = 0-1 
User-Agent: VLC media player (LIVE555 Streaming Media v2005. 11.10) The 
trackID = 0 in the uri indicates that the channel is set. The Transport parameter sets the transmission mode and packet
structure. The second byte of the header of the next data packet is interleaved, and its value is
different for each channel. The interleaved value of trackID = 0 has two 0s or 1s, 0 means rtp packet, 1 means rtcp packet, accept
According to the value of interleaved, the end distinguishes which kind of data packet.

Server response message:

RTSP / 1.0 200 OK 
Server: UServer 0.9.7_rc1 
Cseq: 3 
Session: 6310936469860791894 // Session identifier returned by the server 
Cache-Control: no-cache 
Transport: RTP / AVP / TCP; unicast; interleaved = 0-1; ssrc = 6B8B4567 


PLAY

The client sends a playback request:

PLAY rtsp: //192.168.20.136: 5000 / xxx666 RTSP / 1.0 
CSeq: 4 
Session: 6310936469860791894 
Range: npt = 0.000- // Set the range of playback time 
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10) 
server Response message:

 
RTSP / 1.0 200 OK 
Server: UServer 0.9.7_rc1 
Cseq: 4 
Session: 6310936469860791894 
Range: npt = 0.000000- 
RTP-Info: url = trackID = 0; seq = 17040; rtptime = 1467265309 
// seq and rtptime are both in rtp package Information of 
PAUSE

The client initiates a pause request:

PAUSE rtsp: //192.168.20.136: 5000 / xxx666 RTSP / 1.0 
Cseq: 5
Session: 6310936469860791894
server response:

RTSP/1.0 200 OK 
Server: UServer 0.9.7_rc1 
Cseq: 5 
Session: 6310936469860791894
TEARDOWN

The client initiates a shutdown request:

TEARDOWN rtsp: //192.168.20.136: 5000 / xxx666 RTSP / 1.0 
CSeq: 6
Session: 6310936469860791894 
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10) 
server response:

 
RTSP / 1.0 200 OK 
Server: UServer 0.9.7_rc1 
Cseq: 6
Session: 6310936469860791894 
Connection: Close 
Other methods

The above methods are the most commonly used in the interaction process, and there are other important methods such as:
get / set_parameter, pause, redirect, etc.

sdp format

v=<version> 
o=<username> <session id> <version> <network type> <address type> <address> 
s=<session name> 
i=<session description> 
u=<URI> 
e=<email address> 
p=<phone number> 
c=<network type> <address type> <connection address> 
b=<modifier>:<bandwidth-value> 
t=<start time> <stop time> 
r=<repeat interval> <active duration> <list of offsets from start-time> 
z=<adjustment time> <offset> <adjustment time> <offset> .... 
k=<method> 
k=<method>:<encryption key> 
a=<attribute> 
a=<attribute>: <value> s = (session name) o = (owner / creator and session identifier) v = (protocol version) 
m = <media> <port> <transport> <fmt list> 



i = * (session information) 
u = * (URI description) 
e = * (Email address) 
p = * (phone number) 
c = * (connection information) 
b = * (bandwidth information) 
z = * (time zone adjustment) 
k = * (encryption key) 
a = * (0 or more session attribute lines) 
time description: 
t = (session activity time) 
r = * (0 or more repetitions) 
media description: 
m = (media name And transmission address) 
i = * (media title) 
c = * (connection information — this field is optional if included in the session layer) 
b = * (bandwidth information) 
k = * (encryption key) 
a = * (0 Or multiple media attribute rows) 


RTSP on-demand message process example

Client: VLC
RTSP server: LIVE555 Media Server

1)C(Client)-> M(Media Server) 
OPTIONS rtsp://192.168.1.109/1.mpg RTSP/1.0 
CSeq: 1 
user-Agent: VLC media player(LIVE555 Streaming Media v2007.02.20) 

1)M -> C 
RTSP/1.0 200 OK 
CSeq: 1 
Date: wed, Feb 20 2008 07:13:24 GMT 
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE 
2)C -> M 
DESCRIBE rtsp://192.168.1.109/1.mpg RTSP/1.0 
CSeq: 2 
Accept: application/sdp 
User-Agent: VLC media player(LIVE555 Streaming Media v2007.02.20) 

2)M -> C 
RTSP/1.0 200 OK 
CSeq: 2 
Date: wed, Feb 20 2008 07:13:25 GMT 
Content-Base: rtsp://192.168.1.109/1.mpg/ 
Content-type: application/sdp 
Content-length: 447 
v=0 
o =- 2284269756 1 IN IP4 192.168.1.109 
s=MPEG-1 or 2 program Stream, streamed by the LIVE555 Media Server 
i=1.mpg 
t=0 0 
a=tool:LIVE555 Streaming Media v2008.02.08 
a=type:broadcast 
a=control:* 
a=range:npt=0-66.181 
a=x-qt-text-nam:MPEG-1 or Program Stream, streamed by the LIVE555 Media Server 
a=x-qt-text-inf:1.mpg 
m=video 0 RTP/AVP 32 
c=IN IP4 0.0.0.0 
a=control:track1 
m=audio 0 RTP/AVP 14 
c=IN IP4 0.0.0.0 
a=control:track2 
3)C -> M 
SETUP rtsp://192.168.1.109/1.mpg/track1 RTSP/1.0 
CSeq: 3 
Transport: RTP/AVP; unicast;client_port=1112-1113 
User-Agent: VLC media player(LIVE555 Streaming Media v2007.02.20) 

3)M -> C 
RTSP/1.0 200 OK 
CSeq: 3 
Date: wed, Feb 20 2008 07:13:25 GMT 
Transport: RTP/AVP;unicast;destination=192.168.1.222;source=192.168.1.109;client_port=1112-1113;server_port=6970-6971 
Session: 3 
4)C -> M 
SETUP rtsp://192.168.1.109/1.mpg/track2 RTSP/1.0 
CSeq: 4 
Transport: RTP/AVP; unicast;client_port=1114-1115 
Session: 3 
User-Agent: VLC media player(LIVE555 Streaming Media v2007.02.20) 

4)M -> C 
RTSP/1.0 200 OK 
CSeq: 4 
Date: wed, Feb 20 2008 07:13:25 GMT 
Transport: RTP/AVP;unicast;destination=192.168.1.222;source=192.168.1.109;client_port=1114-1115;server_port=6972-6973 
Session: 3 
5)C -> M 
PLAY rtsp://192.168.1.109/1.mpg/ RTSP/1.0 
CSeq: 5 
Session: 3 
Range: npt=0.000- 
User-Agent: VLC media player(LIVE555 Streaming Media v2007.02.20) 

5) M-> C 
RTSP / 1.0 200 OK 
CSeq: 5 
Range: npt = 0.000- 
Session: 3 
RTP-Info: url = rtsp: //192.168.1.109/1.mpg/track1; seq = 9200; rtptime = 214793785 , url = rtsp: //192.168.1.109/1.mpg/track2; seq = 12770; rtptime = 31721
(start streaming media ...)
————————————————

Published 115 original articles · Like 29 · Visitors 50,000+

Guess you like

Origin blog.csdn.net/huabiaochen/article/details/100666624