OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/formats/mpeg/adts_stream_parser.h" | 5 #include "media/formats/mpeg/adts_stream_parser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "build/build_config.h" | |
9 #include "media/base/media_log.h" | 10 #include "media/base/media_log.h" |
11 #include "media/formats/mp4/aac.h" | |
10 #include "media/formats/mpeg/adts_constants.h" | 12 #include "media/formats/mpeg/adts_constants.h" |
11 | 13 |
12 namespace media { | 14 namespace media { |
13 | 15 |
14 static const uint32_t kADTSStartCodeMask = 0xfff00000; | 16 static const uint32_t kADTSStartCodeMask = 0xfff00000; |
15 | 17 |
16 ADTSStreamParser::ADTSStreamParser() | 18 ADTSStreamParser::ADTSStreamParser() |
17 : MPEGAudioStreamParserBase(kADTSStartCodeMask, kCodecAAC, 0) {} | 19 : MPEGAudioStreamParserBase(kADTSStartCodeMask, kCodecAAC, 0) {} |
18 | 20 |
19 ADTSStreamParser::~ADTSStreamParser() {} | 21 ADTSStreamParser::~ADTSStreamParser() {} |
20 | 22 |
21 int ADTSStreamParser::ParseFrameHeader(const uint8_t* data, | 23 int ADTSStreamParser::ParseFrameHeader(const uint8_t* data, |
chcunningham
2016/09/28 18:50:00
I think we have an opportunity to de-dupe the code
DaleCurtis
2016/09/29 01:23:52
Thanks for pointing that out. I had forgotten abou
| |
22 int size, | 24 int size, |
23 int* frame_size, | 25 int* frame_size, |
24 int* sample_rate, | 26 int* sample_rate, |
25 ChannelLayout* channel_layout, | 27 ChannelLayout* channel_layout, |
26 int* sample_count, | 28 int* sample_count, |
27 bool* metadata_frame) const { | 29 bool* metadata_frame, |
30 std::vector<uint8_t>* extra_data) const { | |
28 DCHECK(data); | 31 DCHECK(data); |
29 DCHECK_GE(size, 0); | 32 DCHECK_GE(size, 0); |
30 DCHECK(frame_size); | 33 DCHECK(frame_size); |
31 | 34 |
32 if (size < 8) | 35 if (size < 8) |
33 return 0; | 36 return 0; |
34 | 37 |
35 BitReader reader(data, size); | 38 BitReader reader(data, size); |
36 int sync; | 39 int sync; |
37 int version; | 40 int version; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 | 91 |
89 if (sample_count) | 92 if (sample_count) |
90 *sample_count = (num_data_blocks + 1) * kSamplesPerAACFrame; | 93 *sample_count = (num_data_blocks + 1) * kSamplesPerAACFrame; |
91 | 94 |
92 if (channel_layout) | 95 if (channel_layout) |
93 *channel_layout = kADTSChannelLayoutTable[channel_layout_index]; | 96 *channel_layout = kADTSChannelLayoutTable[channel_layout_index]; |
94 | 97 |
95 if (metadata_frame) | 98 if (metadata_frame) |
96 *metadata_frame = false; | 99 *metadata_frame = false; |
97 | 100 |
101 // Only Android needs this extra data to be passed. | |
102 #if defined(OS_ANDROID) | |
103 if (extra_data) { | |
104 // See mp4::AAC::Parse() for details. We don't need to worry about writing | |
105 // extensions since we can't have extended ADTS by this point (it's | |
106 // explicitly rejected as invalid above). | |
107 DCHECK_NE(sample_rate_index, 15u); | |
108 const uint16_t esds = (((((profile + 1) << 4) + sample_rate_index) << 4) + | |
109 channel_layout_index) | |
110 << 3; | |
111 extra_data->push_back((esds & 0xFF00) >> 8); | |
112 extra_data->push_back(esds & 0x00FF); | |
113 DCHECK(mp4::AAC().Parse(*extra_data, media_log())); | |
114 } | |
115 #endif | |
116 | |
98 return bytes_read; | 117 return bytes_read; |
99 } | 118 } |
100 | 119 |
101 } // namespace media | 120 } // namespace media |
OLD | NEW |