閱讀130 返回首頁    go 阿裏雲 go 技術社區[雲棲]


RTSP協議分析

RTSP 協議分析
1.概述:
 RTSP(Real Time Streaming Protocol),實時流傳輸協議,是TCP/IP協議體係中的一個應用層協議,由哥倫比亞大學、網景和RealNetworks公司提交的IETF RFC標準。該協議定義了一對多應用程序如何有效地通過IP網絡傳送多媒體數據。類似HTTP協議的流控製協議。它們都使用純文本來發送信息,而且rtsp協議的語法也和HTTP類似,和HTTP協議相比RTSP協議所不同的地方是,RTSP協議是有狀態的協議,而HTTP是無狀態的協議。RTSP通過維護一個session來維護其狀態的轉換。RTSP協議的默認端口是554,默認的承載協議為TCP。

2.RTSP的特性:
(1).流控分離:從控製邏輯上來說RTSP和FTP相似,控製流和數據流是分開的。
(2).可擴展性:因為RTSP協議是基於文本的協議所以其具有較強的可擴展性。
(3).安全:RTSP 使用網頁安全機製。

3.RTSP 協議格式:
請求命令的格式為:
METHOD URL CR LF
Field1:value CR LF
Field2:value CR LF
......
Fieldn:value CR LF
CR LF

應答的格式為:
RTSP/major_version.minor_version status CR LF
Field1:value CR LF
Field2:value CR LF
......
Fieldn:value CR LF
CR LF

4.RTSP的主要命令:

5.RTSP命令的狀態轉換表

6.RTSP狀態碼

Status-Code = "100" ; Continue
| "200" ; OK
| "201" ; Created
| "250" ; Low on Storage Space
| "300" ; Multiple Choices
| "301" ; Moved Permanently
| "302" ; Moved Temporarily
| "303" ; See Other
| "304" ; Not Modified
| "305" ; Use Proxy
| "400" ; Bad Request
| "401" ; Unauthorized
| "402" ; Payment Required
| "403" ; Forbidden
| "404" ; Not Found
| "405" ; Method Not Allowed
| "406" ; Not Acceptable
| "407" ; Proxy Authentication Required
| "408" ; Request Time-out
| "410" ; Gone
| "411" ; Length Required
| "412" ; Precondition Failed
| "413" ; Request Entity Too Large
| "414" ; Request-URI Too Large
| "415" ; Unsupported Media Type
| "451" ; Parameter Not Understood
| "452" ; Conference Not Found
| "453" ; Not Enough Bandwidth
| "454" ; Session Not Found
| "455" ; Method Not Valid in This State
| "456" ; Header Field Not Valid for Resource
| "457" ; Invalid Range
| "458" ; Parameter Is Read-Only
| "459" ; Aggregate operation not allowed
| "460" ; Only aggregate operation allowed
| "461" ; Unsupported transport
| "462" ; Destination unreachable
| "500" ; Internal Server Error
| "501" ; Not Implemented
| "502" ; Bad Gateway
| "503" ; Service Unavailable
| "504" ; Gateway Time-out
| "505" ; RTSP Version not supported
| "551" ; Option not supported
| extension-code
extension-code = 3DIGIT
Reason-Phrase = *<TEXT, excluding CR, LF


以下是某省IPTV的RTSP協商過程:

DESCRIBE rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0
/媒體URL
Accept: application/sdp
//協商用於描述媒體信息協議
CSeq: 1

User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347
//User Agnet信息,顯示是中興的服務器,1.0的版本。如果是Helix服務器的話會有Helix 服務器的標識。
x-NAT:2.1.1.100:20081
//主要用於NAT穿透
x-zmssRtxSdp: yes

RTSP/1.0 200 OK
//應答編號
Server: ZXUSS100 1.0

Cache-Control: no-cache

Content-Base: rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/

Content-Length: 320
//內容長度信息
Content-Type: application/sdp
//描述內容信息所用的協議
CSeq: 1

Date: Wed, 29 Sep 2010 10:20:38 GMT

Expires: Wed, 29 Sep 2010 10:20:38 GMT
// SDP 描述信息

v=0

o=- 296874273 1 IN IP4 118.122.89.27

s=envivio

c=IN IP4 0.0.0.0

b=AS:1500

t=0 0

a=range:clock=20100929T095038.00Z-20100929T102038.00Z

m=video 5140 RTP/AVPF 33 96

