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/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/test/fake_texture_frame.h" | 17 #include "webrtc/test/fake_texture_frame.h" |
18 #include "webrtc/video_frame.h" | 18 #include "webrtc/video_frame.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 | 21 |
22 bool EqualPlane(const uint8_t* data1, | 22 bool EqualPlane(const uint8_t* data1, |
23 const uint8_t* data2, | 23 const uint8_t* data2, |
24 int stride, | 24 int stride, |
25 int width, | 25 int width, |
26 int height); | 26 int height); |
27 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); | |
28 int ExpectedSize(int plane_stride, int image_height, PlaneType type); | 27 int ExpectedSize(int plane_stride, int image_height, PlaneType type); |
29 | 28 |
30 TEST(TestVideoFrame, InitialValues) { | 29 TEST(TestVideoFrame, InitialValues) { |
31 VideoFrame frame; | 30 VideoFrame frame; |
32 EXPECT_TRUE(frame.IsZeroSize()); | 31 EXPECT_TRUE(frame.IsZeroSize()); |
33 EXPECT_EQ(kVideoRotation_0, frame.rotation()); | 32 EXPECT_EQ(kVideoRotation_0, frame.rotation()); |
34 } | 33 } |
35 | 34 |
36 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) { | 35 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) { |
37 VideoFrame frame; | 36 VideoFrame frame; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 memset(buffer_y, 16, kSizeY); | 94 memset(buffer_y, 16, kSizeY); |
96 memset(buffer_u, 8, kSizeU); | 95 memset(buffer_u, 8, kSizeU); |
97 memset(buffer_v, 4, kSizeV); | 96 memset(buffer_v, 4, kSizeV); |
98 VideoFrame big_frame; | 97 VideoFrame big_frame; |
99 EXPECT_EQ(0, | 98 EXPECT_EQ(0, |
100 big_frame.CreateFrame(buffer_y, buffer_u, buffer_v, | 99 big_frame.CreateFrame(buffer_y, buffer_u, buffer_v, |
101 width + 5, height + 5, stride_y + 5, | 100 width + 5, height + 5, stride_y + 5, |
102 stride_u, stride_v, kRotation)); | 101 stride_u, stride_v, kRotation)); |
103 // Frame of smaller dimensions. | 102 // Frame of smaller dimensions. |
104 EXPECT_EQ(0, small_frame.CopyFrame(big_frame)); | 103 EXPECT_EQ(0, small_frame.CopyFrame(big_frame)); |
105 EXPECT_TRUE(EqualFrames(small_frame, big_frame)); | 104 EXPECT_TRUE(small_frame.EqualsFrame(big_frame)); |
106 EXPECT_EQ(kRotation, small_frame.rotation()); | 105 EXPECT_EQ(kRotation, small_frame.rotation()); |
107 | 106 |
108 // Frame of larger dimensions. | 107 // Frame of larger dimensions. |
109 EXPECT_EQ(0, small_frame.CreateEmptyFrame(width, height, | 108 EXPECT_EQ(0, small_frame.CreateEmptyFrame(width, height, |
110 stride_y, stride_u, stride_v)); | 109 stride_y, stride_u, stride_v)); |
111 memset(small_frame.buffer(kYPlane), 1, small_frame.allocated_size(kYPlane)); | 110 memset(small_frame.buffer(kYPlane), 1, small_frame.allocated_size(kYPlane)); |
112 memset(small_frame.buffer(kUPlane), 2, small_frame.allocated_size(kUPlane)); | 111 memset(small_frame.buffer(kUPlane), 2, small_frame.allocated_size(kUPlane)); |
113 memset(small_frame.buffer(kVPlane), 3, small_frame.allocated_size(kVPlane)); | 112 memset(small_frame.buffer(kVPlane), 3, small_frame.allocated_size(kVPlane)); |
114 EXPECT_EQ(0, big_frame.CopyFrame(small_frame)); | 113 EXPECT_EQ(0, big_frame.CopyFrame(small_frame)); |
115 EXPECT_TRUE(EqualFrames(small_frame, big_frame)); | 114 EXPECT_TRUE(small_frame.EqualsFrame(big_frame)); |
116 } | 115 } |
117 | 116 |
118 TEST(TestVideoFrame, ShallowCopy) { | 117 TEST(TestVideoFrame, ShallowCopy) { |
119 uint32_t timestamp = 1; | 118 uint32_t timestamp = 1; |
120 int64_t ntp_time_ms = 2; | 119 int64_t ntp_time_ms = 2; |
121 int64_t render_time_ms = 3; | 120 int64_t render_time_ms = 3; |
122 int stride_y = 15; | 121 int stride_y = 15; |
123 int stride_u = 10; | 122 int stride_u = 10; |
124 int stride_v = 10; | 123 int stride_v = 10; |
125 int width = 15; | 124 int width = 15; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 EXPECT_EQ(100u, frame.timestamp()); | 249 EXPECT_EQ(100u, frame.timestamp()); |
251 EXPECT_EQ(10, frame.render_time_ms()); | 250 EXPECT_EQ(10, frame.render_time_ms()); |
252 EXPECT_EQ(handle, frame.native_handle()); | 251 EXPECT_EQ(handle, frame.native_handle()); |
253 | 252 |
254 frame.set_timestamp(200); | 253 frame.set_timestamp(200); |
255 EXPECT_EQ(200u, frame.timestamp()); | 254 EXPECT_EQ(200u, frame.timestamp()); |
256 frame.set_render_time_ms(20); | 255 frame.set_render_time_ms(20); |
257 EXPECT_EQ(20, frame.render_time_ms()); | 256 EXPECT_EQ(20, frame.render_time_ms()); |
258 } | 257 } |
259 | 258 |
260 bool EqualPlane(const uint8_t* data1, | |
261 const uint8_t* data2, | |
262 int stride, | |
263 int width, | |
264 int height) { | |
265 for (int y = 0; y < height; ++y) { | |
266 if (memcmp(data1, data2, width) != 0) | |
267 return false; | |
268 data1 += stride; | |
269 data2 += stride; | |
270 } | |
271 return true; | |
272 } | |
273 | |
274 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2) { | |
275 if ((frame1.width() != frame2.width()) || | |
276 (frame1.height() != frame2.height()) || | |
277 (frame1.stride(kYPlane) != frame2.stride(kYPlane)) || | |
278 (frame1.stride(kUPlane) != frame2.stride(kUPlane)) || | |
279 (frame1.stride(kVPlane) != frame2.stride(kVPlane)) || | |
280 (frame1.timestamp() != frame2.timestamp()) || | |
281 (frame1.ntp_time_ms() != frame2.ntp_time_ms()) || | |
282 (frame1.render_time_ms() != frame2.render_time_ms())) { | |
283 return false; | |
284 } | |
285 const int half_width = (frame1.width() + 1) / 2; | |
286 const int half_height = (frame1.height() + 1) / 2; | |
287 return EqualPlane(frame1.buffer(kYPlane), frame2.buffer(kYPlane), | |
288 frame1.stride(kYPlane), frame1.width(), frame1.height()) && | |
289 EqualPlane(frame1.buffer(kUPlane), frame2.buffer(kUPlane), | |
290 frame1.stride(kUPlane), half_width, half_height) && | |
291 EqualPlane(frame1.buffer(kVPlane), frame2.buffer(kVPlane), | |
292 frame1.stride(kVPlane), half_width, half_height); | |
293 } | |
294 | |
295 int ExpectedSize(int plane_stride, int image_height, PlaneType type) { | |
296 if (type == kYPlane) { | |
297 return (plane_stride * image_height); | |
298 } else { | |
299 int half_height = (image_height + 1) / 2; | |
300 return (plane_stride * half_height); | |
301 } | |
302 } | |
303 | |
304 } // namespace webrtc | 259 } // namespace webrtc |
OLD | NEW |