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 { |
20 | 20 |
21 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { | 21 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { |
22 public: | 22 public: |
23 // The ApplyRotationToFrame test needs this as a public method. | |
24 using cricket::WebRtcVideoFrame::set_rotation; | 23 using cricket::WebRtcVideoFrame::set_rotation; |
25 | 24 |
26 virtual VideoFrame* CreateEmptyFrame(int w, | 25 virtual VideoFrame* CreateEmptyFrame(int w, |
27 int h, | 26 int h, |
28 int64_t time_stamp) const override { | 27 int64_t time_stamp) const override { |
29 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); | 28 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); |
30 frame->InitToBlack(w, h, time_stamp); | 29 frame->InitToBlack(w, h, time_stamp); |
31 return frame; | 30 return frame; |
32 } | 31 } |
33 }; | 32 }; |
34 | 33 |
35 } // namespace | 34 } // namespace |
36 | 35 |
37 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { | 36 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { |
38 public: | 37 public: |
39 WebRtcVideoFrameTest() { | 38 WebRtcVideoFrameTest() { |
40 } | 39 } |
41 | 40 |
42 void TestInit(int cropped_width, int cropped_height, | 41 void TestInit(int cropped_width, int cropped_height, |
43 webrtc::VideoRotation frame_rotation, | 42 webrtc::VideoRotation frame_rotation, |
44 bool apply_rotation) { | 43 bool apply_rotation) { |
45 const int frame_width = 1920; | 44 const int frame_width = 1920; |
46 const int frame_height = 1080; | 45 const int frame_height = 1080; |
47 | 46 |
48 // Build the CapturedFrame. | 47 // Build the CapturedFrame. |
49 cricket::CapturedFrame captured_frame; | 48 cricket::CapturedFrame captured_frame; |
50 captured_frame.fourcc = cricket::FOURCC_I420; | 49 captured_frame.fourcc = cricket::FOURCC_I420; |
51 captured_frame.time_stamp = rtc::TimeNanos(); | 50 captured_frame.time_stamp = 5678; |
52 captured_frame.rotation = frame_rotation; | 51 captured_frame.rotation = frame_rotation; |
53 captured_frame.width = frame_width; | 52 captured_frame.width = frame_width; |
54 captured_frame.height = frame_height; | 53 captured_frame.height = frame_height; |
55 captured_frame.data_size = (frame_width * frame_height) + | 54 captured_frame.data_size = (frame_width * frame_height) + |
56 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; | 55 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; |
57 std::unique_ptr<uint8_t[]> captured_frame_buffer( | 56 std::unique_ptr<uint8_t[]> captured_frame_buffer( |
58 new uint8_t[captured_frame.data_size]); | 57 new uint8_t[captured_frame.data_size]); |
59 // Initialize memory to satisfy DrMemory tests. | 58 // Initialize memory to satisfy DrMemory tests. |
60 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); | 59 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); |
61 captured_frame.data = captured_frame_buffer.get(); | 60 captured_frame.data = captured_frame_buffer.get(); |
62 | 61 |
63 // Create the new frame from the CapturedFrame. | 62 // Create the new frame from the CapturedFrame. |
64 cricket::WebRtcVideoFrame frame; | 63 cricket::WebRtcVideoFrame frame; |
65 EXPECT_TRUE( | 64 EXPECT_TRUE( |
66 frame.Init(&captured_frame, cropped_width, cropped_height, | 65 frame.Init(&captured_frame, cropped_width, cropped_height, |
67 apply_rotation)); | 66 apply_rotation)); |
68 | 67 |
69 // Verify the new frame. | 68 // Verify the new frame. |
70 EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec, | 69 EXPECT_EQ(5678, frame.GetTimeStamp()); |
71 frame.timestamp_us()); | |
72 if (apply_rotation) | 70 if (apply_rotation) |
73 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); | 71 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); |
74 else | 72 else |
75 EXPECT_EQ(frame_rotation, frame.rotation()); | 73 EXPECT_EQ(frame_rotation, frame.rotation()); |
76 // If |apply_rotation| and the frame rotation is 90 or 270, width and | 74 // If |apply_rotation| and the frame rotation is 90 or 270, width and |
77 // height are flipped. | 75 // height are flipped. |
78 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 | 76 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 |
79 || frame_rotation == webrtc::kVideoRotation_270)) { | 77 || frame_rotation == webrtc::kVideoRotation_270)) { |
80 EXPECT_EQ(cropped_width, frame.height()); | 78 EXPECT_EQ(cropped_width, frame.height()); |
81 EXPECT_EQ(cropped_height, frame.width()); | 79 EXPECT_EQ(cropped_height, frame.width()); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { | 264 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { |
267 TestInit(640, 360, webrtc::kVideoRotation_90, false); | 265 TestInit(640, 360, webrtc::kVideoRotation_90, false); |
268 } | 266 } |
269 | 267 |
270 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { | 268 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { |
271 webrtc::test::FakeNativeHandle* dummy_handle = | 269 webrtc::test::FakeNativeHandle* dummy_handle = |
272 new webrtc::test::FakeNativeHandle(); | 270 new webrtc::test::FakeNativeHandle(); |
273 webrtc::NativeHandleBuffer* buffer = | 271 webrtc::NativeHandleBuffer* buffer = |
274 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 272 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
275 dummy_handle, 640, 480); | 273 dummy_handle, 640, 480); |
276 // Timestamp is converted from ns to us, so last three digits are lost. | 274 cricket::WebRtcVideoFrame frame(buffer, 200, webrtc::kVideoRotation_0); |
277 cricket::WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); | |
278 EXPECT_EQ(dummy_handle, frame.GetNativeHandle()); | 275 EXPECT_EQ(dummy_handle, frame.GetNativeHandle()); |
279 EXPECT_EQ(640, frame.width()); | 276 EXPECT_EQ(640, frame.width()); |
280 EXPECT_EQ(480, frame.height()); | 277 EXPECT_EQ(480, frame.height()); |
281 EXPECT_EQ(20000, frame.GetTimeStamp()); | 278 EXPECT_EQ(200, frame.GetTimeStamp()); |
282 EXPECT_EQ(20, frame.timestamp_us()); | 279 frame.SetTimeStamp(400); |
283 frame.set_timestamp_us(40); | 280 EXPECT_EQ(400, frame.GetTimeStamp()); |
284 EXPECT_EQ(40000, frame.GetTimeStamp()); | |
285 EXPECT_EQ(40, frame.timestamp_us()); | |
286 } | 281 } |
287 | 282 |
288 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { | 283 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { |
289 webrtc::test::FakeNativeHandle* dummy_handle = | 284 webrtc::test::FakeNativeHandle* dummy_handle = |
290 new webrtc::test::FakeNativeHandle(); | 285 new webrtc::test::FakeNativeHandle(); |
291 webrtc::NativeHandleBuffer* buffer = | 286 webrtc::NativeHandleBuffer* buffer = |
292 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 287 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
293 dummy_handle, 640, 480); | 288 dummy_handle, 640, 480); |
294 // Timestamp is converted from ns to us, so last three digits are lost. | 289 cricket::WebRtcVideoFrame frame1(buffer, 200, webrtc::kVideoRotation_0); |
295 cricket::WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0); | |
296 cricket::VideoFrame* frame2 = frame1.Copy(); | 290 cricket::VideoFrame* frame2 = frame1.Copy(); |
297 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); | 291 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); |
298 EXPECT_EQ(frame1.width(), frame2->width()); | 292 EXPECT_EQ(frame1.width(), frame2->width()); |
299 EXPECT_EQ(frame1.height(), frame2->height()); | 293 EXPECT_EQ(frame1.height(), frame2->height()); |
300 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); | 294 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); |
301 EXPECT_EQ(frame1.timestamp_us(), frame2->timestamp_us()); | |
302 delete frame2; | 295 delete frame2; |
303 } | 296 } |
304 | 297 |
305 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { | 298 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { |
306 WebRtcVideoTestFrame applied0; | 299 WebRtcVideoTestFrame applied0; |
307 EXPECT_TRUE(IsNull(applied0)); | 300 EXPECT_TRUE(IsNull(applied0)); |
308 std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); | 301 std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); |
309 EXPECT_TRUE( | 302 EXPECT_TRUE( |
310 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); | 303 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); |
311 | 304 |
(...skipping 10 matching lines...) Expand all Loading... |
322 | 315 |
323 // Claim the frame 2 needs to be rotated for another 270 degree. The output | 316 // Claim the frame 2 needs to be rotated for another 270 degree. The output |
324 // from frame 2 rotation should be the same as frame 1. | 317 // from frame 2 rotation should be the same as frame 1. |
325 applied90->set_rotation(webrtc::kVideoRotation_270); | 318 applied90->set_rotation(webrtc::kVideoRotation_270); |
326 const cricket::VideoFrame* applied360 = | 319 const cricket::VideoFrame* applied360 = |
327 applied90->GetCopyWithRotationApplied(); | 320 applied90->GetCopyWithRotationApplied(); |
328 EXPECT_TRUE(applied360); | 321 EXPECT_TRUE(applied360); |
329 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); | 322 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); |
330 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); | 323 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); |
331 } | 324 } |
OLD | NEW |