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 "webrtc/video_frame.h" | 11 #include "webrtc/video_frame.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/bind.h" | 17 #include "webrtc/base/bind.h" |
18 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
| 19 #include "webrtc/test/fake_texture_frame.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 class NativeHandleImpl { | |
23 public: | |
24 NativeHandleImpl() : no_longer_needed_(false) {} | |
25 virtual ~NativeHandleImpl() {} | |
26 bool no_longer_needed() const { return no_longer_needed_; } | |
27 void SetNoLongerNeeded() { no_longer_needed_ = true; } | |
28 | |
29 private: | |
30 bool no_longer_needed_; | |
31 }; | |
32 | |
33 bool EqualPlane(const uint8_t* data1, | 23 bool EqualPlane(const uint8_t* data1, |
34 const uint8_t* data2, | 24 const uint8_t* data2, |
35 int stride, | 25 int stride, |
36 int width, | 26 int width, |
37 int height); | 27 int height); |
38 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 28 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
39 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2); | |
40 int ExpectedSize(int plane_stride, int image_height, PlaneType type); | 29 int ExpectedSize(int plane_stride, int image_height, PlaneType type); |
41 | 30 |
42 TEST(TestVideoFrame, InitialValues) { | 31 TEST(TestVideoFrame, InitialValues) { |
43 VideoFrame frame; | 32 VideoFrame frame; |
44 EXPECT_TRUE(frame.IsZeroSize()); | 33 EXPECT_TRUE(frame.IsZeroSize()); |
45 EXPECT_EQ(kVideoRotation_0, frame.rotation()); | 34 EXPECT_EQ(kVideoRotation_0, frame.rotation()); |
46 } | 35 } |
47 | 36 |
48 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) { | 37 TEST(TestVideoFrame, CopiesInitialFrameWithoutCrashing) { |
49 VideoFrame frame; | 38 VideoFrame frame; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 const uint8_t* v = frame1.buffer(kVPlane); | 236 const uint8_t* v = frame1.buffer(kVPlane); |
248 // Make a shallow copy of |frame1|. | 237 // Make a shallow copy of |frame1|. |
249 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); | 238 VideoFrame frame2(frame1.video_frame_buffer(), 0, 0, kVideoRotation_0); |
250 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); | 239 frame1.CreateEmptyFrame(640, 320, 640, 320, 320); |
251 EXPECT_NE(y, frame1.buffer(kYPlane)); | 240 EXPECT_NE(y, frame1.buffer(kYPlane)); |
252 EXPECT_NE(u, frame1.buffer(kUPlane)); | 241 EXPECT_NE(u, frame1.buffer(kUPlane)); |
253 EXPECT_NE(v, frame1.buffer(kVPlane)); | 242 EXPECT_NE(v, frame1.buffer(kVPlane)); |
254 } | 243 } |
255 | 244 |
256 TEST(TestVideoFrame, TextureInitialValues) { | 245 TEST(TestVideoFrame, TextureInitialValues) { |
257 NativeHandleImpl handle; | 246 test::FakeNativeHandle* handle = new test::FakeNativeHandle(); |
258 VideoFrame frame(&handle, 640, 480, 100, 10, webrtc::kVideoRotation_0, | 247 VideoFrame frame = test::CreateFakeNativeHandleFrame( |
259 rtc::Callback0<void>()); | 248 handle, 640, 480, 100, 10, webrtc::kVideoRotation_0); |
260 EXPECT_EQ(640, frame.width()); | 249 EXPECT_EQ(640, frame.width()); |
261 EXPECT_EQ(480, frame.height()); | 250 EXPECT_EQ(480, frame.height()); |
262 EXPECT_EQ(100u, frame.timestamp()); | 251 EXPECT_EQ(100u, frame.timestamp()); |
263 EXPECT_EQ(10, frame.render_time_ms()); | 252 EXPECT_EQ(10, frame.render_time_ms()); |
264 EXPECT_EQ(&handle, frame.native_handle()); | 253 EXPECT_EQ(handle, frame.native_handle()); |
265 | 254 |
266 frame.set_timestamp(200); | 255 frame.set_timestamp(200); |
267 EXPECT_EQ(200u, frame.timestamp()); | 256 EXPECT_EQ(200u, frame.timestamp()); |
268 frame.set_render_time_ms(20); | 257 frame.set_render_time_ms(20); |
269 EXPECT_EQ(20, frame.render_time_ms()); | 258 EXPECT_EQ(20, frame.render_time_ms()); |
270 } | 259 } |
271 | 260 |
272 TEST(TestVideoFrame, NoLongerNeeded) { | |
273 NativeHandleImpl handle; | |
274 ASSERT_FALSE(handle.no_longer_needed()); | |
275 VideoFrame* frame = | |
276 new VideoFrame(&handle, 640, 480, 100, 200, webrtc::kVideoRotation_0, | |
277 rtc::Bind(&NativeHandleImpl::SetNoLongerNeeded, &handle)); | |
278 EXPECT_FALSE(handle.no_longer_needed()); | |
279 delete frame; | |
280 EXPECT_TRUE(handle.no_longer_needed()); | |
281 } | |
282 | |
283 bool EqualPlane(const uint8_t* data1, | 261 bool EqualPlane(const uint8_t* data1, |
284 const uint8_t* data2, | 262 const uint8_t* data2, |
285 int stride, | 263 int stride, |
286 int width, | 264 int width, |
287 int height) { | 265 int height) { |
288 for (int y = 0; y < height; ++y) { | 266 for (int y = 0; y < height; ++y) { |
289 if (memcmp(data1, data2, width) != 0) | 267 if (memcmp(data1, data2, width) != 0) |
290 return false; | 268 return false; |
291 data1 += stride; | 269 data1 += stride; |
292 data2 += stride; | 270 data2 += stride; |
(...skipping 15 matching lines...) Expand all Loading... |
308 const int half_width = (frame1.width() + 1) / 2; | 286 const int half_width = (frame1.width() + 1) / 2; |
309 const int half_height = (frame1.height() + 1) / 2; | 287 const int half_height = (frame1.height() + 1) / 2; |
310 return EqualPlane(frame1.buffer(kYPlane), frame2.buffer(kYPlane), | 288 return EqualPlane(frame1.buffer(kYPlane), frame2.buffer(kYPlane), |
311 frame1.stride(kYPlane), frame1.width(), frame1.height()) && | 289 frame1.stride(kYPlane), frame1.width(), frame1.height()) && |
312 EqualPlane(frame1.buffer(kUPlane), frame2.buffer(kUPlane), | 290 EqualPlane(frame1.buffer(kUPlane), frame2.buffer(kUPlane), |
313 frame1.stride(kUPlane), half_width, half_height) && | 291 frame1.stride(kUPlane), half_width, half_height) && |
314 EqualPlane(frame1.buffer(kVPlane), frame2.buffer(kVPlane), | 292 EqualPlane(frame1.buffer(kVPlane), frame2.buffer(kVPlane), |
315 frame1.stride(kVPlane), half_width, half_height); | 293 frame1.stride(kVPlane), half_width, half_height); |
316 } | 294 } |
317 | 295 |
318 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2) { | |
319 return ((frame1.native_handle() == frame2.native_handle()) && | |
320 (frame1.width() == frame2.width()) && | |
321 (frame1.height() == frame2.height()) && | |
322 (frame1.timestamp() == frame2.timestamp()) && | |
323 (frame1.render_time_ms() == frame2.render_time_ms())); | |
324 } | |
325 | |
326 int ExpectedSize(int plane_stride, int image_height, PlaneType type) { | 296 int ExpectedSize(int plane_stride, int image_height, PlaneType type) { |
327 if (type == kYPlane) { | 297 if (type == kYPlane) { |
328 return (plane_stride * image_height); | 298 return (plane_stride * image_height); |
329 } else { | 299 } else { |
330 int half_height = (image_height + 1) / 2; | 300 int half_height = (image_height + 1) / 2; |
331 return (plane_stride * half_height); | 301 return (plane_stride * half_height); |
332 } | 302 } |
333 } | 303 } |
334 | 304 |
335 } // namespace webrtc | 305 } // namespace webrtc |
OLD | NEW |