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