Adts Baotou Analysis

Source: Internet
Author: User
Tags pack reserved

The Adts full name is (Audio Data Transport Stream) and is a very common transmission format for AAC.


ADTS AAC
Adts_header AAC ES Adts_header AAC ES ... Adts_header AAC ES


Adts content and Structure

The information sampling rate, channel number and frame length of the ADTS header are relatively useful. Think about it too, if I were a decoder, you give me a bunch of AAC audio es stream I can not solve it. Each AAC stream with Adts header information clearly sends the decoder the information he needs.

In general, Adts header information is 7 bytes, divided into 2 parts:
Adts_fixed_header ();
Adts_variable_header ();

Syntax
Adts_fixed_header () {
Syncword; bslbf
ID; 1 bslbf
Layer;2 UIMSBF
Protection_absent;1 bslbf
Profile;2 UIMSBF
Sampling_frequency_index;4 UIMSBF
Private_bit;1 bslbf
Channel_configuration;3 UIMSBF
Original_copy;1 bslbf
Home;1 bslbf
}


Syncword: The sync head is always 0xFFF, all bits must is 1, which represents a Adts frame

Id:mpeg version:0 for MPEG-4, 1 for MPEG-2

Layer:always: ' 00 '

Profile: Indicates which level of AAC is used, and some chips only support AAC LC. There are 3 types defined in MPEG-2 AAC:
0:main profile
1:low complexity profile (LC)
2:scalable Sampling Rate profile (SSR)
3:reserved

Sampling_frequency_index: Represents the sample rate subscript used to find the value of the sample rate through this subscript in the sampling frequencies[] array.
There is supported frequencies:
    0:96000 Hz
    1:88200 Hz
    2: 64000 Hz
    3:48000 Hz
    4:44100 Hz
    5:32000 Hz
    6:24 Hz
    7:22050 Hz
    8:16000 Hz
    9:12000 Hz
    10:110 Hz
    11:8000 Hz
    12:7350 Hz
    13:reserved
    14:res erved
    15:frequency is written explictly

Channel_configuration: means number of channels
    0:defined in AOT specifc Config
    1:1 channel:front-c Enter
    2:2 channels:front-left, front-right
    3:3 channels:front-center, Front-left, Front-right
    4:4 channels:front-center, Front-left, Front-right, Back-center
    5:5 Cha Nnels:front-center, Front-left, Front-right, Back-left, back-right
    6:6 Channels:front-center, front-l EFT, Front-right, Back-left, Back-right, Lfe-channel
    7:8 channels:front-center, Front-left, Front-righ T, Side-left, Side-right, Back-left, Back-right, Lfe-channel
    8-15:reserved

Syntax
Adts_variable_header () {
Copyright_identiflaction_bit;1 bslbf
Copyright_identification_start;1 bslbf
Acc_frame_length;13 bslbf;
adts_buffer_fullness; bslbf
Number_of_raw_data_blocks_in_frame;2 UIMSFB
}

Frame_length: Length of a Adts frame includes Adts header and AAC primitive stream

ADTS_BUFFER_FULLNESS:0X7FF description is a code stream with variable rate


//--------------------------------------------------------------------------------------------------------- ------------------------------------------------------//


The following is an introduction from a foreign website. Http://wiki.multimedia.cx/index.php?title=ADTS personally feel that this site of the table structure of the description more image some. Very well understood. 1byte = 8 bits, how many bits each field occupies, the meaning of each field.



Audio Data Transport Stream (ADTS) is a format, used by MPEG TS or Shoutcast to Stream audio, usually AAC.


structure{
AAAAAAAA AAAABCCD eeffffgh hhijklmm mmmmmmmm mmmooooo oooooopp (QQQQQQQQ qqqqqqqq)
Header consists of 7 or 9 bytes (without or with CRC).
}

Letter Length (BITS) Description
A Syncword 0xFFF, all bits must is 1
B 1 MPEG version:0 for MPEG-4, 1 for MPEG-2
C 2 Layer:always 0
D 1 Protection absent, Warning, set to 1 if there are no CRC and 0 if there is CRC
E 2 profile, the MPEG-4 Audio Object Type minus 1
F 4 MPEG-4 sampling Frequency Index (Forbidden)
G 1 private stream, set to 0 when encoding, ignore when decoding
H 3 MPEG-4 Channel configuration (in the case of 0, the Channel configuration was sent via an Inband

PCE)
I 1 originality, set to 0 when encoding, ignore when decoding
J 1 home, set to 0 when encoding, ignore when decoding
K 1 copyrighted stream, set to 0 when encoding, ignore when decoding
L 1 Copyright Start, set to 0 when encoding, ignore when decoding
M frame length, this value must include 7 or 9 bytes of header Length:framelength =

(Protectionabsent = = 1? 7:9) + Size (aacframe)
O-Buffer Fullness
P 2 Number of AAC frames (RDBS) in ADTS frame minus 1, for maximum compatibility always use 1 AAC frame

Per ADTS frame
Q-CRC If protection absent is 0

Usage in Mpeg-ts
ADTS packet must be a content of PES packet. Pack AAC data inside ADTS frame, than pack inside PES packet, then MUX

by TS Packetizer.

Usage in Shoutcast
ADTS frames goes one by one in TCP stream. Look for Syncword, the parse header and look for next syncword.


//------------------------------------------------------------------------------------------------------------- --------------------------------------------------//

package AAC into ADTS format

If it is through the embedded high-definition decoder chip to do products, the general situation of decoding work is done by the hardware. So most of the work is to package the AAC original stream into a Adts format and then throw it to the hardware.

By understanding the Adts format, it is easy to package AAC into Adts. We just need to get information about the audio sample rate, channel number, metadata length, AAC format type, etc. in the package format. Then add a Adts header to the front of each AAC original stream to be OK.

By pasting the code that adds the Adts header to the ffmpeg, you can clearly understand the structure of the Adts head:[HTML]  View plain copy int ff_adts_write_frame_header (adtscontext *ctx,                                    uint8_t *buf, int size, int  pce_size)    {       PutBitContext pb;          init_put_bits (&pb, buf, adts_header_size);           /* adts_fixed_header */       put_bits (&pb,  12, 0XFFF);   /* syncword */       put_bits (&PB ,  1, 0);        /* id */        put_bits (&pb, 2, 0);         /* layer  */       put_bits (&pb, 1, 1);         /* protection_absent */       put_bits (&pb, 2,  ctx->objecttype); /* profile_objecttype */       put_bits (&pb, 4, ctx->sample_rate_index);       put_bits (&pb, 1 ,  0);        /* private_bit */        put_bits (&pb, 3, ctx->channel_conf);  /* channel_configuration */        put_bits (&pb, 1, 0);         /* original_copy */       put_bits (&pb, 1, 0) ;        /* home */           /* adts_variable_header */       put_bits (&pb, 1, 0);         /* copyright_identification_bit */        put_bits (&pb, 1, 0);         /* copyright_ identification_start */       put_bits (&pb, 13, adts_header_ size + size + pce_size); /* aac_frame_length */        put_bits (&PB, 11, 0X7FF);    /* adts_buffer_fullness */        put_bits (&pb, 2, 0);         /* number_of_raw_data_blocks_in_frame */           Flush_put_bits (&PB);          return 0;  }

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.