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

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

Issue 2543633006: To M56: Use ffmpeg for opus decoding, no need to maintain our decoder. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « media/base/audio_discard_helper_unittest.cc ('k') | media/ffmpeg/ffmpeg_common_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sha1.h" 8 #include "base/sha1.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); 322 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id);
323 323
324 SampleFormat sample_format = AVSampleFormatToSampleFormat( 324 SampleFormat sample_format = AVSampleFormatToSampleFormat(
325 codec_context->sample_fmt, codec_context->codec_id); 325 codec_context->sample_fmt, codec_context->codec_id);
326 326
327 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( 327 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout(
328 codec_context->channel_layout, codec_context->channels); 328 codec_context->channel_layout, codec_context->channels);
329 329
330 int sample_rate = codec_context->sample_rate; 330 int sample_rate = codec_context->sample_rate;
331 switch (codec) { 331 switch (codec) {
332 case kCodecOpus:
333 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding
334 // is not enabled in FFmpeg. It doesn't matter what value is set here, so
335 // long as it's valid, the true sample format is selected inside the
336 // decoder.
337 sample_format = kSampleFormatF32;
338
339 // Always use 48kHz for OPUS. Technically we should match to the highest
340 // supported hardware sample rate among [8, 12, 16, 24, 48] kHz, but we
341 // don't know the hardware sample rate at this point and those rates are
342 // rarely used for output. See the "Input Sample Rate" section of the
343 // spec: http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11
344 sample_rate = 48000;
345 break;
346
347 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does 332 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does
348 // not fill |sample_fmt|. 333 // not fill |sample_fmt|.
349 case kCodecAC3: 334 case kCodecAC3:
350 case kCodecEAC3: 335 case kCodecEAC3:
351 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 336 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
352 // The spec for AC3/EAC3 audio is ETSI TS 102 366. According to sections 337 // The spec for AC3/EAC3 audio is ETSI TS 102 366. According to sections
353 // F.3.1 and F.5.1 in that spec the sample_format for AC3/EAC3 must be 16. 338 // F.3.1 and F.5.1 in that spec the sample_format for AC3/EAC3 must be 16.
354 sample_format = kSampleFormatS16; 339 sample_format = kSampleFormatS16;
355 #else 340 #else
356 NOTREACHED(); 341 NOTREACHED();
(...skipping 23 matching lines...) Expand all
380 std::vector<uint8_t> extra_data; 365 std::vector<uint8_t> extra_data;
381 if (codec_context->extradata_size > 0) { 366 if (codec_context->extradata_size > 0) {
382 extra_data.assign(codec_context->extradata, 367 extra_data.assign(codec_context->extradata,
383 codec_context->extradata + codec_context->extradata_size); 368 codec_context->extradata + codec_context->extradata_size);
384 } 369 }
385 370
386 config->Initialize(codec, sample_format, channel_layout, sample_rate, 371 config->Initialize(codec, sample_format, channel_layout, sample_rate,
387 extra_data, encryption_scheme, seek_preroll, 372 extra_data, encryption_scheme, seek_preroll,
388 codec_context->delay); 373 codec_context->delay);
389 374
375 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
376 // These are bitstream formats unknown to ffmpeg, so they don't have
377 // a known sample format size.
378 if (codec == kCodecAC3 || codec == kCodecEAC3)
379 return true;
380 #endif
381
390 // Verify that AudioConfig.bits_per_channel was calculated correctly for 382 // Verify that AudioConfig.bits_per_channel was calculated correctly for
391 // codecs that have |sample_fmt| set by FFmpeg. 383 // codecs that have |sample_fmt| set by FFmpeg.
392 switch (codec) { 384 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8,
393 case kCodecOpus: 385 config->bits_per_channel());
394 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
395 case kCodecAC3:
396 case kCodecEAC3:
397 #endif
398 break;
399 default:
400 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8,
401 config->bits_per_channel());
402 break;
403 }
404
405 return true; 386 return true;
406 } 387 }
407 388
408 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> 389 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext>
409 AVStreamToAVCodecContext(const AVStream* stream) { 390 AVStreamToAVCodecContext(const AVStream* stream) {
410 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context( 391 std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context(
411 avcodec_alloc_context3(nullptr)); 392 avcodec_alloc_context3(nullptr));
412 if (avcodec_parameters_to_context(codec_context.get(), stream->codecpar) < 393 if (avcodec_parameters_to_context(codec_context.get(), stream->codecpar) <
413 0) { 394 0) {
414 return nullptr; 395 return nullptr;
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 TEST_COLORSPACE(RESERVED); 794 TEST_COLORSPACE(RESERVED);
814 TEST_COLORSPACE(FCC); 795 TEST_COLORSPACE(FCC);
815 TEST_COLORSPACE(BT470BG); 796 TEST_COLORSPACE(BT470BG);
816 TEST_COLORSPACE(SMPTE170M); 797 TEST_COLORSPACE(SMPTE170M);
817 TEST_COLORSPACE(SMPTE240M); 798 TEST_COLORSPACE(SMPTE240M);
818 TEST_COLORSPACE(YCOCG); 799 TEST_COLORSPACE(YCOCG);
819 TEST_COLORSPACE(BT2020_NCL); 800 TEST_COLORSPACE(BT2020_NCL);
820 TEST_COLORSPACE(BT2020_CL); 801 TEST_COLORSPACE(BT2020_CL);
821 802
822 } // namespace media 803 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_discard_helper_unittest.cc ('k') | media/ffmpeg/ffmpeg_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698