Audio Data Transport Stream (ADTS) is a format similar to Audio Data Interchange Format (ADIF), used by MPEG TS or Shoutcast to stream audio defined in MPEG-2 Part 7, usually AAC. However, an MPEG-4 decoder may or may not support decoding it, which uses LOAS or LATM.
AAAAAAAA AAAABCCD EEFFFFGH HHIJKLMM MMMMMMMM MMMOOOOO OOOOOOPP (QQQQQQQQ QQQQQQQQ)
Header consists of 7 or 9 bytes (without or with CRC).
|A||12||Syncword, all bits must be set to 1.|
|B||1||MPEG Version, set to 0 for MPEG-4 and 1 for MPEG-2.|
|C||2||Layer, always set to 0.|
|D||1||Protection absence, set to 1 if there is 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 (15 is forbidden).|
|G||1||Private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding.|
|H||3||MPEG-4 Channel Configuration (in the case of 0, the channel configuration is sent via an inband PCE (Program Config Element)).|
|I||1||Originality, set to 1 to signal originality of the audio and 0 otherwise.|
|J||1||Home, set to 1 to signal home usage of the audio and 0 otherwise.|
|K||1||Copyright ID bit, the next bit of a centrally registered copyright identifier. This is transmitted by sliding over the bit-string in LSB-first order and putting the current bit value in this field and wrapping to start if reached end (circular buffer).|
|L||1||Copyright ID start, signals that this frame's Copyright ID bit is the first one by setting 1 and 0 otherwise.|
|M||13||Frame length, length of the ADTS frame including headers and CRC check.|
|O||11||Buffer fullness, states the bit-reservoir per frame.
max_bit_reservoir = minimum_decoder_input_size - mean_bits_per_RDB; // for CBR // bit reservoir state/available bits (≥0 and <max_bit_reservoir); for the i-th frame. bit_reservoir_state[i] = (int)(bit_reservoir_state[i - 1] + mean_framelength - framelength[i]); // NCC is the number of channels. adts_buffer_fullness = bit_reservoir_state[i] / (NCC * 32);
However, a special value of
|P||2||Number of AAC frames (RDBs (Raw Data Blocks)) in ADTS frame minus 1. For maximum compatibility always use one AAC frame per ADTS frame.|
|Q||16||CRC check (as of ISO/IEC 11172-3, subclause 18.104.22.168), if Protection absent is 0.|
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.
ADTS frames goes one by one in TCP stream. Look for syncword, parse header and look for next syncword after.
3GPP, MOV, MP4
Buffer Fullness, apparently, is merely an informative field with no clear use case defined in the specification. Oliver Langlois's blog sheds some light on this topic. FFmpeg's ADTS parser ignores it along with several optional/informative fields and ignorantly puts a 0x7FF like most software. It is advised to ignore this field when decoding and set to VBR mode when encoding (most implementations do).
Up to field Home is the fixed header part of ADTS, meaning these values remain unchanged from frame to frame or ideally it should. The rest part of frame is subject to change. Private bit, Originality, Home, Copyright ID bit, Copyright ID start are subject to ignorance when decoding by setting them to 0 and ignoring it when decoding (most implementations do).
Add internal structure information about ADTS (i.e layout of RDB and details inside of that).