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/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 Loading... |
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_F32LE: | 83 case AV_CODEC_ID_PCM_F32LE: |
78 return kCodecPCM; | 84 return kCodecPCM; |
79 case AV_CODEC_ID_PCM_S16BE: | 85 case AV_CODEC_ID_PCM_S16BE: |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return AV_SAMPLE_FMT_NONE; | 292 return AV_SAMPLE_FMT_NONE; |
287 } | 293 } |
288 | 294 |
289 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, | 295 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, |
290 bool is_encrypted, | 296 bool is_encrypted, |
291 AudioDecoderConfig* config) { | 297 AudioDecoderConfig* config) { |
292 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 298 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
293 | 299 |
294 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 300 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
295 | 301 |
| 302 // For AC3/EAC3, FFmpeg does not fill |sample_fmt|. |
296 SampleFormat sample_format = | 303 SampleFormat sample_format = |
297 AVSampleFormatToSampleFormat(codec_context->sample_fmt); | 304 (codec == kCodecAC3 || codec == kCodecEAC3) |
| 305 ? kSampleFormatS16 |
| 306 : AVSampleFormatToSampleFormat(codec_context->sample_fmt); |
298 | 307 |
299 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( | 308 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
300 codec_context->channel_layout, codec_context->channels); | 309 codec_context->channel_layout, codec_context->channels); |
301 | 310 |
302 int sample_rate = codec_context->sample_rate; | 311 int sample_rate = codec_context->sample_rate; |
303 if (codec == kCodecOpus) { | 312 if (codec == kCodecOpus) { |
304 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is | 313 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is |
305 // not enabled in FFmpeg. It doesn't matter what value is set here, so long | 314 // not enabled in FFmpeg. It doesn't matter what value is set here, so long |
306 // as it's valid, the true sample format is selected inside the decoder. | 315 // as it's valid, the true sample format is selected inside the decoder. |
307 sample_format = kSampleFormatF32; | 316 sample_format = kSampleFormatF32; |
(...skipping 28 matching lines...) Expand all Loading... |
336 codec_context->extradata + codec_context->extradata_size); | 345 codec_context->extradata + codec_context->extradata_size); |
337 } | 346 } |
338 config->Initialize(codec, | 347 config->Initialize(codec, |
339 sample_format, | 348 sample_format, |
340 channel_layout, | 349 channel_layout, |
341 sample_rate, | 350 sample_rate, |
342 extra_data, | 351 extra_data, |
343 is_encrypted, | 352 is_encrypted, |
344 seek_preroll, | 353 seek_preroll, |
345 codec_context->delay); | 354 codec_context->delay); |
346 | 355 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) { |
347 if (codec != kCodecOpus) { | |
348 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 356 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
349 config->bits_per_channel()); | 357 config->bits_per_channel()); |
350 } | 358 } |
351 | 359 |
352 return true; | 360 return true; |
353 } | 361 } |
354 | 362 |
355 bool AVStreamToAudioDecoderConfig(const AVStream* stream, | 363 bool AVStreamToAudioDecoderConfig(const AVStream* stream, |
356 AudioDecoderConfig* config) { | 364 AudioDecoderConfig* config) { |
357 bool is_encrypted = false; | 365 bool is_encrypted = false; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 } | 689 } |
682 | 690 |
683 int32_t HashCodecName(const char* codec_name) { | 691 int32_t HashCodecName(const char* codec_name) { |
684 // Use the first 32-bits from the SHA1 hash as the identifier. | 692 // Use the first 32-bits from the SHA1 hash as the identifier. |
685 int32_t hash; | 693 int32_t hash; |
686 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 694 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
687 return hash; | 695 return hash; |
688 } | 696 } |
689 | 697 |
690 } // namespace media | 698 } // namespace media |
OLD | NEW |