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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 284 |
279 void AVCodecContextToAudioDecoderConfig( | 285 void AVCodecContextToAudioDecoderConfig( |
280 const AVCodecContext* codec_context, | 286 const AVCodecContext* codec_context, |
281 bool is_encrypted, | 287 bool is_encrypted, |
282 AudioDecoderConfig* config, | 288 AudioDecoderConfig* config, |
283 bool record_stats) { | 289 bool record_stats) { |
284 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 290 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
285 | 291 |
286 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 292 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
287 | 293 |
| 294 // For AC3/EAC3, FFmpeg does not fill |sample_fmt|. |
288 SampleFormat sample_format = | 295 SampleFormat sample_format = |
289 AVSampleFormatToSampleFormat(codec_context->sample_fmt); | 296 (codec == kCodecAC3 || codec == kCodecEAC3) |
| 297 ? kSampleFormatS16 |
| 298 : AVSampleFormatToSampleFormat(codec_context->sample_fmt); |
290 | 299 |
291 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( | 300 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
292 codec_context->channel_layout, codec_context->channels); | 301 codec_context->channel_layout, codec_context->channels); |
293 | 302 |
294 int sample_rate = codec_context->sample_rate; | 303 int sample_rate = codec_context->sample_rate; |
295 if (codec == kCodecOpus) { | 304 if (codec == kCodecOpus) { |
296 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is | 305 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is |
297 // not enabled in FFmpeg. It doesn't matter what value is set here, so long | 306 // not enabled in FFmpeg. It doesn't matter what value is set here, so long |
298 // as it's valid, the true sample format is selected inside the decoder. | 307 // as it's valid, the true sample format is selected inside the decoder. |
299 sample_format = kSampleFormatF32; | 308 sample_format = kSampleFormatF32; |
(...skipping 15 matching lines...) Expand all Loading... |
315 config->Initialize(codec, | 324 config->Initialize(codec, |
316 sample_format, | 325 sample_format, |
317 channel_layout, | 326 channel_layout, |
318 sample_rate, | 327 sample_rate, |
319 codec_context->extradata, | 328 codec_context->extradata, |
320 codec_context->extradata_size, | 329 codec_context->extradata_size, |
321 is_encrypted, | 330 is_encrypted, |
322 record_stats, | 331 record_stats, |
323 seek_preroll, | 332 seek_preroll, |
324 codec_context->delay); | 333 codec_context->delay); |
325 if (codec != kCodecOpus) { | 334 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) { |
326 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 335 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
327 config->bits_per_channel()); | 336 config->bits_per_channel()); |
328 } | 337 } |
329 } | 338 } |
330 | 339 |
331 void AVStreamToAudioDecoderConfig( | 340 void AVStreamToAudioDecoderConfig( |
332 const AVStream* stream, | 341 const AVStream* stream, |
333 AudioDecoderConfig* config, | 342 AudioDecoderConfig* config, |
334 bool record_stats) { | 343 bool record_stats) { |
335 bool is_encrypted = false; | 344 bool is_encrypted = false; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 return false; | 608 return false; |
600 | 609 |
601 *out = parsed_time; | 610 *out = parsed_time; |
602 return true; | 611 return true; |
603 } | 612 } |
604 | 613 |
605 return false; | 614 return false; |
606 } | 615 } |
607 | 616 |
608 } // namespace media | 617 } // namespace media |
OLD | NEW |