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

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

Issue 1973873003: Delete AndroidVideoCapturer::FrameFactory. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Move code to AndroidVideoCapturerJni. Make Matrix a class. Created 4 years, 7 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
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
11 #include <math.h> 11 #include <math.h>
12 #include <string.h> 12 #include <string.h>
13 13
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/base/bind.h" 15 #include "webrtc/base/bind.h"
16 #include "webrtc/test/fake_texture_frame.h" 16 #include "webrtc/test/fake_texture_frame.h"
17 #include "webrtc/test/frame_utils.h" 17 #include "webrtc/test/frame_utils.h"
18 #include "webrtc/video_frame.h" 18 #include "webrtc/video_frame.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 21
22 int ExpectedSize(int plane_stride, int image_height, PlaneType type); 22 namespace {
23
24 int ExpectedSize(int plane_stride, int image_height, PlaneType type) {
25 if (type == kYPlane)
26 return plane_stride * image_height;
27 return plane_stride * ((image_height + 1) / 2);
28 }
29
30 rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) {
31 rtc::scoped_refptr<I420Buffer> buffer(
32 new rtc::RefCountedObject<I420Buffer>(width, height));
33 // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h
34 for (int x = 0; x < width; x++) {
35 for (int y = 0; y < height; y++) {
36 buffer->MutableDataY()[x + y * width] =
37 128 * (x * height + y * width) / (width * height);
38 }
39 }
40 int chroma_width = (width + 1) / 2;
41 int chroma_height = (height + 1) / 2;
42 for (int x = 0; x < chroma_width; x++) {
43 for (int y = 0; y < chroma_height; y++) {
44 buffer->MutableDataU()[x + y * chroma_width] =
45 255 * x / (chroma_width - 1);
46 buffer->MutableDataV()[x + y * chroma_width] =
47 255 * y / (chroma_height - 1);
48 }
49 }
50 return buffer;
51 }
52
53 void CheckCrop(webrtc::VideoFrameBuffer* frame,
54 double offset_x,
55 double offset_y,
56 double rel_width,
57 double rel_height) {
58 int width = frame->width();
59 int height = frame->height();
60 // Check that pixel values in the corners match the gradient used
61 // for initialization.
62 for (int i = 0; i < 2; i++)
63 for (int j = 0; j < 2; j++) {
64 // Pixel coordinates of the corner.
65 int x = i * (width - 1);
66 int y = j * (height - 1);
67 // Relative coordinates, range 0.0 - 1.0 correspond to the
68 // size of the uncropped input frame.
69 double orig_x = offset_x + i * rel_width;
70 double orig_y = offset_y + j * rel_height;
71
72 EXPECT_NEAR(frame->DataY()[x + y * frame->StrideY()] / 256.0,
73 (orig_x + orig_y) / 2, 0.02);
74 EXPECT_NEAR(frame->DataU()[x / 2 + (y / 2) * frame->StrideU()] / 256.0,
75 orig_x, 0.02);
76 EXPECT_NEAR(frame->DataV()[x / 2 + (y / 2) * frame->StrideV()] / 256.0,
77 orig_y, 0.02);
78 }
79 }
80 } // namespace
23 81
24 TEST(TestVideoFrame, InitialValues) { 82 TEST(TestVideoFrame, InitialValues) {
25 VideoFrame frame; 83 VideoFrame frame;
26 EXPECT_TRUE(frame.IsZeroSize()); 84 EXPECT_TRUE(frame.IsZeroSize());
27 EXPECT_EQ(kVideoRotation_0, frame.rotation()); 85 EXPECT_EQ(kVideoRotation_0, frame.rotation());
28 } 86 }
29 87
30 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) { 88 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) {
31 VideoFrame frame; 89 VideoFrame frame;
32 VideoFrame frame2; 90 VideoFrame frame2;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 TEST(TestI420FrameBuffer, Copy) { 301 TEST(TestI420FrameBuffer, Copy) {
244 rtc::scoped_refptr<I420Buffer> buf1( 302 rtc::scoped_refptr<I420Buffer> buf1(
245 new rtc::RefCountedObject<I420Buffer>(20, 10)); 303 new rtc::RefCountedObject<I420Buffer>(20, 10));
246 memset(buf1->MutableDataY(), 1, 200); 304 memset(buf1->MutableDataY(), 1, 200);
247 memset(buf1->MutableDataU(), 2, 50); 305 memset(buf1->MutableDataU(), 2, 50);
248 memset(buf1->MutableDataV(), 3, 50); 306 memset(buf1->MutableDataV(), 3, 50);
249 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1); 307 rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(buf1);
250 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); 308 EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2));
251 } 309 }
252 310
311 TEST(TestI420FrameBuffer, Scale) {
312 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
313
314 // Pure scaling, no cropping.
315 rtc::scoped_refptr<I420Buffer> scaled =
316 I420Buffer::CropAndScale(buf, 0, 0, 200, 100, 150, 75);
317 CheckCrop(scaled, 0.0, 0.0, 1.0, 1.0);
318 }
319
320 TEST(TestI420FrameBuffer, CropXCenter) {
321 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
322
323 // Pure center cropping, no scaling.
324 rtc::scoped_refptr<I420Buffer> scaled =
325 I420Buffer::CropAndScale(buf, 50, 0, 100, 100, 100, 100);
326 CheckCrop(scaled, 0.25, 0.0, 0.5, 1.0);
327 }
328
329 TEST(TestI420FrameBuffer, CropXNotCenter) {
330 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100);
331
332 // Non-center cropping, no scaling.
333 rtc::scoped_refptr<I420Buffer> scaled =
334 I420Buffer::CropAndScale(buf, 25, 0, 100, 100, 100, 100);
335 CheckCrop(scaled, 0.125, 0.0, 0.5, 1.0);
336 }
337
338 TEST(TestI420FrameBuffer, CropYCenter) {
339 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
340
341 // Pure center cropping, no scaling.
342 rtc::scoped_refptr<I420Buffer> scaled =
343 I420Buffer::CropAndScale(buf, 0, 50, 100, 100, 100, 100);
344 CheckCrop(scaled, 0.0, 0.25, 1.0, 0.5);
345 }
346
347 TEST(TestI420FrameBuffer, CropYNotCenter) {
348 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200);
349
350 // Non-center cropping, no scaling.
351 rtc::scoped_refptr<I420Buffer> scaled =
352 I420Buffer::CropAndScale(buf, 0, 25, 100, 100, 100, 100);
353 CheckCrop(scaled, 0.0, 0.125, 1.0, 0.5);
354 }
355
356 TEST(TestI420FrameBuffer, CropAndScale16x9) {
357 rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480);
358
359 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2.
360 rtc::scoped_refptr<I420Buffer> scaled =
361 I420Buffer::CropAndScale(buf, 0, 60, 640, 360, 320, 180);
362 CheckCrop(scaled, 0.0, 0.125, 1.0, 0.75);
363 }
364
253 } // namespace webrtc 365 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698