rtp协议基于udp传输,流媒体音视频数据被封装在rtp中,通过rtp协议进行实时的传输。

一、rtp协议头格式

The RTP header has a minimum size of 12 bytes. After the header, optional header extensions may be present. This is followed by the RTP payload, the format of which is determined by the particular class of application.[20] The fields in the header are as follows:

  • Version: (2 bits) Indicates the version of the protocol. Current version is 2.[21]
  • P (Padding): (1 bit) Used to indicate if there are extra padding bytes at the end of the RTP packet. A padding might be used to fill up a block of certain size, for example as required by an encryption algorithm. The last byte of the padding contains the number of padding bytes that were added (including itself).[13]:12[21]
  • X (Extension): (1 bit) Indicates presence of an Extension header between standard header and payload data. This is application or profile specific.[21]
  • CC (CSRC count): (4 bits) Contains the number of CSRC identifiers (defined below) that follow the fixed header.[13]:12
  • M (Marker): (1 bit) Used at the application level and defined by a profile. If it is set, it means that the current data has some special relevance for the application.[13]:13
  • PT (Payload type): (7 bits) Indicates the format of the payload and determines its interpretation by the application. This is specified by an RTP profile. For example, see RTP Profile for audio and video conferences with minimal control(RFC 3551).[22]
  • Sequence number: (16 bits) The sequence number is incremented by one for each RTP data packet sent and is to be used by the receiver to detect packet loss and to restore packet sequence. The RTP does not specify any action on packet loss; it is left to the application to take appropriate action. For example, video applications may play the last known frame in place of the missing frame.[23] According to RFC 3550, the initial value of the sequence number should be random to make known-plaintext attacks on encryption more difficult.[13]:13 RTP provides no guarantee of delivery, but the presence of sequence numbers makes it possible to detect missing packets.[1]
  • Timestamp: (32 bits) Used by the receiver to play back the received samples at appropriate time and interval. When several media streams are present, the timestamps may be independent in each stream.[b] The granularity of the timing is application specific. For example, an audio application that samples data once every 125 µs (8 kHz, a common sample rate in digital telephony) would use that value as its clock resolution. Video streams typically use a 90 kHz clock. The clock granularity is one of the details that is specified in the RTP profile for an application.[23]
  • SSRC: (32 bits) Synchronization source identifier uniquely identifies the source of a stream. The synchronization sources within the same RTP session will be unique.[13]:15
  • CSRC: (32 bits each, number indicated by CSRC count field) Contributing source IDs enumerate contributing sources to a stream which has been generated from multiple sources.[13]:15
  • Header extension: (optional, presence indicated by Extension field) The first 32-bit word contains a profile-specific identifier (16 bits) and a length specifier (16 bits) that indicates the length of the extension (EHL = extension header length) in 32-bit units, excluding the 32 bits of the extension header.[13]:17

上面针对rtp头的解释,最为重要的就是seq 和 timestamp,seq需要保证连续,timestamp对视频数据来说,需要时间毫秒数 x 90,

对于音频则是时间毫秒数 x 80

二、rtp协议头定义

rtp协议头字节序为网络字节序,也就是大端模式:

rfc3550中的rtp头结构体定义

  /*
* RTP data header
*/
typedef struct {
unsigned int version:; /* protocol version */
unsigned int p:; /* padding flag */
unsigned int x:; /* header extension flag */
unsigned int cc:; /* CSRC count */
unsigned int m:; /* marker bit */
unsigned int pt:; /* payload type */
unsigned int seq:; /* sequence number */
u_int32 ts; /* timestamp */
u_int32 ssrc; /* synchronization source */
u_int32 csrc[]; /* optional CSRC list */
} rtp_hdr_t;

rtp封包时,一般设置version, payloadtype,seq,timestamp,ssrc 即可。

可以按照大端模式直接填充上述的结构体

也可以直接封包,下面的例子:

 // Prepare the 12 byte RTP header
RtpBuf[] = 0x80; // RTP version
RtpBuf[] = 0x1a + (marker_bit << ); // JPEG payload (26) and marker bit
RtpBuf[] = m_SequenceNumber >> ;
RtpBuf[] = m_SequenceNumber & 0x0FF; // each packet is counted with a sequence counter
RtpBuf[] = (m_Timestamp & 0xFF000000) >> ; // each image gets a timestamp
RtpBuf[] = (m_Timestamp & 0x00FF0000) >> ;
RtpBuf[] = (m_Timestamp & 0x0000FF00) >> ;
RtpBuf[] = (m_Timestamp & 0x000000FF);
RtpBuf[] = 0x13; // 4 byte SSRC (sychronization source identifier)
RtpBuf[] = 0xf9; // we just an arbitrary number here to keep it simple
RtpBuf[] = 0x7e;
RtpBuf[] = 0x67;

三、wireshark抓包出的rdp包,可以根据包头的版本号和负载类型筛选出rtp包

0x80 =1000 0000  version = 2

0x7f  =1111 1111

0x00 01 = 0000 0000 0000 0001 seq = 1

