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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 int64_t ConvertToTimeBase(const AVRational& time_base, | 59 int64_t ConvertToTimeBase(const AVRational& time_base, |
60 const base::TimeDelta& timestamp) { | 60 const base::TimeDelta& timestamp) { |
61 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base); | 61 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base); |
62 } | 62 } |
63 | 63 |
64 // Converts an FFmpeg audio codec ID into its corresponding supported codec id. | 64 // Converts an FFmpeg audio codec ID into its corresponding supported codec id. |
65 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) { | 65 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) { |
66 switch (codec_id) { | 66 switch (codec_id) { |
67 case AV_CODEC_ID_AAC: | 67 case AV_CODEC_ID_AAC: |
68 return kCodecAAC; | 68 return kCodecAAC; |
69 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
70 case AV_CODEC_ID_AC3: | |
71 return kCodecAC3; | |
72 case AV_CODEC_ID_EAC3: | |
73 return kCodecEAC3; | |
74 #endif | |
69 case AV_CODEC_ID_MP3: | 75 case AV_CODEC_ID_MP3: |
70 return kCodecMP3; | 76 return kCodecMP3; |
71 case AV_CODEC_ID_VORBIS: | 77 case AV_CODEC_ID_VORBIS: |
72 return kCodecVorbis; | 78 return kCodecVorbis; |
73 case AV_CODEC_ID_PCM_U8: | 79 case AV_CODEC_ID_PCM_U8: |
74 case AV_CODEC_ID_PCM_S16LE: | 80 case AV_CODEC_ID_PCM_S16LE: |
75 case AV_CODEC_ID_PCM_S24LE: | 81 case AV_CODEC_ID_PCM_S24LE: |
76 case AV_CODEC_ID_PCM_S32LE: | 82 case AV_CODEC_ID_PCM_S32LE: |
77 case AV_CODEC_ID_PCM_F32LE: | 83 case AV_CODEC_ID_PCM_F32LE: |
78 return kCodecPCM; | 84 return kCodecPCM; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 return AV_SAMPLE_FMT_NONE; | 300 return AV_SAMPLE_FMT_NONE; |
295 } | 301 } |
296 | 302 |
297 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, | 303 bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context, |
298 bool is_encrypted, | 304 bool is_encrypted, |
299 AudioDecoderConfig* config) { | 305 AudioDecoderConfig* config) { |
300 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 306 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
301 | 307 |
302 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 308 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
303 | 309 |
304 SampleFormat sample_format = AVSampleFormatToSampleFormat( | 310 // For AC3/EAC3, FFmpeg does not fill |sample_fmt|. |
ddorwin
2016/01/04 23:22:17
Is this a bug that should be fixed upstream or bec
servolk
2016/01/07 02:30:03
That's because we don't enable decoder, to avoid a
| |
305 codec_context->sample_fmt, codec_context->codec_id); | 311 SampleFormat sample_format = |
312 (codec == kCodecAC3 || codec == kCodecEAC3) | |
313 ? kSampleFormatS16 | |
ddorwin
2016/01/04 23:22:17
How do we know S16 is always correct?
servolk
2016/01/07 02:30:03
The spec for AC3/EAC3 audio is ETSI TS 102 366:
ht
| |
314 : AVSampleFormatToSampleFormat(codec_context->sample_fmt, | |
315 codec_context->codec_id); | |
306 | 316 |
307 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( | 317 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
308 codec_context->channel_layout, codec_context->channels); | 318 codec_context->channel_layout, codec_context->channels); |
309 | 319 |
310 int sample_rate = codec_context->sample_rate; | 320 int sample_rate = codec_context->sample_rate; |
311 if (codec == kCodecOpus) { | 321 if (codec == kCodecOpus) { |
ddorwin
2016/01/04 23:22:17
It looks like we handle exceptions here. I suggest
servolk
2016/01/07 02:30:03
Done.
| |
312 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is | 322 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is |
313 // not enabled in FFmpeg. It doesn't matter what value is set here, so long | 323 // not enabled in FFmpeg. It doesn't matter what value is set here, so long |
314 // as it's valid, the true sample format is selected inside the decoder. | 324 // as it's valid, the true sample format is selected inside the decoder. |
315 sample_format = kSampleFormatF32; | 325 sample_format = kSampleFormatF32; |
316 | 326 |
317 // Always use 48kHz for OPUS. Technically we should match to the highest | 327 // Always use 48kHz for OPUS. Technically we should match to the highest |
318 // supported hardware sample rate among [8, 12, 16, 24, 48] kHz, but we | 328 // supported hardware sample rate among [8, 12, 16, 24, 48] kHz, but we |
319 // don't know the hardware sample rate at this point and those rates are | 329 // don't know the hardware sample rate at this point and those rates are |
320 // rarely used for output. See the "Input Sample Rate" section of the spec: | 330 // rarely used for output. See the "Input Sample Rate" section of the spec: |
321 // http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 | 331 // http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 |
(...skipping 22 matching lines...) Expand all Loading... | |
344 codec_context->extradata + codec_context->extradata_size); | 354 codec_context->extradata + codec_context->extradata_size); |
345 } | 355 } |
346 config->Initialize(codec, | 356 config->Initialize(codec, |
347 sample_format, | 357 sample_format, |
348 channel_layout, | 358 channel_layout, |
349 sample_rate, | 359 sample_rate, |
350 extra_data, | 360 extra_data, |
351 is_encrypted, | 361 is_encrypted, |
352 seek_preroll, | 362 seek_preroll, |
353 codec_context->delay); | 363 codec_context->delay); |
354 | 364 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) { |
ddorwin
2016/01/04 23:22:17
I assume this is for the same reasons. Perhaps ref
servolk
2016/01/07 02:30:04
I think a switch would be awkward here, it would h
| |
355 if (codec != kCodecOpus) { | |
356 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 365 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
357 config->bits_per_channel()); | 366 config->bits_per_channel()); |
358 } | 367 } |
359 | 368 |
360 return true; | 369 return true; |
361 } | 370 } |
362 | 371 |
363 bool AVStreamToAudioDecoderConfig(const AVStream* stream, | 372 bool AVStreamToAudioDecoderConfig(const AVStream* stream, |
364 AudioDecoderConfig* config) { | 373 AudioDecoderConfig* config) { |
365 bool is_encrypted = false; | 374 bool is_encrypted = false; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 } | 698 } |
690 | 699 |
691 int32_t HashCodecName(const char* codec_name) { | 700 int32_t HashCodecName(const char* codec_name) { |
692 // Use the first 32-bits from the SHA1 hash as the identifier. | 701 // Use the first 32-bits from the SHA1 hash as the identifier. |
693 int32_t hash; | 702 int32_t hash; |
694 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 703 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
695 return hash; | 704 return hash; |
696 } | 705 } |
697 | 706 |
698 } // namespace media | 707 } // namespace media |
OLD | NEW |