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 virtual ~QCamera3Stream(); 64 virtual int32_t init(cam_stream_type_t streamType, 65 cam_format_t streamFormat, 66 cam_dimension_t streamDim, 67 cam_rotation_t streamRotation, 68 cam_stream_reproc_config_t* reprocess_config, 69 uint8_t minStreamBufNum, 70 cam_feature_mask_t postprocess_mask, 71 cam_is_type_t is_type, 72 uint32_t batchSize, 73 hal3_stream_cb_routine stream_cb, 74 void *userdata); 75 virtual int32_t bufDone(uint32_t index); 76 virtual int32_t cancelBuffer(uint32_t index); 77 virtual int32_t bufRelease(int32_t index); 78 virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs); 79 virtual int32_t start(); 80 virtual int32_t stop(); 81 virtual int32_t queueBatchBuf(); 82 83 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata); 84 static void *dataProcRoutine(void *data); getMyHandle()85 uint32_t getMyHandle() const {return mHandle;} 86 cam_stream_type_t getMyType() const; 87 int32_t getFrameOffset(cam_frame_len_offset_t &offset); 88 int32_t getFrameDimension(cam_dimension_t &dim); 89 int32_t getFormat(cam_format_t &fmt); getStreamBufs()90 QCamera3StreamMem *getStreamBufs() {return mStreamBufs;}; 91 uint32_t getMyServerID(); 92 93 int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx, 94 int32_t plane_idx, int fd, void *buffer, size_t size); 95 int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx); 96 int32_t setParameter(cam_stream_parm_buffer_t ¶m); getStreamInfo()97 cam_stream_info_t* getStreamInfo() const {return mStreamInfo; }; 98 99 static void releaseFrameData(void *data, void *user_data); 100 int32_t timeoutFrame(int32_t bufIdx); 101 102 private: 103 uint32_t mCamHandle; 104 uint32_t mChannelHandle; 105 uint32_t mHandle; // stream handle from mm-camera-interface 106 mm_camera_ops_t *mCamOps; 107 cam_stream_info_t *mStreamInfo; // ptr to stream info buf 108 mm_camera_stream_mem_vtbl_t mMemVtbl; 109 mm_camera_map_unmap_ops_tbl_t *mMemOps; 110 uint8_t mNumBufs; 111 hal3_stream_cb_routine mDataCB; 112 void *mUserData; 113 114 QCameraQueue mDataQ; 115 QCameraQueue mTimeoutFrameQ; 116 QCameraCmdThread mProcTh; // thread for dataCB 117 118 QCamera3HeapMemory *mStreamInfoBuf; 119 QCamera3StreamMem *mStreamBufs; 120 mm_camera_buf_def_t *mBufDefs; 121 cam_frame_len_offset_t mFrameLenOffset; 122 cam_padding_info_t mPaddingInfo; 123 QCamera3Channel *mChannel; 124 Mutex mLock; //Lock controlling access to 'mBufDefs' 125 126 uint32_t mBatchSize; // 0: No batch, non-0: Number of imaage bufs in a batch 127 uint8_t mNumBatchBufs; //Number of batch buffers which can hold image bufs 128 QCamera3HeapMemory *mStreamBatchBufs; //Pointer to batch buffers memory 129 mm_camera_buf_def_t *mBatchBufDefs; //Pointer to array of batch bufDefs 130 mm_camera_buf_def_t *mCurrentBatchBufDef; //batch buffer in progress during 131 //aggregation 132 uint32_t mBufsStaged; //Number of image buffers aggregated into 133 //currentBatchBufDef 134 QCameraQueue mFreeBatchBufQ; //Buffer queue containing empty batch buffers 135 136 static int32_t get_bufs( 137 cam_frame_len_offset_t *offset, 138 uint8_t *num_bufs, 139 uint8_t **initial_reg_flag, 140 mm_camera_buf_def_t **bufs, 141 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 142 void *user_data); 143 static int32_t put_bufs( 144 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 145 void *user_data); 146 static int32_t invalidate_buf(uint32_t index, void *user_data); 147 static int32_t clean_invalidate_buf(uint32_t index, void *user_data); 148 149 int32_t getBufs(cam_frame_len_offset_t *offset, 150 uint8_t *num_bufs, 151 uint8_t **initial_reg_flag, 152 mm_camera_buf_def_t **bufs, 153 mm_camera_map_unmap_ops_tbl_t *ops_tbl); 154 int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl); 155 int32_t invalidateBuf(uint32_t index); 156 int32_t cleanInvalidateBuf(uint32_t index); 157 int32_t getBatchBufs( 158 uint8_t *num_bufs, uint8_t **initial_reg_flag, 159 mm_camera_buf_def_t **bufs, 160 mm_camera_map_unmap_ops_tbl_t *ops_tbl); 161 int32_t putBatchBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl); 162 int32_t getBatchBufDef(mm_camera_buf_def_t& batchBufDef, 163 int32_t index); 164 int32_t aggregateBufToBatch(mm_camera_buf_def_t& bufDef); 165 int32_t handleBatchBuffer(mm_camera_super_buf_t *superBuf); 166 167 static const char* mStreamNames[CAM_STREAM_TYPE_MAX]; 168 void flushFreeBatchBufQ(); 169 }; 170 171 }; // namespace qcamera 172 173 #endif /* __QCAMERA3_STREAM_H__ */ 174