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