7 #include <packager/media/formats/mp2t/adts_header.h>
9 #include <absl/log/check.h>
11 #include <packager/macros/logging.h>
12 #include <packager/media/base/bit_reader.h>
13 #include <packager/media/base/bit_writer.h>
14 #include <packager/media/formats/mp2t/mp2t_common.h>
17 const size_t kAdtsHeaderMinSize = 7;
21 const int kAdtsFrequencyTable[] = {96000, 88200, 64000, 48000, 44100,
22 32000, 24000, 22050, 16000, 12000,
24 const size_t kAdtsFrequencyTableSize = std::size(kAdtsFrequencyTable);
28 const int kAdtsNumChannelsTable[] = {0, 1, 2, 3, 4, 5, 6, 8};
29 const size_t kAdtsNumChannelsTableSize = std::size(kAdtsNumChannelsTable);
37 return (buf[0] == 0xff) && ((buf[1] & 0xf6) == 0xf0);
41 return kAdtsHeaderMinSize + 1;
45 const size_t kSamplesPerAacFrame = 1024;
46 return kSamplesPerAacFrame;
52 if (adts_frame_size < kAdtsHeaderMinSize)
55 BitReader frame(adts_frame, adts_frame_size);
59 RCHECK(sync == 0xfff);
62 RCHECK(frame.
ReadBits(1, &protection_absent_));
63 RCHECK(frame.
ReadBits(2, &profile_));
64 RCHECK(frame.
ReadBits(4, &sampling_frequency_index_));
65 RCHECK(sampling_frequency_index_ < kAdtsFrequencyTableSize);
68 RCHECK(frame.
ReadBits(3, &channel_configuration_));
69 RCHECK(channel_configuration_ < kAdtsNumChannelsTableSize);
72 RCHECK(frame.
ReadBits(13, &frame_size_));
75 uint8_t num_blocks_minus_1;
76 RCHECK(frame.
ReadBits(2, &num_blocks_minus_1));
77 if (num_blocks_minus_1) {
78 NOTIMPLEMENTED() <<
"ADTS frames with more than one data block "
86 const size_t kCrcSize =
sizeof(uint16_t);
87 return kAdtsHeaderMinSize + (protection_absent_ ? 0 : kCrcSize);
95 size_t num_bytes)
const {
96 DCHECK_GT(num_bytes,
static_cast<size_t>(5));
97 return ((
static_cast<int>(data[5]) >> 5) | (
static_cast<int>(data[4]) << 3) |
98 ((
static_cast<int>(data[3]) & 0x3) << 11));
106 config.
WriteBits(sampling_frequency_index_, 4);
107 config.
WriteBits(channel_configuration_, 4);
116 DCHECK_LT(sampling_frequency_index_, kAdtsFrequencyTableSize);
117 return kAdtsFrequencyTable[sampling_frequency_index_];
121 DCHECK_LT(channel_configuration_, kAdtsNumChannelsTableSize);
122 return kAdtsNumChannelsTable[channel_configuration_];
All the methods that are virtual are virtual for mocking.