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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 int64_t ConvertToTimeBase(const AVRational& time_base, | 60 int64_t 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 sample_format = kSampleFormatF32; | 322 sample_format = kSampleFormatF32; |
317 | 323 |
318 // Always use 48kHz for OPUS. Technically we should match to the highest | 324 // Always use 48kHz for OPUS. Technically we should match to the highest |
319 // supported hardware sample rate among [8, 12, 16, 24, 48] kHz, but we | 325 // supported hardware sample rate among [8, 12, 16, 24, 48] kHz, but we |
320 // don't know the hardware sample rate at this point and those rates are | 326 // don't know the hardware sample rate at this point and those rates are |
321 // rarely used for output. See the "Input Sample Rate" section of the spec: | 327 // rarely used for output. See the "Input Sample Rate" section of the spec: |
322 // http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 | 328 // http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 |
323 sample_rate = 48000; | 329 sample_rate = 48000; |
324 } | 330 } |
325 | 331 |
332 // For AC3/EAC3 we enable only demuxing, but not decoding (due to licensing | |
ddorwin
2016/01/07 19:12:43
For a variety of reasons, including that we don't
servolk
2016/01/07 21:17:36
Done.
| |
333 // restrictions), so FFmpeg does not fill |sample_fmt|. | |
334 if (codec == kCodecAC3 || codec == kCodecEAC3) { | |
ddorwin
2016/01/07 19:12:43
This should be else if.
servolk
2016/01/07 21:17:36
Even if we wrap it into #if as suggested below? I
| |
335 // The spec for AC3/EAC3 audio ETSI TS 102 366, according to Sections F.3.1 | |
336 // and F.5.1 sample_format for AC3/EAC3 must be 16. | |
337 sample_format = kSampleFormatS16; | |
338 } | |
ddorwin
2016/01/07 19:12:43
Should this code be ifdef'd or should we have this
servolk
2016/01/07 21:17:36
The difference is really minor, I think lines 70-7
| |
339 | |
326 base::TimeDelta seek_preroll; | 340 base::TimeDelta seek_preroll; |
327 if (codec_context->seek_preroll > 0) { | 341 if (codec_context->seek_preroll > 0) { |
328 seek_preroll = base::TimeDelta::FromMicroseconds( | 342 seek_preroll = base::TimeDelta::FromMicroseconds( |
329 codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate); | 343 codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate); |
330 } | 344 } |
331 | 345 |
332 // AVStream occasionally has invalid extra data. See http://crbug.com/517163 | 346 // AVStream occasionally has invalid extra data. See http://crbug.com/517163 |
333 if ((codec_context->extradata_size == 0) != | 347 if ((codec_context->extradata_size == 0) != |
334 (codec_context->extradata == nullptr)) { | 348 (codec_context->extradata == nullptr)) { |
335 LOG(ERROR) << __FUNCTION__ | 349 LOG(ERROR) << __FUNCTION__ |
336 << (codec_context->extradata == nullptr ? " NULL" : " Non-NULL") | 350 << (codec_context->extradata == nullptr ? " NULL" : " Non-NULL") |
337 << " extra data cannot have size of " | 351 << " extra data cannot have size of " |
338 << codec_context->extradata_size << "."; | 352 << codec_context->extradata_size << "."; |
339 return false; | 353 return false; |
340 } | 354 } |
341 | 355 |
342 std::vector<uint8_t> extra_data; | 356 std::vector<uint8_t> extra_data; |
343 if (codec_context->extradata_size > 0) { | 357 if (codec_context->extradata_size > 0) { |
344 extra_data.assign(codec_context->extradata, | 358 extra_data.assign(codec_context->extradata, |
345 codec_context->extradata + codec_context->extradata_size); | 359 codec_context->extradata + codec_context->extradata_size); |
346 } | 360 } |
347 config->Initialize(codec, | 361 config->Initialize(codec, |
348 sample_format, | 362 sample_format, |
349 channel_layout, | 363 channel_layout, |
350 sample_rate, | 364 sample_rate, |
351 extra_data, | 365 extra_data, |
352 is_encrypted, | 366 is_encrypted, |
353 seek_preroll, | 367 seek_preroll, |
354 codec_context->delay); | 368 codec_context->delay); |
355 | 369 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) { |
ddorwin
2016/01/07 19:12:43
Suggest:
// Verify XXX for codecs for which FFmpeg
servolk
2016/01/07 21:17:36
Done.
| |
356 if (codec != kCodecOpus) { | |
357 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 370 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
358 config->bits_per_channel()); | 371 config->bits_per_channel()); |
359 } | 372 } |
360 | 373 |
361 return true; | 374 return true; |
362 } | 375 } |
363 | 376 |
364 bool AVStreamToAudioDecoderConfig(const AVStream* stream, | 377 bool AVStreamToAudioDecoderConfig(const AVStream* stream, |
365 AudioDecoderConfig* config) { | 378 AudioDecoderConfig* config) { |
366 bool is_encrypted = false; | 379 bool is_encrypted = false; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 } | 703 } |
691 | 704 |
692 int32_t HashCodecName(const char* codec_name) { | 705 int32_t HashCodecName(const char* codec_name) { |
693 // Use the first 32-bits from the SHA1 hash as the identifier. | 706 // Use the first 32-bits from the SHA1 hash as the identifier. |
694 int32_t hash; | 707 int32_t hash; |
695 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 708 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
696 return hash; | 709 return hash; |
697 } | 710 } |
698 | 711 |
699 } // namespace media | 712 } // namespace media |
OLD | NEW |