buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47: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. |
buildbot@webrtc.org | 4f0d401 | 2014-08-07 04:47:36 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <vector> |
| 13 | |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 14 | #include "webrtc/base/gunit.h" |
| 15 | #include "webrtc/base/logging.h" |
| 16 | #include "webrtc/base/thread.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 17 | #include "webrtc/media/base/fakevideocapturer.h" |
| 18 | #include "webrtc/media/base/fakevideorenderer.h" |
| 19 | #include "webrtc/media/base/testutils.h" |
| 20 | #include "webrtc/media/base/videocapturer.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | using cricket::FakeVideoCapturer; |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | const int kMsCallbackWait = 500; |
| 27 | // For HD only the height matters. |
| 28 | const int kMinHdHeight = 720; |
perkj | 74622e0 | 2016-02-26 02:54:38 -0800 | [diff] [blame] | 29 | const uint32_t kTimeout = 5000U; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
| 31 | } // namespace |
| 32 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | class VideoCapturerTest |
| 34 | : public sigslot::has_slots<>, |
| 35 | public testing::Test { |
| 36 | public: |
| 37 | VideoCapturerTest() |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 38 | : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | capturer_.SignalStateChange.connect(this, |
| 40 | &VideoCapturerTest::OnStateChange); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 41 | capturer_.AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 42 | } |
| 43 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | protected: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | void OnStateChange(cricket::VideoCapturer*, |
| 46 | cricket::CaptureState capture_state) { |
| 47 | capture_state_ = capture_state; |
| 48 | ++num_state_changes_; |
| 49 | } |
| 50 | cricket::CaptureState capture_state() { return capture_state_; } |
| 51 | int num_state_changes() { return num_state_changes_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | |
| 53 | cricket::FakeVideoCapturer capturer_; |
| 54 | cricket::CaptureState capture_state_; |
| 55 | int num_state_changes_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | cricket::FakeVideoRenderer renderer_; |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 57 | bool expects_rotation_applied_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | TEST_F(VideoCapturerTest, CaptureState) { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 61 | EXPECT_TRUE(capturer_.enable_video_adapter()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |
| 63 | 640, |
| 64 | 480, |
| 65 | cricket::VideoFormat::FpsToInterval(30), |
| 66 | cricket::FOURCC_I420))); |
| 67 | EXPECT_TRUE(capturer_.IsRunning()); |
| 68 | EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 69 | EXPECT_EQ(1, num_state_changes()); |
| 70 | capturer_.Stop(); |
| 71 | EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); |
| 72 | EXPECT_EQ(2, num_state_changes()); |
| 73 | capturer_.Stop(); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 74 | rtc::Thread::Current()->ProcessMessages(100); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | EXPECT_EQ(2, num_state_changes()); |
| 76 | } |
| 77 | |
perkj | 74622e0 | 2016-02-26 02:54:38 -0800 | [diff] [blame] | 78 | TEST_F(VideoCapturerTest, TestRestart) { |
| 79 | EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |
| 80 | 640, |
| 81 | 480, |
| 82 | cricket::VideoFormat::FpsToInterval(30), |
| 83 | cricket::FOURCC_I420))); |
| 84 | EXPECT_TRUE(capturer_.IsRunning()); |
| 85 | EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 86 | EXPECT_EQ(1, num_state_changes()); |
| 87 | EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat( |
| 88 | 320, |
| 89 | 240, |
| 90 | cricket::VideoFormat::FpsToInterval(30), |
| 91 | cricket::FOURCC_I420))); |
| 92 | EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 93 | EXPECT_TRUE(capturer_.IsRunning()); |
| 94 | EXPECT_GE(1, num_state_changes()); |
| 95 | capturer_.Stop(); |
| 96 | rtc::Thread::Current()->ProcessMessages(100); |
| 97 | EXPECT_FALSE(capturer_.IsRunning()); |
| 98 | } |
| 99 | |
| 100 | TEST_F(VideoCapturerTest, TestStartingWithRestart) { |
| 101 | EXPECT_FALSE(capturer_.IsRunning()); |
| 102 | EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat( |
| 103 | 640, |
| 104 | 480, |
| 105 | cricket::VideoFormat::FpsToInterval(30), |
| 106 | cricket::FOURCC_I420))); |
| 107 | EXPECT_TRUE(capturer_.IsRunning()); |
| 108 | EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 109 | } |
| 110 | |
| 111 | TEST_F(VideoCapturerTest, TestRestartWithSameFormat) { |
| 112 | cricket::VideoFormat format(640, 480, |
| 113 | cricket::VideoFormat::FpsToInterval(30), |
| 114 | cricket::FOURCC_I420); |
| 115 | EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(format)); |
| 116 | EXPECT_TRUE(capturer_.IsRunning()); |
| 117 | EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); |
| 118 | EXPECT_EQ(1, num_state_changes()); |
| 119 | EXPECT_TRUE(capturer_.Restart(format)); |
| 120 | EXPECT_EQ(cricket::CS_RUNNING, capture_state()); |
| 121 | EXPECT_TRUE(capturer_.IsRunning()); |
| 122 | EXPECT_EQ(1, num_state_changes()); |
| 123 | } |
| 124 | |
| 125 | TEST_F(VideoCapturerTest, CameraOffOnMute) { |
| 126 | EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |
| 127 | 640, |
| 128 | 480, |
| 129 | cricket::VideoFormat::FpsToInterval(30), |
| 130 | cricket::FOURCC_I420))); |
| 131 | EXPECT_TRUE(capturer_.IsRunning()); |
| 132 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 133 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 134 | EXPECT_EQ(1, renderer_.num_rendered_frames()); |
| 135 | EXPECT_FALSE(capturer_.IsMuted()); |
| 136 | |
| 137 | // Mute the camera and expect black output frame. |
| 138 | capturer_.MuteToBlackThenPause(true); |
| 139 | EXPECT_TRUE(capturer_.IsMuted()); |
| 140 | for (int i = 0; i < 31; ++i) { |
| 141 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 142 | EXPECT_TRUE(renderer_.black_frame()); |
| 143 | } |
| 144 | EXPECT_EQ(32, renderer_.num_rendered_frames()); |
| 145 | EXPECT_EQ_WAIT(cricket::CS_PAUSED, |
| 146 | capturer_.capture_state(), kTimeout); |
| 147 | |
| 148 | // Verify that the camera is off. |
| 149 | EXPECT_FALSE(capturer_.CaptureFrame()); |
| 150 | EXPECT_EQ(32, renderer_.num_rendered_frames()); |
| 151 | |
| 152 | // Unmute the camera and expect non-black output frame. |
| 153 | capturer_.MuteToBlackThenPause(false); |
| 154 | EXPECT_FALSE(capturer_.IsMuted()); |
| 155 | EXPECT_EQ_WAIT(cricket::CS_RUNNING, |
| 156 | capturer_.capture_state(), kTimeout); |
| 157 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 158 | EXPECT_FALSE(renderer_.black_frame()); |
| 159 | EXPECT_EQ(33, renderer_.num_rendered_frames()); |
| 160 | } |
| 161 | |
buildbot@webrtc.org | 53f5793 | 2014-06-16 21:08:51 +0000 | [diff] [blame] | 162 | TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { |
| 163 | capturer_.SetScreencast(true); |
| 164 | |
| 165 | int kWidth = 1281; |
| 166 | int kHeight = 720; |
| 167 | |
| 168 | std::vector<cricket::VideoFormat> formats; |
| 169 | formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
| 170 | cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); |
| 171 | capturer_.ResetSupportedFormats(formats); |
| 172 | |
| 173 | EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |
| 174 | kWidth, |
| 175 | kHeight, |
| 176 | cricket::VideoFormat::FpsToInterval(30), |
| 177 | cricket::FOURCC_ARGB))); |
| 178 | EXPECT_TRUE(capturer_.IsRunning()); |
| 179 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
buildbot@webrtc.org | 53f5793 | 2014-06-16 21:08:51 +0000 | [diff] [blame] | 180 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 181 | EXPECT_EQ(1, renderer_.num_rendered_frames()); |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 182 | EXPECT_EQ(kWidth, renderer_.width()); |
| 183 | EXPECT_EQ(kHeight, renderer_.height()); |
buildbot@webrtc.org | 53f5793 | 2014-06-16 21:08:51 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 186 | TEST_F(VideoCapturerTest, TestRotationAppliedBySource) { |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 187 | int kWidth = 800; |
| 188 | int kHeight = 400; |
| 189 | int frame_count = 0; |
| 190 | |
| 191 | std::vector<cricket::VideoFormat> formats; |
| 192 | formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
| 193 | cricket::VideoFormat::FpsToInterval(5), |
| 194 | cricket::FOURCC_I420)); |
| 195 | |
| 196 | capturer_.ResetSupportedFormats(formats); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 197 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 198 | // capturer_ should compensate rotation as default. |
perkj | 74622e0 | 2016-02-26 02:54:38 -0800 | [diff] [blame] | 199 | capturer_.UpdateAspectRatio(400, 200); |
| 200 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 201 | EXPECT_EQ(cricket::CS_RUNNING, |
| 202 | capturer_.Start(cricket::VideoFormat( |
| 203 | kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |
| 204 | cricket::FOURCC_I420))); |
| 205 | EXPECT_TRUE(capturer_.IsRunning()); |
| 206 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 207 | |
| 208 | // If the frame's rotation is compensated anywhere in the pipeline based on |
| 209 | // the rotation information, the renderer should be given the right dimension |
| 210 | // such that the frame could be rendered. |
| 211 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 212 | capturer_.SetRotation(webrtc::kVideoRotation_90); |
| 213 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 214 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 215 | // Swapped width and height |
| 216 | EXPECT_EQ(kWidth, renderer_.height()); |
| 217 | EXPECT_EQ(kHeight, renderer_.width()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 218 | EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 219 | |
| 220 | capturer_.SetRotation(webrtc::kVideoRotation_270); |
| 221 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 222 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 223 | // Swapped width and height |
| 224 | EXPECT_EQ(kWidth, renderer_.height()); |
| 225 | EXPECT_EQ(kHeight, renderer_.width()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 226 | EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 227 | |
| 228 | capturer_.SetRotation(webrtc::kVideoRotation_180); |
| 229 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 230 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 231 | // Back to normal width and height |
| 232 | EXPECT_EQ(kWidth, renderer_.width()); |
| 233 | EXPECT_EQ(kHeight, renderer_.height()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 234 | EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 237 | TEST_F(VideoCapturerTest, TestRotationAppliedBySink) { |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 238 | int kWidth = 800; |
| 239 | int kHeight = 400; |
| 240 | |
| 241 | std::vector<cricket::VideoFormat> formats; |
| 242 | formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
| 243 | cricket::VideoFormat::FpsToInterval(5), |
| 244 | cricket::FOURCC_I420)); |
| 245 | |
| 246 | capturer_.ResetSupportedFormats(formats); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 247 | rtc::VideoSinkWants wants; |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 248 | // capturer_ should not compensate rotation. |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 249 | wants.rotation_applied = false; |
| 250 | capturer_.AddOrUpdateSink(&renderer_, wants); |
| 251 | |
perkj | 74622e0 | 2016-02-26 02:54:38 -0800 | [diff] [blame] | 252 | capturer_.UpdateAspectRatio(400, 200); |
| 253 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 254 | EXPECT_EQ(cricket::CS_RUNNING, |
| 255 | capturer_.Start(cricket::VideoFormat( |
| 256 | kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |
| 257 | cricket::FOURCC_I420))); |
| 258 | EXPECT_TRUE(capturer_.IsRunning()); |
| 259 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 260 | |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 261 | // If the frame's rotation is compensated anywhere in the pipeline, the frame |
| 262 | // won't have its original dimension out from capturer. Since the renderer |
| 263 | // here has the same dimension as the capturer, it will skip that frame as the |
| 264 | // resolution won't match anymore. |
| 265 | |
| 266 | int frame_count = 0; |
| 267 | capturer_.SetRotation(webrtc::kVideoRotation_0); |
| 268 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 269 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 270 | EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 271 | |
| 272 | capturer_.SetRotation(webrtc::kVideoRotation_90); |
| 273 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 274 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 275 | EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 276 | |
| 277 | capturer_.SetRotation(webrtc::kVideoRotation_180); |
| 278 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 279 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 280 | EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 281 | |
| 282 | capturer_.SetRotation(webrtc::kVideoRotation_270); |
| 283 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 284 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 285 | EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); |
| 286 | } |
| 287 | |
| 288 | TEST_F(VideoCapturerTest, TestRotationAppliedBySourceWhenDifferentWants) { |
| 289 | int kWidth = 800; |
| 290 | int kHeight = 400; |
| 291 | |
| 292 | std::vector<cricket::VideoFormat> formats; |
| 293 | formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
| 294 | cricket::VideoFormat::FpsToInterval(5), |
| 295 | cricket::FOURCC_I420)); |
| 296 | |
| 297 | capturer_.ResetSupportedFormats(formats); |
| 298 | rtc::VideoSinkWants wants; |
| 299 | // capturer_ should not compensate rotation. |
| 300 | wants.rotation_applied = false; |
| 301 | capturer_.AddOrUpdateSink(&renderer_, wants); |
| 302 | |
perkj | 74622e0 | 2016-02-26 02:54:38 -0800 | [diff] [blame] | 303 | capturer_.UpdateAspectRatio(400, 200); |
| 304 | |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 305 | EXPECT_EQ(cricket::CS_RUNNING, |
| 306 | capturer_.Start(cricket::VideoFormat( |
| 307 | kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |
| 308 | cricket::FOURCC_I420))); |
| 309 | EXPECT_TRUE(capturer_.IsRunning()); |
| 310 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 311 | |
| 312 | int frame_count = 0; |
| 313 | capturer_.SetRotation(webrtc::kVideoRotation_90); |
| 314 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 315 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
| 316 | EXPECT_EQ(capturer_.GetRotation(), renderer_.rotation()); |
| 317 | |
| 318 | // Add another sink that wants frames to be rotated. |
| 319 | cricket::FakeVideoRenderer renderer2; |
| 320 | wants.rotation_applied = true; |
| 321 | capturer_.AddOrUpdateSink(&renderer2, wants); |
| 322 | |
| 323 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 324 | EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |
| 325 | EXPECT_EQ(1, renderer2.num_rendered_frames()); |
| 326 | EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); |
| 327 | EXPECT_EQ(webrtc::kVideoRotation_0, renderer2.rotation()); |
guoweis@webrtc.org | 1226e92 | 2015-02-11 18:37:54 +0000 | [diff] [blame] | 328 | } |
| 329 | |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame^] | 330 | TEST_F(VideoCapturerTest, SinkWantsMaxPixelAndMaxPixelCountStepUp) { |
| 331 | EXPECT_EQ(cricket::CS_RUNNING, |
| 332 | capturer_.Start(cricket::VideoFormat( |
| 333 | 1280, 720, cricket::VideoFormat::FpsToInterval(30), |
| 334 | cricket::FOURCC_I420))); |
| 335 | EXPECT_TRUE(capturer_.IsRunning()); |
| 336 | |
| 337 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 338 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 339 | EXPECT_EQ(1, renderer_.num_rendered_frames()); |
| 340 | EXPECT_EQ(1280, renderer_.width()); |
| 341 | EXPECT_EQ(720, renderer_.height()); |
| 342 | |
| 343 | // Request a lower resolution. |
| 344 | rtc::VideoSinkWants wants; |
| 345 | wants.max_pixel_count = rtc::Optional<int>(1280 * 720 / 2); |
| 346 | capturer_.AddOrUpdateSink(&renderer_, wants); |
| 347 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 348 | EXPECT_EQ(2, renderer_.num_rendered_frames()); |
| 349 | EXPECT_EQ(960, renderer_.width()); |
| 350 | EXPECT_EQ(540, renderer_.height()); |
| 351 | |
| 352 | // Request a lower resolution. |
| 353 | wants.max_pixel_count = |
| 354 | rtc::Optional<int>(renderer_.width() * renderer_.height() / 2); |
| 355 | capturer_.AddOrUpdateSink(&renderer_, wants); |
| 356 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 357 | EXPECT_EQ(3, renderer_.num_rendered_frames()); |
| 358 | EXPECT_EQ(640, renderer_.width()); |
| 359 | EXPECT_EQ(360, renderer_.height()); |
| 360 | |
| 361 | // Adding a new renderer should not affect resolution. |
| 362 | cricket::FakeVideoRenderer renderer2; |
| 363 | capturer_.AddOrUpdateSink(&renderer2, rtc::VideoSinkWants()); |
| 364 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 365 | EXPECT_EQ(4, renderer_.num_rendered_frames()); |
| 366 | EXPECT_EQ(640, renderer_.width()); |
| 367 | EXPECT_EQ(360, renderer_.height()); |
| 368 | EXPECT_EQ(1, renderer2.num_rendered_frames()); |
| 369 | EXPECT_EQ(640, renderer2.width()); |
| 370 | EXPECT_EQ(360, renderer2.height()); |
| 371 | |
| 372 | // Request higher resolution. |
| 373 | wants.max_pixel_count_step_up = wants.max_pixel_count; |
| 374 | wants.max_pixel_count = rtc::Optional<int>(); |
| 375 | capturer_.AddOrUpdateSink(&renderer_, wants); |
| 376 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 377 | EXPECT_EQ(5, renderer_.num_rendered_frames()); |
| 378 | EXPECT_EQ(960, renderer_.width()); |
| 379 | EXPECT_EQ(540, renderer_.height()); |
| 380 | EXPECT_EQ(2, renderer2.num_rendered_frames()); |
| 381 | EXPECT_EQ(960, renderer2.width()); |
| 382 | EXPECT_EQ(540, renderer2.height()); |
| 383 | |
| 384 | // Updating with no wants should not affect resolution. |
| 385 | capturer_.AddOrUpdateSink(&renderer2, rtc::VideoSinkWants()); |
| 386 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 387 | EXPECT_EQ(6, renderer_.num_rendered_frames()); |
| 388 | EXPECT_EQ(960, renderer_.width()); |
| 389 | EXPECT_EQ(540, renderer_.height()); |
| 390 | EXPECT_EQ(3, renderer2.num_rendered_frames()); |
| 391 | EXPECT_EQ(960, renderer2.width()); |
| 392 | EXPECT_EQ(540, renderer2.height()); |
| 393 | } |
| 394 | |
buildbot@webrtc.org | 53f5793 | 2014-06-16 21:08:51 +0000 | [diff] [blame] | 395 | TEST_F(VideoCapturerTest, ScreencastScaledSuperLarge) { |
| 396 | capturer_.SetScreencast(true); |
| 397 | |
| 398 | const int kMaxWidth = 4096; |
| 399 | const int kMaxHeight = 3072; |
| 400 | int kWidth = kMaxWidth + 4; |
| 401 | int kHeight = kMaxHeight + 4; |
| 402 | |
| 403 | std::vector<cricket::VideoFormat> formats; |
| 404 | formats.push_back(cricket::VideoFormat(kWidth, kHeight, |
| 405 | cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); |
| 406 | capturer_.ResetSupportedFormats(formats); |
| 407 | |
| 408 | EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |
| 409 | kWidth, |
| 410 | kHeight, |
| 411 | cricket::VideoFormat::FpsToInterval(30), |
| 412 | cricket::FOURCC_ARGB))); |
| 413 | EXPECT_TRUE(capturer_.IsRunning()); |
| 414 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
buildbot@webrtc.org | 53f5793 | 2014-06-16 21:08:51 +0000 | [diff] [blame] | 415 | EXPECT_TRUE(capturer_.CaptureFrame()); |
| 416 | EXPECT_EQ(1, renderer_.num_rendered_frames()); |
nisse | c4c8485 | 2016-01-19 00:52:47 -0800 | [diff] [blame] | 417 | EXPECT_EQ(kWidth / 2, renderer_.width()); |
| 418 | EXPECT_EQ(kHeight / 2, renderer_.height()); |
buildbot@webrtc.org | 53f5793 | 2014-06-16 21:08:51 +0000 | [diff] [blame] | 419 | } |
mallinath@webrtc.org | 1b15f42 | 2013-09-06 22:56:28 +0000 | [diff] [blame] | 420 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 421 | TEST_F(VideoCapturerTest, TestFourccMatch) { |
| 422 | cricket::VideoFormat desired(640, 480, |
| 423 | cricket::VideoFormat::FpsToInterval(30), |
| 424 | cricket::FOURCC_ANY); |
| 425 | cricket::VideoFormat best; |
| 426 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 427 | EXPECT_EQ(640, best.width); |
| 428 | EXPECT_EQ(480, best.height); |
| 429 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 430 | |
| 431 | desired.fourcc = cricket::FOURCC_MJPG; |
| 432 | EXPECT_FALSE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 433 | |
| 434 | desired.fourcc = cricket::FOURCC_I420; |
| 435 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 436 | } |
| 437 | |
| 438 | TEST_F(VideoCapturerTest, TestResolutionMatch) { |
| 439 | cricket::VideoFormat desired(1920, 1080, |
| 440 | cricket::VideoFormat::FpsToInterval(30), |
| 441 | cricket::FOURCC_ANY); |
| 442 | cricket::VideoFormat best; |
| 443 | // Ask for 1920x1080. Get HD 1280x720 which is the highest. |
| 444 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 445 | EXPECT_EQ(1280, best.width); |
| 446 | EXPECT_EQ(720, best.height); |
| 447 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 448 | |
| 449 | desired.width = 360; |
| 450 | desired.height = 250; |
| 451 | // Ask for a little higher than QVGA. Get QVGA. |
| 452 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 453 | EXPECT_EQ(320, best.width); |
| 454 | EXPECT_EQ(240, best.height); |
| 455 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 456 | |
| 457 | desired.width = 480; |
magjed@webrtc.org | 35c1ace | 2014-11-13 16:21:49 +0000 | [diff] [blame] | 458 | desired.height = 270; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | // Ask for HVGA. Get VGA. |
| 460 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 461 | EXPECT_EQ(640, best.width); |
| 462 | EXPECT_EQ(480, best.height); |
| 463 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 464 | |
| 465 | desired.width = 320; |
| 466 | desired.height = 240; |
| 467 | // Ask for QVGA. Get QVGA. |
| 468 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 469 | EXPECT_EQ(320, best.width); |
| 470 | EXPECT_EQ(240, best.height); |
| 471 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 472 | |
| 473 | desired.width = 80; |
| 474 | desired.height = 60; |
| 475 | // Ask for lower than QQVGA. Get QQVGA, which is the lowest. |
| 476 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 477 | EXPECT_EQ(160, best.width); |
| 478 | EXPECT_EQ(120, best.height); |
| 479 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 480 | } |
| 481 | |
| 482 | TEST_F(VideoCapturerTest, TestHDResolutionMatch) { |
| 483 | // Add some HD formats typical of a mediocre HD webcam. |
| 484 | std::vector<cricket::VideoFormat> formats; |
| 485 | formats.push_back(cricket::VideoFormat(320, 240, |
| 486 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 487 | formats.push_back(cricket::VideoFormat(640, 480, |
| 488 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 489 | formats.push_back(cricket::VideoFormat(960, 544, |
| 490 | cricket::VideoFormat::FpsToInterval(24), cricket::FOURCC_I420)); |
| 491 | formats.push_back(cricket::VideoFormat(1280, 720, |
| 492 | cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); |
| 493 | formats.push_back(cricket::VideoFormat(2592, 1944, |
| 494 | cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); |
| 495 | capturer_.ResetSupportedFormats(formats); |
| 496 | |
| 497 | cricket::VideoFormat desired(960, 720, |
| 498 | cricket::VideoFormat::FpsToInterval(30), |
| 499 | cricket::FOURCC_ANY); |
| 500 | cricket::VideoFormat best; |
| 501 | // Ask for 960x720 30 fps. Get qHD 24 fps |
| 502 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 503 | EXPECT_EQ(960, best.width); |
| 504 | EXPECT_EQ(544, best.height); |
| 505 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); |
| 506 | |
| 507 | desired.width = 960; |
| 508 | desired.height = 544; |
| 509 | desired.interval = cricket::VideoFormat::FpsToInterval(30); |
| 510 | // Ask for qHD 30 fps. Get qHD 24 fps |
| 511 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 512 | EXPECT_EQ(960, best.width); |
| 513 | EXPECT_EQ(544, best.height); |
| 514 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); |
| 515 | |
| 516 | desired.width = 360; |
| 517 | desired.height = 250; |
| 518 | desired.interval = cricket::VideoFormat::FpsToInterval(30); |
| 519 | // Ask for a little higher than QVGA. Get QVGA. |
| 520 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 521 | EXPECT_EQ(320, best.width); |
| 522 | EXPECT_EQ(240, best.height); |
| 523 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 524 | |
| 525 | desired.width = 480; |
| 526 | desired.height = 270; |
| 527 | // Ask for HVGA. Get VGA. |
| 528 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 529 | EXPECT_EQ(640, best.width); |
| 530 | EXPECT_EQ(480, best.height); |
| 531 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 532 | |
| 533 | desired.width = 320; |
| 534 | desired.height = 240; |
| 535 | // Ask for QVGA. Get QVGA. |
| 536 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 537 | EXPECT_EQ(320, best.width); |
| 538 | EXPECT_EQ(240, best.height); |
| 539 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 540 | |
| 541 | desired.width = 160; |
| 542 | desired.height = 120; |
| 543 | // Ask for lower than QVGA. Get QVGA, which is the lowest. |
| 544 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 545 | EXPECT_EQ(320, best.width); |
| 546 | EXPECT_EQ(240, best.height); |
| 547 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 548 | |
| 549 | desired.width = 1280; |
| 550 | desired.height = 720; |
| 551 | // Ask for HD. 720p fps is too low. Get VGA which has 30 fps. |
| 552 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 553 | EXPECT_EQ(640, best.width); |
| 554 | EXPECT_EQ(480, best.height); |
| 555 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 556 | |
| 557 | desired.width = 1280; |
| 558 | desired.height = 720; |
| 559 | desired.interval = cricket::VideoFormat::FpsToInterval(15); |
| 560 | // Ask for HD 15 fps. Fps matches. Get HD |
| 561 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 562 | EXPECT_EQ(1280, best.width); |
| 563 | EXPECT_EQ(720, best.height); |
| 564 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); |
| 565 | |
| 566 | desired.width = 1920; |
| 567 | desired.height = 1080; |
| 568 | desired.interval = cricket::VideoFormat::FpsToInterval(30); |
| 569 | // Ask for 1080p. Fps of HD formats is too low. Get VGA which can do 30 fps. |
| 570 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |
| 571 | EXPECT_EQ(640, best.width); |
| 572 | EXPECT_EQ(480, best.height); |
| 573 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 574 | } |
| 575 | |
| 576 | // Some cameras support 320x240 and 320x640. Verify we choose 320x240. |
| 577 | TEST_F(VideoCapturerTest, TestStrangeFormats) { |
| 578 | std::vector<cricket::VideoFormat> supported_formats; |
| 579 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 580 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 581 | supported_formats.push_back(cricket::VideoFormat(320, 640, |
| 582 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 583 | capturer_.ResetSupportedFormats(supported_formats); |
| 584 | |
| 585 | std::vector<cricket::VideoFormat> required_formats; |
| 586 | required_formats.push_back(cricket::VideoFormat(320, 240, |
| 587 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 588 | required_formats.push_back(cricket::VideoFormat(320, 200, |
| 589 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 590 | required_formats.push_back(cricket::VideoFormat(320, 180, |
| 591 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 592 | cricket::VideoFormat best; |
| 593 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 594 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 595 | EXPECT_EQ(320, best.width); |
| 596 | EXPECT_EQ(240, best.height); |
| 597 | } |
| 598 | |
| 599 | supported_formats.clear(); |
| 600 | supported_formats.push_back(cricket::VideoFormat(320, 640, |
| 601 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 602 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 603 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 604 | capturer_.ResetSupportedFormats(supported_formats); |
| 605 | |
| 606 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 607 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 608 | EXPECT_EQ(320, best.width); |
| 609 | EXPECT_EQ(240, best.height); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | // Some cameras only have very low fps. Verify we choose something sensible. |
| 614 | TEST_F(VideoCapturerTest, TestPoorFpsFormats) { |
| 615 | // all formats are low framerate |
| 616 | std::vector<cricket::VideoFormat> supported_formats; |
| 617 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 618 | cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); |
| 619 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 620 | cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); |
| 621 | supported_formats.push_back(cricket::VideoFormat(1280, 720, |
| 622 | cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); |
| 623 | capturer_.ResetSupportedFormats(supported_formats); |
| 624 | |
| 625 | std::vector<cricket::VideoFormat> required_formats; |
| 626 | required_formats.push_back(cricket::VideoFormat(320, 240, |
| 627 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 628 | required_formats.push_back(cricket::VideoFormat(640, 480, |
| 629 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 630 | cricket::VideoFormat best; |
| 631 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 632 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 633 | EXPECT_EQ(required_formats[i].width, best.width); |
| 634 | EXPECT_EQ(required_formats[i].height, best.height); |
| 635 | } |
| 636 | |
| 637 | // Increase framerate of 320x240. Expect low fps VGA avoided. |
| 638 | supported_formats.clear(); |
| 639 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 640 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 641 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 642 | cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); |
| 643 | supported_formats.push_back(cricket::VideoFormat(1280, 720, |
| 644 | cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); |
| 645 | capturer_.ResetSupportedFormats(supported_formats); |
| 646 | |
| 647 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 648 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 649 | EXPECT_EQ(320, best.width); |
| 650 | EXPECT_EQ(240, best.height); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | // Some cameras support same size with different frame rates. Verify we choose |
| 655 | // the frame rate properly. |
| 656 | TEST_F(VideoCapturerTest, TestSameSizeDifferentFpsFormats) { |
| 657 | std::vector<cricket::VideoFormat> supported_formats; |
| 658 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 659 | cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); |
| 660 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 661 | cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_I420)); |
| 662 | supported_formats.push_back(cricket::VideoFormat(320, 240, |
| 663 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 664 | capturer_.ResetSupportedFormats(supported_formats); |
| 665 | |
| 666 | std::vector<cricket::VideoFormat> required_formats = supported_formats; |
| 667 | cricket::VideoFormat best; |
| 668 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 669 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 670 | EXPECT_EQ(320, best.width); |
| 671 | EXPECT_EQ(240, best.height); |
| 672 | EXPECT_EQ(required_formats[i].interval, best.interval); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // Some cameras support the correct resolution but at a lower fps than |
| 677 | // we'd like. This tests we get the expected resolution and fps. |
| 678 | TEST_F(VideoCapturerTest, TestFpsFormats) { |
| 679 | // We have VGA but low fps. Choose VGA, not HD |
| 680 | std::vector<cricket::VideoFormat> supported_formats; |
| 681 | supported_formats.push_back(cricket::VideoFormat(1280, 720, |
| 682 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 683 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 684 | cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); |
| 685 | supported_formats.push_back(cricket::VideoFormat(640, 400, |
| 686 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 687 | supported_formats.push_back(cricket::VideoFormat(640, 360, |
| 688 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 689 | capturer_.ResetSupportedFormats(supported_formats); |
| 690 | |
| 691 | std::vector<cricket::VideoFormat> required_formats; |
| 692 | required_formats.push_back(cricket::VideoFormat(640, 480, |
| 693 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY)); |
| 694 | required_formats.push_back(cricket::VideoFormat(640, 480, |
| 695 | cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_ANY)); |
| 696 | required_formats.push_back(cricket::VideoFormat(640, 480, |
| 697 | cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_ANY)); |
| 698 | cricket::VideoFormat best; |
| 699 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 700 | // Expect 30 fps to choose 30 fps format. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 701 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[0], &best)); |
| 702 | EXPECT_EQ(640, best.width); |
| 703 | EXPECT_EQ(400, best.height); |
| 704 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
| 705 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 706 | // Expect 20 fps to choose 30 fps format. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 707 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[1], &best)); |
| 708 | EXPECT_EQ(640, best.width); |
| 709 | EXPECT_EQ(400, best.height); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 710 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 712 | // Expect 10 fps to choose 15 fps format and set fps to 15. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 713 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best)); |
| 714 | EXPECT_EQ(640, best.width); |
| 715 | EXPECT_EQ(480, best.height); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 716 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 717 | |
| 718 | // We have VGA 60 fps and 15 fps. Choose best fps. |
| 719 | supported_formats.clear(); |
| 720 | supported_formats.push_back(cricket::VideoFormat(1280, 720, |
| 721 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 722 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 723 | cricket::VideoFormat::FpsToInterval(60), cricket::FOURCC_MJPG)); |
| 724 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 725 | cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); |
| 726 | supported_formats.push_back(cricket::VideoFormat(640, 400, |
| 727 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 728 | supported_formats.push_back(cricket::VideoFormat(640, 360, |
| 729 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 730 | capturer_.ResetSupportedFormats(supported_formats); |
| 731 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 732 | // Expect 30 fps to choose 60 fps format and will set best fps to 60. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 733 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[0], &best)); |
| 734 | EXPECT_EQ(640, best.width); |
| 735 | EXPECT_EQ(480, best.height); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 736 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 737 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 738 | // Expect 20 fps to choose 60 fps format, and will set best fps to 60. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 739 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[1], &best)); |
| 740 | EXPECT_EQ(640, best.width); |
| 741 | EXPECT_EQ(480, best.height); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 742 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 743 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 744 | // Expect 10 fps to choose 15 fps. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 745 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best)); |
| 746 | EXPECT_EQ(640, best.width); |
| 747 | EXPECT_EQ(480, best.height); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 748 | EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | TEST_F(VideoCapturerTest, TestRequest16x10_9) { |
| 752 | std::vector<cricket::VideoFormat> supported_formats; |
| 753 | // We do not support HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. |
| 754 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 755 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 756 | supported_formats.push_back(cricket::VideoFormat(640, 400, |
| 757 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 758 | supported_formats.push_back(cricket::VideoFormat(640, 360, |
| 759 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 760 | capturer_.ResetSupportedFormats(supported_formats); |
| 761 | |
| 762 | std::vector<cricket::VideoFormat> required_formats = supported_formats; |
| 763 | cricket::VideoFormat best; |
| 764 | // Expect 4x3, 16x10, and 16x9 requests are respected. |
| 765 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 766 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 767 | EXPECT_EQ(required_formats[i].width, best.width); |
| 768 | EXPECT_EQ(required_formats[i].height, best.height); |
| 769 | } |
| 770 | |
| 771 | // We do not support 16x9 HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. |
| 772 | supported_formats.clear(); |
| 773 | supported_formats.push_back(cricket::VideoFormat(960, 720, |
| 774 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 775 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 776 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 777 | supported_formats.push_back(cricket::VideoFormat(640, 400, |
| 778 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 779 | supported_formats.push_back(cricket::VideoFormat(640, 360, |
| 780 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 781 | capturer_.ResetSupportedFormats(supported_formats); |
| 782 | |
| 783 | // Expect 4x3, 16x10, and 16x9 requests are respected. |
| 784 | for (size_t i = 0; i < required_formats.size(); ++i) { |
| 785 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 786 | EXPECT_EQ(required_formats[i].width, best.width); |
| 787 | EXPECT_EQ(required_formats[i].height, best.height); |
| 788 | } |
| 789 | |
| 790 | // We support 16x9HD, Expect 4x3, 16x10, and 16x9 requests are respected. |
| 791 | supported_formats.clear(); |
| 792 | supported_formats.push_back(cricket::VideoFormat(1280, 720, |
| 793 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 794 | supported_formats.push_back(cricket::VideoFormat(640, 480, |
| 795 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 796 | supported_formats.push_back(cricket::VideoFormat(640, 400, |
| 797 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 798 | supported_formats.push_back(cricket::VideoFormat(640, 360, |
| 799 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 800 | capturer_.ResetSupportedFormats(supported_formats); |
| 801 | |
| 802 | // Expect 4x3 for 4x3 and 16x10 requests. |
| 803 | for (size_t i = 0; i < required_formats.size() - 1; ++i) { |
| 804 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best)); |
| 805 | EXPECT_EQ(required_formats[i].width, best.width); |
| 806 | EXPECT_EQ(required_formats[i].height, best.height); |
| 807 | } |
| 808 | |
| 809 | // Expect 16x9 for 16x9 request. |
| 810 | EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best)); |
| 811 | EXPECT_EQ(640, best.width); |
| 812 | EXPECT_EQ(360, best.height); |
| 813 | } |
| 814 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 815 | bool HdFormatInList(const std::vector<cricket::VideoFormat>& formats) { |
| 816 | for (std::vector<cricket::VideoFormat>::const_iterator found = |
| 817 | formats.begin(); found != formats.end(); ++found) { |
| 818 | if (found->height >= kMinHdHeight) { |
| 819 | return true; |
| 820 | } |
| 821 | } |
| 822 | return false; |
| 823 | } |
| 824 | |
| 825 | TEST_F(VideoCapturerTest, Whitelist) { |
| 826 | // The definition of HD only applies to the height. Set the HD width to the |
| 827 | // smallest legal number to document this fact in this test. |
| 828 | const int kMinHdWidth = 1; |
| 829 | cricket::VideoFormat hd_format(kMinHdWidth, |
| 830 | kMinHdHeight, |
| 831 | cricket::VideoFormat::FpsToInterval(30), |
| 832 | cricket::FOURCC_I420); |
| 833 | cricket::VideoFormat vga_format(640, 480, |
| 834 | cricket::VideoFormat::FpsToInterval(30), |
| 835 | cricket::FOURCC_I420); |
| 836 | std::vector<cricket::VideoFormat> formats = *capturer_.GetSupportedFormats(); |
| 837 | formats.push_back(hd_format); |
| 838 | |
| 839 | // Enable whitelist. Expect HD not in list. |
| 840 | capturer_.set_enable_camera_list(true); |
| 841 | capturer_.ResetSupportedFormats(formats); |
| 842 | EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats())); |
| 843 | capturer_.ConstrainSupportedFormats(vga_format); |
| 844 | EXPECT_FALSE(HdFormatInList(*capturer_.GetSupportedFormats())); |
| 845 | |
| 846 | // Disable whitelist. Expect HD in list. |
| 847 | capturer_.set_enable_camera_list(false); |
| 848 | capturer_.ResetSupportedFormats(formats); |
| 849 | EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats())); |
| 850 | capturer_.ConstrainSupportedFormats(vga_format); |
| 851 | EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats())); |
| 852 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 +0000 | [diff] [blame] | 853 | |
| 854 | TEST_F(VideoCapturerTest, BlacklistAllFormats) { |
| 855 | cricket::VideoFormat vga_format(640, 480, |
| 856 | cricket::VideoFormat::FpsToInterval(30), |
| 857 | cricket::FOURCC_I420); |
| 858 | std::vector<cricket::VideoFormat> supported_formats; |
| 859 | // Mock a device that only supports HD formats. |
| 860 | supported_formats.push_back(cricket::VideoFormat(1280, 720, |
| 861 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 862 | supported_formats.push_back(cricket::VideoFormat(1920, 1080, |
| 863 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 864 | capturer_.ResetSupportedFormats(supported_formats); |
| 865 | EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); |
| 866 | // Now, enable the list, which would exclude both formats. However, since |
| 867 | // only HD formats are available, we refuse to filter at all, so we don't |
| 868 | // break this camera. |
| 869 | capturer_.set_enable_camera_list(true); |
| 870 | capturer_.ConstrainSupportedFormats(vga_format); |
| 871 | EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); |
| 872 | // To make sure it's not just the camera list being broken, add in VGA and |
| 873 | // try again. This time, only the VGA format should be there. |
| 874 | supported_formats.push_back(vga_format); |
| 875 | capturer_.ResetSupportedFormats(supported_formats); |
| 876 | ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size()); |
| 877 | EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height); |
| 878 | } |