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