blob: 06615f617b358c0dcdf30bfe6ba5459846d2db1e [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"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080033
34namespace android {
35
36/**
37 * Base interface for version >= 2 camera device classes, which interface to
38 * camera HAL device versions >= 2.
39 */
40class CameraDeviceBase : public virtual RefBase {
41 public:
42 virtual ~CameraDeviceBase();
43
Igor Murashkin71381052013-03-04 14:53:08 -080044 /**
45 * The device's camera ID
46 */
47 virtual int getId() const = 0;
48
Yin-Chia Yehe074a932015-01-30 10:29:02 -080049 virtual status_t initialize(CameraModule *module) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080050 virtual status_t disconnect() = 0;
51
Jianing Weicb0652e2014-03-12 18:29:36 -070052 virtual status_t dump(int fd, const Vector<String16> &args) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080053
54 /**
55 * The device's static characteristics metadata buffer
56 */
57 virtual const CameraMetadata& info() const = 0;
58
59 /**
60 * Submit request for capture. The CameraDevice takes ownership of the
61 * passed-in buffer.
Jianing Weicb0652e2014-03-12 18:29:36 -070062 * Output lastFrameNumber is the expected frame number of this request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080063 */
Jianing Weicb0652e2014-03-12 18:29:36 -070064 virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080065
66 /**
Jianing Wei90e59c92014-03-12 18:29:36 -070067 * Submit a list of requests.
Jianing Weicb0652e2014-03-12 18:29:36 -070068 * Output lastFrameNumber is the expected last frame number of the list of requests.
Jianing Wei90e59c92014-03-12 18:29:36 -070069 */
Jianing Weicb0652e2014-03-12 18:29:36 -070070 virtual status_t captureList(const List<const CameraMetadata> &requests,
71 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -070072
73 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080074 * Submit request for streaming. The CameraDevice makes a copy of the
75 * passed-in buffer and the caller retains ownership.
Jianing Weicb0652e2014-03-12 18:29:36 -070076 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080077 */
Jianing Weicb0652e2014-03-12 18:29:36 -070078 virtual status_t setStreamingRequest(const CameraMetadata &request,
79 int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080080
81 /**
Jianing Wei90e59c92014-03-12 18:29:36 -070082 * Submit a list of requests for streaming.
Jianing Weicb0652e2014-03-12 18:29:36 -070083 * Output lastFrameNumber is the last frame number of the previous streaming request.
Jianing Wei90e59c92014-03-12 18:29:36 -070084 */
Jianing Weicb0652e2014-03-12 18:29:36 -070085 virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests,
86 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -070087
88 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080089 * Clear the streaming request slot.
Jianing Weicb0652e2014-03-12 18:29:36 -070090 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080091 */
Jianing Weicb0652e2014-03-12 18:29:36 -070092 virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080093
94 /**
95 * Wait until a request with the given ID has been dequeued by the
96 * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
97 * immediately if the latest request received by the HAL has this id.
98 */
99 virtual status_t waitUntilRequestReceived(int32_t requestId,
100 nsecs_t timeout) = 0;
101
102 /**
103 * Create an output stream of the requested size and format.
104 *
105 * If format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, then the HAL device selects
106 * an appropriate format; it can be queried with getStreamInfo.
107 *
108 * If format is HAL_PIXEL_FORMAT_COMPRESSED, the size parameter must be
109 * equal to the size in bytes of the buffers to allocate for the stream. For
110 * other formats, the size parameter is ignored.
111 */
112 virtual status_t createStream(sp<ANativeWindow> consumer,
Zhijun He28c9b6f2014-08-08 12:00:47 -0700113 uint32_t width, uint32_t height, int format, int *id) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800114
115 /**
116 * Create an input reprocess stream that uses buffers from an existing
117 * output stream.
118 */
119 virtual status_t createReprocessStreamFromStream(int outputId, int *id) = 0;
120
121 /**
122 * Get information about a given stream.
123 */
124 virtual status_t getStreamInfo(int id,
125 uint32_t *width, uint32_t *height, uint32_t *format) = 0;
126
127 /**
128 * Set stream gralloc buffer transform
129 */
130 virtual status_t setStreamTransform(int id, int transform) = 0;
131
132 /**
133 * Delete stream. Must not be called if there are requests in flight which
134 * reference that stream.
135 */
136 virtual status_t deleteStream(int id) = 0;
137
138 /**
139 * Delete reprocess stream. Must not be called if there are requests in
140 * flight which reference that stream.
141 */
142 virtual status_t deleteReprocessStream(int id) = 0;
143
144 /**
Igor Murashkine2d167e2014-08-19 16:19:59 -0700145 * Take the currently-defined set of streams and configure the HAL to use
146 * them. This is a long-running operation (may be several hundered ms).
147 *
148 * The device must be idle (see waitUntilDrained) before calling this.
149 *
150 * Returns OK on success; otherwise on error:
151 * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes)
152 * - INVALID_OPERATION if the device was in the wrong state
153 */
154 virtual status_t configureStreams() = 0;
155
156 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800157 * Create a metadata buffer with fields that the HAL device believes are
158 * best for the given use case
159 */
160 virtual status_t createDefaultRequest(int templateId,
161 CameraMetadata *request) = 0;
162
163 /**
164 * Wait until all requests have been processed. Returns INVALID_OPERATION if
165 * the streaming slot is not empty, or TIMED_OUT if the requests haven't
166 * finished processing in 10 seconds.
167 */
168 virtual status_t waitUntilDrained() = 0;
169
170 /**
Zhijun He28c9b6f2014-08-08 12:00:47 -0700171 * Get Jpeg buffer size for a given jpeg resolution.
172 * Negative values are error codes.
173 */
174 virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0;
175
176 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800177 * Abstract class for HAL notification listeners
178 */
179 class NotificationListener {
180 public:
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700181 // The set of notifications is a merge of the notifications required for
182 // API1 and API2.
183
184 // Required for API 1 and 2
Jianing Weicb0652e2014-03-12 18:29:36 -0700185 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
186 const CaptureResultExtras &resultExtras) = 0;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700187
188 // Required only for API2
189 virtual void notifyIdle() = 0;
Jianing Weicb0652e2014-03-12 18:29:36 -0700190 virtual void notifyShutter(const CaptureResultExtras &resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700191 nsecs_t timestamp) = 0;
192
193 // Required only for API1
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800194 virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0;
195 virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0;
196 virtual void notifyAutoWhitebalance(uint8_t newState,
197 int triggerId) = 0;
198 protected:
199 virtual ~NotificationListener();
200 };
201
202 /**
203 * Connect HAL notifications to a listener. Overwrites previous
204 * listener. Set to NULL to stop receiving notifications.
205 */
206 virtual status_t setNotifyCallback(NotificationListener *listener) = 0;
207
208 /**
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700209 * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
210 * and notifyAutoWhitebalance; if this returns false, the client must
211 * synthesize these notifications from received frame metadata.
212 */
213 virtual bool willNotify3A() = 0;
214
215 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800216 * Wait for a new frame to be produced, with timeout in nanoseconds.
217 * Returns TIMED_OUT when no frame produced within the specified duration
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700218 * May be called concurrently to most methods, except for getNextFrame
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800219 */
220 virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
221
222 /**
Jianing Weicb0652e2014-03-12 18:29:36 -0700223 * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA
224 * if the queue is empty; caller takes ownership of the metadata buffer inside
225 * the capture result object's metadata field.
226 * May be called concurrently to most methods, except for waitForNextFrame.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800227 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700228 virtual status_t getNextResult(CaptureResult *frame) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800229
230 /**
231 * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
232 * autofocus call will be returned by the HAL in all subsequent AF
233 * notifications.
234 */
235 virtual status_t triggerAutofocus(uint32_t id) = 0;
236
237 /**
238 * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
239 * autofocus call will be returned by the HAL in all subsequent AF
240 * notifications.
241 */
242 virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
243
244 /**
245 * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
246 * call will be returned by the HAL in all subsequent AE and AWB
247 * notifications.
248 */
249 virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
250
251 /**
252 * Abstract interface for clients that want to listen to reprocess buffer
253 * release events
254 */
255 struct BufferReleasedListener : public virtual RefBase {
256 virtual void onBufferReleased(buffer_handle_t *handle) = 0;
257 };
258
259 /**
260 * Push a buffer to be reprocessed into a reprocessing stream, and
261 * provide a listener to call once the buffer is returned by the HAL
262 */
263 virtual status_t pushReprocessBuffer(int reprocessStreamId,
264 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700265
266 /**
267 * Flush all pending and in-flight requests. Blocks until flush is
268 * complete.
Jianing Weicb0652e2014-03-12 18:29:36 -0700269 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700270 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700271 virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700272
Zhijun He204e3292014-07-14 17:09:23 -0700273 /**
274 * Get the HAL device version.
275 */
276 virtual uint32_t getDeviceVersion() = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800277};
278
279}; // namespace android
280
281#endif