1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __QCAMERA3_STREAM_H__ 31 #define __QCAMERA3_STREAM_H__ 32 33 // System dependencies 34 #include <utils/Mutex.h> 35 36 // Camera dependencies 37 #include "QCamera3Mem.h" 38 #include "QCamera3StreamMem.h" 39 #include "QCameraCmdThread.h" 40 #include "QCameraQueue.h" 41 42 extern "C" { 43 #include "mm_camera_interface.h" 44 } 45 46 namespace qcamera { 47 48 class QCamera3Channel; 49 class QCamera3Stream; 50 51 typedef void (*hal3_stream_cb_routine)(mm_camera_super_buf_t *frame, 52 QCamera3Stream *stream, 53 void *userdata); 54 55 class QCamera3Stream 56 { 57 public: 58 QCamera3Stream(uint32_t camHandle, 59 uint32_t chId, 60 mm_camera_ops_t *camOps, 61 cam_padding_info_t *paddingInfo, 62 QCamera3Channel *channel, 63 bool mapStreamBuffers); 64 virtual ~QCamera3Stream(); 65 virtual int32_t init(cam_stream_type_t streamType, 66 cam_format_t streamFormat, 67 cam_dimension_t streamDim, 68 cam_rotation_t streamRotation, 69 cam_stream_reproc_config_t* reprocess_config, 70 uint8_t minStreamBufNum, 71 cam_feature_mask_t postprocess_mask, 72 cam_is_type_t is_type, 73 uint32_t batchSize, 74 hal3_stream_cb_routine stream_cb, 75 void *userdata); 76 virtual int32_t bufDone(uint32_t index); 77 virtual int32_t cancelBuffer(uint32_t index); 78 virtual int32_t bufRelease(int32_t index); 79 virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs); 80 virtual int32_t start(); 81 virtual int32_t stop(); 82 virtual int32_t queueBatchBuf(); 83 84 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata); 85 static void *dataProcRoutine(void *data); getMyHandle()86 uint32_t getMyHandle() const {return mHandle;} 87 cam_stream_type_t getMyType() const; 88 int32_t getFrameOffset(cam_frame_len_offset_t &offset); 89 int32_t getFrameDimension(cam_dimension_t &dim); 90 int32_t getFormat(cam_format_t &fmt); getStreamBufs()91 QCamera3StreamMem *getStreamBufs() {return mStreamBufs;}; 92 uint32_t getMyServerID(); 93 94 int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx, 95 int32_t plane_idx, int fd, void *buffer, size_t size); 96 int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx); 97 int32_t setParameter(cam_stream_parm_buffer_t ¶m); getStreamInfo()98 cam_stream_info_t* getStreamInfo() const {return mStreamInfo; }; 99 100 static void releaseFrameData(void *data, void *user_data); 101 int32_t timeoutFrame(int32_t bufIdx); setBufStride(uint32_t stride)102 void setBufStride(uint32_t stride) {mStreamInfo->buf_stride = stride;} 103 104 private: 105 uint32_t mCamHandle; 106 uint32_t mChannelHandle; 107 uint32_t mHandle; // stream handle from mm-camera-interface 108 mm_camera_ops_t *mCamOps; 109 cam_stream_info_t *mStreamInfo; // ptr to stream info buf 110 mm_camera_stream_mem_vtbl_t mMemVtbl; 111 mm_camera_map_unmap_ops_tbl_t *mMemOps; 112 uint8_t mNumBufs; 113 hal3_stream_cb_routine mDataCB; 114 void *mUserData; 115 116 QCameraQueue mDataQ; 117 118 List<int32_t> mTimeoutFrameQ; 119 Mutex mTimeoutFrameQLock; 120 121 QCameraCmdThread mProcTh; // thread for dataCB 122 123 QCamera3HeapMemory *mStreamInfoBuf; 124 QCamera3StreamMem *mStreamBufs; 125 mm_camera_buf_def_t *mBufDefs; 126 cam_frame_len_offset_t mFrameLenOffset; 127 cam_padding_info_t mPaddingInfo; 128 QCamera3Channel *mChannel; 129 Mutex mLock; //Lock controlling access to 'mBufDefs' 130 131 uint32_t mBatchSize; // 0: No batch, non-0: Number of imaage bufs in a batch 132 uint8_t mNumBatchBufs; //Number of batch buffers which can hold image bufs 133 QCamera3HeapMemory *mStreamBatchBufs; //Pointer to batch buffers memory 134 mm_camera_buf_def_t *mBatchBufDefs; //Pointer to array of batch bufDefs 135 mm_camera_buf_def_t *mCurrentBatchBufDef; //batch buffer in progress during 136 //aggregation 137 uint32_t mBufsStaged; //Number of image buffers aggregated into 138 //currentBatchBufDef 139 QCameraQueue mFreeBatchBufQ; //Buffer queue containing empty batch buffers 140 uint8_t mNRMode; // Initial noise reduction mode 141 142 bool mMapStreamBuffers; // Whether to mmap every stream buffers 143 144 static int32_t get_bufs( 145 cam_frame_len_offset_t *offset, 146 uint8_t *num_bufs, 147 uint8_t **initial_reg_flag, 148 mm_camera_buf_def_t **bufs, 149 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 150 void *user_data); 151 static int32_t put_bufs( 152 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 153 void *user_data); 154 static int32_t invalidate_buf(uint32_t index, void *user_data); 155 static int32_t clean_invalidate_buf(uint32_t index, void *user_data); 156 static int32_t clean_buf(uint32_t index, void *user_data); 157 158 int32_t getBufs(cam_frame_len_offset_t *offset, 159 uint8_t *num_bufs, 160 uint8_t **initial_reg_flag, 161 mm_camera_buf_def_t **bufs, 162 mm_camera_map_unmap_ops_tbl_t *ops_tbl); 163 int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl); 164 int32_t invalidateBuf(uint32_t index); 165 int32_t cleanInvalidateBuf(uint32_t index); 166 int32_t cleanBuf(uint32_t index); 167 int32_t getBatchBufs( 168 uint8_t *num_bufs, uint8_t **initial_reg_flag, 169 mm_camera_buf_def_t **bufs, 170 mm_camera_map_unmap_ops_tbl_t *ops_tbl); 171 int32_t putBatchBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl); 172 int32_t getBatchBufDef(mm_camera_buf_def_t& batchBufDef, 173 int32_t index); 174 int32_t aggregateBufToBatch(mm_camera_buf_def_t& bufDef); 175 int32_t aggregateStartingBufs(const uint8_t *initial_reg_flag); 176 int32_t handleBatchBuffer(mm_camera_super_buf_t *superBuf); 177 int32_t bufDoneLocked(uint32_t index); 178 179 static const char* mStreamNames[CAM_STREAM_TYPE_MAX]; 180 void flushFreeBatchBufQ(); 181 }; 182 183 }; // namespace qcamera 184 185 #endif /* __QCAMERA3_STREAM_H__ */ 186