1 /* Copyright (c) 2012-2013, 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_CHANNEL_H__ 31 #define __QCAMERA3_CHANNEL_H__ 32 33 #include <hardware/camera3.h> 34 #include "QCamera3Stream.h" 35 #include "QCamera3Mem.h" 36 #include "QCamera3PostProc.h" 37 #include "QCamera3HALHeader.h" 38 39 extern "C" { 40 #include <mm_camera_interface.h> 41 } 42 43 using namespace android; 44 45 namespace qcamera { 46 47 typedef void (*channel_cb_routine)(mm_camera_super_buf_t *metadata, 48 camera3_stream_buffer_t *buffer, 49 uint32_t frame_number, void *userdata); 50 51 class QCamera3Channel 52 { 53 public: 54 QCamera3Channel(uint32_t cam_handle, 55 mm_camera_ops_t *cam_ops, 56 channel_cb_routine cb_routine, 57 cam_padding_info_t *paddingInfo, 58 void *userData); 59 QCamera3Channel(); 60 virtual ~QCamera3Channel(); 61 62 int32_t addStream(cam_stream_type_t streamType, 63 cam_format_t streamFormat, 64 cam_dimension_t streamDim, 65 uint8_t minStreamBufnum); 66 int32_t start(); 67 int32_t stop(); 68 int32_t bufDone(mm_camera_super_buf_t *recvd_frame); 69 70 uint32_t getStreamTypeMask(); 71 72 virtual int32_t registerBuffers(uint32_t num_buffers, 73 buffer_handle_t **buffers) = 0; 74 virtual int32_t initialize() = 0; 75 virtual int32_t request(buffer_handle_t * /*buffer*/, 76 uint32_t /*frameNumber*/){ return 0;}; 77 virtual int32_t request(buffer_handle_t * /*buffer*/, 78 uint32_t /*frameNumber*/, 79 jpeg_settings_t* /*mJpegSettings*/, 80 mm_camera_buf_def_t* /*pInputBuffer*/, 81 QCamera3Channel* /*pInputChannel*/){ return 0;}; 82 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 83 QCamera3Stream *stream) = 0; 84 85 virtual QCamera3Memory *getStreamBufs(uint32_t len) = 0; 86 virtual void putStreamBufs() = 0; 87 88 QCamera3Stream *getStreamByHandle(uint32_t streamHandle); 89 uint32_t getMyHandle() const {return m_handle;}; 90 uint8_t getNumOfStreams() const {return m_numStreams;}; 91 QCamera3Stream *getStreamByIndex(uint8_t index); 92 93 static void streamCbRoutine(mm_camera_super_buf_t *super_frame, 94 QCamera3Stream *stream, void *userdata); 95 void *mUserData; 96 cam_padding_info_t *mPaddingInfo; 97 QCamera3Stream *mStreams[MAX_STREAM_NUM_IN_BUNDLE]; 98 uint8_t m_numStreams; 99 protected: 100 101 virtual int32_t init(mm_camera_channel_attr_t *attr, 102 mm_camera_buf_notify_t dataCB); 103 int32_t allocateStreamInfoBuf(camera3_stream_t *stream); 104 105 uint32_t m_camHandle; 106 mm_camera_ops_t *m_camOps; 107 bool m_bIsActive; 108 109 uint32_t m_handle; 110 111 112 mm_camera_buf_notify_t mDataCB; 113 114 115 QCamera3HeapMemory *mStreamInfoBuf; 116 channel_cb_routine mChannelCB; 117 //cam_padding_info_t *mPaddingInfo; 118 }; 119 120 /* QCamera3RegularChannel is used to handle all streams that are directly 121 * generated by hardware and given to frameworks without any postprocessing at HAL. 122 * Examples are: all IMPLEMENTATION_DEFINED streams, CPU_READ streams. */ 123 class QCamera3RegularChannel : public QCamera3Channel 124 { 125 public: 126 QCamera3RegularChannel(uint32_t cam_handle, 127 mm_camera_ops_t *cam_ops, 128 channel_cb_routine cb_routine, 129 cam_padding_info_t *paddingInfo, 130 void *userData, 131 camera3_stream_t *stream); 132 QCamera3RegularChannel(uint32_t cam_handle, 133 mm_camera_ops_t *cam_ops, 134 channel_cb_routine cb_routine, 135 cam_padding_info_t *paddingInfo, 136 void *userData, 137 camera3_stream_t *stream, 138 uint32_t width, uint32_t height); 139 virtual ~QCamera3RegularChannel(); 140 141 virtual int32_t initialize(); 142 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber); 143 virtual int32_t registerBuffers(uint32_t num_buffers, 144 buffer_handle_t **buffers); 145 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 146 QCamera3Stream *stream); 147 148 virtual QCamera3Memory *getStreamBufs(uint32_t le); 149 virtual void putStreamBufs(); 150 mm_camera_buf_def_t* getInternalFormatBuffer(buffer_handle_t* buffer); 151 152 public: 153 static int kMaxBuffers; 154 private: 155 camera3_stream_t *mCamera3Stream; 156 uint32_t mNumBufs; 157 buffer_handle_t **mCamera3Buffers; 158 159 QCamera3GrallocMemory *mMemory; 160 // width and height of internal stream may be different than what's 161 // specified in camera3_stream_t. For example: ZSL stream size is 162 // always the active region size, but internally we use the JPEG 163 // size. 164 uint32_t mWidth, mHeight; 165 }; 166 167 /* QCamera3MetadataChannel is for metadata stream generated by camera daemon. */ 168 class QCamera3MetadataChannel : public QCamera3Channel 169 { 170 public: 171 QCamera3MetadataChannel(uint32_t cam_handle, 172 mm_camera_ops_t *cam_ops, 173 channel_cb_routine cb_routine, 174 cam_padding_info_t *paddingInfo, 175 void *userData); 176 virtual ~QCamera3MetadataChannel(); 177 178 virtual int32_t initialize(); 179 180 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber); 181 virtual int32_t registerBuffers(uint32_t num_buffers, 182 buffer_handle_t **buffers); 183 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 184 QCamera3Stream *stream); 185 186 virtual QCamera3Memory *getStreamBufs(uint32_t le); 187 virtual void putStreamBufs(); 188 189 private: 190 QCamera3HeapMemory *mMemory; 191 }; 192 193 /* QCamera3PicChannel is for JPEG stream, which contains a YUV stream generated 194 * by the hardware, and encoded to a JPEG stream */ 195 class QCamera3PicChannel : public QCamera3Channel 196 { 197 public: 198 QCamera3PicChannel(uint32_t cam_handle, 199 mm_camera_ops_t *cam_ops, 200 channel_cb_routine cb_routine, 201 cam_padding_info_t *paddingInfo, 202 void *userData, 203 camera3_stream_t *stream); 204 ~QCamera3PicChannel(); 205 206 virtual int32_t initialize(); 207 208 virtual int32_t request(buffer_handle_t *buffer, 209 uint32_t frameNumber, jpeg_settings_t* mJpegSettings, 210 mm_camera_buf_def_t* pInputBuffer,QCamera3Channel* pInputChannel); 211 virtual int32_t registerBuffers(uint32_t num_buffers, 212 buffer_handle_t **buffers); 213 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 214 QCamera3Stream *stream); 215 216 virtual QCamera3Memory *getStreamBufs(uint32_t le); 217 virtual void putStreamBufs(); 218 bool isWNREnabled() {return m_bWNROn;}; 219 bool needOnlineRotation(); 220 void getThumbnailSize(cam_dimension_t &dim); 221 int getJpegQuality(); 222 int getJpegRotation(); 223 bool isRawSnapshot(); 224 QCamera3Exif *getExifData(); 225 static void jpegEvtHandle(jpeg_job_status_t status, 226 uint32_t /*client_hdl*/, 227 uint32_t jobId, 228 mm_jpeg_output_t *p_output, 229 void *userdata); 230 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 231 void *userdata); 232 void queueMetadata(mm_camera_super_buf_t *metadata_buf); 233 234 public: 235 static int kMaxBuffers; 236 QCamera3PostProcessor m_postprocessor; // post processor 237 private: 238 camera3_stream_t *mCamera3Stream; 239 uint32_t mNumBufs; 240 buffer_handle_t **mCamera3Buffers; 241 jpeg_settings_t* mJpegSettings; 242 int32_t mCurrentBufIndex; 243 bool m_bWNROn; 244 245 246 QCamera3GrallocMemory *mMemory; 247 QCamera3HeapMemory *mYuvMemory; 248 }; 249 250 // reprocess channel class 251 class QCamera3ReprocessChannel : public QCamera3Channel 252 { 253 public: 254 QCamera3ReprocessChannel(uint32_t cam_handle, 255 mm_camera_ops_t *cam_ops, 256 channel_cb_routine cb_routine, 257 cam_padding_info_t *paddingInfo, 258 void *userData, void *ch_hdl); 259 QCamera3ReprocessChannel(); 260 virtual ~QCamera3ReprocessChannel(); 261 // online reprocess 262 int32_t doReprocess(mm_camera_super_buf_t *frame, 263 mm_camera_super_buf_t *meta_frame); 264 // offline reprocess 265 int32_t doReprocess(int buf_fd, uint32_t buf_length, int32_t &ret_val, 266 mm_camera_super_buf_t *meta_buf); 267 virtual int32_t registerBuffers(uint32_t num_buffers, buffer_handle_t **buffers); 268 virtual QCamera3Memory *getStreamBufs(uint32_t len); 269 virtual void putStreamBufs(); 270 virtual int32_t initialize(); 271 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 272 QCamera3Stream *stream); 273 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 274 void* userdata); 275 int32_t addReprocStreamsFromSource(cam_pp_feature_config_t &config, 276 QCamera3Channel *pSrcChannel, 277 QCamera3Channel *pMetaChannel); 278 QCamera3Stream *getStreamBySourceHandle(uint32_t srcHandle); 279 public: 280 void *picChHandle; 281 private: 282 uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE]; 283 QCamera3Channel *m_pSrcChannel; // ptr to source channel for reprocess 284 QCamera3Channel *m_pMetaChannel; 285 mm_camera_super_buf_t *m_metaFrame; 286 QCamera3HeapMemory *mMemory; 287 }; 288 289 }; // namespace qcamera 290 291 #endif /* __QCAMERA_CHANNEL_H__ */ 292