Chromium Code Reviews| 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 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ | |
| 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <unordered_map> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/sequence_checker.h" | |
| 14 #include "base/synchronization/waitable_event.h" | |
| 15 #include "base/threading/thread.h" | |
| 16 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" | |
| 17 #include "media/capture/video/video_capture_device_factory.h" | |
| 18 #include "media/capture/video_capture_types.h" | |
| 19 #include "mojo/public/cpp/bindings/binding.h" | |
| 20 | |
| 21 namespace media { | |
| 22 | |
| 23 // VideoCaptureDeviceFactoryChromeOS delegates all its VCD factory interface | |
| 24 // function calls to CameraHalDelegate. | |
|
chfremer
2017/05/26 17:40:57
As a reader, here, I would expect to find a descri
jcliang
2017/05/31 14:58:06
Done.
| |
| 25 // | |
| 26 // CameraHalDelegate is refcounted because VideoCaptureDeviceFactoryChromeOS and | |
| 27 // CameraDeviceDelegate both need to reference CameraHalDelegate, and | |
| 28 // VideoCaptureDeviceFactoryChromeOS may be destroyed while CameraDeviceDelegate | |
| 29 // is still alive. | |
| 30 class CAPTURE_EXPORT CameraHalDelegate final | |
| 31 : public base::RefCountedThreadSafe<CameraHalDelegate>, | |
| 32 public arc::mojom::CameraModuleCallbacks { | |
| 33 public: | |
| 34 explicit CameraHalDelegate( | |
| 35 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner); | |
|
chfremer
2017/05/26 17:40:57
Either here or in the class-level description it w
jcliang
2017/05/31 14:58:06
Done.
| |
| 36 | |
| 37 // Establishes the Mojo IPC channel to the camera HAL adapter. This method | |
| 38 // should be called before any other methods of CameraHalDelegate is called. | |
| 39 // Called by VideoCaptureDeviceFactoryChromeOS::Init on the browser UI thread. | |
|
chfremer
2017/05/26 17:40:57
I recommend removing the information about by who
jcliang
2017/05/31 14:58:06
Done.
| |
| 40 bool StartCameraModuleIpc(); | |
| 41 | |
| 42 // Delegation methods for the VideoCaptureDeviceFactory interface. These | |
| 43 // methods are called by VideoCaptureDeviceFactoryChromeOS directly. They | |
| 44 // operate on the same thread that the VideoCaptureDeviceFactoryChromeOS runs | |
| 45 // on. | |
|
chfremer
2017/05/26 17:40:57
This raises the following question (in me, as a re
jcliang
2017/05/31 14:58:06
The reason that VideoCaptureDeviceFactoryChromeOS
chfremer
2017/05/31 18:30:41
I see and agree that this is reasonable.
| |
| 46 std::unique_ptr<VideoCaptureDevice> CreateDevice( | |
| 47 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
| 48 const VideoCaptureDeviceDescriptor& device_descriptor); | |
| 49 void GetSupportedFormats( | |
| 50 const VideoCaptureDeviceDescriptor& device_descriptor, | |
| 51 VideoCaptureFormats* supported_formats); | |
| 52 void GetDeviceDescriptors(VideoCaptureDeviceDescriptors* device_descriptors); | |
| 53 | |
| 54 // Synchronous method to get the camera info of |camera_id|. This method may | |
| 55 // be called on any thread. | |
|
chfremer
2017/05/26 17:40:57
Hmm, the method signature does look asynchronous,
jcliang
2017/05/31 14:58:06
Fixed the comment. I forgot to fix the comment aft
| |
| 56 using GetCameraInfoCallback = | |
| 57 base::Callback<void(int32_t, arc::mojom::CameraInfoPtr)>; | |
| 58 void GetCameraInfo(int32_t camera_id, const GetCameraInfoCallback& callback); | |
| 59 | |
| 60 // Asynchronous method to open the camera device designated by |camera_id|. | |
| 61 // This method may be called on any thread; |callback| will run on | |
| 62 // |module_task_runner_|. | |
| 63 using OpenDeviceCallback = | |
| 64 base::Callback<void(int32_t, arc::mojom::Camera3DeviceOpsPtr)>; | |
| 65 void OpenDevice(int32_t camera_id, const OpenDeviceCallback& callback); | |
| 66 | |
| 67 private: | |
| 68 friend class base::RefCountedThreadSafe<CameraHalDelegate>; | |
| 69 | |
| 70 ~CameraHalDelegate(); | |
| 71 | |
| 72 friend class CameraHalDelegateTest; | |
| 73 friend class CameraDeviceDelegateTest; | |
| 74 void StartForTesting(arc::mojom::CameraModulePtrInfo info); | |
|
chfremer
2017/05/26 17:40:57
The need for a test-only API like this is often an
jcliang
2017/05/31 14:58:06
This test-only API is only to make this CL self-co
chfremer
2017/05/31 18:30:41
I don't see any test for CameraHalDelegate in http
jcliang
2017/06/01 17:11:16
Sorry, by self-contained I mean I need to make thi
| |
| 75 | |
| 76 // Resets the Mojo interface and bindings. | |
| 77 void ResetMojoInterfaceOnModuleThread(base::WaitableEvent* interface_closed); | |
| 78 | |
| 79 // Internal method to update the camera info for all built-in cameras. Runs on | |
| 80 // the same thread as CreateDevice, GetSupportedFormats, and | |
| 81 // GetDeviceDescriptors. | |
| 82 bool UpdateBuiltInCameraInfo(); | |
| 83 void UpdateBuiltInCameraInfoOnModuleThread(); | |
| 84 // Callback for GetNumberOfCameras Mojo IPC function. GetNumberOfCameras | |
| 85 // returns the number of built-in cameras on the device. | |
| 86 void OnGotNumberOfCamerasOnModuleThread(int32_t num_cameras); | |
| 87 // Callback for SetCallbacks Mojo IPC function. SetCallbacks is called after | |
| 88 // GetNumberOfCameras is called for the first time, and before any other calls | |
| 89 // to |camera_module_|. | |
| 90 void OnSetCallbacksOnModuleThread(int32_t result); | |
| 91 void GetCameraInfoOnModuleThread(int32_t camera_id, | |
| 92 const GetCameraInfoCallback& callback); | |
| 93 void OnGotCameraInfoOnModuleThread(int32_t camera_id, | |
| 94 int32_t result, | |
| 95 arc::mojom::CameraInfoPtr camera_info); | |
| 96 | |
| 97 // Called by OpenDevice to actually open the device specified by |camera_id|. | |
| 98 // This method runs on |module_task_runner_|. | |
| 99 void OpenDeviceOnModuleThread(int32_t camera_id, | |
| 100 const OpenDeviceCallback& callback); | |
| 101 | |
| 102 // CameraModuleCallbacks implementation. Operates on |module_task_runner_|. | |
| 103 void CameraDeviceStatusChange( | |
| 104 int32_t camera_id, | |
| 105 arc::mojom::CameraDeviceStatus new_status) final; | |
| 106 | |
| 107 // Signaled when |num_builtin_cameras_| and |camera_info_| are updated. | |
| 108 // Queried and waited by UpdateBuiltInCameraInfo, signaled by | |
| 109 // OnGotCameraInfoOnModuleThread. | |
| 110 base::WaitableEvent builtin_camera_info_updated_; | |
| 111 | |
| 112 // |num_builtin_cameras_| stores the number of built-in camera devices | |
| 113 // reported by the camera HAL, and |camera_info_| stores the camera info of | |
| 114 // each camera device. They are modified only on |module_task_runner_|. They | |
| 115 // are also read in GetSupportedFormats and GetDeviceDescriptors, in which the | |
| 116 // access is sequenced through UpdateBuiltInCameraInfo and | |
| 117 // |builtin_camera_info_updated_| to avoid race conditions. | |
| 118 uint32_t num_builtin_cameras_; | |
| 119 std::unordered_map<std::string, arc::mojom::CameraInfoPtr> camera_info_; | |
| 120 | |
| 121 SEQUENCE_CHECKER(sequence_checker_); | |
| 122 | |
| 123 // The task runner where all the camera module Mojo communication takes place. | |
| 124 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner_; | |
| 125 | |
| 126 // The Mojo proxy to access the camera module at the remote camera HAL. Bound | |
| 127 // to |module_task_runner_|. | |
| 128 arc::mojom::CameraModulePtr camera_module_; | |
| 129 | |
| 130 // The Mojo binding serving the camera module callbacks. Bound to | |
| 131 // |module_task_runner_|. | |
| 132 mojo::Binding<arc::mojom::CameraModuleCallbacks> camera_module_callbacks_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate); | |
| 135 }; | |
| 136 | |
| 137 } // namespace media | |
| 138 | |
| 139 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_ | |
| OLD | NEW |