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/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
15 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
16 #include "media/base/encryption_scheme.h" | |
16 #include "media/base/video_decoder_config.h" | 17 #include "media/base/video_decoder_config.h" |
17 #include "media/base/video_util.h" | 18 #include "media/base/video_util.h" |
18 #include "media/media_features.h" | 19 #include "media/media_features.h" |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 | 22 |
22 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | 23 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are |
23 // padded. Check here to ensure FFmpeg only receives data padded to its | 24 // padded. Check here to ensure FFmpeg only receives data padded to its |
24 // specifications. | 25 // specifications. |
25 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, | 26 static_assert(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 << " extra data cannot have size of " | 365 << " extra data cannot have size of " |
365 << codec_context->extradata_size << "."; | 366 << codec_context->extradata_size << "."; |
366 return false; | 367 return false; |
367 } | 368 } |
368 | 369 |
369 std::vector<uint8_t> extra_data; | 370 std::vector<uint8_t> extra_data; |
370 if (codec_context->extradata_size > 0) { | 371 if (codec_context->extradata_size > 0) { |
371 extra_data.assign(codec_context->extradata, | 372 extra_data.assign(codec_context->extradata, |
372 codec_context->extradata + codec_context->extradata_size); | 373 codec_context->extradata + codec_context->extradata_size); |
373 } | 374 } |
374 config->Initialize(codec, | 375 |
375 sample_format, | 376 EncryptionScheme encryption_scheme( |
ddorwin
2016/03/02 23:24:05
It's weird that the audio path has an extra functi
dougsteed
2016/03/03 04:45:00
Done. The extra audio function AVCodecContextToAud
ddorwin
2016/03/03 18:38:04
Yes. No interfaces are guaranteed not to change ex
| |
376 channel_layout, | 377 is_encrypted ? EncryptionScheme::kCipherModeAesCtr |
377 sample_rate, | 378 : EncryptionScheme::kCipherModeUnencrypted); |
378 extra_data, | 379 config->Initialize(codec, sample_format, channel_layout, sample_rate, |
379 is_encrypted, | 380 extra_data, encryption_scheme, seek_preroll, |
380 seek_preroll, | |
381 codec_context->delay); | 381 codec_context->delay); |
382 | 382 |
383 // Verify that AudioConfig.bits_per_channel was calculated correctly for | 383 // Verify that AudioConfig.bits_per_channel was calculated correctly for |
384 // codecs that have |sample_fmt| set by FFmpeg. | 384 // codecs that have |sample_fmt| set by FFmpeg. |
385 switch (codec) { | 385 switch (codec) { |
386 case kCodecOpus: | 386 case kCodecOpus: |
387 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 387 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
388 case kCodecAC3: | 388 case kCodecAC3: |
389 case kCodecEAC3: | 389 case kCodecEAC3: |
390 #endif | 390 #endif |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 coded_size = visible_rect.size(); | 490 coded_size = visible_rect.size(); |
491 } | 491 } |
492 | 492 |
493 // Pad out |coded_size| for subsampled YUV formats. | 493 // Pad out |coded_size| for subsampled YUV formats. |
494 if (format != PIXEL_FORMAT_YV24) { | 494 if (format != PIXEL_FORMAT_YV24) { |
495 coded_size.set_width((coded_size.width() + 1) / 2 * 2); | 495 coded_size.set_width((coded_size.width() + 1) / 2 * 2); |
496 if (format != PIXEL_FORMAT_YV16) | 496 if (format != PIXEL_FORMAT_YV16) |
497 coded_size.set_height((coded_size.height() + 1) / 2 * 2); | 497 coded_size.set_height((coded_size.height() + 1) / 2 * 2); |
498 } | 498 } |
499 | 499 |
500 bool is_encrypted = false; | |
501 AVDictionaryEntry* key = | 500 AVDictionaryEntry* key = |
502 av_dict_get(stream->metadata, "enc_key_id", nullptr, 0); | 501 av_dict_get(stream->metadata, "enc_key_id", nullptr, 0); |
503 if (key) | 502 EncryptionScheme encryption_scheme( |
504 is_encrypted = true; | 503 key ? EncryptionScheme::kCipherModeAesCtr |
504 : EncryptionScheme::kCipherModeUnencrypted); | |
505 | 505 |
506 AVDictionaryEntry* webm_alpha = | 506 AVDictionaryEntry* webm_alpha = |
507 av_dict_get(stream->metadata, "alpha_mode", nullptr, 0); | 507 av_dict_get(stream->metadata, "alpha_mode", nullptr, 0); |
508 if (webm_alpha && !strcmp(webm_alpha->value, "1")) { | 508 if (webm_alpha && !strcmp(webm_alpha->value, "1")) { |
509 format = PIXEL_FORMAT_YV12A; | 509 format = PIXEL_FORMAT_YV12A; |
510 } | 510 } |
511 | 511 |
512 // Prefer the color space found by libavcodec if available. | 512 // Prefer the color space found by libavcodec if available. |
513 ColorSpace color_space = AVColorSpaceToColorSpace(stream->codec->colorspace, | 513 ColorSpace color_space = AVColorSpaceToColorSpace(stream->codec->colorspace, |
514 stream->codec->color_range); | 514 stream->codec->color_range); |
(...skipping 13 matching lines...) Expand all Loading... | |
528 << stream->codec->extradata_size << "."; | 528 << stream->codec->extradata_size << "."; |
529 return false; | 529 return false; |
530 } | 530 } |
531 | 531 |
532 std::vector<uint8_t> extra_data; | 532 std::vector<uint8_t> extra_data; |
533 if (stream->codec->extradata_size > 0) { | 533 if (stream->codec->extradata_size > 0) { |
534 extra_data.assign(stream->codec->extradata, | 534 extra_data.assign(stream->codec->extradata, |
535 stream->codec->extradata + stream->codec->extradata_size); | 535 stream->codec->extradata + stream->codec->extradata_size); |
536 } | 536 } |
537 config->Initialize(codec, profile, format, color_space, coded_size, | 537 config->Initialize(codec, profile, format, color_space, coded_size, |
538 visible_rect, natural_size, extra_data, is_encrypted); | 538 visible_rect, natural_size, extra_data, encryption_scheme); |
539 return true; | 539 return true; |
540 } | 540 } |
541 | 541 |
542 void VideoDecoderConfigToAVCodecContext( | 542 void VideoDecoderConfigToAVCodecContext( |
543 const VideoDecoderConfig& config, | 543 const VideoDecoderConfig& config, |
544 AVCodecContext* codec_context) { | 544 AVCodecContext* codec_context) { |
545 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 545 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
546 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 546 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
547 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); | 547 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); |
548 codec_context->coded_width = config.coded_size().width(); | 548 codec_context->coded_width = config.coded_size().width(); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 } | 760 } |
761 | 761 |
762 int32_t HashCodecName(const char* codec_name) { | 762 int32_t HashCodecName(const char* codec_name) { |
763 // Use the first 32-bits from the SHA1 hash as the identifier. | 763 // Use the first 32-bits from the SHA1 hash as the identifier. |
764 int32_t hash; | 764 int32_t hash; |
765 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); | 765 memcpy(&hash, base::SHA1HashString(codec_name).substr(0, 4).c_str(), 4); |
766 return hash; | 766 return hash; |
767 } | 767 } |
768 | 768 |
769 } // namespace media | 769 } // namespace media |
OLD | NEW |