Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / media / base / video_decoder_config.cc
blobdc135d89b6dd179ea2b73e19f1a3dedb0e444a1d
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 "base/metrics/histogram.h"
10 namespace media {
12 VideoDecoderConfig::VideoDecoderConfig()
13 : codec_(kUnknownVideoCodec),
14 profile_(VIDEO_CODEC_PROFILE_UNKNOWN),
15 format_(VideoFrame::UNKNOWN),
16 is_encrypted_(false) {
19 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
20 VideoCodecProfile profile,
21 VideoFrame::Format format,
22 const gfx::Size& coded_size,
23 const gfx::Rect& visible_rect,
24 const gfx::Size& natural_size,
25 const uint8* extra_data,
26 size_t extra_data_size,
27 bool is_encrypted) {
28 Initialize(codec, profile, format, VideoFrame::COLOR_SPACE_UNSPECIFIED,
29 coded_size, visible_rect, natural_size, extra_data,
30 extra_data_size, is_encrypted, true);
33 VideoDecoderConfig::~VideoDecoderConfig() {}
35 // Some videos just want to watch the world burn, with a height of 0; cap the
36 // "infinite" aspect ratio resulting.
37 static const int kInfiniteRatio = 99999;
39 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming
40 // video sizes. These were taken on 20111103 from
41 // http://wikipedia.org/wiki/Aspect_ratio_(image)#Previous_and_currently_used_aspect_ratios
42 static const int kCommonAspectRatios100[] = {
43 100, 115, 133, 137, 143, 150, 155, 160, 166, 175, 177, 185, 200, 210, 220,
44 221, 235, 237, 240, 255, 259, 266, 276, 293, 400, 1200, kInfiniteRatio,
47 template<class T> // T has int width() & height() methods.
48 static void UmaHistogramAspectRatio(const char* name, const T& size) {
49 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
50 name,
51 // Intentionally use integer division to truncate the result.
52 size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio,
53 base::CustomHistogram::ArrayToCustomRanges(
54 kCommonAspectRatios100, arraysize(kCommonAspectRatios100)));
57 void VideoDecoderConfig::Initialize(VideoCodec codec,
58 VideoCodecProfile profile,
59 VideoFrame::Format format,
60 VideoFrame::ColorSpace color_space,
61 const gfx::Size& coded_size,
62 const gfx::Rect& visible_rect,
63 const gfx::Size& natural_size,
64 const uint8* extra_data,
65 size_t extra_data_size,
66 bool is_encrypted,
67 bool record_stats) {
68 CHECK((extra_data_size != 0) == (extra_data != NULL));
70 if (record_stats) {
71 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1);
72 // Drop UNKNOWN because U_H_E() uses one bucket for all values less than 1.
73 if (profile >= 0) {
74 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile,
75 VIDEO_CODEC_PROFILE_MAX + 1);
77 UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width());
78 UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size);
79 UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width());
80 UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect);
81 UMA_HISTOGRAM_ENUMERATION("Media.VideoFormat", format,
82 VideoFrame::FORMAT_MAX + 1);
83 UMA_HISTOGRAM_ENUMERATION("Media.VideoFrameColorSpace", color_space,
84 VideoFrame::COLOR_SPACE_MAX + 1);
87 codec_ = codec;
88 profile_ = profile;
89 format_ = format;
90 coded_size_ = coded_size;
91 visible_rect_ = visible_rect;
92 natural_size_ = natural_size;
93 extra_data_.assign(extra_data, extra_data + extra_data_size);
94 is_encrypted_ = is_encrypted;
97 bool VideoDecoderConfig::IsValidConfig() const {
98 return codec_ != kUnknownVideoCodec &&
99 natural_size_.width() > 0 &&
100 natural_size_.height() > 0 &&
101 VideoFrame::IsValidConfig(format_, coded_size_, visible_rect_,
102 natural_size_);
105 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const {
106 return ((codec() == config.codec()) &&
107 (format() == config.format()) &&
108 (profile() == config.profile()) &&
109 (coded_size() == config.coded_size()) &&
110 (visible_rect() == config.visible_rect()) &&
111 (natural_size() == config.natural_size()) &&
112 (extra_data_size() == config.extra_data_size()) &&
113 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
114 extra_data_size())) &&
115 (is_encrypted() == config.is_encrypted()));
118 std::string VideoDecoderConfig::AsHumanReadableString() const {
119 std::ostringstream s;
120 s << "codec: " << GetHumanReadableCodecName()
121 << " format: " << format()
122 << " profile: " << profile()
123 << " coded size: [" << coded_size().width()
124 << "," << coded_size().height() << "]"
125 << " visible rect: [" << visible_rect().x()
126 << "," << visible_rect().y()
127 << "," << visible_rect().width()
128 << "," << visible_rect().height() << "]"
129 << " natural size: [" << natural_size().width()
130 << "," << natural_size().height() << "]"
131 << " has extra data? " << (extra_data() ? "true" : "false")
132 << " encrypted? " << (is_encrypted() ? "true" : "false");
133 return s.str();
136 // The names come from src/third_party/ffmpeg/libavcodec/codec_desc.c
137 std::string VideoDecoderConfig::GetHumanReadableCodecName() const {
138 switch (codec()) {
139 case kUnknownVideoCodec:
140 return "unknown";
141 case kCodecH264:
142 return "h264";
143 case kCodecVC1:
144 return "vc1";
145 case kCodecMPEG2:
146 return "mpeg2video";
147 case kCodecMPEG4:
148 return "mpeg4";
149 case kCodecTheora:
150 return "theora";
151 case kCodecVP8:
152 return "vp8";
153 case kCodecVP9:
154 return "vp9";
156 NOTREACHED();
157 return "";
160 VideoCodec VideoDecoderConfig::codec() const {
161 return codec_;
164 VideoCodecProfile VideoDecoderConfig::profile() const {
165 return profile_;
168 VideoFrame::Format VideoDecoderConfig::format() const {
169 return format_;
172 gfx::Size VideoDecoderConfig::coded_size() const {
173 return coded_size_;
176 gfx::Rect VideoDecoderConfig::visible_rect() const {
177 return visible_rect_;
180 gfx::Size VideoDecoderConfig::natural_size() const {
181 return natural_size_;
184 const uint8* VideoDecoderConfig::extra_data() const {
185 if (extra_data_.empty())
186 return NULL;
187 return &extra_data_[0];
190 size_t VideoDecoderConfig::extra_data_size() const {
191 return extra_data_.size();
194 bool VideoDecoderConfig::is_encrypted() const {
195 return is_encrypted_;
198 } // namespace media