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 26 #include "hardware/camera2.h" 27 #include "camera/CameraMetadata.h" 28 29 namespace android { 30 31 /** 32 * Base interface for version >= 2 camera device classes, which interface to 33 * camera HAL device versions >= 2. 34 */ 35 class CameraDeviceBase : public virtual RefBase { 36 public: 37 virtual ~CameraDeviceBase(); 38 39 /** 40 * The device's camera ID 41 */ 42 virtual int getId() const = 0; 43 44 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 // The set of notifications is a merge of the notifications required for 142 // API1 and API2. 143 144 // Required for API 1 and 2 145 virtual void notifyError(int errorCode, int arg1, int arg2) = 0; 146 147 // Required only for API2 148 virtual void notifyIdle() = 0; 149 virtual void notifyShutter(int requestId, 150 nsecs_t timestamp) = 0; 151 152 // Required only for API1 153 virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0; 154 virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0; 155 virtual void notifyAutoWhitebalance(uint8_t newState, 156 int triggerId) = 0; 157 protected: 158 virtual ~NotificationListener(); 159 }; 160 161 /** 162 * Connect HAL notifications to a listener. Overwrites previous 163 * listener. Set to NULL to stop receiving notifications. 164 */ 165 virtual status_t setNotifyCallback(NotificationListener *listener) = 0; 166 167 /** 168 * Whether the device supports calling notifyAutofocus, notifyAutoExposure, 169 * and notifyAutoWhitebalance; if this returns false, the client must 170 * synthesize these notifications from received frame metadata. 171 */ 172 virtual bool willNotify3A() = 0; 173 174 /** 175 * Wait for a new frame to be produced, with timeout in nanoseconds. 176 * Returns TIMED_OUT when no frame produced within the specified duration 177 * May be called concurrently to most methods, except for getNextFrame 178 */ 179 virtual status_t waitForNextFrame(nsecs_t timeout) = 0; 180 181 /** 182 * Get next metadata frame from the frame queue. Returns NULL if the queue 183 * is empty; caller takes ownership of the metadata buffer. 184 * May be called concurrently to most methods, except for waitForNextFrame 185 */ 186 virtual status_t getNextFrame(CameraMetadata *frame) = 0; 187 188 /** 189 * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel 190 * autofocus call will be returned by the HAL in all subsequent AF 191 * notifications. 192 */ 193 virtual status_t triggerAutofocus(uint32_t id) = 0; 194 195 /** 196 * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel 197 * autofocus call will be returned by the HAL in all subsequent AF 198 * notifications. 199 */ 200 virtual status_t triggerCancelAutofocus(uint32_t id) = 0; 201 202 /** 203 * Trigger pre-capture metering. The latest ID used in a trigger pre-capture 204 * call will be returned by the HAL in all subsequent AE and AWB 205 * notifications. 206 */ 207 virtual status_t triggerPrecaptureMetering(uint32_t id) = 0; 208 209 /** 210 * Abstract interface for clients that want to listen to reprocess buffer 211 * release events 212 */ 213 struct BufferReleasedListener : public virtual RefBase { 214 virtual void onBufferReleased(buffer_handle_t *handle) = 0; 215 }; 216 217 /** 218 * Push a buffer to be reprocessed into a reprocessing stream, and 219 * provide a listener to call once the buffer is returned by the HAL 220 */ 221 virtual status_t pushReprocessBuffer(int reprocessStreamId, 222 buffer_handle_t *buffer, wp<BufferReleasedListener> listener) = 0; 223 224 /** 225 * Flush all pending and in-flight requests. Blocks until flush is 226 * complete. 227 */ 228 virtual status_t flush() = 0; 229 230 }; 231 232 }; // namespace android 233 234 #endif 235