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_ > 0) &&
67 (channel_configuration_ < kAdtsNumChannelsTableSize));
70 RCHECK(frame.
ReadBits(13, &frame_size_));
73 uint8_t num_blocks_minus_1;
74 RCHECK(frame.
ReadBits(2, &num_blocks_minus_1));
75 if (num_blocks_minus_1) {
76 NOTIMPLEMENTED() <<
"ADTS frames with more than one data block " 84 const size_t kCrcSize =
sizeof(uint16_t);
85 return kAdtsHeaderMinSize + (protection_absent_ ? 0 : kCrcSize);
97 config.
WriteBits(sampling_frequency_index_, 4);
98 config.
WriteBits(channel_configuration_, 4);
107 DCHECK_LT(sampling_frequency_index_, kAdtsFrequencyTableSize);
108 return kAdtsFrequencyTable[sampling_frequency_index_];
112 DCHECK_GT(channel_configuration_, 0);
113 DCHECK_LT(channel_configuration_, kAdtsNumChannelsTableSize);
114 return kAdtsNumChannelsTable[channel_configuration_];
All the methods that are virtual are virtual for mocking.