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 "talk/media/base/videoframe_unittest.h" 29#include "talk/media/webrtc/webrtcvideoframe.h" 30 31class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { 32 public: 33 WebRtcVideoFrameTest() { 34 } 35 36 void TestInit(int cropped_width, int cropped_height) { 37 const int frame_width = 1920; 38 const int frame_height = 1080; 39 40 // Build the CapturedFrame. 41 cricket::CapturedFrame captured_frame; 42 captured_frame.fourcc = cricket::FOURCC_I420; 43 captured_frame.pixel_width = 1; 44 captured_frame.pixel_height = 1; 45 captured_frame.elapsed_time = 1234; 46 captured_frame.time_stamp = 5678; 47 captured_frame.rotation = 0; 48 captured_frame.width = frame_width; 49 captured_frame.height = frame_height; 50 captured_frame.data_size = (frame_width * frame_height) + 51 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; 52 rtc::scoped_ptr<uint8[]> captured_frame_buffer( 53 new uint8[captured_frame.data_size]); 54 captured_frame.data = captured_frame_buffer.get(); 55 56 // Create the new frame from the CapturedFrame. 57 cricket::WebRtcVideoFrame frame; 58 EXPECT_TRUE(frame.Init(&captured_frame, cropped_width, cropped_height)); 59 60 // Verify the new frame. 61 EXPECT_EQ(1u, frame.GetPixelWidth()); 62 EXPECT_EQ(1u, frame.GetPixelHeight()); 63 EXPECT_EQ(1234, frame.GetElapsedTime()); 64 EXPECT_EQ(5678, frame.GetTimeStamp()); 65 EXPECT_EQ(0, frame.GetRotation()); 66 // The size of the new frame should have been cropped to multiple of 4. 67 EXPECT_EQ(static_cast<size_t>(cropped_width & ~3), frame.GetWidth()); 68 EXPECT_EQ(static_cast<size_t>(cropped_height & ~3), frame.GetHeight()); 69 } 70}; 71 72#define TEST_WEBRTCVIDEOFRAME(X) TEST_F(WebRtcVideoFrameTest, X) { \ 73 VideoFrameTest<cricket::WebRtcVideoFrame>::X(); \ 74} 75 76TEST_WEBRTCVIDEOFRAME(ConstructI420) 77TEST_WEBRTCVIDEOFRAME(ConstructI422) 78TEST_WEBRTCVIDEOFRAME(ConstructYuy2) 79TEST_WEBRTCVIDEOFRAME(ConstructYuy2Unaligned) 80TEST_WEBRTCVIDEOFRAME(ConstructYuy2Wide) 81TEST_WEBRTCVIDEOFRAME(ConstructYV12) 82TEST_WEBRTCVIDEOFRAME(ConstructUyvy) 83TEST_WEBRTCVIDEOFRAME(ConstructM420) 84TEST_WEBRTCVIDEOFRAME(ConstructQ420) 85TEST_WEBRTCVIDEOFRAME(ConstructNV21) 86TEST_WEBRTCVIDEOFRAME(ConstructNV12) 87TEST_WEBRTCVIDEOFRAME(ConstructABGR) 88TEST_WEBRTCVIDEOFRAME(ConstructARGB) 89TEST_WEBRTCVIDEOFRAME(ConstructARGBWide) 90TEST_WEBRTCVIDEOFRAME(ConstructBGRA) 91TEST_WEBRTCVIDEOFRAME(Construct24BG) 92TEST_WEBRTCVIDEOFRAME(ConstructRaw) 93TEST_WEBRTCVIDEOFRAME(ConstructRGB565) 94TEST_WEBRTCVIDEOFRAME(ConstructARGB1555) 95TEST_WEBRTCVIDEOFRAME(ConstructARGB4444) 96 97TEST_WEBRTCVIDEOFRAME(ConstructI420Mirror) 98TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate0) 99TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate90) 100TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate180) 101TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate270) 102TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate0) 103TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate90) 104TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate180) 105TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate270) 106TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate0) 107TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate90) 108TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate180) 109TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate270) 110TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate0) 111TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate90) 112TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate180) 113TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate270) 114TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate0) 115TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate90) 116TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate180) 117TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate270) 118TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate0) 119TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate90) 120TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate180) 121TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate270) 122TEST_WEBRTCVIDEOFRAME(ConstructI4201Pixel) 123TEST_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) 128TEST_WEBRTCVIDEOFRAME(ConstructI420CropVertical) 129// TODO(juberti): WebRtcVideoFrame is not currently refcounted. 130// TEST_WEBRTCVIDEOFRAME(ConstructCopy) 131// TEST_WEBRTCVIDEOFRAME(ConstructCopyIsRef) 132TEST_WEBRTCVIDEOFRAME(ConstructBlack) 133// TODO(fbarchard): Implement Jpeg 134// TEST_WEBRTCVIDEOFRAME(ConstructMjpgI420) 135TEST_WEBRTCVIDEOFRAME(ConstructMjpgI422) 136// TEST_WEBRTCVIDEOFRAME(ConstructMjpgI444) 137// TEST_WEBRTCVIDEOFRAME(ConstructMjpgI411) 138// TEST_WEBRTCVIDEOFRAME(ConstructMjpgI400) 139// TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420) 140// TEST_WEBRTCVIDEOFRAME(ValidateMjpgI422) 141// TEST_WEBRTCVIDEOFRAME(ValidateMjpgI444) 142// TEST_WEBRTCVIDEOFRAME(ValidateMjpgI411) 143// TEST_WEBRTCVIDEOFRAME(ValidateMjpgI400) 144TEST_WEBRTCVIDEOFRAME(ValidateI420) 145TEST_WEBRTCVIDEOFRAME(ValidateI420SmallSize) 146TEST_WEBRTCVIDEOFRAME(ValidateI420LargeSize) 147TEST_WEBRTCVIDEOFRAME(ValidateI420HugeSize) 148// TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420InvalidSize) 149// TEST_WEBRTCVIDEOFRAME(ValidateI420InvalidSize) 150 151// TODO(fbarchard): WebRtcVideoFrame does not support odd sizes. 152// Re-evaluate once WebRTC switches to libyuv 153// TEST_WEBRTCVIDEOFRAME(ConstructYuy2AllSizes) 154// TEST_WEBRTCVIDEOFRAME(ConstructARGBAllSizes) 155TEST_WEBRTCVIDEOFRAME(Reset) 156TEST_WEBRTCVIDEOFRAME(ConvertToABGRBuffer) 157TEST_WEBRTCVIDEOFRAME(ConvertToABGRBufferStride) 158TEST_WEBRTCVIDEOFRAME(ConvertToABGRBufferInverted) 159TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555Buffer) 160TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555BufferStride) 161TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555BufferInverted) 162TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444Buffer) 163TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444BufferStride) 164TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444BufferInverted) 165TEST_WEBRTCVIDEOFRAME(ConvertToARGBBuffer) 166TEST_WEBRTCVIDEOFRAME(ConvertToARGBBufferStride) 167TEST_WEBRTCVIDEOFRAME(ConvertToARGBBufferInverted) 168TEST_WEBRTCVIDEOFRAME(ConvertToBGRABuffer) 169TEST_WEBRTCVIDEOFRAME(ConvertToBGRABufferStride) 170TEST_WEBRTCVIDEOFRAME(ConvertToBGRABufferInverted) 171TEST_WEBRTCVIDEOFRAME(ConvertToRAWBuffer) 172TEST_WEBRTCVIDEOFRAME(ConvertToRAWBufferStride) 173TEST_WEBRTCVIDEOFRAME(ConvertToRAWBufferInverted) 174TEST_WEBRTCVIDEOFRAME(ConvertToRGB24Buffer) 175TEST_WEBRTCVIDEOFRAME(ConvertToRGB24BufferStride) 176TEST_WEBRTCVIDEOFRAME(ConvertToRGB24BufferInverted) 177TEST_WEBRTCVIDEOFRAME(ConvertToRGB565Buffer) 178TEST_WEBRTCVIDEOFRAME(ConvertToRGB565BufferStride) 179TEST_WEBRTCVIDEOFRAME(ConvertToRGB565BufferInverted) 180TEST_WEBRTCVIDEOFRAME(ConvertToBayerBGGRBuffer) 181TEST_WEBRTCVIDEOFRAME(ConvertToBayerBGGRBufferStride) 182TEST_WEBRTCVIDEOFRAME(ConvertToBayerBGGRBufferInverted) 183TEST_WEBRTCVIDEOFRAME(ConvertToBayerGRBGBuffer) 184TEST_WEBRTCVIDEOFRAME(ConvertToBayerGRBGBufferStride) 185TEST_WEBRTCVIDEOFRAME(ConvertToBayerGRBGBufferInverted) 186TEST_WEBRTCVIDEOFRAME(ConvertToBayerGBRGBuffer) 187TEST_WEBRTCVIDEOFRAME(ConvertToBayerGBRGBufferStride) 188TEST_WEBRTCVIDEOFRAME(ConvertToBayerGBRGBufferInverted) 189TEST_WEBRTCVIDEOFRAME(ConvertToBayerRGGBBuffer) 190TEST_WEBRTCVIDEOFRAME(ConvertToBayerRGGBBufferStride) 191TEST_WEBRTCVIDEOFRAME(ConvertToBayerRGGBBufferInverted) 192TEST_WEBRTCVIDEOFRAME(ConvertToI400Buffer) 193TEST_WEBRTCVIDEOFRAME(ConvertToI400BufferStride) 194TEST_WEBRTCVIDEOFRAME(ConvertToI400BufferInverted) 195TEST_WEBRTCVIDEOFRAME(ConvertToYUY2Buffer) 196TEST_WEBRTCVIDEOFRAME(ConvertToYUY2BufferStride) 197TEST_WEBRTCVIDEOFRAME(ConvertToYUY2BufferInverted) 198TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBuffer) 199TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBufferStride) 200TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBufferInverted) 201TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBuffer) 202TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBufferStride) 203TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBufferInverted) 204TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555Buffer) 205TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555BufferStride) 206TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555BufferInverted) 207TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444Buffer) 208TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444BufferStride) 209TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444BufferInverted) 210TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBuffer) 211TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBufferStride) 212TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBufferInverted) 213TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABuffer) 214TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABufferStride) 215TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABufferInverted) 216TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBuffer) 217TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBufferStride) 218TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBufferInverted) 219TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24Buffer) 220TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24BufferStride) 221TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24BufferInverted) 222TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565Buffer) 223TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565BufferStride) 224TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565BufferInverted) 225TEST_WEBRTCVIDEOFRAME(ConvertFromBayerBGGRBuffer) 226TEST_WEBRTCVIDEOFRAME(ConvertFromBayerBGGRBufferStride) 227TEST_WEBRTCVIDEOFRAME(ConvertFromBayerBGGRBufferInverted) 228TEST_WEBRTCVIDEOFRAME(ConvertFromBayerGRBGBuffer) 229TEST_WEBRTCVIDEOFRAME(ConvertFromBayerGRBGBufferStride) 230TEST_WEBRTCVIDEOFRAME(ConvertFromBayerGRBGBufferInverted) 231TEST_WEBRTCVIDEOFRAME(ConvertFromBayerGBRGBuffer) 232TEST_WEBRTCVIDEOFRAME(ConvertFromBayerGBRGBufferStride) 233TEST_WEBRTCVIDEOFRAME(ConvertFromBayerGBRGBufferInverted) 234TEST_WEBRTCVIDEOFRAME(ConvertFromBayerRGGBBuffer) 235TEST_WEBRTCVIDEOFRAME(ConvertFromBayerRGGBBufferStride) 236TEST_WEBRTCVIDEOFRAME(ConvertFromBayerRGGBBufferInverted) 237TEST_WEBRTCVIDEOFRAME(ConvertFromI400Buffer) 238TEST_WEBRTCVIDEOFRAME(ConvertFromI400BufferStride) 239TEST_WEBRTCVIDEOFRAME(ConvertFromI400BufferInverted) 240TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2Buffer) 241TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferStride) 242TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferInverted) 243TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBuffer) 244TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferStride) 245TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferInverted) 246// TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer) 247TEST_WEBRTCVIDEOFRAME(ConvertARGBToBayerGRBG) 248TEST_WEBRTCVIDEOFRAME(ConvertARGBToBayerGBRG) 249TEST_WEBRTCVIDEOFRAME(ConvertARGBToBayerBGGR) 250TEST_WEBRTCVIDEOFRAME(ConvertARGBToBayerRGGB) 251TEST_WEBRTCVIDEOFRAME(CopyToBuffer) 252TEST_WEBRTCVIDEOFRAME(CopyToFrame) 253TEST_WEBRTCVIDEOFRAME(Write) 254TEST_WEBRTCVIDEOFRAME(CopyToBuffer1Pixel) 255// TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel) 256 257TEST_WEBRTCVIDEOFRAME(StretchToFrame) 258TEST_WEBRTCVIDEOFRAME(Copy) 259TEST_WEBRTCVIDEOFRAME(CopyIsRef) 260TEST_WEBRTCVIDEOFRAME(MakeExclusive) 261 262// These functions test implementation-specific details. 263TEST_F(WebRtcVideoFrameTest, Alias) { 264 cricket::WebRtcVideoFrame frame1, frame2; 265 ASSERT_TRUE(LoadFrameNoRepeat(&frame1)); 266 const int64 time_stamp = INT64_C(0x7FFFFFFFFFFFFFF0); 267 frame1.SetTimeStamp(time_stamp); 268 EXPECT_EQ(time_stamp, frame1.GetTimeStamp()); 269 frame2.Alias(frame1.frame()->Buffer(), frame1.frame()->Size(), 270 kWidth, kHeight, 1, 1, 271 frame1.GetElapsedTime(), frame1.GetTimeStamp(), 0); 272 EXPECT_TRUE(IsEqual(frame1, frame2, 0)); 273} 274 275// Tests the Init function with different cropped size. 276TEST_F(WebRtcVideoFrameTest, InitEvenSize) { 277 TestInit(640, 360); 278} 279 280TEST_F(WebRtcVideoFrameTest, InitOddWidth) { 281 TestInit(601, 480); 282} 283 284TEST_F(WebRtcVideoFrameTest, InitOddHeight) { 285 TestInit(360, 765); 286} 287 288TEST_F(WebRtcVideoFrameTest, InitOddWidthHeight) { 289 TestInit(355, 1021); 290} 291