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

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

Issue 2752323002: Support Opus Ambisonics playback (Closed)
Patch Set: Fix issues from rebase Created 3 years, 7 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 bool is_opus_discrete = false;
328 codec_context->channel_layout, codec_context->channels); 328 if (codec == kCodecOpus && codec_context->extradata_size >= 19) {
329 int mapping_family = codec_context->extradata[18];
330 is_opus_discrete = mapping_family == 2;
331 }
332 ChannelLayout channel_layout =
333 is_opus_discrete && codec_context->channels > 8
DaleCurtis 2017/05/24 00:49:58 Did you ever figure out if this > 8 check could be
flim-chromium 2017/05/25 00:04:25 I'm not familiar enough with the potential problem
DaleCurtis 2017/05/25 00:29:16 Leaving sgtm for now, though I think WebAudio does
334 ? CHANNEL_LAYOUT_DISCRETE
335 : ChannelLayoutToChromeChannelLayout(codec_context->channel_layout,
336 codec_context->channels);
329 337
330 int sample_rate = codec_context->sample_rate; 338 int sample_rate = codec_context->sample_rate;
331 switch (codec) { 339 switch (codec) {
332 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does 340 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does
333 // not fill |sample_fmt|. 341 // not fill |sample_fmt|.
334 case kCodecAC3: 342 case kCodecAC3:
335 case kCodecEAC3: 343 case kCodecEAC3:
336 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 344 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
337 // The spec for AC3/EAC3 audio is ETSI TS 102 366. According to sections 345 // 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. 346 // 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 372
365 std::vector<uint8_t> extra_data; 373 std::vector<uint8_t> extra_data;
366 if (codec_context->extradata_size > 0) { 374 if (codec_context->extradata_size > 0) {
367 extra_data.assign(codec_context->extradata, 375 extra_data.assign(codec_context->extradata,
368 codec_context->extradata + codec_context->extradata_size); 376 codec_context->extradata + codec_context->extradata_size);
369 } 377 }
370 378
371 config->Initialize(codec, sample_format, channel_layout, sample_rate, 379 config->Initialize(codec, sample_format, channel_layout, sample_rate,
372 extra_data, encryption_scheme, seek_preroll, 380 extra_data, encryption_scheme, seek_preroll,
373 codec_context->delay); 381 codec_context->delay);
382 config->SetChannelsForDiscrete(codec_context->channels);
DaleCurtis 2017/05/24 00:49:58 Probably you don't want to always do this. channel
flim-chromium 2017/05/25 00:04:26 Right, I ran into this problem with the ffmpeg tes
374 383
375 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) 384 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING)
376 // These are bitstream formats unknown to ffmpeg, so they don't have 385 // These are bitstream formats unknown to ffmpeg, so they don't have
377 // a known sample format size. 386 // a known sample format size.
378 if (codec == kCodecAC3 || codec == kCodecEAC3) 387 if (codec == kCodecAC3 || codec == kCodecEAC3)
379 return true; 388 return true;
380 #endif 389 #endif
381 390
382 // Verify that AudioConfig.bits_per_channel was calculated correctly for 391 // Verify that AudioConfig.bits_per_channel was calculated correctly for
383 // codecs that have |sample_fmt| set by FFmpeg. 392 // codecs that have |sample_fmt| set by FFmpeg.
(...skipping 28 matching lines...) Expand all
412 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, 421 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config,
413 AVCodecContext* codec_context) { 422 AVCodecContext* codec_context) {
414 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; 423 codec_context->codec_type = AVMEDIA_TYPE_AUDIO;
415 codec_context->codec_id = AudioCodecToCodecID(config.codec(), 424 codec_context->codec_id = AudioCodecToCodecID(config.codec(),
416 config.sample_format()); 425 config.sample_format());
417 codec_context->sample_fmt = SampleFormatToAVSampleFormat( 426 codec_context->sample_fmt = SampleFormatToAVSampleFormat(
418 config.sample_format()); 427 config.sample_format());
419 428
420 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses 429 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses
421 // said information to decode. 430 // said information to decode.
422 codec_context->channels = 431 codec_context->channels = config.channels();
423 ChannelLayoutToChannelCount(config.channel_layout());
424 codec_context->sample_rate = config.samples_per_second(); 432 codec_context->sample_rate = config.samples_per_second();
425 433
426 if (config.extra_data().empty()) { 434 if (config.extra_data().empty()) {
427 codec_context->extradata = nullptr; 435 codec_context->extradata = nullptr;
428 codec_context->extradata_size = 0; 436 codec_context->extradata_size = 0;
429 } else { 437 } else {
430 codec_context->extradata_size = config.extra_data().size(); 438 codec_context->extradata_size = config.extra_data().size();
431 codec_context->extradata = reinterpret_cast<uint8_t*>( 439 codec_context->extradata = reinterpret_cast<uint8_t*>(
432 av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE)); 440 av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE));
433 memcpy(codec_context->extradata, &config.extra_data()[0], 441 memcpy(codec_context->extradata, &config.extra_data()[0],
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 } 759 }
752 760
753 int32_t HashCodecName(const char* codec_name) { 761 int32_t HashCodecName(const char* codec_name) {
754 // Use the first 32-bits from the SHA1 hash as the identifier. 762 // Use the first 32-bits from the SHA1 hash as the identifier.
755 int32_t hash; 763 int32_t hash;
756 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); 764 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4);
757 return hash; 765 return hash;
758 } 766 }
759 767
760 } // namespace media 768 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698