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

Side by Side Diff: media/video/capture/video_capture_device_unittest.cc

Issue 541163002: Clarify resolution change behaviors of video capture devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 EXPECT_TRUE(device == NULL); 225 EXPECT_TRUE(device == NULL);
226 } else { 226 } else {
227 // The presence of the actual device is only checked on AllocateAndStart() 227 // The presence of the actual device is only checked on AllocateAndStart()
228 // and not on creation for QTKit API in Mac OS X platform. 228 // and not on creation for QTKit API in Mac OS X platform.
229 EXPECT_CALL(*client_, OnErr()).Times(1); 229 EXPECT_CALL(*client_, OnErr()).Times(1);
230 230
231 VideoCaptureParams capture_params; 231 VideoCaptureParams capture_params;
232 capture_params.requested_format.frame_size.SetSize(640, 480); 232 capture_params.requested_format.frame_size.SetSize(640, 480);
233 capture_params.requested_format.frame_rate = 30; 233 capture_params.requested_format.frame_rate = 30;
234 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 234 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
235 capture_params.allow_resolution_change = false;
236 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 235 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
237 device->StopAndDeAllocate(); 236 device->StopAndDeAllocate();
238 } 237 }
239 #endif 238 #endif
240 } 239 }
241 240
242 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { 241 TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
243 names_ = EnumerateDevices(); 242 names_ = EnumerateDevices();
244 if (!names_->size()) { 243 if (!names_->size()) {
245 DVLOG(1) << "No camera available. Exiting test."; 244 DVLOG(1) << "No camera available. Exiting test.";
246 return; 245 return;
247 } 246 }
248 247
249 scoped_ptr<VideoCaptureDevice> device( 248 scoped_ptr<VideoCaptureDevice> device(
250 video_capture_device_factory_->Create(names_->front())); 249 video_capture_device_factory_->Create(names_->front()));
251 ASSERT_TRUE(device); 250 ASSERT_TRUE(device);
252 DVLOG(1) << names_->front().id(); 251 DVLOG(1) << names_->front().id();
253 252
254 EXPECT_CALL(*client_, OnErr()) 253 EXPECT_CALL(*client_, OnErr())
255 .Times(0); 254 .Times(0);
256 255
257 VideoCaptureParams capture_params; 256 VideoCaptureParams capture_params;
258 capture_params.requested_format.frame_size.SetSize(640, 480); 257 capture_params.requested_format.frame_size.SetSize(640, 480);
259 capture_params.requested_format.frame_rate = 30; 258 capture_params.requested_format.frame_rate = 30;
260 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 259 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
261 capture_params.allow_resolution_change = false;
262 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 260 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
263 // Get captured video frames. 261 // Get captured video frames.
264 WaitForCapturedFrame(); 262 WaitForCapturedFrame();
265 EXPECT_EQ(last_format().frame_size.width(), 640); 263 EXPECT_EQ(last_format().frame_size.width(), 640);
266 EXPECT_EQ(last_format().frame_size.height(), 480); 264 EXPECT_EQ(last_format().frame_size.height(), 480);
267 device->StopAndDeAllocate(); 265 device->StopAndDeAllocate();
268 } 266 }
269 267
270 TEST_F(VideoCaptureDeviceTest, Capture720p) { 268 TEST_F(VideoCaptureDeviceTest, Capture720p) {
271 names_ = EnumerateDevices(); 269 names_ = EnumerateDevices();
272 if (!names_->size()) { 270 if (!names_->size()) {
273 DVLOG(1) << "No camera available. Exiting test."; 271 DVLOG(1) << "No camera available. Exiting test.";
274 return; 272 return;
275 } 273 }
276 274
277 scoped_ptr<VideoCaptureDevice> device( 275 scoped_ptr<VideoCaptureDevice> device(
278 video_capture_device_factory_->Create(names_->front())); 276 video_capture_device_factory_->Create(names_->front()));
279 ASSERT_TRUE(device); 277 ASSERT_TRUE(device);
280 278
281 EXPECT_CALL(*client_, OnErr()) 279 EXPECT_CALL(*client_, OnErr())
282 .Times(0); 280 .Times(0);
283 281
284 VideoCaptureParams capture_params; 282 VideoCaptureParams capture_params;
285 capture_params.requested_format.frame_size.SetSize(1280, 720); 283 capture_params.requested_format.frame_size.SetSize(1280, 720);
286 capture_params.requested_format.frame_rate = 30; 284 capture_params.requested_format.frame_rate = 30;
287 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 285 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
288 capture_params.allow_resolution_change = false;
289 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 286 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
290 // Get captured video frames. 287 // Get captured video frames.
291 WaitForCapturedFrame(); 288 WaitForCapturedFrame();
292 device->StopAndDeAllocate(); 289 device->StopAndDeAllocate();
293 } 290 }
294 291
295 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 292 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
296 names_ = EnumerateDevices(); 293 names_ = EnumerateDevices();
297 if (!names_->size()) { 294 if (!names_->size()) {
298 DVLOG(1) << "No camera available. Exiting test."; 295 DVLOG(1) << "No camera available. Exiting test.";
299 return; 296 return;
300 } 297 }
301 scoped_ptr<VideoCaptureDevice> device( 298 scoped_ptr<VideoCaptureDevice> device(
302 video_capture_device_factory_->Create(names_->front())); 299 video_capture_device_factory_->Create(names_->front()));
303 ASSERT_TRUE(device); 300 ASSERT_TRUE(device);
304 301
305 EXPECT_CALL(*client_, OnErr()) 302 EXPECT_CALL(*client_, OnErr())
306 .Times(0); 303 .Times(0);
307 304
308 VideoCaptureParams capture_params; 305 VideoCaptureParams capture_params;
309 capture_params.requested_format.frame_size.SetSize(637, 472); 306 capture_params.requested_format.frame_size.SetSize(637, 472);
310 capture_params.requested_format.frame_rate = 35; 307 capture_params.requested_format.frame_rate = 35;
311 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 308 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
312 capture_params.allow_resolution_change = false;
313 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 309 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
314 WaitForCapturedFrame(); 310 WaitForCapturedFrame();
315 device->StopAndDeAllocate(); 311 device->StopAndDeAllocate();
316 EXPECT_EQ(last_format().frame_size.width(), 640); 312 EXPECT_EQ(last_format().frame_size.width(), 640);
317 EXPECT_EQ(last_format().frame_size.height(), 480); 313 EXPECT_EQ(last_format().frame_size.height(), 480);
318 } 314 }
319 315
320 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { 316 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
321 names_ = EnumerateDevices(); 317 names_ = EnumerateDevices();
322 if (!names_->size()) { 318 if (!names_->size()) {
323 DVLOG(1) << "No camera available. Exiting test."; 319 DVLOG(1) << "No camera available. Exiting test.";
324 return; 320 return;
325 } 321 }
326 322
327 // First, do a number of very fast device start/stops. 323 // First, do a number of very fast device start/stops.
328 for (int i = 0; i <= 5; i++) { 324 for (int i = 0; i <= 5; i++) {
329 ResetWithNewClient(); 325 ResetWithNewClient();
330 scoped_ptr<VideoCaptureDevice> device( 326 scoped_ptr<VideoCaptureDevice> device(
331 video_capture_device_factory_->Create(names_->front())); 327 video_capture_device_factory_->Create(names_->front()));
332 gfx::Size resolution; 328 gfx::Size resolution;
333 if (i % 2) { 329 if (i % 2) {
334 resolution = gfx::Size(640, 480); 330 resolution = gfx::Size(640, 480);
335 } else { 331 } else {
336 resolution = gfx::Size(1280, 1024); 332 resolution = gfx::Size(1280, 1024);
337 } 333 }
338 VideoCaptureParams capture_params; 334 VideoCaptureParams capture_params;
339 capture_params.requested_format.frame_size = resolution; 335 capture_params.requested_format.frame_size = resolution;
340 capture_params.requested_format.frame_rate = 30; 336 capture_params.requested_format.frame_rate = 30;
341 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 337 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
342 capture_params.allow_resolution_change = false;
343 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 338 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
344 device->StopAndDeAllocate(); 339 device->StopAndDeAllocate();
345 } 340 }
346 341
347 // Finally, do a device start and wait for it to finish. 342 // Finally, do a device start and wait for it to finish.
348 VideoCaptureParams capture_params; 343 VideoCaptureParams capture_params;
349 capture_params.requested_format.frame_size.SetSize(320, 240); 344 capture_params.requested_format.frame_size.SetSize(320, 240);
350 capture_params.requested_format.frame_rate = 30; 345 capture_params.requested_format.frame_rate = 30;
351 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 346 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
352 capture_params.allow_resolution_change = false;
353 347
354 ResetWithNewClient(); 348 ResetWithNewClient();
355 scoped_ptr<VideoCaptureDevice> device( 349 scoped_ptr<VideoCaptureDevice> device(
356 video_capture_device_factory_->Create(names_->front())); 350 video_capture_device_factory_->Create(names_->front()));
357 351
358 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 352 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
359 WaitForCapturedFrame(); 353 WaitForCapturedFrame();
360 device->StopAndDeAllocate(); 354 device->StopAndDeAllocate();
361 device.reset(); 355 device.reset();
362 EXPECT_EQ(last_format().frame_size.width(), 320); 356 EXPECT_EQ(last_format().frame_size.width(), 320);
(...skipping 10 matching lines...) Expand all
373 video_capture_device_factory_->Create(names_->front())); 367 video_capture_device_factory_->Create(names_->front()));
374 ASSERT_TRUE(device); 368 ASSERT_TRUE(device);
375 369
376 EXPECT_CALL(*client_, OnErr()) 370 EXPECT_CALL(*client_, OnErr())
377 .Times(0); 371 .Times(0);
378 372
379 VideoCaptureParams capture_params; 373 VideoCaptureParams capture_params;
380 capture_params.requested_format.frame_size.SetSize(640, 480); 374 capture_params.requested_format.frame_size.SetSize(640, 480);
381 capture_params.requested_format.frame_rate = 30; 375 capture_params.requested_format.frame_rate = 30;
382 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 376 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
383 capture_params.allow_resolution_change = false;
384 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 377 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
385 // Get captured video frames. 378 // Get captured video frames.
386 WaitForCapturedFrame(); 379 WaitForCapturedFrame();
387 EXPECT_EQ(last_format().frame_size.width(), 640); 380 EXPECT_EQ(last_format().frame_size.width(), 640);
388 EXPECT_EQ(last_format().frame_size.height(), 480); 381 EXPECT_EQ(last_format().frame_size.height(), 480);
389 EXPECT_EQ(last_format().frame_rate, 30); 382 EXPECT_EQ(last_format().frame_rate, 30);
390 device->StopAndDeAllocate(); 383 device->StopAndDeAllocate();
391 } 384 }
392 385
393 // Start the camera in 720p to capture MJPEG instead of a raw format. 386 // Start the camera in 720p to capture MJPEG instead of a raw format.
394 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 387 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
395 scoped_ptr<VideoCaptureDevice::Name> name = 388 scoped_ptr<VideoCaptureDevice::Name> name =
396 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); 389 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
397 if (!name) { 390 if (!name) {
398 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; 391 DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
399 return; 392 return;
400 } 393 }
401 scoped_ptr<VideoCaptureDevice> device( 394 scoped_ptr<VideoCaptureDevice> device(
402 video_capture_device_factory_->Create(*name)); 395 video_capture_device_factory_->Create(*name));
403 ASSERT_TRUE(device); 396 ASSERT_TRUE(device);
404 397
405 EXPECT_CALL(*client_, OnErr()) 398 EXPECT_CALL(*client_, OnErr())
406 .Times(0); 399 .Times(0);
407 400
408 VideoCaptureParams capture_params; 401 VideoCaptureParams capture_params;
409 capture_params.requested_format.frame_size.SetSize(1280, 720); 402 capture_params.requested_format.frame_size.SetSize(1280, 720);
410 capture_params.requested_format.frame_rate = 30; 403 capture_params.requested_format.frame_rate = 30;
411 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 404 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
412 capture_params.allow_resolution_change = false;
413 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 405 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
414 // Get captured video frames. 406 // Get captured video frames.
415 WaitForCapturedFrame(); 407 WaitForCapturedFrame();
416 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 408 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
417 // @ 30 fps, so we don't care about the exact resolution we get. 409 // @ 30 fps, so we don't care about the exact resolution we get.
418 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 410 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
419 device->StopAndDeAllocate(); 411 device->StopAndDeAllocate();
420 } 412 }
421 413
422 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 414 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
423 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 415 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
424 // GetDeviceSupportedFormats(). 416 // GetDeviceSupportedFormats().
425 scoped_ptr<VideoCaptureDevice::Name> name = 417 scoped_ptr<VideoCaptureDevice::Name> name =
426 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 418 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
427 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 419 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
428 // since we cannot forecast the hardware capabilities. 420 // since we cannot forecast the hardware capabilities.
429 ASSERT_FALSE(name); 421 ASSERT_FALSE(name);
430 } 422 }
431 423
432 }; // namespace media 424 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/fake_video_capture_device_unittest.cc ('k') | media/video/capture/video_capture_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698