blob: d26e20cde1f96b179902f31a6fbd8ffc3a24a930 [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"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080032
33namespace android {
34
35/**
36 * Base interface for version >= 2 camera device classes, which interface to
37 * camera HAL device versions >= 2.
38 */
39class CameraDeviceBase : public virtual RefBase {
40 public:
41 virtual ~CameraDeviceBase();
42
Igor Murashkin71381052013-03-04 14:53:08 -080043 /**
44 * The device's camera ID
45 */
46 virtual int getId() const = 0;
47
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080048 virtual status_t initialize(camera_module_t *module) = 0;
49 virtual status_t disconnect() = 0;
50
Jianing Weicb0652e2014-03-12 18:29:36 -070051 virtual status_t dump(int fd, const Vector<String16> &args) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080052
53 /**
54 * The device's static characteristics metadata buffer
55 */
56 virtual const CameraMetadata& info() const = 0;
57
58 /**
59 * Submit request for capture. The CameraDevice takes ownership of the
60 * passed-in buffer.
Jianing Weicb0652e2014-03-12 18:29:36 -070061 * Output lastFrameNumber is the expected frame number of this request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080062 */
Jianing Weicb0652e2014-03-12 18:29:36 -070063 virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080064
65 /**
Jianing Wei90e59c92014-03-12 18:29:36 -070066 * Submit a list of requests.
Jianing Weicb0652e2014-03-12 18:29:36 -070067 * Output lastFrameNumber is the expected last frame number of the list of requests.
Jianing Wei90e59c92014-03-12 18:29:36 -070068 */
Jianing Weicb0652e2014-03-12 18:29:36 -070069 virtual status_t captureList(const List<const CameraMetadata> &requests,
70 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -070071
72 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080073 * Submit request for streaming. The CameraDevice makes a copy of the
74 * passed-in buffer and the caller retains ownership.
Jianing Weicb0652e2014-03-12 18:29:36 -070075 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080076 */
Jianing Weicb0652e2014-03-12 18:29:36 -070077 virtual status_t setStreamingRequest(const CameraMetadata &request,
78 int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080079
80 /**
Jianing Wei90e59c92014-03-12 18:29:36 -070081 * Submit a list of requests for streaming.
Jianing Weicb0652e2014-03-12 18:29:36 -070082 * Output lastFrameNumber is the last frame number of the previous streaming request.
Jianing Wei90e59c92014-03-12 18:29:36 -070083 */
Jianing Weicb0652e2014-03-12 18:29:36 -070084 virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests,
85 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -070086
87 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080088 * Clear the streaming request slot.
Jianing Weicb0652e2014-03-12 18:29:36 -070089 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080090 */
Jianing Weicb0652e2014-03-12 18:29:36 -070091 virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080092
93 /**
94 * Wait until a request with the given ID has been dequeued by the
95 * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
96 * immediately if the latest request received by the HAL has this id.
97 */
98 virtual status_t waitUntilRequestReceived(int32_t requestId,
99 nsecs_t timeout) = 0;
100
101 /**
102 * Create an output stream of the requested size and format.
103 *
104 * If format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, then the HAL device selects
105 * an appropriate format; it can be queried with getStreamInfo.
106 *
107 * If format is HAL_PIXEL_FORMAT_COMPRESSED, the size parameter must be
108 * equal to the size in bytes of the buffers to allocate for the stream. For
109 * other formats, the size parameter is ignored.
110 */
111 virtual status_t createStream(sp<ANativeWindow> consumer,
Zhijun He28c9b6f2014-08-08 12:00:47 -0700112 uint32_t width, uint32_t height, int format, int *id) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800113
114 /**
115 * Create an input reprocess stream that uses buffers from an existing
116 * output stream.
117 */
118 virtual status_t createReprocessStreamFromStream(int outputId, int *id) = 0;
119
120 /**
121 * Get information about a given stream.
122 */
123 virtual status_t getStreamInfo(int id,
124 uint32_t *width, uint32_t *height, uint32_t *format) = 0;
125
126 /**
127 * Set stream gralloc buffer transform
128 */
129 virtual status_t setStreamTransform(int id, int transform) = 0;
130
131 /**
132 * Delete stream. Must not be called if there are requests in flight which
133 * reference that stream.
134 */
135 virtual status_t deleteStream(int id) = 0;
136
137 /**
138 * Delete reprocess stream. Must not be called if there are requests in
139 * flight which reference that stream.
140 */
141 virtual status_t deleteReprocessStream(int id) = 0;
142
143 /**
Igor Murashkine2d167e2014-08-19 16:19:59 -0700144 * Take the currently-defined set of streams and configure the HAL to use
145 * them. This is a long-running operation (may be several hundered ms).
146 *
147 * The device must be idle (see waitUntilDrained) before calling this.
148 *
149 * Returns OK on success; otherwise on error:
150 * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes)
151 * - INVALID_OPERATION if the device was in the wrong state
152 */
153 virtual status_t configureStreams() = 0;
154
155 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800156 * Create a metadata buffer with fields that the HAL device believes are
157 * best for the given use case
158 */
159 virtual status_t createDefaultRequest(int templateId,
160 CameraMetadata *request) = 0;
161
162 /**
163 * Wait until all requests have been processed. Returns INVALID_OPERATION if
164 * the streaming slot is not empty, or TIMED_OUT if the requests haven't
165 * finished processing in 10 seconds.
166 */
167 virtual status_t waitUntilDrained() = 0;
168
169 /**
Zhijun He28c9b6f2014-08-08 12:00:47 -0700170 * Get Jpeg buffer size for a given jpeg resolution.
171 * Negative values are error codes.
172 */
173 virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0;
174
175 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800176 * Abstract class for HAL notification listeners
177 */
178 class NotificationListener {
179 public:
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700180 // The set of notifications is a merge of the notifications required for
181 // API1 and API2.
182
183 // Required for API 1 and 2
Jianing Weicb0652e2014-03-12 18:29:36 -0700184 virtual void notifyError(ICameraDeviceCallbacks::CameraErrorCode errorCode,
185 const CaptureResultExtras &resultExtras) = 0;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700186
187 // Required only for API2
188 virtual void notifyIdle() = 0;
Jianing Weicb0652e2014-03-12 18:29:36 -0700189 virtual void notifyShutter(const CaptureResultExtras &resultExtras,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700190 nsecs_t timestamp) = 0;
191
192 // Required only for API1
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800193 virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0;
194 virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0;
195 virtual void notifyAutoWhitebalance(uint8_t newState,
196 int triggerId) = 0;
197 protected:
198 virtual ~NotificationListener();
199 };
200
201 /**
202 * Connect HAL notifications to a listener. Overwrites previous
203 * listener. Set to NULL to stop receiving notifications.
204 */
205 virtual status_t setNotifyCallback(NotificationListener *listener) = 0;
206
207 /**
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700208 * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
209 * and notifyAutoWhitebalance; if this returns false, the client must
210 * synthesize these notifications from received frame metadata.
211 */
212 virtual bool willNotify3A() = 0;
213
214 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800215 * Wait for a new frame to be produced, with timeout in nanoseconds.
216 * Returns TIMED_OUT when no frame produced within the specified duration
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700217 * May be called concurrently to most methods, except for getNextFrame
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800218 */
219 virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
220
221 /**
Jianing Weicb0652e2014-03-12 18:29:36 -0700222 * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA
223 * if the queue is empty; caller takes ownership of the metadata buffer inside
224 * the capture result object's metadata field.
225 * May be called concurrently to most methods, except for waitForNextFrame.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800226 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700227 virtual status_t getNextResult(CaptureResult *frame) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800228
229 /**
230 * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
231 * autofocus call will be returned by the HAL in all subsequent AF
232 * notifications.
233 */
234 virtual status_t triggerAutofocus(uint32_t id) = 0;
235
236 /**
237 * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
238 * autofocus call will be returned by the HAL in all subsequent AF
239 * notifications.
240 */
241 virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
242
243 /**
244 * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
245 * call will be returned by the HAL in all subsequent AE and AWB
246 * notifications.
247 */
248 virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
249
250 /**
251 * Abstract interface for clients that want to listen to reprocess buffer
252 * release events
253 */
254 struct BufferReleasedListener : public virtual RefBase {
255 virtual void onBufferReleased(buffer_handle_t *handle) = 0;
256 };
257
258 /**
259 * Push a buffer to be reprocessed into a reprocessing stream, and
260 * provide a listener to call once the buffer is returned by the HAL
261 */
262 virtual status_t pushReprocessBuffer(int reprocessStreamId,
263 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700264
265 /**
266 * Flush all pending and in-flight requests. Blocks until flush is
267 * complete.
Jianing Weicb0652e2014-03-12 18:29:36 -0700268 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700269 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700270 virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700271
Zhijun He204e3292014-07-14 17:09:23 -0700272 /**
273 * Get the HAL device version.
274 */
275 virtual uint32_t getDeviceVersion() = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800276};
277
278}; // namespace android
279
280#endif