RTP header extension

RTP Header

In the RTP protocol, the RTP Header (header) includes a fixed header (Fixed Header) and a header extension (Header extension, optional).

The RTP Fixed Header structure is as follows, where the first 12 bytes must be included in each RTP packet.


RTP Header Extension

If the field in the RTP Fixed Header Xis 1, it means that it is followed by the RTP Header Extension. The RTP Header Extension structure is as follows:

  • defined by profile : decide which Header Extension to use: one-byte or two-byte header
  • length : Indicates the length of the Header Extension: length x 4 bytes

 

One-Byte Header

For One-Byte Header, the "defined by profile" field is fixed at 0xBEDE. Then the following structure is as follows:

  • ID : ID of 4-bit length represents a local identifier
  • len : Indicates the length of extension data, range: 0~15, 0 means the length is 1 byte, 15 means 16 bytes

 

The first is the beginning of the 0xBEDE fixed field, and then the length is 3, indicating that it is followed by 3x4the header extension of the byte length. For the first header extension: L=0, it means that the data length is 1 byte. For the second header extension: L=1, it means that the data length is 2 bytes. Since it is aligned by 4 bytes, padding data with a value of 0 follows. The last header extension: L=3, indicates that the data length is 4 bytes.  Defined by profileThe field is 0xBEDE, indicating One-Byte Header, Extension lengthand 1, indicating that the length of the Header Extension is 1x4bytes. For the Header Extension: ID is 3, Lengh is 2.

  • The construction related code is located RtpPacket::AllocateRawExtensionin
  • The parsing related code is located RtpPacket::ParseBufferin

Two-Byte Header 

First, the "defined by profile" field is 0x1000, the length is 3, followed by 3x4byte length extension, for the first header extension: L=0, the data length is 0, for the second header extension: L=1, the data length is 1, followed by padding Data, for the third header extension: L=4, followed by 4-byte length data.

Since the default is One-Byte Header in WebRTC, packet capture and analysis will not be performed. The specific structure and analysis code is located in the same place as the One-Byte Header.

Common RTP Header Extension

Many RTP Header Extensions are defined in WebRTC, the most common one is the Transport-CC extension for bandwidth estimation, which records a serial number of the transport layer: , and each RTP TransportSequenceNumberpacket has this extension by default.

Of course, there are AudioLevel extensions that record the volume, AbsoluteSendTime extensions that record the sending time, and so on.

 

enum RTPExtensionType : int {

  kRtpExtensionNone,

  kRtpExtensionTransmissionTimeOffset,

  kRtpExtensionAudioLevel,

  kRtpExtensionInbandComfortNoise,

  kRtpExtensionAbsoluteSendTime,

  kRtpExtensionAbsoluteCaptureTime,

  kRtpExtensionVideoRotation,

  kRtpExtensionTransportSequenceNumber,

  kRtpExtensionTransportSequenceNumber02,

  kRtpExtensionPlayoutDelay,

  kRtpExtensionVideoContentType,

  kRtpExtensionVideoLayersAllocation,

  kRtpExtensionVideoTiming,

  kRtpExtensionRtpStreamId,

  kRtpExtensionRepairedRtpStreamId,

  kRtpExtensionMid,

  kRtpExtensionGenericFrameDescriptor00,

  kRtpExtensionGenericFrameDescriptor = kRtpExtensionGenericFrameDescriptor00,

  kRtpExtensionGenericFrameDescriptor02,

  kRtpExtensionColorSpace,

  kRtpExtensionVideoFrameTrackingId,

  kRtpExtensionNumberOfExtensions

};

For the RTP Header Extension defined in RFC, the SDP format is as follows:

1

a=extmap:<value> urn:ietf:params:rtp-hdrext:<extensionattributes>

For the custom RTP Header Extension in WebRTC, the SDP format is as follows:

1

a=extmap:<value> <URI>

 

Guess you like

Origin blog.csdn.net/Doubao93/article/details/122032526
RTP