Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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_CAMERA2DEVICE_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERA2DEVICE_H |
| 19 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 20 | #include <utils/Condition.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 21 | #include <utils/Errors.h> |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 22 | #include <utils/List.h> |
| 23 | #include <utils/Mutex.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/String8.h> |
| 26 | #include <utils/String16.h> |
| 27 | #include <utils/Vector.h> |
| 28 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 29 | #include "hardware/camera2.h" |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 30 | #include "camera2/CameraMetadata.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | class Camera2Device : public virtual RefBase { |
| 35 | public: |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 36 | typedef camera2::CameraMetadata CameraMetadata; |
| 37 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 38 | Camera2Device(int id); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 39 | |
| 40 | ~Camera2Device(); |
| 41 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 42 | status_t initialize(camera_module_t *module); |
| 43 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 44 | status_t dump(int fd, const Vector<String16>& args); |
| 45 | |
| 46 | /** |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 47 | * The device's static characteristics metadata buffer |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 48 | */ |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 49 | const CameraMetadata& info() const; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 50 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Submit request for capture. The Camera2Device takes ownership of the |
| 53 | * passed-in buffer. |
| 54 | */ |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 55 | status_t capture(CameraMetadata &request); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 56 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Submit request for streaming. The Camera2Device makes a copy of the |
| 59 | * passed-in buffer and the caller retains ownership. |
| 60 | */ |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 61 | status_t setStreamingRequest(const CameraMetadata &request); |
| 62 | |
| 63 | /** |
| 64 | * Clear the streaming request slot. |
| 65 | */ |
| 66 | status_t clearStreamingRequest(); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Create an output stream of the requested size and format. |
| 70 | * |
| 71 | * If format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, then the HAL device selects |
| 72 | * an appropriate format; it can be queried with getStreamInfo. |
| 73 | * |
| 74 | * If format is HAL_PIXEL_FORMAT_COMPRESSED, the size parameter must be |
| 75 | * equal to the size in bytes of the buffers to allocate for the stream. For |
| 76 | * other formats, the size parameter is ignored. |
| 77 | */ |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 78 | status_t createStream(sp<ANativeWindow> consumer, |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 79 | uint32_t width, uint32_t height, int format, size_t size, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 80 | int *id); |
| 81 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 82 | /** |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame^] | 83 | * Create an input reprocess stream that uses buffers from an existing |
| 84 | * output stream. |
| 85 | */ |
| 86 | status_t createReprocessStreamFromStream(int outputId, int *id); |
| 87 | |
| 88 | /** |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 89 | * Get information about a given stream. |
| 90 | */ |
| 91 | status_t getStreamInfo(int id, |
| 92 | uint32_t *width, uint32_t *height, uint32_t *format); |
| 93 | |
| 94 | /** |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 95 | * Set stream gralloc buffer transform |
| 96 | */ |
| 97 | status_t setStreamTransform(int id, int transform); |
| 98 | |
| 99 | /** |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 100 | * Delete stream. Must not be called if there are requests in flight which |
| 101 | * reference that stream. |
| 102 | */ |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 103 | status_t deleteStream(int id); |
| 104 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 105 | /** |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame^] | 106 | * Delete reprocess stream. Must not be called if there are requests in |
| 107 | * flight which reference that stream. |
| 108 | */ |
| 109 | status_t deleteReprocessStream(int id); |
| 110 | |
| 111 | /** |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 112 | * Create a metadata buffer with fields that the HAL device believes are |
| 113 | * best for the given use case |
| 114 | */ |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 115 | status_t createDefaultRequest(int templateId, CameraMetadata *request); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 116 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 117 | /** |
| 118 | * Wait until all requests have been processed. Returns INVALID_OPERATION if |
| 119 | * the streaming slot is not empty, or TIMED_OUT if the requests haven't |
| 120 | * finished processing in 10 seconds. |
| 121 | */ |
| 122 | status_t waitUntilDrained(); |
| 123 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Abstract class for HAL notification listeners |
| 126 | */ |
| 127 | class NotificationListener { |
| 128 | public: |
| 129 | // Refer to the Camera2 HAL definition for notification definitions |
| 130 | virtual void notifyError(int errorCode, int arg1, int arg2) = 0; |
| 131 | virtual void notifyShutter(int frameNumber, nsecs_t timestamp) = 0; |
| 132 | virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0; |
| 133 | virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0; |
| 134 | virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId) = 0; |
| 135 | protected: |
| 136 | virtual ~NotificationListener(); |
| 137 | }; |
| 138 | |
| 139 | /** |
| 140 | * Connect HAL notifications to a listener. Overwrites previous |
| 141 | * listener. Set to NULL to stop receiving notifications. |
| 142 | */ |
| 143 | status_t setNotifyCallback(NotificationListener *listener); |
| 144 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 145 | /** |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 146 | * Wait for a new frame to be produced, with timeout in nanoseconds. |
| 147 | * Returns TIMED_OUT when no frame produced within the specified duration |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 148 | */ |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 149 | status_t waitForNextFrame(nsecs_t timeout); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * Get next metadata frame from the frame queue. Returns NULL if the queue |
| 153 | * is empty; caller takes ownership of the metadata buffer. |
| 154 | */ |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 155 | status_t getNextFrame(CameraMetadata *frame); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 158 | * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel |
| 159 | * autofocus call will be returned by the HAL in all subsequent AF |
| 160 | * notifications. |
| 161 | */ |
| 162 | status_t triggerAutofocus(uint32_t id); |
| 163 | |
| 164 | /** |
| 165 | * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel |
| 166 | * autofocus call will be returned by the HAL in all subsequent AF |
| 167 | * notifications. |
| 168 | */ |
| 169 | status_t triggerCancelAutofocus(uint32_t id); |
| 170 | |
| 171 | /** |
| 172 | * Trigger pre-capture metering. The latest ID used in a trigger pre-capture |
| 173 | * call will be returned by the HAL in all subsequent AE and AWB |
| 174 | * notifications. |
| 175 | */ |
| 176 | status_t triggerPrecaptureMetering(uint32_t id); |
| 177 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame^] | 178 | /** |
| 179 | * Abstract interface for clients that want to listen to reprocess buffer |
| 180 | * release events |
| 181 | */ |
| 182 | struct BufferReleasedListener: public virtual RefBase { |
| 183 | virtual void onBufferReleased(buffer_handle_t *handle) = 0; |
| 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * Push a buffer to be reprocessed into a reprocessing stream, and |
| 188 | * provide a listener to call once the buffer is returned by the HAL |
| 189 | */ |
| 190 | status_t pushReprocessBuffer(int reprocessStreamId, |
| 191 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener); |
| 192 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 193 | private: |
| 194 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 195 | const int mId; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 196 | camera2_device_t *mDevice; |
| 197 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 198 | CameraMetadata mDeviceInfo; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 199 | vendor_tag_query_ops_t *mVendorTagOps; |
| 200 | |
| 201 | /** |
| 202 | * Queue class for both sending requests to a camera2 device, and for |
| 203 | * receiving frames from a camera2 device. |
| 204 | */ |
| 205 | class MetadataQueue: public camera2_request_queue_src_ops_t, |
| 206 | public camera2_frame_queue_dst_ops_t { |
| 207 | public: |
| 208 | MetadataQueue(); |
| 209 | ~MetadataQueue(); |
| 210 | |
| 211 | // Interface to camera2 HAL device, either for requests (device is |
| 212 | // consumer) or for frames (device is producer) |
| 213 | const camera2_request_queue_src_ops_t* getToConsumerInterface(); |
| 214 | void setFromConsumerInterface(camera2_device_t *d); |
| 215 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 216 | // Connect queue consumer endpoint to a camera2 device |
| 217 | status_t setConsumerDevice(camera2_device_t *d); |
| 218 | // Connect queue producer endpoint to a camera2 device |
| 219 | status_t setProducerDevice(camera2_device_t *d); |
| 220 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 221 | const camera2_frame_queue_dst_ops_t* getToProducerInterface(); |
| 222 | |
| 223 | // Real interfaces. On enqueue, queue takes ownership of buffer pointer |
| 224 | // On dequeue, user takes ownership of buffer pointer. |
| 225 | status_t enqueue(camera_metadata_t *buf); |
| 226 | status_t dequeue(camera_metadata_t **buf, bool incrementCount = true); |
| 227 | int getBufferCount(); |
| 228 | status_t waitForBuffer(nsecs_t timeout); |
| 229 | |
| 230 | // Set repeating buffer(s); if the queue is empty on a dequeue call, the |
| 231 | // queue copies the contents of the stream slot into the queue, and then |
Eino-Ville Talvala | 6ed1ed1 | 2012-06-07 10:46:38 -0700 | [diff] [blame] | 232 | // dequeues the first new entry. The metadata buffers passed in are |
| 233 | // copied. |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 234 | status_t setStreamSlot(camera_metadata_t *buf); |
| 235 | status_t setStreamSlot(const List<camera_metadata_t*> &bufs); |
| 236 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 237 | status_t dump(int fd, const Vector<String16>& args); |
| 238 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 239 | private: |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 240 | status_t signalConsumerLocked(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 241 | status_t freeBuffers(List<camera_metadata_t*>::iterator start, |
| 242 | List<camera_metadata_t*>::iterator end); |
| 243 | |
| 244 | camera2_device_t *mDevice; |
| 245 | |
| 246 | Mutex mMutex; |
| 247 | Condition notEmpty; |
| 248 | |
| 249 | int mFrameCount; |
| 250 | |
| 251 | int mCount; |
| 252 | List<camera_metadata_t*> mEntries; |
| 253 | int mStreamSlotCount; |
| 254 | List<camera_metadata_t*> mStreamSlot; |
| 255 | |
| 256 | bool mSignalConsumer; |
| 257 | |
| 258 | static MetadataQueue* getInstance( |
| 259 | const camera2_frame_queue_dst_ops_t *q); |
| 260 | static MetadataQueue* getInstance( |
| 261 | const camera2_request_queue_src_ops_t *q); |
| 262 | |
| 263 | static int consumer_buffer_count( |
| 264 | const camera2_request_queue_src_ops_t *q); |
| 265 | |
| 266 | static int consumer_dequeue(const camera2_request_queue_src_ops_t *q, |
| 267 | camera_metadata_t **buffer); |
| 268 | |
| 269 | static int consumer_free(const camera2_request_queue_src_ops_t *q, |
| 270 | camera_metadata_t *old_buffer); |
| 271 | |
| 272 | static int producer_dequeue(const camera2_frame_queue_dst_ops_t *q, |
| 273 | size_t entries, size_t bytes, |
| 274 | camera_metadata_t **buffer); |
| 275 | |
| 276 | static int producer_cancel(const camera2_frame_queue_dst_ops_t *q, |
| 277 | camera_metadata_t *old_buffer); |
| 278 | |
| 279 | static int producer_enqueue(const camera2_frame_queue_dst_ops_t *q, |
| 280 | camera_metadata_t *filled_buffer); |
| 281 | |
| 282 | }; // class MetadataQueue |
| 283 | |
| 284 | MetadataQueue mRequestQueue; |
| 285 | MetadataQueue mFrameQueue; |
| 286 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 287 | /** |
| 288 | * Adapter from an ANativeWindow interface to camera2 device stream ops. |
| 289 | * Also takes care of allocating/deallocating stream in device interface |
| 290 | */ |
| 291 | class StreamAdapter: public camera2_stream_ops, public virtual RefBase { |
| 292 | public: |
| 293 | StreamAdapter(camera2_device_t *d); |
| 294 | |
| 295 | ~StreamAdapter(); |
| 296 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 297 | /** |
| 298 | * Create a HAL device stream of the requested size and format. |
| 299 | * |
| 300 | * If format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, then the HAL device |
| 301 | * selects an appropriate format; it can be queried with getFormat. |
| 302 | * |
| 303 | * If format is HAL_PIXEL_FORMAT_COMPRESSED, the size parameter must |
| 304 | * be equal to the size in bytes of the buffers to allocate for the |
| 305 | * stream. For other formats, the size parameter is ignored. |
| 306 | */ |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 307 | status_t connectToDevice(sp<ANativeWindow> consumer, |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 308 | uint32_t width, uint32_t height, int format, size_t size); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 309 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 310 | status_t release(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 311 | |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 312 | status_t setTransform(int transform); |
| 313 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 314 | // Get stream parameters. |
| 315 | // Only valid after a successful connectToDevice call. |
| 316 | int getId() const { return mId; } |
| 317 | uint32_t getWidth() const { return mWidth; } |
| 318 | uint32_t getHeight() const { return mHeight; } |
| 319 | uint32_t getFormat() const { return mFormat; } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 320 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 321 | // Dump stream information |
| 322 | status_t dump(int fd, const Vector<String16>& args); |
| 323 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 324 | private: |
| 325 | enum { |
| 326 | ERROR = -1, |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 327 | RELEASED = 0, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 328 | ALLOCATED, |
| 329 | CONNECTED, |
| 330 | ACTIVE |
| 331 | } mState; |
| 332 | |
| 333 | sp<ANativeWindow> mConsumerInterface; |
| 334 | camera2_device_t *mDevice; |
| 335 | |
| 336 | uint32_t mId; |
| 337 | uint32_t mWidth; |
| 338 | uint32_t mHeight; |
| 339 | uint32_t mFormat; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 340 | size_t mSize; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 341 | uint32_t mUsage; |
| 342 | uint32_t mMaxProducerBuffers; |
| 343 | uint32_t mMaxConsumerBuffers; |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 344 | uint32_t mTotalBuffers; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 345 | int mFormatRequested; |
| 346 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 347 | /** Debugging information */ |
| 348 | uint32_t mActiveBuffers; |
| 349 | uint32_t mFrameCount; |
| 350 | int64_t mLastTimestamp; |
| 351 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 352 | const camera2_stream_ops *getStreamOps(); |
| 353 | |
| 354 | static ANativeWindow* toANW(const camera2_stream_ops_t *w); |
| 355 | |
| 356 | static int dequeue_buffer(const camera2_stream_ops_t *w, |
| 357 | buffer_handle_t** buffer); |
| 358 | |
| 359 | static int enqueue_buffer(const camera2_stream_ops_t* w, |
| 360 | int64_t timestamp, |
| 361 | buffer_handle_t* buffer); |
| 362 | |
| 363 | static int cancel_buffer(const camera2_stream_ops_t* w, |
| 364 | buffer_handle_t* buffer); |
| 365 | |
| 366 | static int set_crop(const camera2_stream_ops_t* w, |
| 367 | int left, int top, int right, int bottom); |
| 368 | }; // class StreamAdapter |
| 369 | |
| 370 | typedef List<sp<StreamAdapter> > StreamList; |
| 371 | StreamList mStreams; |
| 372 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame^] | 373 | /** |
| 374 | * Adapter from an ANativeWindow interface to camera2 device stream ops. |
| 375 | * Also takes care of allocating/deallocating stream in device interface |
| 376 | */ |
| 377 | class ReprocessStreamAdapter: public camera2_stream_in_ops, public virtual RefBase { |
| 378 | public: |
| 379 | ReprocessStreamAdapter(camera2_device_t *d); |
| 380 | |
| 381 | ~ReprocessStreamAdapter(); |
| 382 | |
| 383 | /** |
| 384 | * Create a HAL device reprocess stream based on an existing output stream. |
| 385 | */ |
| 386 | status_t connectToDevice(const sp<StreamAdapter> &outputStream); |
| 387 | |
| 388 | status_t release(); |
| 389 | |
| 390 | /** |
| 391 | * Push buffer into stream for reprocessing. Takes ownership until it notifies |
| 392 | * that the buffer has been released |
| 393 | */ |
| 394 | status_t pushIntoStream(buffer_handle_t *handle, |
| 395 | const wp<BufferReleasedListener> &releaseListener); |
| 396 | |
| 397 | /** |
| 398 | * Get stream parameters. |
| 399 | * Only valid after a successful connectToDevice call. |
| 400 | */ |
| 401 | int getId() const { return mId; } |
| 402 | uint32_t getWidth() const { return mWidth; } |
| 403 | uint32_t getHeight() const { return mHeight; } |
| 404 | uint32_t getFormat() const { return mFormat; } |
| 405 | |
| 406 | // Dump stream information |
| 407 | status_t dump(int fd, const Vector<String16>& args); |
| 408 | |
| 409 | private: |
| 410 | enum { |
| 411 | ERROR = -1, |
| 412 | RELEASED = 0, |
| 413 | ACTIVE |
| 414 | } mState; |
| 415 | |
| 416 | sp<ANativeWindow> mConsumerInterface; |
| 417 | wp<StreamAdapter> mBaseStream; |
| 418 | |
| 419 | struct QueueEntry { |
| 420 | buffer_handle_t *handle; |
| 421 | wp<BufferReleasedListener> releaseListener; |
| 422 | }; |
| 423 | |
| 424 | List<QueueEntry> mQueue; |
| 425 | |
| 426 | List<QueueEntry> mInFlightQueue; |
| 427 | |
| 428 | camera2_device_t *mDevice; |
| 429 | |
| 430 | uint32_t mId; |
| 431 | uint32_t mWidth; |
| 432 | uint32_t mHeight; |
| 433 | uint32_t mFormat; |
| 434 | |
| 435 | /** Debugging information */ |
| 436 | uint32_t mActiveBuffers; |
| 437 | uint32_t mFrameCount; |
| 438 | int64_t mLastTimestamp; |
| 439 | |
| 440 | const camera2_stream_in_ops *getStreamOps(); |
| 441 | |
| 442 | static int acquire_buffer(const camera2_stream_in_ops_t *w, |
| 443 | buffer_handle_t** buffer); |
| 444 | |
| 445 | static int release_buffer(const camera2_stream_in_ops_t* w, |
| 446 | buffer_handle_t* buffer); |
| 447 | |
| 448 | }; // class ReprocessStreamAdapter |
| 449 | |
| 450 | typedef List<sp<ReprocessStreamAdapter> > ReprocessStreamList; |
| 451 | ReprocessStreamList mReprocessStreams; |
| 452 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 453 | // Receives HAL notifications and routes them to the NotificationListener |
| 454 | static void notificationCallback(int32_t msg_type, |
| 455 | int32_t ext1, |
| 456 | int32_t ext2, |
| 457 | int32_t ext3, |
| 458 | void *user); |
| 459 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 460 | }; // class Camera2Device |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 461 | |
| 462 | }; // namespace android |
| 463 | |
| 464 | #endif |