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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
15 #include "media/base/encryption_scheme.h" | |
15 #include "media/base/video_decoder_config.h" | 16 #include "media/base/video_decoder_config.h" |
16 #include "media/base/video_util.h" | 17 #include "media/base/video_util.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"); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 << " extra data cannot have size of " | 338 << " extra data cannot have size of " |
338 << codec_context->extradata_size << "."; | 339 << codec_context->extradata_size << "."; |
339 return false; | 340 return false; |
340 } | 341 } |
341 | 342 |
342 std::vector<uint8_t> extra_data; | 343 std::vector<uint8_t> extra_data; |
343 if (codec_context->extradata_size > 0) { | 344 if (codec_context->extradata_size > 0) { |
344 extra_data.assign(codec_context->extradata, | 345 extra_data.assign(codec_context->extradata, |
345 codec_context->extradata + codec_context->extradata_size); | 346 codec_context->extradata + codec_context->extradata_size); |
346 } | 347 } |
347 config->Initialize(codec, | 348 config->Initialize(codec, sample_format, channel_layout, sample_rate, |
348 sample_format, | 349 extra_data, EncryptionScheme(is_encrypted), seek_preroll, |
349 channel_layout, | |
350 sample_rate, | |
351 extra_data, | |
352 is_encrypted, | |
353 seek_preroll, | |
354 codec_context->delay); | 350 codec_context->delay); |
355 | 351 |
356 if (codec != kCodecOpus) { | 352 if (codec != kCodecOpus) { |
357 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 353 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
358 config->bits_per_channel()); | 354 config->bits_per_channel()); |
359 } | 355 } |
360 | 356 |
361 return true; | 357 return true; |
362 } | 358 } |
363 | 359 |
364 bool AVStreamToAudioDecoderConfig(const AVStream* stream, | 360 bool AVStreamToAudioDecoderConfig(const AVStream* stream, |
365 AudioDecoderConfig* config) { | 361 AudioDecoderConfig* config) { |
366 bool is_encrypted = false; | 362 bool is_encrypted = false; |
367 AVDictionaryEntry* key = | 363 AVDictionaryEntry* key = |
368 av_dict_get(stream->metadata, "enc_key_id", nullptr, 0); | 364 av_dict_get(stream->metadata, "enc_key_id", nullptr, 0); |
369 if (key) | 365 if (key) |
370 is_encrypted = true; | 366 is_encrypted = true; |
371 return AVCodecContextToAudioDecoderConfig(stream->codec, is_encrypted, | 367 return AVCodecContextToAudioDecoderConfig(stream->codec, is_encrypted, |
ddorwin
2015/12/10 18:36:01
We could create the correct object here.
dougsteed
2015/12/14 21:19:02
Would it be beneficial to push EncryptionScheme fu
| |
372 config); | 368 config); |
373 } | 369 } |
374 | 370 |
375 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, | 371 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, |
376 AVCodecContext* codec_context) { | 372 AVCodecContext* codec_context) { |
377 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; | 373 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; |
378 codec_context->codec_id = AudioCodecToCodecID(config.codec(), | 374 codec_context->codec_id = AudioCodecToCodecID(config.codec(), |
379 config.sample_format()); | 375 config.sample_format()); |
380 codec_context->sample_fmt = SampleFormatToAVSampleFormat( | 376 codec_context->sample_fmt = SampleFormatToAVSampleFormat( |
381 config.sample_format()); | 377 config.sample_format()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 << stream->codec->extradata_size << "."; | 487 << stream->codec->extradata_size << "."; |
492 return false; | 488 return false; |
493 } | 489 } |
494 | 490 |
495 std::vector<uint8_t> extra_data; | 491 std::vector<uint8_t> extra_data; |
496 if (stream->codec->extradata_size > 0) { | 492 if (stream->codec->extradata_size > 0) { |
497 extra_data.assign(stream->codec->extradata, | 493 extra_data.assign(stream->codec->extradata, |
498 stream->codec->extradata + stream->codec->extradata_size); | 494 stream->codec->extradata + stream->codec->extradata_size); |
499 } | 495 } |
500 config->Initialize(codec, profile, format, color_space, coded_size, | 496 config->Initialize(codec, profile, format, color_space, coded_size, |
501 visible_rect, natural_size, extra_data, is_encrypted); | 497 visible_rect, natural_size, extra_data, |
498 EncryptionScheme(is_encrypted)); | |
502 return true; | 499 return true; |
503 } | 500 } |
504 | 501 |
505 void VideoDecoderConfigToAVCodecContext( | 502 void VideoDecoderConfigToAVCodecContext( |
506 const VideoDecoderConfig& config, | 503 const VideoDecoderConfig& config, |
507 AVCodecContext* codec_context) { | 504 AVCodecContext* codec_context) { |
508 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 505 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
509 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 506 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
510 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); | 507 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); |
511 codec_context->coded_width = config.coded_size().width(); | 508 codec_context->coded_width = config.coded_size().width(); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 } | 687 } |
691 | 688 |
692 int32_t HashCodecName(const char* codec_name) { | 689 int32_t HashCodecName(const char* codec_name) { |
693 // Use the first 32-bits from the SHA1 hash as the identifier. | 690 // Use the first 32-bits from the SHA1 hash as the identifier. |
694 int32_t hash; | 691 int32_t hash; |
695 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 692 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
696 return hash; | 693 return hash; |
697 } | 694 } |
698 | 695 |
699 } // namespace media | 696 } // namespace media |
OLD | NEW |