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, |
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); | |
31 | 33 |
32 if (size < 8) | 34 if (size < kADTSHeaderMinSize) |
33 return 0; | 35 return 0; |
34 | 36 |
35 BitReader reader(data, size); | 37 BitReader reader(data, size); |
36 int sync; | 38 int sync; |
37 int version; | 39 int version; |
38 int layer; | 40 int layer; |
39 int protection_absent; | 41 int protection_absent; |
40 int profile; | 42 int profile; |
41 size_t sample_rate_index; | 43 size_t sample_rate_index; |
42 size_t channel_layout_index; | 44 size_t channel_layout_index; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 90 |
89 if (sample_count) | 91 if (sample_count) |
90 *sample_count = (num_data_blocks + 1) * kSamplesPerAACFrame; | 92 *sample_count = (num_data_blocks + 1) * kSamplesPerAACFrame; |
91 | 93 |
92 if (channel_layout) | 94 if (channel_layout) |
93 *channel_layout = kADTSChannelLayoutTable[channel_layout_index]; | 95 *channel_layout = kADTSChannelLayoutTable[channel_layout_index]; |
94 | 96 |
95 if (metadata_frame) | 97 if (metadata_frame) |
96 *metadata_frame = false; | 98 *metadata_frame = false; |
97 | 99 |
| 100 if (extra_data) { |
| 101 // See mp4::AAC::Parse() for details. We don't need to worry about writing |
| 102 // extensions since we can't have extended ADTS by this point (it's |
| 103 // explicitly rejected as invalid above). |
| 104 DCHECK_NE(sample_rate_index, 15u); |
| 105 |
| 106 // The following code is written according to ISO 14496 Part 3 Table 1.13 - |
| 107 // Syntax of AudioSpecificConfig. |
| 108 const uint16_t esds = (((((profile + 1) << 4) + sample_rate_index) << 4) + |
| 109 channel_layout_index) |
| 110 << 3; |
| 111 extra_data->push_back(esds >> 8); |
| 112 extra_data->push_back(esds & 0xFF); |
| 113 if (media_log()) |
| 114 DCHECK(mp4::AAC().Parse(*extra_data, media_log())); |
| 115 } |
| 116 |
98 return bytes_read; | 117 return bytes_read; |
99 } | 118 } |
100 | 119 |
101 } // namespace media | 120 } // namespace media |
OLD | NEW |