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_CHANNEL_H__ 31 #define __QCAMERA3_CHANNEL_H__ 32 33 // System dependencies 34 #include <utils/List.h> 35 #include <utils/Mutex.h> 36 #include <utils/Vector.h> 37 #include "gralloc_priv.h" 38 #include <sys/stat.h> 39 // Camera dependencies 40 #include "cam_intf.h" 41 #include "cam_types.h" 42 #include "hardware/camera3.h" 43 #include "QCamera3HALHeader.h" 44 #include "QCamera3Mem.h" 45 #include "QCamera3PostProc.h" 46 #include "QCamera3Stream.h" 47 #include "QCamera3StreamMem.h" 48 49 #include "HdrPlusClient.h" 50 51 extern "C" { 52 #include "mm_camera_interface.h" 53 #include "mm_jpeg_interface.h" 54 } 55 56 using namespace android; 57 58 #define MIN_STREAMING_BUFFER_NUM 7+11 59 60 #define QCAMERA_DUMP_FRM_PREVIEW 1 61 #define QCAMERA_DUMP_FRM_VIDEO (1<<1) 62 #define QCAMERA_DUMP_FRM_INPUT_JPEG (1<<2) 63 #define QCAMERA_DUMP_FRM_CALLBACK (1<<3) 64 #define QCAMERA_DUMP_FRM_OUTPUT_JPEG (1<<5) 65 #define QCAMERA_DUMP_FRM_INPUT_REPROCESS (1<<6) 66 67 typedef int64_t nsecs_t; 68 69 namespace qcamera { 70 71 typedef void (*channel_cb_routine)(mm_camera_super_buf_t *metadata, 72 camera3_stream_buffer_t *buffer, 73 uint32_t frame_number, bool isInputBuffer, 74 void *userdata); 75 76 typedef void (*channel_cb_buffer_err)(QCamera3Channel* ch, uint32_t frameNumber, 77 camera3_buffer_status_t err, 78 void *userdata); 79 80 class QCamera3Channel 81 { 82 public: 83 QCamera3Channel(uint32_t cam_handle, 84 uint32_t channel_handle, 85 mm_camera_ops_t *cam_ops, 86 channel_cb_routine cb_routine, 87 channel_cb_buffer_err cb_buf_err, 88 cam_padding_info_t *paddingInfo, 89 cam_feature_mask_t postprocess_mask, 90 void *userData, uint32_t numBuffers); 91 virtual ~QCamera3Channel(); 92 93 virtual int32_t start(); 94 virtual int32_t stop(); 95 virtual int32_t setBatchSize(uint32_t); 96 virtual int32_t queueBatchBuf(); 97 virtual int32_t setPerFrameMapUnmap(bool enable); 98 int32_t bufDone(mm_camera_super_buf_t *recvd_frame); 99 virtual int32_t setBundleInfo(const cam_bundle_config_t &bundleInfo); 100 101 virtual uint32_t getStreamTypeMask(); 102 uint32_t getStreamID(uint32_t streamMask); 103 void destroy(); 104 virtual int32_t initialize(cam_is_type_t isType) = 0; request(buffer_handle_t *,uint32_t,int &)105 virtual int32_t request(buffer_handle_t * /*buffer*/, 106 uint32_t /*frameNumber*/, 107 int &/*indexUsed*/){ return 0;}; 108 virtual int32_t request(buffer_handle_t * /*buffer*/, 109 uint32_t /*frameNumber*/, 110 camera3_stream_buffer_t* /*pInputBuffer*/, 111 metadata_buffer_t* /*metadata*/, 112 int & /*indexUsed*/, 113 __unused bool internalRequest = false, 114 __unused bool meteringOnly = false){ return 0;}; 115 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 116 QCamera3Stream *stream) = 0; 117 118 virtual int32_t registerBuffer(buffer_handle_t *buffer, cam_is_type_t isType) = 0; 119 virtual QCamera3StreamMem *getStreamBufs(uint32_t len) = 0; 120 virtual void putStreamBufs() = 0; 121 virtual int32_t flush(); 122 123 QCamera3Stream *getStreamByHandle(uint32_t streamHandle); getMyHandle()124 uint32_t getMyHandle() const {return m_handle;}; getNumOfStreams()125 uint32_t getNumOfStreams() const {return m_numStreams;}; getNumBuffers()126 uint32_t getNumBuffers() const {return mNumBuffers;}; 127 QCamera3Stream *getStreamByIndex(uint32_t index); 128 129 static void streamCbRoutine(mm_camera_super_buf_t *super_frame, 130 QCamera3Stream *stream, void *userdata); 131 void dumpYUV(mm_camera_buf_def_t *frame, cam_dimension_t dim, 132 cam_frame_len_offset_t offset, uint8_t name); 133 static bool isUBWCEnabled(); 134 void setUBWCEnabled(bool val); 135 static cam_format_t getStreamDefaultFormat(cam_stream_type_t type, 136 uint32_t width, uint32_t height, bool forcePreviewUBWC, cam_is_type_t isType); 137 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) = 0; 138 setNRMode(uint8_t nrMode)139 void setNRMode(uint8_t nrMode) { mNRMode = nrMode; } getNRMode()140 uint8_t getNRMode() { return mNRMode; } 141 142 void *mUserData; 143 cam_padding_info_t mPaddingInfo; 144 QCamera3Stream *mStreams[MAX_STREAM_NUM_IN_BUNDLE]; 145 uint32_t m_numStreams; 146 protected: 147 148 int32_t addStream(cam_stream_type_t streamType, 149 cam_format_t streamFormat, 150 cam_dimension_t streamDim, 151 cam_rotation_t streamRotation, 152 uint8_t minStreamBufnum, 153 cam_feature_mask_t postprocessMask, 154 cam_is_type_t isType, 155 uint32_t batchSize = 0); 156 157 int32_t allocateStreamInfoBuf(camera3_stream_t *stream); 158 159 uint32_t m_camHandle; 160 mm_camera_ops_t *m_camOps; 161 bool m_bIsActive; 162 bool m_bUBWCenable; 163 164 uint32_t m_handle; 165 166 167 mm_camera_buf_notify_t mDataCB; 168 169 170 QCamera3HeapMemory *mStreamInfoBuf; 171 channel_cb_routine mChannelCB; 172 channel_cb_buffer_err mChannelCbBufErr; 173 //cam_padding_info_t *mPaddingInfo; 174 cam_feature_mask_t mPostProcMask; 175 uint32_t mYUVDump; 176 cam_is_type_t mIsType; 177 uint32_t mNumBuffers; 178 /* Enable unmapping of buffer before issuing buffer callback. Default value 179 * for this flag is true and is selectively set to false for the usecases 180 * such as HFR to avoid any performance hit due to mapping/unmapping */ 181 bool mPerFrameMapUnmapEnable; 182 uint32_t mFrmNum; 183 uint32_t mDumpFrmCnt; 184 uint32_t mSkipMode; 185 uint32_t mDumpSkipCnt; 186 uint8_t mNRMode; 187 bool mMapStreamBuffers; // Whether to mmap all stream buffers 188 }; 189 190 /* QCamera3ProcessingChannel is used to handle all streams that are directly 191 * generated by hardware and given to frameworks without any postprocessing at HAL. 192 * It also handles input streams that require reprocessing by hardware and then 193 * returned to frameworks. */ 194 class QCamera3ProcessingChannel : public QCamera3Channel 195 { 196 public: 197 QCamera3ProcessingChannel(uint32_t cam_handle, 198 uint32_t channel_handle, 199 mm_camera_ops_t *cam_ops, 200 channel_cb_routine cb_routine, 201 channel_cb_buffer_err cb_buffer_err, 202 cam_padding_info_t *paddingInfo, 203 void *userData, 204 camera3_stream_t *stream, 205 cam_stream_type_t stream_type, 206 cam_feature_mask_t postprocess_mask, 207 QCamera3Channel *metadataChannel, 208 uint32_t numBuffers = MAX_INFLIGHT_REQUESTS); 209 210 ~QCamera3ProcessingChannel(); 211 212 virtual int32_t initialize(cam_is_type_t isType); 213 virtual int32_t request(buffer_handle_t *buffer, 214 uint32_t frameNumber, 215 camera3_stream_buffer_t* pInputBuffer, 216 metadata_buffer_t* metadata, int &indexUsed, 217 __unused bool internalRequest, __unused bool meteringOnly); 218 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 219 QCamera3Stream *stream); 220 virtual QCamera3StreamMem *getStreamBufs(uint32_t len); 221 virtual void putStreamBufs(); 222 virtual int32_t registerBuffer(buffer_handle_t *buffer, cam_is_type_t isType); 223 // Register a buffer and get the buffer def for the registered buffer. 224 virtual int32_t registerBufferAndGetBufDef(buffer_handle_t *buffer, mm_camera_buf_def_t *frame); 225 // Unregister a buffer. 226 virtual void unregisterBuffer(mm_camera_buf_def_t *frame); 227 virtual int32_t stop(); 228 229 virtual reprocess_type_t getReprocessType() = 0; 230 231 virtual void reprocessCbRoutine(buffer_handle_t *resultBuffer, 232 uint32_t resultFrameNumber); 233 234 int32_t queueReprocMetadata(mm_camera_super_buf_t *metadata); 235 virtual int32_t metadataBufDone(mm_camera_super_buf_t *recvd_frame); 236 int32_t translateStreamTypeAndFormat(camera3_stream_t *stream, 237 cam_stream_type_t &streamType, 238 cam_format_t &streamFormat); 239 int32_t setReprocConfig(reprocess_config_t &reproc_cfg, 240 camera3_stream_buffer_t *pInputBuffer, 241 metadata_buffer_t *metadata, 242 cam_format_t streamFormat, cam_dimension_t dim); 243 int32_t setFwkInputPPData(qcamera_fwk_input_pp_data_t *src_frame, 244 camera3_stream_buffer_t *pInputBuffer, 245 reprocess_config_t *reproc_cfg, 246 metadata_buffer_t *metadata, 247 buffer_handle_t *output_buffer, 248 uint32_t frameNumber); 249 int32_t checkStreamCbErrors(mm_camera_super_buf_t *super_frame, 250 QCamera3Stream *stream); 251 int32_t getStreamSize(cam_dimension_t &dim); 252 virtual int32_t timeoutFrame(uint32_t frameNumber); 253 virtual int32_t postprocFail(qcamera_hal3_pp_buffer_t *ppBuffer); 254 255 QCamera3PostProcessor m_postprocessor; // post processor 256 void showDebugFPS(int32_t streamType); 257 258 int32_t releaseOfflineMemory(uint32_t resultFrameNumber); 259 protected: 260 uint8_t mDebugFPS; 261 int mFrameCount; 262 int mLastFrameCount; 263 nsecs_t mLastFpsTime; isWNREnabled()264 bool isWNREnabled() {return m_bWNROn;}; 265 void startPostProc(const reprocess_config_t &reproc_cfg); 266 void issueChannelCb(buffer_handle_t *resultBuffer, 267 uint32_t resultFrameNumber); 268 269 QCamera3StreamMem mMemory; //output buffer allocated by fwk 270 camera3_stream_t *mCamera3Stream; 271 uint32_t mNumBufs; 272 cam_stream_type_t mStreamType; 273 cam_format_t mStreamFormat; 274 uint8_t mIntent; 275 276 bool mPostProcStarted; 277 reprocess_type_t mReprocessType; // Only valid when mPostProcStarted is true. 278 bool mInputBufferConfig; // Set when the processing channel is configured 279 // for processing input(framework) buffers 280 281 QCamera3Channel *m_pMetaChannel; 282 mm_camera_super_buf_t *mMetaFrame; 283 QCamera3StreamMem mOfflineMemory; //reprocessing input buffer 284 QCamera3StreamMem mOfflineMetaMemory; //reprocessing metadata buffer 285 List<uint32_t> mFreeOfflineMetaBuffersList; 286 Mutex mFreeOfflineMetaBuffersLock; 287 android::List<mm_camera_super_buf_t *> mOutOfSequenceBuffers; 288 289 private: 290 291 bool m_bWNROn; 292 }; 293 294 /* QCamera3RegularChannel is used to handle all streams that are directly 295 * generated by hardware and given to frameworks without any postprocessing at HAL. 296 * Examples are: all IMPLEMENTATION_DEFINED streams, CPU_READ streams. */ 297 class QCamera3RegularChannel : public QCamera3ProcessingChannel 298 { 299 public: 300 QCamera3RegularChannel(uint32_t cam_handle, 301 uint32_t channel_handle, 302 mm_camera_ops_t *cam_ops, 303 channel_cb_routine cb_routine, 304 channel_cb_buffer_err cb_buffer_err, 305 cam_padding_info_t *paddingInfo, 306 void *userData, 307 camera3_stream_t *stream, 308 cam_stream_type_t stream_type, 309 cam_feature_mask_t postprocess_mask, 310 QCamera3Channel *metadataChannel, 311 uint32_t numBuffers = MAX_INFLIGHT_REQUESTS); 312 313 virtual ~QCamera3RegularChannel(); 314 315 virtual int32_t setBatchSize(uint32_t batchSize); 316 virtual uint32_t getStreamTypeMask(); 317 virtual int32_t queueBatchBuf(); 318 virtual int32_t initialize(cam_is_type_t isType); 319 using QCamera3ProcessingChannel::request; 320 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber, 321 int &indexUsed); 322 virtual reprocess_type_t getReprocessType(); 323 324 private: 325 int32_t initialize(struct private_handle_t *priv_handle); 326 327 uint32_t mBatchSize; 328 cam_rotation_t mRotation; 329 }; 330 331 /* QCamera3MetadataChannel is for metadata stream generated by camera daemon. */ 332 class QCamera3MetadataChannel : public QCamera3Channel 333 { 334 public: 335 QCamera3MetadataChannel(uint32_t cam_handle, 336 uint32_t channel_handle, 337 mm_camera_ops_t *cam_ops, 338 channel_cb_routine cb_routine, 339 channel_cb_buffer_err cb_buffer_err, 340 cam_padding_info_t *paddingInfo, 341 cam_feature_mask_t postprocess_mask, 342 void *userData, 343 uint32_t numBuffers = MIN_STREAMING_BUFFER_NUM); 344 virtual ~QCamera3MetadataChannel(); 345 346 virtual int32_t initialize(cam_is_type_t isType); 347 348 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber, 349 int &indexUsed); 350 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 351 QCamera3Stream *stream); 352 353 virtual QCamera3StreamMem *getStreamBufs(uint32_t le); 354 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)355 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 356 { return NO_ERROR; }; timeoutFrame(__unused uint32_t frameNumber)357 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) {return NO_ERROR; }; 358 enableDepthData(bool enable)359 void enableDepthData(bool enable) { mDepthDataPresent = enable; } 360 361 private: 362 QCamera3StreamMem *mMemory; 363 bool mDepthDataPresent; 364 }; 365 366 /* QCamera3RawChannel is for opaqueu/cross-platform raw stream containing 367 * vendor specific bayer data or 16-bit unpacked bayer data */ 368 class QCamera3RawChannel : public QCamera3RegularChannel 369 { 370 public: 371 QCamera3RawChannel(uint32_t cam_handle, 372 uint32_t channel_handle, 373 mm_camera_ops_t *cam_ops, 374 channel_cb_routine cb_routine, 375 channel_cb_buffer_err cb_buffer_err, 376 cam_padding_info_t *paddingInfo, 377 void *userData, 378 camera3_stream_t *stream, 379 cam_feature_mask_t postprocess_mask, 380 QCamera3Channel *metadataChannel, 381 bool raw_16 = false, 382 uint32_t numBuffers = MAX_INFLIGHT_REQUESTS); 383 384 virtual ~QCamera3RawChannel(); 385 386 virtual int32_t initialize(cam_is_type_t isType); 387 388 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 389 QCamera3Stream *stream); 390 391 virtual reprocess_type_t getReprocessType(); 392 393 private: 394 bool mRawDump; 395 bool mIsRaw16; 396 397 void dumpRawSnapshot(mm_camera_buf_def_t *frame); 398 void convertLegacyToRaw16(mm_camera_buf_def_t *frame); 399 void convertMipiToRaw16(mm_camera_buf_def_t *frame); 400 }; 401 402 /* 403 * QCamera3RawDumpChannel is for internal use only for Raw dump 404 */ 405 406 class QCamera3RawDumpChannel : public QCamera3Channel 407 { 408 public: 409 QCamera3RawDumpChannel(uint32_t cam_handle, 410 uint32_t channel_handle, 411 mm_camera_ops_t *cam_ops, 412 cam_dimension_t rawDumpSize, 413 cam_padding_info_t *paddingInfo, 414 void *userData, 415 cam_feature_mask_t postprocess_mask, uint32_t numBuffers = 3U); 416 virtual ~QCamera3RawDumpChannel(); 417 virtual int32_t initialize(cam_is_type_t isType); 418 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 419 QCamera3Stream *stream); 420 virtual QCamera3StreamMem *getStreamBufs(uint32_t le); 421 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)422 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 423 { return NO_ERROR; }; timeoutFrame(__unused uint32_t frameNumber)424 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) {return NO_ERROR;}; 425 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber, 426 int &indexUsed); 427 void dumpRawSnapshot(mm_camera_buf_def_t *frame); 428 429 public: 430 cam_dimension_t mDim; 431 432 private: 433 bool mRawDump; 434 QCamera3StreamMem *mMemory; 435 }; 436 437 /* 438 * QCamera3HdrPlusRawSrcChannel is for internal use only for providing RAW input buffers to HDR+ 439 * client for prototyping Paintbox HDR+. 440 */ 441 442 class QCamera3HdrPlusRawSrcChannel : public QCamera3RawDumpChannel 443 { 444 public: 445 QCamera3HdrPlusRawSrcChannel( 446 uint32_t cam_handle, 447 uint32_t channel_handle, 448 mm_camera_ops_t *cam_ops, 449 cam_dimension_t rawDumpSize, 450 cam_padding_info_t *paddingInfo, 451 void *userData, 452 cam_feature_mask_t postprocess_mask, 453 std::shared_ptr<HdrPlusClient> hdrPlusClient, 454 uint32_t hdrPlusStreamId, // HDR+ stream ID for RAW input 455 uint32_t numBuffers = 3U); 456 virtual ~QCamera3HdrPlusRawSrcChannel(); 457 458 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 459 QCamera3Stream *stream) override; 460 461 private: 462 // Send a RAW frame to HDR+ service as HDR+ input buffers. 463 void sendRawToHdrPlusService(mm_camera_buf_def_t *frame); 464 std::shared_ptr<HdrPlusClient> mHdrPlusClient; 465 // HDR+ stream ID. 466 uint32_t mHdrPlusStreamId; 467 468 }; 469 470 /* QCamera3YUVChannel is used to handle flexible YUV streams that are directly 471 * generated by hardware and given to frameworks without any postprocessing at HAL. 472 * It is also used to handle input buffers that generate YUV outputs */ 473 class QCamera3YUVChannel : public QCamera3ProcessingChannel 474 { 475 public: 476 QCamera3YUVChannel(uint32_t cam_handle, 477 uint32_t channel_handle, 478 mm_camera_ops_t *cam_ops, 479 channel_cb_routine cb_routine, 480 channel_cb_buffer_err cb_buffer_err, 481 cam_padding_info_t *paddingInfo, 482 void *userData, 483 camera3_stream_t *stream, 484 cam_stream_type_t stream_type, 485 cam_feature_mask_t postprocess_mask, 486 QCamera3Channel *metadataChannel); 487 ~QCamera3YUVChannel(); 488 virtual int32_t initialize(cam_is_type_t isType); 489 using QCamera3ProcessingChannel::request; 490 virtual int32_t request(buffer_handle_t *buffer, 491 uint32_t frameNumber, 492 camera3_stream_buffer_t* pInputBuffer, 493 metadata_buffer_t* metadata, bool &needMetadata, 494 int &indexUsed, bool internalRequest, bool meteringOnly); 495 virtual reprocess_type_t getReprocessType(); 496 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 497 QCamera3Stream *stream); 498 virtual void putStreamBufs(); 499 virtual void reprocessCbRoutine(buffer_handle_t *resultBuffer, 500 uint32_t resultFrameNumber); 501 virtual int32_t postprocFail(qcamera_hal3_pp_buffer_t *ppBuffer); 502 503 private: 504 typedef struct { 505 uint32_t frameNumber; 506 bool offlinePpFlag; 507 buffer_handle_t *output; 508 mm_camera_super_buf_t *callback_buffer; 509 } PpInfo; 510 511 // Whether offline postprocessing is required for this channel 512 bool mBypass; 513 uint32_t mFrameLen; 514 515 // Current edge, noise, and crop region setting 516 cam_edge_application_t mEdgeMode; 517 uint32_t mNoiseRedMode; 518 cam_crop_region_t mCropRegion; 519 520 // Mutex to protect mOfflinePpFlagMap and mFreeHeapBufferList 521 Mutex mOfflinePpLock; 522 // Map between free number and whether the request needs to be 523 // postprocessed. 524 List<PpInfo> mOfflinePpInfoList; 525 // Heap buffer index list 526 List<uint32_t> mFreeHeapBufferList; 527 528 private: 529 bool needsFramePostprocessing(metadata_buffer_t* meta); 530 int32_t handleOfflinePpCallback(uint32_t resultFrameNumber, 531 Vector<mm_camera_super_buf_t *>& pendingCbs); 532 mm_camera_super_buf_t* getNextPendingCbBuffer(); 533 }; 534 535 /* QCamera3PicChannel is for JPEG stream, which contains a YUV stream generated 536 * by the hardware, and encoded to a JPEG stream */ 537 class QCamera3PicChannel : public QCamera3ProcessingChannel 538 { 539 public: 540 QCamera3PicChannel(uint32_t cam_handle, 541 uint32_t channel_handle, 542 mm_camera_ops_t *cam_ops, 543 channel_cb_routine cb_routine, 544 channel_cb_buffer_err cb_buffer_err, 545 cam_padding_info_t *paddingInfo, 546 void *userData, 547 camera3_stream_t *stream, 548 cam_feature_mask_t postprocess_mask, 549 bool is4KVideo, 550 bool isInputStreamConfigured, 551 bool useY8, 552 QCamera3Channel *metadataChannel, 553 uint32_t numBuffers = MAX_INFLIGHT_REQUESTS); 554 ~QCamera3PicChannel(); 555 556 virtual int32_t initialize(cam_is_type_t isType); 557 virtual int32_t flush(); 558 virtual int32_t request(buffer_handle_t *buffer, 559 uint32_t frameNumber, 560 camera3_stream_buffer_t* pInputBuffer, 561 metadata_buffer_t* metadata, 562 int &indexUsed, bool internalRequest, bool meteringOnly); 563 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 564 QCamera3Stream *stream); 565 566 virtual QCamera3StreamMem *getStreamBufs(uint32_t le); 567 virtual void putStreamBufs(); 568 virtual reprocess_type_t getReprocessType(); 569 virtual int32_t timeoutFrame(uint32_t frameNumber); 570 571 QCamera3Exif *getExifData(metadata_buffer_t *metadata, 572 jpeg_settings_t *jpeg_settings); 573 void overrideYuvSize(uint32_t width, uint32_t height); 574 static void jpegEvtHandle(jpeg_job_status_t status, 575 uint32_t /*client_hdl*/, 576 uint32_t jobId, 577 mm_jpeg_output_t *p_output, 578 void *userdata); 579 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 580 void *userdata); 581 582 // Reprocessing is done with the metadata. This function frees the metadata or returns the 583 // metadata to the metadata channel. 584 int32_t metadataBufDone(mm_camera_super_buf_t *recvd_frame) override; 585 586 // Get a YUV buffer for a request from camera service. 587 int32_t getYuvBufferForRequest(mm_camera_buf_def_t *frame, uint32_t frameNumber); 588 589 // Return a YUV buffer (from getYuvBufferForRequest) and request jpeg encoding. 590 int32_t returnYuvBufferAndEncode(mm_camera_buf_def_t *frame, 591 buffer_handle_t *outBuffer, uint32_t frameNumber, 592 std::shared_ptr<metadata_buffer_t> metadata, 593 mm_camera_buf_def_t *metaFrame); 594 595 // Return a YUV buffer (from getYuvBufferForRequest) without requesting jpeg encoding. 596 int32_t returnYuvBuffer(mm_camera_buf_def_t *frame); 597 598 private: 599 int32_t queueJpegSetting(uint32_t out_buf_index, metadata_buffer_t *metadata); 600 int32_t initializeJpegSetting(uint32_t index, metadata_buffer_t *metadata, 601 jpeg_settings_t *settings); 602 603 public: 604 cam_dimension_t m_max_pic_dim; 605 606 private: 607 uint32_t mNumSnapshotBufs; 608 uint32_t mYuvWidth, mYuvHeight; 609 int32_t mCurrentBufIndex; 610 bool mInputBufferHint; 611 QCamera3StreamMem *mYuvMemory; 612 // Keep a list of free buffers 613 Mutex mFreeBuffersLock; 614 List<uint32_t> mFreeBufferList; 615 uint32_t mFrameLen; 616 617 // The metadata passed in via returnYuvBufferAndEncode and is allocated externally. 618 // These should not be returned to metadata channel. 619 Mutex mPendingExternalMetadataLock; 620 std::vector<std::shared_ptr<metadata_buffer_t>> mPendingExternalMetadata; 621 }; 622 623 // reprocess channel class 624 class QCamera3ReprocessChannel : public QCamera3Channel 625 { 626 public: 627 QCamera3ReprocessChannel(uint32_t cam_handle, 628 uint32_t channel_handle, 629 mm_camera_ops_t *cam_ops, 630 channel_cb_routine cb_routine, 631 channel_cb_buffer_err cb_buffer_err, 632 cam_padding_info_t *paddingInfo, 633 cam_feature_mask_t postprocess_mask, 634 void *userData, void *ch_hdl); 635 QCamera3ReprocessChannel(); 636 virtual ~QCamera3ReprocessChannel(); 637 // offline reprocess 638 virtual int32_t start(); 639 virtual int32_t stop(); 640 int32_t doReprocessOffline(qcamera_fwk_input_pp_data_t *frame, 641 bool isPriorityFrame = false); 642 int32_t doReprocess(int buf_fd,void *buffer, size_t buf_length, int32_t &ret_val, 643 mm_camera_super_buf_t *meta_buf); 644 int32_t overrideMetadata(qcamera_hal3_pp_buffer_t *pp_buffer, 645 mm_camera_buf_def_t *meta_buffer, 646 jpeg_settings_t *jpeg_settings, 647 qcamera_fwk_input_pp_data_t &fwk_frame); 648 int32_t overrideFwkMetadata(qcamera_fwk_input_pp_data_t *frame); 649 virtual QCamera3StreamMem *getStreamBufs(uint32_t len); 650 virtual void putStreamBufs(); 651 virtual int32_t initialize(cam_is_type_t isType); 652 int32_t unmapOfflineBuffers(bool all); 653 int32_t bufDone(mm_camera_super_buf_t *recvd_frame); 654 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 655 QCamera3Stream *stream); 656 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 657 void* userdata); 658 int32_t addReprocStreamsFromSource(cam_pp_feature_config_t &pp_config, 659 const reprocess_config_t &src_config, 660 cam_is_type_t is_type, 661 QCamera3Channel *pMetaChannel); 662 QCamera3Stream *getStreamBySrcHandle(uint32_t srcHandle); 663 QCamera3Stream *getSrcStreamBySrcHandle(uint32_t srcHandle); 664 virtual int32_t registerBuffer(buffer_handle_t * buffer, cam_is_type_t isType); timeoutFrame(__unused uint32_t frameNumber)665 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) {return NO_ERROR;}; 666 667 public: 668 void *inputChHandle; 669 670 private: 671 typedef struct { 672 QCamera3Stream *stream; 673 cam_mapping_buf_type type; 674 uint32_t index; 675 } OfflineBuffer; 676 677 int32_t resetToCamPerfNormal(uint32_t frameNumber); 678 Mutex mOfflineBuffersLock; // Lock for offline buffers 679 android::List<OfflineBuffer> mOfflineBuffers; 680 android::List<OfflineBuffer> mOfflineMetaBuffers; 681 int32_t mOfflineBuffersIndex; 682 int32_t mOfflineMetaIndex; 683 uint32_t mFrameLen; 684 Mutex mFreeBuffersLock; // Lock for free heap buffers 685 List<int32_t> mFreeBufferList; // Free heap buffers list 686 reprocess_type_t mReprocessType; 687 uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE]; 688 QCamera3ProcessingChannel *m_pSrcChannel; // ptr to source channel for reprocess 689 QCamera3Channel *m_pMetaChannel; 690 QCamera3StreamMem *mMemory; 691 QCamera3StreamMem mGrallocMemory; 692 Vector<uint32_t> mPriorityFrames; 693 Mutex mPriorityFramesLock; 694 bool mReprocessPerfMode; 695 }; 696 697 698 /* QCamera3SupportChannel is for HAL internal consumption only */ 699 class QCamera3SupportChannel : public QCamera3Channel 700 { 701 public: 702 QCamera3SupportChannel(uint32_t cam_handle, 703 uint32_t channel_handle, 704 mm_camera_ops_t *cam_ops, 705 cam_padding_info_t *paddingInfo, 706 cam_feature_mask_t postprocess_mask, 707 cam_stream_type_t streamType, 708 cam_dimension_t *dim, 709 cam_format_t streamFormat, 710 uint8_t hw_analysis_supported, 711 cam_color_filter_arrangement_t color_arrangement, 712 void *userData, 713 uint32_t numBuffers = MIN_STREAMING_BUFFER_NUM 714 ); 715 virtual ~QCamera3SupportChannel(); 716 717 virtual int32_t initialize(cam_is_type_t isType); 718 719 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber, 720 int &indexUsed); 721 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 722 QCamera3Stream *stream); 723 724 virtual QCamera3StreamMem *getStreamBufs(uint32_t le); 725 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)726 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 727 { return NO_ERROR; }; timeoutFrame(__unused uint32_t frameNumber)728 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) {return NO_ERROR;}; 729 730 static cam_dimension_t kDim; 731 private: 732 QCamera3StreamMem *mMemory; 733 cam_dimension_t mDim; 734 cam_stream_type_t mStreamType; 735 cam_format_t mStreamFormat; 736 uint8_t mHwAnalysisSupported; 737 cam_color_filter_arrangement_t mColorArrangement; 738 }; 739 740 class QCamera3DepthChannel : public QCamera3ProcessingChannel { 741 public: 742 743 QCamera3DepthChannel(QCamera3DepthChannel const&) = delete; 744 QCamera3DepthChannel& operator=(QCamera3DepthChannel const&) = delete; 745 QCamera3DepthChannel(uint32_t cam_handle,uint32_t channel_handle,mm_camera_ops_t * cam_ops,channel_cb_routine cb_routine,channel_cb_buffer_err cb_buf_err,cam_padding_info_t * paddingInfo,cam_feature_mask_t postprocess_mask,void * userData,uint32_t numBuffers,camera3_stream_t * stream,QCamera3Channel * metadataChannel)746 QCamera3DepthChannel(uint32_t cam_handle, 747 uint32_t channel_handle, 748 mm_camera_ops_t *cam_ops, 749 channel_cb_routine cb_routine, 750 channel_cb_buffer_err cb_buf_err, 751 cam_padding_info_t *paddingInfo, 752 cam_feature_mask_t postprocess_mask, 753 void *userData, uint32_t numBuffers, 754 camera3_stream_t *stream, 755 QCamera3Channel *metadataChannel) : 756 QCamera3ProcessingChannel(cam_handle, channel_handle, cam_ops, 757 cb_routine, cb_buf_err, paddingInfo, userData, stream, 758 CAM_STREAM_TYPE_DEFAULT, postprocess_mask, 759 metadataChannel, numBuffers), 760 mStream(stream), mGrallocMem(0) {} 761 ~QCamera3DepthChannel(); 762 763 int32_t mapBuffer(buffer_handle_t *buffer, uint32_t frameNumber); 764 int32_t populateDepthData(const cam_depth_data_t &data, 765 uint32_t frameNumber); 766 buffer_handle_t *getOldestFrame(uint32_t &frameNumber); 767 int32_t unmapBuffer(uint32_t frameNumber); 768 int32_t unmapAllBuffers(); getStream()769 camera3_stream_t *getStream() { return mStream; } 770 start()771 int32_t start() override { return NO_ERROR; }; stop()772 int32_t stop() override { return NO_ERROR; }; setBatchSize(uint32_t)773 int32_t setBatchSize(uint32_t) override { return NO_ERROR; } queueBatchBuf()774 int32_t queueBatchBuf() override { return NO_ERROR; } setPerFrameMapUnmap(bool)775 int32_t setPerFrameMapUnmap(bool) override { return NO_ERROR; } getStreamTypeMask()776 uint32_t getStreamTypeMask() override { return 0; }; initialize(cam_is_type_t)777 int32_t initialize(cam_is_type_t) { return NO_ERROR; } streamCbRoutine(mm_camera_super_buf_t *,QCamera3Stream *)778 void streamCbRoutine(mm_camera_super_buf_t *, QCamera3Stream *) override {} registerBuffer(buffer_handle_t *,cam_is_type_t)779 int32_t registerBuffer(buffer_handle_t *, cam_is_type_t) override 780 { return NO_ERROR; } getStreamBufs(uint32_t)781 QCamera3StreamMem *getStreamBufs(uint32_t) override { return NULL; } putStreamBufs()782 void putStreamBufs() override {} timeoutFrame(uint32_t)783 int32_t timeoutFrame(uint32_t) override { return NO_ERROR; } flush()784 int32_t flush() override { return NO_ERROR; } getReprocessType()785 reprocess_type_t getReprocessType() override { return REPROCESS_TYPE_NONE; } setBundleInfo(const cam_bundle_config_t &)786 int32_t setBundleInfo(const cam_bundle_config_t &) override 787 { return NO_ERROR; } 788 789 private: 790 camera3_stream_t *mStream; 791 QCamera3GrallocMemory mGrallocMem; 792 }; 793 794 }; // namespace qcamera 795 796 #endif /* __QCAMERA_CHANNEL_H__ */ 797