a=control:trackID=2

a=rtpmap:33 MP2T/90000

a=3GPP-Adaptation-Support:5

a=rtcp-fb:33 nack

a=rtpmap:96 rtx/90000

a=fmtp:96 apt=33;rtx-time=0

SETUP rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/trackID=2 RTSP/1.0
//用於建立RTSP連接,協商傳輸用的協議。
CSeq: 2

3GPP-Adaptation: url=rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/trackID=2;size=1061400;target-time=2200

Transport: MP2T/RTP/UDP;unicast;destination=2.1.1.100;client_port=8360-8361,MP2T/RTP/TCP;unicast;destination=2.1.1.100;interleaved=0-1,MP2T/UDP;unicast;destination=2.1.1.100;client_port=8360-8361,MP2T/TCP;unicast;destination=2.1.1.100;interleaved=0-1
// MP2T/RTP/UDP表示是TS流用於RTP打包,基於UDP傳輸。MP2T/RTP/TCP表示是TS流用於RTP打包,基於TCP。
User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347

RTSP/1.0 200 OK

Server: ZXUSS100 1.0

CSeq: 2

Date: Wed, 29 Sep 2010 10:20:38 GMT

Expires: Wed, 29 Sep 2010 10:20:38 GMT

Session: 65565885

Transport: MP2T/RTP/UDP;unicast;destination=2.1.1.100;client_port=8360-8361;server_port=13306-13307;source=118.122.89.29
// 通過協商MP2T/RTP/UDP表示是TS流用於RTP打包,基於UDP傳輸。server端端口:13306-13307。client端端口:8360-8361
3GPP-Adaptation:url=rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/trackID=2;size=1061400;target-time=2200

PLAY rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0
//播放視頻。對於有些視頻可能會分別要對音頻視頻進行play。
CSeq: 3

Session: 65565885

User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347

Scale: 1.0

Range: npt=end-

//npt=end-在IPTV2.0裏麵有其自身的定義(可參看上海電信IPTV2.0標準)

RTSP/1.0 200 OK

Server: ZXUSS100 1.0

CSeq: 3

Range: npt=end-

Scale: 1.0

Session: 65565885

RTP-Info: url=rtsp://118.122.89.29:13306/live/ch10083121594790060557.sdp/trackID=2

......

PLAY rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0
//play的另外一種用法。用於快進和快退。
CSeq: 43

Session: 65565885

User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347

Scale: -32.0
//Scale: -32.0,表示以32倍速快退。Scale: 32.0,表示以32倍速快進。
Range: npt=now-

RTSP/1.0 200 OK

Server: ZXUSS100 1.0

CSeq: 43

Range: clock=20100929T102609.02Z-20100929T095637.75Z

Scale: -32.0

Session: 65565885

RTP-Info: url=rtsp://118.122.89.36:10084/live/ch10083121594790060557.sdp/trackID=2;seq=22277;rtptime=1792329138

GET_PARAMETER rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0
//獲取當前的一些播放參數。
CSeq: 44

Session: 65565885

User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347

x-Timeshift_Range
//請求時移的範圍
x-Timeshift_Current
//獲取當前的時間點

RTSP/1.0 200 OK
//返回當前的媒體信息。
Server: ZXUSS100 1.0

CSeq: 44

Session: 65565885

x-Timeshift_Range: clock=20100929T095638.83Z-20100929T102638.83Z

x-Timeshift_Current: clock=20100929T102530.20Z;rtptime=1788844914

中間省去了45,46,47三個包。通過CSeq: 48字段可以看出來

PLAY rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0
用於恢複正常的播放速度。
CSeq: 48

Session: 65565885

User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347

Scale: 1.0

Range: npt=beginning-

RTSP/1.0 200 OK

Server: ZXUSS100 1.0

CSeq: 48

Range: clock=20100929T095730.00Z-20100929T102730.61Z
//可以時移的範圍。
Scale: 1.0

Session: 65565885

RTP-Info: url=rtsp://118.122.89.36:10084/live/ch10083121594790060557.sdp/trackID=2;seq=39900;rtptime=1637595010

<中間在Descript應答中所用的SDP協議將會在以後中描述>

最後更新:2017-04-03 07:57:10

  上一篇:go asp.net概述
  下一篇:go 【方法1】刪除Map中Value重複的記錄,並且隻保留Key最小的那條記錄