RTP Package H264

Source: Internet
Author: User
Tags rfc

Network Abstraction Layer Unit type (NALU):

The Nalu header consists of a byte with the following syntax:

+---------------+
|0|1|2|3|4|5|6|7|
+-+-+-+-+-+-+-+-+
| F|  nri| Type |
+---------------+

F:1 a bit.
Forbidden_zero_bit. This one must be 0, as stipulated in the H.

Nri:2 a bit.
NAL_REF_IDC. Taking 00~11, it seems to indicate the importance of this nalu, such as 00 of the Nalu decoder can discard it without affecting the playback of the image.

Type:5 a bit.
Nal_unit_type. The type of this NALU unit is summarized as follows:

0 Not defined
1-23 NAL Unit single NAL unit package
Stap-a Single-time combo package
Stap-b Single-time combo pack
MTAP16 Multi-time combo pack
MTAP24 Multi-time combo pack
Fu-a Shards of cells
Elements of Fu-b shards
30-31 Not defined

H264 used in RTP H264 payload type headers only with 1-23 and 24

The structure of the RTP header:

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| v=2| p|  X| CC |     m|       PT | Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Timestamp |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Synchronization source (SSRC) identifier |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| Contributing Source (CSRC) identifiers |
| ....                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Load type Payload type (PT): 7bits
The RFC defines this payload type for some of the earlier formats. But later, such as H264 is not allocated, then use 96来 instead. So now more than 96 does not represent a specific format, specifically what to use SDP or other protocol to negotiate.

Serial Sequence Number (SN): 16bits
Time Stamp Timestamp:32bits

The basic structure of NALU and RTP headers is described above, and all of the following is part of the RTP payload

The first byte of the RTP payload is structured as follows, and it is consistent with the NALU head structure of H. x, which can be thought of as RTP h264 payload Type byte, which is fully incremented by one byte without affecting the subsequent NALU structure

+---------------+
|0|1|2|3|4|5|6|7|
+-+-+-+-+-+-+-+-+
| F|  nri| Type |
+---------------+

The type types here have the following values in addition to 1-23:

Stap-a Single-time combo package
Stap-b Single-time combo pack
MTAP16 Multi-time combo pack
MTAP24 Multi-time combo pack
Fu-a Shards of cells
Elements of Fu-b shards

If 1-23 is used: single nal cell mode

Description of the package:

Single NAL unit mode

For NALU packets with a length less than the MTU size, a single NAL cell pattern is generally used.
For an original H. Nalu unit is usually composed of [start code] [Nalu Header] [Nalu Payload] three parts, where Start code is used to indicate that this is a

The start of the Nalu unit must be "00 00 00 01" or "XX", Nalu only one byte, followed by Nalu unit content.
When packaging, remove the "00 00 01" or "00 00 00 01" Of the start code, the other data packets to the RTP packet.

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| F|  nri|                                               Type | |
+-+-+-+-+-+-+-+-+                                               |
| |
| Bytes 2..N of a single NAL unit |
| |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| :... OPTIONAL RTP Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Cases:
If there is a nalu of H. S:

[xx] A0 1E 0E 2F ...]

This is a sequence parameter set of NAL cells. [00 00 00 01] is the start code of four bytes, 67 is the NALU header, and 42 begins with the Nalu content.

Package into RTP package will be as follows:

[RTP Header] [A0 1E 0E 2F]

That is, just get rid of the 4-byte start code.

Combo Packet mode

Second, when the length of the Nalu is special, several NALU units can be sealed in a RTP packet.

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| RTP Header |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Stap-a NAL HDR | Nalu 1 Size | Nalu 1 HDR |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nalu 1 Data |
:                                                               :
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Nalu 2 Size | Nalu 2 HDR |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Nalu 2 Data |
:                                                               :
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| :... OPTIONAL RTP Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Here only to introduce the STAP-A mode, if it is stap-b will add more than one don domain, in addition there are MTAP16, MTAP24, specifically not introduced, you can see the RFC document, the end of the article post a link can go to see.

If reproduced, please note jwybobo2007 Source: http://blog.csdn.net/jwybobo2007/article/details/7054140

Cases:

If there is a nalu of H. S:

[xx] A0 1E 0E 2F ...]

[B0] 6A D4 FF .....

Package into RTP package will be as follows:

[RTP Header] [Stap-a (1 bytes in total)] [First Nalu length (occupies two bytes)] [A0 1E 0E 2F] [Second Nalu length (occupies two bytes)] [B0 6A D4 FF ...]

Shards of cells:

When the length of the Nalu exceeds the MTU, the NALU unit must be shard-encapsulated. Also known as Fragmentation Units (FUs).

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   FU Indicator |                               FU Header | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               |
| |
| FU Payload |
| |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| :... OPTIONAL RTP Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 14. RTP Payload format for FU-A

The FU indicator octet has the following format:

+---------------+
|0|1|2|3|4|5|6|7|
+-+-+-+-+-+-+-+-+
| F|  nri| Type |
+---------------+

Don't be intimidated by the name. This format is the RTP h264 payload typementioned above, type Fu-a

The FU header has the following format:

+---------------+
|0|1|2|3|4|5|6|7|
+-+-+-+-+-+-+-+-+
| s| e|  r| Type |
+---------------+

An S bit of 1 means that the nal of the Shard begins, and when it is 1 o'clock, E cannot be 1

The E bit is 1 for the end, when it is 1,s cannot be 1

R bit reserved bit

Type is the type in the Nalu header, which takes 1-23 of the value

Report:

A translated rfc3984 document, translation of a little messy, the look of the stock

Http://wenku.baidu.com/view/0f612e1ec5da50e2524d7f32.html

RTP Package H264

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.