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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, 0); | 424 AVDictionaryEntry* key = av_dict_get(stream->metadata, "enc_key_id", NULL, 0); |
425 if (key) | 425 if (key) |
426 is_encrypted = true; | 426 is_encrypted = true; |
427 | 427 |
428 AVDictionaryEntry* webm_alpha = | 428 AVDictionaryEntry* webm_alpha = |
429 av_dict_get(stream->metadata, "alpha_mode", NULL, 0); | 429 av_dict_get(stream->metadata, "alpha_mode", NULL, 0); |
430 if (webm_alpha && !strcmp(webm_alpha->value, "1")) { | 430 if (webm_alpha && !strcmp(webm_alpha->value, "1")) { |
431 format = VideoFrame::YV12A; | 431 format = VideoFrame::YV12A; |
432 } | 432 } |
433 | 433 |
434 // Prefer the color space found by libavcodec if available. | 434 config->Initialize(codec, |
435 VideoFrame::ColorSpace color_space = | 435 profile, |
436 AVColorSpaceToVideoFrameColorSpace(stream->codec->colorspace); | 436 format, |
437 if (color_space == VideoFrame::COLOR_SPACE_UNSPECIFIED) { | 437 (stream->codec->colorspace == AVCOL_SPC_BT709) |
438 // Otherwise, assume that SD video is usually Rec.601, and HD is usually | 438 ? VideoFrame::COLOR_SPACE_HD_REC709 |
439 // Rec.709. | 439 : VideoFrame::COLOR_SPACE_UNSPECIFIED, |
440 color_space = (natural_size.height() < 720) | 440 coded_size, visible_rect, natural_size, |
441 ? VideoFrame::COLOR_SPACE_SD_REC601 | 441 stream->codec->extradata, stream->codec->extradata_size, |
442 : VideoFrame::COLOR_SPACE_HD_REC709; | 442 is_encrypted, |
443 } | 443 record_stats); |
444 | |
445 config->Initialize(codec, profile, format, color_space, coded_size, | |
446 visible_rect, natural_size, stream->codec->extradata, | |
447 stream->codec->extradata_size, is_encrypted, record_stats); | |
448 } | 444 } |
449 | 445 |
450 void VideoDecoderConfigToAVCodecContext( | 446 void VideoDecoderConfigToAVCodecContext( |
451 const VideoDecoderConfig& config, | 447 const VideoDecoderConfig& config, |
452 AVCodecContext* codec_context) { | 448 AVCodecContext* codec_context) { |
453 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 449 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
454 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 450 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
455 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); | 451 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); |
456 codec_context->coded_width = config.coded_size().width(); | 452 codec_context->coded_width = config.coded_size().width(); |
457 codec_context->coded_height = config.coded_size().height(); | 453 codec_context->coded_height = config.coded_size().height(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 case VideoFrame::YV12A: | 557 case VideoFrame::YV12A: |
562 return PIX_FMT_YUVA420P; | 558 return PIX_FMT_YUVA420P; |
563 case VideoFrame::YV24: | 559 case VideoFrame::YV24: |
564 return PIX_FMT_YUV444P; | 560 return PIX_FMT_YUV444P; |
565 default: | 561 default: |
566 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; | 562 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; |
567 } | 563 } |
568 return PIX_FMT_NONE; | 564 return PIX_FMT_NONE; |
569 } | 565 } |
570 | 566 |
571 VideoFrame::ColorSpace AVColorSpaceToVideoFrameColorSpace( | |
572 AVColorSpace color_space) { | |
573 switch (color_space) { | |
574 case AVCOL_SPC_BT709: | |
575 return VideoFrame::COLOR_SPACE_HD_REC709; | |
576 case AVCOL_SPC_SMPTE170M: | |
577 case AVCOL_SPC_BT470BG: | |
578 return VideoFrame::COLOR_SPACE_SD_REC601; | |
579 case AVCOL_SPC_UNSPECIFIED: | |
580 break; | |
581 default: | |
582 DVLOG(1) << "Unknown AVColorSpace: " << color_space; | |
583 } | |
584 return VideoFrame::COLOR_SPACE_UNSPECIFIED; | |
585 } | |
586 | |
587 bool FFmpegUTCDateToTime(const char* date_utc, base::Time* out) { | 567 bool FFmpegUTCDateToTime(const char* date_utc, base::Time* out) { |
588 DCHECK(date_utc); | 568 DCHECK(date_utc); |
589 DCHECK(out); | 569 DCHECK(out); |
590 | 570 |
591 std::vector<base::StringPiece> fields = base::SplitStringPiece( | 571 std::vector<base::StringPiece> fields = base::SplitStringPiece( |
592 date_utc, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 572 date_utc, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
593 if (fields.size() != 2) | 573 if (fields.size() != 2) |
594 return false; | 574 return false; |
595 | 575 |
596 std::vector<base::StringPiece> date_fields = base::SplitStringPiece( | 576 std::vector<base::StringPiece> date_fields = base::SplitStringPiece( |
(...skipping 21 matching lines...) Expand all Loading... |
618 return false; | 598 return false; |
619 | 599 |
620 *out = parsed_time; | 600 *out = parsed_time; |
621 return true; | 601 return true; |
622 } | 602 } |
623 | 603 |
624 return false; | 604 return false; |
625 } | 605 } |
626 | 606 |
627 } // namespace media | 607 } // namespace media |
OLD | NEW |