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 594 // Return a YUV buffer (from getYuvBufferForRequest) without requesting jpeg encoding. 595 int32_t returnYuvBuffer(mm_camera_buf_def_t *frame); 596 597 private: 598 int32_t queueJpegSetting(uint32_t out_buf_index, metadata_buffer_t *metadata); 599 600 public: 601 cam_dimension_t m_max_pic_dim; 602 603 private: 604 uint32_t mNumSnapshotBufs; 605 uint32_t mYuvWidth, mYuvHeight; 606 int32_t mCurrentBufIndex; 607 bool mInputBufferHint; 608 QCamera3StreamMem *mYuvMemory; 609 // Keep a list of free buffers 610 Mutex mFreeBuffersLock; 611 List<uint32_t> mFreeBufferList; 612 uint32_t mFrameLen; 613 614 // The metadata passed in via returnYuvBufferAndEncode and is allocated externally. 615 // These should not be returned to metadata channel. 616 Mutex mPendingExternalMetadataLock; 617 std::vector<std::shared_ptr<metadata_buffer_t>> mPendingExternalMetadata; 618 }; 619 620 // reprocess channel class 621 class QCamera3ReprocessChannel : public QCamera3Channel 622 { 623 public: 624 QCamera3ReprocessChannel(uint32_t cam_handle, 625 uint32_t channel_handle, 626 mm_camera_ops_t *cam_ops, 627 channel_cb_routine cb_routine, 628 channel_cb_buffer_err cb_buffer_err, 629 cam_padding_info_t *paddingInfo, 630 cam_feature_mask_t postprocess_mask, 631 void *userData, void *ch_hdl); 632 QCamera3ReprocessChannel(); 633 virtual ~QCamera3ReprocessChannel(); 634 // offline reprocess 635 virtual int32_t start(); 636 virtual int32_t stop(); 637 int32_t doReprocessOffline(qcamera_fwk_input_pp_data_t *frame, 638 bool isPriorityFrame = false); 639 int32_t doReprocess(int buf_fd,void *buffer, size_t buf_length, int32_t &ret_val, 640 mm_camera_super_buf_t *meta_buf); 641 int32_t overrideMetadata(qcamera_hal3_pp_buffer_t *pp_buffer, 642 mm_camera_buf_def_t *meta_buffer, 643 jpeg_settings_t *jpeg_settings, 644 qcamera_fwk_input_pp_data_t &fwk_frame); 645 int32_t overrideFwkMetadata(qcamera_fwk_input_pp_data_t *frame); 646 virtual QCamera3StreamMem *getStreamBufs(uint32_t len); 647 virtual void putStreamBufs(); 648 virtual int32_t initialize(cam_is_type_t isType); 649 int32_t unmapOfflineBuffers(bool all); 650 int32_t bufDone(mm_camera_super_buf_t *recvd_frame); 651 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 652 QCamera3Stream *stream); 653 static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, 654 void* userdata); 655 int32_t addReprocStreamsFromSource(cam_pp_feature_config_t &pp_config, 656 const reprocess_config_t &src_config, 657 cam_is_type_t is_type, 658 QCamera3Channel *pMetaChannel); 659 QCamera3Stream *getStreamBySrcHandle(uint32_t srcHandle); 660 QCamera3Stream *getSrcStreamBySrcHandle(uint32_t srcHandle); 661 virtual int32_t registerBuffer(buffer_handle_t * buffer, cam_is_type_t isType); timeoutFrame(__unused uint32_t frameNumber)662 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) {return NO_ERROR;}; 663 664 public: 665 void *inputChHandle; 666 667 private: 668 typedef struct { 669 QCamera3Stream *stream; 670 cam_mapping_buf_type type; 671 uint32_t index; 672 } OfflineBuffer; 673 674 int32_t resetToCamPerfNormal(uint32_t frameNumber); 675 Mutex mOfflineBuffersLock; // Lock for offline buffers 676 android::List<OfflineBuffer> mOfflineBuffers; 677 android::List<OfflineBuffer> mOfflineMetaBuffers; 678 int32_t mOfflineBuffersIndex; 679 int32_t mOfflineMetaIndex; 680 uint32_t mFrameLen; 681 Mutex mFreeBuffersLock; // Lock for free heap buffers 682 List<int32_t> mFreeBufferList; // Free heap buffers list 683 reprocess_type_t mReprocessType; 684 uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE]; 685 QCamera3ProcessingChannel *m_pSrcChannel; // ptr to source channel for reprocess 686 QCamera3Channel *m_pMetaChannel; 687 QCamera3StreamMem *mMemory; 688 QCamera3StreamMem mGrallocMemory; 689 Vector<uint32_t> mPriorityFrames; 690 Mutex mPriorityFramesLock; 691 bool mReprocessPerfMode; 692 }; 693 694 695 /* QCamera3SupportChannel is for HAL internal consumption only */ 696 class QCamera3SupportChannel : public QCamera3Channel 697 { 698 public: 699 QCamera3SupportChannel(uint32_t cam_handle, 700 uint32_t channel_handle, 701 mm_camera_ops_t *cam_ops, 702 cam_padding_info_t *paddingInfo, 703 cam_feature_mask_t postprocess_mask, 704 cam_stream_type_t streamType, 705 cam_dimension_t *dim, 706 cam_format_t streamFormat, 707 uint8_t hw_analysis_supported, 708 cam_color_filter_arrangement_t color_arrangement, 709 void *userData, 710 uint32_t numBuffers = MIN_STREAMING_BUFFER_NUM 711 ); 712 virtual ~QCamera3SupportChannel(); 713 714 virtual int32_t initialize(cam_is_type_t isType); 715 716 virtual int32_t request(buffer_handle_t *buffer, uint32_t frameNumber, 717 int &indexUsed); 718 virtual void streamCbRoutine(mm_camera_super_buf_t *super_frame, 719 QCamera3Stream *stream); 720 721 virtual QCamera3StreamMem *getStreamBufs(uint32_t le); 722 virtual void putStreamBufs(); registerBuffer(buffer_handle_t *,cam_is_type_t)723 virtual int32_t registerBuffer(buffer_handle_t * /*buffer*/, cam_is_type_t /*isType*/) 724 { return NO_ERROR; }; timeoutFrame(__unused uint32_t frameNumber)725 virtual int32_t timeoutFrame(__unused uint32_t frameNumber) {return NO_ERROR;}; 726 727 static cam_dimension_t kDim; 728 private: 729 QCamera3StreamMem *mMemory; 730 cam_dimension_t mDim; 731 cam_stream_type_t mStreamType; 732 cam_format_t mStreamFormat; 733 uint8_t mHwAnalysisSupported; 734 cam_color_filter_arrangement_t mColorArrangement; 735 }; 736 737 class QCamera3DepthChannel : public QCamera3ProcessingChannel { 738 public: 739 740 QCamera3DepthChannel(QCamera3DepthChannel const&) = delete; 741 QCamera3DepthChannel& operator=(QCamera3DepthChannel const&) = delete; 742 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)743 QCamera3DepthChannel(uint32_t cam_handle, 744 uint32_t channel_handle, 745 mm_camera_ops_t *cam_ops, 746 channel_cb_routine cb_routine, 747 channel_cb_buffer_err cb_buf_err, 748 cam_padding_info_t *paddingInfo, 749 cam_feature_mask_t postprocess_mask, 750 void *userData, uint32_t numBuffers, 751 camera3_stream_t *stream, 752 QCamera3Channel *metadataChannel) : 753 QCamera3ProcessingChannel(cam_handle, channel_handle, cam_ops, 754 cb_routine, cb_buf_err, paddingInfo, userData, stream, 755 CAM_STREAM_TYPE_DEFAULT, postprocess_mask, 756 metadataChannel, numBuffers), 757 mStream(stream), mGrallocMem(0) {} 758 ~QCamera3DepthChannel(); 759 760 int32_t mapBuffer(buffer_handle_t *buffer, uint32_t frameNumber); 761 int32_t populateDepthData(const cam_depth_data_t &data, 762 uint32_t frameNumber); 763 buffer_handle_t *getOldestFrame(uint32_t &frameNumber); 764 int32_t unmapBuffer(uint32_t frameNumber); 765 int32_t unmapAllBuffers(); getStream()766 camera3_stream_t *getStream() { return mStream; } 767 start()768 int32_t start() override { return NO_ERROR; }; stop()769 int32_t stop() override { return NO_ERROR; }; setBatchSize(uint32_t)770 int32_t setBatchSize(uint32_t) override { return NO_ERROR; } queueBatchBuf()771 int32_t queueBatchBuf() override { return NO_ERROR; } setPerFrameMapUnmap(bool)772 int32_t setPerFrameMapUnmap(bool) override { return NO_ERROR; } getStreamTypeMask()773 uint32_t getStreamTypeMask() override { return 0; }; initialize(cam_is_type_t)774 int32_t initialize(cam_is_type_t) { return NO_ERROR; } streamCbRoutine(mm_camera_super_buf_t *,QCamera3Stream *)775 void streamCbRoutine(mm_camera_super_buf_t *, QCamera3Stream *) override {} registerBuffer(buffer_handle_t *,cam_is_type_t)776 int32_t registerBuffer(buffer_handle_t *, cam_is_type_t) override 777 { return NO_ERROR; } getStreamBufs(uint32_t)778 QCamera3StreamMem *getStreamBufs(uint32_t) override { return NULL; } putStreamBufs()779 void putStreamBufs() override {} timeoutFrame(uint32_t)780 int32_t timeoutFrame(uint32_t) override { return NO_ERROR; } flush()781 int32_t flush() override { return NO_ERROR; } getReprocessType()782 reprocess_type_t getReprocessType() override { return REPROCESS_TYPE_NONE; } setBundleInfo(const cam_bundle_config_t &)783 int32_t setBundleInfo(const cam_bundle_config_t &) override 784 { return NO_ERROR; } 785 786 private: 787 camera3_stream_t *mStream; 788 QCamera3GrallocMemory mGrallocMem; 789 }; 790 791 }; // namespace qcamera 792 793 #endif /* __QCAMERA_CHANNEL_H__ */ 794