7 #include "packager/media/formats/mp2t/adts_header.h"
9 #include "packager/media/base/bit_reader.h"
10 #include "packager/media/base/bit_writer.h"
11 #include "packager/media/formats/mp2t/mp2t_common.h"
14 const size_t kAdtsHeaderMinSize = 7;
18 const int kAdtsFrequencyTable[] = {96000, 88200, 64000, 48000, 44100,
19 32000, 24000, 22050, 16000, 12000,
21 const size_t kAdtsFrequencyTableSize = arraysize(kAdtsFrequencyTable);
25 const int kAdtsNumChannelsTable[] = {0, 1, 2, 3, 4, 5, 6, 8};
26 const size_t kAdtsNumChannelsTableSize = arraysize(kAdtsNumChannelsTable);
34 return (buf[0] == 0xff) && ((buf[1] & 0xf6) == 0xf0);
38 return kAdtsHeaderMinSize + 1;
42 const size_t kSamplesPerAacFrame = 1024;
43 return kSamplesPerAacFrame;
49 if (adts_frame_size < kAdtsHeaderMinSize)
52 BitReader frame(adts_frame, adts_frame_size);
56 RCHECK(sync == 0xfff);
59 RCHECK(frame.
ReadBits(1, &protection_absent_));
60 RCHECK(frame.
ReadBits(2, &profile_));
61 RCHECK(frame.
ReadBits(4, &sampling_frequency_index_));
62 RCHECK(sampling_frequency_index_ < kAdtsFrequencyTableSize);
65 RCHECK(frame.
ReadBits(3, &channel_configuration_));
66 RCHECK(channel_configuration_ < kAdtsNumChannelsTableSize);
69 RCHECK(frame.
ReadBits(13, &frame_size_));
72 uint8_t num_blocks_minus_1;
73 RCHECK(frame.
ReadBits(2, &num_blocks_minus_1));
74 if (num_blocks_minus_1) {
75 NOTIMPLEMENTED() <<
"ADTS frames with more than one data block "
83 const size_t kCrcSize =
sizeof(uint16_t);
84 return kAdtsHeaderMinSize + (protection_absent_ ? 0 : kCrcSize);
92 size_t num_bytes)
const {
93 DCHECK_GT(num_bytes,
static_cast<size_t>(5));
94 return ((
static_cast<int>(data[5]) >> 5) | (
static_cast<int>(data[4]) << 3) |
95 ((
static_cast<int>(data[3]) & 0x3) << 11));
103 config.
WriteBits(sampling_frequency_index_, 4);
104 config.
WriteBits(channel_configuration_, 4);
113 DCHECK_LT(sampling_frequency_index_, kAdtsFrequencyTableSize);
114 return kAdtsFrequencyTable[sampling_frequency_index_];
118 DCHECK_LT(channel_configuration_, kAdtsNumChannelsTableSize);
119 return kAdtsNumChannelsTable[channel_configuration_];