One, Adts format:
The full name of Adts is the audio Data Transport Stream. is the transport stream format for AAC audio.
The AAC audio format is defined in MPEG-2 (ISO-13318-7 2003). AAC was later adopted in the MPEG-4 standard.
1. Adts_sequence ()
{
while (nextbits () = = Syncword) {
Adts_frame ();
}
}
2. Adts_frame ()
{
Adts_fixed_header ();
Adts_variable_header ();
if (Number_of_raw_data_blocks_in_frame = = 0) {
Adts_error_check ();
Raw_data_block ();
}
else {
Adts_header_error_check ();
for (i = 0; I <= number_of_raw_data_blocks_in_frame; i++) {
Raw_data_block ();
Adts_raw_data_block_error_check ();
}
}
}
3.
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
}
Adts_variable_header ()
{
Copyright_identification_bit; 1 bslbf
Copyright_identification_start; 1 bslbf
Frame_length; bslbf
adts_buffer_fullness; bslbf
Number_of_raw_data_blocks_in_frame; 2 UIMSFB
}
Detailed description of the important data section of the Adts head:
Syncword Sync Word The bit string ' 1111 1111 1111 ', which illustrates the beginning of a Adts frame.
ID MPEG designator, set to 1.
Layer indicates which layer is used. Set to ' 00 '
Protection_absent Indicates whether the error check
Profile indicates which level of AAC to use, such as complexity Low (LC)---AACLC
Sampling_frequency_index indicates the sample rate subscript used
Sampling_frequency_index sampling Frequeny [Hz]
0x0 96000
0x1 88200
0x2 64000
0x3 48000
0x4 44100
0x5 32000
0x6 24000
0x7 22050
0x8 16000
0X9 2000
0xa 11025
0XB 8000
0XC reserved
0XD reserved
0XE reserved
0XF reserved
Channel_configuration indicates the number of channels
Frame_length the length of a Adts frame includes the Adts header and the raw data block.
Adts_buffer_fullness 0x7ff Description is a code stream with variable rate
Number_of_raw_data_blocks_in_frame
Indicates that there are Number_of_raw_data_blocks_in_frame + 1 AAC original frames in the Adts frame.
So number_of_raw_data_blocks_in_frame = = 0 says that there is an AAC data block in the Adts frame that doesn't say no.
(An AAC original frame contains 1024 samples and related data over a period of time)
Second, package AAC for Adts frame
The length of an AAC raw block is variable, and a Adts frame is formed by Adts the original frame plus the Adts header. Usually we will get the AAC original frame after encapsulation to write to the file, with the usual players such as listening to play, this is a way to verify that the AAC data is correct.
Before encapsulation, you need to know the relevant parameters, such as sample rate, number of channels, length of original data block, etc.
The following is the AAC raw data frame processing as Adts frame, according to the relevant parameters to complete the composition of the 7-byte Adts head.
The ADTS header is defined below-
unsigned int obj_type = 0;
unsigned int num_data_block = frame_length/1024;
Include the header length also
Frame_length + = 7;
/* We want the same metadata */
/* Generate ADTS Header */
if (Adts_header = = NULL) return;
/* Sync point through a full byte */
Adts_header[0] = 0xFF;
/* Sync Point continued over first 4 bits + static 4 bits
* (ID, layer, protection) */
ADTS_HEADER[1] = 0xf9;
/* Object type over first 2 bits */
ADTS_HEADER[2] = Obj_type << 6;//
/* Rate index over next 4 bits */
ADTS_HEADER[2] |= (rate_idx << 2);
/* channels over last 2 bits */
ADTS_HEADER[2] |= (Channels & 0x4) >> 2;
/* Channels continued over next 2 bits + 4 bits at zero */
ADTS_HEADER[3] = (channels & 0x3) << 6;
/* Frame size over last 2 bits */
ADTS_HEADER[3] |= (Frame_length & 0x1800) >> 11;
/* Frame size continued over full BYTE */
ADTS_HEADER[4] = (Frame_length & 0X1FF8) >> 3;
/* Frame size continued first 3 bits */
ADTS_HEADER[5] = (Frame_length & 0x7) << 5;
/* Buffer fullness (0X7FF for VBR) over 5 last bits*/
ADTS_HEADER[5] |= 0x1F;
/* Buffer fullness (0X7FF for VBR) continued over 6 first bits + 2 zeros
* Number of raw data blocks */
ADTS_HEADER[6] = 0xfc;//one raw data blocks.
ADTS_HEADER[6] |= Num_data_block & 0x03; Set Raw Data blocks.
In CMMB, using the AAC audio compression standard, by default, the encoding parameters are as follows: Two channels, sampling rate 24KHZ, frame length and length, the code stream variable bitrate, generally used AAC profile for AAC-LC. The method of encapsulating an AAC original frame parsed from a CMMB multiplex frame into a adts frame is as follows:
Uint8 AAC_BUF[ADTS_FRAME_SIZE]={0X0FF,0X0F9,0X058,0X80,0,0X1F,0XFC};
Analyze the audio parameters from the above 7 bytes as follows:
Synword--0xfff
ID:0X1---1---MPEG2 identifier,
layer--00
Protection_absent---01
PROFILE--01 1 Low Complexity profile (LC) AAC-LC
Smaping_freuency_index---0110-->0x06---> Sample rate 24KHZ
Channel_configuration---aac_buf[3] = 0x08---->2----> Dual channel.
Adts_buffer_fullness--->0x7ff code stream with variable rate
Now insert length parameter wdatalen;
void Onaudioaacframe (byte* data, uint16 Wdatalen)
{
unsigned int num_data_block = wdatalen/1024;
UInt16 frame_length;
Frame_length = Wdatalen + 7;
/* Frame size over last 2 bits */
AAC_BUF[3] |= (Frame_length & 0x1800) >> 11;//the upper 2 bit
/* Frame size continued over full BYTE */
AAC_BUF[4] = (Frame_length & 0x1ff8) >> 3;//the middle 8 bit
/* Frame size continued first 3 bits */
AAC_BUF[5] |= (Frame_length & 0x7) << 5;//the last 3 bit
AAC_BUG[6] |= Num_data_block & 0x03; Set Raw Data blocks.
memcpy (&aac_buf[7],data,wdatalen);
Form a Adts frame to write to the file.
Fwrite (Aac_buf,wdatalen+7,sizeof (Byte), f_audio);
}
Three. Latm format
The LATM is all called "Low-overhead MPEG-4 Audio Transportmultiplex" (Low overhead sound transfer multiplexing),
MPEG-4 AAC is a highly efficient mode of stream transmission, MPEG-2 TS stream is also used LATM
The LATM format, which is the package format for AAC audio streams, is also in frames, consisting mainly of audiospecificconfig (audio-specific hive) and audio load.
Audiospecificconfig describes a LATM frame of information, the audio load is mainly composed of payloadlengthinfo (load length information) and Payloadmux (payload).
Audiospecificconfig information can be either with incoming or with a rumor. The so-called belt incoming, refers to each LATM frame, contains a audiospecificconfig information;
And with the outgoing, each LATM frame does not contain audiospecificconfig information, and other ways to send audiospecificconfig information to the decoder side,
Since audiospecificconfig information is generally constant, you can only send it once. Thus
Audiospecificconfig information using in-band transmission can adapt to the changing situation of audio coding information,
The use of out-of-band transmission, you can save audio transmission code rate. In-band or in-band, determined by the muxconfigpresent flag. For example, in streaming media applications,
The muxconfigpresent can be set to 0 so that the LATM frame will not contain audiospecificconfig information, LATM frames are sent out via RTP packets,
The audiospecificconfig can be transmitted to the decoder side at once via the SDP file.
Audiospecificconfig Main parameters
Numsubframes number of sub-frames
Number of programs Numprogram re-use
Numlayer number of layers used for multiplexing
Framelengthtype load frame length type, including fixed length and variable length
Audioobjecttype Audio Object Type
Samplingfrequency Sample Rate
Channelconfiguration Channel Configuration
The audio load consists of several sub-frames, each of which consists of payloadlengthinfo and Payloadmux,
Like the Adts frame payload, the audio payload mainly contains the original frame data.
AAC is packaged into TS flow in two ways, first packaged as Adts or LATM. Each frame of the Adts has a frame header,
Each frame header information is the same situation, there is a lot of redundancy. The LATM format has great flexibility, and each frame of the audio configuration Unit can be transmitted in-band,
It can also be transmitted out of the room. Because of this, LATM not only applies to streaming but also to RTP transmissions,
RTP transmission, if the audio data configuration information is maintained, you can first transfer streammuxconfig (audiospecificconfig) information through the SDP session,
Because the Latm stream consists of a sequence of audiomuxelements that contains one or more audio frames.
A full or partial complete audiomuxelement can be mapped directly to an RTP payload.
Here is a audomuxemlemt
Audiomuxelement (muxconfigpresent)
{
if (muxconfigpresent)
{
Usesamestreammux;
if (!usesamestreammux)
Streammuxconfig ();
}
if (Audiomuxversiona = = 0)
{
for (i = 0; I <= numsubframes; i++)
{
Payloadlengthinfo ();
Payloadmux ();
}
}
}
Can be very simple to convert Adts frame to LATM frame, according to Adts header information, generate Streammuxconfig,
Extracts the original frame from the Adts, preceded by the Payloadlengthinfo as the LATM audio frame.
The generated audiomuxelement is packaged in the format described above as a load transfer for RTP.
Iv. the LATM in CMMB
When the audio compression standard in CMMB is AAC, the LATM package is used by default. The streammuxconfig uses out-of-band transmission.
Some of the default parameters in STREAMMUXCONIFG are as follows: the AUDIOMUXVERSION:0 flag Stream syntax version number is 0,
The allstreamssametimeframing flag is multiplexed across all the loads in Payloadmux () to share a common base-frame audio subframe.
Audioobjecttype:2 AAC-LC
freamelengthtype:0 The frame length is variable
Latmbufferfullness:0xff code stream with variable rate
Reference:
[1] ISO/IEC 13818-7 (2003 MPEG-2 AAC, Second Edition)
[2] Iso13818-7 (2006 fourth edition AAC)
[3] RFC 3016 (rfc3016)-RTP Payload Format for MPEG-4 audio-visualstreams
[4] AAC Audio compression coding standard ADTS and LATM format analysis
[5] GYZ 234-2008:CMMB Reuse Implementation Guide
[6] ISO/IEC 14496-3 2005 (MPEG-4 PART-3) (LATM)