Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: talk/media/webrtc/webrtcvideoframe_unittest.cc

Issue 1587193006: Move talk/media to webrtc/media (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased to b647aca12a884a13c1728118586245399b55fa3d (#11493) Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/webrtc/webrtcvideoframe.cc ('k') | talk/media/webrtc/webrtcvideoframefactory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2011 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <string.h>
29
30 #include "talk/media/base/videoframe_unittest.h"
31 #include "talk/media/webrtc/webrtcvideoframe.h"
32 #include "webrtc/test/fake_texture_frame.h"
33
34 namespace {
35
36 class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame {
37 public:
38 using cricket::WebRtcVideoFrame::SetRotation;
39
40 virtual VideoFrame* CreateEmptyFrame(int w,
41 int h,
42 int64_t time_stamp) const override {
43 WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame();
44 frame->InitToBlack(w, h, time_stamp);
45 return frame;
46 }
47 };
48
49 } // namespace
50
51 class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> {
52 public:
53 WebRtcVideoFrameTest() {
54 }
55
56 void TestInit(int cropped_width, int cropped_height,
57 webrtc::VideoRotation frame_rotation,
58 bool apply_rotation) {
59 const int frame_width = 1920;
60 const int frame_height = 1080;
61
62 // Build the CapturedFrame.
63 cricket::CapturedFrame captured_frame;
64 captured_frame.fourcc = cricket::FOURCC_I420;
65 captured_frame.time_stamp = 5678;
66 captured_frame.rotation = frame_rotation;
67 captured_frame.width = frame_width;
68 captured_frame.height = frame_height;
69 captured_frame.data_size = (frame_width * frame_height) +
70 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2;
71 rtc::scoped_ptr<uint8_t[]> captured_frame_buffer(
72 new uint8_t[captured_frame.data_size]);
73 // Initialize memory to satisfy DrMemory tests.
74 memset(captured_frame_buffer.get(), 0, captured_frame.data_size);
75 captured_frame.data = captured_frame_buffer.get();
76
77 // Create the new frame from the CapturedFrame.
78 cricket::WebRtcVideoFrame frame;
79 EXPECT_TRUE(
80 frame.Init(&captured_frame, cropped_width, cropped_height,
81 apply_rotation));
82
83 // Verify the new frame.
84 EXPECT_EQ(5678, frame.GetTimeStamp());
85 if (apply_rotation)
86 EXPECT_EQ(webrtc::kVideoRotation_0, frame.GetRotation());
87 else
88 EXPECT_EQ(frame_rotation, frame.GetRotation());
89 // If |apply_rotation| and the frame rotation is 90 or 270, width and
90 // height are flipped.
91 if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90
92 || frame_rotation == webrtc::kVideoRotation_270)) {
93 EXPECT_EQ(static_cast<size_t>(cropped_width), frame.GetHeight());
94 EXPECT_EQ(static_cast<size_t>(cropped_height), frame.GetWidth());
95 } else {
96 EXPECT_EQ(static_cast<size_t>(cropped_width), frame.GetWidth());
97 EXPECT_EQ(static_cast<size_t>(cropped_height), frame.GetHeight());
98 }
99 }
100 };
101
102 #define TEST_WEBRTCVIDEOFRAME(X) TEST_F(WebRtcVideoFrameTest, X) { \
103 VideoFrameTest<cricket::WebRtcVideoFrame>::X(); \
104 }
105
106 TEST_WEBRTCVIDEOFRAME(ConstructI420)
107 TEST_WEBRTCVIDEOFRAME(ConstructI422)
108 TEST_WEBRTCVIDEOFRAME(ConstructYuy2)
109 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Unaligned)
110 TEST_WEBRTCVIDEOFRAME(ConstructYuy2Wide)
111 TEST_WEBRTCVIDEOFRAME(ConstructYV12)
112 TEST_WEBRTCVIDEOFRAME(ConstructUyvy)
113 TEST_WEBRTCVIDEOFRAME(ConstructM420)
114 TEST_WEBRTCVIDEOFRAME(ConstructNV21)
115 TEST_WEBRTCVIDEOFRAME(ConstructNV12)
116 TEST_WEBRTCVIDEOFRAME(ConstructABGR)
117 TEST_WEBRTCVIDEOFRAME(ConstructARGB)
118 TEST_WEBRTCVIDEOFRAME(ConstructARGBWide)
119 TEST_WEBRTCVIDEOFRAME(ConstructBGRA)
120 TEST_WEBRTCVIDEOFRAME(Construct24BG)
121 TEST_WEBRTCVIDEOFRAME(ConstructRaw)
122 TEST_WEBRTCVIDEOFRAME(ConstructRGB565)
123 TEST_WEBRTCVIDEOFRAME(ConstructARGB1555)
124 TEST_WEBRTCVIDEOFRAME(ConstructARGB4444)
125
126 TEST_WEBRTCVIDEOFRAME(ConstructI420Mirror)
127 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate0)
128 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate90)
129 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate180)
130 TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate270)
131 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate0)
132 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate90)
133 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate180)
134 TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate270)
135 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate0)
136 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate90)
137 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate180)
138 TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate270)
139 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate0)
140 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate90)
141 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate180)
142 TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate270)
143 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate0)
144 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate90)
145 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate180)
146 TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate270)
147 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate0)
148 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate90)
149 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate180)
150 TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate270)
151 TEST_WEBRTCVIDEOFRAME(ConstructI4201Pixel)
152 TEST_WEBRTCVIDEOFRAME(ConstructI4205Pixel)
153 // TODO(juberti): WebRtcVideoFrame does not support horizontal crop.
154 // Re-evaluate once it supports 3 independent planes, since we might want to
155 // just Init normally and then crop by adjusting pointers.
156 // TEST_WEBRTCVIDEOFRAME(ConstructI420CropHorizontal)
157 TEST_WEBRTCVIDEOFRAME(ConstructI420CropVertical)
158 // TODO(juberti): WebRtcVideoFrame is not currently refcounted.
159 // TEST_WEBRTCVIDEOFRAME(ConstructCopy)
160 // TEST_WEBRTCVIDEOFRAME(ConstructCopyIsRef)
161 TEST_WEBRTCVIDEOFRAME(ConstructBlack)
162 // TODO(fbarchard): Implement Jpeg
163 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI420)
164 TEST_WEBRTCVIDEOFRAME(ConstructMjpgI422)
165 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI444)
166 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI411)
167 // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI400)
168 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420)
169 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI422)
170 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI444)
171 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI411)
172 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI400)
173 TEST_WEBRTCVIDEOFRAME(ValidateI420)
174 TEST_WEBRTCVIDEOFRAME(ValidateI420SmallSize)
175 TEST_WEBRTCVIDEOFRAME(ValidateI420LargeSize)
176 TEST_WEBRTCVIDEOFRAME(ValidateI420HugeSize)
177 // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420InvalidSize)
178 // TEST_WEBRTCVIDEOFRAME(ValidateI420InvalidSize)
179
180 // TODO(fbarchard): WebRtcVideoFrame does not support odd sizes.
181 // Re-evaluate once WebRTC switches to libyuv
182 // TEST_WEBRTCVIDEOFRAME(ConstructYuy2AllSizes)
183 // TEST_WEBRTCVIDEOFRAME(ConstructARGBAllSizes)
184 TEST_WEBRTCVIDEOFRAME(ResetAndApplyRotation)
185 TEST_WEBRTCVIDEOFRAME(ResetAndDontApplyRotation)
186 TEST_WEBRTCVIDEOFRAME(ConvertToABGRBuffer)
187 TEST_WEBRTCVIDEOFRAME(ConvertToABGRBufferStride)
188 TEST_WEBRTCVIDEOFRAME(ConvertToABGRBufferInverted)
189 TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555Buffer)
190 TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555BufferStride)
191 TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555BufferInverted)
192 TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444Buffer)
193 TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444BufferStride)
194 TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444BufferInverted)
195 TEST_WEBRTCVIDEOFRAME(ConvertToARGBBuffer)
196 TEST_WEBRTCVIDEOFRAME(ConvertToARGBBufferStride)
197 TEST_WEBRTCVIDEOFRAME(ConvertToARGBBufferInverted)
198 TEST_WEBRTCVIDEOFRAME(ConvertToBGRABuffer)
199 TEST_WEBRTCVIDEOFRAME(ConvertToBGRABufferStride)
200 TEST_WEBRTCVIDEOFRAME(ConvertToBGRABufferInverted)
201 TEST_WEBRTCVIDEOFRAME(ConvertToRAWBuffer)
202 TEST_WEBRTCVIDEOFRAME(ConvertToRAWBufferStride)
203 TEST_WEBRTCVIDEOFRAME(ConvertToRAWBufferInverted)
204 TEST_WEBRTCVIDEOFRAME(ConvertToRGB24Buffer)
205 TEST_WEBRTCVIDEOFRAME(ConvertToRGB24BufferStride)
206 TEST_WEBRTCVIDEOFRAME(ConvertToRGB24BufferInverted)
207 TEST_WEBRTCVIDEOFRAME(ConvertToRGB565Buffer)
208 TEST_WEBRTCVIDEOFRAME(ConvertToRGB565BufferStride)
209 TEST_WEBRTCVIDEOFRAME(ConvertToRGB565BufferInverted)
210 TEST_WEBRTCVIDEOFRAME(ConvertToI400Buffer)
211 TEST_WEBRTCVIDEOFRAME(ConvertToI400BufferStride)
212 TEST_WEBRTCVIDEOFRAME(ConvertToI400BufferInverted)
213 TEST_WEBRTCVIDEOFRAME(ConvertToYUY2Buffer)
214 TEST_WEBRTCVIDEOFRAME(ConvertToYUY2BufferStride)
215 TEST_WEBRTCVIDEOFRAME(ConvertToYUY2BufferInverted)
216 TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBuffer)
217 TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBufferStride)
218 TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBufferInverted)
219 TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBuffer)
220 TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBufferStride)
221 TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBufferInverted)
222 TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555Buffer)
223 TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555BufferStride)
224 TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555BufferInverted)
225 TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444Buffer)
226 TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444BufferStride)
227 TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444BufferInverted)
228 TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBuffer)
229 TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBufferStride)
230 TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBufferInverted)
231 TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABuffer)
232 TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABufferStride)
233 TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABufferInverted)
234 TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBuffer)
235 TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBufferStride)
236 TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBufferInverted)
237 TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24Buffer)
238 TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24BufferStride)
239 TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24BufferInverted)
240 TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565Buffer)
241 TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565BufferStride)
242 TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565BufferInverted)
243 TEST_WEBRTCVIDEOFRAME(ConvertFromI400Buffer)
244 TEST_WEBRTCVIDEOFRAME(ConvertFromI400BufferStride)
245 TEST_WEBRTCVIDEOFRAME(ConvertFromI400BufferInverted)
246 TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2Buffer)
247 TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferStride)
248 TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferInverted)
249 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBuffer)
250 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferStride)
251 TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferInverted)
252 // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer)
253 TEST_WEBRTCVIDEOFRAME(CopyToBuffer)
254 TEST_WEBRTCVIDEOFRAME(CopyToFrame)
255 TEST_WEBRTCVIDEOFRAME(Write)
256 TEST_WEBRTCVIDEOFRAME(CopyToBuffer1Pixel)
257 // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel)
258
259 TEST_WEBRTCVIDEOFRAME(StretchToFrame)
260 TEST_WEBRTCVIDEOFRAME(Copy)
261 TEST_WEBRTCVIDEOFRAME(CopyIsRef)
262 TEST_WEBRTCVIDEOFRAME(MakeExclusive)
263
264 // These functions test implementation-specific details.
265 // Tests the Init function with different cropped size.
266 TEST_F(WebRtcVideoFrameTest, InitEvenSize) {
267 TestInit(640, 360, webrtc::kVideoRotation_0, true);
268 }
269
270 TEST_F(WebRtcVideoFrameTest, InitOddWidth) {
271 TestInit(601, 480, webrtc::kVideoRotation_0, true);
272 }
273
274 TEST_F(WebRtcVideoFrameTest, InitOddHeight) {
275 TestInit(360, 765, webrtc::kVideoRotation_0, true);
276 }
277
278 TEST_F(WebRtcVideoFrameTest, InitOddWidthHeight) {
279 TestInit(355, 1021, webrtc::kVideoRotation_0, true);
280 }
281
282 TEST_F(WebRtcVideoFrameTest, InitRotated90ApplyRotation) {
283 TestInit(640, 360, webrtc::kVideoRotation_90, true);
284 }
285
286 TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) {
287 TestInit(640, 360, webrtc::kVideoRotation_90, false);
288 }
289
290 TEST_F(WebRtcVideoFrameTest, TextureInitialValues) {
291 webrtc::test::FakeNativeHandle* dummy_handle =
292 new webrtc::test::FakeNativeHandle();
293 webrtc::NativeHandleBuffer* buffer =
294 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
295 dummy_handle, 640, 480);
296 cricket::WebRtcVideoFrame frame(buffer, 200, webrtc::kVideoRotation_0);
297 EXPECT_EQ(dummy_handle, frame.GetNativeHandle());
298 EXPECT_EQ(640u, frame.GetWidth());
299 EXPECT_EQ(480u, frame.GetHeight());
300 EXPECT_EQ(200, frame.GetTimeStamp());
301 frame.SetTimeStamp(400);
302 EXPECT_EQ(400, frame.GetTimeStamp());
303 }
304
305 TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) {
306 webrtc::test::FakeNativeHandle* dummy_handle =
307 new webrtc::test::FakeNativeHandle();
308 webrtc::NativeHandleBuffer* buffer =
309 new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>(
310 dummy_handle, 640, 480);
311 cricket::WebRtcVideoFrame frame1(buffer, 200, webrtc::kVideoRotation_0);
312 cricket::VideoFrame* frame2 = frame1.Copy();
313 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle());
314 EXPECT_EQ(frame1.GetWidth(), frame2->GetWidth());
315 EXPECT_EQ(frame1.GetHeight(), frame2->GetHeight());
316 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp());
317 delete frame2;
318 }
319
320 TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) {
321 WebRtcVideoTestFrame applied0;
322 EXPECT_TRUE(IsNull(applied0));
323 rtc::scoped_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12));
324 EXPECT_TRUE(
325 LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0));
326
327 // Claim that this frame needs to be rotated for 90 degree.
328 applied0.SetRotation(webrtc::kVideoRotation_90);
329
330 // Apply rotation on frame 1. Output should be different from frame 1.
331 WebRtcVideoTestFrame* applied90 = const_cast<WebRtcVideoTestFrame*>(
332 static_cast<const WebRtcVideoTestFrame*>(
333 applied0.GetCopyWithRotationApplied()));
334 EXPECT_TRUE(applied90);
335 EXPECT_EQ(applied90->GetVideoRotation(), webrtc::kVideoRotation_0);
336 EXPECT_FALSE(IsEqual(applied0, *applied90, 0));
337
338 // Claim the frame 2 needs to be rotated for another 270 degree. The output
339 // from frame 2 rotation should be the same as frame 1.
340 applied90->SetRotation(webrtc::kVideoRotation_270);
341 const cricket::VideoFrame* applied360 =
342 applied90->GetCopyWithRotationApplied();
343 EXPECT_TRUE(applied360);
344 EXPECT_EQ(applied360->GetVideoRotation(), webrtc::kVideoRotation_0);
345 EXPECT_TRUE(IsEqual(applied0, *applied360, 0));
346 }
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvideoframe.cc ('k') | talk/media/webrtc/webrtcvideoframefactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698