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