| 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 |  | 
 | 20 | #include <utils/RefBase.h> | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame^] | 21 | #include <utils/List.h> | 
 | 22 | #include <utils/Mutex.h> | 
 | 23 | #include <utils/Condition.h> | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 24 | #include <utils/Errors.h> | 
 | 25 | #include "hardware/camera2.h" | 
 | 26 |  | 
 | 27 | namespace android { | 
 | 28 |  | 
 | 29 | class Camera2Device : public virtual RefBase { | 
 | 30 |   public: | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame^] | 31 |     Camera2Device(int id); | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 32 |  | 
 | 33 |     ~Camera2Device(); | 
 | 34 |  | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame^] | 35 |     status_t initialize(camera_module_t *module); | 
 | 36 |  | 
 | 37 |     status_t setStreamingRequest(camera_metadata_t* request); | 
 | 38 |  | 
 | 39 |     camera_metadata_t* info() { | 
 | 40 |         return mDeviceInfo; | 
 | 41 |     } | 
 | 42 |  | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 43 |   private: | 
 | 44 |  | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame^] | 45 |     const int mId; | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 46 |     camera2_device_t *mDevice; | 
 | 47 |  | 
| Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame^] | 48 |     camera_metadata_t *mDeviceInfo; | 
 | 49 |     vendor_tag_query_ops_t *mVendorTagOps; | 
 | 50 |  | 
 | 51 |     /** | 
 | 52 |      * Queue class for both sending requests to a camera2 device, and for | 
 | 53 |      * receiving frames from a camera2 device. | 
 | 54 |      */ | 
 | 55 |     class MetadataQueue: public camera2_request_queue_src_ops_t, | 
 | 56 |                          public camera2_frame_queue_dst_ops_t { | 
 | 57 |       public: | 
 | 58 |         MetadataQueue(); | 
 | 59 |         ~MetadataQueue(); | 
 | 60 |  | 
 | 61 |         // Interface to camera2 HAL device, either for requests (device is | 
 | 62 |         // consumer) or for frames (device is producer) | 
 | 63 |         const camera2_request_queue_src_ops_t*   getToConsumerInterface(); | 
 | 64 |         void setFromConsumerInterface(camera2_device_t *d); | 
 | 65 |  | 
 | 66 |         const camera2_frame_queue_dst_ops_t* getToProducerInterface(); | 
 | 67 |  | 
 | 68 |         // Real interfaces. On enqueue, queue takes ownership of buffer pointer | 
 | 69 |         // On dequeue, user takes ownership of buffer pointer. | 
 | 70 |         status_t enqueue(camera_metadata_t *buf); | 
 | 71 |         status_t dequeue(camera_metadata_t **buf, bool incrementCount = true); | 
 | 72 |         int      getBufferCount(); | 
 | 73 |         status_t waitForBuffer(nsecs_t timeout); | 
 | 74 |  | 
 | 75 |         // Set repeating buffer(s); if the queue is empty on a dequeue call, the | 
 | 76 |         // queue copies the contents of the stream slot into the queue, and then | 
 | 77 |         // dequeues the first new entry. | 
 | 78 |         status_t setStreamSlot(camera_metadata_t *buf); | 
 | 79 |         status_t setStreamSlot(const List<camera_metadata_t*> &bufs); | 
 | 80 |  | 
 | 81 |       private: | 
 | 82 |         status_t freeBuffers(List<camera_metadata_t*>::iterator start, | 
 | 83 |                 List<camera_metadata_t*>::iterator end); | 
 | 84 |  | 
 | 85 |         camera2_device_t *mDevice; | 
 | 86 |  | 
 | 87 |         Mutex mMutex; | 
 | 88 |         Condition notEmpty; | 
 | 89 |  | 
 | 90 |         int mFrameCount; | 
 | 91 |  | 
 | 92 |         int mCount; | 
 | 93 |         List<camera_metadata_t*> mEntries; | 
 | 94 |         int mStreamSlotCount; | 
 | 95 |         List<camera_metadata_t*> mStreamSlot; | 
 | 96 |  | 
 | 97 |         bool mSignalConsumer; | 
 | 98 |  | 
 | 99 |         static MetadataQueue* getInstance( | 
 | 100 |             const camera2_frame_queue_dst_ops_t *q); | 
 | 101 |         static MetadataQueue* getInstance( | 
 | 102 |             const camera2_request_queue_src_ops_t *q); | 
 | 103 |  | 
 | 104 |         static int consumer_buffer_count( | 
 | 105 |             const camera2_request_queue_src_ops_t *q); | 
 | 106 |  | 
 | 107 |         static int consumer_dequeue(const camera2_request_queue_src_ops_t *q, | 
 | 108 |             camera_metadata_t **buffer); | 
 | 109 |  | 
 | 110 |         static int consumer_free(const camera2_request_queue_src_ops_t *q, | 
 | 111 |                 camera_metadata_t *old_buffer); | 
 | 112 |  | 
 | 113 |         static int producer_dequeue(const camera2_frame_queue_dst_ops_t *q, | 
 | 114 |                 size_t entries, size_t bytes, | 
 | 115 |                 camera_metadata_t **buffer); | 
 | 116 |  | 
 | 117 |         static int producer_cancel(const camera2_frame_queue_dst_ops_t *q, | 
 | 118 |             camera_metadata_t *old_buffer); | 
 | 119 |  | 
 | 120 |         static int producer_enqueue(const camera2_frame_queue_dst_ops_t *q, | 
 | 121 |                 camera_metadata_t *filled_buffer); | 
 | 122 |  | 
 | 123 |     }; // class MetadataQueue | 
 | 124 |  | 
 | 125 |     MetadataQueue mRequestQueue; | 
 | 126 |     MetadataQueue mFrameQueue; | 
 | 127 |  | 
 | 128 | }; // class Camera2Device | 
| Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 129 |  | 
 | 130 | }; // namespace android | 
 | 131 |  | 
 | 132 | #endif |