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

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: address wuchengli@'s 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
wuchengli 2017/05/23 04:29:07 Explain why we need to make this reference counted
jcliang 2017/05/25 14:23:47 Done.
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.
wuchengli 2017/05/25 08:24:12 s/IO/UI/
jcliang 2017/05/25 14:23:47 Done.
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 friend class CameraHalDelegateTest;
64 friend class CameraDeviceDelegateTest;
65 void StartForTesting(arc::mojom::CameraModulePtrInfo info);
66
67 // Resets the Mojo interface and bindings.
68 void ResetMojoInterfaceOnModuleThread(base::WaitableEvent* interface_closed);
69
70 // Internal method to update the camera info for all built-in cameras. Runs on
71 // the same thread as CreateDevice, GetSupportedFormats, and
72 // GetDeviceDescriptors.
73 bool UpdateBuiltInCameraInfo();
74 void UpdateBuiltInCameraInfoOnModuleThread();
75 // Callback for GetNumberOfCameras Mojo IPC function. GetNumberOfCameras
76 // returns the number of built-in cameras on the device.
77 void OnGotNumberOfCamerasOnModuleThread(int32_t num_cameras);
78 // Callback for SetCallbacks Mojo IPC function. SetCallbacks is called after
79 // GetNumberOfCameras is called for the first time, and before any other calls
80 // to |camera_module_|.
81 void OnSetCallbacksOnModuleThread(int32_t result);
82 void GetCameraInfoOnModuleThread(int32_t camera_id,
83 const GetCameraInfoCallback& callback);
84 void OnGotCameraInfoOnModuleThread(int32_t camera_id,
85 int32_t result,
86 arc::mojom::CameraInfoPtr camera_info);
87
88 // Called by OpenDevice to actually open the device specified by |camera_id|.
89 // This method runs on |module_task_runner_|.
90 void OpenDeviceOnModuleThread(int32_t camera_id,
91 const OpenDeviceCallback& callback);
92
93 // CameraModuleCallbacks implementation. Operates on |module_task_runner_|.
94 void CameraDeviceStatusChange(
95 int32_t camera_id,
96 arc::mojom::CameraDeviceStatus new_status) final;
97
98 // Signaled when |num_builtin_cameras_| and |camera_info_| are updated.
99 // Queried and waited by UpdateBuiltInCameraInfo, signaled by
100 // OnGotCameraInfoOnModuleThread.
101 base::WaitableEvent builtin_camera_info_updated_;
102
103 // |num_builtin_cameras_| stores the number of built-in camera devices
104 // reported by the camera HAL, and |camera_info_| stores the camera info of
105 // each camera device. They are modified only on |module_task_runner_|. They
106 // are also read in GetSupportedFormats and GetDeviceDescriptors, in which the
107 // access is sequenced through UpdateBuiltInCameraInfo and
108 // |builtin_camera_info_updated_| to avoid race conditions.
109 uint32_t num_builtin_cameras_;
110 std::unordered_map<std::string, arc::mojom::CameraInfoPtr> camera_info_;
111
112 base::ThreadChecker thread_checker_;
113
114 // The task runner where all the camera module Mojo communication takes place.
115 const scoped_refptr<base::SingleThreadTaskRunner> module_task_runner_;
116
117 // The Mojo proxy to access the camera module at the remote camera HAL. Bound
118 // to |module_task_runner_|.
119 arc::mojom::CameraModulePtr camera_module_;
120
121 // The Mojo binding serving the camera module callbacks. Bound to
122 // |module_task_runner_|.
123 mojo::Binding<arc::mojom::CameraModuleCallbacks> camera_module_callbacks_;
124
125 DISALLOW_COPY_AND_ASSIGN(CameraHalDelegate);
126 };
127
128 } // namespace media
129
130 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_HAL_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698