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

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

Issue 2906053002: Update I420Buffer to new VideoFrameBuffer interface (Closed)
Patch Set: Make const versions of Get functions Created 3 years, 6 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
(...skipping 15 matching lines...) Expand all
26 rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) { 26 rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) {
27 rtc::scoped_refptr<I420Buffer> buffer( 27 rtc::scoped_refptr<I420Buffer> buffer(
28 I420Buffer::Create(width, height)); 28 I420Buffer::Create(width, height));
29 // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h 29 // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h
30 for (int x = 0; x < width; x++) { 30 for (int x = 0; x < width; x++) {
31 for (int y = 0; y < height; y++) { 31 for (int y = 0; y < height; y++) {
32 buffer->MutableDataY()[x + y * width] = 32 buffer->MutableDataY()[x + y * width] =
33 128 * (x * height + y * width) / (width * height); 33 128 * (x * height + y * width) / (width * height);
34 } 34 }
35 } 35 }
36 int chroma_width = (width + 1) / 2; 36 int chroma_width = buffer->ChromaWidth();
37 int chroma_height = (height + 1) / 2; 37 int chroma_height = buffer->ChromaHeight();
38 for (int x = 0; x < chroma_width; x++) { 38 for (int x = 0; x < chroma_width; x++) {
39 for (int y = 0; y < chroma_height; y++) { 39 for (int y = 0; y < chroma_height; y++) {
40 buffer->MutableDataU()[x + y * chroma_width] = 40 buffer->MutableDataU()[x + y * chroma_width] =
41 255 * x / (chroma_width - 1); 41 255 * x / (chroma_width - 1);
42 buffer->MutableDataV()[x + y * chroma_width] = 42 buffer->MutableDataV()[x + y * chroma_width] =
43 255 * y / (chroma_height - 1); 43 255 * y / (chroma_height - 1);
44 } 44 }
45 } 45 }
46 return buffer; 46 return buffer;
47 } 47 }
48 48
49 // The offsets and sizes describe the rectangle extracted from the 49 // The offsets and sizes describe the rectangle extracted from the
50 // original (gradient) frame, in relative coordinates where the 50 // original (gradient) frame, in relative coordinates where the
51 // original frame correspond to the unit square, 0.0 <= x, y < 1.0. 51 // original frame correspond to the unit square, 0.0 <= x, y < 1.0.
52 void CheckCrop(const webrtc::VideoFrameBuffer& frame, 52 void CheckCrop(const webrtc::I420BufferInterface& frame,
53 double offset_x, 53 double offset_x,
54 double offset_y, 54 double offset_y,
55 double rel_width, 55 double rel_width,
56 double rel_height) { 56 double rel_height) {
57 int width = frame.width(); 57 int width = frame.width();
58 int height = frame.height(); 58 int height = frame.height();
59 // Check that pixel values in the corners match the gradient used 59 // Check that pixel values in the corners match the gradient used
60 // for initialization. 60 // for initialization.
61 for (int i = 0; i < 2; i++) { 61 for (int i = 0; i < 2; i++) {
62 for (int j = 0; j < 2; j++) { 62 for (int j = 0; j < 2; j++) {
63 // Pixel coordinates of the corner. 63 // Pixel coordinates of the corner.
64 int x = i * (width - 1); 64 int x = i * (width - 1);
65 int y = j * (height - 1); 65 int y = j * (height - 1);
66 // Relative coordinates, range 0.0 - 1.0 correspond to the 66 // Relative coordinates, range 0.0 - 1.0 correspond to the
67 // size of the uncropped input frame. 67 // size of the uncropped input frame.
68 double orig_x = offset_x + i * rel_width; 68 double orig_x = offset_x + i * rel_width;
69 double orig_y = offset_y + j * rel_height; 69 double orig_y = offset_y + j * rel_height;
70 70
71 EXPECT_NEAR(frame.DataY()[x + y * frame.StrideY()] / 256.0, 71 EXPECT_NEAR(frame.DataY()[x + y * frame.StrideY()] / 256.0,
72 (orig_x + orig_y) / 2, 0.02); 72 (orig_x + orig_y) / 2, 0.02);
73 EXPECT_NEAR(frame.DataU()[x / 2 + (y / 2) * frame.StrideU()] / 256.0, 73 EXPECT_NEAR(frame.DataU()[x / 2 + (y / 2) * frame.StrideU()] / 256.0,
74 orig_x, 0.02); 74 orig_x, 0.02);
75 EXPECT_NEAR(frame.DataV()[x / 2 + (y / 2) * frame.StrideV()] / 256.0, 75 EXPECT_NEAR(frame.DataV()[x / 2 + (y / 2) * frame.StrideV()] / 256.0,
76 orig_y, 0.02); 76 orig_y, 0.02);
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 void CheckRotate(int width, int height, webrtc::VideoRotation rotation, 81 void CheckRotate(int width,
82 const webrtc::VideoFrameBuffer& rotated) { 82 int height,
83 webrtc::VideoRotation rotation,
84 const webrtc::I420BufferInterface& rotated) {
83 int rotated_width = width; 85 int rotated_width = width;
84 int rotated_height = height; 86 int rotated_height = height;
85 87
86 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { 88 if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) {
87 std::swap(rotated_width, rotated_height); 89 std::swap(rotated_width, rotated_height);
88 } 90 }
89 EXPECT_EQ(rotated_width, rotated.width()); 91 EXPECT_EQ(rotated_width, rotated.width());
90 EXPECT_EQ(rotated_height, rotated.height()); 92 EXPECT_EQ(rotated_height, rotated.height());
91 93
92 // Clock-wise order (with 0,0 at top-left) 94 // Clock-wise order (with 0,0 at top-left)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 buffer_y, stride_y, 155 buffer_y, stride_y,
154 buffer_u, stride_u, 156 buffer_u, stride_u,
155 buffer_v, stride_v), 157 buffer_v, stride_v),
156 kRotation, 0); 158 kRotation, 0);
157 frame1.set_timestamp(timestamp); 159 frame1.set_timestamp(timestamp);
158 frame1.set_ntp_time_ms(ntp_time_ms); 160 frame1.set_ntp_time_ms(ntp_time_ms);
159 frame1.set_timestamp_us(timestamp_us); 161 frame1.set_timestamp_us(timestamp_us);
160 VideoFrame frame2(frame1); 162 VideoFrame frame2(frame1);
161 163
162 EXPECT_EQ(frame1.video_frame_buffer(), frame2.video_frame_buffer()); 164 EXPECT_EQ(frame1.video_frame_buffer(), frame2.video_frame_buffer());
163 EXPECT_EQ(frame1.video_frame_buffer()->DataY(), 165 rtc::scoped_refptr<I420BufferInterface> yuv1 =
164 frame2.video_frame_buffer()->DataY()); 166 frame1.video_frame_buffer()->GetI420();
165 EXPECT_EQ(frame1.video_frame_buffer()->DataU(), 167 rtc::scoped_refptr<I420BufferInterface> yuv2 =
166 frame2.video_frame_buffer()->DataU()); 168 frame2.video_frame_buffer()->GetI420();
167 EXPECT_EQ(frame1.video_frame_buffer()->DataV(), 169 EXPECT_EQ(yuv1->DataY(), yuv2->DataY());
168 frame2.video_frame_buffer()->DataV()); 170 EXPECT_EQ(yuv1->DataU(), yuv2->DataU());
171 EXPECT_EQ(yuv1->DataV(), yuv2->DataV());
169 172
170 EXPECT_EQ(frame2.timestamp(), frame1.timestamp()); 173 EXPECT_EQ(frame2.timestamp(), frame1.timestamp());
171 EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms()); 174 EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms());
172 EXPECT_EQ(frame2.timestamp_us(), frame1.timestamp_us()); 175 EXPECT_EQ(frame2.timestamp_us(), frame1.timestamp_us());
173 EXPECT_EQ(frame2.rotation(), frame1.rotation()); 176 EXPECT_EQ(frame2.rotation(), frame1.rotation());
174 177
175 frame2.set_timestamp(timestamp + 1); 178 frame2.set_timestamp(timestamp + 1);
176 frame2.set_ntp_time_ms(ntp_time_ms + 1); 179 frame2.set_ntp_time_ms(ntp_time_ms + 1);
177 frame2.set_timestamp_us(timestamp_us + 1); 180 frame2.set_timestamp_us(timestamp_us + 1);
178 frame2.set_rotation(kVideoRotation_90); 181 frame2.set_rotation(kVideoRotation_90);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 I420Buffer::Create(320, 180)); 276 I420Buffer::Create(320, 180));
274 277
275 scaled_buffer->CropAndScaleFrom(*buf); 278 scaled_buffer->CropAndScaleFrom(*buf);
276 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75); 279 CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75);
277 } 280 }
278 281
279 class TestI420BufferRotate 282 class TestI420BufferRotate
280 : public ::testing::TestWithParam<webrtc::VideoRotation> {}; 283 : public ::testing::TestWithParam<webrtc::VideoRotation> {};
281 284
282 TEST_P(TestI420BufferRotate, Rotates) { 285 TEST_P(TestI420BufferRotate, Rotates) {
283 rtc::scoped_refptr<VideoFrameBuffer> buffer = CreateGradient(640, 480); 286 rtc::scoped_refptr<I420BufferInterface> buffer = CreateGradient(640, 480);
284 rtc::scoped_refptr<VideoFrameBuffer> rotated_buffer = 287 rtc::scoped_refptr<I420BufferInterface> rotated_buffer =
285 I420Buffer::Rotate(*buffer, GetParam()); 288 I420Buffer::Rotate(*buffer, GetParam());
286 CheckRotate(640, 480, GetParam(), *rotated_buffer); 289 CheckRotate(640, 480, GetParam(), *rotated_buffer);
287 } 290 }
288 291
289 INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate, 292 INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate,
290 ::testing::Values(kVideoRotation_0, 293 ::testing::Values(kVideoRotation_0,
291 kVideoRotation_90, 294 kVideoRotation_90,
292 kVideoRotation_180, 295 kVideoRotation_180,
293 kVideoRotation_270)); 296 kVideoRotation_270));
294 297
295 } // namespace webrtc 298 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/i420_buffer_pool_unittest.cc ('k') | webrtc/common_video/libyuv/include/webrtc_libyuv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698