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

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

Issue 227613005: Fix CaptureMjpeg test may fail on devices that cannot capture MJPEG. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 | « no previous file | 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 (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/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 run_loop_->QuitClosure().Run(); 121 run_loop_->QuitClosure().Run();
122 } 122 }
123 123
124 void WaitForCapturedFrame() { 124 void WaitForCapturedFrame() {
125 run_loop_.reset(new base::RunLoop()); 125 run_loop_.reset(new base::RunLoop());
126 run_loop_->Run(); 126 run_loop_->Run();
127 } 127 }
128 128
129 const VideoCaptureFormat& last_format() const { return last_format_; } 129 const VideoCaptureFormat& last_format() const { return last_format_; }
130 130
131 scoped_ptr<VideoCaptureDevice::Name> GetRquestedPixelFormatDeviceName(
Ami GONE FROM CHROMIUM 2014/04/07 17:14:17 typo: GetRquestedPixelFormatDeviceName
Ami GONE FROM CHROMIUM 2014/04/07 17:14:17 This function's name is a bit convoluted, and "req
yuli 2014/04/08 07:42:54 Done.
132 const VideoPixelFormat& requested_pixel_format) {
133 VideoCaptureDevice::GetDeviceNames(&names_);
134 if (!names_.size()) {
135 DVLOG(1) << "No camera available.";
136 return scoped_ptr<VideoCaptureDevice::Name>();
137 }
138 VideoCaptureFormats supported_formats;
139 VideoCaptureDevice::Names::iterator names_iterator;
140 for (names_iterator = names_.begin(); names_iterator != names_.end();
141 ++names_iterator) {
142 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
Ami GONE FROM CHROMIUM 2014/04/07 17:14:17 This doesn't specify that it clears its output arg
yuli 2014/04/08 07:42:54 Done.
143 &supported_formats);
144 VideoCaptureFormats::iterator formats_iterator;
145 for (formats_iterator = supported_formats.begin();
146 formats_iterator != supported_formats.end(); ++formats_iterator) {
147 if (formats_iterator->pixel_format == requested_pixel_format) {
148 return scoped_ptr<VideoCaptureDevice::Name>(
149 new VideoCaptureDevice::Name(*names_iterator));
150 }
151 }
152 }
153 DVLOG(1) << "No camera can capture the requested pixel format.";
Ami GONE FROM CHROMIUM 2014/04/07 17:14:17 DVLOG(1) << "No camera can capture " << requested_
yuli 2014/04/08 07:42:54 Done.
154 return scoped_ptr<VideoCaptureDevice::Name>();
155 }
156
131 #if defined(OS_WIN) 157 #if defined(OS_WIN)
132 base::win::ScopedCOMInitializer initialize_com_; 158 base::win::ScopedCOMInitializer initialize_com_;
133 #endif 159 #endif
134 VideoCaptureDevice::Names names_; 160 VideoCaptureDevice::Names names_;
135 scoped_ptr<base::MessageLoop> loop_; 161 scoped_ptr<base::MessageLoop> loop_;
136 scoped_ptr<base::RunLoop> run_loop_; 162 scoped_ptr<base::RunLoop> run_loop_;
137 scoped_ptr<MockClient> client_; 163 scoped_ptr<MockClient> client_;
138 VideoCaptureFormat last_format_; 164 VideoCaptureFormat last_format_;
139 }; 165 };
140 166
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 351 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
326 WaitForCapturedFrame(); 352 WaitForCapturedFrame();
327 EXPECT_EQ(last_format().frame_size.width(), 640); 353 EXPECT_EQ(last_format().frame_size.width(), 640);
328 EXPECT_EQ(last_format().frame_size.height(), 480); 354 EXPECT_EQ(last_format().frame_size.height(), 480);
329 EXPECT_EQ(last_format().frame_rate, 30); 355 EXPECT_EQ(last_format().frame_rate, 30);
330 device->StopAndDeAllocate(); 356 device->StopAndDeAllocate();
331 } 357 }
332 358
333 // Start the camera in 720p to capture MJPEG instead of a raw format. 359 // Start the camera in 720p to capture MJPEG instead of a raw format.
334 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 360 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
335 VideoCaptureDevice::GetDeviceNames(&names_); 361 scoped_ptr<VideoCaptureDevice::Name> name = GetRquestedPixelFormatDeviceName(
336 if (!names_.size()) { 362 PIXEL_FORMAT_MJPEG);
337 DVLOG(1) << "No camera available. Exiting test."; 363 if (name.get() == NULL) {
364 DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
338 return; 365 return;
339 } 366 }
340 scoped_ptr<VideoCaptureDevice> device( 367 scoped_ptr<VideoCaptureDevice> device(VideoCaptureDevice::Create(*name));
341 VideoCaptureDevice::Create(names_.front()));
342 ASSERT_TRUE(device.get() != NULL); 368 ASSERT_TRUE(device.get() != NULL);
343 369
344 EXPECT_CALL(*client_, OnErr()) 370 EXPECT_CALL(*client_, OnErr())
345 .Times(0); 371 .Times(0);
346 372
347 VideoCaptureParams capture_params; 373 VideoCaptureParams capture_params;
348 capture_params.requested_format.frame_size.SetSize(1280, 720); 374 capture_params.requested_format.frame_size.SetSize(1280, 720);
349 capture_params.requested_format.frame_rate = 30; 375 capture_params.requested_format.frame_rate = 30;
350 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 376 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
351 capture_params.allow_resolution_change = false; 377 capture_params.allow_resolution_change = false;
352 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 378 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
353 // Get captured video frames. 379 // Get captured video frames.
354 WaitForCapturedFrame(); 380 WaitForCapturedFrame();
355 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 381 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
356 // @ 30 fps, so we don't care about the exact resolution we get. 382 // @ 30 fps, so we don't care about the exact resolution we get.
357 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 383 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
358 device->StopAndDeAllocate(); 384 device->StopAndDeAllocate();
359 } 385 }
360 386
361 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 387 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
362 VideoCaptureDevice::GetDeviceNames(&names_); 388 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
363 if (!names_.size()) { 389 // GetDeviceSupportedFormats().
364 DVLOG(1) << "No camera available. Exiting test."; 390 scoped_ptr<VideoCaptureDevice::Name> name = GetRquestedPixelFormatDeviceName(
365 return; 391 PIXEL_FORMAT_MAX);
366 } 392 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
367 VideoCaptureFormats supported_formats; 393 // since we cannot forecast the hardware capabilities.
368 VideoCaptureDevice::Names::iterator names_iterator; 394 ASSERT_TRUE(name.get() == NULL);
369 for (names_iterator = names_.begin(); names_iterator != names_.end();
370 ++names_iterator) {
371 VideoCaptureDevice::GetDeviceSupportedFormats(*names_iterator,
372 &supported_formats);
373 // Nothing to test here since we cannot forecast the hardware capabilities.
374 }
375 } 395 }
376 396
377 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) { 397 TEST_F(VideoCaptureDeviceTest, FakeCaptureVariableResolution) {
378 VideoCaptureDevice::Names names; 398 VideoCaptureDevice::Names names;
379 399
380 FakeVideoCaptureDevice::GetDeviceNames(&names); 400 FakeVideoCaptureDevice::GetDeviceNames(&names);
381 VideoCaptureParams capture_params; 401 VideoCaptureParams capture_params;
382 capture_params.requested_format.frame_size.SetSize(640, 480); 402 capture_params.requested_format.frame_size.SetSize(640, 480);
383 capture_params.requested_format.frame_rate = 30; 403 capture_params.requested_format.frame_rate = 30;
384 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 404 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420); 445 EXPECT_EQ(supported_formats[1].pixel_format, media::PIXEL_FORMAT_I420);
426 EXPECT_GE(supported_formats[1].frame_rate, 20); 446 EXPECT_GE(supported_formats[1].frame_rate, 20);
427 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); 447 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280);
428 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); 448 EXPECT_EQ(supported_formats[2].frame_size.height(), 720);
429 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420); 449 EXPECT_EQ(supported_formats[2].pixel_format, media::PIXEL_FORMAT_I420);
430 EXPECT_GE(supported_formats[2].frame_rate, 20); 450 EXPECT_GE(supported_formats[2].frame_rate, 20);
431 } 451 }
432 } 452 }
433 453
434 }; // namespace media 454 }; // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698