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

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

Issue 2752323002: Support Opus Ambisonics playback (Closed)
Patch Set: +tests Created 3 years, 9 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/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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 const AVCodecContext* codec_context, 317 const AVCodecContext* codec_context,
318 const EncryptionScheme& encryption_scheme, 318 const EncryptionScheme& encryption_scheme,
319 AudioDecoderConfig* config) { 319 AudioDecoderConfig* config) {
320 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); 320 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO);
321 321
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 // If it is an Opus Ambisonics file, always use CHANNEL_LAYOUT_DISCRETE
328 codec_context->channel_layout, codec_context->channels); 328 int is_opus_ambisonics = 0;
DaleCurtis 2017/03/20 17:38:58 bool
flim-chromium 2017/03/22 06:20:51 Also renamed to is_opus_discrete to remove focus f
flim-chromium 2017/03/22 06:20:51 Done.
329 if (codec == kCodecOpus && codec_context->extradata_size >= 19) {
330 int mapping_family = codec_context->extradata[18];
331 is_opus_ambisonics = mapping_family == 2;
332 }
333 ChannelLayout channel_layout = is_opus_ambisonics
334 ? CHANNEL_LAYOUT_DISCRETE
DaleCurtis 2017/03/20 17:38:58 This should also include channels > kMaxConcurrent
flim-chromium 2017/03/22 06:20:51 Done. Refactored slightly to avoid having to redef
335 : ChannelLayoutToChromeChannelLayout(
336 codec_context->channel_layout,
337 codec_context->channels);
329 338
330 int sample_rate = codec_context->sample_rate; 339 int sample_rate = codec_context->sample_rate;
331 switch (codec) { 340 switch (codec) {
332 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does 341 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does
333 // not fill |sample_fmt|. 342 // not fill |sample_fmt|.
334 case kCodecAC3: 343 case kCodecAC3:
335 case kCodecEAC3: 344 case kCodecEAC3:
336 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 345 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
337 // The spec for AC3/EAC3 audio is ETSI TS 102 366. According to sections 346 // 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. 347 // F.3.1 and F.5.1 in that spec the sample_format for AC3/EAC3 must be 16.
(...skipping 25 matching lines...) Expand all
364 373
365 std::vector<uint8_t> extra_data; 374 std::vector<uint8_t> extra_data;
366 if (codec_context->extradata_size > 0) { 375 if (codec_context->extradata_size > 0) {
367 extra_data.assign(codec_context->extradata, 376 extra_data.assign(codec_context->extradata,
368 codec_context->extradata + codec_context->extradata_size); 377 codec_context->extradata + codec_context->extradata_size);
369 } 378 }
370 379
371 config->Initialize(codec, sample_format, channel_layout, sample_rate, 380 config->Initialize(codec, sample_format, channel_layout, sample_rate,
372 extra_data, encryption_scheme, seek_preroll, 381 extra_data, encryption_scheme, seek_preroll,
373 codec_context->delay); 382 codec_context->delay);
383 config->set_channels_for_discrete(codec_context->channels);
374 384
375 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 385 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
376 // These are bitstream formats unknown to ffmpeg, so they don't have 386 // These are bitstream formats unknown to ffmpeg, so they don't have
377 // a known sample format size. 387 // a known sample format size.
378 if (codec == kCodecAC3 || codec == kCodecEAC3) 388 if (codec == kCodecAC3 || codec == kCodecEAC3)
379 return true; 389 return true;
380 #endif 390 #endif
381 391
382 // Verify that AudioConfig.bits_per_channel was calculated correctly for 392 // Verify that AudioConfig.bits_per_channel was calculated correctly for
383 // codecs that have |sample_fmt| set by FFmpeg. 393 // codecs that have |sample_fmt| set by FFmpeg.
(...skipping 28 matching lines...) Expand all
412 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, 422 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config,
413 AVCodecContext* codec_context) { 423 AVCodecContext* codec_context) {
414 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; 424 codec_context->codec_type = AVMEDIA_TYPE_AUDIO;
415 codec_context->codec_id = AudioCodecToCodecID(config.codec(), 425 codec_context->codec_id = AudioCodecToCodecID(config.codec(),
416 config.sample_format()); 426 config.sample_format());
417 codec_context->sample_fmt = SampleFormatToAVSampleFormat( 427 codec_context->sample_fmt = SampleFormatToAVSampleFormat(
418 config.sample_format()); 428 config.sample_format());
419 429
420 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses 430 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses
421 // said information to decode. 431 // said information to decode.
422 codec_context->channels = 432 codec_context->channels = config.channels();
423 ChannelLayoutToChannelCount(config.channel_layout());
424 codec_context->sample_rate = config.samples_per_second(); 433 codec_context->sample_rate = config.samples_per_second();
425 434
426 if (config.extra_data().empty()) { 435 if (config.extra_data().empty()) {
427 codec_context->extradata = nullptr; 436 codec_context->extradata = nullptr;
428 codec_context->extradata_size = 0; 437 codec_context->extradata_size = 0;
429 } else { 438 } else {
430 codec_context->extradata_size = config.extra_data().size(); 439 codec_context->extradata_size = config.extra_data().size();
431 codec_context->extradata = reinterpret_cast<uint8_t*>( 440 codec_context->extradata = reinterpret_cast<uint8_t*>(
432 av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE)); 441 av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE));
433 memcpy(codec_context->extradata, &config.extra_data()[0], 442 memcpy(codec_context->extradata, &config.extra_data()[0],
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 } 745 }
737 746
738 int32_t HashCodecName(const char* codec_name) { 747 int32_t HashCodecName(const char* codec_name) {
739 // Use the first 32-bits from the SHA1 hash as the identifier. 748 // Use the first 32-bits from the SHA1 hash as the identifier.
740 int32_t hash; 749 int32_t hash;
741 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); 750 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4);
742 return hash; 751 return hash;
743 } 752 }
744 753
745 } // namespace media 754 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698