| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ | 5 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ |
| 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ | 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "media/capture/video/chromeos/arc_camera3_service.h" |
| 11 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" | 12 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" |
| 12 #include "media/capture/video/video_capture_device_factory.h" | 13 #include "media/capture/video/video_capture_device_factory.h" |
| 13 #include "media/capture/video_capture_types.h" | 14 #include "media/capture/video_capture_types.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 // VideoCaptureDeviceFactoryChromeOS delegates all its VCD factory interface | 19 // VideoCaptureDeviceFactoryChromeOS delegates all its VCD factory interface |
| 19 // function calls to CameraHalDelegate. | 20 // function calls to CameraHalDelegate. |
| 20 | 21 |
| 21 class CAPTURE_EXPORT CameraHalDelegate final | 22 class CAPTURE_EXPORT CameraHalDelegate final |
| 22 : public base::RefCountedThreadSafe<CameraHalDelegate>, | 23 : public base::RefCountedThreadSafe<CameraHalDelegate>, |
| 23 public arc::mojom::CameraModuleCallbacks { | 24 public arc::mojom::CameraModuleCallbacks { |
| 24 public: | 25 public: |
| 25 explicit CameraHalDelegate( | 26 explicit CameraHalDelegate( |
| 26 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner); | 27 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner); |
| 27 | 28 |
| 29 // TODO(jcliang): Update docstring. |
| 28 // Establishes the Mojo IPC channel to the camera HAL adapter. This method | 30 // Establishes the Mojo IPC channel to the camera HAL adapter. This method |
| 29 // should be called before any other methods of CameraHalDelegate is called. | 31 // should be called before any other methods of CameraHalDelegate is called. |
| 30 // Called by VideoCaptureDeviceFactoryChromeOS::Init on the browser IO thread. | 32 // Called by VideoCaptureDeviceFactoryChromeOS::Init on the browser IO thread. |
| 31 bool StartCameraModuleIpc(); | 33 void Start(); |
| 32 | 34 |
| 33 // Delegation methods for the VideoCaptureDeviceFactory interface. These | 35 // Delegation methods for the VideoCaptureDeviceFactory interface. These |
| 34 // methods are called by VideoCaptureDeviceFactoryChromeOS directly. They | 36 // methods are called by VideoCaptureDeviceFactoryChromeOS directly. They |
| 35 // operate on the same thread that the VideoCaptureDeviceFactoryChromeOS runs | 37 // operate on the same thread that the VideoCaptureDeviceFactoryChromeOS runs |
| 36 // on. | 38 // on. |
| 37 std::unique_ptr<VideoCaptureDevice> CreateDevice( | 39 std::unique_ptr<VideoCaptureDevice> CreateDevice( |
| 38 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 40 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 39 const VideoCaptureDeviceDescriptor& device_descriptor); | 41 const VideoCaptureDeviceDescriptor& device_descriptor); |
| 40 void GetSupportedFormats( | 42 void GetSupportedFormats( |
| 41 const VideoCaptureDeviceDescriptor& device_descriptor, | 43 const VideoCaptureDeviceDescriptor& device_descriptor, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 // |module_task_runner_|. | 55 // |module_task_runner_|. |
| 54 using OpenDeviceCallback = | 56 using OpenDeviceCallback = |
| 55 base::Callback<void(int32_t, arc::mojom::Camera3DeviceOpsPtr)>; | 57 base::Callback<void(int32_t, arc::mojom::Camera3DeviceOpsPtr)>; |
| 56 void OpenDevice(int32_t camera_id, const OpenDeviceCallback& callback); | 58 void OpenDevice(int32_t camera_id, const OpenDeviceCallback& callback); |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 friend class base::RefCountedThreadSafe<CameraHalDelegate>; | 61 friend class base::RefCountedThreadSafe<CameraHalDelegate>; |
| 60 | 62 |
| 61 ~CameraHalDelegate(); | 63 ~CameraHalDelegate(); |
| 62 | 64 |
| 65 class LocalCameraClient : public ArcCamera3Service::CameraClientObserver { |
| 66 public: |
| 67 LocalCameraClient(scoped_refptr<CameraHalDelegate> camera_hal_delegate); |
| 68 |
| 69 void NotifyCameraHalRegistered(arc::mojom::CameraModulePtr camera_module); |
| 70 |
| 71 private: |
| 72 scoped_refptr<CameraHalDelegate> camera_hal_delegate_; |
| 73 DISALLOW_IMPLICIT_CONSTRUCTORS(LocalCameraClient); |
| 74 }; |
| 75 |
| 76 void SetCameraModule(arc::mojom::CameraModulePtrInfo camera_module_ptr_info); |
| 77 base::WaitableEvent camera_module_set_; |
| 78 |
| 79 // Mojo connection error handler. On Mojo connection error, the handler will |
| 80 // try to re-establish the Mojo connection to the camera HAL. |
| 81 void SetConnectionErrorHandlerOnModuleThread(); |
| 82 void HandleMojoConnectionErrorOnModuleThread(); |
| 83 |
| 63 // Resets the Mojo interface and bindings. | 84 // Resets the Mojo interface and bindings. |
| 64 void ResetMojoInterfaceOnModuleThread(base::WaitableEvent* interface_closed); | 85 void ResetMojoInterfaceOnModuleThread(base::WaitableEvent* interface_closed); |
| 65 | 86 |
| 66 // Internal method to update the camera info for all built-in cameras. Runs on | 87 // Internal method to update the camera info for all built-in cameras. Runs on |
| 67 // the same thread as CreateDevice, GetSupportedFormats, and | 88 // the same thread as CreateDevice, GetSupportedFormats, and |
| 68 // GetDeviceDescriptors. | 89 // GetDeviceDescriptors. |
| 69 bool UpdateBuiltInCameraInfo(); | 90 bool UpdateBuiltInCameraInfo(); |
| 70 void UpdateBuiltInCameraInfoOnModuleThread(); | 91 void UpdateBuiltInCameraInfoOnModuleThread(); |
| 71 // Callback for GetNumberOfCameras Mojo IPC function. GetNumberOfCameras | 92 // Callback for GetNumberOfCameras Mojo IPC function. GetNumberOfCameras |
| 72 // returns the number of built-in cameras on the device. | 93 // returns the number of built-in cameras on the device. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // The Mojo binding serving the camera module callbacks. Bound to | 138 // The Mojo binding serving the camera module callbacks. Bound to |
| 118 // |module_task_runner_|. | 139 // |module_task_runner_|. |
| 119 mojo::Binding<arc::mojom::CameraModuleCallbacks> camera_module_callbacks_; | 140 mojo::Binding<arc::mojom::CameraModuleCallbacks> camera_module_callbacks_; |
| 120 | 141 |
| 121 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate); | 142 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate); |
| 122 }; | 143 }; |
| 123 | 144 |
| 124 } // namespace media | 145 } // namespace media |
| 125 | 146 |
| 126 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ | 147 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ |
| OLD | NEW |