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/base/video_decoder_config.h" | 5 #include "media/base/video_decoder_config.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 VideoDecoderConfig::VideoDecoderConfig() | 12 VideoDecoderConfig::VideoDecoderConfig() |
13 : codec_(kUnknownVideoCodec), | 13 : codec_(kUnknownVideoCodec), |
14 profile_(VIDEO_CODEC_PROFILE_UNKNOWN), | 14 profile_(VIDEO_CODEC_PROFILE_UNKNOWN), |
15 format_(VideoFrame::INVALID), | 15 format_(VideoFrame::INVALID), |
16 extra_data_size_(0) { | 16 extra_data_size_(0) { |
17 } | 17 } |
18 | 18 |
19 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, | 19 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, |
20 VideoCodecProfile profile, | 20 VideoCodecProfile profile, |
21 VideoFrame::Format format, | 21 VideoFrame::Format format, |
22 const gfx::Size& coded_size, | 22 const gfx::Size& coded_size, |
23 const gfx::Rect& visible_rect, | 23 const gfx::Rect& visible_rect, |
24 const gfx::Size& natural_size, | 24 const gfx::Size& natural_size, |
25 const uint8* extra_data, | 25 const uint8* extra_data, |
26 size_t extra_data_size) { | 26 size_t extra_data_size, |
| 27 bool is_encrypted) { |
27 Initialize(codec, profile, format, coded_size, visible_rect, natural_size, | 28 Initialize(codec, profile, format, coded_size, visible_rect, natural_size, |
28 extra_data, extra_data_size, true); | 29 extra_data, extra_data_size, is_encrypted, true); |
29 } | 30 } |
30 | 31 |
31 VideoDecoderConfig::~VideoDecoderConfig() {} | 32 VideoDecoderConfig::~VideoDecoderConfig() {} |
32 | 33 |
33 // Some videos just want to watch the world burn, with a height of 0; cap the | 34 // Some videos just want to watch the world burn, with a height of 0; cap the |
34 // "infinite" aspect ratio resulting. | 35 // "infinite" aspect ratio resulting. |
35 static const int kInfiniteRatio = 99999; | 36 static const int kInfiniteRatio = 99999; |
36 | 37 |
37 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming | 38 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming |
38 // video sizes. These were taken on 20111103 from | 39 // video sizes. These were taken on 20111103 from |
(...skipping 14 matching lines...) Expand all Loading... |
53 } | 54 } |
54 | 55 |
55 void VideoDecoderConfig::Initialize(VideoCodec codec, | 56 void VideoDecoderConfig::Initialize(VideoCodec codec, |
56 VideoCodecProfile profile, | 57 VideoCodecProfile profile, |
57 VideoFrame::Format format, | 58 VideoFrame::Format format, |
58 const gfx::Size& coded_size, | 59 const gfx::Size& coded_size, |
59 const gfx::Rect& visible_rect, | 60 const gfx::Rect& visible_rect, |
60 const gfx::Size& natural_size, | 61 const gfx::Size& natural_size, |
61 const uint8* extra_data, | 62 const uint8* extra_data, |
62 size_t extra_data_size, | 63 size_t extra_data_size, |
| 64 bool is_encrypted, |
63 bool record_stats) { | 65 bool record_stats) { |
64 CHECK((extra_data_size != 0) == (extra_data != NULL)); | 66 CHECK((extra_data_size != 0) == (extra_data != NULL)); |
65 | 67 |
66 if (record_stats) { | 68 if (record_stats) { |
67 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1); | 69 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodec", codec, kVideoCodecMax + 1); |
68 // Drop UNKNOWN because U_H_E() uses one bucket for all values less than 1. | 70 // Drop UNKNOWN because U_H_E() uses one bucket for all values less than 1. |
69 if (profile >= 0) { | 71 if (profile >= 0) { |
70 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile, | 72 UMA_HISTOGRAM_ENUMERATION("Media.VideoCodecProfile", profile, |
71 VIDEO_CODEC_PROFILE_MAX + 1); | 73 VIDEO_CODEC_PROFILE_MAX + 1); |
72 } | 74 } |
(...skipping 10 matching lines...) Expand all Loading... |
83 visible_rect_ = visible_rect; | 85 visible_rect_ = visible_rect; |
84 natural_size_ = natural_size; | 86 natural_size_ = natural_size; |
85 extra_data_size_ = extra_data_size; | 87 extra_data_size_ = extra_data_size; |
86 | 88 |
87 if (extra_data_size_ > 0) { | 89 if (extra_data_size_ > 0) { |
88 extra_data_.reset(new uint8[extra_data_size_]); | 90 extra_data_.reset(new uint8[extra_data_size_]); |
89 memcpy(extra_data_.get(), extra_data, extra_data_size_); | 91 memcpy(extra_data_.get(), extra_data, extra_data_size_); |
90 } else { | 92 } else { |
91 extra_data_.reset(); | 93 extra_data_.reset(); |
92 } | 94 } |
| 95 |
| 96 is_encrypted_ = is_encrypted; |
93 } | 97 } |
94 | 98 |
95 void VideoDecoderConfig::CopyFrom(const VideoDecoderConfig& video_config) { | 99 void VideoDecoderConfig::CopyFrom(const VideoDecoderConfig& video_config) { |
96 Initialize(video_config.codec(), | 100 Initialize(video_config.codec(), |
97 video_config.profile(), | 101 video_config.profile(), |
98 video_config.format(), | 102 video_config.format(), |
99 video_config.coded_size(), | 103 video_config.coded_size(), |
100 video_config.visible_rect(), | 104 video_config.visible_rect(), |
101 video_config.natural_size(), | 105 video_config.natural_size(), |
102 video_config.extra_data(), | 106 video_config.extra_data(), |
103 video_config.extra_data_size(), | 107 video_config.extra_data_size(), |
| 108 video_config.is_encrypted(), |
104 false); | 109 false); |
105 } | 110 } |
106 | 111 |
107 bool VideoDecoderConfig::IsValidConfig() const { | 112 bool VideoDecoderConfig::IsValidConfig() const { |
108 return codec_ != kUnknownVideoCodec && | 113 return codec_ != kUnknownVideoCodec && |
109 natural_size_.width() > 0 && | 114 natural_size_.width() > 0 && |
110 natural_size_.height() > 0 && | 115 natural_size_.height() > 0 && |
111 VideoFrame::IsValidConfig(format_, visible_rect().size(), natural_size_); | 116 VideoFrame::IsValidConfig(format_, visible_rect().size(), natural_size_); |
112 } | 117 } |
113 | 118 |
114 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const { | 119 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const { |
115 return ((codec() == config.codec()) && | 120 return ((codec() == config.codec()) && |
116 (format() == config.format()) && | 121 (format() == config.format()) && |
117 (profile() == config.profile()) && | 122 (profile() == config.profile()) && |
118 (coded_size() == config.coded_size()) && | 123 (coded_size() == config.coded_size()) && |
119 (visible_rect() == config.visible_rect()) && | 124 (visible_rect() == config.visible_rect()) && |
120 (natural_size() == config.natural_size()) && | 125 (natural_size() == config.natural_size()) && |
121 (extra_data_size() == config.extra_data_size()) && | 126 (extra_data_size() == config.extra_data_size()) && |
122 (!extra_data() || !memcmp(extra_data(), config.extra_data(), | 127 (!extra_data() || !memcmp(extra_data(), config.extra_data(), |
123 extra_data_size()))); | 128 extra_data_size())) && |
| 129 (is_encrypted() == config.is_encrypted())); |
124 } | 130 } |
125 | 131 |
126 std::string VideoDecoderConfig::AsHumanReadableString() const { | 132 std::string VideoDecoderConfig::AsHumanReadableString() const { |
127 std::ostringstream s; | 133 std::ostringstream s; |
128 s << "codec: " << codec() | 134 s << "codec: " << codec() |
129 << " format: " << format() | 135 << " format: " << format() |
130 << " coded size: [" << coded_size().width() | 136 << " coded size: [" << coded_size().width() |
131 << "," << coded_size().height() << "]" | 137 << "," << coded_size().height() << "]" |
132 << " visible rect: [" << visible_rect().x() | 138 << " visible rect: [" << visible_rect().x() |
133 << "," << visible_rect().y() | 139 << "," << visible_rect().y() |
134 << "," << visible_rect().width() | 140 << "," << visible_rect().width() |
135 << "," << visible_rect().height() << "]" | 141 << "," << visible_rect().height() << "]" |
136 << " natural size: [" << natural_size().width() | 142 << " natural size: [" << natural_size().width() |
137 << "," << natural_size().height() << "]"; | 143 << "," << natural_size().height() << "]" |
| 144 << " encryption: [" << (is_encrypted() ? "true" : "false") << "]"; |
138 return s.str(); | 145 return s.str(); |
139 } | 146 } |
140 | 147 |
141 VideoCodec VideoDecoderConfig::codec() const { | 148 VideoCodec VideoDecoderConfig::codec() const { |
142 return codec_; | 149 return codec_; |
143 } | 150 } |
144 | 151 |
145 VideoCodecProfile VideoDecoderConfig::profile() const { | 152 VideoCodecProfile VideoDecoderConfig::profile() const { |
146 return profile_; | 153 return profile_; |
147 } | 154 } |
(...skipping 15 matching lines...) Expand all Loading... |
163 } | 170 } |
164 | 171 |
165 uint8* VideoDecoderConfig::extra_data() const { | 172 uint8* VideoDecoderConfig::extra_data() const { |
166 return extra_data_.get(); | 173 return extra_data_.get(); |
167 } | 174 } |
168 | 175 |
169 size_t VideoDecoderConfig::extra_data_size() const { | 176 size_t VideoDecoderConfig::extra_data_size() const { |
170 return extra_data_size_; | 177 return extra_data_size_; |
171 } | 178 } |
172 | 179 |
| 180 bool VideoDecoderConfig::is_encrypted() const { |
| 181 return is_encrypted_; |
| 182 } |
| 183 |
173 } // namespace media | 184 } // namespace media |
OLD | NEW |