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