| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/capture/video/chromeos/video_capture_device_factory_chromeos.h" |
| 6 |
| 7 #include "base/files/file_util.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "media/capture/video/linux/video_capture_device_factory_linux.h" |
| 10 |
| 11 namespace media { |
| 12 |
| 13 VideoCaptureDeviceFactoryChromeOS::VideoCaptureDeviceFactoryChromeOS( |
| 14 scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_screen_observer) |
| 15 : task_runner_for_screen_observer_(task_runner_for_screen_observer), |
| 16 camera_hal_ipc_thread_("CameraHalIpcThread") {} |
| 17 |
| 18 VideoCaptureDeviceFactoryChromeOS::~VideoCaptureDeviceFactoryChromeOS() { |
| 19 camera_hal_delegate_->Reset(); |
| 20 camera_hal_ipc_thread_.Stop(); |
| 21 } |
| 22 |
| 23 bool VideoCaptureDeviceFactoryChromeOS::Init() { |
| 24 if (!camera_hal_ipc_thread_.Start()) { |
| 25 LOG(ERROR) << "Module thread failed to start"; |
| 26 return false; |
| 27 } |
| 28 camera_hal_delegate_ = |
| 29 new CameraHalDelegate(camera_hal_ipc_thread_.task_runner()); |
| 30 return camera_hal_delegate_->StartCameraModuleIpc(); |
| 31 } |
| 32 |
| 33 std::unique_ptr<VideoCaptureDevice> |
| 34 VideoCaptureDeviceFactoryChromeOS::CreateDevice( |
| 35 const VideoCaptureDeviceDescriptor& device_descriptor) { |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 DCHECK(camera_hal_delegate_); |
| 38 return camera_hal_delegate_->CreateDevice(task_runner_for_screen_observer_, |
| 39 device_descriptor); |
| 40 } |
| 41 |
| 42 void VideoCaptureDeviceFactoryChromeOS::GetSupportedFormats( |
| 43 const VideoCaptureDeviceDescriptor& device_descriptor, |
| 44 VideoCaptureFormats* supported_formats) { |
| 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 46 DCHECK(camera_hal_delegate_); |
| 47 camera_hal_delegate_->GetSupportedFormats(device_descriptor, |
| 48 supported_formats); |
| 49 } |
| 50 |
| 51 void VideoCaptureDeviceFactoryChromeOS::GetDeviceDescriptors( |
| 52 VideoCaptureDeviceDescriptors* device_descriptors) { |
| 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 54 DCHECK(camera_hal_delegate_); |
| 55 camera_hal_delegate_->GetDeviceDescriptors(device_descriptors); |
| 56 } |
| 57 |
| 58 // static |
| 59 bool VideoCaptureDeviceFactoryChromeOS::ShouldEnable() { |
| 60 // Checks whether the Chrome OS binary which provides the HAL v3 camera |
| 61 // service is installed on the device. If the binary exists we assume the |
| 62 // device is using the new camera HAL v3 stack. |
| 63 const base::FilePath kArcCamera3Service("/usr/bin/arc_camera3_service"); |
| 64 return base::PathExists(kArcCamera3Service); |
| 65 } |
| 66 |
| 67 #if defined(OS_CHROMEOS) |
| 68 // static |
| 69 VideoCaptureDeviceFactory* |
| 70 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
| 71 scoped_refptr<base::SingleThreadTaskRunner> |
| 72 task_runner_for_screen_observer) { |
| 73 // On Chrome OS we have to support two use cases: |
| 74 // |
| 75 // 1. For devices that have the camera HAL v3 service running on Chrome OS, |
| 76 // we use the HAL v3 capture device which VideoCaptureDeviceFactoryChromeOS |
| 77 // provides. |
| 78 // 2. Existing devices that use UVC cameras need to use the V4L2 capture |
| 79 // device which VideoCaptureDeviceFacotoryLinux provides; there are also |
| 80 // some special devices that may never be able to implement a camera HAL |
| 81 // v3. |
| 82 if (VideoCaptureDeviceFactoryChromeOS::ShouldEnable()) { |
| 83 auto factory = base::MakeUnique<VideoCaptureDeviceFactoryChromeOS>( |
| 84 task_runner_for_screen_observer); |
| 85 if (!factory->Init()) { |
| 86 return nullptr; |
| 87 } |
| 88 return factory.release(); |
| 89 } else { |
| 90 return new VideoCaptureDeviceFactoryLinux(task_runner_for_screen_observer); |
| 91 } |
| 92 } |
| 93 #endif |
| 94 |
| 95 } // namespace media |
| OLD | NEW |