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

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

Issue 2721633006: Reland Add MJPEG support to FakeVideoCaptureDevice (Closed)
Patch Set: Created 3 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
« no previous file with comments | « media/capture/video/fake_video_capture_device_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/fake_video_capture_device.h" 5 #include "media/capture/video/fake_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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; 260 const scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_;
261 const scoped_refptr<ImageCaptureClient> image_capture_client_; 261 const scoped_refptr<ImageCaptureClient> image_capture_client_;
262 VideoCaptureFormat last_format_; 262 VideoCaptureFormat last_format_;
263 const std::unique_ptr<VideoCaptureDeviceFactory> 263 const std::unique_ptr<VideoCaptureDeviceFactory>
264 video_capture_device_factory_; 264 video_capture_device_factory_;
265 }; 265 };
266 266
267 class FakeVideoCaptureDeviceTest 267 class FakeVideoCaptureDeviceTest
268 : public FakeVideoCaptureDeviceBase, 268 : public FakeVideoCaptureDeviceBase,
269 public ::testing::WithParamInterface< 269 public ::testing::WithParamInterface<
270 ::testing::tuple<VideoPixelFormat, 270 ::testing::tuple<FakeVideoCaptureDeviceMaker::PixelFormat,
271 FakeVideoCaptureDeviceMaker::DeliveryMode, 271 FakeVideoCaptureDeviceMaker::DeliveryMode,
272 float>> {}; 272 float>> {};
273 273
274 // Tests that a frame is delivered with the expected settings. 274 // Tests that a frame is delivered with the expected settings.
275 // Sweeps through a fixed set of requested/expected resolutions. 275 // Sweeps through a fixed set of requested/expected resolutions.
276 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { 276 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) {
277 if (testing::get<1>(GetParam()) == FakeVideoCaptureDeviceMaker::DeliveryMode::
278 USE_CLIENT_PROVIDED_BUFFERS &&
279 testing::get<0>(GetParam()) ==
280 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) {
281 // Unsupported case
282 return;
283 }
284
277 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 285 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
278 EnumerateDevices()); 286 EnumerateDevices());
279 ASSERT_FALSE(descriptors->empty()); 287 ASSERT_FALSE(descriptors->empty());
280 288
281 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( 289 auto device = FakeVideoCaptureDeviceMaker::MakeInstance(
282 testing::get<0>(GetParam()), testing::get<1>(GetParam()), 290 testing::get<0>(GetParam()), testing::get<1>(GetParam()),
283 testing::get<2>(GetParam())); 291 testing::get<2>(GetParam()));
284 ASSERT_TRUE(device); 292 ASSERT_TRUE(device);
285 293
286 // First: Requested, Second: Expected 294 // First: Requested, Second: Expected
(...skipping 11 matching lines...) Expand all
298 EXPECT_CALL(*client, OnStarted()); 306 EXPECT_CALL(*client, OnStarted());
299 307
300 VideoCaptureParams capture_params; 308 VideoCaptureParams capture_params;
301 capture_params.requested_format.frame_size = resolution.first; 309 capture_params.requested_format.frame_size = resolution.first;
302 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); 310 capture_params.requested_format.frame_rate = testing::get<2>(GetParam());
303 device->AllocateAndStart(capture_params, std::move(client)); 311 device->AllocateAndStart(capture_params, std::move(client));
304 312
305 WaitForCapturedFrame(); 313 WaitForCapturedFrame();
306 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width()); 314 EXPECT_EQ(resolution.second.width(), last_format().frame_size.width());
307 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height()); 315 EXPECT_EQ(resolution.second.height(), last_format().frame_size.height());
308 EXPECT_EQ(last_format().pixel_format, testing::get<0>(GetParam())); 316 EXPECT_EQ(last_format().pixel_format,
317 static_cast<VideoPixelFormat>(testing::get<0>(GetParam())));
309 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); 318 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam()));
310 device->StopAndDeAllocate(); 319 device->StopAndDeAllocate();
311 } 320 }
312 } 321 }
313 322
314 INSTANTIATE_TEST_CASE_P( 323 INSTANTIATE_TEST_CASE_P(
315 , 324 ,
316 FakeVideoCaptureDeviceTest, 325 FakeVideoCaptureDeviceTest,
317 Combine(Values(PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_ARGB), 326 Combine(Values(FakeVideoCaptureDeviceMaker::PixelFormat::I420,
327 FakeVideoCaptureDeviceMaker::PixelFormat::Y16,
328 FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG),
318 Values(FakeVideoCaptureDeviceMaker::DeliveryMode:: 329 Values(FakeVideoCaptureDeviceMaker::DeliveryMode::
319 USE_DEVICE_INTERNAL_BUFFERS, 330 USE_DEVICE_INTERNAL_BUFFERS,
320 FakeVideoCaptureDeviceMaker::DeliveryMode:: 331 FakeVideoCaptureDeviceMaker::DeliveryMode::
321 USE_CLIENT_PROVIDED_BUFFERS), 332 USE_CLIENT_PROVIDED_BUFFERS),
322 Values(20, 29.97, 30, 50, 60))); 333 Values(20, 29.97, 30, 50, 60)));
323 334
324 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { 335 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) {
325 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 336 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
326 switches::kUseFakeDeviceForMediaStream, "device-count=3"); 337 switches::kUseFakeDeviceForMediaStream, "device-count=4");
327 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 338 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
328 EnumerateDevices()); 339 EnumerateDevices());
329 ASSERT_EQ(3u, descriptors->size()); 340 ASSERT_EQ(4u, descriptors->size());
341 const VideoPixelFormat expected_format_by_device_index[] = {
342 PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_MJPEG,
343 PIXEL_FORMAT_I420};
330 344
345 int device_index = 0;
331 for (const auto& descriptors_iterator : *descriptors) { 346 for (const auto& descriptors_iterator : *descriptors) {
332 VideoCaptureFormats supported_formats; 347 VideoCaptureFormats supported_formats;
333 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, 348 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator,
334 &supported_formats); 349 &supported_formats);
335 ASSERT_EQ(5u, supported_formats.size()); 350 ASSERT_EQ(5u, supported_formats.size());
336 const std::string device_id = descriptors_iterator.device_id;
337 VideoPixelFormat expected_format = 351 VideoPixelFormat expected_format =
338 (device_id == "/dev/video1") ? PIXEL_FORMAT_Y16 : PIXEL_FORMAT_I420; 352 expected_format_by_device_index[device_index];
339 EXPECT_EQ(96, supported_formats[0].frame_size.width()); 353 EXPECT_EQ(96, supported_formats[0].frame_size.width());
340 EXPECT_EQ(96, supported_formats[0].frame_size.height()); 354 EXPECT_EQ(96, supported_formats[0].frame_size.height());
341 EXPECT_EQ(expected_format, supported_formats[0].pixel_format); 355 EXPECT_EQ(expected_format, supported_formats[0].pixel_format);
342 EXPECT_GE(supported_formats[0].frame_rate, 20.0); 356 EXPECT_GE(supported_formats[0].frame_rate, 20.0);
343 EXPECT_EQ(320, supported_formats[1].frame_size.width()); 357 EXPECT_EQ(320, supported_formats[1].frame_size.width());
344 EXPECT_EQ(240, supported_formats[1].frame_size.height()); 358 EXPECT_EQ(240, supported_formats[1].frame_size.height());
345 EXPECT_EQ(expected_format, supported_formats[1].pixel_format); 359 EXPECT_EQ(expected_format, supported_formats[1].pixel_format);
346 EXPECT_GE(supported_formats[1].frame_rate, 20.0); 360 EXPECT_GE(supported_formats[1].frame_rate, 20.0);
347 EXPECT_EQ(640, supported_formats[2].frame_size.width()); 361 EXPECT_EQ(640, supported_formats[2].frame_size.width());
348 EXPECT_EQ(480, supported_formats[2].frame_size.height()); 362 EXPECT_EQ(480, supported_formats[2].frame_size.height());
349 EXPECT_EQ(expected_format, supported_formats[2].pixel_format); 363 EXPECT_EQ(expected_format, supported_formats[2].pixel_format);
350 EXPECT_GE(supported_formats[2].frame_rate, 20.0); 364 EXPECT_GE(supported_formats[2].frame_rate, 20.0);
351 EXPECT_EQ(1280, supported_formats[3].frame_size.width()); 365 EXPECT_EQ(1280, supported_formats[3].frame_size.width());
352 EXPECT_EQ(720, supported_formats[3].frame_size.height()); 366 EXPECT_EQ(720, supported_formats[3].frame_size.height());
353 EXPECT_EQ(expected_format, supported_formats[3].pixel_format); 367 EXPECT_EQ(expected_format, supported_formats[3].pixel_format);
354 EXPECT_GE(supported_formats[3].frame_rate, 20.0); 368 EXPECT_GE(supported_formats[3].frame_rate, 20.0);
355 EXPECT_EQ(1920, supported_formats[4].frame_size.width()); 369 EXPECT_EQ(1920, supported_formats[4].frame_size.width());
356 EXPECT_EQ(1080, supported_formats[4].frame_size.height()); 370 EXPECT_EQ(1080, supported_formats[4].frame_size.height());
357 EXPECT_EQ(expected_format, supported_formats[4].pixel_format); 371 EXPECT_EQ(expected_format, supported_formats[4].pixel_format);
358 EXPECT_GE(supported_formats[4].frame_rate, 20.0); 372 EXPECT_GE(supported_formats[4].frame_rate, 20.0);
373 device_index++;
359 } 374 }
360 } 375 }
361 376
362 TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) { 377 TEST_F(FakeVideoCaptureDeviceTest, GetCameraCalibration) {
363 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 378 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
364 switches::kUseFakeDeviceForMediaStream, "device-count=2"); 379 switches::kUseFakeDeviceForMediaStream, "device-count=2");
365 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 380 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
366 EnumerateDevices()); 381 EnumerateDevices());
367 ASSERT_EQ(2u, descriptors->size()); 382 ASSERT_EQ(2u, descriptors->size());
368 ASSERT_FALSE(descriptors->at(0).camera_calibration); 383 ASSERT_FALSE(descriptors->at(0).camera_calibration);
369 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1); 384 const VideoCaptureDeviceDescriptor& depth_device = descriptors->at(1);
370 EXPECT_EQ("/dev/video1", depth_device.device_id); 385 EXPECT_EQ("/dev/video1", depth_device.device_id);
371 ASSERT_TRUE(depth_device.camera_calibration); 386 ASSERT_TRUE(depth_device.camera_calibration);
372 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x); 387 EXPECT_EQ(135.0, depth_device.camera_calibration->focal_length_x);
373 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y); 388 EXPECT_EQ(135.6, depth_device.camera_calibration->focal_length_y);
374 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near); 389 EXPECT_EQ(0.0, depth_device.camera_calibration->depth_near);
375 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far); 390 EXPECT_EQ(65.535, depth_device.camera_calibration->depth_far);
376 } 391 }
377 392
378 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { 393 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) {
379 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( 394 auto device = FakeVideoCaptureDeviceMaker::MakeInstance(
380 PIXEL_FORMAT_I420, 395 FakeVideoCaptureDeviceMaker::PixelFormat::I420,
381 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, 396 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS,
382 30.0); 397 30.0);
383 ASSERT_TRUE(device); 398 ASSERT_TRUE(device);
384 399
385 VideoCaptureParams capture_params; 400 VideoCaptureParams capture_params;
386 capture_params.requested_format.frame_size.SetSize(640, 480); 401 capture_params.requested_format.frame_size.SetSize(640, 480);
387 capture_params.requested_format.frame_rate = 30.0; 402 capture_params.requested_format.frame_rate = 30.0;
388 EXPECT_CALL(*client_, OnStarted()); 403 EXPECT_CALL(*client_, OnStarted());
389 device->AllocateAndStart(capture_params, std::move(client_)); 404 device->AllocateAndStart(capture_params, std::move(client_));
390 405
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 run_loop_.reset(new base::RunLoop()); 497 run_loop_.reset(new base::RunLoop());
483 run_loop_->Run(); 498 run_loop_->Run();
484 EXPECT_EQ(max_zoom_value, 499 EXPECT_EQ(max_zoom_value,
485 image_capture_client_->capabilities()->zoom->current); 500 image_capture_client_->capabilities()->zoom->current);
486 501
487 device->StopAndDeAllocate(); 502 device->StopAndDeAllocate();
488 } 503 }
489 504
490 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) { 505 TEST_F(FakeVideoCaptureDeviceTest, TakePhoto) {
491 auto device = FakeVideoCaptureDeviceMaker::MakeInstance( 506 auto device = FakeVideoCaptureDeviceMaker::MakeInstance(
492 PIXEL_FORMAT_I420, 507 FakeVideoCaptureDeviceMaker::PixelFormat::I420,
493 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS, 508 FakeVideoCaptureDeviceMaker::DeliveryMode::USE_DEVICE_INTERNAL_BUFFERS,
494 30.0); 509 30.0);
495 ASSERT_TRUE(device); 510 ASSERT_TRUE(device);
496 511
497 VideoCaptureParams capture_params; 512 VideoCaptureParams capture_params;
498 capture_params.requested_format.frame_size.SetSize(640, 480); 513 capture_params.requested_format.frame_size.SetSize(640, 480);
499 capture_params.requested_format.frame_rate = 30.0; 514 capture_params.requested_format.frame_rate = 30.0;
500 EXPECT_CALL(*client_, OnStarted()); 515 EXPECT_CALL(*client_, OnStarted());
501 device->AllocateAndStart(capture_params, std::move(client_)); 516 device->AllocateAndStart(capture_params, std::move(client_));
502 517
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 1u, 592 1u,
578 {PIXEL_FORMAT_I420}}, 593 {PIXEL_FORMAT_I420}},
579 CommandLineTestData{"fps=60,device-count=2", 594 CommandLineTestData{"fps=60,device-count=2",
580 60, 595 60,
581 2u, 596 2u,
582 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16}}, 597 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16}},
583 CommandLineTestData{"fps=1000,device-count=-1", 598 CommandLineTestData{"fps=1000,device-count=-1",
584 60, 599 60,
585 1u, 600 1u,
586 {PIXEL_FORMAT_I420}}, 601 {PIXEL_FORMAT_I420}},
587 CommandLineTestData{ 602 CommandLineTestData{"device-count=4",
588 "device-count=3", 603 20,
589 20, 604 4u,
590 3u, 605
591 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, 606 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16,
592 CommandLineTestData{ 607 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}},
593 "device-count=3,ownership=client", 608 CommandLineTestData{"device-count=4,ownership=client",
594 20, 609 20,
595 3u, 610 4u,
596 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16, PIXEL_FORMAT_I420}}, 611
612 {PIXEL_FORMAT_I420, PIXEL_FORMAT_Y16,
613 PIXEL_FORMAT_MJPEG, PIXEL_FORMAT_I420}},
597 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}})); 614 CommandLineTestData{"device-count=0", 20, 1u, {PIXEL_FORMAT_I420}}));
598 }; // namespace media 615 }; // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/fake_video_capture_device_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698