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