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

Side by Side Diff: media/ffmpeg/ffmpeg_common.cc

Issue 812643005: Re-add AC3/EAC3 audio demuxing support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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
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/ffmpeg/ffmpeg_common.h" 5 #include "media/ffmpeg/ffmpeg_common.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 int64 ConvertToTimeBase(const AVRational& time_base, 60 int64 ConvertToTimeBase(const AVRational& time_base,
61 const base::TimeDelta& timestamp) { 61 const base::TimeDelta& timestamp) {
62 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base); 62 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base);
63 } 63 }
64 64
65 // Converts an FFmpeg audio codec ID into its corresponding supported codec id. 65 // Converts an FFmpeg audio codec ID into its corresponding supported codec id.
66 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) { 66 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) {
67 switch (codec_id) { 67 switch (codec_id) {
68 case AV_CODEC_ID_AAC: 68 case AV_CODEC_ID_AAC:
69 return kCodecAAC; 69 return kCodecAAC;
70 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
71 case AV_CODEC_ID_AC3:
72 return kCodecAC3;
73 case AV_CODEC_ID_EAC3:
74 return kCodecEAC3;
75 #endif
70 case AV_CODEC_ID_MP3: 76 case AV_CODEC_ID_MP3:
71 return kCodecMP3; 77 return kCodecMP3;
72 case AV_CODEC_ID_VORBIS: 78 case AV_CODEC_ID_VORBIS:
73 return kCodecVorbis; 79 return kCodecVorbis;
74 case AV_CODEC_ID_PCM_U8: 80 case AV_CODEC_ID_PCM_U8:
75 case AV_CODEC_ID_PCM_S16LE: 81 case AV_CODEC_ID_PCM_S16LE:
76 case AV_CODEC_ID_PCM_S24LE: 82 case AV_CODEC_ID_PCM_S24LE:
77 case AV_CODEC_ID_PCM_S32LE: 83 case AV_CODEC_ID_PCM_S32LE:
78 case AV_CODEC_ID_PCM_F32LE: 84 case AV_CODEC_ID_PCM_F32LE:
79 return kCodecPCM; 85 return kCodecPCM;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 return AV_SAMPLE_FMT_NONE; 301 return AV_SAMPLE_FMT_NONE;
296 } 302 }
297 303
298 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, 304 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
299 bool is_encrypted, 305 bool is_encrypted,
300 AudioDecoderConfig* config) { 306 AudioDecoderConfig* config) {
301 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); 307 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO);
302 308
303 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); 309 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id);
304 310
305 SampleFormat sample_format = AVSampleFormatToSampleFormat( 311 // For AC3/EAC3, FFmpeg does not fill |sample_fmt|.
306 codec_context->sample_fmt, codec_context->codec_id); 312 SampleFormat sample_format =
313 (codec == kCodecAC3 || codec == kCodecEAC3)
314 ? kSampleFormatS16
315 : AVSampleFormatToSampleFormat(codec_context->sample_fmt,
316 codec_context->codec_id);
307 317
308 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( 318 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout(
309 codec_context->channel_layout, codec_context->channels); 319 codec_context->channel_layout, codec_context->channels);
310 320
311 int sample_rate = codec_context->sample_rate; 321 int sample_rate = codec_context->sample_rate;
312 if (codec == kCodecOpus) { 322 if (codec == kCodecOpus) {
313 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is 323 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is
314 // not enabled in FFmpeg. It doesn't matter what value is set here, so long 324 // not enabled in FFmpeg. It doesn't matter what value is set here, so long
315 // as it's valid, the true sample format is selected inside the decoder. 325 // as it's valid, the true sample format is selected inside the decoder.
316 sample_format = kSampleFormatF32; 326 sample_format = kSampleFormatF32;
(...skipping 28 matching lines...) Expand all
345 codec_context->extradata + codec_context->extradata_size); 355 codec_context->extradata + codec_context->extradata_size);
346 } 356 }
347 config->Initialize(codec, 357 config->Initialize(codec,
348 sample_format, 358 sample_format,
349 channel_layout, 359 channel_layout,
350 sample_rate, 360 sample_rate,
351 extra_data, 361 extra_data,
352 is_encrypted, 362 is_encrypted,
353 seek_preroll, 363 seek_preroll,
354 codec_context->delay); 364 codec_context->delay);
355 365 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) {
356 if (codec != kCodecOpus) {
357 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, 366 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8,
358 config->bits_per_channel()); 367 config->bits_per_channel());
359 } 368 }
360 369
361 return true; 370 return true;
362 } 371 }
363 372
364 bool AVStreamToAudioDecoderConfig(const AVStream* stream, 373 bool AVStreamToAudioDecoderConfig(const AVStream* stream,
365 AudioDecoderConfig* config) { 374 AudioDecoderConfig* config) {
366 bool is_encrypted = false; 375 bool is_encrypted = false;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 699 }
691 700
692 int32_t HashCodecName(const char* codec_name) { 701 int32_t HashCodecName(const char* codec_name) {
693 // Use the first 32-bits from the SHA1 hash as the identifier. 702 // Use the first 32-bits from the SHA1 hash as the identifier.
694 int32_t hash; 703 int32_t hash;
695 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); 704 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4);
696 return hash; 705 return hash;
697 } 706 }
698 707
699 } // namespace media 708 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698