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"
12 #if defined(OS_MACOSX)
13 #include "media/video/capture/mac/video_capture_device_factory_mac.h"
14 #elif defined(OS_LINUX)
15 #include "media/video/capture/linux/video_capture_device_factory_linux.h"
16 #elif defined(OS_ANDROID)
17 #include "media/video/capture/android/video_capture_device_factory_android.h"
19 #include "media/video/capture/win/video_capture_device_factory_win.h"
25 scoped_ptr
<VideoCaptureDeviceFactory
> VideoCaptureDeviceFactory::CreateFactory(
26 scoped_refptr
<base::SingleThreadTaskRunner
> ui_task_runner
) {
27 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
28 // Use a Fake or File Video Device Factory if the command line flags are
29 // present, otherwise use the normal, platform-dependent, device factory.
30 if (command_line
->HasSwitch(switches::kUseFakeDeviceForMediaStream
)) {
31 if (command_line
->HasSwitch(switches::kUseFileForFakeVideoCapture
)) {
32 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
33 media::FileVideoCaptureDeviceFactory());
35 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
36 media::FakeVideoCaptureDeviceFactory());
39 // |ui_task_runner| is needed for the Linux ChromeOS factory to retrieve
40 // screen rotations and for the Mac factory to run QTKit device enumeration.
41 #if defined(OS_MACOSX)
42 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
43 VideoCaptureDeviceFactoryMac(ui_task_runner
));
44 #elif defined(OS_LINUX)
45 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
46 VideoCaptureDeviceFactoryLinux(ui_task_runner
));
47 #elif defined(OS_ANDROID)
48 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
49 VideoCaptureDeviceFactoryAndroid());
51 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
52 VideoCaptureDeviceFactoryWin());
54 return scoped_ptr
<VideoCaptureDeviceFactory
>(new
55 VideoCaptureDeviceFactory());
60 VideoCaptureDeviceFactory::VideoCaptureDeviceFactory() {
61 thread_checker_
.DetachFromThread();
64 VideoCaptureDeviceFactory::~VideoCaptureDeviceFactory() {}
66 void VideoCaptureDeviceFactory::EnumerateDeviceNames(const base::Callback
<
67 void(scoped_ptr
<media::VideoCaptureDevice::Names
>)>& callback
) {
68 DCHECK(thread_checker_
.CalledOnValidThread());
69 DCHECK(!callback
.is_null());
70 scoped_ptr
<VideoCaptureDevice::Names
> device_names(
71 new VideoCaptureDevice::Names());
72 GetDeviceNames(device_names
.get());
73 callback
.Run(device_names
.Pass());