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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 || |
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 #if defined(ENABLE_EAC3_PLAYBACK) | |
acolwell GONE FROM CHROMIUM
2013/04/30 18:43:43
I think we should just drop the #if's in this file
ycheo (away)
2013/05/01 00:05:46
Done.
| |
204 || entry.format == FOURCC_EAC3 | |
205 #endif | |
206 )) { | |
203 MEDIA_LOG(log_cb_) << "Unsupported audio format 0x" | 207 MEDIA_LOG(log_cb_) << "Unsupported audio format 0x" |
204 << std::hex << entry.format << " in stsd box."; | 208 << std::hex << entry.format << " in stsd box."; |
205 return false; | 209 return false; |
206 } | 210 } |
207 | 211 |
208 int audio_type = entry.esds.object_type; | 212 int audio_type = entry.esds.object_type; |
209 DVLOG(1) << "audio_type " << std::hex << audio_type; | 213 DVLOG(1) << "audio_type " << std::hex << audio_type; |
214 #if defined(ENABLE_EAC3_PLAYBACK) | |
215 if (audio_type == kForbidden && | |
216 audio_object_types_.find(kEAC3) != audio_object_types_.end()) { | |
217 audio_type = kEAC3; | |
218 } | |
219 #endif | |
210 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { | 220 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { |
211 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type | 221 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type |
212 << " does not match what is specified in the" | 222 << " does not match what is specified in the" |
213 << " mimetype."; | 223 << " mimetype."; |
214 return false; | 224 return false; |
215 } | 225 } |
216 | 226 |
227 AudioCodec codec = kUnknownAudioCodec; | |
217 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or | 228 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or |
218 // supported MPEG2 AAC varients. | 229 // supported MPEG2 AAC varients. |
219 if (audio_type != kISO_14496_3 && audio_type != kISO_13818_7_AAC_LC) { | 230 if (audio_type == kISO_14496_3 || audio_type == kISO_13818_7_AAC_LC) { |
231 codec = kCodecAAC; | |
232 #if defined(ENABLE_EAC3_PLAYBACK) | |
233 } else if (audio_type == kEAC3) { | |
234 codec = kCodecEAC3; | |
235 #endif | |
236 } else { | |
220 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex | 237 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex |
221 << audio_type << " in esds."; | 238 << audio_type << " in esds."; |
222 return false; | 239 return false; |
223 } | 240 } |
224 | 241 |
225 SampleFormat sample_format; | 242 SampleFormat sample_format; |
226 if (entry.samplesize == 8) { | 243 if (entry.samplesize == 8) { |
227 sample_format = kSampleFormatU8; | 244 sample_format = kSampleFormatU8; |
228 } else if (entry.samplesize == 16) { | 245 } else if (entry.samplesize == 16) { |
229 sample_format = kSampleFormatS16; | 246 sample_format = kSampleFormatS16; |
230 } else if (entry.samplesize == 32) { | 247 } else if (entry.samplesize == 32) { |
231 sample_format = kSampleFormatS32; | 248 sample_format = kSampleFormatS32; |
232 } else { | 249 } else { |
233 LOG(ERROR) << "Unsupported sample size."; | 250 LOG(ERROR) << "Unsupported sample size."; |
234 return false; | 251 return false; |
235 } | 252 } |
236 | 253 |
254 ChannelLayout channel_layout = aac.GetChannelLayout(has_sbr_); | |
255 if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED && | |
256 entry.channelcount > 0) { | |
acolwell GONE FROM CHROMIUM
2013/04/30 18:19:02
Should this logic be moved above where 'codec' is
ycheo (away)
2013/05/01 00:05:46
Done.
| |
257 channel_layout = GuessChannelLayout(entry.channelcount); | |
258 } | |
259 | |
260 int sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_); | |
261 if (sample_per_second == 0 && entry.samplerate > 0) | |
262 sample_per_second = entry.samplerate; | |
263 | |
237 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; | 264 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; |
238 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; | 265 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; |
239 audio_config.Initialize(kCodecAAC, sample_format, | 266 audio_config.Initialize(codec, sample_format, |
240 aac.GetChannelLayout(has_sbr_), | 267 channel_layout, |
241 aac.GetOutputSamplesPerSecond(has_sbr_), | 268 sample_per_second, |
242 NULL, 0, is_audio_track_encrypted_, false); | 269 NULL, 0, is_audio_track_encrypted_, false); |
243 has_audio_ = true; | 270 has_audio_ = true; |
244 audio_track_id_ = track->header.track_id; | 271 audio_track_id_ = track->header.track_id; |
245 } | 272 } |
246 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { | 273 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { |
247 RCHECK(!samp_descr.video_entries.empty()); | 274 RCHECK(!samp_descr.video_entries.empty()); |
248 if (desc_idx >= samp_descr.video_entries.size()) | 275 if (desc_idx >= samp_descr.video_entries.size()) |
249 desc_idx = 0; | 276 desc_idx = 0; |
250 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; | 277 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; |
251 | 278 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 if (video) { | 475 if (video) { |
449 if (!PrepareAVCBuffer(runs_->video_description().avcc, | 476 if (!PrepareAVCBuffer(runs_->video_description().avcc, |
450 &frame_buf, &subsamples)) { | 477 &frame_buf, &subsamples)) { |
451 MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode"; | 478 MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode"; |
452 *err = true; | 479 *err = true; |
453 return false; | 480 return false; |
454 } | 481 } |
455 } | 482 } |
456 | 483 |
457 if (audio) { | 484 if (audio) { |
458 if (!PrepareAACBuffer(runs_->audio_description().esds.aac, | 485 if (runs_->audio_description().esds.object_type != kForbidden && |
acolwell GONE FROM CHROMIUM
2013/04/30 18:19:02
nit: How about adding a isAAC() helper method to e
ycheo (away)
2013/05/01 00:05:46
Done.
| |
486 !PrepareAACBuffer(runs_->audio_description().esds.aac, | |
459 &frame_buf, &subsamples)) { | 487 &frame_buf, &subsamples)) { |
460 MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode"; | 488 MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode"; |
461 *err = true; | 489 *err = true; |
462 return false; | 490 return false; |
463 } | 491 } |
464 } | 492 } |
465 | 493 |
466 if (decrypt_config) { | 494 if (decrypt_config) { |
467 if (!subsamples.empty()) { | 495 if (!subsamples.empty()) { |
468 // Create a new config with the updated subsamples. | 496 // Create a new config with the updated subsamples. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 return !err; | 574 return !err; |
547 } | 575 } |
548 | 576 |
549 void MP4StreamParser::ChangeState(State new_state) { | 577 void MP4StreamParser::ChangeState(State new_state) { |
550 DVLOG(2) << "Changing state: " << new_state; | 578 DVLOG(2) << "Changing state: " << new_state; |
551 state_ = new_state; | 579 state_ = new_state; |
552 } | 580 } |
553 | 581 |
554 } // namespace mp4 | 582 } // namespace mp4 |
555 } // namespace media | 583 } // namespace media |
OLD | NEW |