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