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

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

Issue 8686010: <video> decode in hardware! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing OVERRIDEs Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "media/base/limits.h" 11 #include "media/base/limits.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 VideoDecoderConfig::VideoDecoderConfig() 15 VideoDecoderConfig::VideoDecoderConfig()
16 : codec_(kUnknownVideoCodec), 16 : codec_(kUnknownVideoCodec),
17 profile_(VIDEO_CODEC_PROFILE_UNKNOWN),
17 format_(VideoFrame::INVALID), 18 format_(VideoFrame::INVALID),
18 frame_rate_numerator_(0), 19 frame_rate_numerator_(0),
19 frame_rate_denominator_(0), 20 frame_rate_denominator_(0),
20 aspect_ratio_numerator_(0), 21 aspect_ratio_numerator_(0),
21 aspect_ratio_denominator_(0), 22 aspect_ratio_denominator_(0),
22 extra_data_size_(0) { 23 extra_data_size_(0) {
23 } 24 }
24 25
25 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, 26 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
27 VideoCodecProfile profile,
26 VideoFrame::Format format, 28 VideoFrame::Format format,
27 const gfx::Size& coded_size, 29 const gfx::Size& coded_size,
28 const gfx::Rect& visible_rect, 30 const gfx::Rect& visible_rect,
29 int frame_rate_numerator, 31 int frame_rate_numerator,
30 int frame_rate_denominator, 32 int frame_rate_denominator,
31 int aspect_ratio_numerator, 33 int aspect_ratio_numerator,
32 int aspect_ratio_denominator, 34 int aspect_ratio_denominator,
33 const uint8* extra_data, 35 const uint8* extra_data,
34 size_t extra_data_size) { 36 size_t extra_data_size) {
35 Initialize(codec, format, coded_size, visible_rect, 37 Initialize(codec, profile, format, coded_size, visible_rect,
36 frame_rate_numerator, frame_rate_denominator, 38 frame_rate_numerator, frame_rate_denominator,
37 aspect_ratio_numerator, aspect_ratio_denominator, 39 aspect_ratio_numerator, aspect_ratio_denominator,
38 extra_data, extra_data_size); 40 extra_data, extra_data_size);
39 } 41 }
40 42
41 VideoDecoderConfig::~VideoDecoderConfig() {} 43 VideoDecoderConfig::~VideoDecoderConfig() {}
42 44
43 // Some videos just want to watch the world burn, with a height of 0; cap the 45 // Some videos just want to watch the world burn, with a height of 0; cap the
44 // "infinite" aspect ratio resulting. 46 // "infinite" aspect ratio resulting.
45 static const int kInfiniteRatio = 99999; 47 static const int kInfiniteRatio = 99999;
46 48
47 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming 49 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming
48 // video sizes. These were taken on 20111103 from 50 // video sizes. These were taken on 20111103 from
49 // http://wikipedia.org/wiki/Aspect_ratio_(image)#Previous_and_currently_used_as pect_ratios 51 // http://wikipedia.org/wiki/Aspect_ratio_(image)#Previous_and_currently_used_as pect_ratios
50 static const int kCommonAspectRatios100[] = { 52 static const int kCommonAspectRatios100[] = {
51 100, 115, 133, 137, 143, 150, 155, 160, 166, 175, 177, 185, 200, 210, 220, 53 100, 115, 133, 137, 143, 150, 155, 160, 166, 175, 177, 185, 200, 210, 220,
52 221, 235, 237, 240, 255, 259, 266, 276, 293, 400, 1200, kInfiniteRatio, 54 221, 235, 237, 240, 255, 259, 266, 276, 293, 400, 1200, kInfiniteRatio,
53 }; 55 };
54 56
55 template<class T> // T has int width() & height() methods. 57 template<class T> // T has int width() & height() methods.
56 static void UmaHistogramAspectRatio(const char* name, const T& size) { 58 static void UmaHistogramAspectRatio(const char* name, const T& size) {
57 UMA_HISTOGRAM_CUSTOM_ENUMERATION( 59 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
58 name, 60 name,
59 // Intentionally use integer division to truncate the result. 61 // Intentionally use integer division to truncate the result.
60 size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio, 62 size.height() ? (size.width() * 100) / size.height() : kInfiniteRatio,
61 base::CustomHistogram::ArrayToCustomRanges( 63 base::CustomHistogram::ArrayToCustomRanges(
62 kCommonAspectRatios100, arraysize(kCommonAspectRatios100))); 64 kCommonAspectRatios100, arraysize(kCommonAspectRatios100)));
63 } 65 }
64 66
65 void VideoDecoderConfig::Initialize(VideoCodec codec, VideoFrame::Format format, 67 void VideoDecoderConfig::Initialize(VideoCodec codec,
68 VideoCodecProfile profile,
69 VideoFrame::Format format,
66 const gfx::Size& coded_size, 70 const gfx::Size& coded_size,
67 const gfx::Rect& visible_rect, 71 const gfx::Rect& visible_rect,
68 int frame_rate_numerator, 72 int frame_rate_numerator,
69 int frame_rate_denominator, 73 int frame_rate_denominator,
70 int aspect_ratio_numerator, 74 int aspect_ratio_numerator,
71 int aspect_ratio_denominator, 75 int aspect_ratio_denominator,
72 const uint8* extra_data, 76 const uint8* extra_data,
73 size_t extra_data_size) { 77 size_t extra_data_size) {
74 CHECK((extra_data_size != 0) == (extra_data != NULL)); 78 CHECK((extra_data_size != 0) == (extra_data != NULL));
75 79
76 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1); 80 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1);
81 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile,
82 VIDEO_CODEC_PROFILE_MAX + 1);
77 UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width()); 83 UMA_HISTOGRAM_COUNTS_10000("Media.VideoCodedWidth", coded_size.width());
78 UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size); 84 UmaHistogramAspectRatio("Media.VideoCodedAspectRatio", coded_size);
79 UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width()); 85 UMA_HISTOGRAM_COUNTS_10000("Media.VideoVisibleWidth", visible_rect.width());
80 UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect); 86 UmaHistogramAspectRatio("Media.VideoVisibleAspectRatio", visible_rect);
81 87
82 codec_ = codec; 88 codec_ = codec;
89 profile_ = profile;
83 format_ = format; 90 format_ = format;
84 coded_size_ = coded_size; 91 coded_size_ = coded_size;
85 visible_rect_ = visible_rect; 92 visible_rect_ = visible_rect;
86 frame_rate_numerator_ = frame_rate_numerator; 93 frame_rate_numerator_ = frame_rate_numerator;
87 frame_rate_denominator_ = frame_rate_denominator; 94 frame_rate_denominator_ = frame_rate_denominator;
88 aspect_ratio_numerator_ = aspect_ratio_numerator; 95 aspect_ratio_numerator_ = aspect_ratio_numerator;
89 aspect_ratio_denominator_ = aspect_ratio_denominator; 96 aspect_ratio_denominator_ = aspect_ratio_denominator;
90 extra_data_size_ = extra_data_size; 97 extra_data_size_ = extra_data_size;
91 98
92 if (extra_data_size_ > 0) { 99 if (extra_data_size_ > 0) {
(...skipping 25 matching lines...) Expand all
118 format_ != VideoFrame::INVALID && 125 format_ != VideoFrame::INVALID &&
119 frame_rate_numerator_ > 0 && 126 frame_rate_numerator_ > 0 &&
120 frame_rate_denominator_ > 0 && 127 frame_rate_denominator_ > 0 &&
121 aspect_ratio_numerator_ > 0 && 128 aspect_ratio_numerator_ > 0 &&
122 aspect_ratio_denominator_ > 0 && 129 aspect_ratio_denominator_ > 0 &&
123 natural_size_.width() <= Limits::kMaxDimension && 130 natural_size_.width() <= Limits::kMaxDimension &&
124 natural_size_.height() <= Limits::kMaxDimension && 131 natural_size_.height() <= Limits::kMaxDimension &&
125 natural_size_.GetArea() <= Limits::kMaxCanvas; 132 natural_size_.GetArea() <= Limits::kMaxCanvas;
126 } 133 }
127 134
135 std::string VideoDecoderConfig::AsHumanReadableString() const {
136 std::ostringstream s;
137 s << "codec: " << codec()
138 << " format: " << format()
139 << " coded size: [" << coded_size().width()
140 << "," << coded_size().height() << "]"
141 << " visible rect: [" << visible_rect().x()
142 << "," << visible_rect().y()
143 << "," << visible_rect().width()
144 << "," << visible_rect().height() << "]"
145 << " natural size: [" << natural_size().width()
146 << "," << natural_size().height() << "]"
147 << " frame rate: " << frame_rate_numerator()
148 << "/" << frame_rate_denominator()
149 << " aspect ratio: " << aspect_ratio_numerator()
150 << "/" << aspect_ratio_denominator();
151 return s.str();
152 }
153
128 VideoCodec VideoDecoderConfig::codec() const { 154 VideoCodec VideoDecoderConfig::codec() const {
129 return codec_; 155 return codec_;
130 } 156 }
131 157
158 VideoCodecProfile VideoDecoderConfig::profile() const {
159 return profile_;
160 }
161
132 VideoFrame::Format VideoDecoderConfig::format() const { 162 VideoFrame::Format VideoDecoderConfig::format() const {
133 return format_; 163 return format_;
134 } 164 }
135 165
136 gfx::Size VideoDecoderConfig::coded_size() const { 166 gfx::Size VideoDecoderConfig::coded_size() const {
137 return coded_size_; 167 return coded_size_;
138 } 168 }
139 169
140 gfx::Rect VideoDecoderConfig::visible_rect() const { 170 gfx::Rect VideoDecoderConfig::visible_rect() const {
141 return visible_rect_; 171 return visible_rect_;
(...skipping 21 matching lines...) Expand all
163 193
164 uint8* VideoDecoderConfig::extra_data() const { 194 uint8* VideoDecoderConfig::extra_data() const {
165 return extra_data_.get(); 195 return extra_data_.get();
166 } 196 }
167 197
168 size_t VideoDecoderConfig::extra_data_size() const { 198 size_t VideoDecoderConfig::extra_data_size() const {
169 return extra_data_size_; 199 return extra_data_size_;
170 } 200 }
171 201
172 } // namespace media 202 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698