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

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

Issue 2133233003: VideoCaptureDeviceTest: s/MockClient/MockVideoCaptureClient/ and s/client_/video_capture_client_/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 "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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #define MAYBE_AllocateBadSize AllocateBadSize 68 #define MAYBE_AllocateBadSize AllocateBadSize
69 #define MAYBE_CaptureMjpeg CaptureMjpeg 69 #define MAYBE_CaptureMjpeg CaptureMjpeg
70 #endif 70 #endif
71 71
72 using ::testing::_; 72 using ::testing::_;
73 using ::testing::SaveArg; 73 using ::testing::SaveArg;
74 74
75 namespace media { 75 namespace media {
76 namespace { 76 namespace {
77 77
78 class MockClient : public VideoCaptureDevice::Client { 78 class MockVideoCaptureClient : public VideoCaptureDevice::Client {
79 public: 79 public:
80 MOCK_METHOD0(DoReserveOutputBuffer, void(void)); 80 MOCK_METHOD0(DoReserveOutputBuffer, void(void));
81 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); 81 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void));
82 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void)); 82 MOCK_METHOD0(DoOnIncomingCapturedVideoFrame, void(void));
83 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void)); 83 MOCK_METHOD0(DoResurrectLastOutputBuffer, void(void));
84 MOCK_METHOD2(OnError, 84 MOCK_METHOD2(OnError,
85 void(const tracked_objects::Location& from_here, 85 void(const tracked_objects::Location& from_here,
86 const std::string& reason)); 86 const std::string& reason));
87 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void)); 87 MOCK_CONST_METHOD0(GetBufferPoolUtilization, double(void));
88 88
89 explicit MockClient(base::Callback<void(const VideoCaptureFormat&)> frame_cb) 89 explicit MockVideoCaptureClient(
90 base::Callback<void(const VideoCaptureFormat&)> frame_cb)
90 : main_thread_(base::ThreadTaskRunnerHandle::Get()), 91 : main_thread_(base::ThreadTaskRunnerHandle::Get()),
91 frame_cb_(frame_cb) {} 92 frame_cb_(frame_cb) {}
92 93
93 void OnIncomingCapturedData(const uint8_t* data, 94 void OnIncomingCapturedData(const uint8_t* data,
94 int length, 95 int length,
95 const VideoCaptureFormat& format, 96 const VideoCaptureFormat& format,
96 int rotation, 97 int rotation,
97 base::TimeTicks reference_time, 98 base::TimeTicks reference_time,
98 base::TimeDelta timestamp) override { 99 base::TimeDelta timestamp) override {
99 ASSERT_GT(length, 0); 100 ASSERT_GT(length, 0);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 }; 153 };
153 154
154 } // namespace 155 } // namespace
155 156
156 class VideoCaptureDeviceTest : public testing::TestWithParam<gfx::Size> { 157 class VideoCaptureDeviceTest : public testing::TestWithParam<gfx::Size> {
157 protected: 158 protected:
158 typedef VideoCaptureDevice::Client Client; 159 typedef VideoCaptureDevice::Client Client;
159 160
160 VideoCaptureDeviceTest() 161 VideoCaptureDeviceTest()
161 : loop_(new base::MessageLoop()), 162 : loop_(new base::MessageLoop()),
162 client_( 163 video_capture_client_(new MockVideoCaptureClient(
163 new MockClient(base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured, 164 base::Bind(&VideoCaptureDeviceTest::OnFrameCaptured,
164 base::Unretained(this)))), 165 base::Unretained(this)))),
165 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory( 166 video_capture_device_factory_(VideoCaptureDeviceFactory::CreateFactory(
166 base::ThreadTaskRunnerHandle::Get())) { 167 base::ThreadTaskRunnerHandle::Get())) {
167 device_enumeration_listener_ = new DeviceEnumerationListener(); 168 device_enumeration_listener_ = new DeviceEnumerationListener();
168 } 169 }
169 170
170 void SetUp() override { 171 void SetUp() override {
171 #if defined(OS_ANDROID) 172 #if defined(OS_ANDROID)
172 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice( 173 VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(
173 base::android::AttachCurrentThread()); 174 base::android::AttachCurrentThread());
174 #endif 175 #endif
175 #if defined(OS_MACOSX) 176 #if defined(OS_MACOSX)
176 AVFoundationGlue::InitializeAVFoundation(); 177 AVFoundationGlue::InitializeAVFoundation();
177 #endif 178 #endif
178 EXPECT_CALL(*client_, DoReserveOutputBuffer()).Times(0); 179 EXPECT_CALL(*video_capture_client_, DoReserveOutputBuffer()).Times(0);
179 EXPECT_CALL(*client_, DoOnIncomingCapturedBuffer()).Times(0); 180 EXPECT_CALL(*video_capture_client_, DoOnIncomingCapturedBuffer()).Times(0);
180 EXPECT_CALL(*client_, DoOnIncomingCapturedVideoFrame()).Times(0); 181 EXPECT_CALL(*video_capture_client_, DoOnIncomingCapturedVideoFrame())
182 .Times(0);
181 } 183 }
182 184
183 void ResetWithNewClient() { 185 void ResetWithNewClient() {
184 client_.reset(new MockClient(base::Bind( 186 video_capture_client_.reset(new MockVideoCaptureClient(base::Bind(
185 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this)))); 187 &VideoCaptureDeviceTest::OnFrameCaptured, base::Unretained(this))));
186 } 188 }
187 189
188 void OnFrameCaptured(const VideoCaptureFormat& format) { 190 void OnFrameCaptured(const VideoCaptureFormat& format) {
189 last_format_ = format; 191 last_format_ = format;
190 run_loop_->QuitClosure().Run(); 192 run_loop_->QuitClosure().Run();
191 } 193 }
192 194
193 void WaitForCapturedFrame() { 195 void WaitForCapturedFrame() {
194 run_loop_.reset(new base::RunLoop()); 196 run_loop_.reset(new base::RunLoop());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 250 }
249 return true; 251 return true;
250 } 252 }
251 253
252 #if defined(OS_WIN) 254 #if defined(OS_WIN)
253 base::win::ScopedCOMInitializer initialize_com_; 255 base::win::ScopedCOMInitializer initialize_com_;
254 #endif 256 #endif
255 std::unique_ptr<VideoCaptureDevice::Names> names_; 257 std::unique_ptr<VideoCaptureDevice::Names> names_;
256 std::unique_ptr<base::MessageLoop> loop_; 258 std::unique_ptr<base::MessageLoop> loop_;
257 std::unique_ptr<base::RunLoop> run_loop_; 259 std::unique_ptr<base::RunLoop> run_loop_;
258 std::unique_ptr<MockClient> client_; 260 std::unique_ptr<MockVideoCaptureClient> video_capture_client_;
259 scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; 261 scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_;
260 VideoCaptureFormat last_format_; 262 VideoCaptureFormat last_format_;
261 std::unique_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; 263 std::unique_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_;
262 }; 264 };
263 265
264 // Cause hangs on Windows Debug. http://crbug.com/417824 266 // Cause hangs on Windows Debug. http://crbug.com/417824
265 #if defined(OS_WIN) && !defined(NDEBUG) 267 #if defined(OS_WIN) && !defined(NDEBUG)
266 #define MAYBE_OpenInvalidDevice DISABLED_OpenInvalidDevice 268 #define MAYBE_OpenInvalidDevice DISABLED_OpenInvalidDevice
267 #else 269 #else
268 #define MAYBE_OpenInvalidDevice OpenInvalidDevice 270 #define MAYBE_OpenInvalidDevice OpenInvalidDevice
(...skipping 13 matching lines...) Expand all
282 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); 284 VideoCaptureDevice::Name device_name("jibberish", "jibberish");
283 #endif 285 #endif
284 std::unique_ptr<VideoCaptureDevice> device = 286 std::unique_ptr<VideoCaptureDevice> device =
285 video_capture_device_factory_->Create(device_name); 287 video_capture_device_factory_->Create(device_name);
286 288
287 #if !defined(OS_MACOSX) 289 #if !defined(OS_MACOSX)
288 EXPECT_TRUE(device == NULL); 290 EXPECT_TRUE(device == NULL);
289 #else 291 #else
290 // The presence of the actual device is only checked on AllocateAndStart() 292 // The presence of the actual device is only checked on AllocateAndStart()
291 // and not on creation. 293 // and not on creation.
292 EXPECT_CALL(*client_, OnError(_, _)).Times(1); 294 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(1);
293 295
294 VideoCaptureParams capture_params; 296 VideoCaptureParams capture_params;
295 capture_params.requested_format.frame_size.SetSize(640, 480); 297 capture_params.requested_format.frame_size.SetSize(640, 480);
296 capture_params.requested_format.frame_rate = 30; 298 capture_params.requested_format.frame_rate = 30;
297 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 299 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
298 device->AllocateAndStart(capture_params, std::move(client_)); 300 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
299 device->StopAndDeAllocate(); 301 device->StopAndDeAllocate();
300 #endif 302 #endif
301 } 303 }
302 304
303 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) { 305 TEST_P(VideoCaptureDeviceTest, CaptureWithSize) {
304 names_ = EnumerateDevices(); 306 names_ = EnumerateDevices();
305 if (names_->empty()) { 307 if (names_->empty()) {
306 VLOG(1) << "No camera available. Exiting test."; 308 VLOG(1) << "No camera available. Exiting test.";
307 return; 309 return;
308 } 310 }
309 311
310 const gfx::Size& size = GetParam(); 312 const gfx::Size& size = GetParam();
311 if (!IsCaptureSizeSupported(names_->front(), size)) 313 if (!IsCaptureSizeSupported(names_->front(), size))
312 return; 314 return;
313 const int width = size.width(); 315 const int width = size.width();
314 const int height = size.height(); 316 const int height = size.height();
315 317
316 std::unique_ptr<VideoCaptureDevice> device( 318 std::unique_ptr<VideoCaptureDevice> device(
317 video_capture_device_factory_->Create(names_->front())); 319 video_capture_device_factory_->Create(names_->front()));
318 ASSERT_TRUE(device); 320 ASSERT_TRUE(device);
319 DVLOG(1) << names_->front().id(); 321 DVLOG(1) << names_->front().id();
320 322
321 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 323 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
322 324
323 VideoCaptureParams capture_params; 325 VideoCaptureParams capture_params;
324 capture_params.requested_format.frame_size.SetSize(width, height); 326 capture_params.requested_format.frame_size.SetSize(width, height);
325 capture_params.requested_format.frame_rate = 30.0f; 327 capture_params.requested_format.frame_rate = 30.0f;
326 capture_params.requested_format.pixel_format = 328 capture_params.requested_format.pixel_format =
327 PIXEL_FORMAT_I420; 329 PIXEL_FORMAT_I420;
328 device->AllocateAndStart(capture_params, std::move(client_)); 330 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
329 // Get captured video frames. 331 // Get captured video frames.
330 WaitForCapturedFrame(); 332 WaitForCapturedFrame();
331 EXPECT_EQ(last_format().frame_size.width(), width); 333 EXPECT_EQ(last_format().frame_size.width(), width);
332 EXPECT_EQ(last_format().frame_size.height(), height); 334 EXPECT_EQ(last_format().frame_size.height(), height);
333 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 335 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
334 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea()); 336 EXPECT_EQ(size.GetArea(), last_format().frame_size.GetArea());
335 device->StopAndDeAllocate(); 337 device->StopAndDeAllocate();
336 } 338 }
337 339
338 #if !defined(OS_ANDROID) 340 #if !defined(OS_ANDROID)
339 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)}; 341 const gfx::Size kCaptureSizes[] = {gfx::Size(640, 480), gfx::Size(1280, 720)};
340 342
341 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests, 343 INSTANTIATE_TEST_CASE_P(VideoCaptureDeviceTests,
342 VideoCaptureDeviceTest, 344 VideoCaptureDeviceTest,
343 testing::ValuesIn(kCaptureSizes)); 345 testing::ValuesIn(kCaptureSizes));
344 #endif 346 #endif
345 347
346 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 348 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
347 names_ = EnumerateDevices(); 349 names_ = EnumerateDevices();
348 if (names_->empty()) { 350 if (names_->empty()) {
349 VLOG(1) << "No camera available. Exiting test."; 351 VLOG(1) << "No camera available. Exiting test.";
350 return; 352 return;
351 } 353 }
352 std::unique_ptr<VideoCaptureDevice> device( 354 std::unique_ptr<VideoCaptureDevice> device(
353 video_capture_device_factory_->Create(names_->front())); 355 video_capture_device_factory_->Create(names_->front()));
354 ASSERT_TRUE(device); 356 ASSERT_TRUE(device);
355 357
356 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 358 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
357 359
358 const gfx::Size input_size(640, 480); 360 const gfx::Size input_size(640, 480);
359 VideoCaptureParams capture_params; 361 VideoCaptureParams capture_params;
360 capture_params.requested_format.frame_size.SetSize(637, 472); 362 capture_params.requested_format.frame_size.SetSize(637, 472);
361 capture_params.requested_format.frame_rate = 35; 363 capture_params.requested_format.frame_rate = 35;
362 capture_params.requested_format.pixel_format = 364 capture_params.requested_format.pixel_format =
363 PIXEL_FORMAT_I420; 365 PIXEL_FORMAT_I420;
364 device->AllocateAndStart(capture_params, std::move(client_)); 366 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
365 WaitForCapturedFrame(); 367 WaitForCapturedFrame();
366 device->StopAndDeAllocate(); 368 device->StopAndDeAllocate();
367 EXPECT_EQ(last_format().frame_size.width(), input_size.width()); 369 EXPECT_EQ(last_format().frame_size.width(), input_size.width());
368 EXPECT_EQ(last_format().frame_size.height(), input_size.height()); 370 EXPECT_EQ(last_format().frame_size.height(), input_size.height());
369 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG) 371 if (last_format().pixel_format != PIXEL_FORMAT_MJPEG)
370 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea()); 372 EXPECT_EQ(input_size.GetArea(), last_format().frame_size.GetArea());
371 } 373 }
372 374
373 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824 375 // Cause hangs on Windows, Linux. Fails Android. http://crbug.com/417824
374 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) { 376 TEST_F(VideoCaptureDeviceTest, DISABLED_ReAllocateCamera) {
(...skipping 11 matching lines...) Expand all
386 gfx::Size resolution; 388 gfx::Size resolution;
387 if (i % 2) { 389 if (i % 2) {
388 resolution = gfx::Size(640, 480); 390 resolution = gfx::Size(640, 480);
389 } else { 391 } else {
390 resolution = gfx::Size(1280, 1024); 392 resolution = gfx::Size(1280, 1024);
391 } 393 }
392 VideoCaptureParams capture_params; 394 VideoCaptureParams capture_params;
393 capture_params.requested_format.frame_size = resolution; 395 capture_params.requested_format.frame_size = resolution;
394 capture_params.requested_format.frame_rate = 30; 396 capture_params.requested_format.frame_rate = 30;
395 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 397 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
396 device->AllocateAndStart(capture_params, std::move(client_)); 398 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
397 device->StopAndDeAllocate(); 399 device->StopAndDeAllocate();
398 } 400 }
399 401
400 // Finally, do a device start and wait for it to finish. 402 // Finally, do a device start and wait for it to finish.
401 VideoCaptureParams capture_params; 403 VideoCaptureParams capture_params;
402 capture_params.requested_format.frame_size.SetSize(320, 240); 404 capture_params.requested_format.frame_size.SetSize(320, 240);
403 capture_params.requested_format.frame_rate = 30; 405 capture_params.requested_format.frame_rate = 30;
404 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 406 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
405 407
406 ResetWithNewClient(); 408 ResetWithNewClient();
407 std::unique_ptr<VideoCaptureDevice> device( 409 std::unique_ptr<VideoCaptureDevice> device(
408 video_capture_device_factory_->Create(names_->front())); 410 video_capture_device_factory_->Create(names_->front()));
409 411
410 device->AllocateAndStart(capture_params, std::move(client_)); 412 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
411 WaitForCapturedFrame(); 413 WaitForCapturedFrame();
412 device->StopAndDeAllocate(); 414 device->StopAndDeAllocate();
413 device.reset(); 415 device.reset();
414 EXPECT_EQ(last_format().frame_size.width(), 320); 416 EXPECT_EQ(last_format().frame_size.width(), 320);
415 EXPECT_EQ(last_format().frame_size.height(), 240); 417 EXPECT_EQ(last_format().frame_size.height(), 240);
416 } 418 }
417 419
418 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 420 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
419 names_ = EnumerateDevices(); 421 names_ = EnumerateDevices();
420 if (names_->empty()) { 422 if (names_->empty()) {
421 VLOG(1) << "No camera available. Exiting test."; 423 VLOG(1) << "No camera available. Exiting test.";
422 return; 424 return;
423 } 425 }
424 std::unique_ptr<VideoCaptureDevice> device( 426 std::unique_ptr<VideoCaptureDevice> device(
425 video_capture_device_factory_->Create(names_->front())); 427 video_capture_device_factory_->Create(names_->front()));
426 ASSERT_TRUE(device); 428 ASSERT_TRUE(device);
427 429
428 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 430 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
429 431
430 VideoCaptureParams capture_params; 432 VideoCaptureParams capture_params;
431 capture_params.requested_format.frame_size.SetSize(640, 480); 433 capture_params.requested_format.frame_size.SetSize(640, 480);
432 capture_params.requested_format.frame_rate = 30; 434 capture_params.requested_format.frame_rate = 30;
433 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 435 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
434 device->AllocateAndStart(capture_params, std::move(client_)); 436 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
435 // Get captured video frames. 437 // Get captured video frames.
436 WaitForCapturedFrame(); 438 WaitForCapturedFrame();
437 EXPECT_EQ(last_format().frame_size.width(), 640); 439 EXPECT_EQ(last_format().frame_size.width(), 640);
438 EXPECT_EQ(last_format().frame_size.height(), 480); 440 EXPECT_EQ(last_format().frame_size.height(), 480);
439 EXPECT_EQ(last_format().frame_rate, 30); 441 EXPECT_EQ(last_format().frame_rate, 30);
440 device->StopAndDeAllocate(); 442 device->StopAndDeAllocate();
441 } 443 }
442 444
443 // Start the camera in 720p to capture MJPEG instead of a raw format. 445 // Start the camera in 720p to capture MJPEG instead of a raw format.
444 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 446 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
445 std::unique_ptr<VideoCaptureDevice::Name> name = 447 std::unique_ptr<VideoCaptureDevice::Name> name =
446 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); 448 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
447 if (!name) { 449 if (!name) {
448 VLOG(1) << "No camera supports MJPEG format. Exiting test."; 450 VLOG(1) << "No camera supports MJPEG format. Exiting test.";
449 return; 451 return;
450 } 452 }
451 #if defined(OS_WIN) 453 #if defined(OS_WIN)
452 base::win::Version version = base::win::GetVersion(); 454 base::win::Version version = base::win::GetVersion();
453 VLOG(1) << "Windows version: " << (int)version; 455 VLOG(1) << "Windows version: " << (int)version;
454 if (version >= base::win::VERSION_WIN10) { 456 if (version >= base::win::VERSION_WIN10) {
455 VLOG(1) << "Skipped on Win10: http://crbug.com/570604."; 457 VLOG(1) << "Skipped on Win10: http://crbug.com/570604.";
456 return; 458 return;
457 } 459 }
458 #endif 460 #endif
459 std::unique_ptr<VideoCaptureDevice> device( 461 std::unique_ptr<VideoCaptureDevice> device(
460 video_capture_device_factory_->Create(*name)); 462 video_capture_device_factory_->Create(*name));
461 ASSERT_TRUE(device); 463 ASSERT_TRUE(device);
462 464
463 EXPECT_CALL(*client_, OnError(_, _)).Times(0); 465 EXPECT_CALL(*video_capture_client_, OnError(_, _)).Times(0);
464 466
465 VideoCaptureParams capture_params; 467 VideoCaptureParams capture_params;
466 capture_params.requested_format.frame_size.SetSize(1280, 720); 468 capture_params.requested_format.frame_size.SetSize(1280, 720);
467 capture_params.requested_format.frame_rate = 30; 469 capture_params.requested_format.frame_rate = 30;
468 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 470 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
469 device->AllocateAndStart(capture_params, std::move(client_)); 471 device->AllocateAndStart(capture_params, std::move(video_capture_client_));
470 // Get captured video frames. 472 // Get captured video frames.
471 WaitForCapturedFrame(); 473 WaitForCapturedFrame();
472 // Verify we get MJPEG from the device. Not all devices can capture 1280x720 474 // Verify we get MJPEG from the device. Not all devices can capture 1280x720
473 // @ 30 fps, so we don't care about the exact resolution we get. 475 // @ 30 fps, so we don't care about the exact resolution we get.
474 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG); 476 EXPECT_EQ(last_format().pixel_format, PIXEL_FORMAT_MJPEG);
475 EXPECT_GE(static_cast<size_t>(1280 * 720), 477 EXPECT_GE(static_cast<size_t>(1280 * 720),
476 last_format().ImageAllocationSize()); 478 last_format().ImageAllocationSize());
477 device->StopAndDeAllocate(); 479 device->StopAndDeAllocate();
478 } 480 }
479 481
480 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) { 482 TEST_F(VideoCaptureDeviceTest, GetDeviceSupportedFormats) {
481 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 483 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
482 // GetDeviceSupportedFormats(). 484 // GetDeviceSupportedFormats().
483 std::unique_ptr<VideoCaptureDevice::Name> name = 485 std::unique_ptr<VideoCaptureDevice::Name> name =
484 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 486 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
485 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else 487 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else
486 // to test here 488 // to test here
487 // since we cannot forecast the hardware capabilities. 489 // since we cannot forecast the hardware capabilities.
488 ASSERT_FALSE(name); 490 ASSERT_FALSE(name);
489 } 491 }
490 492
491 }; // namespace media 493 }; // 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