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
3 // found in the LICENSE file.
5 #include "media/video/capture/video_capture_device_factory.h"
7 #include "base/command_line.h"
8 #include "media/base/media_switches.h"
9 #include "media/video/capture/fake_video_capture_device_factory.h"
10 #include "media/video/capture/file_video_capture_device_factory.h"
15 scoped_ptr
<VideoCaptureDeviceFactory
> VideoCaptureDeviceFactory::CreateFactory(
16 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
) {
17 const base::CommandLine
* command_line
=
18 base::CommandLine::ForCurrentProcess();
19 // Use a Fake or File Video Device Factory if the command line flags are
20 // present, otherwise use the normal, platform-dependent, device factory.
21 if (command_line
->HasSwitch(switches::kUseFakeDeviceForMediaStream
)) {
22 if (command_line
->HasSwitch(switches::kUseFileForFakeVideoCapture
)) {
23 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
24 media::FileVideoCaptureDeviceFactory());
26 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
27 media::FakeVideoCaptureDeviceFactory());
30 // |ui_task_runner| is needed for the Linux ChromeOS factory to retrieve
31 // screen rotations and for the Mac factory to run QTKit device enumeration.
32 return scoped_ptr
<VideoCaptureDeviceFactory
>(
33 CreateVideoCaptureDeviceFactory(ui_task_runner
));
37 VideoCaptureDeviceFactory::VideoCaptureDeviceFactory() {
38 thread_checker_
.DetachFromThread();
41 VideoCaptureDeviceFactory::~VideoCaptureDeviceFactory() {}
43 void VideoCaptureDeviceFactory::EnumerateDeviceNames(const base::Callback
<
44 void(scoped_ptr
<media::VideoCaptureDevice::Names
>)>& callback
) {
45 DCHECK(thread_checker_
.CalledOnValidThread());
46 DCHECK(!callback
.is_null());
47 scoped_ptr
<VideoCaptureDevice::Names
> device_names(
48 new VideoCaptureDevice::Names());
49 GetDeviceNames(device_names
.get());
50 callback
.Run(device_names
.Pass());
53 #if !defined(OS_MACOSX) && !defined(OS_LINUX) && !defined(OS_ANDROID) && !defined(OS_WIN)
55 VideoCaptureDeviceFactory
*
56 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
57 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
) {