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. 4 5 #include "media/video/capture/video_capture_device_factory.h" 6 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" 11 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" 18 #elif defined(OS_WIN) 19 #include "media/video/capture/win/video_capture_device_factory_win.h" 20 #endif 21 22 namespace media { 23 24 // static CreateFactory(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)25scoped_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()); 34 } else { 35 return scoped_ptr<VideoCaptureDeviceFactory>(new 36 media::FakeVideoCaptureDeviceFactory()); 37 } 38 } else { 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()); 50 #elif defined(OS_WIN) 51 return scoped_ptr<VideoCaptureDeviceFactory>(new 52 VideoCaptureDeviceFactoryWin()); 53 #else 54 return scoped_ptr<VideoCaptureDeviceFactory>(new 55 VideoCaptureDeviceFactory()); 56 #endif 57 } 58 } 59 VideoCaptureDeviceFactory()60VideoCaptureDeviceFactory::VideoCaptureDeviceFactory() { 61 thread_checker_.DetachFromThread(); 62 } 63 ~VideoCaptureDeviceFactory()64VideoCaptureDeviceFactory::~VideoCaptureDeviceFactory() {} 65 EnumerateDeviceNames(const base::Callback<void (scoped_ptr<media::VideoCaptureDevice::Names>)> & callback)66void 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()); 74 } 75 76 } // namespace media 77