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