1 /* Copyright (c) 2012-2015, The Linux Foundataion. 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 #include <hardware/camera3.h> 34 #include "utils/Mutex.h" 35 #include "QCameraCmdThread.h" 36 #include "QCamera3Mem.h" 37 38 extern "C" { 39 #include <mm_camera_interface.h> 40 } 41 42 namespace qcamera { 43 44 class QCamera3Stream; 45 class QCamera3Channel; 46 47 typedef void (*hal3_stream_cb_routine)(mm_camera_super_buf_t *frame, 48 QCamera3Stream *stream, 49 void *userdata); 50 51 class QCamera3Stream 52 { 53 public: 54 QCamera3Stream(uint32_t camHandle, 55 uint32_t chId, 56 mm_camera_ops_t *camOps, 57 cam_padding_info_t *paddingInfo, 58 QCamera3Channel *channel); 59 virtual ~QCamera3Stream(); 60 virtual int32_t init(cam_stream_type_t streamType, 61 cam_format_t streamFormat, 62 cam_dimension_t streamDim, 63 cam_stream_reproc_config_t* reprocess_config, 64 uint8_t minStreamBufNum, 65 uint32_t postprocess_mask, 66 cam_is_type_t is_type, 67 hal3_stream_cb_routine stream_cb, 68 void *userdata); 69 virtual int32_t bufDone(int index); 70 virtual int32_t bufRelease(int32_t index); 71 virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs); 72 virtual int32_t start(); 73 virtual int32_t stop(); 74 75 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata); 76 static void *dataProcRoutine(void *data); getMyHandle()77 uint32_t getMyHandle() const {return mHandle;} 78 cam_stream_type_t getMyType() const; 79 int32_t getFrameOffset(cam_frame_len_offset_t &offset); 80 int32_t getFrameDimension(cam_dimension_t &dim); 81 int32_t getFormat(cam_format_t &fmt); getStreamBufs()82 QCamera3Memory *getStreamBufs() {return mStreamBufs;}; 83 uint32_t getMyServerID(); 84 85 int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx, 86 int32_t plane_idx, int fd, uint32_t size); 87 int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx); 88 int32_t setParameter(cam_stream_parm_buffer_t ¶m); 89 90 static void releaseFrameData(void *data, void *user_data); 91 92 private: 93 uint32_t mCamHandle; 94 uint32_t mChannelHandle; 95 uint32_t mHandle; // stream handle from mm-camera-interface 96 mm_camera_ops_t *mCamOps; 97 cam_stream_info_t *mStreamInfo; // ptr to stream info buf 98 mm_camera_stream_mem_vtbl_t mMemVtbl; 99 mm_camera_map_unmap_ops_tbl_t *mMemOps; 100 uint8_t mNumBufs; 101 hal3_stream_cb_routine mDataCB; 102 void *mUserData; 103 104 QCameraQueue mDataQ; 105 QCameraCmdThread mProcTh; // thread for dataCB 106 107 QCamera3HeapMemory *mStreamInfoBuf; 108 QCamera3Memory *mStreamBufs; 109 mm_camera_buf_def_t *mBufDefs; 110 cam_frame_len_offset_t mFrameLenOffset; 111 cam_padding_info_t mPaddingInfo; 112 QCamera3Channel *mChannel; 113 Mutex mLock; //Lock controlling access to 'mBufDefs' 114 115 static int32_t get_bufs( 116 cam_frame_len_offset_t *offset, 117 uint8_t *num_bufs, 118 uint8_t **initial_reg_flag, 119 mm_camera_buf_def_t **bufs, 120 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 121 void *user_data); 122 static int32_t put_bufs( 123 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 124 void *user_data); 125 static int32_t invalidate_buf(int index, void *user_data); 126 static int32_t clean_invalidate_buf(int index, void *user_data); 127 128 int32_t getBufs(cam_frame_len_offset_t *offset, 129 uint8_t *num_bufs, 130 uint8_t **initial_reg_flag, 131 mm_camera_buf_def_t **bufs, 132 mm_camera_map_unmap_ops_tbl_t *ops_tbl); 133 int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl); 134 int32_t invalidateBuf(int index); 135 int32_t cleanInvalidateBuf(int index); 136 137 }; 138 139 }; // namespace qcamera 140 141 #endif /* __QCAMERA3_STREAM_H__ */ 142