RTP/AVP & RTP/AVP/TCP
RTSP流(传输RTP包)的传输方式有两种:
RTP/AVP/UDP
-
RTP/AVP/TCP
默认传输方式为: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申请时,指定client端用于接收RTP和RTCP交互的端口:
client_port=4588-4589
.- 偶数(
4588
)
用于接收RTP数据. - 奇数(
4589
)
用于进行RTCP交互.
RTSP Server响应时, 会指定服务器端用于交互的端口:server_port=6256-6257.
其中偶数(6256)用于发送RTP数据, 奇数(6257)用于RTCP交互.
视频和音频分别执行SETUP指令, 故它们有自己独自的RTP和RTCP端口.
- 基本流程:
RTP打包->UDP传输->RTP解包
. - RTCP用于质量控制, 通过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.- 有时候处于安全设计, 防火墙可能要求RTSP控制方法和流数据公用一个通信通道,进行交错传输.
- 仅在RTSP控制方法通过TCP方式传输时,才可以交错传输二进制数据.
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.既然是在同一个通道传输,怎么区分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抓包,示意如下:
以上数据中看到Payload type等于97, 一般为音频(视频的Payload type一般为96).
interleaved参数详解
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请求和响应的示意如下:
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=
一般指定为一个范围:0-1
或2-3
一般偶数用于标示RTP数据
奇数用于标示RTCP数据.openRTSP (live555)
- 有
-t
参数Transport: RTP/AVP/TCP
- 无
-t
参数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 - 偶数(