7 #include "packager/media/formats/mp2t/adts_header.h"
9 #include "packager/media/base/bit_reader.h"
10 #include "packager/media/formats/mp2t/mp2t_common.h"
11 #include "packager/media/formats/mpeg/adts_constants.h"
13 namespace edash_packager {
17 AdtsHeader::AdtsHeader()
18 : valid_config_(false),
20 sampling_frequency_index_(0),
21 channel_configuration_(0) {}
23 size_t AdtsHeader::GetAdtsFrameSize(
const uint8_t* data,
size_t num_bytes) {
26 return ((static_cast<int>(data[5]) >> 5) |
27 (static_cast<int>(data[4]) << 3) |
28 ((static_cast<int>(data[3]) & 0x3) << 11));
31 size_t AdtsHeader::GetAdtsHeaderSize(
const uint8_t* data,
size_t num_bytes) {
35 return kAdtsHeaderMinSize;
36 return kAdtsHeaderMinSize +
sizeof(uint16_t);
39 bool AdtsHeader::Parse(
const uint8_t* adts_frame,
size_t adts_frame_size) {
42 valid_config_ =
false;
44 BitReader frame(adts_frame, adts_frame_size);
48 RCHECK(sync == 0xfff);
52 uint8_t protection_absent;
53 RCHECK(frame.
ReadBits(1, &protection_absent));
55 RCHECK(frame.
ReadBits(2, &profile_));
57 RCHECK(frame.
ReadBits(4, &sampling_frequency_index_));
58 RCHECK(sampling_frequency_index_ < kAdtsFrequencyTableSize);
62 RCHECK(frame.
ReadBits(3, &channel_configuration_));
63 RCHECK((channel_configuration_ > 0) &&
64 (channel_configuration_ < kAdtsNumChannelsTableSize));
69 RCHECK(frame.
ReadBits(13, &frame_size));
70 RCHECK(frame_size == adts_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 "
85 bool AdtsHeader::GetAudioSpecificConfig(std::vector<uint8_t>* buffer)
const {
91 (*buffer)[0] = ((profile_ + 1) << 3) | (sampling_frequency_index_ >> 1);
92 (*buffer)[1] = ((sampling_frequency_index_ & 1) << 7) |
93 (channel_configuration_ << 3);
97 uint8_t AdtsHeader::GetObjectType()
const {
101 uint32_t AdtsHeader::GetSamplingFrequency()
const {
102 DCHECK_LT(sampling_frequency_index_, kAdtsFrequencyTableSize);
103 return kAdtsFrequencyTable[sampling_frequency_index_];
106 uint8_t AdtsHeader::GetNumChannels()
const {
107 DCHECK_GT(channel_configuration_, 0);
108 DCHECK_LT(channel_configuration_, kAdtsNumChannelsTableSize);
109 return kAdtsNumChannelsTable[channel_configuration_];