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_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 #include "utils/Vector.h" 39 #include <utils/List.h> 40 41 extern "C" { 42 #include <mm_camera_interface.h> 43 } 44 45 using namespace android; 46 47 namespace qcamera { 48 49 typedef void (*channel_cb_routine)(mm_camera_super_buf_t *metadata, 50 camera3_stream_buffer_t *buffer, 51 uint32_t frame_number, void *userdata); 52 53 class QCamera3Channel 54 { 55 public: 56 QCamera3Channel(uint32_t cam_handle, 57 mm_camera_ops_t *cam_ops, 58 channel_cb_routine cb_routine, 59 cam_padding_info_t *paddingInfo, 60 uint32_t postprocess_mask, 61 void *userData); 62 QCamera3Channel(); 63 virtual ~QCamera3Channel(); 64 65 int32_t addStream(cam_stream_type_t streamType, 66 cam_format_t streamFormat, 67 cam_dimension_t streamDim, 68 uint8_t minStreamBufnum, 69 uint32_t postprocessMask, 70 cam_is_type_t isType); 71 virtual int32_t start(); 72 virtual int32_t stop(); 73 int32_t bufDone(mm_camera_super_buf_t *recvd_frame); 74 75 uint32_t getStreamTypeMask(); 76 uint32_t getStreamID(uint32_t streamMask); 77 virtual int32_t initialize(cam_is_type_t isType) = 0; request(buffer_handle_t *,uint32_t)78 virtual int32_t request(buffer_handle_t * /*buffer*/, 79 uint32_t /*frameNumber*/){ return 0;}; request(buffer_handle_t *,uint32_t,camera3_stream_buffer_t *,metadata_buffer_t *)80 virtual int32_t request(buffer_handle_t * /*buffer*/, 81 uint32_t /*frameNumber*/, 82 camera3_stream_buffer_t* /*pInputBuffer*/, 83 metadata_buffer_t* /*metadata*/){ return 0;}; 84 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 85 QCamera3Stream *stream) = 0; 86 87 virtual int32_t registerBuffer(buffer_handle_t *buffer, cam_is_type_t isType) = 0; 88 virtual QCamera3Memory *getStreamBufs(uint32_t len) = 0; 89 virtual void putStreamBufs() = 0; 90 91 QCamera3Stream *getStreamByHandle(uint32_t streamHandle); getMyHandle()92 uint32_t getMyHandle() const {return m_handle;}; getNumOfStreams()93 uint8_t getNumOfStreams() const {return m_numStreams;}; 94 QCamera3Stream *getStreamByIndex(uint8_t index); 95 96 static void streamCbRoutine(mm_camera_super_buf_t *super_frame, 97 QCamera3Stream *stream, void *userdata); 98 void dumpYUV(mm_camera_buf_def_t *frame, cam_dimension_t dim, 99 cam_frame_len_offset_t offset, uint8_t name); 100 101 void *mUserData; 102 cam_padding_info_t *mPaddingInfo; 103 QCamera3Stream *mStreams[MAX_STREAM_NUM_IN_BUNDLE]; 104 uint8_t m_numStreams; 105 protected: 106 107 virtual int32_t init(mm_camera_channel_attr_t *attr, 108 mm_camera_buf_notify_t dataCB); 109 int32_t allocateStreamInfoBuf(camera3_stream_t *stream); 110 111 uint32_t m_camHandle; 112 mm_camera_ops_t *m_camOps; 113 bool m_bIsActive; 114 115 uint32_t m_handle; 116 117 118 mm_camera_buf_notify_t mDataCB; 119 120 121 QCamera3HeapMemory *mStreamInfoBuf; 122 channel_cb_routine mChannelCB; 123 //cam_padding_info_t *mPaddingInfo; 124 uint32_t mPostProcMask; 125 uint8_t mYUVDump; 126 cam_is_type_t mIsType; 127 uint8_t mIntent; 128 }; 129 130 /* QCamera3RegularChannel is used to handle all streams that are directly 131 * generated by hardware and given to frameworks without any postprocessing at HAL. 132 * Examples are: all IMPLEMENTATION_DEFINED streams, CPU_READ streams. */ 133 class QCamera3RegularChannel : public QCamera3Channel 134 { 135 public: 136 QCamera3RegularChannel(uint32_t cam_handle, 137 mm_camera_ops_t *cam_ops, 138 channel_cb_routine cb_routine, 139 cam_padding_info_t *paddingInfo, 140 void *userData, 141 camera3_stream_t *stream, 142 cam_stream_type_t stream_type, 143 uint32_t postprocess_mask); 144 145 virtual ~QCamera3RegularChannel(); 146 147 virtual int32_t start(); 148 virtual int32_t initialize(cam_is_type_t isType); 149 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber); 150 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 151 QCamera3Stream *stream); 152 153 virtual QCamera3Memory *getStreamBufs(uint32_t le); 154 virtual void putStreamBufs(); 155 virtual int32_t registerBuffer(buffer_handle_t *buffer, cam_is_type_t isType); 156 157 public: 158 static int kMaxBuffers; 159 protected: 160 QCamera3GrallocMemory mMemory; 161 private: 162 int32_t initialize(struct private_handle_t *priv_handle); 163 164 camera3_stream_t *mCamera3Stream; 165 uint32_t mNumBufs; 166 cam_stream_type_t mStreamType; // Stream type 167 uint8_t mIntent; 168 }; 169 170 /* QCamera3MetadataChannel is for metadata stream generated by camera daemon. */ 171 class QCamera3MetadataChannel : public QCamera3Channel 172 { 173 public: 174 QCamera3MetadataChannel(uint32_t cam_handle, 175 mm_camera_ops_t *cam_ops, 176 channel_cb_routine cb_routine, 177 cam_padding_info_t *paddingInfo, 178 uint32_t postprocess_mask, 179 void *userData); 180 virtual ~QCamera3MetadataChannel(); 181 182 virtual int32_t initialize(cam_is_type_t isType); 183 184 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber); 185 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 186 QCamera3Stream *stream); 187 188 virtual QCamera3Memory *getStreamBufs(uint32_t le); 189 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)190 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 191 { return NO_ERROR; }; 192 193 private: 194 QCamera3HeapMemory *mMemory; 195 }; 196 197 /* QCamera3RawChannel is for opaqueu/cross-platform raw stream containing 198 * vendor specific bayer data or 16-bit unpacked bayer data */ 199 class QCamera3RawChannel : public QCamera3RegularChannel 200 { 201 public: 202 QCamera3RawChannel(uint32_t cam_handle, 203 mm_camera_ops_t *cam_ops, 204 channel_cb_routine cb_routine, 205 cam_padding_info_t *paddingInfo, 206 void *userData, 207 camera3_stream_t *stream, 208 uint32_t postprocess_mask, 209 bool raw_16 = false); 210 virtual ~QCamera3RawChannel(); 211 212 virtual int32_t initialize(cam_is_type_t isType); 213 214 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 215 QCamera3Stream *stream); 216 217 public: 218 static int kMaxBuffers; 219 220 private: 221 bool mRawDump; 222 bool mIsRaw16; 223 224 void dumpRawSnapshot(mm_camera_buf_def_t *frame); 225 void convertLegacyToRaw16(mm_camera_buf_def_t *frame); 226 void convertMipiToRaw16(mm_camera_buf_def_t *frame); 227 }; 228 229 /* 230 * QCamera3RawDumpChannel is for internal use only for Raw dump 231 */ 232 233 class QCamera3RawDumpChannel : public QCamera3Channel 234 { 235 public: 236 QCamera3RawDumpChannel(uint32_t cam_handle, 237 mm_camera_ops_t *cam_ops, 238 cam_dimension_t rawDumpSize, 239 cam_padding_info_t *paddingInfo, 240 void *userData, 241 uint32_t postprocess_mask); 242 virtual ~QCamera3RawDumpChannel(); 243 virtual int32_t initialize(cam_is_type_t isType); 244 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 245 QCamera3Stream *stream); 246 virtual QCamera3Memory *getStreamBufs(uint32_t le); 247 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)248 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 249 { return NO_ERROR; }; 250 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber); 251 void dumpRawSnapshot(mm_camera_buf_def_t *frame); 252 253 public: 254 static int kMaxBuffers; 255 cam_dimension_t mDim; 256 257 private: 258 bool mRawDump; 259 QCamera3HeapMemory *mMemory; 260 }; 261 262 /* QCamera3PicChannel is for JPEG stream, which contains a YUV stream generated 263 * by the hardware, and encoded to a JPEG stream */ 264 class QCamera3PicChannel : public QCamera3Channel 265 { 266 public: 267 QCamera3PicChannel(uint32_t cam_handle, 268 mm_camera_ops_t *cam_ops, 269 channel_cb_routine cb_routine, 270 cam_padding_info_t *paddingInfo, 271 void *userData, 272 camera3_stream_t *stream, 273 uint32_t postprocess_mask, 274 bool is4KVideo, 275 QCamera3Channel *metadataChannel); 276 ~QCamera3PicChannel(); 277 278 virtual int32_t initialize(cam_is_type_t isType); 279 virtual int32_t stop(); 280 virtual int32_t request(buffer_handle_t *buffer, 281 uint32_t frameNumber, 282 camera3_stream_buffer_t* pInputBuffer, 283 metadata_buffer_t* metadata); 284 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 285 QCamera3Stream *stream); 286 287 virtual QCamera3Memory *getStreamBufs(uint32_t le); 288 virtual void putStreamBufs(); 289 isWNREnabled()290 bool isWNREnabled() {return m_bWNROn;}; 291 bool needOnlineRotation(); 292 int32_t metadataBufDone(mm_camera_super_buf_t *recvd_frame); 293 QCamera3Exif *getExifData(metadata_buffer_t *metadata, 294 jpeg_settings_t *jpeg_settings); 295 void overrideYuvSize(uint32_t width, uint32_t height); 296 static void jpegEvtHandle(jpeg_job_status_t status, 297 uint32_t /*client_hdl*/, 298 uint32_t jobId, 299 mm_jpeg_output_t *p_output, 300 void *userdata); 301 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 302 void *userdata); 303 virtual int32_t registerBuffer(buffer_handle_t *buffer, cam_is_type_t isType); 304 int32_t queueReprocMetadata(mm_camera_super_buf_t *metadata); 305 306 private: 307 int32_t queueJpegSetting(int32_t out_buf_index, metadata_buffer_t *metadata); 308 309 public: 310 static int kMaxBuffers; 311 QCamera3PostProcessor m_postprocessor; // post processor 312 cam_dimension_t m_max_pic_dim; 313 314 private: 315 camera3_stream_t *mCamera3Stream; 316 uint32_t mNumBufsRegistered; 317 uint32_t mNumSnapshotBufs; 318 uint32_t mYuvWidth, mYuvHeight; 319 int32_t mCurrentBufIndex; 320 cam_stream_type_t mStreamType; 321 cam_format_t mStreamFormat; 322 bool m_bWNROn; 323 bool mPostProcStarted; 324 bool mInputBufferConfig; // Set when the picture channel is configured 325 // for processing input(framework) buffers 326 327 QCamera3GrallocMemory mMemory; 328 QCamera3HeapMemory *mYuvMemory; 329 QCamera3Channel *m_pMetaChannel; 330 mm_camera_super_buf_t *mMetaFrame; 331 QCamera3GrallocMemory mOfflineMemory; 332 QCamera3HeapMemory mOfflineMetaMemory; 333 334 // Keep a list of free buffers 335 Mutex mFreeBuffersLock; 336 List<uint32_t> mFreeBufferList; 337 }; 338 339 // reprocess channel class 340 class QCamera3ReprocessChannel : public QCamera3Channel 341 { 342 public: 343 QCamera3ReprocessChannel(uint32_t cam_handle, 344 mm_camera_ops_t *cam_ops, 345 channel_cb_routine cb_routine, 346 cam_padding_info_t *paddingInfo, 347 uint32_t postprocess_mask, 348 void *userData, void *ch_hdl); 349 QCamera3ReprocessChannel(); 350 virtual ~QCamera3ReprocessChannel(); 351 // offline reprocess 352 int32_t doReprocessOffline(qcamera_fwk_input_pp_data_t *frame); 353 int32_t doReprocess(int buf_fd, uint32_t buf_length, int32_t &ret_val, 354 mm_camera_super_buf_t *meta_buf); 355 int32_t extractFrameCropAndRotation(mm_camera_super_buf_t *frame, 356 mm_camera_buf_def_t *meta_buffer, 357 jpeg_settings_t *jpeg_settings, 358 qcamera_fwk_input_pp_data_t &fwk_frame); 359 int32_t extractCrop(qcamera_fwk_input_pp_data_t *frame); 360 virtual QCamera3Memory *getStreamBufs(uint32_t len); 361 virtual void putStreamBufs(); 362 virtual int32_t initialize(cam_is_type_t isType); 363 int32_t unmapOfflineBuffers(bool all); 364 virtual int32_t stop(); 365 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 366 QCamera3Stream *stream); 367 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 368 void* userdata); 369 int32_t addReprocStreamsFromSource(cam_pp_feature_config_t &pp_config, 370 const reprocess_config_t &src_config, 371 cam_is_type_t is_type, 372 QCamera3Channel *pMetaChannel); 373 QCamera3Stream *getStreamBySrcHandle(uint32_t srcHandle); 374 QCamera3Stream *getSrcStreamBySrcHandle(uint32_t srcHandle); registerBuffer(buffer_handle_t *,cam_is_type_t)375 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 376 { return NO_ERROR; }; 377 378 public: 379 void *picChHandle; 380 private: 381 typedef struct { 382 QCamera3Stream *stream; 383 cam_mapping_buf_type type; 384 int index; 385 } OfflineBuffer; 386 387 android::List<OfflineBuffer> mOfflineBuffers; 388 android::List<OfflineBuffer> mOfflineMetaBuffers; 389 int32_t mOfflineBuffersIndex; 390 int32_t mOfflineMetaIndex; 391 uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE]; 392 QCamera3Channel *m_pSrcChannel; // ptr to source channel for reprocess 393 QCamera3Channel *m_pMetaChannel; 394 QCamera3HeapMemory *mMemory; 395 }; 396 397 /* QCamera3SupportChannel is for HAL internal consumption only */ 398 class QCamera3SupportChannel : public QCamera3Channel 399 { 400 public: 401 QCamera3SupportChannel(uint32_t cam_handle, 402 mm_camera_ops_t *cam_ops, 403 cam_padding_info_t *paddingInfo, 404 uint32_t postprocess_mask, 405 void *userData); 406 virtual ~QCamera3SupportChannel(); 407 408 virtual int32_t initialize(cam_is_type_t isType); 409 410 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber); 411 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 412 QCamera3Stream *stream); 413 414 virtual QCamera3Memory *getStreamBufs(uint32_t le); 415 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)416 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 417 { return NO_ERROR; }; 418 419 static cam_dimension_t kDim; 420 private: 421 QCamera3HeapMemory *mMemory; 422 }; 423 424 }; // namespace qcamera 425 426 #endif /* __QCAMERA_CHANNEL_H__ */ 427