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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 int64 ConvertToTimeBase(const AVRational& time_base, | 58 int64 ConvertToTimeBase(const AVRational& time_base, |
59 const base::TimeDelta& timestamp) { | 59 const base::TimeDelta& timestamp) { |
60 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base); | 60 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base); |
61 } | 61 } |
62 | 62 |
63 // Converts an FFmpeg audio codec ID into its corresponding supported codec id. | 63 // Converts an FFmpeg audio codec ID into its corresponding supported codec id. |
64 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) { | 64 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) { |
65 switch (codec_id) { | 65 switch (codec_id) { |
66 case AV_CODEC_ID_AAC: | 66 case AV_CODEC_ID_AAC: |
67 return kCodecAAC; | 67 return kCodecAAC; |
| 68 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 69 case AV_CODEC_ID_AC3: |
| 70 return kCodecAC3; |
| 71 case AV_CODEC_ID_EAC3: |
| 72 return kCodecEAC3; |
| 73 #endif |
68 case AV_CODEC_ID_MP3: | 74 case AV_CODEC_ID_MP3: |
69 return kCodecMP3; | 75 return kCodecMP3; |
70 case AV_CODEC_ID_VORBIS: | 76 case AV_CODEC_ID_VORBIS: |
71 return kCodecVorbis; | 77 return kCodecVorbis; |
72 case AV_CODEC_ID_PCM_U8: | 78 case AV_CODEC_ID_PCM_U8: |
73 case AV_CODEC_ID_PCM_S16LE: | 79 case AV_CODEC_ID_PCM_S16LE: |
74 case AV_CODEC_ID_PCM_S24LE: | 80 case AV_CODEC_ID_PCM_S24LE: |
75 case AV_CODEC_ID_PCM_F32LE: | 81 case AV_CODEC_ID_PCM_F32LE: |
76 return kCodecPCM; | 82 return kCodecPCM; |
77 case AV_CODEC_ID_PCM_S16BE: | 83 case AV_CODEC_ID_PCM_S16BE: |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 278 |
273 void AVCodecContextToAudioDecoderConfig( | 279 void AVCodecContextToAudioDecoderConfig( |
274 const AVCodecContext* codec_context, | 280 const AVCodecContext* codec_context, |
275 bool is_encrypted, | 281 bool is_encrypted, |
276 AudioDecoderConfig* config, | 282 AudioDecoderConfig* config, |
277 bool record_stats) { | 283 bool record_stats) { |
278 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 284 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
279 | 285 |
280 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 286 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
281 | 287 |
| 288 // For AC3/EAC3, FFmpeg does not fill |sample_fmt|. |
282 SampleFormat sample_format = | 289 SampleFormat sample_format = |
283 AVSampleFormatToSampleFormat(codec_context->sample_fmt); | 290 (codec == kCodecAC3 || codec == kCodecEAC3) |
| 291 ? kSampleFormatS16 |
| 292 : AVSampleFormatToSampleFormat(codec_context->sample_fmt); |
284 | 293 |
285 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( | 294 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
286 codec_context->channel_layout, codec_context->channels); | 295 codec_context->channel_layout, codec_context->channels); |
287 | 296 |
288 int sample_rate = codec_context->sample_rate; | 297 int sample_rate = codec_context->sample_rate; |
289 if (codec == kCodecOpus) { | 298 if (codec == kCodecOpus) { |
290 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is | 299 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is |
291 // not enabled in FFmpeg. It doesn't matter what value is set here, so long | 300 // not enabled in FFmpeg. It doesn't matter what value is set here, so long |
292 // as it's valid, the true sample format is selected inside the decoder. | 301 // as it's valid, the true sample format is selected inside the decoder. |
293 sample_format = kSampleFormatF32; | 302 sample_format = kSampleFormatF32; |
(...skipping 15 matching lines...) Expand all Loading... |
309 config->Initialize(codec, | 318 config->Initialize(codec, |
310 sample_format, | 319 sample_format, |
311 channel_layout, | 320 channel_layout, |
312 sample_rate, | 321 sample_rate, |
313 codec_context->extradata, | 322 codec_context->extradata, |
314 codec_context->extradata_size, | 323 codec_context->extradata_size, |
315 is_encrypted, | 324 is_encrypted, |
316 record_stats, | 325 record_stats, |
317 seek_preroll, | 326 seek_preroll, |
318 codec_context->delay); | 327 codec_context->delay); |
319 if (codec != kCodecOpus) { | 328 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) { |
320 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 329 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
321 config->bits_per_channel()); | 330 config->bits_per_channel()); |
322 } | 331 } |
323 } | 332 } |
324 | 333 |
325 void AVStreamToAudioDecoderConfig( | 334 void AVStreamToAudioDecoderConfig( |
326 const AVStream* stream, | 335 const AVStream* stream, |
327 AudioDecoderConfig* config, | 336 AudioDecoderConfig* config, |
328 bool record_stats) { | 337 bool record_stats) { |
329 bool is_encrypted = false; | 338 bool is_encrypted = false; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 return false; | 595 return false; |
587 | 596 |
588 *out = parsed_time; | 597 *out = parsed_time; |
589 return true; | 598 return true; |
590 } | 599 } |
591 | 600 |
592 return false; | 601 return false; |
593 } | 602 } |
594 | 603 |
595 } // namespace media | 604 } // namespace media |
OLD | NEW |