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