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

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

Issue 2169013002: Change class VideoCaptureDevice::Name to struct VideoCaptureDeviceDescriptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed emircan's comments Created 4 years, 4 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 // 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 "media/capture/video/video_capture_device.h" 5 #include "media/capture/video/video_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void(const base::Callback<void(mojom::BlobPtr)>&)); 161 void(const base::Callback<void(mojom::BlobPtr)>&));
162 162
163 private: 163 private:
164 friend class base::RefCounted<MockImageCaptureClient>; 164 friend class base::RefCounted<MockImageCaptureClient>;
165 virtual ~MockImageCaptureClient() {} 165 virtual ~MockImageCaptureClient() {}
166 }; 166 };
167 167
168 class DeviceEnumerationListener 168 class DeviceEnumerationListener
169 : public base::RefCounted<DeviceEnumerationListener> { 169 : public base::RefCounted<DeviceEnumerationListener> {
170 public: 170 public:
171 MOCK_METHOD1(OnEnumeratedDevicesCallbackPtr, 171 MOCK_METHOD1(OnEnumerateDeviceDescriptorsCallbackPtr,
172 void(VideoCaptureDevice::Names* names)); 172 void(VideoCaptureDeviceDescriptors* device_descriptors));
173 // GMock doesn't support move-only arguments, so we use this forward method. 173 // GMock doesn't support move-only arguments, so we use this forward method.
174 void OnEnumeratedDevicesCallback( 174 void OnEnumerateDeviceDescriptorsCallback(
175 std::unique_ptr<VideoCaptureDevice::Names> names) { 175 std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors) {
176 OnEnumeratedDevicesCallbackPtr(names.release()); 176 OnEnumerateDeviceDescriptorsCallbackPtr(device_descriptors.release());
177 } 177 }
178 178
179 private: 179 private:
180 friend class base::RefCounted<DeviceEnumerationListener>; 180 friend class base::RefCounted<DeviceEnumerationListener>;
181 virtual ~DeviceEnumerationListener() {} 181 virtual ~DeviceEnumerationListener() {}
182 }; 182 };
183 183
184 } // namespace 184 } // namespace
185 185
186 class VideoCaptureDeviceTest : public testing::TestWithParam<gfx::Size> { 186 class VideoCaptureDeviceTest : public testing::TestWithParam<gfx::Size> {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 void OnFrameCaptured(const VideoCaptureFormat& format) { 219 void OnFrameCaptured(const VideoCaptureFormat& format) {
220 last_format_ = format; 220 last_format_ = format;
221 run_loop_->QuitClosure().Run(); 221 run_loop_->QuitClosure().Run();
222 } 222 }
223 223
224 void WaitForCapturedFrame() { 224 void WaitForCapturedFrame() {
225 run_loop_.reset(new base::RunLoop()); 225 run_loop_.reset(new base::RunLoop());
226 run_loop_->Run(); 226 run_loop_->Run();
227 } 227 }
228 228
229 std::unique_ptr<VideoCaptureDevice::Names> EnumerateDevices() { 229 std::unique_ptr<VideoCaptureDeviceDescriptors> EnumerateDeviceDescriptors() {
230 VideoCaptureDevice::Names* names; 230 VideoCaptureDeviceDescriptors* device_descriptors;
231 EXPECT_CALL(*device_enumeration_listener_.get(), 231 EXPECT_CALL(*device_enumeration_listener_.get(),
232 OnEnumeratedDevicesCallbackPtr(_)).WillOnce(SaveArg<0>(&names)); 232 OnEnumerateDeviceDescriptorsCallbackPtr(_))
233 .WillOnce(SaveArg<0>(&device_descriptors));
233 234
234 video_capture_device_factory_->EnumerateDeviceNames( 235 video_capture_device_factory_->EnumerateDeviceDescriptors(base::Bind(
235 base::Bind(&DeviceEnumerationListener::OnEnumeratedDevicesCallback, 236 &DeviceEnumerationListener::OnEnumerateDeviceDescriptorsCallback,
236 device_enumeration_listener_)); 237 device_enumeration_listener_));
237 base::RunLoop().RunUntilIdle(); 238 base::RunLoop().RunUntilIdle();
238 return std::unique_ptr<VideoCaptureDevice::Names>(names); 239 return std::unique_ptr<VideoCaptureDeviceDescriptors>(device_descriptors);
239 } 240 }
240 241
241 const VideoCaptureFormat& last_format() const { return last_format_; } 242 const VideoCaptureFormat& last_format() const { return last_format_; }
242 243
243 std::unique_ptr<VideoCaptureDevice::Name> 244 std::unique_ptr<VideoCaptureDeviceDescriptor>
244 GetFirstDeviceNameSupportingPixelFormat( 245 GetFirstDeviceDescriptorSupportingPixelFormat(
245 const VideoPixelFormat& pixel_format) { 246 const VideoPixelFormat& pixel_format) {
246 names_ = EnumerateDevices(); 247 device_descriptors_ = EnumerateDeviceDescriptors();
247 if (names_->empty()) { 248 if (device_descriptors_->empty()) {
248 DVLOG(1) << "No camera available."; 249 DVLOG(1) << "No camera available.";
249 return std::unique_ptr<VideoCaptureDevice::Name>(); 250 return std::unique_ptr<VideoCaptureDeviceDescriptor>();
250 } 251 }
251 for (const auto& names_iterator : *names_) { 252 for (const auto& descriptors_iterator : *device_descriptors_) {
252 VideoCaptureFormats supported_formats; 253 VideoCaptureDeviceInfo device_info;
253 video_capture_device_factory_->GetDeviceSupportedFormats( 254 video_capture_device_factory_->GetDeviceInfo(descriptors_iterator,
254 names_iterator, &supported_formats); 255 &device_info);
255 for (const auto& formats_iterator : supported_formats) { 256 for (const auto& formats_iterator : device_info.supported_formats) {
256 if (formats_iterator.pixel_format == pixel_format) { 257 if (formats_iterator.pixel_format == pixel_format) {
257 return std::unique_ptr<VideoCaptureDevice::Name>( 258 return std::unique_ptr<VideoCaptureDeviceDescriptor>(
258 new VideoCaptureDevice::Name(names_iterator)); 259 new VideoCaptureDeviceDescriptor(descriptors_iterator));
259 } 260 }
260 } 261 }
261 } 262 }
262 DVLOG_IF(1, pixel_format != PIXEL_FORMAT_MAX) 263 DVLOG_IF(1, pixel_format != PIXEL_FORMAT_MAX)
263 << "No camera can capture the" 264 << "No camera can capture the"
264 << " format: " << VideoPixelFormatToString(pixel_format); 265 << " format: " << VideoPixelFormatToString(pixel_format);
265 return std::unique_ptr<VideoCaptureDevice::Name>(); 266 return std::unique_ptr<VideoCaptureDeviceDescriptor>();
266 } 267 }
267 268
268 bool IsCaptureSizeSupported(const VideoCaptureDevice::Name& device, 269 bool IsCaptureSizeSupported(const VideoCaptureDeviceDescriptor& device,
269 const gfx::Size& size) { 270 const gfx::Size& size) {
270 VideoCaptureFormats supported_formats; 271 VideoCaptureDeviceInfo device_info;
271 video_capture_device_factory_->GetDeviceSupportedFormats( 272 video_capture_device_factory_->GetDeviceInfo(device, &device_info);
272 device, &supported_formats);
273 const auto it = std::find_if( 273 const auto it = std::find_if(
274 supported_formats.begin(), supported_formats.end(), 274 device_info.supported_formats.begin(),
275 device_info.supported_formats.end(),
275 [&size](VideoCaptureFormat const& f) { return f.frame_size == size; }); 276 [&size](VideoCaptureFormat const& f) { return f.frame_size == size; });
276 if (it == supported_formats.end()) { 277 if (it == device_info.supported_formats.end()) {
277 DVLOG(1) << "Size " << size.ToString() << " is not supported."; 278 DVLOG(1) << "Size " << size.ToString() << " is not supported.";
278 return false; 279 return false;
279 } 280 }
280 return true; 281 return true;
281 } 282 }
282 283
283 #if defined(OS_WIN) 284 #if defined(OS_WIN)
284 base::win::ScopedCOMInitializer initialize_com_; 285 base::win::ScopedCOMInitializer initialize_com_;
285 #endif 286 #endif
286 std::unique_ptr<VideoCaptureDevice::Names> names_; 287 std::unique_ptr<VideoCaptureDeviceDescriptors> device_descriptors_;
287 const std::unique_ptr<base::MessageLoop> loop_; 288 const std::unique_ptr<base::MessageLoop> loop_;
288 std::unique_ptr<base::RunLoop> run_loop_; 289 std::unique_ptr<base::RunLoop> run_loop_;
289 std::unique_ptr<MockVideoCaptureClient> video_capture_client_; 290 std::unique_ptr<MockVideoCaptureClient> video_capture_client_;
290 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; 291 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_;
291 const scoped_refptr<MockImageCaptureClient> image_capture_client_; 292 const scoped_refptr<MockImageCaptureClient> image_capture_client_;
292 VideoCaptureFormat last_format_; 293 VideoCaptureFormat last_format_;
293 const std::unique_ptr<VideoCaptureDeviceFactory> 294 const std::unique_ptr<VideoCaptureDeviceFactory>
294 video_capture_device_factory_; 295 video_capture_device_factory_;
295 }; 296 };
296 297
297 // Cause hangs on Windows Debug. http://crbug.com/417824 298 // Cause hangs on Windows Debug. http://crbug.com/417824
298 #if defined(OS_WIN) && !defined(NDEBUG) 299 #if defined(OS_WIN) && !defined(NDEBUG)
299 #define MAYBE_OpenInvalidDevice DISABLED_OpenInvalidDevice 300 #define MAYBE_OpenInvalidDevice DISABLED_OpenInvalidDevice
300 #else 301 #else
301 #define MAYBE_OpenInvalidDevice OpenInvalidDevice 302 #define MAYBE_OpenInvalidDevice OpenInvalidDevice
302 #endif 303 #endif
303 304
304 TEST_F(VideoCaptureDeviceTest, MAYBE_OpenInvalidDevice) { 305 TEST_F(VideoCaptureDeviceTest, MAYBE_OpenInvalidDevice) {
306 VideoCaptureDeviceDescriptor invalid_descriptor;
307 invalid_descriptor.device_id = "jibberish";
308 invalid_descriptor.friendly_name = "jibberish";
305 #if defined(OS_WIN) 309 #if defined(OS_WIN)
306 VideoCaptureDevice::Name::CaptureApiType api_type = 310 invalid_descriptor.capture_api =
307 VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation() 311 VideoCaptureDeviceFactoryWin::PlatformSupportsMediaFoundation()
308 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION 312 ? VideoCaptureApiType::WINDOWS_MEDIA_FOUNDATION
309 : VideoCaptureDevice::Name::DIRECT_SHOW; 313 : VideoCaptureApiType::WINDOWS_DIRECT_SHOW;
310 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type);
311 #elif defined(OS_MACOSX) 314 #elif defined(OS_MACOSX)
312 VideoCaptureDevice::Name device_name("jibberish", "jibberish", 315 invalid_descriptor.capture_api = VideoCaptureApiType::MACOSX_AVFOUNDATION;
313 VideoCaptureDevice::Name::AVFOUNDATION);
314 #else
315 VideoCaptureDevice::Name device_name("jibberish", "jibberish");
316 #endif 316 #endif
317 std::unique_ptr<VideoCaptureDevice> device = 317 std::unique_ptr<VideoCaptureDevice> device =
318 video_capture_device_factory_->Create(device_name); 318 video_capture_device_factory_->Create(invalid_descriptor);
319 319
320 #if !defined(OS_MACOSX) 320 #if !defined(OS_MACOSX)
321 EXPECT_TRUE(device == NULL); 321 EXPECT_TRUE(device == NULL);
322 #else 322 #else
323 // The presence of the actual device is only checked on AllocateAndStart() 323 // The presence of the actual device is only checked on AllocateAndStart()
324 // and not on creation. 324 // and not on creation.
325 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(1); 325 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(1);
326 326
327 VideoCaptureParams capture_params; 327 VideoCaptureParams capture_params;
328 capture_params.requested_format.frame_size.SetSize(640, 480); 328 capture_params.requested_format.frame_size.SetSize(640, 480);
329 capture_params.requested_format.frame_rate = 30; 329 capture_params.requested_format.frame_rate = 30;
330 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 330 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
331 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 331 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
332 device->StopAndDeAllocate(); 332 device->StopAndDeAllocate();
333 #endif 333 #endif
334 } 334 }
335 335
336 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { 336 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) {
337 names_ = EnumerateDevices(); 337 device_descriptors_ = EnumerateDeviceDescriptors();
338 if (names_->empty()) { 338 if (device_descriptors_->empty()) {
339 VLOG(1) << "No camera available. Exiting test."; 339 VLOG(1) << "No camera available. Exiting test.";
340 return; 340 return;
341 } 341 }
342 342
343 const gfx::Size& size = GetParam(); 343 const gfx::Size& size = GetParam();
344 if (!IsCaptureSizeSupported(names_->front(), size)) 344 if (!IsCaptureSizeSupported(device_descriptors_->front(), size))
345 return; 345 return;
346 const int width = size.width(); 346 const int width = size.width();
347 const int height = size.height(); 347 const int height = size.height();
348 348
349 std::unique_ptr<VideoCaptureDevice> device( 349 std::unique_ptr<VideoCaptureDevice> device(
350 video_capture_device_factory_->Create(names_->front())); 350 video_capture_device_factory_->Create(device_descriptors_->front()));
351 ASSERT_TRUE(device); 351 ASSERT_TRUE(device);
352 DVLOG(1) << names_->front().id(); 352 DVLOG(1) << device_descriptors_->front().device_id;
353 353
354 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 354 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
355 355
356 VideoCaptureParams capture_params; 356 VideoCaptureParams capture_params;
357 capture_params.requested_format.frame_size.SetSize(width, height); 357 capture_params.requested_format.frame_size.SetSize(width, height);
358 capture_params.requested_format.frame_rate = 30.0f; 358 capture_params.requested_format.frame_rate = 30.0f;
359 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 359 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
360 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 360 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
361 // Get captured video frames. 361 // Get captured video frames.
362 WaitForCapturedFrame(); 362 WaitForCapturedFrame();
363 EXPECT_EQ(last_format().frame_size.width(), width); 363 EXPECT_EQ(last_format().frame_size.width(), width);
364 EXPECT_EQ(last_format().frame_size.height(), height); 364 EXPECT_EQ(last_format().frame_size.height(), height);
365 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 365 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
366 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea()); 366 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea());
367 device->StopAndDeAllocate(); 367 device->StopAndDeAllocate();
368 } 368 }
369 369
370 #if !defined(OS_ANDROID) 370 #if !defined(OS_ANDROID)
371 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)}; 371 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)};
372 372
373 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests, 373 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests,
374 VideoCaptureDeviceTest, 374 VideoCaptureDeviceTest,
375 testing::ValuesIn(kCaptureSizes)); 375 testing::ValuesIn(kCaptureSizes));
376 #endif 376 #endif
377 377
378 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 378 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
379 names_ = EnumerateDevices(); 379 device_descriptors_ = EnumerateDeviceDescriptors();
380 if (names_->empty()) { 380 if (device_descriptors_->empty()) {
381 VLOG(1) << "No camera available. Exiting test."; 381 VLOG(1) << "No camera available. Exiting test.";
382 return; 382 return;
383 } 383 }
384 std::unique_ptr<VideoCaptureDevice> device( 384 std::unique_ptr<VideoCaptureDevice> device(
385 video_capture_device_factory_->Create(names_->front())); 385 video_capture_device_factory_->Create(device_descriptors_->front()));
386 ASSERT_TRUE(device); 386 ASSERT_TRUE(device);
387 387
388 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 388 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
389 389
390 const gfx::Size input_size(640, 480); 390 const gfx::Size input_size(640, 480);
391 VideoCaptureParams capture_params; 391 VideoCaptureParams capture_params;
392 capture_params.requested_format.frame_size.SetSize(637, 472); 392 capture_params.requested_format.frame_size.SetSize(637, 472);
393 capture_params.requested_format.frame_rate = 35; 393 capture_params.requested_format.frame_rate = 35;
394 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 394 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
395 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 395 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
396 WaitForCapturedFrame(); 396 WaitForCapturedFrame();
397 device->StopAndDeAllocate(); 397 device->StopAndDeAllocate();
398 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); 398 EXPECT_EQ(last_format().frame_size.width(), input_size.width());
399 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); 399 EXPECT_EQ(last_format().frame_size.height(), input_size.height());
400 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 400 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
401 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); 401 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea());
402 } 402 }
403 403
404 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824 404 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824
405 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { 405 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) {
406 names_ = EnumerateDevices(); 406 device_descriptors_ = EnumerateDeviceDescriptors();
407 if (names_->empty()) { 407 if (device_descriptors_->empty()) {
408 VLOG(1) << "No camera available. Exiting test."; 408 VLOG(1) << "No camera available. Exiting test.";
409 return; 409 return;
410 } 410 }
411 411
412 // First, do a number of very fast device start/stops. 412 // First, do a number of very fast device start/stops.
413 for (int i = 0; i <= 5; i++) { 413 for (int i = 0; i <= 5; i++) {
414 ResetWithNewClient(); 414 ResetWithNewClient();
415 std::unique_ptr<VideoCaptureDevice> device( 415 std::unique_ptr<VideoCaptureDevice> device(
416 video_capture_device_factory_->Create(names_->front())); 416 video_capture_device_factory_->Create(device_descriptors_->front()));
417 gfx::Size resolution; 417 gfx::Size resolution;
418 if (i % 2) { 418 if (i % 2) {
419 resolution = gfx::Size(640, 480); 419 resolution = gfx::Size(640, 480);
420 } else { 420 } else {
421 resolution = gfx::Size(1280, 1024); 421 resolution = gfx::Size(1280, 1024);
422 } 422 }
423 VideoCaptureParams capture_params; 423 VideoCaptureParams capture_params;
424 capture_params.requested_format.frame_size = resolution; 424 capture_params.requested_format.frame_size = resolution;
425 capture_params.requested_format.frame_rate = 30; 425 capture_params.requested_format.frame_rate = 30;
426 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 426 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
427 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 427 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
428 device->StopAndDeAllocate(); 428 device->StopAndDeAllocate();
429 } 429 }
430 430
431 // Finally, do a device start and wait for it to finish. 431 // Finally, do a device start and wait for it to finish.
432 VideoCaptureParams capture_params; 432 VideoCaptureParams capture_params;
433 capture_params.requested_format.frame_size.SetSize(320, 240); 433 capture_params.requested_format.frame_size.SetSize(320, 240);
434 capture_params.requested_format.frame_rate = 30; 434 capture_params.requested_format.frame_rate = 30;
435 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 435 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
436 436
437 ResetWithNewClient(); 437 ResetWithNewClient();
438 std::unique_ptr<VideoCaptureDevice> device( 438 std::unique_ptr<VideoCaptureDevice> device(
439 video_capture_device_factory_->Create(names_->front())); 439 video_capture_device_factory_->Create(device_descriptors_->front()));
440 440
441 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 441 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
442 WaitForCapturedFrame(); 442 WaitForCapturedFrame();
443 device->StopAndDeAllocate(); 443 device->StopAndDeAllocate();
444 device.reset(); 444 device.reset();
445 EXPECT_EQ(last_format().frame_size.width(), 320); 445 EXPECT_EQ(last_format().frame_size.width(), 320);
446 EXPECT_EQ(last_format().frame_size.height(), 240); 446 EXPECT_EQ(last_format().frame_size.height(), 240);
447 } 447 }
448 448
449 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 449 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
450 names_ = EnumerateDevices(); 450 device_descriptors_ = EnumerateDeviceDescriptors();
451 if (names_->empty()) { 451 if (device_descriptors_->empty()) {
452 VLOG(1) << "No camera available. Exiting test."; 452 VLOG(1) << "No camera available. Exiting test.";
453 return; 453 return;
454 } 454 }
455 std::unique_ptr<VideoCaptureDevice> device( 455 std::unique_ptr<VideoCaptureDevice> device(
456 video_capture_device_factory_->Create(names_->front())); 456 video_capture_device_factory_->Create(device_descriptors_->front()));
457 ASSERT_TRUE(device); 457 ASSERT_TRUE(device);
458 458
459 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 459 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
460 460
461 VideoCaptureParams capture_params; 461 VideoCaptureParams capture_params;
462 capture_params.requested_format.frame_size.SetSize(640, 480); 462 capture_params.requested_format.frame_size.SetSize(640, 480);
463 capture_params.requested_format.frame_rate = 30; 463 capture_params.requested_format.frame_rate = 30;
464 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 464 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
465 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 465 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
466 // Get captured video frames. 466 // Get captured video frames.
467 WaitForCapturedFrame(); 467 WaitForCapturedFrame();
468 EXPECT_EQ(last_format().frame_size.width(), 640); 468 EXPECT_EQ(last_format().frame_size.width(), 640);
469 EXPECT_EQ(last_format().frame_size.height(), 480); 469 EXPECT_EQ(last_format().frame_size.height(), 480);
470 EXPECT_EQ(last_format().frame_rate, 30); 470 EXPECT_EQ(last_format().frame_rate, 30);
471 device->StopAndDeAllocate(); 471 device->StopAndDeAllocate();
472 } 472 }
473 473
474 // Start the camera in 720p to capture MJPEG instead of a raw format. 474 // Start the camera in 720p to capture MJPEG instead of a raw format.
475 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 475 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
476 std::unique_ptr<VideoCaptureDevice::Name> name = 476 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor =
477 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); 477 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
478 if (!name) { 478 if (!device_descriptor) {
479 VLOG(1) << "No camera supports MJPEG format. Exiting test."; 479 VLOG(1) << "No camera supports MJPEG format. Exiting test.";
480 return; 480 return;
481 } 481 }
482 #if defined(OS_WIN) 482 #if defined(OS_WIN)
483 base::win::Version version = base::win::GetVersion(); 483 base::win::Version version = base::win::GetVersion();
484 VLOG(1) << "Windows version: " << (int)version; 484 VLOG(1) << "Windows version: " << (int)version;
485 if (version >= base::win::VERSION_WIN10) { 485 if (version >= base::win::VERSION_WIN10) {
486 VLOG(1) << "Skipped on Win10: http://crbug.com/570604."; 486 VLOG(1) << "Skipped on Win10: http://crbug.com/570604.";
487 return; 487 return;
488 } 488 }
489 #endif 489 #endif
490 std::unique_ptr<VideoCaptureDevice> device( 490 std::unique_ptr<VideoCaptureDevice> device(
491 video_capture_device_factory_->Create(*name)); 491 video_capture_device_factory_->Create(*device_descriptor));
492 ASSERT_TRUE(device); 492 ASSERT_TRUE(device);
493 493
494 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 494 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
495 495
496 VideoCaptureParams capture_params; 496 VideoCaptureParams capture_params;
497 capture_params.requested_format.frame_size.SetSize(1280, 720); 497 capture_params.requested_format.frame_size.SetSize(1280, 720);
498 capture_params.requested_format.frame_rate = 30; 498 capture_params.requested_format.frame_rate = 30;
499 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 499 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
500 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 500 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
501 // Get captured video frames. 501 // Get captured video frames.
502 WaitForCapturedFrame(); 502 WaitForCapturedFrame();
503 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 503 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
504 // @ 30 fps, so we don't care about the exact resolution we get. 504 // @ 30 fps, so we don't care about the exact resolution we get.
505 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 505 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
506 EXPECT_GE(static_cast<size_t>(1280 * 720), 506 EXPECT_GE(static_cast<size_t>(1280 * 720),
507 last_format().ImageAllocationSize()); 507 last_format().ImageAllocationSize());
508 device->StopAndDeAllocate(); 508 device->StopAndDeAllocate();
509 } 509 }
510 510
511 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 511 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
512 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 512 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
513 // GetDeviceSupportedFormats(). 513 // GetDeviceSupportedFormats().
514 std::unique_ptr<VideoCaptureDevice::Name> name = 514 std::unique_ptr<VideoCaptureDeviceDescriptor> device_descriptor =
515 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 515 GetFirstDeviceDescriptorSupportingPixelFormat(PIXEL_FORMAT_MAX);
516 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 516 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
517 // since we cannot forecast the hardware capabilities. 517 // since we cannot forecast the hardware capabilities.
518 ASSERT_FALSE(name); 518 ASSERT_FALSE(device_descriptor);
519 } 519 }
520 520
521 // Start the camera and take a photo. 521 // Start the camera and take a photo.
522 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) { 522 TEST_F(VideoCaptureDeviceTest, MAYBE_TakePhoto) {
523 names_ = EnumerateDevices(); 523 device_descriptors_ = EnumerateDeviceDescriptors();
524 if (names_->empty()) { 524 if (device_descriptors_->empty()) {
525 VLOG(1) << "No camera available. Exiting test."; 525 VLOG(1) << "No camera available. Exiting test.";
526 return; 526 return;
527 } 527 }
528 std::unique_ptr<VideoCaptureDevice> device( 528 std::unique_ptr<VideoCaptureDevice> device(
529 video_capture_device_factory_->Create(names_->front())); 529 video_capture_device_factory_->Create(device_descriptors_->front()));
530 ASSERT_TRUE(device); 530 ASSERT_TRUE(device);
531 531
532 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0); 532 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
533 533
534 VideoCaptureParams capture_params; 534 VideoCaptureParams capture_params;
535 capture_params.requested_format.frame_size.SetSize(640, 480); 535 capture_params.requested_format.frame_size.SetSize(640, 480);
536 capture_params.requested_format.frame_rate = 30; 536 capture_params.requested_format.frame_rate = 30;
537 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 537 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
538 device->AllocateAndStart(capture_params, std::move(video_capture_client_)); 538 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
539 WaitForCapturedFrame(); 539 WaitForCapturedFrame();
540 540
541 VideoCaptureDevice::TakePhotoCallback scoped_callback( 541 VideoCaptureDevice::TakePhotoCallback scoped_callback(
542 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken, 542 base::Bind(&MockImageCaptureClient::DoOnPhotoTaken,
543 image_capture_client_), 543 image_capture_client_),
544 media::BindToCurrentLoop(base::Bind( 544 media::BindToCurrentLoop(base::Bind(
545 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_))); 545 &MockImageCaptureClient::OnTakePhotoFailure, image_capture_client_)));
546 546
547 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); 547 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1);
548 device->TakePhoto(std::move(scoped_callback)); 548 device->TakePhoto(std::move(scoped_callback));
549 WaitForCapturedFrame(); 549 WaitForCapturedFrame();
550 550
551 device->StopAndDeAllocate(); 551 device->StopAndDeAllocate();
552 } 552 }
553 553
554 }; // namespace media 554 }; // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698