blob: 6fd2b39408faddf3b94d0f3a26f96384f63ae6f9 [file] [log] [blame]
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_SERVERS_CAMERA_CAMERADEVICEBASE_H
18#define ANDROID_SERVERS_CAMERA_CAMERADEVICEBASE_H
19
20#include <utils/RefBase.h>
21#include <utils/String8.h>
22#include <utils/String16.h>
23#include <utils/Vector.h>
24#include <utils/Timers.h>
Jianing Wei90e59c92014-03-12 18:29:36 -070025#include <utils/List.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080026
Jianing Weicb0652e2014-03-12 18:29:36 -070027#include <camera/camera2/ICameraDeviceCallbacks.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080028#include "hardware/camera2.h"
Zhijun He0ea8fa42014-07-07 17:05:38 -070029#include "hardware/camera3.h"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080030#include "camera/CameraMetadata.h"
Jianing Weicb0652e2014-03-12 18:29:36 -070031#include "camera/CaptureResult.h"
Yin-Chia Yehe074a932015-01-30 10:29:02 -080032#include "common/CameraModule.h"
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070033#include "gui/IGraphicBufferProducer.h"
Zhijun He125684a2015-12-26 15:07:30 -080034#include "device3/Camera3StreamInterface.h"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080035
36namespace android {
37
38/**
39 * Base interface for version >= 2 camera device classes, which interface to
40 * camera HAL device versions >= 2.
41 */
42class CameraDeviceBase : public virtual RefBase {
43 public:
44 virtual ~CameraDeviceBase();
45
Igor Murashkin71381052013-03-04 14:53:08 -080046 /**
47 * The device's camera ID
48 */
49 virtual int getId() const = 0;
50
Yin-Chia Yehe074a932015-01-30 10:29:02 -080051 virtual status_t initialize(CameraModule *module) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080052 virtual status_t disconnect() = 0;
53
Jianing Weicb0652e2014-03-12 18:29:36 -070054 virtual status_t dump(int fd, const Vector<String16> &args) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080055
56 /**
57 * The device's static characteristics metadata buffer
58 */
59 virtual const CameraMetadata& info() const = 0;
60
61 /**
62 * Submit request for capture. The CameraDevice takes ownership of the
63 * passed-in buffer.
Jianing Weicb0652e2014-03-12 18:29:36 -070064 * Output lastFrameNumber is the expected frame number of this request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080065 */
Jianing Weicb0652e2014-03-12 18:29:36 -070066 virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080067
68 /**
Jianing Wei90e59c92014-03-12 18:29:36 -070069 * Submit a list of requests.
Jianing Weicb0652e2014-03-12 18:29:36 -070070 * Output lastFrameNumber is the expected last frame number of the list of requests.
Jianing Wei90e59c92014-03-12 18:29:36 -070071 */
Jianing Weicb0652e2014-03-12 18:29:36 -070072 virtual status_t captureList(const List<const CameraMetadata> &requests,
73 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -070074
75 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080076 * Submit request for streaming. The CameraDevice makes a copy of the
77 * passed-in buffer and the caller retains ownership.
Jianing Weicb0652e2014-03-12 18:29:36 -070078 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080079 */
Jianing Weicb0652e2014-03-12 18:29:36 -070080 virtual status_t setStreamingRequest(const CameraMetadata &request,
81 int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080082
83 /**
Jianing Wei90e59c92014-03-12 18:29:36 -070084 * Submit a list of requests for streaming.
Jianing Weicb0652e2014-03-12 18:29:36 -070085 * Output lastFrameNumber is the last frame number of the previous streaming request.
Jianing Wei90e59c92014-03-12 18:29:36 -070086 */
Jianing Weicb0652e2014-03-12 18:29:36 -070087 virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests,
88 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -070089
90 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080091 * Clear the streaming request slot.
Jianing Weicb0652e2014-03-12 18:29:36 -070092 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080093 */
Jianing Weicb0652e2014-03-12 18:29:36 -070094 virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080095
96 /**
97 * Wait until a request with the given ID has been dequeued by the
98 * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
99 * immediately if the latest request received by the HAL has this id.
100 */
101 virtual status_t waitUntilRequestReceived(int32_t requestId,
102 nsecs_t timeout) = 0;
103
104 /**
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700105 * Create an output stream of the requested size, format, rotation and dataspace
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800106 *
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800107 * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the
108 * logical dimensions of the buffer, not the number of bytes.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800109 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700110 virtual status_t createStream(sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800111 uint32_t width, uint32_t height, int format,
Zhijun He125684a2015-12-26 15:07:30 -0800112 android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id,
113 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800114
115 /**
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700116 * Create an input stream of width, height, and format.
117 *
118 * Return value is the stream ID if non-negative and an error if negative.
119 */
120 virtual status_t createInputStream(uint32_t width, uint32_t height,
121 int32_t format, /*out*/ int32_t *id) = 0;
122
123 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800124 * Create an input reprocess stream that uses buffers from an existing
125 * output stream.
126 */
127 virtual status_t createReprocessStreamFromStream(int outputId, int *id) = 0;
128
129 /**
130 * Get information about a given stream.
131 */
132 virtual status_t getStreamInfo(int id,
Eino-Ville Talvalad46a6b92015-05-14 17:26:24 -0700133 uint32_t *width, uint32_t *height,
134 uint32_t *format, android_dataspace *dataSpace) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800135
136 /**
137 * Set stream gralloc buffer transform
138 */
139 virtual status_t setStreamTransform(int id, int transform) = 0;
140
141 /**
142 * Delete stream. Must not be called if there are requests in flight which
143 * reference that stream.
144 */
145 virtual status_t deleteStream(int id) = 0;
146
147 /**
148 * Delete reprocess stream. Must not be called if there are requests in
149 * flight which reference that stream.
150 */
151 virtual status_t deleteReprocessStream(int id) = 0;
152
153 /**
Igor Murashkine2d167e2014-08-19 16:19:59 -0700154 * Take the currently-defined set of streams and configure the HAL to use
155 * them. This is a long-running operation (may be several hundered ms).
156 *
157 * The device must be idle (see waitUntilDrained) before calling this.
158 *
159 * Returns OK on success; otherwise on error:
160 * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes)
161 * - INVALID_OPERATION if the device was in the wrong state
162 */
Zhijun He1fa89992015-06-01 15:44:31 -0700163 virtual status_t configureStreams(bool isConstrainedHighSpeed = false) = 0;
Igor Murashkine2d167e2014-08-19 16:19:59 -0700164
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700165 // get the buffer producer of the input stream
166 virtual status_t getInputBufferProducer(
167 sp<IGraphicBufferProducer> *producer) = 0;
168
Igor Murashkine2d167e2014-08-19 16:19:59 -0700169 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800170 * Create a metadata buffer with fields that the HAL device believes are
171 * best for the given use case
172 */
173 virtual status_t createDefaultRequest(int templateId,
174 CameraMetadata *request) = 0;
175
176 /**
177 * Wait until all requests have been processed. Returns INVALID_OPERATION if
178 * the streaming slot is not empty, or TIMED_OUT if the requests haven't
179 * finished processing in 10 seconds.
180 */
181 virtual status_t waitUntilDrained() = 0;
182
183 /**
Zhijun He28c9b6f2014-08-08 12:00:47 -0700184 * Get Jpeg buffer size for a given jpeg resolution.
185 * Negative values are error codes.
186 */
187 virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0;
188
189 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800190 * Abstract class for HAL notification listeners
191 */
192 class NotificationListener {
193 public:
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700194 // The set of notifications is a merge of the notifications required for
195 // API1 and API2.
196
197 // Required for API 1 and 2
Jianing Weicb0652e2014-03-12 18:29:36 -0700198 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
199 const CaptureResultExtras &resultExtras) = 0;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700200
201 // Required only for API2
202 virtual void notifyIdle() = 0;
Jianing Weicb0652e2014-03-12 18:29:36 -0700203 virtual void notifyShutter(const CaptureResultExtras &resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700204 nsecs_t timestamp) = 0;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700205 virtual void notifyPrepared(int streamId) = 0;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700206
207 // Required only for API1
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800208 virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0;
209 virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0;
210 virtual void notifyAutoWhitebalance(uint8_t newState,
211 int triggerId) = 0;
212 protected:
213 virtual ~NotificationListener();
214 };
215
216 /**
217 * Connect HAL notifications to a listener. Overwrites previous
218 * listener. Set to NULL to stop receiving notifications.
219 */
220 virtual status_t setNotifyCallback(NotificationListener *listener) = 0;
221
222 /**
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700223 * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
224 * and notifyAutoWhitebalance; if this returns false, the client must
225 * synthesize these notifications from received frame metadata.
226 */
227 virtual bool willNotify3A() = 0;
228
229 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800230 * Wait for a new frame to be produced, with timeout in nanoseconds.
231 * Returns TIMED_OUT when no frame produced within the specified duration
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700232 * May be called concurrently to most methods, except for getNextFrame
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800233 */
234 virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
235
236 /**
Jianing Weicb0652e2014-03-12 18:29:36 -0700237 * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA
238 * if the queue is empty; caller takes ownership of the metadata buffer inside
239 * the capture result object's metadata field.
240 * May be called concurrently to most methods, except for waitForNextFrame.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800241 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700242 virtual status_t getNextResult(CaptureResult *frame) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800243
244 /**
245 * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
246 * autofocus call will be returned by the HAL in all subsequent AF
247 * notifications.
248 */
249 virtual status_t triggerAutofocus(uint32_t id) = 0;
250
251 /**
252 * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
253 * autofocus call will be returned by the HAL in all subsequent AF
254 * notifications.
255 */
256 virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
257
258 /**
259 * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
260 * call will be returned by the HAL in all subsequent AE and AWB
261 * notifications.
262 */
263 virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
264
265 /**
266 * Abstract interface for clients that want to listen to reprocess buffer
267 * release events
268 */
269 struct BufferReleasedListener : public virtual RefBase {
270 virtual void onBufferReleased(buffer_handle_t *handle) = 0;
271 };
272
273 /**
274 * Push a buffer to be reprocessed into a reprocessing stream, and
275 * provide a listener to call once the buffer is returned by the HAL
276 */
277 virtual status_t pushReprocessBuffer(int reprocessStreamId,
278 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700279
280 /**
281 * Flush all pending and in-flight requests. Blocks until flush is
282 * complete.
Jianing Weicb0652e2014-03-12 18:29:36 -0700283 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700284 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700285 virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700286
Zhijun He204e3292014-07-14 17:09:23 -0700287 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700288 * Prepare stream by preallocating buffers for it asynchronously.
289 * Calls notifyPrepared() once allocation is complete.
290 */
291 virtual status_t prepare(int streamId) = 0;
292
293 /**
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700294 * Free stream resources by dumping its unused gralloc buffers.
295 */
296 virtual status_t tearDown(int streamId) = 0;
297
298 /**
Ruben Brunkc78ac262015-08-13 17:58:46 -0700299 * Prepare stream by preallocating up to maxCount buffers for it asynchronously.
300 * Calls notifyPrepared() once allocation is complete.
301 */
302 virtual status_t prepare(int maxCount, int streamId) = 0;
303
304 /**
Zhijun He204e3292014-07-14 17:09:23 -0700305 * Get the HAL device version.
306 */
307 virtual uint32_t getDeviceVersion() = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800308};
309
310}; // namespace android
311
312#endif