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> |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 24 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 25 | #include "common/CameraDeviceBase.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 29 | /** |
| 30 | * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_2_0 |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 31 | * |
| 32 | * TODO for camera2 API implementation: |
| 33 | * Does not produce notifyShutter / notifyIdle callbacks to NotificationListener |
| 34 | * Use waitUntilDrained for idle. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 35 | */ |
| 36 | class Camera2Device: public CameraDeviceBase { |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 37 | public: |
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 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 40 | virtual ~Camera2Device(); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 43 | * CameraDevice interface |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 44 | */ |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 45 | virtual int getId() const; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 46 | virtual status_t initialize(CameraModule *module); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 47 | virtual status_t disconnect(); |
| 48 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 49 | virtual const CameraMetadata& info() const; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 50 | virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL); |
| 51 | virtual status_t captureList(const List<const CameraMetadata> &requests, |
| 52 | int64_t *lastFrameNumber = NULL); |
| 53 | virtual status_t setStreamingRequest(const CameraMetadata &request, |
| 54 | int64_t *lastFrameNumber = NULL); |
| 55 | virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests, |
| 56 | int64_t *lastFrameNumber = NULL); |
| 57 | virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 58 | virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout); |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 59 | virtual status_t createStream(sp<Surface> consumer, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 60 | uint32_t width, uint32_t height, int format, |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 61 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 62 | virtual status_t createInputStream( |
| 63 | uint32_t width, uint32_t height, int format, int *id); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 64 | virtual status_t createReprocessStreamFromStream(int outputId, int *id); |
| 65 | virtual status_t getStreamInfo(int id, |
Eino-Ville Talvala | d46a6b9 | 2015-05-14 17:26:24 -0700 | [diff] [blame] | 66 | uint32_t *width, uint32_t *height, |
| 67 | uint32_t *format, android_dataspace *dataSpace); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 68 | virtual status_t setStreamTransform(int id, int transform); |
| 69 | virtual status_t deleteStream(int id); |
| 70 | virtual status_t deleteReprocessStream(int id); |
Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 71 | // No-op on HAL2 devices |
Zhijun He | 1fa8999 | 2015-06-01 15:44:31 -0700 | [diff] [blame] | 72 | virtual status_t configureStreams(bool isConstrainedHighSpeed = false); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 73 | virtual status_t getInputBufferProducer( |
| 74 | sp<IGraphicBufferProducer> *producer); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 75 | virtual status_t createDefaultRequest(int templateId, CameraMetadata *request); |
| 76 | virtual status_t waitUntilDrained(); |
| 77 | virtual status_t setNotifyCallback(NotificationListener *listener); |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 78 | virtual bool willNotify3A(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 79 | virtual status_t waitForNextFrame(nsecs_t timeout); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 80 | virtual status_t getNextResult(CaptureResult *frame); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 81 | virtual status_t triggerAutofocus(uint32_t id); |
| 82 | virtual status_t triggerCancelAutofocus(uint32_t id); |
| 83 | virtual status_t triggerPrecaptureMetering(uint32_t id); |
| 84 | virtual status_t pushReprocessBuffer(int reprocessStreamId, |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 85 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener); |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 86 | // Flush implemented as just a wait |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 87 | virtual status_t flush(int64_t *lastFrameNumber = NULL); |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 88 | // Prepare and tearDown are no-ops |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 89 | virtual status_t prepare(int streamId); |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 90 | virtual status_t tearDown(int streamId); |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame^] | 91 | virtual status_t prepare(int maxCount, int streamId); |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 92 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 93 | virtual uint32_t getDeviceVersion(); |
Zhijun He | 28c9b6f | 2014-08-08 12:00:47 -0700 | [diff] [blame] | 94 | virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const; |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 95 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 96 | private: |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 97 | const int mId; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 98 | camera2_device_t *mHal2Device; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 99 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 100 | CameraMetadata mDeviceInfo; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 101 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 102 | uint32_t mDeviceVersion; |
| 103 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Queue class for both sending requests to a camera2 device, and for |
| 106 | * receiving frames from a camera2 device. |
| 107 | */ |
| 108 | class MetadataQueue: public camera2_request_queue_src_ops_t, |
| 109 | public camera2_frame_queue_dst_ops_t { |
| 110 | public: |
| 111 | MetadataQueue(); |
| 112 | ~MetadataQueue(); |
| 113 | |
| 114 | // Interface to camera2 HAL device, either for requests (device is |
| 115 | // consumer) or for frames (device is producer) |
| 116 | const camera2_request_queue_src_ops_t* getToConsumerInterface(); |
| 117 | void setFromConsumerInterface(camera2_device_t *d); |
| 118 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 119 | // Connect queue consumer endpoint to a camera2 device |
| 120 | status_t setConsumerDevice(camera2_device_t *d); |
| 121 | // Connect queue producer endpoint to a camera2 device |
| 122 | status_t setProducerDevice(camera2_device_t *d); |
| 123 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 124 | const camera2_frame_queue_dst_ops_t* getToProducerInterface(); |
| 125 | |
| 126 | // Real interfaces. On enqueue, queue takes ownership of buffer pointer |
| 127 | // On dequeue, user takes ownership of buffer pointer. |
| 128 | status_t enqueue(camera_metadata_t *buf); |
Eino-Ville Talvala | fbd6066 | 2012-10-16 10:28:07 -0700 | [diff] [blame] | 129 | status_t dequeue(camera_metadata_t **buf, bool incrementCount = false); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 130 | int getBufferCount(); |
| 131 | status_t waitForBuffer(nsecs_t timeout); |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 132 | // Wait until a buffer with the given ID is dequeued. Will return |
| 133 | // immediately if the latest buffer dequeued has that ID. |
| 134 | status_t waitForDequeue(int32_t id, nsecs_t timeout); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 135 | |
| 136 | // Set repeating buffer(s); if the queue is empty on a dequeue call, the |
| 137 | // queue copies the contents of the stream slot into the queue, and then |
Chien-Yu Chen | 80de5dc | 2014-11-07 17:45:00 -0800 | [diff] [blame] | 138 | // dequeues the first new entry. The methods take the ownership of the |
| 139 | // metadata buffers passed in. |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 140 | status_t setStreamSlot(camera_metadata_t *buf); |
| 141 | status_t setStreamSlot(const List<camera_metadata_t*> &bufs); |
| 142 | |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 143 | // Clear the request queue and the streaming slot |
| 144 | status_t clear(); |
| 145 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 146 | status_t dump(int fd, const Vector<String16>& args); |
| 147 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 148 | private: |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 149 | status_t signalConsumerLocked(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 150 | status_t freeBuffers(List<camera_metadata_t*>::iterator start, |
| 151 | List<camera_metadata_t*>::iterator end); |
| 152 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 153 | camera2_device_t *mHal2Device; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 154 | |
| 155 | Mutex mMutex; |
| 156 | Condition notEmpty; |
| 157 | |
| 158 | int mFrameCount; |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 159 | int32_t mLatestRequestId; |
| 160 | Condition mNewRequestId; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 161 | |
| 162 | int mCount; |
| 163 | List<camera_metadata_t*> mEntries; |
| 164 | int mStreamSlotCount; |
| 165 | List<camera_metadata_t*> mStreamSlot; |
| 166 | |
| 167 | bool mSignalConsumer; |
| 168 | |
| 169 | static MetadataQueue* getInstance( |
| 170 | const camera2_frame_queue_dst_ops_t *q); |
| 171 | static MetadataQueue* getInstance( |
| 172 | const camera2_request_queue_src_ops_t *q); |
| 173 | |
| 174 | static int consumer_buffer_count( |
| 175 | const camera2_request_queue_src_ops_t *q); |
| 176 | |
| 177 | static int consumer_dequeue(const camera2_request_queue_src_ops_t *q, |
| 178 | camera_metadata_t **buffer); |
| 179 | |
| 180 | static int consumer_free(const camera2_request_queue_src_ops_t *q, |
| 181 | camera_metadata_t *old_buffer); |
| 182 | |
| 183 | static int producer_dequeue(const camera2_frame_queue_dst_ops_t *q, |
| 184 | size_t entries, size_t bytes, |
| 185 | camera_metadata_t **buffer); |
| 186 | |
| 187 | static int producer_cancel(const camera2_frame_queue_dst_ops_t *q, |
| 188 | camera_metadata_t *old_buffer); |
| 189 | |
| 190 | static int producer_enqueue(const camera2_frame_queue_dst_ops_t *q, |
| 191 | camera_metadata_t *filled_buffer); |
| 192 | |
| 193 | }; // class MetadataQueue |
| 194 | |
| 195 | MetadataQueue mRequestQueue; |
| 196 | MetadataQueue mFrameQueue; |
| 197 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 198 | /** |
| 199 | * Adapter from an ANativeWindow interface to camera2 device stream ops. |
| 200 | * Also takes care of allocating/deallocating stream in device interface |
| 201 | */ |
| 202 | class StreamAdapter: public camera2_stream_ops, public virtual RefBase { |
| 203 | public: |
| 204 | StreamAdapter(camera2_device_t *d); |
| 205 | |
| 206 | ~StreamAdapter(); |
| 207 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 208 | /** |
| 209 | * Create a HAL device stream of the requested size and format. |
| 210 | * |
| 211 | * If format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE, then the HAL device |
| 212 | * selects an appropriate format; it can be queried with getFormat. |
| 213 | * |
| 214 | * If format is HAL_PIXEL_FORMAT_COMPRESSED, the size parameter must |
| 215 | * be equal to the size in bytes of the buffers to allocate for the |
| 216 | * stream. For other formats, the size parameter is ignored. |
| 217 | */ |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 218 | status_t connectToDevice(sp<ANativeWindow> consumer, |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 219 | uint32_t width, uint32_t height, int format, size_t size); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 220 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 221 | status_t release(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 222 | |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 223 | status_t setTransform(int transform); |
| 224 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 225 | // Get stream parameters. |
| 226 | // Only valid after a successful connectToDevice call. |
| 227 | int getId() const { return mId; } |
| 228 | uint32_t getWidth() const { return mWidth; } |
| 229 | uint32_t getHeight() const { return mHeight; } |
| 230 | uint32_t getFormat() const { return mFormat; } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 231 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 232 | // Dump stream information |
| 233 | status_t dump(int fd, const Vector<String16>& args); |
| 234 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 235 | private: |
| 236 | enum { |
| 237 | ERROR = -1, |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 238 | RELEASED = 0, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 239 | ALLOCATED, |
| 240 | CONNECTED, |
| 241 | ACTIVE |
| 242 | } mState; |
| 243 | |
| 244 | sp<ANativeWindow> mConsumerInterface; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 245 | camera2_device_t *mHal2Device; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 246 | |
| 247 | uint32_t mId; |
| 248 | uint32_t mWidth; |
| 249 | uint32_t mHeight; |
| 250 | uint32_t mFormat; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 251 | size_t mSize; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 252 | uint32_t mUsage; |
| 253 | uint32_t mMaxProducerBuffers; |
| 254 | uint32_t mMaxConsumerBuffers; |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 255 | uint32_t mTotalBuffers; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 256 | int mFormatRequested; |
| 257 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 258 | /** Debugging information */ |
| 259 | uint32_t mActiveBuffers; |
| 260 | uint32_t mFrameCount; |
| 261 | int64_t mLastTimestamp; |
| 262 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 263 | const camera2_stream_ops *getStreamOps(); |
| 264 | |
| 265 | static ANativeWindow* toANW(const camera2_stream_ops_t *w); |
| 266 | |
| 267 | static int dequeue_buffer(const camera2_stream_ops_t *w, |
| 268 | buffer_handle_t** buffer); |
| 269 | |
| 270 | static int enqueue_buffer(const camera2_stream_ops_t* w, |
| 271 | int64_t timestamp, |
| 272 | buffer_handle_t* buffer); |
| 273 | |
| 274 | static int cancel_buffer(const camera2_stream_ops_t* w, |
| 275 | buffer_handle_t* buffer); |
| 276 | |
| 277 | static int set_crop(const camera2_stream_ops_t* w, |
| 278 | int left, int top, int right, int bottom); |
| 279 | }; // class StreamAdapter |
| 280 | |
| 281 | typedef List<sp<StreamAdapter> > StreamList; |
| 282 | StreamList mStreams; |
| 283 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 284 | /** |
| 285 | * Adapter from an ANativeWindow interface to camera2 device stream ops. |
| 286 | * Also takes care of allocating/deallocating stream in device interface |
| 287 | */ |
| 288 | class ReprocessStreamAdapter: public camera2_stream_in_ops, public virtual RefBase { |
| 289 | public: |
| 290 | ReprocessStreamAdapter(camera2_device_t *d); |
| 291 | |
| 292 | ~ReprocessStreamAdapter(); |
| 293 | |
| 294 | /** |
| 295 | * Create a HAL device reprocess stream based on an existing output stream. |
| 296 | */ |
| 297 | status_t connectToDevice(const sp<StreamAdapter> &outputStream); |
| 298 | |
| 299 | status_t release(); |
| 300 | |
| 301 | /** |
| 302 | * Push buffer into stream for reprocessing. Takes ownership until it notifies |
| 303 | * that the buffer has been released |
| 304 | */ |
| 305 | status_t pushIntoStream(buffer_handle_t *handle, |
| 306 | const wp<BufferReleasedListener> &releaseListener); |
| 307 | |
| 308 | /** |
| 309 | * Get stream parameters. |
| 310 | * Only valid after a successful connectToDevice call. |
| 311 | */ |
| 312 | int getId() const { return mId; } |
| 313 | uint32_t getWidth() const { return mWidth; } |
| 314 | uint32_t getHeight() const { return mHeight; } |
| 315 | uint32_t getFormat() const { return mFormat; } |
| 316 | |
| 317 | // Dump stream information |
| 318 | status_t dump(int fd, const Vector<String16>& args); |
| 319 | |
| 320 | private: |
| 321 | enum { |
| 322 | ERROR = -1, |
| 323 | RELEASED = 0, |
| 324 | ACTIVE |
| 325 | } mState; |
| 326 | |
| 327 | sp<ANativeWindow> mConsumerInterface; |
| 328 | wp<StreamAdapter> mBaseStream; |
| 329 | |
| 330 | struct QueueEntry { |
| 331 | buffer_handle_t *handle; |
| 332 | wp<BufferReleasedListener> releaseListener; |
| 333 | }; |
| 334 | |
| 335 | List<QueueEntry> mQueue; |
| 336 | |
| 337 | List<QueueEntry> mInFlightQueue; |
| 338 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 339 | camera2_device_t *mHal2Device; |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 340 | |
| 341 | uint32_t mId; |
| 342 | uint32_t mWidth; |
| 343 | uint32_t mHeight; |
| 344 | uint32_t mFormat; |
| 345 | |
| 346 | /** Debugging information */ |
| 347 | uint32_t mActiveBuffers; |
| 348 | uint32_t mFrameCount; |
| 349 | int64_t mLastTimestamp; |
| 350 | |
| 351 | const camera2_stream_in_ops *getStreamOps(); |
| 352 | |
| 353 | static int acquire_buffer(const camera2_stream_in_ops_t *w, |
| 354 | buffer_handle_t** buffer); |
| 355 | |
| 356 | static int release_buffer(const camera2_stream_in_ops_t* w, |
| 357 | buffer_handle_t* buffer); |
| 358 | |
| 359 | }; // class ReprocessStreamAdapter |
| 360 | |
| 361 | typedef List<sp<ReprocessStreamAdapter> > ReprocessStreamList; |
| 362 | ReprocessStreamList mReprocessStreams; |
| 363 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 364 | // Receives HAL notifications and routes them to the NotificationListener |
| 365 | static void notificationCallback(int32_t msg_type, |
| 366 | int32_t ext1, |
| 367 | int32_t ext2, |
| 368 | int32_t ext3, |
| 369 | void *user); |
| 370 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 371 | }; // class Camera2Device |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 372 | |
| 373 | }; // namespace android |
| 374 | |
| 375 | #endif |