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/mp4_stream_parser.h" | 5 #include "media/mp4/mp4_stream_parser.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { | 190 if (track->media.handler.type == kAudio && !audio_config.IsValidConfig()) { |
191 RCHECK(!samp_descr.audio_entries.empty()); | 191 RCHECK(!samp_descr.audio_entries.empty()); |
192 | 192 |
193 // It is not uncommon to find otherwise-valid files with incorrect sample | 193 // It is not uncommon to find otherwise-valid files with incorrect sample |
194 // description indices, so we fail gracefully in that case. | 194 // description indices, so we fail gracefully in that case. |
195 if (desc_idx >= samp_descr.audio_entries.size()) | 195 if (desc_idx >= samp_descr.audio_entries.size()) |
196 desc_idx = 0; | 196 desc_idx = 0; |
197 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; | 197 const AudioSampleEntry& entry = samp_descr.audio_entries[desc_idx]; |
198 const AAC& aac = entry.esds.aac; | 198 const AAC& aac = entry.esds.aac; |
199 | 199 |
200 if (!(entry.format == FOURCC_MP4A || | 200 if (!(entry.format == FOURCC_MP4A || entry.format == FOURCC_EAC3 || |
201 (entry.format == FOURCC_ENCA && | 201 (entry.format == FOURCC_ENCA && |
202 entry.sinf.format.format == FOURCC_MP4A))) { | 202 entry.sinf.format.format == FOURCC_MP4A))) { |
203 MEDIA_LOG(log_cb_) << "Unsupported audio format 0x" | 203 MEDIA_LOG(log_cb_) << "Unsupported audio format 0x" |
204 << std::hex << entry.format << " in stsd box."; | 204 << std::hex << entry.format << " in stsd box."; |
205 return false; | 205 return false; |
206 } | 206 } |
207 | 207 |
208 int audio_type = entry.esds.object_type; | 208 uint8 audio_type = entry.esds.object_type; |
209 DVLOG(1) << "audio_type " << std::hex << audio_type; | 209 DVLOG(1) << "audio_type " << std::hex << audio_type; |
210 if (audio_type == kForbidden && | |
211 audio_object_types_.find(kEAC3) != audio_object_types_.end()) { | |
acolwell GONE FROM CHROMIUM
2013/05/01 00:31:00
nit: Replace 'audio_object_types_.find(kEAC3) != a
ycheo (away)
2013/05/01 06:01:10
Done.
| |
212 audio_type = kEAC3; | |
213 } | |
210 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { | 214 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { |
211 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type | 215 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type |
212 << " does not match what is specified in the" | 216 << " does not match what is specified in the" |
213 << " mimetype."; | 217 << " mimetype."; |
214 return false; | 218 return false; |
215 } | 219 } |
216 | 220 |
221 AudioCodec codec = kUnknownAudioCodec; | |
222 ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE; | |
223 int sample_per_second = 0; | |
217 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or | 224 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or |
218 // supported MPEG2 AAC varients. | 225 // supported MPEG2 AAC varients. |
219 if (audio_type != kISO_14496_3 && audio_type != kISO_13818_7_AAC_LC) { | 226 if (ESDescriptor::IsAAC(audio_type)) { |
227 codec = kCodecAAC; | |
228 channel_layout = aac.GetChannelLayout(has_sbr_); | |
229 sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_); | |
230 } else if (audio_type == kEAC3) { | |
231 codec = kCodecEAC3; | |
232 channel_layout = GuessChannelLayout(entry.channelcount); | |
233 sample_per_second = entry.samplerate; | |
234 } else { | |
220 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex | 235 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex |
221 << audio_type << " in esds."; | 236 << audio_type << " in esds."; |
222 return false; | 237 return false; |
223 } | 238 } |
224 | 239 |
225 SampleFormat sample_format; | 240 SampleFormat sample_format; |
226 if (entry.samplesize == 8) { | 241 if (entry.samplesize == 8) { |
227 sample_format = kSampleFormatU8; | 242 sample_format = kSampleFormatU8; |
228 } else if (entry.samplesize == 16) { | 243 } else if (entry.samplesize == 16) { |
229 sample_format = kSampleFormatS16; | 244 sample_format = kSampleFormatS16; |
230 } else if (entry.samplesize == 32) { | 245 } else if (entry.samplesize == 32) { |
231 sample_format = kSampleFormatS32; | 246 sample_format = kSampleFormatS32; |
232 } else { | 247 } else { |
233 LOG(ERROR) << "Unsupported sample size."; | 248 LOG(ERROR) << "Unsupported sample size."; |
234 return false; | 249 return false; |
235 } | 250 } |
236 | 251 |
237 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; | 252 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; |
238 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; | 253 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; |
239 audio_config.Initialize(kCodecAAC, sample_format, | 254 audio_config.Initialize(codec, sample_format, |
240 aac.GetChannelLayout(has_sbr_), | 255 channel_layout, |
241 aac.GetOutputSamplesPerSecond(has_sbr_), | 256 sample_per_second, |
242 NULL, 0, is_audio_track_encrypted_, false); | 257 NULL, 0, is_audio_track_encrypted_, false); |
243 has_audio_ = true; | 258 has_audio_ = true; |
244 audio_track_id_ = track->header.track_id; | 259 audio_track_id_ = track->header.track_id; |
245 } | 260 } |
246 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { | 261 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { |
247 RCHECK(!samp_descr.video_entries.empty()); | 262 RCHECK(!samp_descr.video_entries.empty()); |
248 if (desc_idx >= samp_descr.video_entries.size()) | 263 if (desc_idx >= samp_descr.video_entries.size()) |
249 desc_idx = 0; | 264 desc_idx = 0; |
250 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; | 265 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; |
251 | 266 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 if (video) { | 463 if (video) { |
449 if (!PrepareAVCBuffer(runs_->video_description().avcc, | 464 if (!PrepareAVCBuffer(runs_->video_description().avcc, |
450 &frame_buf, &subsamples)) { | 465 &frame_buf, &subsamples)) { |
451 MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode"; | 466 MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode"; |
452 *err = true; | 467 *err = true; |
453 return false; | 468 return false; |
454 } | 469 } |
455 } | 470 } |
456 | 471 |
457 if (audio) { | 472 if (audio) { |
458 if (!PrepareAACBuffer(runs_->audio_description().esds.aac, | 473 if (ESDescriptor::IsAAC(runs_->audio_description().esds.object_type) && |
474 !PrepareAACBuffer(runs_->audio_description().esds.aac, | |
459 &frame_buf, &subsamples)) { | 475 &frame_buf, &subsamples)) { |
460 MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode"; | 476 MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode"; |
461 *err = true; | 477 *err = true; |
462 return false; | 478 return false; |
463 } | 479 } |
464 } | 480 } |
465 | 481 |
466 if (decrypt_config) { | 482 if (decrypt_config) { |
467 if (!subsamples.empty()) { | 483 if (!subsamples.empty()) { |
468 // Create a new config with the updated subsamples. | 484 // Create a new config with the updated subsamples. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 return !err; | 562 return !err; |
547 } | 563 } |
548 | 564 |
549 void MP4StreamParser::ChangeState(State new_state) { | 565 void MP4StreamParser::ChangeState(State new_state) { |
550 DVLOG(2) << "Changing state: " << new_state; | 566 DVLOG(2) << "Changing state: " << new_state; |
551 state_ = new_state; | 567 state_ = new_state; |
552 } | 568 } |
553 | 569 |
554 } // namespace mp4 | 570 } // namespace mp4 |
555 } // namespace media | 571 } // namespace media |
OLD | NEW |