Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: media/capture/video/chromeos/camera_hal_delegate.h

Issue 2837273004: media: add video capture device for ARC++ camera HAL v3 (Closed)
Patch Set: revise some code comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/macros.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/thread.h"
11 #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_capture_types.h"
14 #include "mojo/public/cpp/bindings/binding.h"
15
16 namespace media {
17
18 // VideoCaptureDeviceFactoryChromeOS delegates all its VCD factory interface
19 // function calls to CameraHalDelegate.
20
21 class CAPTURE_EXPORT CameraHalDelegate final
22 : public base::RefCountedThreadSafe<CameraHalDelegate>,
23 public arc::mojom::CameraModuleCallbacks {
24 public:
25 explicit CameraHalDelegate(
26 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner);
27
28 // Establishes the Mojo IPC channel to the camera HAL adapter. This method
29 // should be called before any other methods of CameraHalDelegate is called.
30 // Called by VideoCaptureDeviceFactoryChromeOS::Init on the browser IO thread.
31 bool StartCameraModuleIpc();
32
33 // Delegation methods for the VideoCaptureDeviceFactory interface. These
34 // methods are called by VideoCaptureDeviceFactoryChromeOS directly. They
35 // operate on the same thread that the VideoCaptureDeviceFactoryChromeOS runs
36 // on.
37 std::unique_ptr<VideoCaptureDevice> CreateDevice(
38 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
39 const VideoCaptureDeviceDescriptor& device_descriptor);
40 void GetSupportedFormats(
41 const VideoCaptureDeviceDescriptor& device_descriptor,
42 VideoCaptureFormats* supported_formats);
43 void GetDeviceDescriptors(VideoCaptureDeviceDescriptors* device_descriptors);
44
45 // Synchronous method to get the camera info of |camera_id|. This method may
46 // be called on any thread.
47 using GetCameraInfoCallback =
48 base::Callback<void(int32_t, arc::mojom::CameraInfoPtr)>;
49 void GetCameraInfo(int32_t camera_id, const GetCameraInfoCallback& callback);
50
51 // Asynchronous method to open the camera device designated by |camera_id|.
52 // This method may be called on any thread; |callback| will run on
53 // |module_task_runner_|.
54 using OpenDeviceCallback =
55 base::Callback<void(int32_t, arc::mojom::Camera3DeviceOpsPtr)>;
56 void OpenDevice(int32_t camera_id, const OpenDeviceCallback& callback);
57
58 private:
59 friend class base::RefCountedThreadSafe<CameraHalDelegate>;
60
61 ~CameraHalDelegate();
62
63 // Resets the Mojo interface and bindings.
64 void ResetMojoInterfaceOnModuleThread(base::WaitableEvent* interface_closed);
65
66 // Internal method to attempt to update the camera info for all cameras.
67 // Runs on the same thread as CreateDevice, GetSupportedFormats, and
68 // GetDeviceDescriptors. This is the only entry point to update
69 // |num_cameras_| and |camera_info_|.
70 bool UpdateCameraInfo();
71
72 // The actual methods that update the camera info. These methods run on
73 // |module_task_runner_|.
74 void UpdateCameraInfoOnModuleThread();
75 void OnGotNumberOfCamerasOnModuleThread(int32_t num_cameras);
76 void GetCameraInfoOnModuleThread(int32_t camera_id,
77 const GetCameraInfoCallback& callback);
78 void OnGotCameraInfoOnModuleThread(int32_t camera_id,
79 int32_t result,
80 arc::mojom::CameraInfoPtr camera_info);
81
82 // Signaled when |num_cameras_| and |camera_info_| are updated. Queried and
83 // waited by UpdateCameraInfo, signaled by OnGotCameraInfoOnModuleThread, and
84 // reset by CameraDeviceStatusChange.
85 base::WaitableEvent camera_info_updated_;
86
87 // |num_cameras_| stores the number of camera devices reported by the camera
88 // HAL, and |camera_info_| stores the camera info of each camera device.
89 // They are modified only on |module_task_runner_|. They are also read in
90 // GetSupportedFormats and GetDeviceDescriptors, in which the access is
91 // sequenced through UpdateCameraInfo and |camera_info_updated_| to avoid race
92 // conditions.
93 uint32_t num_cameras_;
94 std::unordered_map<int32_t, arc::mojom::CameraInfoPtr> camera_info_;
95
96 // Called by OpenDevice to actually open the device specified by |camera_id|.
97 // This method runs on |module_task_runner_|.
98 void OpenDeviceOnModuleThread(int32_t camera_id,
99 const OpenDeviceCallback& callback);
100
101 // Registers camera HAL module callback functions. SetCallbacks is called
102 // after GetNumberOfCameras is called for the first time, and before any other
103 // calls to |camera_module_|. These methods run on |module_task_runner_|.
104 void SetCallbacksOnModuleThread();
105 void OnSetCallbacksOnModuleThread(int32_t result);
106 // Indicates if the module callbacks are successfully registered.
107 bool module_callbacks_registered_;
108
109 // CameraModuleCallbacks implementation. Operates on |module_task_runner_|.
110 void CameraDeviceStatusChange(
111 int32_t camera_id,
112 arc::mojom::CameraDeviceStatus new_status) final;
113
114 base::ThreadChecker thread_checker_;
115
116 // The task runner where all the camera module Mojo communication takes place.
117 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner_;
118
119 // The Mojo proxy to access the camera module at the remote camera HAL. Bound
120 // to |module_task_runner_|.
121 arc::mojom::CameraModulePtr camera_module_;
122
123 // The Mojo binding serving the camera module callbacks. Bound to
124 // |module_task_runner_|.
125 mojo::Binding<arc::mojom::CameraModuleCallbacks> camera_module_callbacks_;
126
127 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate);
128 };
129
130 } // namespace media
131
132 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698