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

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

Issue 907113002: Reland:Refactored pixel format resize operations in media/video/capture into a function called Vide… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed size for VCC unittest. Created 5 years, 10 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 "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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 256
257 VideoCaptureParams capture_params; 257 VideoCaptureParams capture_params;
258 capture_params.requested_format.frame_size.SetSize(640, 480); 258 capture_params.requested_format.frame_size.SetSize(640, 480);
259 capture_params.requested_format.frame_rate = 30; 259 capture_params.requested_format.frame_rate = 30;
260 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 260 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
261 device->AllocateAndStart(capture_params, client_.Pass()); 261 device->AllocateAndStart(capture_params, client_.Pass());
262 // Get captured video frames. 262 // Get captured video frames.
263 WaitForCapturedFrame(); 263 WaitForCapturedFrame();
264 EXPECT_EQ(last_format().frame_size.width(), 640); 264 EXPECT_EQ(last_format().frame_size.width(), 640);
265 EXPECT_EQ(last_format().frame_size.height(), 480); 265 EXPECT_EQ(last_format().frame_size.height(), 480);
266 EXPECT_EQ(static_cast<size_t>(640 * 480 * 3 / 2),
267 last_format().ImageAllocationSize());
266 device->StopAndDeAllocate(); 268 device->StopAndDeAllocate();
267 } 269 }
268 270
269 TEST_F(VideoCaptureDeviceTest, Capture720p) { 271 TEST_F(VideoCaptureDeviceTest, Capture720p) {
270 names_ = EnumerateDevices(); 272 names_ = EnumerateDevices();
271 if (names_->empty()) { 273 if (names_->empty()) {
272 DVLOG(1) << "No camera available. Exiting test."; 274 DVLOG(1) << "No camera available. Exiting test.";
273 return; 275 return;
274 } 276 }
275 277
276 scoped_ptr<VideoCaptureDevice> device( 278 scoped_ptr<VideoCaptureDevice> device(
277 video_capture_device_factory_->Create(names_->front())); 279 video_capture_device_factory_->Create(names_->front()));
278 ASSERT_TRUE(device); 280 ASSERT_TRUE(device);
279 281
280 EXPECT_CALL(*client_, OnError(_)).Times(0); 282 EXPECT_CALL(*client_, OnError(_)).Times(0);
281 283
282 VideoCaptureParams capture_params; 284 VideoCaptureParams capture_params;
283 capture_params.requested_format.frame_size.SetSize(1280, 720); 285 capture_params.requested_format.frame_size.SetSize(1280, 720);
284 capture_params.requested_format.frame_rate = 30; 286 capture_params.requested_format.frame_rate = 30;
285 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 287 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
286 device->AllocateAndStart(capture_params, client_.Pass()); 288 device->AllocateAndStart(capture_params, client_.Pass());
287 // Get captured video frames. 289 // Get captured video frames.
288 WaitForCapturedFrame(); 290 WaitForCapturedFrame();
291 EXPECT_EQ(last_format().frame_size.width(), 1280);
292 EXPECT_EQ(last_format().frame_size.height(), 720);
293 EXPECT_EQ(static_cast<size_t>(1280 * 720 * 3 / 2),
294 last_format().ImageAllocationSize());
289 device->StopAndDeAllocate(); 295 device->StopAndDeAllocate();
290 } 296 }
291 297
292 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 298 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
293 names_ = EnumerateDevices(); 299 names_ = EnumerateDevices();
294 if (names_->empty()) { 300 if (names_->empty()) {
295 DVLOG(1) << "No camera available. Exiting test."; 301 DVLOG(1) << "No camera available. Exiting test.";
296 return; 302 return;
297 } 303 }
298 scoped_ptr<VideoCaptureDevice> device( 304 scoped_ptr<VideoCaptureDevice> device(
299 video_capture_device_factory_->Create(names_->front())); 305 video_capture_device_factory_->Create(names_->front()));
300 ASSERT_TRUE(device); 306 ASSERT_TRUE(device);
301 307
302 EXPECT_CALL(*client_, OnError(_)).Times(0); 308 EXPECT_CALL(*client_, OnError(_)).Times(0);
303 309
304 VideoCaptureParams capture_params; 310 VideoCaptureParams capture_params;
305 capture_params.requested_format.frame_size.SetSize(637, 472); 311 capture_params.requested_format.frame_size.SetSize(637, 472);
306 capture_params.requested_format.frame_rate = 35; 312 capture_params.requested_format.frame_rate = 35;
307 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 313 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
308 device->AllocateAndStart(capture_params, client_.Pass()); 314 device->AllocateAndStart(capture_params, client_.Pass());
309 WaitForCapturedFrame(); 315 WaitForCapturedFrame();
310 device->StopAndDeAllocate(); 316 device->StopAndDeAllocate();
311 EXPECT_EQ(last_format().frame_size.width(), 640); 317 EXPECT_EQ(last_format().frame_size.width(), 640);
312 EXPECT_EQ(last_format().frame_size.height(), 480); 318 EXPECT_EQ(last_format().frame_size.height(), 480);
319 EXPECT_EQ(static_cast<size_t>(640 * 480 * 3 / 2),
320 last_format().ImageAllocationSize());
313 } 321 }
314 322
315 // Cause hangs on Windows Debug. http://crbug.com/417824 323 // Cause hangs on Windows Debug. http://crbug.com/417824
316 #if defined(OS_WIN) && !defined(NDEBUG) 324 #if defined(OS_WIN) && !defined(NDEBUG)
317 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera 325 #define MAYBE_ReAllocateCamera DISABLED_ReAllocateCamera
318 #else 326 #else
319 #define MAYBE_ReAllocateCamera ReAllocateCamera 327 #define MAYBE_ReAllocateCamera ReAllocateCamera
320 #endif 328 #endif
321 329
322 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) { 330 TEST_F(VideoCaptureDeviceTest, MAYBE_ReAllocateCamera) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 VideoCaptureParams capture_params; 413 VideoCaptureParams capture_params;
406 capture_params.requested_format.frame_size.SetSize(1280, 720); 414 capture_params.requested_format.frame_size.SetSize(1280, 720);
407 capture_params.requested_format.frame_rate = 30; 415 capture_params.requested_format.frame_rate = 30;
408 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 416 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
409 device->AllocateAndStart(capture_params, client_.Pass()); 417 device->AllocateAndStart(capture_params, client_.Pass());
410 // Get captured video frames. 418 // Get captured video frames.
411 WaitForCapturedFrame(); 419 WaitForCapturedFrame();
412 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 420 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
413 // @ 30 fps, so we don't care about the exact resolution we get. 421 // @ 30 fps, so we don't care about the exact resolution we get.
414 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 422 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
423 EXPECT_GE(static_cast<size_t>(1280 * 720),
424 last_format().ImageAllocationSize());
415 device->StopAndDeAllocate(); 425 device->StopAndDeAllocate();
416 } 426 }
417 427
418 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 428 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
419 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 429 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
420 // GetDeviceSupportedFormats(). 430 // GetDeviceSupportedFormats().
421 scoped_ptr<VideoCaptureDevice::Name> name = 431 scoped_ptr<VideoCaptureDevice::Name> name =
422 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 432 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
423 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 433 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
424 // since we cannot forecast the hardware capabilities. 434 // since we cannot forecast the hardware capabilities.
425 ASSERT_FALSE(name); 435 ASSERT_FALSE(name);
426 } 436 }
427 437
428 }; // namespace media 438 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/file_video_capture_device.cc ('k') | media/video/capture/video_capture_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698