Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: media/base/video_decoder_config.cc

Issue 10830110: Remove VideoDecoderConfig::aspect_ratio_xxx methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments & rebased Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/video_decoder_config.h ('k') | media/base/video_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/video_decoder_config.h" 5 #include "media/base/video_decoder_config.h"
6 6
7 #include <cmath>
8
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
11 9
12 namespace media { 10 namespace media {
13 11
14 VideoDecoderConfig::VideoDecoderConfig() 12 VideoDecoderConfig::VideoDecoderConfig()
15 : codec_(kUnknownVideoCodec), 13 : codec_(kUnknownVideoCodec),
16 profile_(VIDEO_CODEC_PROFILE_UNKNOWN), 14 profile_(VIDEO_CODEC_PROFILE_UNKNOWN),
17 format_(VideoFrame::INVALID), 15 format_(VideoFrame::INVALID),
18 aspect_ratio_numerator_(0),
19 aspect_ratio_denominator_(0),
20 extra_data_size_(0) { 16 extra_data_size_(0) {
21 } 17 }
22 18
23 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, 19 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
24 VideoCodecProfile profile, 20 VideoCodecProfile profile,
25 VideoFrame::Format format, 21 VideoFrame::Format format,
26 const gfx::Size& coded_size, 22 const gfx::Size& coded_size,
27 const gfx::Rect& visible_rect, 23 const gfx::Rect& visible_rect,
28 int aspect_ratio_numerator, 24 const gfx::Size& natural_size,
29 int aspect_ratio_denominator,
30 const uint8* extra_data, 25 const uint8* extra_data,
31 size_t extra_data_size) { 26 size_t extra_data_size) {
32 Initialize(codec, profile, format, coded_size, visible_rect, 27 Initialize(codec, profile, format, coded_size, visible_rect, natural_size,
33 aspect_ratio_numerator, aspect_ratio_denominator,
34 extra_data, extra_data_size, true); 28 extra_data, extra_data_size, true);
35 } 29 }
36 30
37 VideoDecoderConfig::~VideoDecoderConfig() {} 31 VideoDecoderConfig::~VideoDecoderConfig() {}
38 32
39 // Some videos just want to watch the world burn, with a height of 0; cap the 33 // Some videos just want to watch the world burn, with a height of 0; cap the
40 // "infinite" aspect ratio resulting. 34 // "infinite" aspect ratio resulting.
41 static const int kInfiniteRatio = 99999; 35 static const int kInfiniteRatio = 99999;
42 36
43 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming 37 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming
(...skipping 12 matching lines...) Expand all
56 size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio, 50 size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio,
57 base::CustomHistogram::ArrayToCustomRanges( 51 base::CustomHistogram::ArrayToCustomRanges(
58 kCommonAspectRatios100, arraysize(kCommonAspectRatios100))); 52 kCommonAspectRatios100, arraysize(kCommonAspectRatios100)));
59 } 53 }
60 54
61 void VideoDecoderConfig::Initialize(VideoCodec codec, 55 void VideoDecoderConfig::Initialize(VideoCodec codec,
62 VideoCodecProfile profile, 56 VideoCodecProfile profile,
63 VideoFrame::Format format, 57 VideoFrame::Format format,
64 const gfx::Size& coded_size, 58 const gfx::Size& coded_size,
65 const gfx::Rect& visible_rect, 59 const gfx::Rect& visible_rect,
66 int aspect_ratio_numerator, 60 const gfx::Size& natural_size,
67 int aspect_ratio_denominator,
68 const uint8* extra_data, 61 const uint8* extra_data,
69 size_t extra_data_size, 62 size_t extra_data_size,
70 bool record_stats) { 63 bool record_stats) {
71 CHECK((extra_data_size != 0) == (extra_data != NULL)); 64 CHECK((extra_data_size != 0) == (extra_data != NULL));
72 65
73 if (record_stats) { 66 if (record_stats) {
74 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1); 67 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1);
75 // Drop UNKNOWN because U_H_E() uses one bucket for all values less than 1. 68 // Drop UNKNOWN because U_H_E() uses one bucket for all values less than 1.
76 if (profile >= 0) { 69 if (profile >= 0) {
77 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile, 70 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile,
78 VIDEO_CODEC_PROFILE_MAX + 1); 71 VIDEO_CODEC_PROFILE_MAX + 1);
79 } 72 }
80 UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width()); 73 UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width());
81 UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size); 74 UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size);
82 UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width()); 75 UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width());
83 UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect); 76 UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect);
84 } 77 }
85 78
86 codec_ = codec; 79 codec_ = codec;
87 profile_ = profile; 80 profile_ = profile;
88 format_ = format; 81 format_ = format;
89 coded_size_ = coded_size; 82 coded_size_ = coded_size;
90 visible_rect_ = visible_rect; 83 visible_rect_ = visible_rect;
91 aspect_ratio_numerator_ = aspect_ratio_numerator; 84 natural_size_ = natural_size;
92 aspect_ratio_denominator_ = aspect_ratio_denominator;
93 extra_data_size_ = extra_data_size; 85 extra_data_size_ = extra_data_size;
94 86
95 if (extra_data_size_ > 0) { 87 if (extra_data_size_ > 0) {
96 extra_data_.reset(new uint8[extra_data_size_]); 88 extra_data_.reset(new uint8[extra_data_size_]);
97 memcpy(extra_data_.get(), extra_data, extra_data_size_); 89 memcpy(extra_data_.get(), extra_data, extra_data_size_);
98 } else { 90 } else {
99 extra_data_.reset(); 91 extra_data_.reset();
100 } 92 }
101
102 // Calculate the natural size given the aspect ratio and visible rect.
103 if (aspect_ratio_denominator == 0) {
104 natural_size_.SetSize(0, 0);
105 return;
106 }
107
108 double aspect_ratio = aspect_ratio_numerator /
109 static_cast<double>(aspect_ratio_denominator);
110
111 int width = floor(visible_rect.width() * aspect_ratio + 0.5);
112 int height = visible_rect.height();
113
114 // An even width makes things easier for YV12 and appears to be the behavior
115 // expected by WebKit layout tests.
116 natural_size_.SetSize(width & ~1, height);
117 } 93 }
118 94
119 void VideoDecoderConfig::CopyFrom(const VideoDecoderConfig& video_config) { 95 void VideoDecoderConfig::CopyFrom(const VideoDecoderConfig& video_config) {
120 Initialize(video_config.codec(), 96 Initialize(video_config.codec(),
121 video_config.profile(), 97 video_config.profile(),
122 video_config.format(), 98 video_config.format(),
123 video_config.coded_size(), 99 video_config.coded_size(),
124 video_config.visible_rect(), 100 video_config.visible_rect(),
125 video_config.aspect_ratio_numerator(), 101 video_config.natural_size(),
126 video_config.aspect_ratio_denominator(),
127 video_config.extra_data(), 102 video_config.extra_data(),
128 video_config.extra_data_size(), 103 video_config.extra_data_size(),
129 false); 104 false);
130 } 105 }
131 106
132 bool VideoDecoderConfig::IsValidConfig() const { 107 bool VideoDecoderConfig::IsValidConfig() const {
133 return codec_ != kUnknownVideoCodec && 108 return codec_ != kUnknownVideoCodec &&
134 aspect_ratio_numerator_ > 0 && 109 natural_size_.width() > 0 &&
135 aspect_ratio_denominator_ > 0 && 110 natural_size_.height() > 0 &&
136 VideoFrame::IsValidConfig( 111 VideoFrame::IsValidConfig(
137 format_, natural_size_.width(), natural_size_.height()); 112 format_, natural_size_.width(), natural_size_.height());
138 } 113 }
139 114
140 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const { 115 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const {
141 return ((codec() == config.codec()) && 116 return ((codec() == config.codec()) &&
142 (format() == config.format()) && 117 (format() == config.format()) &&
143 (profile() == config.profile()) && 118 (profile() == config.profile()) &&
144 (coded_size() == config.coded_size()) && 119 (coded_size() == config.coded_size()) &&
145 (visible_rect() == config.visible_rect()) && 120 (visible_rect() == config.visible_rect()) &&
146 (natural_size() == config.natural_size()) && 121 (natural_size() == config.natural_size()) &&
147 (extra_data_size() == config.extra_data_size()) && 122 (extra_data_size() == config.extra_data_size()) &&
148 (!extra_data() || !memcmp(extra_data(), config.extra_data(), 123 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
149 extra_data_size()))); 124 extra_data_size())));
150 } 125 }
151 126
152 std::string VideoDecoderConfig::AsHumanReadableString() const { 127 std::string VideoDecoderConfig::AsHumanReadableString() const {
153 std::ostringstream s; 128 std::ostringstream s;
154 s << "codec: " << codec() 129 s << "codec: " << codec()
155 << " format: " << format() 130 << " format: " << format()
156 << " coded size: [" << coded_size().width() 131 << " coded size: [" << coded_size().width()
157 << "," << coded_size().height() << "]" 132 << "," << coded_size().height() << "]"
158 << " visible rect: [" << visible_rect().x() 133 << " visible rect: [" << visible_rect().x()
159 << "," << visible_rect().y() 134 << "," << visible_rect().y()
160 << "," << visible_rect().width() 135 << "," << visible_rect().width()
161 << "," << visible_rect().height() << "]" 136 << "," << visible_rect().height() << "]"
162 << " natural size: [" << natural_size().width() 137 << " natural size: [" << natural_size().width()
163 << "," << natural_size().height() << "]" 138 << "," << natural_size().height() << "]";
164 << " aspect ratio: " << aspect_ratio_numerator()
165 << "/" << aspect_ratio_denominator();
166 return s.str(); 139 return s.str();
167 } 140 }
168 141
169 VideoCodec VideoDecoderConfig::codec() const { 142 VideoCodec VideoDecoderConfig::codec() const {
170 return codec_; 143 return codec_;
171 } 144 }
172 145
173 VideoCodecProfile VideoDecoderConfig::profile() const { 146 VideoCodecProfile VideoDecoderConfig::profile() const {
174 return profile_; 147 return profile_;
175 } 148 }
176 149
177 VideoFrame::Format VideoDecoderConfig::format() const { 150 VideoFrame::Format VideoDecoderConfig::format() const {
178 return format_; 151 return format_;
179 } 152 }
180 153
181 gfx::Size VideoDecoderConfig::coded_size() const { 154 gfx::Size VideoDecoderConfig::coded_size() const {
182 return coded_size_; 155 return coded_size_;
183 } 156 }
184 157
185 gfx::Rect VideoDecoderConfig::visible_rect() const { 158 gfx::Rect VideoDecoderConfig::visible_rect() const {
186 return visible_rect_; 159 return visible_rect_;
187 } 160 }
188 161
189 gfx::Size VideoDecoderConfig::natural_size() const { 162 gfx::Size VideoDecoderConfig::natural_size() const {
190 return natural_size_; 163 return natural_size_;
191 } 164 }
192 165
193 int VideoDecoderConfig::aspect_ratio_numerator() const {
194 return aspect_ratio_numerator_;
195 }
196
197 int VideoDecoderConfig::aspect_ratio_denominator() const {
198 return aspect_ratio_denominator_;
199 }
200
201 uint8* VideoDecoderConfig::extra_data() const { 166 uint8* VideoDecoderConfig::extra_data() const {
202 return extra_data_.get(); 167 return extra_data_.get();
203 } 168 }
204 169
205 size_t VideoDecoderConfig::extra_data_size() const { 170 size_t VideoDecoderConfig::extra_data_size() const {
206 return extra_data_size_; 171 return extra_data_size_;
207 } 172 }
208 173
209 } // namespace media 174 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_decoder_config.h ('k') | media/base/video_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698