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

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

Issue 2837273004: media: add video capture device for ARC++ camera HAL v3 (Closed)
Patch Set: fix style checker errors Created 3 years, 6 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_DEVICE_DELEGATE_H_
6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h"
12 #include "media/capture/video/video_capture_device.h"
13 #include "media/capture/video_capture_types.h"
14
15 namespace media {
16
17 class CameraHalDelegate;
18 class CameraDeviceContext;
19 class StreamBufferManager;
20
21 // The interface to register buffer with and send capture request to the
22 // camera HAL.
23 class CAPTURE_EXPORT StreamCaptureInterface {
24 public:
25 struct Plane {
26 Plane();
27 ~Plane();
28 mojo::ScopedHandle fd;
29 uint32_t stride;
30 uint32_t offset;
31 };
32
33 virtual ~StreamCaptureInterface() {}
34
35 // Registers a buffer to the camera HAL.
36 virtual void RegisterBuffer(uint64_t buffer_id,
37 arc::mojom::Camera3DeviceOps::BufferType type,
38 uint32_t drm_format,
39 arc::mojom::HalPixelFormat hal_pixel_format,
40 uint32_t width,
41 uint32_t height,
42 std::vector<Plane> planes,
43 base::OnceCallback<void(int32_t)> callback);
44
45 // Sends a capture request to the camera HAL.
46 virtual void ProcessCaptureRequest(
47 arc::mojom::Camera3CaptureRequestPtr request,
48 base::OnceCallback<void(int32_t)> callback);
49 };
50
51 // CameraDeviceDelegate is instantiated on the capture thread where
52 // AllocateAndStart of VideoCaptureDeviceArcChromeOS runs on. All the methods
53 // in CameraDeviceDelegate run on |ipc_task_runner_| and hence all the
54 // access to member variables is sequenced.
55 //
56 // CameraDeviceDelegate is refcounted because it is bound to closures that run
57 // on the module ipc thread of |hal_delegate_| and the device ipc thread which
58 // is referenced by |ipc_task_runner_|.
59 class CAPTURE_EXPORT CameraDeviceDelegate final
60 : public base::RefCountedThreadSafe<CameraDeviceDelegate> {
61 public:
62 CameraDeviceDelegate(
63 VideoCaptureDeviceDescriptor device_descriptor,
64 scoped_refptr<CameraHalDelegate> camera_hal_delegate,
65 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner);
66
67 // Delegation methods for the VideoCaptureDevice interface.
68 void AllocateAndStart(const VideoCaptureParams& params,
69 std::unique_ptr<VideoCaptureDevice::Client> client);
70 void StopAndDeAllocate();
71 void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback);
72 void GetPhotoState(VideoCaptureDevice::GetPhotoStateCallback callback);
73 void SetPhotoOptions(mojom::PhotoSettingsPtr settings,
74 VideoCaptureDevice::SetPhotoOptionsCallback callback);
75
76 // Sets the frame rotation angle in |rotation_|. |rotation_| is clockwise
77 // rotation in degrees, and is passed to |client_| along with the captured
78 // frames.
79 void SetRotation(int rotation);
80
81 private:
82 class StreamCaptureInterfaceImpl;
83
84 friend class CameraDeviceDelegateTest;
85 friend class base::RefCountedThreadSafe<CameraDeviceDelegate>;
86 ~CameraDeviceDelegate();
87
88 // Mojo connection error handler.
89 void OnMojoConnectionError();
90
91 // Callback method for the Close Mojo IPC call. This method resets the Mojo
92 // connection and closes the camera device.
93 void OnClosed(int32_t result);
94
95 // Resets the Mojo interface and bindings.
96 void ResetMojoInterface();
97
98 // Sets |static_metadata_| from |camera_info|.
99 void OnGotCameraInfo(int32_t result, arc::mojom::CameraInfoPtr camera_info);
100
101 // Creates the Mojo connection to the camera device.
102 void OnOpenedDevice(int32_t result);
103
104 // Initializes the camera HAL. Initialize sets up the Camera3CallbackOps with
105 // the camera HAL. OnInitialized continues to ConfigureStreams if the
106 // Initialize call succeeds.
107 void Initialize();
108 void OnInitialized(int32_t result);
109
110 // ConfigureStreams sets up stream context in |streams_| and configure the
111 // streams with the camera HAL. OnConfiguredStreams updates |streams_| with
112 // the stream config returned, and allocates buffers as per |updated_config|
113 // indicates. If there's no error OnConfiguredStreams notifies
114 // |client_| the capture has started by calling OnStarted, and proceeds to
115 // ConstructDefaultRequestSettings.
116 void ConfigureStreams();
117 void OnConfiguredStreams(
118 int32_t result,
119 arc::mojom::Camera3StreamConfigurationPtr updated_config);
120
121 // ConstructDefaultRequestSettings asks the camera HAL for the default request
122 // settings of the stream in |stream_context_|.
123 // OnConstructedDefaultRequestSettings sets the request settings in
124 // |streams_context_|. If there's no error
125 // OnConstructedDefaultRequestSettings calls StartCapture to start the video
126 // capture loop.
127 void ConstructDefaultRequestSettings();
128 void OnConstructedDefaultRequestSettings(
129 arc::mojom::CameraMetadataPtr settings);
130
131 // StreamCaptureInterface implementations. These methods are called by
132 // |stream_buffer_manager_| on |ipc_task_runner_|.
133 void RegisterBuffer(uint64_t buffer_id,
134 arc::mojom::Camera3DeviceOps::BufferType type,
135 uint32_t drm_format,
136 arc::mojom::HalPixelFormat hal_pixel_format,
137 uint32_t width,
138 uint32_t height,
139 std::vector<StreamCaptureInterface::Plane> planes,
140 base::OnceCallback<void(int32_t)> callback);
141 void ProcessCaptureRequest(arc::mojom::Camera3CaptureRequestPtr request,
142 base::OnceCallback<void(int32_t)> callback);
143
144 const VideoCaptureDeviceDescriptor device_descriptor_;
145
146 int32_t camera_id_;
147
148 const scoped_refptr<CameraHalDelegate> camera_hal_delegate_;
149
150 VideoCaptureParams chrome_capture_params_;
151
152 std::unique_ptr<CameraDeviceContext> device_context_;
153
154 std::unique_ptr<StreamBufferManager> stream_buffer_manager_;
155
156 // Stores the static camera characteristics of the camera device. E.g. the
157 // supported formats and resolution, various available exposure and apeture
158 // settings, etc.
159 arc::mojom::CameraMetadataPtr static_metadata_;
160
161 arc::mojom::Camera3DeviceOpsPtr device_ops_;
162
163 // Where all the Mojo IPC calls takes place.
164 const scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_;
165
166 DISALLOW_IMPLICIT_CONSTRUCTORS(CameraDeviceDelegate);
167 };
168
169 } // namespace media
170
171 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698