RTP Package h264__ Streaming Media

Source: Internet
Author: User
Tags rfc

Turn from: http://blog.csdn.net/jwybobo2007/article/details/7054140


Network Abstraction Layer Unit type (NALU):

The Nalu header consists of a byte, and its syntax is as follows:

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

F:1 a bit.
Forbidden_zero_bit. The H.264 specification stipulates that this one must be 0.

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

Type:5 a bit.
Nal_unit_type. The type of the Nalu unit. The brief description is as follows:

0 No definition
1-23 NAL Unit single NAL unit package
Stap-a a single time combination package
Stap-b a single time combination package
MTAP16 multiple-time combination packages
MTAP24 combination of multiple time packages
Fu-a Fragment Unit
Fu-b Partitioned Unit
30-31 No definition

H264 is used only after 1-23, 24 in the RTP H264 load Type header


the structure of the RTP head:

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, if the 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 agreements to negotiate.

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


The basic structure of the NALU and RTP headers is described above, all of which are the RTP payload parts

RTP load the first byte of the structure is as follows, it and H.264 NALU header structure is consistent, it can be considered as RTP h264 load Type Byte, is a total increase of a byte, does not affect the back of the 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 a single time combination package
Stap-b a single time combination package
MTAP16 multiple-time combination packages
MTAP24 combination of multiple time packages
Fu-a Fragment Unit
Fu-b Partitioned Unit

If using 1-23 is: single NAL unit mode


Package Introduction:

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.264 Nalu unit is often composed of [start code] [Nalu Header] [Nalu Payload] Three parts, where the Start code is used to indicate that this is a

The beginning of the Nalu unit must be "00 00 00 01" or "a", the Nalu header is only one byte, followed by the Nalu unit content.
Remove the start code of "00 00 01" or "00 00 00 01" At the time of packing, and then the RTP package of other data is sealed.

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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Example:
If there is a H.264 the Nalu is like this:

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

This is a NAL unit of sequence parameter sets. [00 00 00 01] is the four-byte start code, 67 is the NALU header, and the 42-starting data is NALU content.

Packaged into RTP packages will be as follows:

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

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


Combined Packet mode

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

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 introduce stap-a mode, if it is stap-b words will add a don domain, in addition to MTAP16, MTAP24, specifically do not introduce, you can see the RFC documents.

Example:

If there is a H.264 the Nalu is like this:

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

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

Packaged into RTP packages will be as follows:

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


Fragments of units:

When the length of the Nalu exceeds the MTU, the NALU unit must be fragmented. 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 names. This format is the RTP h264 load typementioned above, type Fu-a

The FU header has the following format:

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

The S bit is 1 for the nal start, when it is 1 o'clock, E cannot be 1

E bit is 1 to end, when it is 1,s cannot be 1

R bit retention bit

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

Related Article

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.