Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Side by Side Diff: media/ffmpeg/ffmpeg_common.cc

Issue 812643005: Re-add AC3/EAC3 audio demuxing support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "media/base/decoder_buffer.h" 14 #include "media/base/decoder_buffer.h"
15 #include "media/base/video_decoder_config.h" 15 #include "media/base/video_decoder_config.h"
16 #include "media/base/video_util.h" 16 #include "media/base/video_util.h"
17 #include "media/media_features.h"
17 18
18 namespace media { 19 namespace media {
19 20
20 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are 21 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are
21 // padded. Check here to ensure FFmpeg only receives data padded to its 22 // padded. Check here to ensure FFmpeg only receives data padded to its
22 // specifications. 23 // specifications.
23 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, 24 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE,
24 "DecoderBuffer padding size does not fit ffmpeg requirement"); 25 "DecoderBuffer padding size does not fit ffmpeg requirement");
25 26
26 // Alignment requirement by FFmpeg for input and output buffers. This need to 27 // Alignment requirement by FFmpeg for input and output buffers. This need to
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 int64_t ConvertToTimeBase(const AVRational& time_base, 61 int64_t ConvertToTimeBase(const AVRational& time_base,
61 const base::TimeDelta& timestamp) { 62 const base::TimeDelta& timestamp) {
62 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base); 63 return av_rescale_q(timestamp.InMicroseconds(), kMicrosBase, time_base);
63 } 64 }
64 65
65 // Converts an FFmpeg audio codec ID into its corresponding supported codec id. 66 // Converts an FFmpeg audio codec ID into its corresponding supported codec id.
66 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) { 67 static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) {
67 switch (codec_id) { 68 switch (codec_id) {
68 case AV_CODEC_ID_AAC: 69 case AV_CODEC_ID_AAC:
69 return kCodecAAC; 70 return kCodecAAC;
71 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
72 case AV_CODEC_ID_AC3:
73 return kCodecAC3;
74 case AV_CODEC_ID_EAC3:
75 return kCodecEAC3;
76 #endif
70 case AV_CODEC_ID_MP3: 77 case AV_CODEC_ID_MP3:
71 return kCodecMP3; 78 return kCodecMP3;
72 case AV_CODEC_ID_VORBIS: 79 case AV_CODEC_ID_VORBIS:
73 return kCodecVorbis; 80 return kCodecVorbis;
74 case AV_CODEC_ID_PCM_U8: 81 case AV_CODEC_ID_PCM_U8:
75 case AV_CODEC_ID_PCM_S16LE: 82 case AV_CODEC_ID_PCM_S16LE:
76 case AV_CODEC_ID_PCM_S24LE: 83 case AV_CODEC_ID_PCM_S24LE:
77 case AV_CODEC_ID_PCM_S32LE: 84 case AV_CODEC_ID_PCM_S32LE:
78 case AV_CODEC_ID_PCM_F32LE: 85 case AV_CODEC_ID_PCM_F32LE:
79 return kCodecPCM; 86 return kCodecPCM;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 sample_format = kSampleFormatF32; 323 sample_format = kSampleFormatF32;
317 324
318 // Always use 48kHz for OPUS. Technically we should match to the highest 325 // 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 326 // 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 327 // 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: 328 // 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 329 // http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11
323 sample_rate = 48000; 330 sample_rate = 48000;
324 } 331 }
325 332
333 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
334 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does not
335 // fill |sample_fmt|.
336 if (codec == kCodecAC3 || codec == kCodecEAC3) {
337 // The spec for AC3/EAC3 audio is ETSI TS 102 366. According to sections
338 // F.3.1 and F.5.1 in that spec the sample_format for AC3/EAC3 must be 16.
339 sample_format = kSampleFormatS16;
340 }
341 #else
342 DCHECK(codec != kCodecAC3 && codec != kCodecEAC3);
343 #endif
344
326 base::TimeDelta seek_preroll; 345 base::TimeDelta seek_preroll;
327 if (codec_context->seek_preroll > 0) { 346 if (codec_context->seek_preroll > 0) {
328 seek_preroll = base::TimeDelta::FromMicroseconds( 347 seek_preroll = base::TimeDelta::FromMicroseconds(
329 codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate); 348 codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate);
330 } 349 }
331 350
332 // AVStream occasionally has invalid extra data. See http://crbug.com/517163 351 // AVStream occasionally has invalid extra data. See http://crbug.com/517163
333 if ((codec_context->extradata_size == 0) != 352 if ((codec_context->extradata_size == 0) !=
334 (codec_context->extradata == nullptr)) { 353 (codec_context->extradata == nullptr)) {
335 LOG(ERROR) << __FUNCTION__ 354 LOG(ERROR) << __FUNCTION__
336 << (codec_context->extradata == nullptr ? " NULL" : " Non-NULL") 355 << (codec_context->extradata == nullptr ? " NULL" : " Non-NULL")
337 << " extra data cannot have size of " 356 << " extra data cannot have size of "
338 << codec_context->extradata_size << "."; 357 << codec_context->extradata_size << ".";
339 return false; 358 return false;
340 } 359 }
341 360
342 std::vector<uint8_t> extra_data; 361 std::vector<uint8_t> extra_data;
343 if (codec_context->extradata_size > 0) { 362 if (codec_context->extradata_size > 0) {
344 extra_data.assign(codec_context->extradata, 363 extra_data.assign(codec_context->extradata,
345 codec_context->extradata + codec_context->extradata_size); 364 codec_context->extradata + codec_context->extradata_size);
346 } 365 }
347 config->Initialize(codec, 366 config->Initialize(codec,
348 sample_format, 367 sample_format,
349 channel_layout, 368 channel_layout,
350 sample_rate, 369 sample_rate,
351 extra_data, 370 extra_data,
352 is_encrypted, 371 is_encrypted,
353 seek_preroll, 372 seek_preroll,
354 codec_context->delay); 373 codec_context->delay);
355 374 if (codec != kCodecOpus && codec != kCodecAC3 && codec != kCodecEAC3) {
ddorwin 2016/01/08 18:11:02 That leaves this as the only code in this file not
servolk 2016/01/08 20:02:32 Done (and converted to switch to avoid splitting t
356 if (codec != kCodecOpus) { 375 // Verify that AudioConfig.bits_per_channel was calculated correctly for
376 // codecs that have |sample_fmt| set by FFmpeg.
357 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, 377 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8,
358 config->bits_per_channel()); 378 config->bits_per_channel());
359 } 379 }
360 380
361 return true; 381 return true;
362 } 382 }
363 383
364 bool AVStreamToAudioDecoderConfig(const AVStream* stream, 384 bool AVStreamToAudioDecoderConfig(const AVStream* stream,
365 AudioDecoderConfig* config) { 385 AudioDecoderConfig* config) {
366 bool is_encrypted = false; 386 bool is_encrypted = false;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 710 }
691 711
692 int32_t HashCodecName(const char* codec_name) { 712 int32_t HashCodecName(const char* codec_name) {
693 // Use the first 32-bits from the SHA1 hash as the identifier. 713 // Use the first 32-bits from the SHA1 hash as the identifier.
694 int32_t hash; 714 int32_t hash;
695 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); 715 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4);
696 return hash; 716 return hash;
697 } 717 }
698 718
699 } // namespace media 719 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698