blob: ebbd4ea3df3fb39a9d4a0489f72d56e32cc80aef [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>
25
26#include "hardware/camera2.h"
27#include "camera/CameraMetadata.h"
28
29namespace android {
30
31/**
32 * Base interface for version >= 2 camera device classes, which interface to
33 * camera HAL device versions >= 2.
34 */
35class CameraDeviceBase : public virtual RefBase {
36 public:
37 virtual ~CameraDeviceBase();
38
Igor Murashkin71381052013-03-04 14:53:08 -080039 /**
40 * The device's camera ID
41 */
42 virtual int getId() const = 0;
43
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080044 virtual status_t initialize(camera_module_t *module) = 0;
45 virtual status_t disconnect() = 0;
46
47 virtual status_t dump(int fd, const Vector<String16>& args) = 0;
48
49 /**
50 * The device's static characteristics metadata buffer
51 */
52 virtual const CameraMetadata& info() const = 0;
53
54 /**
55 * Submit request for capture. The CameraDevice takes ownership of the
56 * passed-in buffer.
57 */
58 virtual status_t capture(CameraMetadata &request) = 0;
59
60 /**
61 * Submit request for streaming. The CameraDevice makes a copy of the
62 * passed-in buffer and the caller retains ownership.
63 */
64 virtual status_t setStreamingRequest(const CameraMetadata &request) = 0;
65
66 /**
67 * Clear the streaming request slot.
68 */
69 virtual status_t clearStreamingRequest() = 0;
70
71 /**
72 * Wait until a request with the given ID has been dequeued by the
73 * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
74 * immediately if the latest request received by the HAL has this id.
75 */
76 virtual status_t waitUntilRequestReceived(int32_t requestId,
77 nsecs_t timeout) = 0;
78
79 /**
80 * Create an output stream of the requested size and format.
81 *
82 * If format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, then the HAL device selects
83 * an appropriate format; it can be queried with getStreamInfo.
84 *
85 * If format is HAL_PIXEL_FORMAT_COMPRESSED, the size parameter must be
86 * equal to the size in bytes of the buffers to allocate for the stream. For
87 * other formats, the size parameter is ignored.
88 */
89 virtual status_t createStream(sp<ANativeWindow> consumer,
90 uint32_t width, uint32_t height, int format, size_t size,
91 int *id) = 0;
92
93 /**
94 * Create an input reprocess stream that uses buffers from an existing
95 * output stream.
96 */
97 virtual status_t createReprocessStreamFromStream(int outputId, int *id) = 0;
98
99 /**
100 * Get information about a given stream.
101 */
102 virtual status_t getStreamInfo(int id,
103 uint32_t *width, uint32_t *height, uint32_t *format) = 0;
104
105 /**
106 * Set stream gralloc buffer transform
107 */
108 virtual status_t setStreamTransform(int id, int transform) = 0;
109
110 /**
111 * Delete stream. Must not be called if there are requests in flight which
112 * reference that stream.
113 */
114 virtual status_t deleteStream(int id) = 0;
115
116 /**
117 * Delete reprocess stream. Must not be called if there are requests in
118 * flight which reference that stream.
119 */
120 virtual status_t deleteReprocessStream(int id) = 0;
121
122 /**
123 * Create a metadata buffer with fields that the HAL device believes are
124 * best for the given use case
125 */
126 virtual status_t createDefaultRequest(int templateId,
127 CameraMetadata *request) = 0;
128
129 /**
130 * Wait until all requests have been processed. Returns INVALID_OPERATION if
131 * the streaming slot is not empty, or TIMED_OUT if the requests haven't
132 * finished processing in 10 seconds.
133 */
134 virtual status_t waitUntilDrained() = 0;
135
136 /**
137 * Abstract class for HAL notification listeners
138 */
139 class NotificationListener {
140 public:
141 // Refer to the Camera2 HAL definition for notification definitions
142 virtual void notifyError(int errorCode, int arg1, int arg2) = 0;
143 virtual void notifyShutter(int frameNumber, nsecs_t timestamp) = 0;
144 virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0;
145 virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0;
146 virtual void notifyAutoWhitebalance(uint8_t newState,
147 int triggerId) = 0;
148 protected:
149 virtual ~NotificationListener();
150 };
151
152 /**
153 * Connect HAL notifications to a listener. Overwrites previous
154 * listener. Set to NULL to stop receiving notifications.
155 */
156 virtual status_t setNotifyCallback(NotificationListener *listener) = 0;
157
158 /**
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700159 * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
160 * and notifyAutoWhitebalance; if this returns false, the client must
161 * synthesize these notifications from received frame metadata.
162 */
163 virtual bool willNotify3A() = 0;
164
165 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800166 * Wait for a new frame to be produced, with timeout in nanoseconds.
167 * Returns TIMED_OUT when no frame produced within the specified duration
168 */
169 virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
170
171 /**
172 * Get next metadata frame from the frame queue. Returns NULL if the queue
173 * is empty; caller takes ownership of the metadata buffer.
174 */
175 virtual status_t getNextFrame(CameraMetadata *frame) = 0;
176
177 /**
178 * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
179 * autofocus call will be returned by the HAL in all subsequent AF
180 * notifications.
181 */
182 virtual status_t triggerAutofocus(uint32_t id) = 0;
183
184 /**
185 * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
186 * autofocus call will be returned by the HAL in all subsequent AF
187 * notifications.
188 */
189 virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
190
191 /**
192 * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
193 * call will be returned by the HAL in all subsequent AE and AWB
194 * notifications.
195 */
196 virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
197
198 /**
199 * Abstract interface for clients that want to listen to reprocess buffer
200 * release events
201 */
202 struct BufferReleasedListener : public virtual RefBase {
203 virtual void onBufferReleased(buffer_handle_t *handle) = 0;
204 };
205
206 /**
207 * Push a buffer to be reprocessed into a reprocessing stream, and
208 * provide a listener to call once the buffer is returned by the HAL
209 */
210 virtual status_t pushReprocessBuffer(int reprocessStreamId,
211 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700212
213 /**
214 * Flush all pending and in-flight requests. Blocks until flush is
215 * complete.
216 */
217 virtual status_t flush() = 0;
218
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800219};
220
221}; // namespace android
222
223#endif