Example analysis of AAC audio data structure:

Example analysis of AAC audio data structure:

AAC has two data exchange formats: ADTS and ADIF
ADIF: Audio Data Interchange Format, a file has only one header, which can be compared to the ps stream used in dvd.
ADTS: Audio Data Transport Stream, each frame has this synchronization header, which can be compared to the ts stream in dvb.
This blog only introduces the ADTS format AAC.
The basic composition is 7bytes header + original data. Repeat

1. AAC file header information
ADTS header information is divided into two parts: fixed header information (adts_fixed_header, 28bits) and variable header information (adts_variable_header, 28bits).
Below is the description of iso13818-7.

Fixed header:
syncword: the sync header represents the beginning of an ADTS frame, all bits are set to 1, that is, 0xFFF
ID: MPEG identifier, 0 indicates MPEG-4, 1 indicates MPEG-2
Layer: directly set 00, ignore this when decoding Parameter
protection_absent: Indicates whether to check for errors. 1 no CRC, 0 has CRC
profile: AAC encoding level, 0: Main Profile, 1: LC (most commonly used), 2: SSR, 3: reserved.
sampling_frequency_index: sampling rate identification, important!
Private bit: directly set to 0, ignore this parameter when decoding
channel_configuration: channel number identification, important!
original_copy: directly set to 0, ignore this parameter when decoding
home: directly set to 0, ignore this parameter when decoding

Focus on:
1. sample_freq_index: 4 represents 44100hz
2. channel_configuration: 2 represents two channels
3. frame_length: 13bits

Variable header:
copyright_identification_bit: directly set to 0, ignore this parameter when decoding
copyright_identification_start: directly set to 0, ignore this parameter when decoding
aac_frame_lenght: the number of bytes of the current audio frame. Important!
adts_buffer_fullness: When it is set to 0x7FF, it means variable bit rate
number_of_raw_data_blocks_in_frames: The number of audio encoding frames contained in the current audio packet, 0 means 1frame.

Focus on:
1. sample_freq_index: 4 represents 44100hz
2. channel_configuration: 2 represents two channels
3. frame_length: 13bits

2. AAC data instance

Data analysis is all in the picture.

Paste the sample table and channel configuration table
Sampling rate table
const int avpriv_mpeg4audio_sample_rates[16] = {     96000, 88200, 64000, 48000, 44100, 32000, 24000,     22050, 16000, 12000, 11025, 83000 , }


Channel configuration table
const uint8_t ff_mpeg4audio_channels[14] = {     0,     1, // mono (1/0)     2, // stereo (2/0)     3, // 3/0     4, // 3/1     5, / / 3/2     6, // 3/2.1     8, // 5/2.1     0,     0,     0,     7, // 3/3.1     8, // 3/2/2.1     24 // 3/3/3 - 5 /2/3 - 3/0/0.2 };















In addition, the number of frames number_of_raw_block (represented by 0) is always 1, and raw_data_in_frame is always 1024

Record a debug stack, as the name suggests, you can look at the function name and parameters. Really understand the code to debug!

(gdb) bt parse 出一个frame 的调用栈
  #0  ff_adts_header_parse (gbc=0x7fffffff8ad0, hdr=0x7fffffff8ab0) at libavcodec/adts_header.c:38
  #1  0x00007ffff6783069 in aac_sync (state=72050243209011196, hdr_info=0x555555573240, need_next_header=0x5555555732a8, new_frame_start=0x7fffffff8b88) at libavcodec/aac_parser.c:45
  #2  0x00007ffff678162e in ff_aac_ac3_parse (s1=0x555555573040, avctx=0x555555559040, poutbuf=0x555555573318, poutbuf_size=0x555555573320, buf=0x7fffffff8d10 "\377\371P\200t\037\374!\020\005 \244\033\377\300", buf_size=20480) at libavcodec/aac_ac3_parser.c:52
  #3  0x00007ffff6f27cc7 in av_parser_parse2 (s=0x555555573040, avctx=0x555555559040, poutbuf=0x555555573318, poutbuf_size=0x555555573320, buf=0x7fffffff8d10 "\377\371P\200t\037\374!\020\005 \244\033\377\300", buf_size=20480, pts=-9223372036854775808, dts=-9223372036854775808, pos=0) at libavcodec/parser.c:169
  #4  0x0000555555555b13 in main (argc=3, argv=0x7fffffffde58) at decode_audio.c:186


(gdb) bt decode_frame 的调用栈
  #0  ff_adts_header_parse (gbc=0x7fffffff8a90, hdr=0x7fffffff8780) at libavcodec/adts_header.c:38
  #1  0x00007ffff67a4078 in parse_adts_frame_header (ac=0x555555559480, gb=0x7fffffff8a90) at libavcodec/aacdec_template.c:3091
  #2  0x00007ffff67a47e8 in aac_decode_frame_int (avctx=0x555555559040, data=0x55555555bac0, got_frame_ptr=0x7fffffff8af8, gb=0x7fffffff8a90, avpkt=0x55555555c080) at libavcodec/aacdec_template.c:3234
  #3  0x00007ffff67a53ad in aac_decode_frame (avctx=0x555555559040, data=0x55555555bac0, got_frame_ptr=0x7fffffff8af8, avpkt=0x55555555c080) at libavcodec/aacdec_template.c:3480
  #4  0x00007ffff699cd56 in decode_simple_internal (avctx=0x555555559040, frame=0x55555555bac0, discarded_samples=0x7fffffff8bb0) at libavcodec/decode.c:327
  #5  0x00007ffff699da08 in decode_simple_receive_frame (avctx=0x555555559040, frame=0x55555555bac0) at libavcodec/decode.c:526
  #6  0x00007ffff699db0c in decode_receive_frame_internal (avctx=0x555555559040, frame=0x55555555bac0) at libavcodec/decode.c:546
  #7  0x00007ffff699dd97 in avcodec_send_packet (avctx=0x555555559040, avpkt=0x555555573300) at libavcodec/decode.c:608
  #8  0x0000555555555635 in decode (dec_ctx=0x555555559040, pkt=0x555555573300, frame=0x555555573400, outfile=0x555555573ab0) at decode_audio.c:81
  #9  0x0000555555555ba3 in main (argc=3, argv=0x7fffffffde58) at decode_audio.c:197

Reference: libavcodec/adts_header.c
Reference: libavcodec/aac_parser.c
Reference: libavcodec/decode.c
Reference: iso-iec-13818-7

Guess you like

Origin blog.csdn.net/hejinjing_tom_com/article/details/127558649