OLD | NEW |
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 namespace { | 22 namespace { |
23 | 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) { | 24 rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) { |
31 rtc::scoped_refptr<I420Buffer> buffer( | 25 rtc::scoped_refptr<I420Buffer> buffer( |
32 I420Buffer::Create(width, height)); | 26 I420Buffer::Create(width, height)); |
33 // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h | 27 // 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++) { | 28 for (int x = 0; x < width; x++) { |
35 for (int y = 0; y < height; y++) { | 29 for (int y = 0; y < height; y++) { |
36 buffer->MutableDataY()[x + y * width] = | 30 buffer->MutableDataY()[x + y * width] = |
37 128 * (x * height + y * width) / (width * height); | 31 128 * (x * height + y * width) / (width * height); |
38 } | 32 } |
39 } | 33 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_EQ(valid_value, frame.width()); | 97 EXPECT_EQ(valid_value, frame.width()); |
104 EXPECT_EQ(valid_value, frame.height()); | 98 EXPECT_EQ(valid_value, frame.height()); |
105 frame.set_timestamp(123u); | 99 frame.set_timestamp(123u); |
106 EXPECT_EQ(123u, frame.timestamp()); | 100 EXPECT_EQ(123u, frame.timestamp()); |
107 frame.set_ntp_time_ms(456); | 101 frame.set_ntp_time_ms(456); |
108 EXPECT_EQ(456, frame.ntp_time_ms()); | 102 EXPECT_EQ(456, frame.ntp_time_ms()); |
109 frame.set_render_time_ms(789); | 103 frame.set_render_time_ms(789); |
110 EXPECT_EQ(789, frame.render_time_ms()); | 104 EXPECT_EQ(789, frame.render_time_ms()); |
111 } | 105 } |
112 | 106 |
113 TEST(TestVideoFrame, SizeAllocation) { | |
114 VideoFrame frame; | |
115 frame. CreateEmptyFrame(10, 10, 12, 14, 220); | |
116 int height = frame.height(); | |
117 int stride_y = frame.video_frame_buffer()->StrideY(); | |
118 int stride_u = frame.video_frame_buffer()->StrideU(); | |
119 int stride_v = frame.video_frame_buffer()->StrideV(); | |
120 // Verify that allocated size was computed correctly. | |
121 EXPECT_EQ(ExpectedSize(stride_y, height, kYPlane), | |
122 frame.allocated_size(kYPlane)); | |
123 EXPECT_EQ(ExpectedSize(stride_u, height, kUPlane), | |
124 frame.allocated_size(kUPlane)); | |
125 EXPECT_EQ(ExpectedSize(stride_v, height, kVPlane), | |
126 frame.allocated_size(kVPlane)); | |
127 } | |
128 | |
129 TEST(TestVideoFrame, CopyFrame) { | 107 TEST(TestVideoFrame, CopyFrame) { |
130 uint32_t timestamp = 1; | 108 uint32_t timestamp = 1; |
131 int64_t ntp_time_ms = 2; | 109 int64_t ntp_time_ms = 2; |
132 int64_t render_time_ms = 3; | 110 int64_t render_time_ms = 3; |
133 int stride_y = 15; | 111 int stride_y = 15; |
134 int stride_u = 10; | 112 int stride_u = 10; |
135 int stride_v = 10; | 113 int stride_v = 10; |
136 int width = 15; | 114 int width = 15; |
137 int height = 15; | 115 int height = 15; |
138 // Copy frame. | 116 // Copy frame. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 frame2.CreateFrame(buffer_y, buffer_u, buffer_v, | 225 frame2.CreateFrame(buffer_y, buffer_u, buffer_v, |
248 width, height, stride_y, stride_uv, stride_uv, | 226 width, height, stride_y, stride_uv, stride_uv, |
249 kVideoRotation_0); | 227 kVideoRotation_0); |
250 // Expect exactly the same pixel data. | 228 // Expect exactly the same pixel data. |
251 EXPECT_TRUE(test::EqualPlane(buffer_y, frame2.video_frame_buffer()->DataY(), | 229 EXPECT_TRUE(test::EqualPlane(buffer_y, frame2.video_frame_buffer()->DataY(), |
252 stride_y, 15, 15)); | 230 stride_y, 15, 15)); |
253 EXPECT_TRUE(test::EqualPlane(buffer_u, frame2.video_frame_buffer()->DataU(), | 231 EXPECT_TRUE(test::EqualPlane(buffer_u, frame2.video_frame_buffer()->DataU(), |
254 stride_uv, 8, 8)); | 232 stride_uv, 8, 8)); |
255 EXPECT_TRUE(test::EqualPlane(buffer_v, frame2.video_frame_buffer()->DataV(), | 233 EXPECT_TRUE(test::EqualPlane(buffer_v, frame2.video_frame_buffer()->DataV(), |
256 stride_uv, 8, 8)); | 234 stride_uv, 8, 8)); |
257 | |
258 // Compare size. | |
259 EXPECT_LE(kSizeY, frame2.allocated_size(kYPlane)); | |
260 EXPECT_LE(kSizeUv, frame2.allocated_size(kUPlane)); | |
261 EXPECT_LE(kSizeUv, frame2.allocated_size(kVPlane)); | |
262 } | 235 } |
263 | 236 |
264 TEST(TestVideoFrame, FailToReuseAllocation) { | 237 TEST(TestVideoFrame, FailToReuseAllocation) { |
265 VideoFrame frame1; | 238 VideoFrame frame1; |
266 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); | 239 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); |
267 const uint8_t* y = frame1.video_frame_buffer()->DataY(); | 240 const uint8_t* y = frame1.video_frame_buffer()->DataY(); |
268 const uint8_t* u = frame1.video_frame_buffer()->DataU(); | 241 const uint8_t* u = frame1.video_frame_buffer()->DataU(); |
269 const uint8_t* v = frame1.video_frame_buffer()->DataV(); | 242 const uint8_t* v = frame1.video_frame_buffer()->DataV(); |
270 // Make a shallow copy of |frame1|. | 243 // Make a shallow copy of |frame1|. |
271 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); | 244 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 335 |
363 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. | 336 // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. |
364 rtc::scoped_refptr<I420Buffer> scaled_buffer( | 337 rtc::scoped_refptr<I420Buffer> scaled_buffer( |
365 I420Buffer::Create(320, 180)); | 338 I420Buffer::Create(320, 180)); |
366 | 339 |
367 scaled_buffer->CropAndScaleFrom(buf); | 340 scaled_buffer->CropAndScaleFrom(buf); |
368 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75); | 341 CheckCrop(scaled_buffer, 0.0, 0.125, 1.0, 0.75); |
369 } | 342 } |
370 | 343 |
371 } // namespace webrtc | 344 } // namespace webrtc |
OLD | NEW |