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. 振动器(Vibrator)

    package com.wwj.serviceandboardcast;   import android.app.Activity; import android.app.Service; impo ...

  2. shell 脚本学习

    Shell简介 概述 Shell是一种具备特殊功能的程序,它提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令,并把它送入内核去执行.内核是Linux系统的心脏,从开机自检就驻留在计算机的内 ...

  3. linux 定时器 定时执行php

    输入命令:    crontab -e 添加定时命令 每隔一分钟执行一次php //复制一下命令即可.  */1 * * * * /usr/bin/curl -o /home/logs/temp.lo ...

  4. day28(ajax之js原生代码实现)

    ajax ajax:异步页面无刷新技术 AJAX:异步的 JavaScript And XML. * 使用的是老的技术,用的是新的思想. AJAX的功能:完成页面的局部刷新,不中断用户的体验. XML ...

  5. Set tooltip on customized tab header in WPF

    <UserControl> <UserControl.Resources> <ResourceDictionary> <ResourceDictionary. ...

  6. C语言注意点汇总

    计算机的一切源头都是0和1,其中0:断电,1:有电. 计算机语言发展史:机器语言--汇编语言--高级语言.机器语言0.1直接对硬件起作用.汇编语言,给机器语言添加了一些符号,使其更易于让人理解.记忆. ...

  7. HashMap原理、源码、实践

    HashMap是一种十分常用的数据结构,作为一个应用开发人员,对其原理.实现的加深理解有助于更高效地进行数据存取.本文所用的jdk版本为1.5. 使用HashMap <Effective JAV ...

  8. JVM可支持的最大线程数

    转微博,因为他也是转载  不知道原出处 一.认识问题: 首先我们通过下面这个 测试程序 来认识这个问题:运行的环境 (有必要说明一下,不同环境会有不同的结果):32位 Windows XP,Sun J ...

  9. bootstrap 警告框单个删除

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  10. Swift3 重写一个带占位符的textView

    class PlaceStrTextView: UIView,UITextViewDelegate{ var palceStr = "即将输入的信息" //站位文字 var inp ...