RTSP流(傳輸RTP包)的傳輸方式有兩種:
RTP/AVP/UDP
-
RTP/AVP/TCP
.
默認(rèn)傳輸方式為:RTP/AVP
. 即RTP/AVP/UDP
.
RTP/AVP stand for RTP A/V Profile
.
采用那種方式傳輸是由 客戶端 來決定的.
客戶端在RTSP的SETUP命令中需要確定是使用TCP傳輸還是建立UDP傳輸.
RTP/AVP
C->S: SETUP rtsp://example.com/foo/bar/baz.rm RTSP/1.0
CSeq: 302
Transport: RTP/AVP;unicast;client_port=4588-4589
S->C: RTSP/1.0 200 OK
CSeq: 302
Date: 23 Jan 1997 15:35:06 GMT
Session: 47112344
Transport: RTP/AVP;unicast; client_port=4588-4589;server_port=6256-6257
在RTP/AVP情況下, RTSP Client向RTSP Server提出SETUP申請(qǐng)時(shí),指定client端用于接收RTP和RTCP交互的端口:client_port=4588-4589
.
- 偶數(shù)(
4588
)
用于接收RTP數(shù)據(jù). - 奇數(shù)(
4589
)
用于進(jìn)行RTCP交互.
RTSP Server響應(yīng)時(shí), 會(huì)指定服務(wù)器端用于交互的端口:server_port=6256-6257.
其中偶數(shù)(6256)用于發(fā)送RTP數(shù)據(jù), 奇數(shù)(6257)用于RTCP交互.
視頻和音頻分別執(zhí)行SETUP指令, 故它們有自己獨(dú)自的RTP和RTCP端口.
- 基本流程:
RTP打包->UDP傳輸->RTP解包
. - RTCP用于質(zhì)量控制, 通過QoS反饋到RTP打包和RTP解包.
RTP/AVP/TCP
Certain firewall designs and other circumstances may force a server to interleave RTSP methods and stream data.
This interleaving should generally be avoided unless necessary since it complicates client and server operation and imposes additional overhead.
Interleaved binary data SHOULD only be used if RTSP is carried over TCP.
- 有時(shí)候處于安全設(shè)計(jì), 防火墻可能要求RTSP控制方法和流數(shù)據(jù)公用一個(gè)通信通道拧抖,進(jìn)行交錯(cuò)傳輸.
- 僅在RTSP控制方法通過TCP方式傳輸時(shí)已球,才可以交錯(cuò)傳輸二進(jìn)制數(shù)據(jù).
interleaved
When the transport choice is RTP, RTCP messages are also interleaved
by the server over the TCP connection.
As a default, RTCP packets are sent on the first available channel higher than the RTP channel.
The client MAY explicitly request RTCP packets on another channel.
This is done by specifying two channels in the interleaved parameter of the Transport header.
既然是在同一個(gè)通道傳輸碳抄,怎么區(qū)分RTP通道(channel)和RTCP通道呢?
答案是 在RTP層之上增加一層, 叫做:RTSP Interleaved Frame
層.
該層在RFC2326中的描述是:
Stream data such as RTP packets is
- encapsulated by an ASCII dollar sign (24 hexadecimal),
- followed by a one-byte channel identifier,
- followed by the length of the encapsulated binary data as a binary, two-byte integer in network byte order.
The stream data follows immediately afterwards, without a CRLF, but including the upper-layer protocol headers. Each $ block contains exactly one upper-layer protocol data unit, e.g., one RTP packet.
用wireshark抓包撵幽,示意如下:
以上數(shù)據(jù)中看到Payload type等于97, 一般為音頻(視頻的Payload type一般為96).
interleaved參數(shù)詳解
The interleaved parameter implies mixing the media stream with
the control stream in whatever protocol is being used by the
control stream, using the mechanism defined in Section 10.12.
The argument provides the channel number to be used in the $
statement.
This parameter may be specified as a range, e.g.,
interleaved=4-5 in cases where the transport choice for the
media stream requires it.
This allows RTP/RTCP to be handled similarly to the way that it is
done with UDP, i.e., one channel for RTP and the other for RTCP.
SETUP請(qǐng)求和響應(yīng)的示意如下:
C->S: SETUP rtsp://foo.com/bar.file RTSP/1.0
CSeq: 2
Transport: RTP/AVP/TCP;interleaved=0-1
S->C: RTSP/1.0 200 OK
CSeq: 2
Date: 05 Jun 1997 18:57:18 GMT
Transport: RTP/AVP/TCP;interleaved=0-1
可看出Transport: RTP/AVP/TCP;interleaved=0-1
中interleaved=
一般指定為一個(gè)范圍: 0-1
或2-3
一般偶數(shù)用于標(biāo)示RTP數(shù)據(jù)
奇數(shù)用于標(biāo)示RTCP數(shù)據(jù).
openRTSP (live555)
- 有
-t
參數(shù)
Transport: RTP/AVP/TCP
- 無
-t
參數(shù)
Transport: RTP/AVP
References:
http://blog.sina.com.cn/s/blog_4c2bf01a0100xc47.html
http://www.ithao123.cn/content-8129332.html
http://zhidao.baidu.com/link?url=f7yWE9pL67sf4vj0Vni0UiYGsNJ98v-u0Ybfubo12CjqRrSTcQEwBYBgTZrs_tMX6moSSOBVR_XIFYRZC03HJffJmCKuzpFvnHEk5TKhZwC
https://tools.ietf.org/pdf/rfc3550.pdf
https://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol