OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <string.h> | |
12 | |
13 #include <memory> | |
14 | |
15 #include "webrtc/media/base/videoframe_unittest.h" | |
16 #include "webrtc/media/engine/webrtcvideoframe.h" | |
17 #include "webrtc/test/fake_texture_frame.h" | |
18 | |
19 namespace cricket { | |
20 | |
21 class WebRtcVideoFrameTest : public VideoFrameTest<WebRtcVideoFrame> { | |
22 public: | |
23 WebRtcVideoFrameTest() {} | |
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, | |
72 webrtc::VideoRotation rotation) { | |
73 frame->rotation_ = rotation; | |
74 } | |
75 }; | |
76 | |
77 #define TEST_WEBRTCVIDEOFRAME(X) \ | |
78 TEST_F(WebRtcVideoFrameTest, X) { VideoFrameTest<WebRtcVideoFrame>::X(); } | |
79 | |
80 TEST_WEBRTCVIDEOFRAME(ConstructI420) | |
81 TEST_WEBRTCVIDEOFRAME(ConstructI422) | |
82 TEST_WEBRTCVIDEOFRAME(ConstructYuy2) | |
83 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Unaligned) | |
84 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Wide) | |
85 TEST_WEBRTCVIDEOFRAME(ConstructYV12) | |
86 TEST_WEBRTCVIDEOFRAME(ConstructUyvy) | |
87 TEST_WEBRTCVIDEOFRAME(ConstructM420) | |
88 TEST_WEBRTCVIDEOFRAME(ConstructNV21) | |
89 TEST_WEBRTCVIDEOFRAME(ConstructNV12) | |
90 TEST_WEBRTCVIDEOFRAME(ConstructABGR) | |
91 TEST_WEBRTCVIDEOFRAME(ConstructARGB) | |
92 TEST_WEBRTCVIDEOFRAME(ConstructARGBWide) | |
93 TEST_WEBRTCVIDEOFRAME(ConstructBGRA) | |
94 TEST_WEBRTCVIDEOFRAME(Construct24BG) | |
95 TEST_WEBRTCVIDEOFRAME(ConstructRaw) | |
96 | |
97 TEST_WEBRTCVIDEOFRAME(ConstructI420Mirror) | |
98 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate0) | |
99 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate90) | |
100 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate180) | |
101 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate270) | |
102 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate0) | |
103 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate90) | |
104 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate180) | |
105 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate270) | |
106 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate0) | |
107 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate90) | |
108 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate180) | |
109 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate270) | |
110 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate0) | |
111 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate90) | |
112 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate180) | |
113 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate270) | |
114 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate0) | |
115 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate90) | |
116 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate180) | |
117 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate270) | |
118 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate0) | |
119 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate90) | |
120 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate180) | |
121 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate270) | |
122 TEST_WEBRTCVIDEOFRAME(ConstructI4201Pixel) | |
123 TEST_WEBRTCVIDEOFRAME(ConstructI4205Pixel) | |
124 // TODO(juberti): WebRtcVideoFrame does not support horizontal crop. | |
125 // Re-evaluate once it supports 3 independent planes, since we might want to | |
126 // just Init normally and then crop by adjusting pointers. | |
127 // TEST_WEBRTCVIDEOFRAME(ConstructI420CropHorizontal) | |
128 TEST_WEBRTCVIDEOFRAME(ConstructI420CropVertical) | |
129 // TODO(juberti): WebRtcVideoFrame is not currently refcounted. | |
130 // TEST_WEBRTCVIDEOFRAME(ConstructCopy) | |
131 // TEST_WEBRTCVIDEOFRAME(ConstructCopyIsRef) | |
132 // TODO(fbarchard): Implement Jpeg | |
133 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI420) | |
134 TEST_WEBRTCVIDEOFRAME(ConstructMjpgI422) | |
135 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI444) | |
136 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI411) | |
137 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI400) | |
138 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420) | |
139 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI422) | |
140 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI444) | |
141 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI411) | |
142 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI400) | |
143 TEST_WEBRTCVIDEOFRAME(ValidateI420) | |
144 TEST_WEBRTCVIDEOFRAME(ValidateI420SmallSize) | |
145 TEST_WEBRTCVIDEOFRAME(ValidateI420LargeSize) | |
146 TEST_WEBRTCVIDEOFRAME(ValidateI420HugeSize) | |
147 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420InvalidSize) | |
148 // TEST_WEBRTCVIDEOFRAME(ValidateI420InvalidSize) | |
149 | |
150 // TODO(fbarchard): WebRtcVideoFrame does not support odd sizes. | |
151 // Re-evaluate once WebRTC switches to libyuv | |
152 // TEST_WEBRTCVIDEOFRAME(ConstructYuy2AllSizes) | |
153 // TEST_WEBRTCVIDEOFRAME(ConstructARGBAllSizes) | |
154 // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer) | |
155 // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel) | |
156 | |
157 // These functions test implementation-specific details. | |
158 // Tests the Init function with different cropped size. | |
159 TEST_F(WebRtcVideoFrameTest, InitEvenSize) { | |
160 TestInit(640, 360, webrtc::kVideoRotation_0, true); | |
161 } | |
162 | |
163 TEST_F(WebRtcVideoFrameTest, InitOddWidth) { | |
164 TestInit(601, 480, webrtc::kVideoRotation_0, true); | |
165 } | |
166 | |
167 TEST_F(WebRtcVideoFrameTest, InitOddHeight) { | |
168 TestInit(360, 765, webrtc::kVideoRotation_0, true); | |
169 } | |
170 | |
171 TEST_F(WebRtcVideoFrameTest, InitOddWidthHeight) { | |
172 TestInit(355, 1021, webrtc::kVideoRotation_0, true); | |
173 } | |
174 | |
175 TEST_F(WebRtcVideoFrameTest, InitRotated90ApplyRotation) { | |
176 TestInit(640, 360, webrtc::kVideoRotation_90, true); | |
177 } | |
178 | |
179 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { | |
180 TestInit(640, 360, webrtc::kVideoRotation_90, false); | |
181 } | |
182 | |
183 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { | |
184 webrtc::test::FakeNativeHandle* dummy_handle = | |
185 new webrtc::test::FakeNativeHandle(); | |
186 webrtc::NativeHandleBuffer* buffer = | |
187 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( | |
188 dummy_handle, 640, 480); | |
189 // Timestamp is converted from ns to us, so last three digits are lost. | |
190 WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); | |
191 EXPECT_EQ(dummy_handle, frame.video_frame_buffer()->native_handle()); | |
192 EXPECT_EQ(640, frame.width()); | |
193 EXPECT_EQ(480, frame.height()); | |
194 EXPECT_EQ(20000, frame.GetTimeStamp()); | |
195 EXPECT_EQ(20, frame.timestamp_us()); | |
196 frame.set_timestamp_us(40); | |
197 EXPECT_EQ(40000, frame.GetTimeStamp()); | |
198 EXPECT_EQ(40, frame.timestamp_us()); | |
199 } | |
200 | |
201 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { | |
202 WebRtcVideoFrame applied0; | |
203 EXPECT_TRUE(IsNull(applied0)); | |
204 EXPECT_TRUE(LoadFrame(CreateYuvSample(kWidth, kHeight, 12).get(), FOURCC_I420, | |
205 kWidth, kHeight, &applied0)); | |
206 | |
207 // Claim that this frame needs to be rotated for 90 degree. | |
208 SetFrameRotation(&applied0, webrtc::kVideoRotation_90); | |
209 EXPECT_EQ(applied0.rotation(), webrtc::kVideoRotation_90); | |
210 | |
211 // Apply rotation on frame 1. Output should be different from frame 1. | |
212 WebRtcVideoFrame applied90( | |
213 webrtc::I420Buffer::Rotate(applied0.video_frame_buffer(), | |
214 applied0.rotation()), | |
215 webrtc::kVideoRotation_0, applied0.timestamp_us()); | |
216 | |
217 EXPECT_EQ(applied90.rotation(), webrtc::kVideoRotation_0); | |
218 EXPECT_FALSE(IsEqual(applied0, applied90, 0)); | |
219 | |
220 // Claim the frame 2 needs to be rotated for another 270 degree. The output | |
221 // from frame 2 rotation should be the same as frame 1. | |
222 SetFrameRotation(&applied90, webrtc::kVideoRotation_270); | |
223 WebRtcVideoFrame applied360( | |
224 webrtc::I420Buffer::Rotate(applied90.video_frame_buffer(), | |
225 applied90.rotation()), | |
226 webrtc::kVideoRotation_0, applied90.timestamp_us()); | |
227 EXPECT_EQ(applied360.rotation(), webrtc::kVideoRotation_0); | |
228 EXPECT_TRUE(IsEqual(applied0, applied360, 0)); | |
229 } | |
230 | |
231 } // namespace cricket | |
OLD | NEW |