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

Side by Side Diff: webrtc/common_video/i420_video_frame_unittest.cc

Issue 2477233004: Update VideoFrameBuffer-related methods to not use references to scoped_refptr. (Closed)
Patch Set: Created 4 years, 1 month 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 const int kSizeY = 400; 144 const int kSizeY = 400;
145 const int kSizeU = 100; 145 const int kSizeU = 100;
146 const int kSizeV = 100; 146 const int kSizeV = 100;
147 const VideoRotation kRotation = kVideoRotation_270; 147 const VideoRotation kRotation = kVideoRotation_270;
148 uint8_t buffer_y[kSizeY]; 148 uint8_t buffer_y[kSizeY];
149 uint8_t buffer_u[kSizeU]; 149 uint8_t buffer_u[kSizeU];
150 uint8_t buffer_v[kSizeV]; 150 uint8_t buffer_v[kSizeV];
151 memset(buffer_y, 16, kSizeY); 151 memset(buffer_y, 16, kSizeY);
152 memset(buffer_u, 8, kSizeU); 152 memset(buffer_u, 8, kSizeU);
153 memset(buffer_v, 4, kSizeV); 153 memset(buffer_v, 4, kSizeV);
154 // TODO(nisse): This new + Copy looks quite awkward. Consider adding
155 // an alternative I420Buffer::Create method.
154 VideoFrame frame1( 156 VideoFrame frame1(
155 I420Buffer::Copy(new rtc::RefCountedObject<webrtc::WrappedI420Buffer>( 157 I420Buffer::Copy(*new rtc::RefCountedObject<webrtc::WrappedI420Buffer>(
156 width, height, 158 width, height,
157 buffer_y, stride_y, 159 buffer_y, stride_y,
158 buffer_u, stride_u, 160 buffer_u, stride_u,
159 buffer_v, stride_v, 161 buffer_v, stride_v,
160 rtc::Callback0<void>([](){}))), 162 rtc::Callback0<void>([](){}))),
161 kRotation, 0); 163 kRotation, 0);
162 frame1.set_timestamp(timestamp); 164 frame1.set_timestamp(timestamp);
163 frame1.set_ntp_time_ms(ntp_time_ms); 165 frame1.set_ntp_time_ms(ntp_time_ms);
164 frame1.set_render_time_ms(render_time_ms); 166 frame1.set_render_time_ms(render_time_ms);
165 VideoFrame frame2(frame1); 167 VideoFrame frame2(frame1);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 frame.set_render_time_ms(20); 206 frame.set_render_time_ms(20);
205 EXPECT_EQ(20, frame.render_time_ms()); 207 EXPECT_EQ(20, frame.render_time_ms());
206 } 208 }
207 209
208 TEST(TestI420FrameBuffer, Copy) { 210 TEST(TestI420FrameBuffer, Copy) {
209 rtc::scoped_refptr<I420Buffer> buf1( 211 rtc::scoped_refptr<I420Buffer> buf1(
210 I420Buffer::Create(20, 10)); 212 I420Buffer::Create(20, 10));
211 memset(buf1->MutableDataY(), 1, 200); 213 memset(buf1->MutableDataY(), 1, 200);
212 memset(buf1->MutableDataU(), 2, 50); 214 memset(buf1->MutableDataU(), 2, 50);
213 memset(buf1->MutableDataV(), 3, 50); 215 memset(buf1->MutableDataV(), 3, 50);
214 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 216 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(*buf1);
215 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 217 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
216 } 218 }
217 219
218 TEST(TestI420FrameBuffer, Scale) { 220 TEST(TestI420FrameBuffer, Scale) {
219 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 221 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
220 222
221 // Pure scaling, no cropping. 223 // Pure scaling, no cropping.
222 rtc::scoped_refptr<I420Buffer> scaled_buffer( 224 rtc::scoped_refptr<I420Buffer> scaled_buffer(
223 I420Buffer::Create(150, 75)); 225 I420Buffer::Create(150, 75));
224 226
225 scaled_buffer->ScaleFrom(buf); 227 scaled_buffer->ScaleFrom(*buf);
226 CheckCrop(*scaled_buffer, 0.0, 0.0, 1.0, 1.0); 228 CheckCrop(*scaled_buffer, 0.0, 0.0, 1.0, 1.0);
227 } 229 }
228 230
229 TEST(TestI420FrameBuffer, CropXCenter) { 231 TEST(TestI420FrameBuffer, CropXCenter) {
230 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 232 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
231 233
232 // Pure center cropping, no scaling. 234 // Pure center cropping, no scaling.
233 rtc::scoped_refptr<I420Buffer> scaled_buffer( 235 rtc::scoped_refptr<I420Buffer> scaled_buffer(
234 I420Buffer::Create(100, 100)); 236 I420Buffer::Create(100, 100));
235 237
236 scaled_buffer->CropAndScaleFrom(buf, 50, 0, 100, 100); 238 scaled_buffer->CropAndScaleFrom(*buf, 50, 0, 100, 100);
237 CheckCrop(*scaled_buffer, 0.25, 0.0, 0.5, 1.0); 239 CheckCrop(*scaled_buffer, 0.25, 0.0, 0.5, 1.0);
238 } 240 }
239 241
240 TEST(TestI420FrameBuffer, CropXNotCenter) { 242 TEST(TestI420FrameBuffer, CropXNotCenter) {
241 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); 243 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
242 244
243 // Non-center cropping, no scaling. 245 // Non-center cropping, no scaling.
244 rtc::scoped_refptr<I420Buffer> scaled_buffer( 246 rtc::scoped_refptr<I420Buffer> scaled_buffer(
245 I420Buffer::Create(100, 100)); 247 I420Buffer::Create(100, 100));
246 248
247 scaled_buffer->CropAndScaleFrom(buf, 25, 0, 100, 100); 249 scaled_buffer->CropAndScaleFrom(*buf, 25, 0, 100, 100);
248 CheckCrop(*scaled_buffer, 0.125, 0.0, 0.5, 1.0); 250 CheckCrop(*scaled_buffer, 0.125, 0.0, 0.5, 1.0);
249 } 251 }
250 252
251 TEST(TestI420FrameBuffer, CropYCenter) { 253 TEST(TestI420FrameBuffer, CropYCenter) {
252 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); 254 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
253 255
254 // Pure center cropping, no scaling. 256 // Pure center cropping, no scaling.
255 rtc::scoped_refptr<I420Buffer> scaled_buffer( 257 rtc::scoped_refptr<I420Buffer> scaled_buffer(
256 I420Buffer::Create(100, 100)); 258 I420Buffer::Create(100, 100));
257 259
258 scaled_buffer->CropAndScaleFrom(buf, 0, 50, 100, 100); 260 scaled_buffer->CropAndScaleFrom(*buf, 0, 50, 100, 100);
259 CheckCrop(*scaled_buffer, 0.0, 0.25, 1.0, 0.5); 261 CheckCrop(*scaled_buffer, 0.0, 0.25, 1.0, 0.5);
260 } 262 }
261 263
262 TEST(TestI420FrameBuffer, CropYNotCenter) { 264 TEST(TestI420FrameBuffer, CropYNotCenter) {
263 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); 265 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
264 266
265 // Non-center cropping, no scaling. 267 // Non-center cropping, no scaling.
266 rtc::scoped_refptr<I420Buffer> scaled_buffer( 268 rtc::scoped_refptr<I420Buffer> scaled_buffer(
267 I420Buffer::Create(100, 100)); 269 I420Buffer::Create(100, 100));
268 270
269 scaled_buffer->CropAndScaleFrom(buf, 0, 25, 100, 100); 271 scaled_buffer->CropAndScaleFrom(*buf, 0, 25, 100, 100);
270 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.5); 272 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.5);
271 } 273 }
272 274
273 TEST(TestI420FrameBuffer, CropAndScale16x9) { 275 TEST(TestI420FrameBuffer, CropAndScale16x9) {
274 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480); 276 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480);
275 277
276 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. 278 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2.
277 rtc::scoped_refptr<I420Buffer> scaled_buffer( 279 rtc::scoped_refptr<I420Buffer> scaled_buffer(
278 I420Buffer::Create(320, 180)); 280 I420Buffer::Create(320, 180));
279 281
280 scaled_buffer->CropAndScaleFrom(buf); 282 scaled_buffer->CropAndScaleFrom(*buf);
281 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75); 283 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75);
282 } 284 }
283 285
284 class TestI420BufferRotate 286 class TestI420BufferRotate
285 : public ::testing::TestWithParam<webrtc::VideoRotation> {}; 287 : public ::testing::TestWithParam<webrtc::VideoRotation> {};
286 288
287 TEST_P(TestI420BufferRotate, Rotates) { 289 TEST_P(TestI420BufferRotate, Rotates) {
288 rtc::scoped_refptr<VideoFrameBuffer> buffer = CreateGradient(640, 480); 290 rtc::scoped_refptr<VideoFrameBuffer> buffer = CreateGradient(640, 480);
289 rtc::scoped_refptr<VideoFrameBuffer> rotated_buffer = 291 rtc::scoped_refptr<VideoFrameBuffer> rotated_buffer =
290 I420Buffer::Rotate(buffer, GetParam()); 292 I420Buffer::Rotate(buffer, GetParam());
291 CheckRotate(640, 480, GetParam(), *rotated_buffer); 293 CheckRotate(640, 480, GetParam(), *rotated_buffer);
292 } 294 }
293 295
294 INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate, 296 INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate,
295 ::testing::Values(kVideoRotation_0, 297 ::testing::Values(kVideoRotation_0,
296 kVideoRotation_90, 298 kVideoRotation_90,
297 kVideoRotation_180, 299 kVideoRotation_180,
298 kVideoRotation_270)); 300 kVideoRotation_270));
299 301
300 } // namespace webrtc 302 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/common_video/include/video_frame_buffer.h » ('j') | webrtc/common_video/include/video_frame_buffer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698