RTP/AVP & RTP/AVP/TCP

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/AVP/UDP中視頻或音頻的RTP和RTCP交互示意
RTP/AVP/UDP 視頻傳輸框圖示意
  • 基本流程: 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.
RTSP Interleaved Frame

用wireshark抓包,示意如下:

RTP層上又封裝了一層:RTSP Interleaved Frame層

以上數(shù)據(jù)中看到Payload type等于97, 一般為音頻(視頻的Payload type一般為96).

視頻的RTSP Interleaved Frame數(shù)據(jù)分析
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-1interleaved=一般指定為一個(gè)范圍: 0-12-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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容