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