0xa5 be c7 60 = 10100101101111101100011101100000  timestamp = 2780743520

引用:

1、https://en.wikipedia.org/wiki/Real-time_Transport_Protocol

2、https://tools.ietf.org/html/rfc3550

rtp header的更多相关文章

  1. (转载)H.264码流的RTP封包说明

    H.264的NALU,RTP封包说明(转自牛人) 2010-06-30 16:28 H.264 RTP payload 格式 H.264 视频 RTP 负载格式 1. 网络抽象层单元类型 (NALU) ...

  2. 自己动手写RTP服务器——关于RTP协议

    转自:http://blog.csdn.net/baby313/article/details/7353605 本文会带领着你一步步动手实现一个简单的RTP传输服务器,旨在了解RTP流媒体传输协议以及 ...

  3. H.264 基础及 RTP 封包详解

    转自:http://my.oschina.net/u/1431835/blog/393315 一. h264基础概念 1.NAL.Slice与frame意思及相互关系 1 frame的数据可以分为多个 ...

  4. RTMP/RTP/RTSP/RTCP的区别

    RTCP RTMP/RTP/RTSP/RTCP的区别 http://blog.csdn.net/frankiewang008/article/details/7665547 流媒体协议介绍(rtp/r ...

  5. 庖丁解牛-----Live555源码彻底解密(RTP解包)

    Live555 客户端解包 以testRTSPClient.cpp为例讲解: Medium<-MediaSource<-FramedSource<-RTPSource<-Mul ...

  6. 庖丁解牛-----Live555源码彻底解密(RTP打包)

    本文主要讲解live555的服务端RTP打包流程,根据MediaServer讲解RTP的打包流程,所以大家看这篇文章时,先看看下面这个链接的内容; 庖丁解牛-----Live555源码彻底解密(根据M ...

  7. 基于RTP的H264视频数据打包解包类

    from:http://blog.csdn.net/dengzikun/article/details/5807694 最近考虑使用RTP替换原有的高清视频传输协议,遂上网查找有关H264视频RTP打 ...

  8. 用实例分析H264 RTP payload

    用实例分析H264 RTP payload H264的RTP中有三种不同的基本负载(Single NAL,Non-interleaved,Interleaved) 应用程序可以使用第一个字节来识别. ...

  9. RTP封装h264

    网络抽象层单元类型 (NALU): NALU头由一个字节组成,它的语法如下: +---------------+      |0|1|2|3|4|5|6|7|      +-+-+-+-+-+-+-+ ...

随机推荐

  1. MacOS使用常用配置

    如何增加tree命令? 安装Homebrew步骤:http://blog.csdn.net/xianyiqi/article/details/51297562 安装npm步骤:https://blog ...

  2. shell脚本之正则表达式

    具体参考: www.jb51.net/tools/shell_regex.html 正则表达式常用于grep AWK 等工具中

  3. IE上如何设置input type=file的光标不闪烁

    我们使用文件上传时,时常自定义图标,这时候通常会把input的透明度设置为0,但是在IE上使用时会出现光标闪烁问题 解决办法 css设置font-size为0

  4. javaweb项目中的文件上传下载功能的实现

    框架是基于spring+myBatis的. 前台页面的部分代码: <form action="${ctx}/file/upLoadFile.do"method="p ...

  5. ckeditor 实现ctrl+v粘贴图片并上传、word粘贴带图片

    公司做的项目需要用到文本上传功能. Chrome+IE默认支持粘贴剪切板中的图片,但是我要粘贴的文章存在word里面,图片多达数十张,我总不能一张一张复制吧? 我希望打开文档doc直接复制粘贴到富文本 ...

  6. lua rc4算法实现

    由于项目需要,用python django写restful接口遇到瓶颈,python django+uwsgi处理请求是会阻塞的, 如果阻塞请求不及时处理,会卡住越来越多的其它的请求,导致越来越多的5 ...

  7. 阿里云服务器 OSS的使用限制

    使用限制 更新时间:2019-02-12 16:50:27 编辑 · OSS的使用限制及性能指标如下:   限制项 说明 归档存储 已经存储的数据从冷冻状态恢复到可读取状态需要 1 分钟的等待时间. ...

  8. 【python-crypto】导入crypto包失败的情况,怎么处理

    [python-crypto]导入crypto包失败的情况,怎么处理 是因为你自己安装的python的版本太高,所以自己降版本吧,捣鼓了一下午 pip install crypto pip insta ...

  9. vc6中向vs2010迁移的几个问题(2)

    1. 库文件的迁移 参考:http://www.cnblogs.com/icmzn/p/6724969.html 2. 其他项目中的可能遇到的问题: 2.1 无法打开包括文件:“fstream.h”: ...

  10. DCDC与LDO

    DCDC DC/DC:直流电压转直流电压.严格来讲,LDO也是DC/DC的一种,但目前DC/DC多指开关电源. 具有很多种拓朴结构,如升压型DC/DC转换器.降压型DC/DC转换器以及升降压型DC/D ...