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/mp4/mp4_stream_parser.h" | 5 #include "media/formats/mp4/mp4_stream_parser.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { | 209 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { |
210 RCHECK(!samp_descr.audio_entries.empty()); | 210 RCHECK(!samp_descr.audio_entries.empty()); |
211 | 211 |
212 // It is not uncommon to find otherwise-valid files with incorrect sample | 212 // It is not uncommon to find otherwise-valid files with incorrect sample |
213 // description indices, so we fail gracefully in that case. | 213 // description indices, so we fail gracefully in that case. |
214 if (desc_idx >= samp_descr.audio_entries.size()) | 214 if (desc_idx >= samp_descr.audio_entries.size()) |
215 desc_idx = 0; | 215 desc_idx = 0; |
216 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; | 216 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; |
217 const AAC& aac = entry.esds.aac; | 217 const AAC& aac = entry.esds.aac; |
218 | 218 |
219 if (!(entry.format == FOURCC_MP4A || | 219 FourCC audio_format = (entry.format == FOURCC_ENCA) |
220 (entry.format == FOURCC_ENCA && | 220 ? entry.sinf.format.format |
221 entry.sinf.format.format == FOURCC_MP4A))) { | 221 : entry.format; |
| 222 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 223 if (audio_format != FOURCC_MP4A && audio_format != FOURCC_A52 && |
| 224 audio_format != FOURCC_A52b && audio_format != FOURCC_AC3 && |
| 225 audio_format != FOURCC_AC_3 && audio_format != FOURCC_EAC3) { |
| 226 #else |
| 227 if (audio_format != FOURCC_MP4A) { |
| 228 #endif |
222 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio format 0x" | 229 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio format 0x" |
223 << std::hex << entry.format | 230 << std::hex << entry.format |
224 << " in stsd box."; | 231 << " in stsd box."; |
225 return false; | 232 return false; |
226 } | 233 } |
227 | 234 |
228 uint8 audio_type = entry.esds.object_type; | 235 uint8 audio_type = entry.esds.object_type; |
| 236 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 237 if (audio_type == kForbidden && |
| 238 (audio_format == FOURCC_EAC3 || audio_format == FOURCC_A52b)) { |
| 239 audio_type = kEAC3; |
| 240 } |
| 241 if (audio_type == kForbidden && |
| 242 (audio_format == FOURCC_A52 || audio_format == FOURCC_AC3 || |
| 243 audio_format == FOURCC_AC_3)) { |
| 244 audio_type = kAC3; |
| 245 } |
| 246 #endif |
229 DVLOG(1) << "audio_type " << std::hex << static_cast<int>(audio_type); | 247 DVLOG(1) << "audio_type " << std::hex << static_cast<int>(audio_type); |
230 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { | 248 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { |
231 MEDIA_LOG(ERROR, media_log_) | 249 MEDIA_LOG(ERROR, media_log_) |
232 << "audio object type 0x" << std::hex << audio_type | 250 << "audio object type 0x" << std::hex << audio_type |
233 << " does not match what is specified in the" | 251 << " does not match what is specified in the" |
234 << " mimetype."; | 252 << " mimetype."; |
235 return false; | 253 return false; |
236 } | 254 } |
237 | 255 |
238 AudioCodec codec = kUnknownAudioCodec; | 256 AudioCodec codec = kUnknownAudioCodec; |
239 ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE; | 257 ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE; |
240 int sample_per_second = 0; | 258 int sample_per_second = 0; |
241 std::vector<uint8> extra_data; | 259 std::vector<uint8> extra_data; |
242 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or | 260 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or |
243 // supported MPEG2 AAC varients. | 261 // supported MPEG2 AAC varients. |
244 if (ESDescriptor::IsAAC(audio_type)) { | 262 if (ESDescriptor::IsAAC(audio_type)) { |
245 codec = kCodecAAC; | 263 codec = kCodecAAC; |
246 channel_layout = aac.GetChannelLayout(has_sbr_); | 264 channel_layout = aac.GetChannelLayout(has_sbr_); |
247 sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_); | 265 sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_); |
248 #if defined(OS_ANDROID) | 266 #if defined(OS_ANDROID) |
249 extra_data = aac.codec_specific_data(); | 267 extra_data = aac.codec_specific_data(); |
250 #endif | 268 #endif |
| 269 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 270 } else if (audio_type == kAC3) { |
| 271 codec = kCodecAC3; |
| 272 channel_layout = GuessChannelLayout(entry.channelcount); |
| 273 sample_per_second = entry.samplerate; |
| 274 } else if (audio_type == kEAC3) { |
| 275 codec = kCodecEAC3; |
| 276 channel_layout = GuessChannelLayout(entry.channelcount); |
| 277 sample_per_second = entry.samplerate; |
| 278 #endif |
251 } else { | 279 } else { |
252 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio object type 0x" | 280 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio object type 0x" |
253 << std::hex << audio_type << " in esds."; | 281 << std::hex << audio_type << " in esds."; |
254 return false; | 282 return false; |
255 } | 283 } |
256 | 284 |
257 SampleFormat sample_format; | 285 SampleFormat sample_format; |
258 if (entry.samplesize == 8) { | 286 if (entry.samplesize == 8) { |
259 sample_format = kSampleFormatU8; | 287 sample_format = kSampleFormatU8; |
260 } else if (entry.samplesize == 16) { | 288 } else if (entry.samplesize == 16) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 runs.AdvanceSample(); | 650 runs.AdvanceSample(); |
623 } | 651 } |
624 runs.AdvanceRun(); | 652 runs.AdvanceRun(); |
625 } | 653 } |
626 | 654 |
627 return true; | 655 return true; |
628 } | 656 } |
629 | 657 |
630 } // namespace mp4 | 658 } // namespace mp4 |
631 } // namespace media | 659 } // namespace media |
OLD | NEW |