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