RTSP Session Basic Process
RTSP Interaction Process:
C represents the RTSP client, s represents the RTSP server
①c->s:option request//Ask S which methods are available
S->c:option Response//s Response information includes all available methods provided
②c->s:describe Request//Requires media initialization description information provided by S
S->c:describe response//s responds to media initialization description information, mostly SDP
③c->s:setup request//Set session properties, and transfer mode, reminding S to establish a session
S->c:setup response//s Set up session, return session identifier and session-related information
④c->s:play Request//C Requests play
S->c:play Response//s Response Request Information
S->c: Sending streaming media data
⑤c->s:teardown request//C Requests Close session
S->c:teardown Response//s Response request
The above process is the standard RTSP process, where steps 3rd and 4th are required.
Opencore after executing Player_set_datasource,prepare, when Player_init is executed, if DATASOURCE is found to be an RTSP stream, it enters the RTSP module.
Opencore's RTSP module is implemented in Pvrtsp_client_engine_node.cpp, Pvrtspenginenode::sendrtspdescribe () describes the process of State change during connection establishment.
When it comes to attention, Opencore does not wait to receive response after issuing the option request, but to send describe request directly before it starts receiving option response and describe response.
LIVE555 uses Rtspserver::rtspclientsession::incomingrequesthandler () in RTSPServer.cpp to process the request from the client side.
RTSP source Receiving end Use sample:
1 //RtstClientTest.cpp2#include"stdafx.h"3#include"RtspRequest.h"4#include"Rtp.h"5 6 rtsprequest g_rtsprequest;7 int_tmain (intARGC, _tchar*argv[])8 {9 //ReceiveTen stringURL ="rtsp://192.168.1.1:554/aacaudiotest"; One stringSetupname ="aacaudiotest"; AINT Rtpport =8080; -INT Rtcpport = Rtpport +2; - stringSDP; the INT64 Sess; -G_rtsprequest.open (Url.c_str (),"127.0.0.0",0); - g_rtsprequest.requestoptions (); -G_rtsprequest.requestdescribe (&SDP); +G_rtsprequest.requestsetup (Setupname.c_str (), TRANSPORTMODERTPUDP, Rtpport, Rtcpport, &sess); - G_rtsprequest.requestplay (); +rtp* PRTP =NewRTP (); APrtp->open ("127.0.0.0", rtpport); atPbyte pbuffer =Newbyte[1024x768*1024x768*Ten]; - intIread; - INT Payloadtype; - WORD SequenceNumber; - INT32 TimeStamp; - INT32 ssrc; in while(TRUE) { -Iread = Prtp->read (pbuffer,1024x768*1024x768*Ten, &payloadtype, &sequencenumber, ×tamp, &ssrc); to if(Iread >0) { + //Save Buff - } the * } $ DeletePRTP;Panax Notoginseng g_rtsprequest.requestpause (); - G_rtsprequest.requestteardown (); the g_rtsprequest.close (); + Delete[]pbuffer; A the return 0; + } - $ $ - //
View Code
1.OPTION
The goal 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 an ordinal, 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 of the methods provided, such as:
rtsp/1.0 OK
Server:userver 0.9.7_rc1
Cseq:1//CSEQ value of each response message corresponds to the cseq of the request message
Public:options, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, scale,
Get_parameter//The available methods provided by the server
2.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 to some descriptive information (SDP) for this session:
rtsp/1.0 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, 2006 12:34:38 GMT
Date:fri, 2006 12:34:38 GMT
Expires:fri, 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 are SDP information
O=onewaveuserverng 1451516402 1025358037 in IP4 192.168.20.136
s=/xxx666
u=http:///
[Email protected]
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//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 is using channel 0
3.SETUP
The client reminds the server to establish a session and determines the transfer 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 URI is provided with Trackid=0, which indicates that the channel is set. The transport parameter sets the transport mode, the package structure. The second byte position of the next packet header is interleaved, whose value is different for each channel, the Trackid=0 interleaved value has two 0 or 1,0 for the RTP packet, 1 for the RTCP package, The receiving end distinguishes what kind of packet according to the value of the interleaved.
Server Response Information:
rtsp/1.0 OK
Server:userver 0.9.7_rc1
Cseq:3
session:6310936469860791894//The session identifier of the server response
Cache-control:no-cache
transport:rtp/avp/tcp;unicast;interleaved=0-1;ssrc=6b8b4567
4.PLAY
The client sends a play 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 Information:
rtsp/1.0 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 all information in the RTP package.
5.TEARDOWN
The client initiates a shutdown request:
TEARDOWN rtsp://192.168.20.136:5000/xxx666 rtsp/1.0
Cseq:5
session:6310936469860791894
USER-AGENT:VLC Media Player (LIVE555 streaming media v2005.11.10)
Server response:
rtsp/1.0 OK
Server:userver 0.9.7_rc1
Cseq:5
session:6310936469860791894
Connection:close
The above methods are the most common in the interactive process, and there are some important methods such as get/set_parameter,pause,redirect and so on.
Ps:
Format of the SDP
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>
m=<media> <port> <transport> <fmt list>
v = (Protocol version)
o = (owner/creator and session identifier)
s = (session name)
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 property rows)
Time Description:
T = (Session activity time)
R = * (0 or more repetitions)
Media Description:
m = (media name and transport 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 more media property rows)
Reference article: rfc2326 (RTSP); rfc2327 (SDP)
RTSP on-Demand Message process instance (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 OK
Cseq:1
date:wed, Feb 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 OK
Cseq:2
date:wed, Feb 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 OK
Cseq:3
date:wed, Feb 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 OK
Cseq:4
date:wed, Feb 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 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/tr
RTSP Session Basic Process