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

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

Powered by Google App Engine
This is Rietveld 408576698