OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/mp4/aac.h" | 5 #include "media/mp4/aac.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/bit_reader.h" | 10 #include "media/base/bit_reader.h" |
11 #include "media/mp4/rcheck.h" | 11 #include "media/mp4/rcheck.h" |
12 | 12 |
13 // The following conversion table is extracted from ISO 14496 Part 3 - | 13 // The following conversion table is extracted from ISO 14496 Part 3 - |
14 // Table 1.16 - Sampling Frequency Index. | 14 // Table 1.16 - Sampling Frequency Index. |
15 static const int kFrequencyMap[] = { | 15 static const int kFrequencyMap[] = { |
16 96000, 88200, 64000, 48000, 44100, 32000, 24000, | 16 96000, 88200, 64000, 48000, 44100, 32000, 24000, |
17 22050, 16000, 12000, 11025, 8000, 7350 | 17 22050, 16000, 12000, 11025, 8000, 7350 |
18 }; | 18 }; |
19 | 19 |
20 namespace media { | 20 namespace media { |
21 | 21 |
22 static ChannelLayout GetChannelLayout(uint8 channel_config) { | 22 static ChannelLayout ConvertChannelConfigToLayout(uint8 channel_config) { |
23 switch (channel_config) { | 23 switch (channel_config) { |
24 case 1: | 24 case 1: |
25 return CHANNEL_LAYOUT_MONO; | 25 return CHANNEL_LAYOUT_MONO; |
26 case 2: | 26 case 2: |
27 return CHANNEL_LAYOUT_STEREO; | 27 return CHANNEL_LAYOUT_STEREO; |
28 case 3: | 28 case 3: |
29 return CHANNEL_LAYOUT_SURROUND; | 29 return CHANNEL_LAYOUT_SURROUND; |
30 case 4: | 30 case 4: |
31 return CHANNEL_LAYOUT_4_0; | 31 return CHANNEL_LAYOUT_4_0; |
32 case 5: | 32 case 5: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 frequency_ = kFrequencyMap[frequency_index_]; | 123 frequency_ = kFrequencyMap[frequency_index_]; |
124 } | 124 } |
125 | 125 |
126 if (extension_frequency_ == 0 && extension_frequency_index != 0xff) { | 126 if (extension_frequency_ == 0 && extension_frequency_index != 0xff) { |
127 RCHECK(extension_frequency_index < arraysize(kFrequencyMap)); | 127 RCHECK(extension_frequency_index < arraysize(kFrequencyMap)); |
128 extension_frequency_ = kFrequencyMap[extension_frequency_index]; | 128 extension_frequency_ = kFrequencyMap[extension_frequency_index]; |
129 } | 129 } |
130 | 130 |
131 // When Parametric Stereo is on, mono will be played as stereo. | 131 // When Parametric Stereo is on, mono will be played as stereo. |
132 if (ps_present && channel_config_ == 1) | 132 if (ps_present && channel_config_ == 1) |
133 channel_layout_ = GetChannelLayout(2); | 133 channel_layout_ = CHANNEL_LAYOUT_STEREO; |
134 else | 134 else |
135 channel_layout_ = GetChannelLayout(channel_config_); | 135 channel_layout_ = ConvertChannelConfigToLayout(channel_config_); |
136 | 136 |
137 return frequency_ != 0 && channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && | 137 return frequency_ != 0 && channel_layout_ != CHANNEL_LAYOUT_UNSUPPORTED && |
138 profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf && | 138 profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf && |
139 channel_config_ <= 7; | 139 channel_config_ <= 7; |
140 } | 140 } |
141 | 141 |
142 int AAC::GetOutputSamplesPerSecond(bool sbr_in_mimetype) const { | 142 int AAC::GetOutputSamplesPerSecond(bool sbr_in_mimetype) const { |
143 if (extension_frequency_ > 0) | 143 if (extension_frequency_ > 0) |
144 return extension_frequency_; | 144 return extension_frequency_; |
145 | 145 |
146 if (!sbr_in_mimetype) | 146 if (!sbr_in_mimetype) |
147 return frequency_; | 147 return frequency_; |
148 | 148 |
149 // The following code is written according to ISO 14496 Part 3 Table 1.11 and | 149 // The following code is written according to ISO 14496 Part 3 Table 1.11 and |
150 // Table 1.22. (Table 1.11 refers to the capping to 48000, Table 1.22 refers | 150 // Table 1.22. (Table 1.11 refers to the capping to 48000, Table 1.22 refers |
151 // to SBR doubling the AAC sample rate.) | 151 // to SBR doubling the AAC sample rate.) |
152 // TODO(acolwell) : Extend sample rate cap to 96kHz for Level 5 content. | 152 // TODO(acolwell) : Extend sample rate cap to 96kHz for Level 5 content. |
153 DCHECK_GT(frequency_, 0); | 153 DCHECK_GT(frequency_, 0); |
154 return std::min(2 * frequency_, 48000); | 154 return std::min(2 * frequency_, 48000); |
155 } | 155 } |
156 | 156 |
157 ChannelLayout AAC::channel_layout() const { | 157 ChannelLayout AAC::GetChannelLayout(bool sbr_in_mimetype) const { |
| 158 // Check for implicit signalling of HE-AAC and indicate stereo output |
| 159 // if the mono channel configuration is signalled. |
| 160 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. |
| 161 if (sbr_in_mimetype && channel_config_ == 1) |
| 162 return CHANNEL_LAYOUT_STEREO; |
| 163 |
158 return channel_layout_; | 164 return channel_layout_; |
159 } | 165 } |
160 | 166 |
161 bool AAC::ConvertEsdsToADTS(std::vector<uint8>* buffer) const { | 167 bool AAC::ConvertEsdsToADTS(std::vector<uint8>* buffer) const { |
162 size_t size = buffer->size() + kADTSHeaderSize; | 168 size_t size = buffer->size() + kADTSHeaderSize; |
163 | 169 |
164 DCHECK(profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf && | 170 DCHECK(profile_ >= 1 && profile_ <= 4 && frequency_index_ != 0xf && |
165 channel_config_ <= 7); | 171 channel_config_ <= 7); |
166 | 172 |
167 // ADTS header uses 13 bits for packet size. | 173 // ADTS header uses 13 bits for packet size. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 263 |
258 RCHECK(bit_reader->ReadBits(1, &dummy)); // extensionFlag3 | 264 RCHECK(bit_reader->ReadBits(1, &dummy)); // extensionFlag3 |
259 } | 265 } |
260 | 266 |
261 return true; | 267 return true; |
262 } | 268 } |
263 | 269 |
264 } // namespace mp4 | 270 } // namespace mp4 |
265 | 271 |
266 } // namespace media | 272 } // namespace media |
OLD | NEW |