henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
magjed@webrtc.org | cb04aa4 | 2015-03-03 09:23:47 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 15 | #include "webrtc/media/base/videoframe_unittest.h" |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 16 | #include "webrtc/media/engine/webrtcvideoframe.h" |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 17 | #include "webrtc/test/fake_texture_frame.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 19 | namespace { |
| 20 | |
| 21 | class WebRtcVideoTestFrame : public cricket::WebRtcVideoFrame { |
| 22 | public: |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 23 | // The ApplyRotationToFrame test needs this as a public method. |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 24 | using cricket::WebRtcVideoFrame::set_rotation; |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 25 | |
| 26 | virtual VideoFrame* CreateEmptyFrame(int w, |
| 27 | int h, |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 28 | int64_t time_stamp) const override { |
| 29 | WebRtcVideoTestFrame* frame = new WebRtcVideoTestFrame(); |
nisse | 8b1e431 | 2016-01-18 01:46:27 -0800 | [diff] [blame] | 30 | frame->InitToBlack(w, h, time_stamp); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 31 | return frame; |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | } // namespace |
| 36 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | class WebRtcVideoFrameTest : public VideoFrameTest<cricket::WebRtcVideoFrame> { |
| 38 | public: |
| 39 | WebRtcVideoFrameTest() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | } |
| 41 | |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 42 | void TestInit(int cropped_width, int cropped_height, |
| 43 | webrtc::VideoRotation frame_rotation, |
| 44 | bool apply_rotation) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | const int frame_width = 1920; |
| 46 | const int frame_height = 1080; |
| 47 | |
| 48 | // Build the CapturedFrame. |
| 49 | cricket::CapturedFrame captured_frame; |
| 50 | captured_frame.fourcc = cricket::FOURCC_I420; |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 51 | captured_frame.time_stamp = rtc::TimeNanos(); |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 52 | captured_frame.rotation = frame_rotation; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | captured_frame.width = frame_width; |
| 54 | captured_frame.height = frame_height; |
| 55 | captured_frame.data_size = (frame_width * frame_height) + |
| 56 | ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 57 | std::unique_ptr<uint8_t[]> captured_frame_buffer( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 58 | new uint8_t[captured_frame.data_size]); |
magjed@webrtc.org | cb04aa4 | 2015-03-03 09:23:47 +0000 | [diff] [blame] | 59 | // Initialize memory to satisfy DrMemory tests. |
| 60 | memset(captured_frame_buffer.get(), 0, captured_frame.data_size); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | captured_frame.data = captured_frame_buffer.get(); |
| 62 | |
| 63 | // Create the new frame from the CapturedFrame. |
| 64 | cricket::WebRtcVideoFrame frame; |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 65 | EXPECT_TRUE( |
| 66 | frame.Init(&captured_frame, cropped_width, cropped_height, |
| 67 | apply_rotation)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | |
| 69 | // Verify the new frame. |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 70 | EXPECT_EQ(captured_frame.time_stamp / rtc::kNumNanosecsPerMicrosec, |
| 71 | frame.timestamp_us()); |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 72 | if (apply_rotation) |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 73 | EXPECT_EQ(webrtc::kVideoRotation_0, frame.rotation()); |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 74 | else |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 75 | EXPECT_EQ(frame_rotation, frame.rotation()); |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 76 | // If |apply_rotation| and the frame rotation is 90 or 270, width and |
| 77 | // height are flipped. |
| 78 | if (apply_rotation && (frame_rotation == webrtc::kVideoRotation_90 |
| 79 | || frame_rotation == webrtc::kVideoRotation_270)) { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 80 | EXPECT_EQ(cropped_width, frame.height()); |
| 81 | EXPECT_EQ(cropped_height, frame.width()); |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 82 | } else { |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 83 | EXPECT_EQ(cropped_width, frame.width()); |
| 84 | EXPECT_EQ(cropped_height, frame.height()); |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 85 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | } |
| 87 | }; |
| 88 | |
| 89 | #define TEST_WEBRTCVIDEOFRAME(X) TEST_F(WebRtcVideoFrameTest, X) { \ |
| 90 | VideoFrameTest<cricket::WebRtcVideoFrame>::X(); \ |
| 91 | } |
| 92 | |
| 93 | TEST_WEBRTCVIDEOFRAME(ConstructI420) |
| 94 | TEST_WEBRTCVIDEOFRAME(ConstructI422) |
| 95 | TEST_WEBRTCVIDEOFRAME(ConstructYuy2) |
| 96 | TEST_WEBRTCVIDEOFRAME(ConstructYuy2Unaligned) |
| 97 | TEST_WEBRTCVIDEOFRAME(ConstructYuy2Wide) |
| 98 | TEST_WEBRTCVIDEOFRAME(ConstructYV12) |
| 99 | TEST_WEBRTCVIDEOFRAME(ConstructUyvy) |
| 100 | TEST_WEBRTCVIDEOFRAME(ConstructM420) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | TEST_WEBRTCVIDEOFRAME(ConstructNV21) |
| 102 | TEST_WEBRTCVIDEOFRAME(ConstructNV12) |
| 103 | TEST_WEBRTCVIDEOFRAME(ConstructABGR) |
| 104 | TEST_WEBRTCVIDEOFRAME(ConstructARGB) |
| 105 | TEST_WEBRTCVIDEOFRAME(ConstructARGBWide) |
| 106 | TEST_WEBRTCVIDEOFRAME(ConstructBGRA) |
| 107 | TEST_WEBRTCVIDEOFRAME(Construct24BG) |
| 108 | TEST_WEBRTCVIDEOFRAME(ConstructRaw) |
| 109 | TEST_WEBRTCVIDEOFRAME(ConstructRGB565) |
| 110 | TEST_WEBRTCVIDEOFRAME(ConstructARGB1555) |
| 111 | TEST_WEBRTCVIDEOFRAME(ConstructARGB4444) |
| 112 | |
| 113 | TEST_WEBRTCVIDEOFRAME(ConstructI420Mirror) |
| 114 | TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate0) |
| 115 | TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate90) |
| 116 | TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate180) |
| 117 | TEST_WEBRTCVIDEOFRAME(ConstructI420Rotate270) |
| 118 | TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate0) |
| 119 | TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate90) |
| 120 | TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate180) |
| 121 | TEST_WEBRTCVIDEOFRAME(ConstructYV12Rotate270) |
| 122 | TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate0) |
| 123 | TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate90) |
| 124 | TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate180) |
| 125 | TEST_WEBRTCVIDEOFRAME(ConstructNV12Rotate270) |
| 126 | TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate0) |
| 127 | TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate90) |
| 128 | TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate180) |
| 129 | TEST_WEBRTCVIDEOFRAME(ConstructNV21Rotate270) |
| 130 | TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate0) |
| 131 | TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate90) |
| 132 | TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate180) |
| 133 | TEST_WEBRTCVIDEOFRAME(ConstructUYVYRotate270) |
| 134 | TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate0) |
| 135 | TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate90) |
| 136 | TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate180) |
| 137 | TEST_WEBRTCVIDEOFRAME(ConstructYUY2Rotate270) |
| 138 | TEST_WEBRTCVIDEOFRAME(ConstructI4201Pixel) |
| 139 | TEST_WEBRTCVIDEOFRAME(ConstructI4205Pixel) |
| 140 | // TODO(juberti): WebRtcVideoFrame does not support horizontal crop. |
| 141 | // Re-evaluate once it supports 3 independent planes, since we might want to |
| 142 | // just Init normally and then crop by adjusting pointers. |
| 143 | // TEST_WEBRTCVIDEOFRAME(ConstructI420CropHorizontal) |
| 144 | TEST_WEBRTCVIDEOFRAME(ConstructI420CropVertical) |
| 145 | // TODO(juberti): WebRtcVideoFrame is not currently refcounted. |
| 146 | // TEST_WEBRTCVIDEOFRAME(ConstructCopy) |
| 147 | // TEST_WEBRTCVIDEOFRAME(ConstructCopyIsRef) |
| 148 | TEST_WEBRTCVIDEOFRAME(ConstructBlack) |
| 149 | // TODO(fbarchard): Implement Jpeg |
| 150 | // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI420) |
thorcarpenter@google.com | a3344cf | 2014-09-05 16:34:13 +0000 | [diff] [blame] | 151 | TEST_WEBRTCVIDEOFRAME(ConstructMjpgI422) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI444) |
| 153 | // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI411) |
| 154 | // TEST_WEBRTCVIDEOFRAME(ConstructMjpgI400) |
| 155 | // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420) |
| 156 | // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI422) |
| 157 | // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI444) |
| 158 | // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI411) |
| 159 | // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI400) |
| 160 | TEST_WEBRTCVIDEOFRAME(ValidateI420) |
| 161 | TEST_WEBRTCVIDEOFRAME(ValidateI420SmallSize) |
| 162 | TEST_WEBRTCVIDEOFRAME(ValidateI420LargeSize) |
| 163 | TEST_WEBRTCVIDEOFRAME(ValidateI420HugeSize) |
| 164 | // TEST_WEBRTCVIDEOFRAME(ValidateMjpgI420InvalidSize) |
| 165 | // TEST_WEBRTCVIDEOFRAME(ValidateI420InvalidSize) |
| 166 | |
| 167 | // TODO(fbarchard): WebRtcVideoFrame does not support odd sizes. |
| 168 | // Re-evaluate once WebRTC switches to libyuv |
| 169 | // TEST_WEBRTCVIDEOFRAME(ConstructYuy2AllSizes) |
| 170 | // TEST_WEBRTCVIDEOFRAME(ConstructARGBAllSizes) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 171 | TEST_WEBRTCVIDEOFRAME(ConvertToABGRBuffer) |
| 172 | TEST_WEBRTCVIDEOFRAME(ConvertToABGRBufferStride) |
| 173 | TEST_WEBRTCVIDEOFRAME(ConvertToABGRBufferInverted) |
| 174 | TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555Buffer) |
| 175 | TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555BufferStride) |
| 176 | TEST_WEBRTCVIDEOFRAME(ConvertToARGB1555BufferInverted) |
| 177 | TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444Buffer) |
| 178 | TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444BufferStride) |
| 179 | TEST_WEBRTCVIDEOFRAME(ConvertToARGB4444BufferInverted) |
| 180 | TEST_WEBRTCVIDEOFRAME(ConvertToARGBBuffer) |
| 181 | TEST_WEBRTCVIDEOFRAME(ConvertToARGBBufferStride) |
| 182 | TEST_WEBRTCVIDEOFRAME(ConvertToARGBBufferInverted) |
| 183 | TEST_WEBRTCVIDEOFRAME(ConvertToBGRABuffer) |
| 184 | TEST_WEBRTCVIDEOFRAME(ConvertToBGRABufferStride) |
| 185 | TEST_WEBRTCVIDEOFRAME(ConvertToBGRABufferInverted) |
| 186 | TEST_WEBRTCVIDEOFRAME(ConvertToRAWBuffer) |
| 187 | TEST_WEBRTCVIDEOFRAME(ConvertToRAWBufferStride) |
| 188 | TEST_WEBRTCVIDEOFRAME(ConvertToRAWBufferInverted) |
| 189 | TEST_WEBRTCVIDEOFRAME(ConvertToRGB24Buffer) |
| 190 | TEST_WEBRTCVIDEOFRAME(ConvertToRGB24BufferStride) |
| 191 | TEST_WEBRTCVIDEOFRAME(ConvertToRGB24BufferInverted) |
| 192 | TEST_WEBRTCVIDEOFRAME(ConvertToRGB565Buffer) |
| 193 | TEST_WEBRTCVIDEOFRAME(ConvertToRGB565BufferStride) |
| 194 | TEST_WEBRTCVIDEOFRAME(ConvertToRGB565BufferInverted) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | TEST_WEBRTCVIDEOFRAME(ConvertToI400Buffer) |
| 196 | TEST_WEBRTCVIDEOFRAME(ConvertToI400BufferStride) |
| 197 | TEST_WEBRTCVIDEOFRAME(ConvertToI400BufferInverted) |
| 198 | TEST_WEBRTCVIDEOFRAME(ConvertToYUY2Buffer) |
| 199 | TEST_WEBRTCVIDEOFRAME(ConvertToYUY2BufferStride) |
| 200 | TEST_WEBRTCVIDEOFRAME(ConvertToYUY2BufferInverted) |
| 201 | TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBuffer) |
| 202 | TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBufferStride) |
| 203 | TEST_WEBRTCVIDEOFRAME(ConvertToUYVYBufferInverted) |
| 204 | TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBuffer) |
| 205 | TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBufferStride) |
| 206 | TEST_WEBRTCVIDEOFRAME(ConvertFromABGRBufferInverted) |
| 207 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555Buffer) |
| 208 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555BufferStride) |
| 209 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGB1555BufferInverted) |
| 210 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444Buffer) |
| 211 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444BufferStride) |
| 212 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGB4444BufferInverted) |
| 213 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBuffer) |
| 214 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBufferStride) |
| 215 | TEST_WEBRTCVIDEOFRAME(ConvertFromARGBBufferInverted) |
| 216 | TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABuffer) |
| 217 | TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABufferStride) |
| 218 | TEST_WEBRTCVIDEOFRAME(ConvertFromBGRABufferInverted) |
| 219 | TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBuffer) |
| 220 | TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBufferStride) |
| 221 | TEST_WEBRTCVIDEOFRAME(ConvertFromRAWBufferInverted) |
| 222 | TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24Buffer) |
| 223 | TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24BufferStride) |
| 224 | TEST_WEBRTCVIDEOFRAME(ConvertFromRGB24BufferInverted) |
| 225 | TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565Buffer) |
| 226 | TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565BufferStride) |
| 227 | TEST_WEBRTCVIDEOFRAME(ConvertFromRGB565BufferInverted) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 228 | TEST_WEBRTCVIDEOFRAME(ConvertFromI400Buffer) |
| 229 | TEST_WEBRTCVIDEOFRAME(ConvertFromI400BufferStride) |
| 230 | TEST_WEBRTCVIDEOFRAME(ConvertFromI400BufferInverted) |
| 231 | TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2Buffer) |
| 232 | TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferStride) |
| 233 | TEST_WEBRTCVIDEOFRAME(ConvertFromYUY2BufferInverted) |
| 234 | TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBuffer) |
| 235 | TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferStride) |
| 236 | TEST_WEBRTCVIDEOFRAME(ConvertFromUYVYBufferInverted) |
| 237 | // TEST_WEBRTCVIDEOFRAME(ConvertToI422Buffer) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | // TEST_WEBRTCVIDEOFRAME(ConstructARGBBlackWhitePixel) |
| 239 | |
| 240 | TEST_WEBRTCVIDEOFRAME(StretchToFrame) |
| 241 | TEST_WEBRTCVIDEOFRAME(Copy) |
| 242 | TEST_WEBRTCVIDEOFRAME(CopyIsRef) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 243 | |
| 244 | // These functions test implementation-specific details. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | // Tests the Init function with different cropped size. |
| 246 | TEST_F(WebRtcVideoFrameTest, InitEvenSize) { |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 247 | TestInit(640, 360, webrtc::kVideoRotation_0, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(WebRtcVideoFrameTest, InitOddWidth) { |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 251 | TestInit(601, 480, webrtc::kVideoRotation_0, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | TEST_F(WebRtcVideoFrameTest, InitOddHeight) { |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 255 | TestInit(360, 765, webrtc::kVideoRotation_0, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | TEST_F(WebRtcVideoFrameTest, InitOddWidthHeight) { |
perkj@webrtc.org | 1d82813 | 2015-03-03 06:44:06 +0000 | [diff] [blame] | 259 | TestInit(355, 1021, webrtc::kVideoRotation_0, true); |
| 260 | } |
| 261 | |
| 262 | TEST_F(WebRtcVideoFrameTest, InitRotated90ApplyRotation) { |
| 263 | TestInit(640, 360, webrtc::kVideoRotation_90, true); |
| 264 | } |
| 265 | |
| 266 | TEST_F(WebRtcVideoFrameTest, InitRotated90DontApplyRotation) { |
| 267 | TestInit(640, 360, webrtc::kVideoRotation_90, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 268 | } |
magjed@webrtc.org | 1af1391 | 2015-03-06 17:17:18 +0000 | [diff] [blame] | 269 | |
| 270 | TEST_F(WebRtcVideoFrameTest, TextureInitialValues) { |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 271 | webrtc::test::FakeNativeHandle* dummy_handle = |
| 272 | new webrtc::test::FakeNativeHandle(); |
| 273 | webrtc::NativeHandleBuffer* buffer = |
| 274 | new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
| 275 | dummy_handle, 640, 480); |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 276 | // Timestamp is converted from ns to us, so last three digits are lost. |
| 277 | cricket::WebRtcVideoFrame frame(buffer, 20000, webrtc::kVideoRotation_0); |
Per | 9b3f56e | 2015-04-09 13:44:16 +0200 | [diff] [blame] | 278 | EXPECT_EQ(dummy_handle, frame.GetNativeHandle()); |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 279 | EXPECT_EQ(640, frame.width()); |
| 280 | EXPECT_EQ(480, frame.height()); |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 281 | EXPECT_EQ(20000, frame.GetTimeStamp()); |
| 282 | EXPECT_EQ(20, frame.timestamp_us()); |
| 283 | frame.set_timestamp_us(40); |
| 284 | EXPECT_EQ(40000, frame.GetTimeStamp()); |
| 285 | EXPECT_EQ(40, frame.timestamp_us()); |
magjed@webrtc.org | 1af1391 | 2015-03-06 17:17:18 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(WebRtcVideoFrameTest, CopyTextureFrame) { |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 289 | webrtc::test::FakeNativeHandle* dummy_handle = |
| 290 | new webrtc::test::FakeNativeHandle(); |
| 291 | webrtc::NativeHandleBuffer* buffer = |
| 292 | new rtc::RefCountedObject<webrtc::test::FakeNativeHandleBuffer>( |
| 293 | dummy_handle, 640, 480); |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 294 | // Timestamp is converted from ns to us, so last three digits are lost. |
| 295 | cricket::WebRtcVideoFrame frame1(buffer, 20000, webrtc::kVideoRotation_0); |
magjed@webrtc.org | 1af1391 | 2015-03-06 17:17:18 +0000 | [diff] [blame] | 296 | cricket::VideoFrame* frame2 = frame1.Copy(); |
| 297 | EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); |
nisse | 71a0c2f | 2016-04-04 00:57:29 -0700 | [diff] [blame] | 298 | EXPECT_EQ(frame1.width(), frame2->width()); |
| 299 | EXPECT_EQ(frame1.height(), frame2->height()); |
magjed@webrtc.org | 1af1391 | 2015-03-06 17:17:18 +0000 | [diff] [blame] | 300 | EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); |
nisse | b17712f | 2016-04-14 02:29:29 -0700 | [diff] [blame] | 301 | EXPECT_EQ(frame1.timestamp_us(), frame2->timestamp_us()); |
magjed@webrtc.org | 1af1391 | 2015-03-06 17:17:18 +0000 | [diff] [blame] | 302 | delete frame2; |
| 303 | } |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 304 | |
| 305 | TEST_F(WebRtcVideoFrameTest, ApplyRotationToFrame) { |
| 306 | WebRtcVideoTestFrame applied0; |
| 307 | EXPECT_TRUE(IsNull(applied0)); |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 308 | std::unique_ptr<rtc::MemoryStream> ms(CreateYuvSample(kWidth, kHeight, 12)); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 309 | EXPECT_TRUE( |
| 310 | LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, &applied0)); |
| 311 | |
| 312 | // Claim that this frame needs to be rotated for 90 degree. |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 313 | applied0.set_rotation(webrtc::kVideoRotation_90); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 314 | |
| 315 | // Apply rotation on frame 1. Output should be different from frame 1. |
| 316 | WebRtcVideoTestFrame* applied90 = const_cast<WebRtcVideoTestFrame*>( |
| 317 | static_cast<const WebRtcVideoTestFrame*>( |
| 318 | applied0.GetCopyWithRotationApplied())); |
| 319 | EXPECT_TRUE(applied90); |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 320 | EXPECT_EQ(applied90->rotation(), webrtc::kVideoRotation_0); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 321 | EXPECT_FALSE(IsEqual(applied0, *applied90, 0)); |
| 322 | |
| 323 | // Claim the frame 2 needs to be rotated for another 270 degree. The output |
| 324 | // from frame 2 rotation should be the same as frame 1. |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 325 | applied90->set_rotation(webrtc::kVideoRotation_270); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 326 | const cricket::VideoFrame* applied360 = |
| 327 | applied90->GetCopyWithRotationApplied(); |
| 328 | EXPECT_TRUE(applied360); |
nisse | f386876 | 2016-04-13 03:29:16 -0700 | [diff] [blame] | 329 | EXPECT_EQ(applied360->rotation(), webrtc::kVideoRotation_0); |
guoweis@webrtc.org | 00c509a | 2015-03-12 21:37:26 +0000 | [diff] [blame] | 330 | EXPECT_TRUE(IsEqual(applied0, *applied360, 0)); |
| 331 | } |