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 __QCAMERA3HARDWAREINTERFACE_H__ 31 #define __QCAMERA3HARDWAREINTERFACE_H__ 32 33 // System dependencies 34 #include <CameraMetadata.h> 35 #include <map> 36 #include <mutex> 37 #include <pthread.h> 38 #include <utils/KeyedVector.h> 39 #include <utils/List.h> 40 // Camera dependencies 41 #include "hardware/camera3.h" 42 #include "QCamera3Channel.h" 43 #include "QCamera3CropRegionMapper.h" 44 #include "QCamera3HALHeader.h" 45 #include "QCamera3Mem.h" 46 #include "QCameraPerf.h" 47 #include "QCameraCommon.h" 48 #include "QCamera3VendorTags.h" 49 #include "QCameraDualCamSettings.h" 50 51 #include "EaselManagerClient.h" 52 #include "HdrPlusClient.h" 53 54 extern "C" { 55 #include "mm_camera_interface.h" 56 #include "mm_jpeg_interface.h" 57 } 58 59 using ::android::hardware::camera::common::V1_0::helper::CameraMetadata; 60 using namespace android; 61 62 namespace qcamera { 63 64 #ifndef TRUE 65 #define TRUE 1 66 #endif 67 68 #ifndef FALSE 69 #define FALSE 0 70 #endif 71 72 /* Time related macros */ 73 typedef int64_t nsecs_t; 74 #define NSEC_PER_SEC 1000000000LLU 75 #define NSEC_PER_USEC 1000LLU 76 #define NSEC_PER_33MSEC 33000000LLU 77 78 /*Orchestrate Macros */ 79 #define EV_COMP_SETTLE_DELAY 2 80 #define GB_HDR_HALF_STEP_EV -6 81 #define GB_HDR_2X_STEP_EV 6 82 83 #define FRAME_REGISTER_LRU_SIZE 256 84 #define INTERNAL_FRAME_STARTING_NUMBER 800 85 #define EMPTY_FRAMEWORK_FRAME_NUMBER 0xFFFFFFFF 86 87 typedef enum { 88 SET_ENABLE, 89 SET_CONTROLENABLE, 90 SET_RELOAD_CHROMATIX, 91 SET_STATUS, 92 } optype_t; 93 94 #define MODULE_ALL 0 95 96 extern volatile uint32_t gCamHal3LogLevel; 97 98 class QCamera3MetadataChannel; 99 class QCamera3PicChannel; 100 class QCamera3HeapMemory; 101 class QCamera3Exif; 102 class ShutterDispatcher; 103 class BufferDispatcher; 104 105 typedef struct { 106 camera3_stream_t *stream; 107 camera3_stream_buffer_set_t buffer_set; 108 stream_status_t status; 109 int registered; 110 QCamera3ProcessingChannel *channel; 111 uint32_t id; // unique ID 112 } stream_info_t; 113 114 typedef struct { 115 // Stream handle 116 camera3_stream_t *stream; 117 // Buffer handle 118 buffer_handle_t *buffer; 119 // Buffer status 120 camera3_buffer_status_t bufStatus = CAMERA3_BUFFER_STATUS_OK; 121 } PendingBufferInfo; 122 123 typedef struct { 124 // Frame number corresponding to request 125 uint32_t frame_number; 126 // Time when request queued into system 127 nsecs_t timestamp; 128 nsecs_t av_timestamp; 129 List<PendingBufferInfo> mPendingBufferList; 130 bool hdrplus; 131 } PendingBuffersInRequest; 132 133 class PendingBuffersMap { 134 public: 135 // Number of outstanding buffers at flush 136 uint32_t numPendingBufsAtFlush; 137 // List of pending buffers per request 138 List<PendingBuffersInRequest> mPendingBuffersInRequest; 139 uint32_t get_num_overall_buffers(); 140 void removeBuf(buffer_handle_t *buffer); 141 int32_t getBufErrStatus(buffer_handle_t *buffer); 142 }; 143 144 class FrameNumberRegistry { 145 public: 146 147 FrameNumberRegistry(); 148 ~FrameNumberRegistry(); 149 int32_t allocStoreInternalFrameNumber(uint32_t frameworkFrameNumber, 150 uint32_t &internalFrameNumber); 151 int32_t generateStoreInternalFrameNumber(uint32_t &internalFrameNumber); 152 int32_t freeInternalFrameNumber(uint32_t internalFrameNumber); 153 int32_t getFrameworkFrameNumber(uint32_t internalFrameNumber, uint32_t &frameworkFrameNumber); 154 void purgeOldEntriesLocked(); 155 156 private: 157 std::map<uint32_t, uint32_t> _register; 158 uint32_t _nextFreeInternalNumber; 159 Mutex mRegistryLock; 160 }; 161 162 class QCamera3HardwareInterface; 163 164 /* 165 * ShutterDispatcher class dispatches shutter callbacks in order of the frame 166 * number. It will dispatch a shutter callback only after all shutter callbacks 167 * of previous frames were dispatched. 168 */ 169 class ShutterDispatcher { 170 public: 171 ShutterDispatcher(QCamera3HardwareInterface *parent); 172 virtual ~ShutterDispatcher() = default; 173 174 // Tell dispatch to expect a shutter for a frame number. 175 void expectShutter(uint32_t frameNumber, bool isReprocess); 176 // Mark a shutter callback for a frame ready. 177 void markShutterReady(uint32_t frameNumber, uint64_t timestamp); 178 // Discard a pending shutter for frame number. 179 void clear(uint32_t frameNumber); 180 // Discard all pending shutters. 181 void clear(); 182 183 private: 184 struct Shutter { 185 bool ready; // If the shutter is ready. 186 uint64_t timestamp; // Timestamp of the shutter. ShutterShutter187 Shutter() : ready(false), timestamp(0) {}; 188 }; 189 190 std::mutex mLock; 191 192 // frame number -> shutter map. Protected by mLock. 193 std::map<uint32_t, Shutter> mShutters; 194 std::map<uint32_t, Shutter> mReprocessShutters; 195 196 QCamera3HardwareInterface *mParent; 197 }; 198 199 /* 200 * BufferDispatcher class dispatches output buffers in a stream in order of the 201 * frame number. It will dispatch an output buffer in a stream only after all 202 * previous output buffers in the same stream were dispatched. 203 */ 204 class OutputBufferDispatcher { 205 public: 206 OutputBufferDispatcher(QCamera3HardwareInterface *parent); 207 virtual ~OutputBufferDispatcher() = default; 208 209 // Configure streams. 210 status_t configureStreams(camera3_stream_configuration_t *streamList); 211 // Tell dispatcher to expect a buffer for a stream for a frame number. 212 status_t expectBuffer(uint32_t frameNumber, camera3_stream_t *stream); 213 // Mark a buffer ready for a stream for a frame number. 214 void markBufferReady(uint32_t frameNumber, const camera3_stream_buffer_t &buffer); 215 // Discard all pending buffers. If clearConfiguredStreams is true, discard configured streams 216 // as well. 217 void clear(bool clearConfiguredStreams = true); 218 219 private: 220 struct Buffer { 221 bool ready; // If the buffer is ready. 222 camera3_stream_buffer_t buffer; BufferBuffer223 Buffer() : ready(false), buffer({}) {}; 224 }; 225 226 std::mutex mLock; 227 228 // A two-level map: stream -> (frame number -> buffer). Protected by mLock. 229 std::map<camera3_stream_t*, std::map<uint32_t, Buffer>> mStreamBuffers; 230 231 QCamera3HardwareInterface *mParent; 232 }; 233 234 class QCamera3HardwareInterface : public HdrPlusClientListener, 235 public EaselManagerClientListener { 236 public: 237 /* static variable and functions accessed by camera service */ 238 static camera3_device_ops_t mCameraOps; 239 //Id of each session in bundle/link 240 static uint32_t sessionId[MM_CAMERA_MAX_NUM_SENSORS]; 241 static int initialize(const struct camera3_device *, 242 const camera3_callback_ops_t *callback_ops); 243 static int configure_streams(const struct camera3_device *, 244 camera3_stream_configuration_t *stream_list); 245 static const camera_metadata_t* construct_default_request_settings( 246 const struct camera3_device *, int type); 247 static int process_capture_request(const struct camera3_device *, 248 camera3_capture_request_t *request); 249 250 static void dump(const struct camera3_device *, int fd); 251 static int flush(const struct camera3_device *); 252 static int close_camera_device(struct hw_device_t* device); 253 254 public: 255 QCamera3HardwareInterface(uint32_t cameraId, 256 const camera_module_callbacks_t *callbacks); 257 virtual ~QCamera3HardwareInterface(); 258 static void camEvtHandle(uint32_t camera_handle, mm_camera_event_t *evt, 259 void *user_data); 260 int openCamera(struct hw_device_t **hw_device); 261 camera_metadata_t* translateCapabilityToMetadata(int type); 262 263 typedef struct { 264 camera3_stream_t *stream; 265 bool need_metadata; 266 bool meteringOnly; 267 } InternalRequest; 268 269 static int getCamInfo(uint32_t cameraId, struct camera_info *info); 270 static cam_capability_t *getCapabilities(mm_camera_ops_t *ops, 271 uint32_t cam_handle); 272 static int initCapabilities(uint32_t cameraId); 273 static int initStaticMetadata(uint32_t cameraId); 274 static int initHdrPlusClientLocked(); 275 static void makeTable(cam_dimension_t *dimTable, size_t size, 276 size_t max_size, int32_t *sizeTable); 277 static void makeFPSTable(cam_fps_range_t *fpsTable, size_t size, 278 size_t max_size, int32_t *fpsRangesTable); 279 static void makeOverridesList(cam_scene_mode_overrides_t *overridesTable, 280 size_t size, size_t max_size, uint8_t *overridesList, 281 uint8_t *supported_indexes, uint32_t camera_id); 282 static size_t filterJpegSizes(int32_t *jpegSizes, int32_t *processedSizes, 283 size_t processedSizesCnt, size_t maxCount, cam_rect_t active_array_size, 284 uint8_t downscale_factor); 285 static void convertToRegions(cam_rect_t rect, int32_t* region, int weight); 286 static void convertFromRegions(cam_area_t &roi, const CameraMetadata &frame_settings, 287 uint32_t tag); 288 static bool resetIfNeededROI(cam_area_t* roi, const cam_crop_region_t* scalerCropRegion); 289 static int32_t getSensorSensitivity(int32_t iso_mode); 290 291 double computeNoiseModelEntryS(int32_t sensitivity); 292 double computeNoiseModelEntryO(int32_t sensitivity); 293 294 static void captureResultCb(mm_camera_super_buf_t *metadata, 295 camera3_stream_buffer_t *buffer, uint32_t frame_number, 296 bool isInputBuffer, void *userdata); 297 298 int initialize(const camera3_callback_ops_t *callback_ops); 299 int configureStreams(camera3_stream_configuration_t *stream_list); 300 int configureStreamsPerfLocked(camera3_stream_configuration_t *stream_list); 301 int processCaptureRequest(camera3_capture_request_t *request, 302 List<InternalRequest> &internalReqs); 303 int orchestrateRequest(camera3_capture_request_t *request); 304 void orchestrateResult(camera3_capture_result_t *result); 305 void orchestrateNotify(camera3_notify_msg_t *notify_msg); 306 307 void dump(int fd); 308 int flushPerf(); 309 310 int setFrameParameters(camera3_capture_request_t *request, 311 cam_stream_ID_t streamID, int blob_request, uint32_t snapshotStreamId); 312 int32_t setReprocParameters(camera3_capture_request_t *request, 313 metadata_buffer_t *reprocParam, uint32_t snapshotStreamId); 314 int translateToHalMetadata(const camera3_capture_request_t *request, 315 metadata_buffer_t *parm, uint32_t snapshotStreamId); 316 int translateFwkMetadataToHalMetadata(const camera_metadata_t *frameworkMetadata, 317 metadata_buffer_t *hal_metadata, uint32_t snapshotStreamId, int64_t minFrameDuration); 318 camera_metadata_t* translateCbUrgentMetadataToResultMetadata ( 319 metadata_buffer_t *metadata, bool lastUrgentMetadataInBatch, 320 uint32_t frame_number, bool isJumpstartMetadata); 321 camera_metadata_t* saveRequestSettings(const CameraMetadata& jpegMetadata, 322 camera3_capture_request_t *request); 323 int initParameters(); 324 void deinitParameters(); 325 QCamera3ReprocessChannel *addOfflineReprocChannel(const reprocess_config_t &config, 326 QCamera3ProcessingChannel *inputChHandle); 327 bool needRotationReprocess(); 328 bool needJpegExifRotation(); 329 bool needReprocess(cam_feature_mask_t postprocess_mask); 330 bool needJpegRotation(); 331 cam_denoise_process_type_t getWaveletDenoiseProcessPlate(); 332 cam_denoise_process_type_t getTemporalDenoiseProcessPlate(); 333 334 void captureResultCb(mm_camera_super_buf_t *metadata, 335 camera3_stream_buffer_t *buffer, uint32_t frame_number, 336 bool isInputBuffer); 337 cam_dimension_t calcMaxJpegDim(); 338 bool needOnlineRotation(); 339 uint32_t getJpegQuality(); 340 QCamera3Exif *getExifData(); 341 mm_jpeg_exif_params_t get3AExifParams(); 342 uint8_t getMobicatMask(); 343 static void getFlashInfo(const int cameraId, 344 bool& hasFlash, 345 char (&flashNode)[QCAMERA_MAX_FILEPATH_LENGTH]); 346 const char *getEepromVersionInfo(); 347 const uint32_t *getLdafCalib(); 348 const char *getEaselFwVersion(); 349 void get3AVersion(cam_q3a_version_t &swVersion); 350 static void setBufferErrorStatus(QCamera3Channel*, uint32_t frameNumber, 351 camera3_buffer_status_t err, void *userdata); 352 void setBufferErrorStatus(QCamera3Channel*, uint32_t frameNumber, 353 camera3_buffer_status_t err); 354 bool is60HzZone(); 355 356 // Get dual camera related info isDeviceLinked()357 bool isDeviceLinked() {return mIsDeviceLinked;} isMainCamera()358 bool isMainCamera() {return mIsMainCamera;} 359 uint32_t getSensorMountAngle(); 360 const cam_related_system_calibration_data_t *getRelatedCalibrationData(); 361 362 template <typename fwkType, typename halType> struct QCameraMap { 363 fwkType fwk_name; 364 halType hal_name; 365 }; 366 367 typedef struct { 368 const char *const desc; 369 cam_cds_mode_type_t val; 370 } QCameraPropMap; 371 372 private: 373 374 // State transition conditions: 375 // "\" means not applicable 376 // "x" means not valid 377 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 378 // | | CLOSED | OPENED | INITIALIZED | CONFIGURED | STARTED | ERROR | DEINIT | 379 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 380 // | CLOSED | \ | open | x | x | x | x | x | 381 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 382 // | OPENED | close | \ | initialize | x | x | error | x | 383 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 384 // |INITIALIZED | close | x | \ | configure | x | error | x | 385 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 386 // | CONFIGURED | close | x | x | configure | request | error | x | 387 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 388 // | STARTED | close | x | x | configure | \ | error | x | 389 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 390 // | ERROR | close | x | x | x | x | \ | any | 391 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 392 // | DEINIT | close | x | x | x | x | x | \ | 393 // +------------+----------+----------+-------------+------------+---------+-------+--------+ 394 395 typedef enum { 396 CLOSED, 397 OPENED, 398 INITIALIZED, 399 CONFIGURED, 400 STARTED, 401 ERROR, 402 DEINIT 403 } State; 404 405 int openCamera(); 406 int closeCamera(); 407 int flush(bool restartChannels, bool stopChannelImmediately = false); 408 static size_t calcMaxJpegSize(uint32_t camera_id); 409 cam_dimension_t getMaxRawSize(uint32_t camera_id); 410 static void addStreamConfig(Vector<int32_t> &available_stream_configs, 411 int32_t scalar_format, const cam_dimension_t &dim, 412 int32_t config_type); 413 414 int validateCaptureRequest(camera3_capture_request_t *request, 415 List<InternalRequest> &internallyRequestedStreams); 416 int validateStreamDimensions(camera3_stream_configuration_t *streamList); 417 int validateStreamRotations(camera3_stream_configuration_t *streamList); 418 int validateUsageFlags(const camera3_stream_configuration_t *streamList); 419 int validateUsageFlagsForEis(const camera3_stream_configuration_t *streamList); 420 void deriveMinFrameDuration(); 421 void handleBuffersDuringFlushLock(camera3_stream_buffer_t *buffer); 422 int64_t getMinFrameDuration(const camera3_capture_request_t *request); 423 void handleMetadataWithLock(mm_camera_super_buf_t *metadata_buf, 424 bool free_and_bufdone_meta_buf, 425 bool lastUrgentMetadataInBatch, 426 bool lastMetadataInBatch, 427 bool *p_is_metabuf_queued); 428 void handleBatchMetadata(mm_camera_super_buf_t *metadata_buf, 429 bool free_and_bufdone_meta_buf); 430 void handleBufferWithLock(camera3_stream_buffer_t *buffer, 431 uint32_t frame_number); 432 void handleInputBufferWithLock(uint32_t frame_number); 433 // Handle pending results when a new result metadata of a frame is received. 434 // metadata callbacks are invoked in the order of frame number. 435 void handlePendingResultMetadataWithLock(uint32_t frameNumber, 436 camera_metadata_t *resultMetadata); 437 // Going through pending request list and send out result metadata for requests 438 // that are ready. 439 // frameNumber is the lastest frame whose result metadata is ready. 440 // isLiveRequest is whether the frame belongs to a live request. 441 void dispatchResultMetadataWithLock(uint32_t frameNumber, bool isLiveRequest); 442 void handleDepthDataLocked(const cam_depth_data_t &depthData, 443 uint32_t frameNumber, uint8_t valid); 444 void notifyErrorFoPendingDepthData(QCamera3DepthChannel *depthCh); 445 void unblockRequestIfNecessary(); 446 void dumpMetadataToFile(tuning_params_t &meta, uint32_t &dumpFrameCount, 447 bool enabled, const char *type, uint32_t frameNumber); 448 static void getLogLevel(); 449 static int32_t getPDStatIndex(cam_capability_t *caps); 450 451 void cleanAndSortStreamInfo(); 452 void extractJpegMetadata(CameraMetadata& jpegMetadata, 453 const camera3_capture_request_t *request); 454 455 bool isSupportChannelNeeded(camera3_stream_configuration_t *streamList, 456 cam_stream_size_info_t stream_config_info); 457 bool isHdrSnapshotRequest(camera3_capture_request *request); 458 int32_t setMobicat(); 459 460 int32_t getSensorModeInfo(cam_sensor_mode_info_t &sensorModeInfo); 461 // Get information of the sensor mode that is currently selected. 462 int32_t getCurrentSensorModeInfo(cam_sensor_mode_info_t &sensorModeInfo); 463 int32_t setHalFpsRange(const CameraMetadata &settings, 464 metadata_buffer_t *hal_metadata); 465 int32_t extractSceneMode(const CameraMetadata &frame_settings, uint8_t metaMode, 466 metadata_buffer_t *hal_metadata); 467 int32_t setVideoHdrMode(metadata_buffer_t *hal_metadata, 468 cam_video_hdr_mode_t vhdr); 469 int32_t numOfSizesOnEncoder(const camera3_stream_configuration_t *streamList, 470 const cam_dimension_t &maxViewfinderSize); 471 472 void addToPPFeatureMask(int stream_format, uint32_t stream_idx); 473 void updateFpsInPreviewBuffer(metadata_buffer_t *metadata, uint32_t frame_number); 474 void updateTimeStampInPendingBuffers(uint32_t frameNumber, nsecs_t timestamp); 475 476 void enablePowerHint(); 477 void disablePowerHint(); 478 int32_t dynamicUpdateMetaStreamInfo(); 479 int32_t startAllChannels(); 480 int32_t stopAllChannels(); 481 int32_t notifyErrorForPendingRequests(); 482 void notifyError(uint32_t frameNumber, 483 camera3_error_msg_code_t errorCode); 484 int32_t getReprocessibleOutputStreamId(uint32_t &id); 485 int32_t handleCameraDeviceError(bool stopChannelImmediately = false); 486 487 bool isOnEncoder(const cam_dimension_t max_viewfinder_size, 488 uint32_t width, uint32_t height); 489 void hdrPlusPerfLock(mm_camera_super_buf_t *metadata_buf); 490 491 static bool supportBurstCapture(uint32_t cameraId); 492 int32_t setBundleInfo(); 493 int32_t setInstantAEC(const CameraMetadata &meta); 494 495 static void convertLandmarks(cam_face_landmarks_info_t face, int32_t* landmarks); 496 static void setInvalidLandmarks(int32_t* landmarks); 497 498 static void setPAAFSupport(cam_feature_mask_t& feature_mask, 499 cam_stream_type_t stream_type, 500 cam_color_filter_arrangement_t filter_arrangement); 501 int32_t setSensorHDR(metadata_buffer_t *hal_metadata, bool enable, 502 bool isVideoHdrEnable = false); 503 504 template <typename T> 505 static void adjustBlackLevelForCFA(T input[BLACK_LEVEL_PATTERN_CNT], 506 T output[BLACK_LEVEL_PATTERN_CNT], 507 cam_color_filter_arrangement_t color_arrangement); 508 509 int32_t startChannelLocked(); 510 void stopChannelLocked(bool stopChannelImmediately); 511 512 camera3_device_t mCameraDevice; 513 uint32_t mCameraId; 514 mm_camera_vtbl_t *mCameraHandle; 515 bool mCameraInitialized; 516 camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT]; 517 const camera3_callback_ops_t *mCallbackOps; 518 519 QCamera3MetadataChannel *mMetadataChannel; 520 QCamera3PicChannel *mPictureChannel; 521 QCamera3RawChannel *mRawChannel; 522 QCamera3SupportChannel *mSupportChannel; 523 QCamera3SupportChannel *mAnalysisChannel; 524 QCamera3RawDumpChannel *mRawDumpChannel; 525 QCamera3HdrPlusRawSrcChannel *mHdrPlusRawSrcChannel; 526 QCamera3RegularChannel *mDummyBatchChannel; 527 QCamera3DepthChannel *mDepthChannel; 528 cam_sensor_pd_data_t mDepthCloudMode; //Cache last configured mode 529 QCameraPerfLockMgr mPerfLockMgr; 530 531 uint32_t mChannelHandle; 532 533 void saveExifParams(metadata_buffer_t *metadata); 534 mm_jpeg_exif_params_t mExifParams; 535 536 //First request yet to be processed after configureStreams 537 bool mFirstConfiguration; 538 bool mFlush; 539 bool mFlushPerf; 540 bool mEnableRawDump; 541 bool mForceHdrSnapshot; 542 QCamera3HeapMemory *mParamHeap; 543 metadata_buffer_t* mParameters; 544 metadata_buffer_t* mPrevParameters; 545 CameraMetadata mCurJpegMeta; 546 bool m_bIsVideo; 547 bool m_bIs4KVideo; 548 bool m_bEisSupportedSize; 549 bool m_bEisEnable; 550 bool m_bEis3PropertyEnabled; 551 bool m_bEisSupported; 552 bool m_bAVTimerEnabled; 553 typedef struct { 554 cam_dimension_t dim; 555 int format; 556 uint32_t usage; 557 } InputStreamInfo; 558 559 InputStreamInfo mInputStreamInfo; 560 uint8_t m_MobicatMask; 561 uint8_t m_bTnrEnabled; 562 int8_t mSupportedFaceDetectMode; 563 uint8_t m_bTnrPreview; 564 uint8_t m_bSwTnrPreview; 565 uint8_t m_bTnrVideo; 566 uint8_t m_debug_avtimer; 567 uint8_t m_bVideoHdrEnabled; 568 uint8_t m_cacModeDisabled; 569 uint8_t m_bForceInfinityAf; 570 571 /* Data structure to store pending request */ 572 typedef struct { 573 camera3_stream_t *stream; 574 camera3_stream_buffer_t *buffer; 575 // metadata needs to be consumed by the corresponding stream 576 // in order to generate the buffer. 577 bool need_metadata; 578 } RequestedBufferInfo; 579 580 typedef struct { 581 uint32_t frame_number; 582 uint32_t num_buffers; 583 int32_t request_id; 584 List<RequestedBufferInfo> buffers; 585 List<InternalRequest> internalRequestList; 586 int blob_request; 587 uint8_t bUseFirstPartial; // Use first available partial result in case of jumpstart. 588 nsecs_t timestamp; 589 nsecs_t expectedFrameDuration; 590 camera3_stream_buffer_t *input_buffer; 591 const camera_metadata_t *settings; 592 const camera_metadata_t *resultMetadata; // Result metadata for this request. 593 CameraMetadata jpegMetadata; 594 uint8_t pipeline_depth; 595 uint32_t partial_result_cnt; 596 uint8_t capture_intent; 597 uint8_t fwkCacMode; 598 uint8_t hybrid_ae_enable; 599 /* DevCamDebug metadata PendingRequestInfo */ 600 uint8_t DevCamDebug_meta_enable; 601 /* DevCamDebug metadata end */ 602 603 bool focusStateSent = false; 604 bool focusStateValid = false; 605 uint8_t focusState = ANDROID_CONTROL_AF_STATE_INACTIVE; 606 607 bool enableZsl; // If ZSL is enabled. 608 bool hdrplus; // If this is an HDR+ request. 609 uint8_t requestedLensShadingMapMode; // Lens shading map mode for this request. 610 uint8_t requestedFaceDetectMode; // Face detect mode for this request. 611 bool partialResultDropped; // Whether partial metadata is dropped. 612 } PendingRequestInfo; 613 typedef struct { 614 uint32_t frame_number; 615 uint32_t stream_ID; 616 } PendingFrameDropInfo; 617 618 class FrameNumberRegistry _orchestrationDb; 619 typedef KeyedVector<uint32_t, Vector<PendingBufferInfo> > FlushMap; 620 typedef List<QCamera3HardwareInterface::PendingRequestInfo>::iterator 621 pendingRequestIterator; 622 typedef List<QCamera3HardwareInterface::RequestedBufferInfo>::iterator 623 pendingBufferIterator; 624 625 List<PendingRequestInfo> mPendingRequestsList; 626 List<PendingFrameDropInfo> mPendingFrameDropList; 627 /* Use last frame number of the batch as key and first frame number of the 628 * batch as value for that key */ 629 KeyedVector<uint32_t, uint32_t> mPendingBatchMap; 630 cam_stream_ID_t mBatchedStreamsArray; 631 632 PendingBuffersMap mPendingBuffersMap; 633 pthread_cond_t mRequestCond; 634 uint32_t mPendingLiveRequest; 635 bool mWokenUpByDaemon; 636 int32_t mCurrentRequestId; 637 cam_stream_size_info_t mStreamConfigInfo; 638 639 ShutterDispatcher mShutterDispatcher; 640 OutputBufferDispatcher mOutputBufferDispatcher; 641 642 //mutex for serialized access to camera3_device_ops_t functions 643 pthread_mutex_t mMutex; 644 645 //condition used to signal flush after buffers have returned 646 pthread_cond_t mBuffersCond; 647 648 List<stream_info_t*> mStreamInfo; 649 650 int64_t mMinProcessedFrameDuration; 651 int64_t mMinJpegFrameDuration; 652 int64_t mMinRawFrameDuration; 653 nsecs_t mExpectedFrameDuration; 654 nsecs_t mExpectedInflightDuration; 655 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms 656 657 uint32_t mMetaFrameCount; 658 bool mUpdateDebugLevel; 659 const camera_module_callbacks_t *mCallbacks; 660 661 uint8_t mCaptureIntent; 662 uint8_t mCacMode; 663 // DevCamDebug metadata internal variable 664 uint8_t mDevCamDebugMetaEnable; 665 /* DevCamDebug metadata end */ 666 667 metadata_buffer_t mReprocMeta; //scratch meta buffer 668 /* 0: Not batch, non-zero: Number of image buffers in a batch */ 669 uint8_t mBatchSize; 670 // Used only in batch mode 671 uint8_t mToBeQueuedVidBufs; 672 // Fixed video fps 673 float mHFRVideoFps; 674 public: 675 uint32_t mOpMode; 676 bool mStreamConfig; 677 QCameraCommon mCommon; 678 private: 679 uint32_t mFirstFrameNumberInBatch; 680 camera3_stream_t mDummyBatchStream; 681 bool mNeedSensorRestart; 682 bool mPreviewStarted; 683 uint32_t mMinInFlightRequests; 684 uint32_t mMaxInFlightRequests; 685 bool mPDSupported; 686 int32_t mPDIndex; 687 // Param to trigger instant AEC. 688 bool mInstantAEC; 689 // Param to know when to reset AEC 690 bool mResetInstantAEC; 691 // Frame number, untill which we need to drop the frames. 692 uint32_t mInstantAECSettledFrameNumber; 693 // Max number of frames, that HAL will hold without displaying, for instant AEC mode. 694 uint8_t mAecSkipDisplayFrameBound; 695 // Counter to keep track of number of frames that took for AEC convergence. 696 uint8_t mInstantAecFrameIdxCount; 697 /* sensor output size with current stream configuration */ 698 QCamera3CropRegionMapper mCropRegionMapper; 699 // Last lens shading map mode framework requsted. 700 uint8_t mLastRequestedLensShadingMapMode; 701 // Last face detect mode framework requsted. 702 uint8_t mLastRequestedFaceDetectMode; 703 704 cam_feature_mask_t mCurrFeatureState; 705 /* Ldaf calibration data */ 706 bool mLdafCalibExist; 707 uint32_t mLdafCalib[2]; 708 int32_t mLastCustIntentFrmNum; 709 // Easel firmware version 710 char mEaselFwVersion[FW_VER_SIZE]; 711 bool mEaselFwUpdated; 712 static const QCameraMap<camera_metadata_enum_android_control_effect_mode_t, 713 cam_effect_mode_type> EFFECT_MODES_MAP[]; 714 static const QCameraMap<camera_metadata_enum_android_control_awb_mode_t, 715 cam_wb_mode_type> WHITE_BALANCE_MODES_MAP[]; 716 static const QCameraMap<camera_metadata_enum_android_control_scene_mode_t, 717 cam_scene_mode_type> SCENE_MODES_MAP[]; 718 static const QCameraMap<camera_metadata_enum_android_control_af_mode_t, 719 cam_focus_mode_type> FOCUS_MODES_MAP[]; 720 static const QCameraMap<camera_metadata_enum_android_color_correction_aberration_mode_t, 721 cam_aberration_mode_t> COLOR_ABERRATION_MAP[]; 722 static const QCameraMap<camera_metadata_enum_android_control_ae_antibanding_mode_t, 723 cam_antibanding_mode_type> ANTIBANDING_MODES_MAP[]; 724 static const QCameraMap<camera_metadata_enum_android_lens_state_t, 725 cam_af_lens_state_t> LENS_STATE_MAP[]; 726 static const QCameraMap<camera_metadata_enum_android_control_ae_mode_t, 727 cam_flash_mode_t> AE_FLASH_MODE_MAP[]; 728 static const QCameraMap<camera_metadata_enum_android_flash_mode_t, 729 cam_flash_mode_t> FLASH_MODES_MAP[]; 730 static const QCameraMap<camera_metadata_enum_android_statistics_face_detect_mode_t, 731 cam_face_detect_mode_t> FACEDETECT_MODES_MAP[]; 732 static const QCameraMap<camera_metadata_enum_android_lens_info_focus_distance_calibration_t, 733 cam_focus_calibration_t> FOCUS_CALIBRATION_MAP[]; 734 static const QCameraMap<camera_metadata_enum_android_sensor_test_pattern_mode_t, 735 cam_test_pattern_mode_t> TEST_PATTERN_MAP[]; 736 static const QCameraMap<camera_metadata_enum_android_video_hdr_mode_t, 737 cam_video_hdr_mode_t> VIDEO_HDR_MODES_MAP[]; 738 static const QCameraMap<camera_metadata_enum_android_sensor_reference_illuminant1_t, 739 cam_illuminat_t> REFERENCE_ILLUMINANT_MAP[]; 740 static const QCameraMap<int32_t, 741 cam_hfr_mode_t> HFR_MODE_MAP[]; 742 static const QCameraMap<camera_metadata_enum_android_ir_mode_t, 743 cam_ir_mode_type_t> IR_MODES_MAP[]; 744 static const QCameraMap<qcamera3_ext_instant_aec_mode_t, 745 cam_aec_convergence_type> INSTANT_AEC_MODES_MAP[]; 746 static const QCameraMap<camera_metadata_enum_android_binning_correction_mode_t, 747 cam_binning_correction_mode_t> BINNING_CORRECTION_MODES_MAP[]; 748 static const QCameraMap<qcamera3_ext_exposure_meter_mode_t, 749 cam_auto_exposure_mode_type> AEC_MODES_MAP[]; 750 static const QCameraMap<qcamera3_ext_iso_mode_t, 751 cam_iso_mode_type> ISO_MODES_MAP[]; 752 static const QCameraPropMap CDS_MAP[]; 753 754 pendingRequestIterator erasePendingRequest(pendingRequestIterator i); 755 756 // Remove unrequested metadata due to Easel HDR+. 757 void removeUnrequestedMetadata(pendingRequestIterator requestIter, 758 camera_metadata_t *resultMetadata); 759 760 //GPU library to read buffer padding details. 761 void *lib_surface_utils; 762 int (*LINK_get_surface_pixel_alignment)(); 763 uint32_t mSurfaceStridePadding; 764 765 bool mFirstMetadataCallback; 766 void sendPartialMetadataWithLock(metadata_buffer_t *metadata, 767 const pendingRequestIterator requestIter, 768 bool lastUrgentMetadataInBatch, bool isJumpstartMetadata); 769 770 camera_metadata_t* translateFromHalMetadata(metadata_buffer_t *metadata, 771 const PendingRequestInfo& pendingRequest, 772 /* DevCamDebug metadata end */ 773 bool pprocDone, 774 bool lastMetadataInBatch, 775 const bool *enableZsl); 776 777 State mState; 778 //Dual camera related params 779 bool mIsDeviceLinked; 780 bool mIsMainCamera; 781 uint8_t mLinkedCameraId; 782 QCamera3HeapMemory *m_pDualCamCmdHeap; 783 cam_dual_camera_cmd_info_t *m_pDualCamCmdPtr; 784 cam_sync_related_sensors_event_info_t m_relCamSyncInfo; 785 Mutex mFlushLock; 786 bool m60HzZone; 787 788 // Issue an additional RAW for every 10 requests to control RAW capture rate. Requesting RAW 789 // too often will cause frame drops due to latency of sending RAW to HDR+ service. 790 const static uint32_t kHdrPlusRawPeriod = 10; 791 792 // Define a pending HDR+ request submitted to HDR+ service and not yet received by HAL. 793 struct HdrPlusPendingRequest { 794 // HDR+ stream ID -> output buffer to be filled by HDR+ client with an HDR+ processed frame. 795 std::map<uint32_t, std::shared_ptr<mm_camera_buf_def_t>> outputBuffers; 796 797 // HDR+ stream ID -> output buffers in camera framework's request. 798 std::map<uint32_t, camera3_stream_buffer_t> frameworkOutputBuffers; 799 800 // Settings in camera framework's request. 801 std::shared_ptr<metadata_buffer_t> settings; 802 }; 803 804 // Fill pbcamera::StreamConfiguration based on the channel stream. 805 status_t fillPbStreamConfig(pbcamera::StreamConfiguration *config, uint32_t pbStreamId, 806 QCamera3Channel *channel, uint32_t streamIndex); 807 808 // Open HDR+ client asynchronously. 809 status_t openHdrPlusClientAsyncLocked(); 810 811 // Enable HDR+ mode. Easel will start capturing ZSL buffers. 812 status_t enableHdrPlusModeLocked(); 813 814 // Disable HDR+ mode. Easel will stop capturing ZSL buffers. 815 void disableHdrPlusModeLocked(); 816 817 // Return if current session with configured streams is compatible with HDR+ mode. 818 bool isSessionHdrPlusModeCompatible(); 819 820 // Return if the request is compatible with HDR+. 821 bool isRequestHdrPlusCompatible( 822 const camera3_capture_request_t &request, const CameraMetadata &metadata); 823 824 // Configure streams for HDR+. 825 status_t configureHdrPlusStreamsLocked(); 826 827 // Try to submit an HDR+ request. Returning true if an HDR+ request was submitted. Returning 828 // false if it is not an HDR+ request or submitting an HDR+ request failed. Must be called with 829 // gHdrPlusClientLock held. 830 bool trySubmittingHdrPlusRequestLocked(HdrPlusPendingRequest *hdrPlusRequest, 831 const camera3_capture_request_t &request, const CameraMetadata &metadata); 832 833 // Abort an HDR+ request that was not submitted successfully in 834 // trySubmittingHdrPlusRequestLocked. 835 void abortPendingHdrplusRequest(HdrPlusPendingRequest *hdrPlusRequest); 836 837 // Update HDR+ result metadata with the still capture's request settings. 838 void updateHdrPlusResultMetadata(CameraMetadata &resultMetadata, 839 std::shared_ptr<metadata_buffer_t> settings); 840 841 // Wait until opening HDR+ client completes if it's being opened. 842 void finishHdrPlusClientOpeningLocked(std::unique_lock<std::mutex> &lock); 843 844 // Handle Easel error asynchronuously in another thread. 845 void handleEaselFatalErrorAsync(); 846 847 // Handle Easel error. 848 void handleEaselFatalError(); 849 850 // Easel manager client callbacks. 851 void onEaselFatalError(std::string errMsg); 852 853 // HDR+ client callbacks. 854 void onOpened(std::unique_ptr<HdrPlusClient> client) override; 855 void onOpenFailed(status_t err) override; 856 void onFatalError() override; 857 void onCaptureResult(pbcamera::CaptureResult *result, 858 const camera_metadata_t &resultMetadata) override; 859 void onFailedCaptureResult(pbcamera::CaptureResult *failedResult) override; 860 void onShutter(uint32_t requestId, int64_t apSensorTimestampNs) override; 861 void onNextCaptureReady(uint32_t requestId) override; 862 void onPostview(uint32_t requestId, std::unique_ptr<std::vector<uint8_t>> postview, 863 uint32_t width, uint32_t height, uint32_t stride, int32_t format) override; 864 865 nsecs_t calculateMaxExpectedDuration(const camera_metadata_t *request); 866 void getExpectedFrameDuration(const camera_metadata_t *request, nsecs_t *frameDuration); 867 868 // Map from frame number to frame. Must be protected by mHdrPlusPendingRequestsLock. 869 std::map<uint32_t, HdrPlusPendingRequest> mHdrPlusPendingRequests; 870 Mutex mHdrPlusPendingRequestsLock; 871 872 // If HDR+ mode is enabled i.e. if Easel is capturing ZSL buffers. 873 bool mHdrPlusModeEnabled; 874 875 // If ZSL is enabled (android.control.enableZsl). 876 bool mZslEnabled; 877 878 // If Easel MIPI has been started. 879 bool mEaselMipiStarted; 880 881 // If HAL provides RAW input buffers to Easel. This is just for prototyping. 882 bool mIsApInputUsedForHdrPlus; 883 884 // Current sensor mode information. 885 cam_sensor_mode_info_t mSensorModeInfo; 886 887 // If there is a capture request with preview intent since stream configuration. 888 bool mFirstPreviewIntentSeen; 889 890 bool m_bSensorHDREnabled; 891 892 cam_trigger_t mAfTrigger; 893 894 int32_t mSceneDistance; 895 896 std::future<void> mEaselErrorFuture; 897 }; 898 899 }; // namespace qcamera 900 901 #endif /* __QCAMERA2HARDWAREINTERFACE_H__ */ 902