Chromium Code Reviews| 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/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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
| 328 codec_context->channel_layout, codec_context->channels); | 328 codec_context->channel_layout, codec_context->channels); |
| 329 | 329 |
| 330 // If it is an Opus channel mapping with discrete channels, or there are more | |
| 331 // channels than supported in the renderer, use CHANNEL_LAYOUT_DISCRETE. | |
| 332 bool is_opus_discrete = false; | |
| 333 if (codec == kCodecOpus && codec_context->extradata_size >= 19) { | |
| 334 int mapping_family = codec_context->extradata[18]; | |
| 335 is_opus_discrete = mapping_family == 2; | |
| 336 } | |
| 337 if (is_opus_discrete || channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) | |
|
DaleCurtis
2017/03/29 22:46:55
Do we need this || clause? Seems like we might all
flim-chromium
2017/03/30 19:35:10
Sorry, I misunderstood your original comment. Fixe
| |
| 338 channel_layout = CHANNEL_LAYOUT_DISCRETE; | |
| 339 | |
| 330 int sample_rate = codec_context->sample_rate; | 340 int sample_rate = codec_context->sample_rate; |
| 331 switch (codec) { | 341 switch (codec) { |
| 332 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does | 342 // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does |
| 333 // not fill |sample_fmt|. | 343 // not fill |sample_fmt|. |
| 334 case kCodecAC3: | 344 case kCodecAC3: |
| 335 case kCodecEAC3: | 345 case kCodecEAC3: |
| 336 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 346 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 337 // The spec for AC3/EAC3 audio is ETSI TS 102 366. According to sections | 347 // 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. | 348 // F.3.1 and F.5.1 in that spec the sample_format for AC3/EAC3 must be 16. |
| 339 sample_format = kSampleFormatS16; | 349 sample_format = kSampleFormatS16; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 364 | 374 |
| 365 std::vector<uint8_t> extra_data; | 375 std::vector<uint8_t> extra_data; |
| 366 if (codec_context->extradata_size > 0) { | 376 if (codec_context->extradata_size > 0) { |
| 367 extra_data.assign(codec_context->extradata, | 377 extra_data.assign(codec_context->extradata, |
| 368 codec_context->extradata + codec_context->extradata_size); | 378 codec_context->extradata + codec_context->extradata_size); |
| 369 } | 379 } |
| 370 | 380 |
| 371 config->Initialize(codec, sample_format, channel_layout, sample_rate, | 381 config->Initialize(codec, sample_format, channel_layout, sample_rate, |
| 372 extra_data, encryption_scheme, seek_preroll, | 382 extra_data, encryption_scheme, seek_preroll, |
| 373 codec_context->delay); | 383 codec_context->delay); |
| 384 config->SetChannelsForDiscrete(codec_context->channels); | |
| 374 | 385 |
| 375 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 386 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 376 // These are bitstream formats unknown to ffmpeg, so they don't have | 387 // These are bitstream formats unknown to ffmpeg, so they don't have |
| 377 // a known sample format size. | 388 // a known sample format size. |
| 378 if (codec == kCodecAC3 || codec == kCodecEAC3) | 389 if (codec == kCodecAC3 || codec == kCodecEAC3) |
| 379 return true; | 390 return true; |
| 380 #endif | 391 #endif |
| 381 | 392 |
| 382 // Verify that AudioConfig.bits_per_channel was calculated correctly for | 393 // Verify that AudioConfig.bits_per_channel was calculated correctly for |
| 383 // codecs that have |sample_fmt| set by FFmpeg. | 394 // codecs that have |sample_fmt| set by FFmpeg. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 412 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, | 423 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, |
| 413 AVCodecContext* codec_context) { | 424 AVCodecContext* codec_context) { |
| 414 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; | 425 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; |
| 415 codec_context->codec_id = AudioCodecToCodecID(config.codec(), | 426 codec_context->codec_id = AudioCodecToCodecID(config.codec(), |
| 416 config.sample_format()); | 427 config.sample_format()); |
| 417 codec_context->sample_fmt = SampleFormatToAVSampleFormat( | 428 codec_context->sample_fmt = SampleFormatToAVSampleFormat( |
| 418 config.sample_format()); | 429 config.sample_format()); |
| 419 | 430 |
| 420 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses | 431 // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses |
| 421 // said information to decode. | 432 // said information to decode. |
| 422 codec_context->channels = | 433 codec_context->channels = config.channels(); |
| 423 ChannelLayoutToChannelCount(config.channel_layout()); | |
| 424 codec_context->sample_rate = config.samples_per_second(); | 434 codec_context->sample_rate = config.samples_per_second(); |
| 425 | 435 |
| 426 if (config.extra_data().empty()) { | 436 if (config.extra_data().empty()) { |
| 427 codec_context->extradata = nullptr; | 437 codec_context->extradata = nullptr; |
| 428 codec_context->extradata_size = 0; | 438 codec_context->extradata_size = 0; |
| 429 } else { | 439 } else { |
| 430 codec_context->extradata_size = config.extra_data().size(); | 440 codec_context->extradata_size = config.extra_data().size(); |
| 431 codec_context->extradata = reinterpret_cast<uint8_t*>( | 441 codec_context->extradata = reinterpret_cast<uint8_t*>( |
| 432 av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE)); | 442 av_malloc(config.extra_data().size() + FF_INPUT_BUFFER_PADDING_SIZE)); |
| 433 memcpy(codec_context->extradata, &config.extra_data()[0], | 443 memcpy(codec_context->extradata, &config.extra_data()[0], |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 } | 761 } |
| 752 | 762 |
| 753 int32_t HashCodecName(const char* codec_name) { | 763 int32_t HashCodecName(const char* codec_name) { |
| 754 // Use the first 32-bits from the SHA1 hash as the identifier. | 764 // Use the first 32-bits from the SHA1 hash as the identifier. |
| 755 int32_t hash; | 765 int32_t hash; |
| 756 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 766 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
| 757 return hash; | 767 return hash; |
| 758 } | 768 } |
| 759 | 769 |
| 760 } // namespace media | 770 } // namespace media |
| OLD | NEW |