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

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

Issue 270263008: Add a ChromeOS implementation of VideoCaptureDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h" 9 #include "base/test/test_timeouts.h"
9 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
10 #include "media/video/capture/video_capture_device.h" 11 #include "media/video/capture/video_capture_device.h"
11 #include "media/video/capture/video_capture_device_factory.h" 12 #include "media/video/capture/video_capture_device_factory.h"
12 #include "media/video/capture/video_capture_types.h" 13 #include "media/video/capture/video_capture_types.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 #if defined(OS_WIN) 17 #if defined(OS_WIN)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION 169 ? VideoCaptureDevice::Name::MEDIA_FOUNDATION
169 : VideoCaptureDevice::Name::DIRECT_SHOW; 170 : VideoCaptureDevice::Name::DIRECT_SHOW;
170 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); 171 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type);
171 #elif defined(OS_MACOSX) 172 #elif defined(OS_MACOSX)
172 VideoCaptureDevice::Name device_name("jibberish", "jibberish", 173 VideoCaptureDevice::Name device_name("jibberish", "jibberish",
173 VideoCaptureDevice::Name::AVFOUNDATION); 174 VideoCaptureDevice::Name::AVFOUNDATION);
174 #else 175 #else
175 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); 176 VideoCaptureDevice::Name device_name("jibberish", "jibberish");
176 #endif 177 #endif
177 scoped_ptr<VideoCaptureDevice> device = 178 scoped_ptr<VideoCaptureDevice> device =
178 video_capture_device_factory_->Create(device_name); 179 video_capture_device_factory_->Create(
180 base::MessageLoopProxy::current(),
181 device_name);
179 EXPECT_TRUE(device == NULL); 182 EXPECT_TRUE(device == NULL);
180 } 183 }
181 184
182 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { 185 TEST_F(VideoCaptureDeviceTest, CaptureVGA) {
183 video_capture_device_factory_->GetDeviceNames(&names_); 186 video_capture_device_factory_->GetDeviceNames(&names_);
184 if (!names_.size()) { 187 if (!names_.size()) {
185 DVLOG(1) << "No camera available. Exiting test."; 188 DVLOG(1) << "No camera available. Exiting test.";
186 return; 189 return;
187 } 190 }
188 191
189 scoped_ptr<VideoCaptureDevice> device( 192 scoped_ptr<VideoCaptureDevice> device(
190 video_capture_device_factory_->Create(names_.front())); 193 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
194 names_.front()));
191 ASSERT_TRUE(device); 195 ASSERT_TRUE(device);
192 DVLOG(1) << names_.front().id(); 196 DVLOG(1) << names_.front().id();
193 197
194 EXPECT_CALL(*client_, OnErr()) 198 EXPECT_CALL(*client_, OnErr())
195 .Times(0); 199 .Times(0);
196 200
197 VideoCaptureParams capture_params; 201 VideoCaptureParams capture_params;
198 capture_params.requested_format.frame_size.SetSize(640, 480); 202 capture_params.requested_format.frame_size.SetSize(640, 480);
199 capture_params.requested_format.frame_rate = 30; 203 capture_params.requested_format.frame_rate = 30;
200 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 204 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
201 capture_params.allow_resolution_change = false; 205 capture_params.allow_resolution_change = false;
202 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 206 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
203 // Get captured video frames. 207 // Get captured video frames.
204 WaitForCapturedFrame(); 208 WaitForCapturedFrame();
205 EXPECT_EQ(last_format().frame_size.width(), 640); 209 EXPECT_EQ(last_format().frame_size.width(), 640);
206 EXPECT_EQ(last_format().frame_size.height(), 480); 210 EXPECT_EQ(last_format().frame_size.height(), 480);
207 device->StopAndDeAllocate(); 211 device->StopAndDeAllocate();
208 } 212 }
209 213
210 TEST_F(VideoCaptureDeviceTest, Capture720p) { 214 TEST_F(VideoCaptureDeviceTest, Capture720p) {
211 video_capture_device_factory_->GetDeviceNames(&names_); 215 video_capture_device_factory_->GetDeviceNames(&names_);
212 if (!names_.size()) { 216 if (!names_.size()) {
213 DVLOG(1) << "No camera available. Exiting test."; 217 DVLOG(1) << "No camera available. Exiting test.";
214 return; 218 return;
215 } 219 }
216 220
217 scoped_ptr<VideoCaptureDevice> device( 221 scoped_ptr<VideoCaptureDevice> device(
218 video_capture_device_factory_->Create(names_.front())); 222 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
223 names_.front()));
219 ASSERT_TRUE(device); 224 ASSERT_TRUE(device);
220 225
221 EXPECT_CALL(*client_, OnErr()) 226 EXPECT_CALL(*client_, OnErr())
222 .Times(0); 227 .Times(0);
223 228
224 VideoCaptureParams capture_params; 229 VideoCaptureParams capture_params;
225 capture_params.requested_format.frame_size.SetSize(1280, 720); 230 capture_params.requested_format.frame_size.SetSize(1280, 720);
226 capture_params.requested_format.frame_rate = 30; 231 capture_params.requested_format.frame_rate = 30;
227 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 232 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
228 capture_params.allow_resolution_change = false; 233 capture_params.allow_resolution_change = false;
229 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 234 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
230 // Get captured video frames. 235 // Get captured video frames.
231 WaitForCapturedFrame(); 236 WaitForCapturedFrame();
232 device->StopAndDeAllocate(); 237 device->StopAndDeAllocate();
233 } 238 }
234 239
235 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) { 240 TEST_F(VideoCaptureDeviceTest, MAYBE_AllocateBadSize) {
236 video_capture_device_factory_->GetDeviceNames(&names_); 241 video_capture_device_factory_->GetDeviceNames(&names_);
237 if (!names_.size()) { 242 if (!names_.size()) {
238 DVLOG(1) << "No camera available. Exiting test."; 243 DVLOG(1) << "No camera available. Exiting test.";
239 return; 244 return;
240 } 245 }
241 scoped_ptr<VideoCaptureDevice> device( 246 scoped_ptr<VideoCaptureDevice> device(
242 video_capture_device_factory_->Create(names_.front())); 247 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
248 names_.front()));
243 ASSERT_TRUE(device); 249 ASSERT_TRUE(device);
244 250
245 EXPECT_CALL(*client_, OnErr()) 251 EXPECT_CALL(*client_, OnErr())
246 .Times(0); 252 .Times(0);
247 253
248 VideoCaptureParams capture_params; 254 VideoCaptureParams capture_params;
249 capture_params.requested_format.frame_size.SetSize(637, 472); 255 capture_params.requested_format.frame_size.SetSize(637, 472);
250 capture_params.requested_format.frame_rate = 35; 256 capture_params.requested_format.frame_rate = 35;
251 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 257 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
252 capture_params.allow_resolution_change = false; 258 capture_params.allow_resolution_change = false;
253 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 259 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
254 WaitForCapturedFrame(); 260 WaitForCapturedFrame();
255 device->StopAndDeAllocate(); 261 device->StopAndDeAllocate();
256 EXPECT_EQ(last_format().frame_size.width(), 640); 262 EXPECT_EQ(last_format().frame_size.width(), 640);
257 EXPECT_EQ(last_format().frame_size.height(), 480); 263 EXPECT_EQ(last_format().frame_size.height(), 480);
258 } 264 }
259 265
260 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) { 266 TEST_F(VideoCaptureDeviceTest, ReAllocateCamera) {
261 video_capture_device_factory_->GetDeviceNames(&names_); 267 video_capture_device_factory_->GetDeviceNames(&names_);
262 if (!names_.size()) { 268 if (!names_.size()) {
263 DVLOG(1) << "No camera available. Exiting test."; 269 DVLOG(1) << "No camera available. Exiting test.";
264 return; 270 return;
265 } 271 }
266 272
267 // First, do a number of very fast device start/stops. 273 // First, do a number of very fast device start/stops.
268 for (int i = 0; i <= 5; i++) { 274 for (int i = 0; i <= 5; i++) {
269 ResetWithNewClient(); 275 ResetWithNewClient();
270 scoped_ptr<VideoCaptureDevice> device( 276 scoped_ptr<VideoCaptureDevice> device(
271 video_capture_device_factory_->Create(names_.front())); 277 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
278 names_.front()));
272 gfx::Size resolution; 279 gfx::Size resolution;
273 if (i % 2) { 280 if (i % 2) {
274 resolution = gfx::Size(640, 480); 281 resolution = gfx::Size(640, 480);
275 } else { 282 } else {
276 resolution = gfx::Size(1280, 1024); 283 resolution = gfx::Size(1280, 1024);
277 } 284 }
278 VideoCaptureParams capture_params; 285 VideoCaptureParams capture_params;
279 capture_params.requested_format.frame_size = resolution; 286 capture_params.requested_format.frame_size = resolution;
280 capture_params.requested_format.frame_rate = 30; 287 capture_params.requested_format.frame_rate = 30;
281 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 288 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
282 capture_params.allow_resolution_change = false; 289 capture_params.allow_resolution_change = false;
283 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 290 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
284 device->StopAndDeAllocate(); 291 device->StopAndDeAllocate();
285 } 292 }
286 293
287 // Finally, do a device start and wait for it to finish. 294 // Finally, do a device start and wait for it to finish.
288 VideoCaptureParams capture_params; 295 VideoCaptureParams capture_params;
289 capture_params.requested_format.frame_size.SetSize(320, 240); 296 capture_params.requested_format.frame_size.SetSize(320, 240);
290 capture_params.requested_format.frame_rate = 30; 297 capture_params.requested_format.frame_rate = 30;
291 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 298 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
292 capture_params.allow_resolution_change = false; 299 capture_params.allow_resolution_change = false;
293 300
294 ResetWithNewClient(); 301 ResetWithNewClient();
295 scoped_ptr<VideoCaptureDevice> device( 302 scoped_ptr<VideoCaptureDevice> device(
296 video_capture_device_factory_->Create(names_.front())); 303 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
304 names_.front()));
297 305
298 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 306 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
299 WaitForCapturedFrame(); 307 WaitForCapturedFrame();
300 device->StopAndDeAllocate(); 308 device->StopAndDeAllocate();
301 device.reset(); 309 device.reset();
302 EXPECT_EQ(last_format().frame_size.width(), 320); 310 EXPECT_EQ(last_format().frame_size.width(), 320);
303 EXPECT_EQ(last_format().frame_size.height(), 240); 311 EXPECT_EQ(last_format().frame_size.height(), 240);
304 } 312 }
305 313
306 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) { 314 TEST_F(VideoCaptureDeviceTest, DeAllocateCameraWhileRunning) {
307 video_capture_device_factory_->GetDeviceNames(&names_); 315 video_capture_device_factory_->GetDeviceNames(&names_);
308 if (!names_.size()) { 316 if (!names_.size()) {
309 DVLOG(1) << "No camera available. Exiting test."; 317 DVLOG(1) << "No camera available. Exiting test.";
310 return; 318 return;
311 } 319 }
312 scoped_ptr<VideoCaptureDevice> device( 320 scoped_ptr<VideoCaptureDevice> device(
313 video_capture_device_factory_->Create(names_.front())); 321 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
322 names_.front()));
314 ASSERT_TRUE(device); 323 ASSERT_TRUE(device);
315 324
316 EXPECT_CALL(*client_, OnErr()) 325 EXPECT_CALL(*client_, OnErr())
317 .Times(0); 326 .Times(0);
318 327
319 VideoCaptureParams capture_params; 328 VideoCaptureParams capture_params;
320 capture_params.requested_format.frame_size.SetSize(640, 480); 329 capture_params.requested_format.frame_size.SetSize(640, 480);
321 capture_params.requested_format.frame_rate = 30; 330 capture_params.requested_format.frame_rate = 30;
322 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420; 331 capture_params.requested_format.pixel_format = PIXEL_FORMAT_I420;
323 capture_params.allow_resolution_change = false; 332 capture_params.allow_resolution_change = false;
324 device->AllocateAndStart(capture_params, client_.PassAs<Client>()); 333 device->AllocateAndStart(capture_params, client_.PassAs<Client>());
325 // Get captured video frames. 334 // Get captured video frames.
326 WaitForCapturedFrame(); 335 WaitForCapturedFrame();
327 EXPECT_EQ(last_format().frame_size.width(), 640); 336 EXPECT_EQ(last_format().frame_size.width(), 640);
328 EXPECT_EQ(last_format().frame_size.height(), 480); 337 EXPECT_EQ(last_format().frame_size.height(), 480);
329 EXPECT_EQ(last_format().frame_rate, 30); 338 EXPECT_EQ(last_format().frame_rate, 30);
330 device->StopAndDeAllocate(); 339 device->StopAndDeAllocate();
331 } 340 }
332 341
333 // Start the camera in 720p to capture MJPEG instead of a raw format. 342 // Start the camera in 720p to capture MJPEG instead of a raw format.
334 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) { 343 TEST_F(VideoCaptureDeviceTest, MAYBE_CaptureMjpeg) {
335 scoped_ptr<VideoCaptureDevice::Name> name = 344 scoped_ptr<VideoCaptureDevice::Name> name =
336 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG); 345 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MJPEG);
337 if (!name) { 346 if (!name) {
338 DVLOG(1) << "No camera supports MJPEG format. Exiting test."; 347 DVLOG(1) << "No camera supports MJPEG format. Exiting test.";
339 return; 348 return;
340 } 349 }
341 scoped_ptr<VideoCaptureDevice> device( 350 scoped_ptr<VideoCaptureDevice> device(
342 video_capture_device_factory_->Create(*name)); 351 video_capture_device_factory_->Create(base::MessageLoopProxy::current(),
352 *name));
343 ASSERT_TRUE(device); 353 ASSERT_TRUE(device);
344 354
345 EXPECT_CALL(*client_, OnErr()) 355 EXPECT_CALL(*client_, OnErr())
346 .Times(0); 356 .Times(0);
347 357
348 VideoCaptureParams capture_params; 358 VideoCaptureParams capture_params;
349 capture_params.requested_format.frame_size.SetSize(1280, 720); 359 capture_params.requested_format.frame_size.SetSize(1280, 720);
350 capture_params.requested_format.frame_rate = 30; 360 capture_params.requested_format.frame_rate = 30;
351 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG; 361 capture_params.requested_format.pixel_format = PIXEL_FORMAT_MJPEG;
352 capture_params.allow_resolution_change = false; 362 capture_params.allow_resolution_change = false;
(...skipping 10 matching lines...) Expand all
363 // Use PIXEL_FORMAT_MAX to iterate all device names for testing 373 // Use PIXEL_FORMAT_MAX to iterate all device names for testing
364 // GetDeviceSupportedFormats(). 374 // GetDeviceSupportedFormats().
365 scoped_ptr<VideoCaptureDevice::Name> name = 375 scoped_ptr<VideoCaptureDevice::Name> name =
366 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX); 376 GetFirstDeviceNameSupportingPixelFormat(PIXEL_FORMAT_MAX);
367 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here 377 // Verify no camera returned for PIXEL_FORMAT_MAX. Nothing else to test here
368 // since we cannot forecast the hardware capabilities. 378 // since we cannot forecast the hardware capabilities.
369 ASSERT_FALSE(name); 379 ASSERT_FALSE(name);
370 } 380 }
371 381
372 }; // namespace media 382 }; // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/video_capture_device_factory.cc ('k') | media/video/capture/win/video_capture_device_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698