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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 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
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "media/base/video_frame.h" 6 #include "media/base/video_frame.h"
7 #include "media/base/video_util.h" 7 #include "media/base/video_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 13 matching lines...) Expand all
24 int y_stride, int u_stride, int v_stride) { 24 int y_stride, int u_stride, int v_stride) {
25 EXPECT_GE(y_stride, width); 25 EXPECT_GE(y_stride, width);
26 EXPECT_GE(u_stride, width / 2); 26 EXPECT_GE(u_stride, width / 2);
27 EXPECT_GE(v_stride, width / 2); 27 EXPECT_GE(v_stride, width / 2);
28 28
29 height_ = height; 29 height_ = height;
30 y_stride_ = y_stride; 30 y_stride_ = y_stride;
31 u_stride_ = u_stride; 31 u_stride_ = u_stride;
32 v_stride_ = v_stride; 32 v_stride_ = v_stride;
33 33
34 y_plane_.reset(new uint8[y_stride * height]); 34 y_plane_.reset(new uint8_t[y_stride * height]);
35 u_plane_.reset(new uint8[u_stride * height / 2]); 35 u_plane_.reset(new uint8_t[u_stride * height / 2]);
36 v_plane_.reset(new uint8[v_stride * height / 2]); 36 v_plane_.reset(new uint8_t[v_stride * height / 2]);
37 } 37 }
38 38
39 void CreateDestinationFrame(int width, int height) { 39 void CreateDestinationFrame(int width, int height) {
40 gfx::Size size(width, height); 40 gfx::Size size(width, height);
41 destination_frame_ = VideoFrame::CreateFrame( 41 destination_frame_ = VideoFrame::CreateFrame(
42 PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, base::TimeDelta()); 42 PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, base::TimeDelta());
43 } 43 }
44 44
45 private: 45 private:
46 scoped_ptr<uint8[]> y_plane_; 46 scoped_ptr<uint8_t[]> y_plane_;
47 scoped_ptr<uint8[]> u_plane_; 47 scoped_ptr<uint8_t[]> u_plane_;
48 scoped_ptr<uint8[]> v_plane_; 48 scoped_ptr<uint8_t[]> v_plane_;
49 49
50 int height_; 50 int height_;
51 int y_stride_; 51 int y_stride_;
52 int u_stride_; 52 int u_stride_;
53 int v_stride_; 53 int v_stride_;
54 54
55 scoped_refptr<VideoFrame> destination_frame_; 55 scoped_refptr<VideoFrame> destination_frame_;
56 56
57 DISALLOW_COPY_AND_ASSIGN(VideoUtilTest); 57 DISALLOW_COPY_AND_ASSIGN(VideoUtilTest);
58 }; 58 };
(...skipping 22 matching lines...) Expand all
81 EXPECT_EQ(gfx::Size(569, 240), GetNaturalSize(visible_size, 16, 9)); 81 EXPECT_EQ(gfx::Size(569, 240), GetNaturalSize(visible_size, 16, 9));
82 EXPECT_EQ(gfx::Size(180, 240), GetNaturalSize(visible_size, 9, 16)); 82 EXPECT_EQ(gfx::Size(180, 240), GetNaturalSize(visible_size, 9, 16));
83 83
84 // Test some random ratios. 84 // Test some random ratios.
85 EXPECT_EQ(gfx::Size(495, 240), GetNaturalSize(visible_size, 17, 11)); 85 EXPECT_EQ(gfx::Size(495, 240), GetNaturalSize(visible_size, 17, 11));
86 EXPECT_EQ(gfx::Size(207, 240), GetNaturalSize(visible_size, 11, 17)); 86 EXPECT_EQ(gfx::Size(207, 240), GetNaturalSize(visible_size, 11, 17));
87 } 87 }
88 88
89 namespace { 89 namespace {
90 90
91 uint8 src6x4[] = { 91 uint8_t src6x4[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
92 0, 1, 2, 3, 4, 5, 92 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
93 6, 7, 8, 9, 10, 11,
94 12, 13, 14, 15, 16, 17,
95 18, 19, 20, 21, 22, 23
96 };
97 93
98 // Target images, name pattern target_rotation_flipV_flipH. 94 // Target images, name pattern target_rotation_flipV_flipH.
99 uint8* target6x4_0_n_n = src6x4; 95 uint8_t* target6x4_0_n_n = src6x4;
100 96
101 uint8 target6x4_0_n_y[] = { 97 uint8_t target6x4_0_n_y[] = {5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6,
102 5, 4, 3, 2, 1, 0, 98 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18};
103 11, 10, 9, 8, 7, 6,
104 17, 16, 15, 14, 13, 12,
105 23, 22, 21, 20, 19, 18
106 };
107 99
108 uint8 target6x4_0_y_n[] = { 100 uint8_t target6x4_0_y_n[] = {18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,
109 18, 19, 20, 21, 22, 23, 101 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5};
110 12, 13, 14, 15, 16, 17,
111 6, 7, 8, 9, 10, 11,
112 0, 1, 2, 3, 4, 5
113 };
114 102
115 uint8 target6x4_0_y_y[] = { 103 uint8_t target6x4_0_y_y[] = {23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12,
116 23, 22, 21, 20, 19, 18, 104 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
117 17, 16, 15, 14, 13, 12,
118 11, 10, 9, 8, 7, 6,
119 5, 4, 3, 2, 1, 0
120 };
121 105
122 uint8 target6x4_90_n_n[] = { 106 uint8_t target6x4_90_n_n[] = {255, 19, 13, 7, 1, 255, 255, 20, 14, 8, 2, 255,
123 255, 19, 13, 7, 1, 255, 107 255, 21, 15, 9, 3, 255, 255, 22, 16, 10, 4, 255};
124 255, 20, 14, 8, 2, 255,
125 255, 21, 15, 9, 3, 255,
126 255, 22, 16, 10, 4, 255
127 };
128 108
129 uint8 target6x4_90_n_y[] = { 109 uint8_t target6x4_90_n_y[] = {255, 1, 7, 13, 19, 255, 255, 2, 8, 14, 20, 255,
130 255, 1, 7, 13, 19, 255, 110 255, 3, 9, 15, 21, 255, 255, 4, 10, 16, 22, 255};
131 255, 2, 8, 14, 20, 255,
132 255, 3, 9, 15, 21, 255,
133 255, 4, 10, 16, 22, 255
134 };
135 111
136 uint8 target6x4_90_y_n[] = { 112 uint8_t target6x4_90_y_n[] = {255, 22, 16, 10, 4, 255, 255, 21, 15, 9, 3, 255,
137 255, 22, 16, 10, 4, 255, 113 255, 20, 14, 8, 2, 255, 255, 19, 13, 7, 1, 255};
138 255, 21, 15, 9, 3, 255,
139 255, 20, 14, 8, 2, 255,
140 255, 19, 13, 7, 1, 255
141 };
142 114
143 uint8 target6x4_90_y_y[] = { 115 uint8_t target6x4_90_y_y[] = {255, 4, 10, 16, 22, 255, 255, 3, 9, 15, 21, 255,
144 255, 4, 10, 16, 22, 255, 116 255, 2, 8, 14, 20, 255, 255, 1, 7, 13, 19, 255};
145 255, 3, 9, 15, 21, 255,
146 255, 2, 8, 14, 20, 255,
147 255, 1, 7, 13, 19, 255
148 };
149 117
150 uint8* target6x4_180_n_n = target6x4_0_y_y; 118 uint8_t* target6x4_180_n_n = target6x4_0_y_y;
151 uint8* target6x4_180_n_y = target6x4_0_y_n; 119 uint8_t* target6x4_180_n_y = target6x4_0_y_n;
152 uint8* target6x4_180_y_n = target6x4_0_n_y; 120 uint8_t* target6x4_180_y_n = target6x4_0_n_y;
153 uint8* target6x4_180_y_y = target6x4_0_n_n; 121 uint8_t* target6x4_180_y_y = target6x4_0_n_n;
154 122
155 uint8* target6x4_270_n_n = target6x4_90_y_y; 123 uint8_t* target6x4_270_n_n = target6x4_90_y_y;
156 uint8* target6x4_270_n_y = target6x4_90_y_n; 124 uint8_t* target6x4_270_n_y = target6x4_90_y_n;
157 uint8* target6x4_270_y_n = target6x4_90_n_y; 125 uint8_t* target6x4_270_y_n = target6x4_90_n_y;
158 uint8* target6x4_270_y_y = target6x4_90_n_n; 126 uint8_t* target6x4_270_y_y = target6x4_90_n_n;
159 127
160 uint8 src4x6[] = { 128 uint8_t src4x6[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
161 0, 1, 2, 3, 129 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23};
162 4, 5, 6, 7,
163 8, 9, 10, 11,
164 12, 13, 14, 15,
165 16, 17, 18, 19,
166 20, 21, 22, 23
167 };
168 130
169 uint8* target4x6_0_n_n = src4x6; 131 uint8_t* target4x6_0_n_n = src4x6;
170 132
171 uint8 target4x6_0_n_y[] = { 133 uint8_t target4x6_0_n_y[] = {3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8,
172 3, 2, 1, 0, 134 15, 14, 13, 12, 19, 18, 17, 16, 23, 22, 21, 20};
173 7, 6, 5, 4,
174 11, 10, 9, 8,
175 15, 14, 13, 12,
176 19, 18, 17, 16,
177 23, 22, 21, 20
178 };
179 135
180 uint8 target4x6_0_y_n[] = { 136 uint8_t target4x6_0_y_n[] = {20, 21, 22, 23, 16, 17, 18, 19, 12, 13, 14, 15,
181 20, 21, 22, 23, 137 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3};
182 16, 17, 18, 19,
183 12, 13, 14, 15,
184 8, 9, 10, 11,
185 4, 5, 6, 7,
186 0, 1, 2, 3
187 };
188 138
189 uint8 target4x6_0_y_y[] = { 139 uint8_t target4x6_0_y_y[] = {23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12,
190 23, 22, 21, 20, 140 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
191 19, 18, 17, 16,
192 15, 14, 13, 12,
193 11, 10, 9, 8,
194 7, 6, 5, 4,
195 3, 2, 1, 0
196 };
197 141
198 uint8 target4x6_90_n_n[] = { 142 uint8_t target4x6_90_n_n[] = {255, 255, 255, 255, 16, 12, 8, 4,
199 255, 255, 255, 255, 143 17, 13, 9, 5, 18, 14, 10, 6,
200 16, 12, 8, 4, 144 19, 15, 11, 7, 255, 255, 255, 255};
201 17, 13, 9, 5,
202 18, 14, 10, 6,
203 19, 15, 11, 7,
204 255, 255, 255, 255
205 };
206 145
207 uint8 target4x6_90_n_y[] = { 146 uint8_t target4x6_90_n_y[] = {255, 255, 255, 255, 4, 8, 12, 16,
208 255, 255, 255, 255, 147 5, 9, 13, 17, 6, 10, 14, 18,
209 4, 8, 12, 16, 148 7, 11, 15, 19, 255, 255, 255, 255};
210 5, 9, 13, 17,
211 6, 10, 14, 18,
212 7, 11, 15, 19,
213 255, 255, 255, 255
214 };
215 149
216 uint8 target4x6_90_y_n[] = { 150 uint8_t target4x6_90_y_n[] = {255, 255, 255, 255, 19, 15, 11, 7,
217 255, 255, 255, 255, 151 18, 14, 10, 6, 17, 13, 9, 5,
218 19, 15, 11, 7, 152 16, 12, 8, 4, 255, 255, 255, 255};
219 18, 14, 10, 6,
220 17, 13, 9, 5,
221 16, 12, 8, 4,
222 255, 255, 255, 255
223 };
224 153
225 uint8 target4x6_90_y_y[] = { 154 uint8_t target4x6_90_y_y[] = {255, 255, 255, 255, 7, 11, 15, 19,
226 255, 255, 255, 255, 155 6, 10, 14, 18, 5, 9, 13, 17,
227 7, 11, 15, 19, 156 4, 8, 12, 16, 255, 255, 255, 255};
228 6, 10, 14, 18,
229 5, 9, 13, 17,
230 4, 8, 12, 16,
231 255, 255, 255, 255
232 };
233 157
234 uint8* target4x6_180_n_n = target4x6_0_y_y; 158 uint8_t* target4x6_180_n_n = target4x6_0_y_y;
235 uint8* target4x6_180_n_y = target4x6_0_y_n; 159 uint8_t* target4x6_180_n_y = target4x6_0_y_n;
236 uint8* target4x6_180_y_n = target4x6_0_n_y; 160 uint8_t* target4x6_180_y_n = target4x6_0_n_y;
237 uint8* target4x6_180_y_y = target4x6_0_n_n; 161 uint8_t* target4x6_180_y_y = target4x6_0_n_n;
238 162
239 uint8* target4x6_270_n_n = target4x6_90_y_y; 163 uint8_t* target4x6_270_n_n = target4x6_90_y_y;
240 uint8* target4x6_270_n_y = target4x6_90_y_n; 164 uint8_t* target4x6_270_n_y = target4x6_90_y_n;
241 uint8* target4x6_270_y_n = target4x6_90_n_y; 165 uint8_t* target4x6_270_y_n = target4x6_90_n_y;
242 uint8* target4x6_270_y_y = target4x6_90_n_n; 166 uint8_t* target4x6_270_y_y = target4x6_90_n_n;
243 167
244 struct VideoRotationTestData { 168 struct VideoRotationTestData {
245 uint8* src; 169 uint8_t* src;
246 uint8* target; 170 uint8_t* target;
247 int width; 171 int width;
248 int height; 172 int height;
249 int rotation; 173 int rotation;
250 bool flip_vert; 174 bool flip_vert;
251 bool flip_horiz; 175 bool flip_horiz;
252 }; 176 };
253 177
254 const VideoRotationTestData kVideoRotationTestData[] = { 178 const VideoRotationTestData kVideoRotationTestData[] = {
255 { src6x4, target6x4_0_n_n, 6, 4, 0, false, false }, 179 { src6x4, target6x4_0_n_n, 6, 4, 0, false, false },
256 { src6x4, target6x4_0_n_y, 6, 4, 0, false, true }, 180 { src6x4, target6x4_0_n_y, 6, 4, 0, false, true },
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 { src4x6, target4x6_270_y_n, 4, 6, 270, true, false }, 216 { src4x6, target4x6_270_y_n, 4, 6, 270, true, false },
293 { src4x6, target4x6_270_y_y, 4, 6, 270, true, true } 217 { src4x6, target4x6_270_y_y, 4, 6, 270, true, true }
294 }; 218 };
295 219
296 } // namespace 220 } // namespace
297 221
298 class VideoUtilRotationTest 222 class VideoUtilRotationTest
299 : public testing::TestWithParam<VideoRotationTestData> { 223 : public testing::TestWithParam<VideoRotationTestData> {
300 public: 224 public:
301 VideoUtilRotationTest() { 225 VideoUtilRotationTest() {
302 dest_.reset(new uint8[GetParam().width * GetParam().height]); 226 dest_.reset(new uint8_t[GetParam().width * GetParam().height]);
303 } 227 }
304 228
305 virtual ~VideoUtilRotationTest() {} 229 virtual ~VideoUtilRotationTest() {}
306 230
307 uint8* dest_plane() { return dest_.get(); } 231 uint8_t* dest_plane() { return dest_.get(); }
308 232
309 private: 233 private:
310 scoped_ptr<uint8[]> dest_; 234 scoped_ptr<uint8_t[]> dest_;
311 235
312 DISALLOW_COPY_AND_ASSIGN(VideoUtilRotationTest); 236 DISALLOW_COPY_AND_ASSIGN(VideoUtilRotationTest);
313 }; 237 };
314 238
315 TEST_P(VideoUtilRotationTest, Rotate) { 239 TEST_P(VideoUtilRotationTest, Rotate) {
316 int rotation = GetParam().rotation; 240 int rotation = GetParam().rotation;
317 EXPECT_TRUE((rotation >= 0) && (rotation < 360) && (rotation % 90 == 0)); 241 EXPECT_TRUE((rotation >= 0) && (rotation < 360) && (rotation % 90 == 0));
318 242
319 int size = GetParam().width * GetParam().height; 243 int size = GetParam().width * GetParam().height;
320 uint8* dest = dest_plane(); 244 uint8_t* dest = dest_plane();
321 memset(dest, 255, size); 245 memset(dest, 255, size);
322 246
323 RotatePlaneByPixels(GetParam().src, dest, GetParam().width, 247 RotatePlaneByPixels(GetParam().src, dest, GetParam().width,
324 GetParam().height, rotation, 248 GetParam().height, rotation,
325 GetParam().flip_vert, GetParam().flip_horiz); 249 GetParam().flip_vert, GetParam().flip_horiz);
326 250
327 EXPECT_EQ(memcmp(dest, GetParam().target, size), 0); 251 EXPECT_EQ(memcmp(dest, GetParam().target, size), 0);
328 } 252 }
329 253
330 INSTANTIATE_TEST_CASE_P(, VideoUtilRotationTest, 254 INSTANTIATE_TEST_CASE_P(, VideoUtilRotationTest,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 inside ? 0x03 : 0x80); 351 inside ? 0x03 : 0x80);
428 } 352 }
429 } 353 }
430 } 354 }
431 } 355 }
432 } 356 }
433 } 357 }
434 } 358 }
435 359
436 } // namespace media 360 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_util.cc ('k') | media/base/yuv_convert.h » ('j') | media/cdm/stub/stub_cdm.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698