美文网首页ijkplayer秘籍
RTP/AVP & RTP/AVP/TCP

RTP/AVP & RTP/AVP/TCP

作者: FlyingPenguin | 来源:发表于2016-08-24 21:56 被阅读2089次

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/AVP/UDP中视频或音频的RTP和RTCP交互示意
RTP/AVP/UDP 视频传输框图示意
  • 基本流程: 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.
RTSP Interleaved Frame

用wireshark抓包,示意如下:

RTP层上又封装了一层:RTSP Interleaved Frame层

以上数据中看到Payload type等于97, 一般为音频(视频的Payload type一般为96).

视频的RTSP Interleaved Frame数据分析
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-1interleaved=一般指定为一个范围: 0-12-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

相关文章

  • RTP/AVP & RTP/AVP/TCP

    RTSP流(传输RTP包)的传输方式有两种: RTP/AVP/UDP RTP/AVP/TCP.默认传输方式为: R...

  • 一些缩写的全称

    RTP/AVP AVP audio video profile AVPF audio video profi...

  • 山武阀门定位器AVP302-RSD3A

    山武定位器型号 AVP300-RSD3A AVP301-RSD3A AVP302-RSD3A AVP100-H S...

  • NuPlayer:RTP/RTSP

    RTSP SDP RTP/RTCP 介绍应用层 RTSP、SDP; 传输层 RTP、TCP、UDP; 网络层 IP...

  • 协议

    rtp协议基于udp,视频数据流传输rtcp协议基于udp,在rtp基础上可控制码率、倍数等rtsp协议基于tcp...

  • RTP timestamp(时间戳)算法 (live555)

    live555中进行RTP打包时,生成RTP header时,需要计算该RTP的时间戳. RTP header t...

  • WebRTC源码分析之RTP/RTCP(一)

    首先学习一下RTP/RTCP的基础知识。 RTP/RTCP协议 RTP报头 当没有CSRC时RTP报头一共12个字...

  • H264 RTP FU-A解包

    每一个RTP包头长度RTP_HEADER_LEN为12,RTP头后面就是H264数据,对于RTP里的FU-A分片的...

  • WebRTC之RTP包

    RTP固定头部 RTP的固定头部,详情可以阅读rfc文档5.1 RTP Fixed Header Fields V...

  • webrtc-RTP/RTSP/RTCP的概念

    RTSP发起/终结流媒体、RTP传输流媒体数据 、RTCP对RTP进行控制,同步。 RTP Real-time T...

网友评论

  • 363bfcfcde3c:博主,我使用 RTP/TCP 协议获取 RTP 数据包,在 RTSP 通信中设置:

    Transport: RTP/AVP/TCP;unicast;interleaved=0-1

    通过判断语句来接收 RTP 数据包:

    /* 如果接受的数据的第一个字节是符号'$' 且是信道0 ,说明是 RTP 数据包,就开始解包*/
    if(0x24 == recvbuf[0] && 0 == recvbuf[1])
    {
    poutfile = fopen(outputfilename, "ab+");
    rtp_unpackage(recvbuf, receive_bytes);
    fclose(poutfile);
    }

    但是还是会接收到除 RTP 数据包以外的数据包,不知道是什么问题?
    363bfcfcde3c:@FlyingPenguin 我通过 wireshark 抓包,发现没有 RTSP 数据包和 RTP 数据包之类的数据包,有 RSL 这些类型为 unknown 数据包,但是之前采用 RTP/UDP 协议可以正常接收 RTP 数据包,可能是因为设置了独立的端口用来接收 RTP 数据包。
    363bfcfcde3c:@FlyingPenguin 当我设置接收的数据包的最大值为1500字节,这个异常数据包大小为1500字节;当我设置接收的数据包的最大值为2000字节,这个异常数据包大小为2000字节;而正常接收到的 RTP 数据包大小都为 1206字节。
    FlyingPenguin:@寒烟凝碧 异常数据什么特征 是随机的吗

本文标题:RTP/AVP & RTP/AVP/TCP

本文链接:https://www.haomeiwen.com/subject/weagsttx.html