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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.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 #include "media/media_features.h" | 18 #include "media/media_features.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 | 21 |
21 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | 22 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are |
22 // padded. Check here to ensure FFmpeg only receives data padded to its | 23 // padded. Check here to ensure FFmpeg only receives data padded to its |
23 // specifications. | 24 // specifications. |
24 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, | 25 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 << " extra data cannot have size of " | 364 << " extra data cannot have size of " |
364 << codec_context->extradata_size << "."; | 365 << codec_context->extradata_size << "."; |
365 return false; | 366 return false; |
366 } | 367 } |
367 | 368 |
368 std::vector<uint8_t> extra_data; | 369 std::vector<uint8_t> extra_data; |
369 if (codec_context->extradata_size > 0) { | 370 if (codec_context->extradata_size > 0) { |
370 extra_data.assign(codec_context->extradata, | 371 extra_data.assign(codec_context->extradata, |
371 codec_context->extradata + codec_context->extradata_size); | 372 codec_context->extradata + codec_context->extradata_size); |
372 } | 373 } |
373 config->Initialize(codec, | 374 config->Initialize(codec, sample_format, channel_layout, sample_rate, |
374 sample_format, | 375 extra_data, EncryptionScheme(is_encrypted), seek_preroll, |
ddorwin
2016/03/01 02:17:41
FFmpeg only supports CTR without a pattern, so we
dougsteed
2016/03/02 18:07:53
Done.
| |
375 channel_layout, | |
376 sample_rate, | |
377 extra_data, | |
378 is_encrypted, | |
379 seek_preroll, | |
380 codec_context->delay); | 376 codec_context->delay); |
381 | 377 |
382 // Verify that AudioConfig.bits_per_channel was calculated correctly for | 378 // Verify that AudioConfig.bits_per_channel was calculated correctly for |
383 // codecs that have |sample_fmt| set by FFmpeg. | 379 // codecs that have |sample_fmt| set by FFmpeg. |
384 switch (codec) { | 380 switch (codec) { |
385 case kCodecOpus: | 381 case kCodecOpus: |
386 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 382 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
387 case kCodecAC3: | 383 case kCodecAC3: |
388 case kCodecEAC3: | 384 case kCodecEAC3: |
389 #endif | 385 #endif |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 << stream->codec->extradata_size << "."; | 523 << stream->codec->extradata_size << "."; |
528 return false; | 524 return false; |
529 } | 525 } |
530 | 526 |
531 std::vector<uint8_t> extra_data; | 527 std::vector<uint8_t> extra_data; |
532 if (stream->codec->extradata_size > 0) { | 528 if (stream->codec->extradata_size > 0) { |
533 extra_data.assign(stream->codec->extradata, | 529 extra_data.assign(stream->codec->extradata, |
534 stream->codec->extradata + stream->codec->extradata_size); | 530 stream->codec->extradata + stream->codec->extradata_size); |
535 } | 531 } |
536 config->Initialize(codec, profile, format, color_space, coded_size, | 532 config->Initialize(codec, profile, format, color_space, coded_size, |
537 visible_rect, natural_size, extra_data, is_encrypted); | 533 visible_rect, natural_size, extra_data, |
534 EncryptionScheme(is_encrypted)); | |
ddorwin
2016/03/01 02:17:41
ditto
dougsteed
2016/03/02 18:07:53
Done.
| |
538 return true; | 535 return true; |
539 } | 536 } |
540 | 537 |
541 void VideoDecoderConfigToAVCodecContext( | 538 void VideoDecoderConfigToAVCodecContext( |
542 const VideoDecoderConfig& config, | 539 const VideoDecoderConfig& config, |
543 AVCodecContext* codec_context) { | 540 AVCodecContext* codec_context) { |
544 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 541 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
545 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 542 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
546 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); | 543 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); |
547 codec_context->coded_width = config.coded_size().width(); | 544 codec_context->coded_width = config.coded_size().width(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
759 } | 756 } |
760 | 757 |
761 int32_t HashCodecName(const char* codec_name) { | 758 int32_t HashCodecName(const char* codec_name) { |
762 // Use the first 32-bits from the SHA1 hash as the identifier. | 759 // Use the first 32-bits from the SHA1 hash as the identifier. |
763 int32_t hash; | 760 int32_t hash; |
764 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 761 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
765 return hash; | 762 return hash; |
766 } | 763 } |
767 | 764 |
768 } // namespace media | 765 } // namespace media |
OLD | NEW |