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 cricket { |
20 | 20 |
21 class WebRtcVideoFrameTest : public VideoFrameTest<WebRtcVideoFrame> { | 21 class WebRtcVideoFrameTest : public VideoFrameTest<WebRtcVideoFrame> { |
22 public: | 22 public: |
23 WebRtcVideoFrameTest() {} | 23 WebRtcVideoFrameTest() {} |
24 | 24 |
25 void TestInit(int cropped_width, int cropped_height, | |
26 webrtc::VideoRotation frame_rotation, | |
27 bool apply_rotation) { | |
28 const int frame_width = 1920; | |
29 const int frame_height = 1080; | |
30 | |
31 // Build the CapturedFrame. | |
32 CapturedFrame captured_frame; | |
33 captured_frame.fourcc = FOURCC_I420; | |
34 captured_frame.time_stamp = rtc::TimeNanos(); | |
35 captured_frame.rotation = frame_rotation; | |
36 captured_frame.width = frame_width; | |
37 captured_frame.height = frame_height; | |
38 captured_frame.data_size = (frame_width * frame_height) + | |
39 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; | |
40 std::unique_ptr<uint8_t[]> captured_frame_buffer( | |
41 new uint8_t[captured_frame.data_size]); | |
42 // Initialize memory to satisfy DrMemory tests. | |
43 memset(captured_frame_buffer.get(), 0, captured_frame.data_size); | |
44 captured_frame.data = captured_frame_buffer.get(); | |
45 | |
46 // Create the new frame from the CapturedFrame. | |
47 WebRtcVideoFrame frame; | |
48 EXPECT_TRUE( | |
49 frame.Init(&captured_frame, cropped_width, cropped_height, | |
50 apply_rotation)); | |
51 | |
52 // Verify the new frame. | |
53 EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec, | |
54 frame.timestamp_us()); | |
55 if (apply_rotation) | |
56 EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); | |
57 else | |
58 EXPECT_EQ(frame_rotation, frame.rotation()); | |
59 // If |apply_rotation| and the frame rotation is 90 or 270, width and | |
60 // height are flipped. | |
61 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 | |
62 || frame_rotation == webrtc::kVideoRotation_270)) { | |
63 EXPECT_EQ(cropped_width, frame.height()); | |
64 EXPECT_EQ(cropped_height, frame.width()); | |
65 } else { | |
66 EXPECT_EQ(cropped_width, frame.width()); | |
67 EXPECT_EQ(cropped_height, frame.height()); | |
68 } | |
69 } | |
70 | |
71 void SetFrameRotation(WebRtcVideoFrame* frame, | 25 void SetFrameRotation(WebRtcVideoFrame* frame, |
72 webrtc::VideoRotation rotation) { | 26 webrtc::VideoRotation rotation) { |
73 frame->rotation_ = rotation; | 27 frame->rotation_ = rotation; |
74 } | 28 } |
75 }; | 29 }; |
76 | 30 |
77 #define TEST_WEBRTCVIDEOFRAME(X) \ | 31 #define TEST_WEBRTCVIDEOFRAME(X) \ |
78 TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest<WebRtcVideoFrame>::X(); } | 32 TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest<WebRtcVideoFrame>::X(); } |
79 | 33 |
80 TEST_WEBRTCVIDEOFRAME(ConstructI420) | 34 TEST_WEBRTCVIDEOFRAME(ConstructI420) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferInverted) | 173 TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferInverted) |
220 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBuffer) | 174 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBuffer) |
221 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferStride) | 175 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferStride) |
222 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferInverted) | 176 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferInverted) |
223 // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer) | 177 // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer) |
224 // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel) | 178 // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel) |
225 | 179 |
226 TEST_WEBRTCVIDEOFRAME(Copy) | 180 TEST_WEBRTCVIDEOFRAME(Copy) |
227 TEST_WEBRTCVIDEOFRAME(CopyIsRef) | 181 TEST_WEBRTCVIDEOFRAME(CopyIsRef) |
228 | 182 |
229 // These functions test implementation-specific details. | |
230 // Tests the Init function with different cropped size. | |
231 TEST_F(WebRtcVideoFrameTest, InitEvenSize) { | |
232 TestInit(640, 360, webrtc::kVideoRotation_0, true); | |
233 } | |
234 | |
235 TEST_F(WebRtcVideoFrameTest, InitOddWidth) { | |
236 TestInit(601, 480, webrtc::kVideoRotation_0, true); | |
237 } | |
238 | |
239 TEST_F(WebRtcVideoFrameTest, InitOddHeight) { | |
240 TestInit(360, 765, webrtc::kVideoRotation_0, true); | |
241 } | |
242 | |
243 TEST_F(WebRtcVideoFrameTest, InitOddWidthHeight) { | |
244 TestInit(355, 1021, webrtc::kVideoRotation_0, true); | |
245 } | |
246 | |
247 TEST_F(WebRtcVideoFrameTest, InitRotated90ApplyRotation) { | |
248 TestInit(640, 360, webrtc::kVideoRotation_90, true); | |
249 } | |
250 | |
251 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { | |
252 TestInit(640, 360, webrtc::kVideoRotation_90, false); | |
253 } | |
254 | |
255 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { | 183 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { |
256 webrtc::test::FakeNativeHandle* dummy_handle = | 184 webrtc::test::FakeNativeHandle* dummy_handle = |
257 new webrtc::test::FakeNativeHandle(); | 185 new webrtc::test::FakeNativeHandle(); |
258 webrtc::NativeHandleBuffer* buffer = | 186 webrtc::NativeHandleBuffer* buffer = |
259 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | 187 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
260 dummy_handle, 640, 480); | 188 dummy_handle, 640, 480); |
261 // Timestamp is converted from ns to us, so last three digits are lost. | 189 // Timestamp is converted from ns to us, so last three digits are lost. |
262 WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); | 190 WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); |
263 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); | 191 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); |
264 EXPECT_EQ(640, frame.width()); | 192 EXPECT_EQ(640, frame.width()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // Claim the frame 2 needs to be rotated for another 270 degree. The output | 236 // Claim the frame 2 needs to be rotated for another 270 degree. The output |
309 // from frame 2 rotation should be the same as frame 1. | 237 // from frame 2 rotation should be the same as frame 1. |
310 SetFrameRotation(applied90, webrtc::kVideoRotation_270); | 238 SetFrameRotation(applied90, webrtc::kVideoRotation_270); |
311 const VideoFrame* applied360 = applied90->GetCopyWithRotationApplied(); | 239 const VideoFrame* applied360 = applied90->GetCopyWithRotationApplied(); |
312 EXPECT_TRUE(applied360); | 240 EXPECT_TRUE(applied360); |
313 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); | 241 EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); |
314 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); | 242 EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); |
315 } | 243 } |
316 | 244 |
317 } // namespace cricket | 245 } // namespace cricket |
OLD | NEW |