Delete unused downloads page asset.
[chromium-blink-merge.git] / media / base / video_decoder_config.cc
blob501bf4d7b7801cb83f33d5edf4d8fc1cb9924f8e
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
3 // found in the LICENSE file.
5 #include "media/base/video_decoder_config.h"
7 #include "base/logging.h"
8 #include "media/base/video_frame.h"
10 namespace media {
12 VideoCodec VideoCodecProfileToVideoCodec(VideoCodecProfile profile) {
13 switch (profile) {
14 case VIDEO_CODEC_PROFILE_UNKNOWN:
15 return kUnknownVideoCodec;
16 case H264PROFILE_BASELINE:
17 case H264PROFILE_MAIN:
18 case H264PROFILE_EXTENDED:
19 case H264PROFILE_HIGH:
20 case H264PROFILE_HIGH10PROFILE:
21 case H264PROFILE_HIGH422PROFILE:
22 case H264PROFILE_HIGH444PREDICTIVEPROFILE:
23 case H264PROFILE_SCALABLEBASELINE:
24 case H264PROFILE_SCALABLEHIGH:
25 case H264PROFILE_STEREOHIGH:
26 case H264PROFILE_MULTIVIEWHIGH:
27 return kCodecH264;
28 case VP8PROFILE_ANY:
29 return kCodecVP8;
30 case VP9PROFILE_ANY:
31 return kCodecVP9;
33 NOTREACHED();
34 return kUnknownVideoCodec;
38 VideoDecoderConfig::VideoDecoderConfig()
39 : codec_(kUnknownVideoCodec),
40 profile_(VIDEO_CODEC_PROFILE_UNKNOWN),
41 format_(PIXEL_FORMAT_UNKNOWN),
42 is_encrypted_(false) {
45 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
46 VideoCodecProfile profile,
47 VideoPixelFormat format,
48 ColorSpace color_space,
49 const gfx::Size& coded_size,
50 const gfx::Rect& visible_rect,
51 const gfx::Size& natural_size,
52 const uint8* extra_data,
53 size_t extra_data_size,
54 bool is_encrypted) {
55 Initialize(codec, profile, format, color_space, coded_size, visible_rect,
56 natural_size, extra_data, extra_data_size, is_encrypted);
59 VideoDecoderConfig::~VideoDecoderConfig() {}
61 void VideoDecoderConfig::Initialize(VideoCodec codec,
62 VideoCodecProfile profile,
63 VideoPixelFormat format,
64 ColorSpace color_space,
65 const gfx::Size& coded_size,
66 const gfx::Rect& visible_rect,
67 const gfx::Size& natural_size,
68 const uint8* extra_data,
69 size_t extra_data_size,
70 bool is_encrypted) {
71 CHECK((extra_data_size != 0) == (extra_data != NULL));
73 codec_ = codec;
74 profile_ = profile;
75 format_ = format;
76 color_space_ = color_space;
77 coded_size_ = coded_size;
78 visible_rect_ = visible_rect;
79 natural_size_ = natural_size;
80 extra_data_.assign(extra_data, extra_data + extra_data_size);
81 is_encrypted_ = is_encrypted;
84 bool VideoDecoderConfig::IsValidConfig() const {
85 return codec_ != kUnknownVideoCodec &&
86 natural_size_.width() > 0 &&
87 natural_size_.height() > 0 &&
88 VideoFrame::IsValidConfig(format_, VideoFrame::STORAGE_UNOWNED_MEMORY,
89 coded_size_, visible_rect_, natural_size_);
92 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const {
93 return ((codec() == config.codec()) &&
94 (format() == config.format()) &&
95 (profile() == config.profile()) &&
96 (coded_size() == config.coded_size()) &&
97 (visible_rect() == config.visible_rect()) &&
98 (natural_size() == config.natural_size()) &&
99 (extra_data_size() == config.extra_data_size()) &&
100 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
101 extra_data_size())) &&
102 (is_encrypted() == config.is_encrypted()));
105 std::string VideoDecoderConfig::AsHumanReadableString() const {
106 std::ostringstream s;
107 s << "codec: " << GetHumanReadableCodecName()
108 << " format: " << format()
109 << " profile: " << profile()
110 << " coded size: [" << coded_size().width()
111 << "," << coded_size().height() << "]"
112 << " visible rect: [" << visible_rect().x()
113 << "," << visible_rect().y()
114 << "," << visible_rect().width()
115 << "," << visible_rect().height() << "]"
116 << " natural size: [" << natural_size().width()
117 << "," << natural_size().height() << "]"
118 << " has extra data? " << (extra_data() ? "true" : "false")
119 << " encrypted? " << (is_encrypted() ? "true" : "false");
120 return s.str();
123 // The names come from src/third_party/ffmpeg/libavcodec/codec_desc.c
124 std::string VideoDecoderConfig::GetHumanReadableCodecName() const {
125 switch (codec()) {
126 case kUnknownVideoCodec:
127 return "unknown";
128 case kCodecH264:
129 return "h264";
130 case kCodecVC1:
131 return "vc1";
132 case kCodecMPEG2:
133 return "mpeg2video";
134 case kCodecMPEG4:
135 return "mpeg4";
136 case kCodecTheora:
137 return "theora";
138 case kCodecVP8:
139 return "vp8";
140 case kCodecVP9:
141 return "vp9";
143 NOTREACHED();
144 return "";
147 const uint8* VideoDecoderConfig::extra_data() const {
148 if (extra_data_.empty())
149 return NULL;
150 return &extra_data_[0];
153 } // namespace media