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 <stddef.h> | 7 #include <stddef.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { | 213 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { |
214 RCHECK(!samp_descr.audio_entries.empty()); | 214 RCHECK(!samp_descr.audio_entries.empty()); |
215 | 215 |
216 // It is not uncommon to find otherwise-valid files with incorrect sample | 216 // It is not uncommon to find otherwise-valid files with incorrect sample |
217 // description indices, so we fail gracefully in that case. | 217 // description indices, so we fail gracefully in that case. |
218 if (desc_idx >= samp_descr.audio_entries.size()) | 218 if (desc_idx >= samp_descr.audio_entries.size()) |
219 desc_idx = 0; | 219 desc_idx = 0; |
220 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; | 220 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; |
221 const AAC& aac = entry.esds.aac; | 221 const AAC& aac = entry.esds.aac; |
222 | 222 |
223 if (!(entry.format == FOURCC_MP4A || | 223 // For encrypted audio streams entry.format is FOURCC_ENCA and actual |
224 (entry.format == FOURCC_ENCA && | 224 // format is in entry.sinf.format.format. |
225 entry.sinf.format.format == FOURCC_MP4A))) { | 225 FourCC audio_format = (entry.format == FOURCC_ENCA) |
226 ? entry.sinf.format.format | |
227 : entry.format; | |
228 | |
229 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
230 if (audio_format != FOURCC_MP4A && audio_format != FOURCC_AC_3 && | |
231 audio_format != FOURCC_EAC_3) { | |
232 #else | |
233 if (audio_format != FOURCC_MP4A) { | |
234 #endif | |
226 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio format 0x" | 235 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio format 0x" |
227 << std::hex << entry.format | 236 << std::hex << entry.format |
228 << " in stsd box."; | 237 << " in stsd box."; |
229 return false; | 238 return false; |
230 } | 239 } |
231 | 240 |
232 uint8_t audio_type = entry.esds.object_type; | 241 uint8_t audio_type = entry.esds.object_type; |
233 DVLOG(1) << "audio_type " << std::hex << static_cast<int>(audio_type); | 242 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
243 if (audio_type == kForbidden) { | |
ddorwin
2016/01/07 19:12:43
Does "forbidden" have a special meaning or would "
servolk
2016/01/07 21:17:36
AFAIK no special meaning, it was just a name chose
| |
244 if (audio_format == FOURCC_AC_3) | |
245 audio_type = kAC3; | |
246 if (audio_format == FOURCC_EAC_3) | |
247 audio_type = kEAC3; | |
248 } | |
249 #endif | |
250 DVLOG(1) << "audio_type 0x" << std::hex << static_cast<int>(audio_type); | |
234 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { | 251 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { |
235 MEDIA_LOG(ERROR, media_log_) | 252 MEDIA_LOG(ERROR, media_log_) |
236 << "audio object type 0x" << std::hex << audio_type | 253 << "audio object type 0x" << std::hex |
237 << " does not match what is specified in the" | 254 << static_cast<int>(audio_type) |
238 << " mimetype."; | 255 << " does not match what is specified in the mimetype."; |
239 return false; | 256 return false; |
240 } | 257 } |
241 | 258 |
242 AudioCodec codec = kUnknownAudioCodec; | 259 AudioCodec codec = kUnknownAudioCodec; |
243 ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE; | 260 ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE; |
244 int sample_per_second = 0; | 261 int sample_per_second = 0; |
245 std::vector<uint8_t> extra_data; | 262 std::vector<uint8_t> extra_data; |
246 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or | 263 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or |
247 // supported MPEG2 AAC varients. | 264 // supported MPEG2 AAC varients. |
248 if (ESDescriptor::IsAAC(audio_type)) { | 265 if (ESDescriptor::IsAAC(audio_type)) { |
249 codec = kCodecAAC; | 266 codec = kCodecAAC; |
250 channel_layout = aac.GetChannelLayout(has_sbr_); | 267 channel_layout = aac.GetChannelLayout(has_sbr_); |
251 sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_); | 268 sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_); |
252 #if defined(OS_ANDROID) | 269 #if defined(OS_ANDROID) |
253 extra_data = aac.codec_specific_data(); | 270 extra_data = aac.codec_specific_data(); |
254 #endif | 271 #endif |
272 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
273 } else if (audio_type == kAC3) { | |
274 codec = kCodecAC3; | |
275 channel_layout = GuessChannelLayout(entry.channelcount); | |
276 sample_per_second = entry.samplerate; | |
277 } else if (audio_type == kEAC3) { | |
278 codec = kCodecEAC3; | |
279 channel_layout = GuessChannelLayout(entry.channelcount); | |
280 sample_per_second = entry.samplerate; | |
281 #endif | |
255 } else { | 282 } else { |
256 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio object type 0x" | 283 MEDIA_LOG(ERROR, media_log_) << "Unsupported audio object type 0x" |
257 << std::hex << audio_type << " in esds."; | 284 << std::hex << static_cast<int>(audio_type) |
285 << " in esds."; | |
258 return false; | 286 return false; |
259 } | 287 } |
260 | 288 |
261 SampleFormat sample_format; | 289 SampleFormat sample_format; |
262 if (entry.samplesize == 8) { | 290 if (entry.samplesize == 8) { |
263 sample_format = kSampleFormatU8; | 291 sample_format = kSampleFormatU8; |
264 } else if (entry.samplesize == 16) { | 292 } else if (entry.samplesize == 16) { |
265 sample_format = kSampleFormatS16; | 293 sample_format = kSampleFormatS16; |
266 } else if (entry.samplesize == 32) { | 294 } else if (entry.samplesize == 32) { |
267 sample_format = kSampleFormatS32; | 295 sample_format = kSampleFormatS32; |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 runs.AdvanceSample(); | 655 runs.AdvanceSample(); |
628 } | 656 } |
629 runs.AdvanceRun(); | 657 runs.AdvanceRun(); |
630 } | 658 } |
631 | 659 |
632 return true; | 660 return true; |
633 } | 661 } |
634 | 662 |
635 } // namespace mp4 | 663 } // namespace mp4 |
636 } // namespace media | 664 } // namespace media |
OLD | NEW |