OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/media/base/videoframe_unittest.h" | 15 #include "webrtc/media/base/videoframe_unittest.h" |
16 #include "webrtc/media/engine/webrtcvideoframe.h" | 16 #include "webrtc/media/engine/webrtcvideoframe.h" |
17 #include "webrtc/test/fake_texture_frame.h" | 17 #include "webrtc/test/fake_texture_frame.h" |
18 | 18 |
19 namespace { | 19 namespace cricket { |
20 | 20 |
21 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { | 21 class WebRtcVideoFrameTest : public VideoFrameTest<WebRtcVideoFrame> { |
22 public: | 22 public: |
23 WebRtcVideoTestFrame() {} | 23 WebRtcVideoFrameTest() {} |
24 WebRtcVideoTestFrame( | |
25 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | |
26 int64_t time_stamp_ns, | |
27 webrtc::VideoRotation rotation) | |
28 : WebRtcVideoFrame(buffer, time_stamp_ns, rotation) {} | |
29 | |
30 // The ApplyRotationToFrame test needs this as a public method. | |
31 using cricket::WebRtcVideoFrame::set_rotation; | |
32 | |
33 virtual VideoFrame* CreateEmptyFrame(int w, | |
34 int h, | |
35 int64_t time_stamp) const override { | |
36 rtc::scoped_refptr<webrtc::I420Buffer> buffer( | |
37 new rtc::RefCountedObject<webrtc::I420Buffer>(w, h)); | |
38 buffer->SetToBlack(); | |
39 return new WebRtcVideoTestFrame( | |
40 buffer, time_stamp, webrtc::kVideoRotation_0); | |
41 } | |
42 }; | |
43 | |
44 } // namespace | |
45 | |
46 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { | |
47 public: | |
48 WebRtcVideoFrameTest() { | |
49 } | |
50 | 24 |
51 void TestInit(int cropped_width, int cropped_height, | 25 void TestInit(int cropped_width, int cropped_height, |
52 webrtc::VideoRotation frame_rotation, | 26 webrtc::VideoRotation frame_rotation, |
53 bool apply_rotation) { | 27 bool apply_rotation) { |
54 const int frame_width = 1920; | 28 const int frame_width = 1920; |
55 const int frame_height = 1080; | 29 const int frame_height = 1080; |
56 | 30 |
57 // Build the CapturedFrame. | 31 // Build the CapturedFrame. |
58 cricket::CapturedFrame captured_frame; | 32 CapturedFrame captured_frame; |
59 captured_frame.fourcc = cricket::FOURCC_I420; | 33 captured_frame.fourcc = FOURCC_I420; |
60 captured_frame.time_stamp = rtc::TimeNanos(); | 34 captured_frame.time_stamp = rtc::TimeNanos(); |
61 captured_frame.rotation = frame_rotation; | 35 captured_frame.rotation = frame_rotation; |
62 captured_frame.width = frame_width; | 36 captured_frame.width = frame_width; |
63 captured_frame.height = frame_height; | 37 captured_frame.height = frame_height; |
64 captured_frame.data_size = (frame_width * frame_height) + | 38 captured_frame.data_size = (frame_width * frame_height) + |
65 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; | 39 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; |
66 std::unique_ptr<uint8_t[]> captured_frame_buffer( | 40 std::unique_ptr<uint8_t[]> captured_frame_buffer( |
67 new uint8_t[captured_frame.data_size]); | 41 new uint8_t[captured_frame.data_size]); |
68 // Initialize memory to satisfy DrMemory tests. | 42 // Initialize memory to satisfy DrMemory tests. |
69 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); | 43 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); |
70 captured_frame.data = captured_frame_buffer.get(); | 44 captured_frame.data = captured_frame_buffer.get(); |
71 | 45 |
72 // Create the new frame from the CapturedFrame. | 46 // Create the new frame from the CapturedFrame. |
73 cricket::WebRtcVideoFrame frame; | 47 WebRtcVideoFrame frame; |
74 EXPECT_TRUE( | 48 EXPECT_TRUE( |
75 frame.Init(&captured_frame, cropped_width, cropped_height, | 49 frame.Init(&captured_frame, cropped_width, cropped_height, |
76 apply_rotation)); | 50 apply_rotation)); |
77 | 51 |
78 // Verify the new frame. | 52 // Verify the new frame. |
79 EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec, | 53 EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec, |
80 frame.timestamp_us()); | 54 frame.timestamp_us()); |
81 if (apply_rotation) | 55 if (apply_rotation) |
82 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); | 56 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); |
83 else | 57 else |
84 EXPECT_EQ(frame_rotation, frame.rotation()); | 58 EXPECT_EQ(frame_rotation, frame.rotation()); |
85 // If |apply_rotation| and the frame rotation is 90 or 270, width and | 59 // If |apply_rotation| and the frame rotation is 90 or 270, width and |
86 // height are flipped. | 60 // height are flipped. |
87 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 | 61 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 |
88 || frame_rotation == webrtc::kVideoRotation_270)) { | 62 || frame_rotation == webrtc::kVideoRotation_270)) { |
89 EXPECT_EQ(cropped_width, frame.height()); | 63 EXPECT_EQ(cropped_width, frame.height()); |
90 EXPECT_EQ(cropped_height, frame.width()); | 64 EXPECT_EQ(cropped_height, frame.width()); |
91 } else { | 65 } else { |
92 EXPECT_EQ(cropped_width, frame.width()); | 66 EXPECT_EQ(cropped_width, frame.width()); |
93 EXPECT_EQ(cropped_height, frame.height()); | 67 EXPECT_EQ(cropped_height, frame.height()); |
94 } | 68 } |
95 } | 69 } |
| 70 |
| 71 void SetFrameRotation(WebRtcVideoFrame* frame, |
| 72 webrtc::VideoRotation rotation) { |
| 73 frame->rotation_ = rotation; |
| 74 } |
96 }; | 75 }; |
97 | 76 |
98 #define TEST_WEBRTCVIDEOFRAME(X) TEST_F(WebRtcVideoFrameTest, X) { \ | 77 #define TEST_WEBRTCVIDEOFRAME(X) \ |
99 VideoFrameTest<cricket::WebRtcVideoFrame>::X(); \ | 78 TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest<WebRtcVideoFrame>::X(); } |
100 } | |
101 | 79 |
102 TEST_WEBRTCVIDEOFRAME(ConstructI420) | 80 TEST_WEBRTCVIDEOFRAME(ConstructI420) |
103 TEST_WEBRTCVIDEOFRAME(ConstructI422) | 81 TEST_WEBRTCVIDEOFRAME(ConstructI422) |
104 TEST_WEBRTCVIDEOFRAME(ConstructYuy2) | 82 TEST_WEBRTCVIDEOFRAME(ConstructYuy2) |
105 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Unaligned) | 83 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Unaligned) |
106 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Wide) | 84 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Wide) |
107 TEST_WEBRTCVIDEOFRAME(ConstructYV12) | 85 TEST_WEBRTCVIDEOFRAME(ConstructYV12) |
108 TEST_WEBRTCVIDEOFRAME(ConstructUyvy) | 86 TEST_WEBRTCVIDEOFRAME(ConstructUyvy) |
109 TEST_WEBRTCVIDEOFRAME(ConstructM420) | 87 TEST_WEBRTCVIDEOFRAME(ConstructM420) |
110 TEST_WEBRTCVIDEOFRAME(ConstructNV21) | 88 TEST_WEBRTCVIDEOFRAME(ConstructNV21) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 TestInit(640, 360, webrtc::kVideoRotation_90, false); | 252 TestInit(640, 360, webrtc::kVideoRotation_90, false); |
275 } | 253 } |
276 | 254 |
277 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { | 255 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { |
278 webrtc::test::FakeNativeHandle* dummy_handle = | 256 webrtc::test::FakeNativeHandle* dummy_handle = |
279 new webrtc::test::FakeNativeHandle(); | 257 new webrtc::test::FakeNativeHandle(); |
280 webrtc::NativeHandleBuffer* buffer = | 258 webrtc::NativeHandleBuffer* buffer = |
281 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 259 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
282 dummy_handle, 640, 480); | 260 dummy_handle, 640, 480); |
283 // Timestamp is converted from ns to us, so last three digits are lost. | 261 // Timestamp is converted from ns to us, so last three digits are lost. |
284 cricket::WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); | 262 WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); |
285 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); | 263 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); |
286 EXPECT_EQ(640, frame.width()); | 264 EXPECT_EQ(640, frame.width()); |
287 EXPECT_EQ(480, frame.height()); | 265 EXPECT_EQ(480, frame.height()); |
288 EXPECT_EQ(20000, frame.GetTimeStamp()); | 266 EXPECT_EQ(20000, frame.GetTimeStamp()); |
289 EXPECT_EQ(20, frame.timestamp_us()); | 267 EXPECT_EQ(20, frame.timestamp_us()); |
290 frame.set_timestamp_us(40); | 268 frame.set_timestamp_us(40); |
291 EXPECT_EQ(40000, frame.GetTimeStamp()); | 269 EXPECT_EQ(40000, frame.GetTimeStamp()); |
292 EXPECT_EQ(40, frame.timestamp_us()); | 270 EXPECT_EQ(40, frame.timestamp_us()); |
293 } | 271 } |
294 | 272 |
295 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { | 273 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { |
296 webrtc::test::FakeNativeHandle* dummy_handle = | 274 webrtc::test::FakeNativeHandle* dummy_handle = |
297 new webrtc::test::FakeNativeHandle(); | 275 new webrtc::test::FakeNativeHandle(); |
298 webrtc::NativeHandleBuffer* buffer = | 276 webrtc::NativeHandleBuffer* buffer = |
299 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 277 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
300 dummy_handle, 640, 480); | 278 dummy_handle, 640, 480); |
301 // Timestamp is converted from ns to us, so last three digits are lost. | 279 // Timestamp is converted from ns to us, so last three digits are lost. |
302 cricket::WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0); | 280 WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0); |
303 cricket::VideoFrame* frame2 = frame1.Copy(); | 281 VideoFrame* frame2 = frame1.Copy(); |
304 EXPECT_EQ(frame1.video_frame_buffer()->native_handle(), | 282 EXPECT_EQ(frame1.video_frame_buffer()->native_handle(), |
305 frame2->video_frame_buffer()->native_handle()); | 283 frame2->video_frame_buffer()->native_handle()); |
306 EXPECT_EQ(frame1.width(), frame2->width()); | 284 EXPECT_EQ(frame1.width(), frame2->width()); |
307 EXPECT_EQ(frame1.height(), frame2->height()); | 285 EXPECT_EQ(frame1.height(), frame2->height()); |
308 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); | 286 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); |
309 EXPECT_EQ(frame1.timestamp_us(), frame2->timestamp_us()); | 287 EXPECT_EQ(frame1.timestamp_us(), frame2->timestamp_us()); |
310 delete frame2; | 288 delete frame2; |
311 } | 289 } |
312 | 290 |
313 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { | 291 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { |
314 WebRtcVideoTestFrame applied0; | 292 WebRtcVideoFrame applied0; |
315 EXPECT_TRUE(IsNull(applied0)); | 293 EXPECT_TRUE(IsNull(applied0)); |
316 EXPECT_TRUE(LoadFrame(CreateYuvSample(kWidth, kHeight, 12).get(), | 294 EXPECT_TRUE(LoadFrame(CreateYuvSample(kWidth, kHeight, 12).get(), FOURCC_I420, |
317 cricket::FOURCC_I420, kWidth, kHeight, &applied0)); | 295 kWidth, kHeight, &applied0)); |
318 | 296 |
319 // Claim that this frame needs to be rotated for 90 degree. | 297 // Claim that this frame needs to be rotated for 90 degree. |
320 applied0.set_rotation(webrtc::kVideoRotation_90); | 298 SetFrameRotation(&applied0, webrtc::kVideoRotation_90); |
321 | 299 |
322 // Apply rotation on frame 1. Output should be different from frame 1. | 300 // Apply rotation on frame 1. Output should be different from frame 1. |
323 WebRtcVideoTestFrame* applied90 = const_cast<WebRtcVideoTestFrame*>( | 301 WebRtcVideoFrame* applied90 = |
324 static_cast<const WebRtcVideoTestFrame*>( | 302 const_cast<WebRtcVideoFrame*>(static_cast<const WebRtcVideoFrame*>( |
325 applied0.GetCopyWithRotationApplied())); | 303 applied0.GetCopyWithRotationApplied())); |
326 EXPECT_TRUE(applied90); | 304 EXPECT_TRUE(applied90); |
327 EXPECT_EQ(applied90->rotation(), webrtc::kVideoRotation_0); | 305 EXPECT_EQ(applied90->rotation(), webrtc::kVideoRotation_0); |
328 EXPECT_FALSE(IsEqual(applied0, *applied90, 0)); | 306 EXPECT_FALSE(IsEqual(applied0, *applied90, 0)); |
329 | 307 |
330 // Claim the frame 2 needs to be rotated for another 270 degree. The output | 308 // Claim the frame 2 needs to be rotated for another 270 degree. The output |
331 // from frame 2 rotation should be the same as frame 1. | 309 // from frame 2 rotation should be the same as frame 1. |
332 applied90->set_rotation(webrtc::kVideoRotation_270); | 310 SetFrameRotation(applied90, webrtc::kVideoRotation_270); |
333 const cricket::VideoFrame* applied360 = | 311 const VideoFrame* applied360 = applied90->GetCopyWithRotationApplied(); |
334 applied90->GetCopyWithRotationApplied(); | |
335 EXPECT_TRUE(applied360); | 312 EXPECT_TRUE(applied360); |
336 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); | 313 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); |
337 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); | 314 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); |
338 } | 315 } |
| 316 |
| 317 } // namespace cricket |
OLD | NEW |