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