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