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

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

Powered by Google App Engine
This is Rietveld 408576698