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

Side by Side Diff: webrtc/media/base/videocapturer_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698