Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: media/mp4/mp4_stream_parser.cc

Issue 14641006: Support EAC3 (Dolby Digital Plus) codec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/mp4/fourccs.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 && entry.format == FOURCC_EAC3) {
211 audio_type = kEAC3;
212 }
210 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) { 213 if (audio_object_types_.find(audio_type) == audio_object_types_.end()) {
211 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type 214 MEDIA_LOG(log_cb_) << "audio object type 0x" << std::hex << audio_type
212 << " does not match what is specified in the" 215 << " does not match what is specified in the"
213 << " mimetype."; 216 << " mimetype.";
214 return false; 217 return false;
215 } 218 }
216 219
220 AudioCodec codec = kUnknownAudioCodec;
221 ChannelLayout channel_layout = CHANNEL_LAYOUT_NONE;
222 int sample_per_second = 0;
217 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or 223 // Check if it is MPEG4 AAC defined in ISO 14496 Part 3 or
218 // supported MPEG2 AAC varients. 224 // supported MPEG2 AAC varients.
219 if (audio_type != kISO_14496_3 && audio_type != kISO_13818_7_AAC_LC) { 225 if (ESDescriptor::IsAAC(audio_type)) {
226 codec = kCodecAAC;
227 channel_layout = aac.GetChannelLayout(has_sbr_);
228 sample_per_second = aac.GetOutputSamplesPerSecond(has_sbr_);
229 } else if (audio_type == kEAC3) {
230 codec = kCodecEAC3;
231 channel_layout = GuessChannelLayout(entry.channelcount);
232 sample_per_second = entry.samplerate;
233 } else {
220 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex 234 MEDIA_LOG(log_cb_) << "Unsupported audio object type 0x" << std::hex
221 << audio_type << " in esds."; 235 << audio_type << " in esds.";
222 return false; 236 return false;
223 } 237 }
224 238
225 SampleFormat sample_format; 239 SampleFormat sample_format;
226 if (entry.samplesize == 8) { 240 if (entry.samplesize == 8) {
227 sample_format = kSampleFormatU8; 241 sample_format = kSampleFormatU8;
228 } else if (entry.samplesize == 16) { 242 } else if (entry.samplesize == 16) {
229 sample_format = kSampleFormatS16; 243 sample_format = kSampleFormatS16;
230 } else if (entry.samplesize == 32) { 244 } else if (entry.samplesize == 32) {
231 sample_format = kSampleFormatS32; 245 sample_format = kSampleFormatS32;
232 } else { 246 } else {
233 LOG(ERROR) << "Unsupported sample size."; 247 LOG(ERROR) << "Unsupported sample size.";
234 return false; 248 return false;
235 } 249 }
236 250
237 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; 251 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted;
238 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; 252 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_;
239 audio_config.Initialize(kCodecAAC, sample_format, 253 audio_config.Initialize(codec, sample_format,
240 aac.GetChannelLayout(has_sbr_), 254 channel_layout,
241 aac.GetOutputSamplesPerSecond(has_sbr_), 255 sample_per_second,
242 NULL, 0, is_audio_track_encrypted_, false); 256 NULL, 0, is_audio_track_encrypted_, false);
243 has_audio_ = true; 257 has_audio_ = true;
244 audio_track_id_ = track->header.track_id; 258 audio_track_id_ = track->header.track_id;
245 } 259 }
246 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { 260 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) {
247 RCHECK(!samp_descr.video_entries.empty()); 261 RCHECK(!samp_descr.video_entries.empty());
248 if (desc_idx >= samp_descr.video_entries.size()) 262 if (desc_idx >= samp_descr.video_entries.size())
249 desc_idx = 0; 263 desc_idx = 0;
250 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; 264 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx];
251 265
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (video) { 462 if (video) {
449 if (!PrepareAVCBuffer(runs_->video_description().avcc, 463 if (!PrepareAVCBuffer(runs_->video_description().avcc,
450 &frame_buf, &subsamples)) { 464 &frame_buf, &subsamples)) {
451 MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode"; 465 MEDIA_LOG(log_cb_) << "Failed to prepare AVC sample for decode";
452 *err = true; 466 *err = true;
453 return false; 467 return false;
454 } 468 }
455 } 469 }
456 470
457 if (audio) { 471 if (audio) {
458 if (!PrepareAACBuffer(runs_->audio_description().esds.aac, 472 if (ESDescriptor::IsAAC(runs_->audio_description().esds.object_type) &&
473 !PrepareAACBuffer(runs_->audio_description().esds.aac,
459 &frame_buf, &subsamples)) { 474 &frame_buf, &subsamples)) {
460 MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode"; 475 MEDIA_LOG(log_cb_) << "Failed to prepare AAC sample for decode";
461 *err = true; 476 *err = true;
462 return false; 477 return false;
463 } 478 }
464 } 479 }
465 480
466 if (decrypt_config) { 481 if (decrypt_config) {
467 if (!subsamples.empty()) { 482 if (!subsamples.empty()) {
468 // Create a new config with the updated subsamples. 483 // Create a new config with the updated subsamples.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 return !err; 561 return !err;
547 } 562 }
548 563
549 void MP4StreamParser::ChangeState(State new_state) { 564 void MP4StreamParser::ChangeState(State new_state) {
550 DVLOG(2) << "Changing state: " << new_state; 565 DVLOG(2) << "Changing state: " << new_state;
551 state_ = new_state; 566 state_ = new_state;
552 } 567 }
553 568
554 } // namespace mp4 569 } // namespace mp4
555 } // namespace media 570 } // namespace media
OLDNEW
« no previous file with comments | « media/mp4/fourccs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698