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 __QCAMERA2HARDWAREINTERFACE_H__ 31 #define __QCAMERA2HARDWAREINTERFACE_H__ 32 33 // System dependencies 34 #include <utils/Mutex.h> 35 #include <utils/Condition.h> 36 37 // Camera dependencies 38 #include "camera.h" 39 #include "QCameraAllocator.h" 40 #include "QCameraChannel.h" 41 #include "QCameraCmdThread.h" 42 #include "QCameraDisplay.h" 43 #include "QCameraMem.h" 44 #include "QCameraParameters.h" 45 #include "QCameraParametersIntf.h" 46 #include "QCameraPerf.h" 47 #include "QCameraPostProc.h" 48 #include "QCameraQueue.h" 49 #include "QCameraStream.h" 50 #include "QCameraStateMachine.h" 51 #include "QCameraThermalAdapter.h" 52 53 #ifdef TARGET_TS_MAKEUP 54 #include "ts_makeup_engine.h" 55 #include "ts_detectface_engine.h" 56 #endif 57 extern "C" { 58 #include "mm_camera_interface.h" 59 #include "mm_jpeg_interface.h" 60 } 61 62 #include "QCameraTrace.h" 63 64 namespace qcamera { 65 66 #ifndef TRUE 67 #define TRUE 1 68 #endif 69 70 #ifndef FALSE 71 #define FALSE 0 72 #endif 73 74 typedef enum { 75 QCAMERA_CH_TYPE_ZSL, 76 QCAMERA_CH_TYPE_CAPTURE, 77 QCAMERA_CH_TYPE_PREVIEW, 78 QCAMERA_CH_TYPE_VIDEO, 79 QCAMERA_CH_TYPE_SNAPSHOT, 80 QCAMERA_CH_TYPE_RAW, 81 QCAMERA_CH_TYPE_METADATA, 82 QCAMERA_CH_TYPE_ANALYSIS, 83 QCAMERA_CH_TYPE_CALLBACK, 84 QCAMERA_CH_TYPE_REPROCESSING, 85 QCAMERA_CH_TYPE_MAX 86 } qcamera_ch_type_enum_t; 87 88 typedef struct { 89 int32_t msg_type; 90 int32_t ext1; 91 int32_t ext2; 92 } qcamera_evt_argm_t; 93 94 #define QCAMERA_DUMP_FRM_PREVIEW 1 95 #define QCAMERA_DUMP_FRM_VIDEO (1<<1) 96 #define QCAMERA_DUMP_FRM_INPUT_JPEG (1<<2) 97 #define QCAMERA_DUMP_FRM_THUMBNAIL (1<<3) 98 #define QCAMERA_DUMP_FRM_RAW (1<<4) 99 #define QCAMERA_DUMP_FRM_OUTPUT_JPEG (1<<5) 100 #define QCAMERA_DUMP_FRM_INPUT_REPROCESS (1<<6) 101 102 #define QCAMERA_DUMP_FRM_MASK_ALL 0x000000ff 103 104 #define QCAMERA_ION_USE_CACHE true 105 #define QCAMERA_ION_USE_NOCACHE false 106 #define MAX_ONGOING_JOBS 25 107 108 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 109 110 #define EXIF_ASCII_PREFIX_SIZE 8 //(sizeof(ExifAsciiPrefix)) 111 112 typedef enum { 113 QCAMERA_NOTIFY_CALLBACK, 114 QCAMERA_DATA_CALLBACK, 115 QCAMERA_DATA_TIMESTAMP_CALLBACK, 116 QCAMERA_DATA_SNAPSHOT_CALLBACK 117 } qcamera_callback_type_m; 118 119 typedef void (*camera_release_callback)(void *user_data, 120 void *cookie, 121 int32_t cb_status); 122 typedef void (*jpeg_data_callback)(int32_t msg_type, 123 const camera_memory_t *data, unsigned int index, 124 camera_frame_metadata_t *metadata, void *user, 125 uint32_t frame_idx, camera_release_callback release_cb, 126 void *release_cookie, void *release_data); 127 128 typedef struct { 129 qcamera_callback_type_m cb_type; // event type 130 int32_t msg_type; // msg type 131 int32_t ext1; // extended parameter 132 int32_t ext2; // extended parameter 133 camera_memory_t * data; // ptr to data memory struct 134 unsigned int index; // index of the buf in the whole buffer 135 int64_t timestamp; // buffer timestamp 136 camera_frame_metadata_t *metadata; // meta data 137 void *user_data; // any data needs to be released after callback 138 void *cookie; // release callback cookie 139 camera_release_callback release_cb; // release callback 140 uint32_t frame_index; // frame index for the buffer 141 } qcamera_callback_argm_t; 142 143 class QCameraCbNotifier { 144 public: 145 QCameraCbNotifier(QCamera2HardwareInterface *parent) : 146 mNotifyCb (NULL), 147 mDataCb (NULL), 148 mDataCbTimestamp (NULL), 149 mCallbackCookie (NULL), 150 mJpegCb(NULL), 151 mJpegCallbackCookie(NULL), 152 mParent (parent), 153 mDataQ(releaseNotifications, this), 154 mActive(false){} 155 156 virtual ~QCameraCbNotifier(); 157 158 virtual int32_t notifyCallback(qcamera_callback_argm_t &cbArgs); 159 virtual void setCallbacks(camera_notify_callback notifyCb, 160 camera_data_callback dataCb, 161 camera_data_timestamp_callback dataCbTimestamp, 162 void *callbackCookie); 163 virtual void setJpegCallBacks( 164 jpeg_data_callback jpegCb, void *callbackCookie); 165 virtual int32_t startSnapshots(); 166 virtual void stopSnapshots(); 167 virtual void exit(); 168 static void * cbNotifyRoutine(void * data); 169 static void releaseNotifications(void *data, void *user_data); 170 static bool matchSnapshotNotifications(void *data, void *user_data); 171 static bool matchPreviewNotifications(void *data, void *user_data); 172 static bool matchTimestampNotifications(void *data, void *user_data); 173 virtual int32_t flushPreviewNotifications(); 174 virtual int32_t flushVideoNotifications(); 175 private: 176 177 camera_notify_callback mNotifyCb; 178 camera_data_callback mDataCb; 179 camera_data_timestamp_callback mDataCbTimestamp; 180 void *mCallbackCookie; 181 jpeg_data_callback mJpegCb; 182 void *mJpegCallbackCookie; 183 QCamera2HardwareInterface *mParent; 184 185 QCameraQueue mDataQ; 186 QCameraCmdThread mProcTh; 187 bool mActive; 188 }; 189 class QCamera2HardwareInterface : public QCameraAllocator, 190 public QCameraThermalCallback, public QCameraAdjustFPS 191 { 192 public: 193 /* static variable and functions accessed by camera service */ 194 static camera_device_ops_t mCameraOps; 195 196 static int set_preview_window(struct camera_device *, 197 struct preview_stream_ops *window); 198 static void set_CallBacks(struct camera_device *, 199 camera_notify_callback notify_cb, 200 camera_data_callback data_cb, 201 camera_data_timestamp_callback data_cb_timestamp, 202 camera_request_memory get_memory, 203 void *user); 204 static void enable_msg_type(struct camera_device *, int32_t msg_type); 205 static void disable_msg_type(struct camera_device *, int32_t msg_type); 206 static int msg_type_enabled(struct camera_device *, int32_t msg_type); 207 static int start_preview(struct camera_device *); 208 static void stop_preview(struct camera_device *); 209 static int preview_enabled(struct camera_device *); 210 static int store_meta_data_in_buffers(struct camera_device *, int enable); 211 static int restart_start_preview(struct camera_device *); 212 static int restart_stop_preview(struct camera_device *); 213 static int pre_start_recording(struct camera_device *); 214 static int start_recording(struct camera_device *); 215 static void stop_recording(struct camera_device *); 216 static int recording_enabled(struct camera_device *); 217 static void release_recording_frame(struct camera_device *, const void *opaque); 218 static int auto_focus(struct camera_device *); 219 static int cancel_auto_focus(struct camera_device *); 220 static int pre_take_picture(struct camera_device *); 221 static int take_picture(struct camera_device *); 222 int takeLiveSnapshot_internal(); 223 int cancelLiveSnapshot_internal(); 224 int takeBackendPic_internal(bool *JpegMemOpt, char *raw_format); 225 void clearIntPendingEvents(); 226 void checkIntPicPending(bool JpegMemOpt, char *raw_format); 227 static int cancel_picture(struct camera_device *); 228 static int set_parameters(struct camera_device *, const char *parms); 229 static int stop_after_set_params(struct camera_device *); 230 static int commit_params(struct camera_device *); 231 static int restart_after_set_params(struct camera_device *); 232 static char* get_parameters(struct camera_device *); 233 static void put_parameters(struct camera_device *, char *); 234 static int send_command(struct camera_device *, 235 int32_t cmd, int32_t arg1, int32_t arg2); 236 static int send_command_restart(struct camera_device *, 237 int32_t cmd, int32_t arg1, int32_t arg2); 238 static void release(struct camera_device *); 239 static int dump(struct camera_device *, int fd); 240 static int close_camera_device(hw_device_t *); 241 242 static int register_face_image(struct camera_device *, 243 void *img_ptr, 244 cam_pp_offline_src_config_t *config); 245 static int prepare_preview(struct camera_device *); 246 static int prepare_snapshot(struct camera_device *device); 247 248 public: 249 QCamera2HardwareInterface(uint32_t cameraId); 250 virtual ~QCamera2HardwareInterface(); 251 int openCamera(struct hw_device_t **hw_device); 252 253 // Dual camera specific oprations 254 int bundleRelatedCameras(bool syncOn, 255 uint32_t related_sensor_session_id); 256 int getCameraSessionId(uint32_t* session_id); 257 const cam_sync_related_sensors_event_info_t* getRelatedCamSyncInfo( 258 void); 259 int32_t setRelatedCamSyncInfo( 260 cam_sync_related_sensors_event_info_t* info); 261 bool isFrameSyncEnabled(void); 262 int32_t setFrameSyncEnabled(bool enable); 263 int32_t setMpoComposition(bool enable); 264 bool getMpoComposition(void); 265 bool getRecordingHintValue(void); 266 int32_t setRecordingHintValue(int32_t value); 267 bool isPreviewRestartNeeded(void) { return mPreviewRestartNeeded; }; 268 static int getCapabilities(uint32_t cameraId, 269 struct camera_info *info, cam_sync_type_t *cam_type); 270 static int initCapabilities(uint32_t cameraId, mm_camera_vtbl_t *cameraHandle); 271 static cam_capability_t *getCapabilities(mm_camera_ops_t *ops, 272 uint32_t cam_handle); 273 cam_capability_t *getCamHalCapabilities(); 274 275 // Implementation of QCameraAllocator 276 virtual QCameraMemory *allocateStreamBuf(cam_stream_type_t stream_type, 277 size_t size, int stride, int scanline, uint8_t &bufferCnt); 278 virtual int32_t allocateMoreStreamBuf(QCameraMemory *mem_obj, 279 size_t size, uint8_t &bufferCnt); 280 virtual QCameraHeapMemory *allocateStreamInfoBuf( 281 cam_stream_type_t stream_type, uint8_t bufCount = 1); 282 virtual QCameraHeapMemory *allocateMiscBuf(cam_stream_info_t *streamInfo); 283 virtual QCameraMemory *allocateStreamUserBuf(cam_stream_info_t *streamInfo); 284 virtual void waitForDeferredAlloc(cam_stream_type_t stream_type); 285 286 // Implementation of QCameraThermalCallback 287 virtual int thermalEvtHandle(qcamera_thermal_level_enum_t *level, 288 void *userdata, void *data); 289 290 virtual int recalcFPSRange(int &minFPS, int &maxFPS, 291 const float &minVideoFPS, const float &maxVideoFPS, 292 cam_fps_range_t &adjustedRange); 293 294 friend class QCameraStateMachine; 295 friend class QCameraPostProcessor; 296 friend class QCameraCbNotifier; 297 friend class QCameraMuxer; 298 299 int32_t initStreamInfoBuf(cam_stream_type_t stream_type, 300 cam_stream_info_t *streamInfo); 301 void setJpegCallBacks(jpeg_data_callback jpegCb, 302 void *callbackCookie); 303 int32_t initJpegHandle(); 304 int32_t deinitJpegHandle(); 305 int32_t setJpegHandleInfo(mm_jpeg_ops_t *ops, 306 mm_jpeg_mpo_ops_t *mpo_ops, uint32_t pJpegClientHandle); 307 int32_t getJpegHandleInfo(mm_jpeg_ops_t *ops, 308 mm_jpeg_mpo_ops_t *mpo_ops, uint32_t *pJpegClientHandle); 309 uint32_t getCameraId() { return mCameraId; }; 310 bool bLiveSnapshot; 311 private: 312 int setPreviewWindow(struct preview_stream_ops *window); 313 int setCallBacks( 314 camera_notify_callback notify_cb, 315 camera_data_callback data_cb, 316 camera_data_timestamp_callback data_cb_timestamp, 317 camera_request_memory get_memory, 318 void *user); 319 int enableMsgType(int32_t msg_type); 320 int disableMsgType(int32_t msg_type); 321 int msgTypeEnabled(int32_t msg_type); 322 int msgTypeEnabledWithLock(int32_t msg_type); 323 int startPreview(); 324 int stopPreview(); 325 int storeMetaDataInBuffers(int enable); 326 int preStartRecording(); 327 int startRecording(); 328 int stopRecording(); 329 int releaseRecordingFrame(const void *opaque); 330 int autoFocus(); 331 int cancelAutoFocus(); 332 int preTakePicture(); 333 int takePicture(); 334 int stopCaptureChannel(bool destroy); 335 int cancelPicture(); 336 int takeLiveSnapshot(); 337 int takePictureInternal(); 338 int cancelLiveSnapshot(); 339 char* getParameters() {return mParameters.getParameters(); } 340 int putParameters(char *); 341 int sendCommand(int32_t cmd, int32_t &arg1, int32_t &arg2); 342 int release(); 343 int dump(int fd); 344 int registerFaceImage(void *img_ptr, 345 cam_pp_offline_src_config_t *config, 346 int32_t &faceID); 347 int32_t longShot(); 348 349 uint32_t deferPPInit(); 350 int openCamera(); 351 int closeCamera(); 352 353 int processAPI(qcamera_sm_evt_enum_t api, void *api_payload); 354 int processEvt(qcamera_sm_evt_enum_t evt, void *evt_payload); 355 int processSyncEvt(qcamera_sm_evt_enum_t evt, void *evt_payload); 356 void lockAPI(); 357 void waitAPIResult(qcamera_sm_evt_enum_t api_evt, qcamera_api_result_t *apiResult); 358 void unlockAPI(); 359 void signalAPIResult(qcamera_api_result_t *result); 360 void signalEvtResult(qcamera_api_result_t *result); 361 362 int calcThermalLevel(qcamera_thermal_level_enum_t level, 363 const int minFPSi, const int maxFPSi, 364 const float &minVideoFPS, const float &maxVideoFPS, 365 cam_fps_range_t &adjustedRange, 366 enum msm_vfe_frame_skip_pattern &skipPattern); 367 int updateThermalLevel(void *level); 368 369 // update entris to set parameters and check if restart is needed 370 int updateParameters(const char *parms, bool &needRestart); 371 // send request to server to set parameters 372 int commitParameterChanges(); 373 374 bool isCaptureShutterEnabled(); 375 bool needDebugFps(); 376 bool isRegularCapture(); 377 bool needOfflineReprocessing(); 378 bool isCACEnabled(); 379 bool is4k2kResolution(cam_dimension_t* resolution); 380 bool isPreviewRestartEnabled(); 381 bool needReprocess(); 382 bool needRotationReprocess(); 383 void debugShowVideoFPS(); 384 void debugShowPreviewFPS(); 385 void dumpJpegToFile(const void *data, size_t size, uint32_t index); 386 void dumpFrameToFile(QCameraStream *stream, 387 mm_camera_buf_def_t *frame, uint32_t dump_type, const char *misc = NULL); 388 void dumpMetadataToFile(QCameraStream *stream, 389 mm_camera_buf_def_t *frame,char *type); 390 void releaseSuperBuf(mm_camera_super_buf_t *super_buf); 391 void playShutter(); 392 void getThumbnailSize(cam_dimension_t &dim); 393 uint32_t getJpegQuality(); 394 QCameraExif *getExifData(); 395 cam_sensor_t getSensorType(); 396 bool isLowPowerMode(); 397 nsecs_t getBootToMonoTimeOffset(); 398 399 int32_t processAutoFocusEvent(cam_auto_focus_data_t &focus_data); 400 int32_t processZoomEvent(cam_crop_data_t &crop_info); 401 int32_t processPrepSnapshotDoneEvent(cam_prep_snapshot_state_t prep_snapshot_state); 402 int32_t processASDUpdate(cam_asd_decision_t asd_decision); 403 int32_t processJpegNotify(qcamera_jpeg_evt_payload_t *jpeg_job); 404 int32_t processHDRData(cam_asd_hdr_scene_data_t hdr_scene); 405 int32_t processRetroAECUnlock(); 406 int32_t processZSLCaptureDone(); 407 int32_t processSceneData(cam_scene_mode_type scene); 408 int32_t transAwbMetaToParams(cam_awb_params_t &awb_params); 409 int32_t processFocusPositionInfo(cam_focus_pos_info_t &cur_pos_info); 410 int32_t processAEInfo(cam_3a_params_t &ae_params); 411 int32_t processDCFOVControl(); 412 413 int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2); 414 int32_t sendDataNotify(int32_t msg_type, 415 camera_memory_t *data, 416 uint8_t index, 417 camera_frame_metadata_t *metadata, 418 uint32_t frame_idx); 419 420 int32_t sendPreviewCallback(QCameraStream *stream, 421 QCameraMemory *memory, uint32_t idx); 422 int32_t selectScene(QCameraChannel *pChannel, 423 mm_camera_super_buf_t *recvd_frame); 424 425 int32_t addChannel(qcamera_ch_type_enum_t ch_type); 426 int32_t startChannel(qcamera_ch_type_enum_t ch_type); 427 int32_t stopChannel(qcamera_ch_type_enum_t ch_type); 428 int32_t delChannel(qcamera_ch_type_enum_t ch_type, bool destroy = true); 429 int32_t addPreviewChannel(); 430 int32_t addSnapshotChannel(); 431 int32_t addVideoChannel(); 432 int32_t addZSLChannel(); 433 int32_t addCaptureChannel(); 434 int32_t addRawChannel(); 435 int32_t addMetaDataChannel(); 436 int32_t addAnalysisChannel(); 437 QCameraReprocessChannel *addReprocChannel(QCameraChannel *pInputChannel, 438 int8_t cur_channel_index = 0); 439 QCameraReprocessChannel *addOfflineReprocChannel( 440 cam_pp_offline_src_config_t &img_config, 441 cam_pp_feature_config_t &pp_feature, 442 stream_cb_routine stream_cb, 443 void *userdata); 444 int32_t addCallbackChannel(); 445 446 int32_t addStreamToChannel(QCameraChannel *pChannel, 447 cam_stream_type_t streamType, 448 stream_cb_routine streamCB, 449 void *userData); 450 int32_t preparePreview(); 451 void unpreparePreview(); 452 int32_t prepareRawStream(QCameraChannel *pChannel); 453 QCameraChannel *getChannelByHandle(uint32_t channelHandle); 454 mm_camera_buf_def_t *getSnapshotFrame(mm_camera_super_buf_t *recvd_frame); 455 int32_t processFaceDetectionResult(cam_faces_data_t *fd_data); 456 bool needPreviewFDCallback(uint8_t num_faces); 457 int32_t processHistogramStats(cam_hist_stats_t &stats_data); 458 int32_t setHistogram(bool histogram_en); 459 int32_t setFaceDetection(bool enabled); 460 int32_t prepareHardwareForSnapshot(int32_t afNeeded); 461 bool needProcessPreviewFrame(uint32_t frameID); 462 bool needSendPreviewCallback(); 463 bool isNoDisplayMode() {return mParameters.isNoDisplayMode();}; 464 bool isZSLMode() {return mParameters.isZSLMode();}; 465 bool isRdiMode() {return mParameters.isRdiMode();}; 466 uint8_t numOfSnapshotsExpected() { 467 return mParameters.getNumOfSnapshots();}; 468 bool isSecureMode() {return mParameters.isSecureMode();}; 469 bool isLongshotEnabled() { return mLongshotEnabled; }; 470 bool isHFRMode() {return mParameters.isHfrMode();}; 471 bool isLiveSnapshot() {return m_stateMachine.isRecording();}; 472 void setRetroPicture(bool enable) { bRetroPicture = enable; }; 473 bool isRetroPicture() {return bRetroPicture; }; 474 bool isHDRMode() {return mParameters.isHDREnabled();}; 475 uint8_t getBufNumRequired(cam_stream_type_t stream_type); 476 uint8_t getBufNumForAux(cam_stream_type_t stream_type); 477 bool needFDMetadata(qcamera_ch_type_enum_t channel_type); 478 int32_t configureOnlineRotation(QCameraChannel &ch); 479 int32_t declareSnapshotStreams(); 480 int32_t unconfigureAdvancedCapture(); 481 int32_t configureAdvancedCapture(); 482 int32_t configureAFBracketing(bool enable = true); 483 int32_t configureHDRBracketing(); 484 int32_t stopAdvancedCapture(QCameraPicChannel *pChannel); 485 int32_t startAdvancedCapture(QCameraPicChannel *pChannel); 486 int32_t configureOptiZoom(); 487 int32_t configureStillMore(); 488 int32_t configureAEBracketing(); 489 int32_t updatePostPreviewParameters(); 490 inline void setOutputImageCount(uint32_t aCount) {mOutputCount = aCount;} 491 inline uint32_t getOutputImageCount() {return mOutputCount;} 492 bool processUFDumps(qcamera_jpeg_evt_payload_t *evt); 493 void captureDone(); 494 int32_t updateMetadata(metadata_buffer_t *pMetaData); 495 void fillFacesData(cam_faces_data_t &faces_data, metadata_buffer_t *metadata); 496 497 int32_t getPPConfig(cam_pp_feature_config_t &pp_config, 498 int8_t curIndex = 0, bool multipass = FALSE); 499 virtual uint32_t scheduleBackgroundTask(BackgroundTask* bgTask); 500 virtual int32_t waitForBackgroundTask(uint32_t &taskId); 501 bool needDeferred(cam_stream_type_t stream_type); 502 static void camEvtHandle(uint32_t camera_handle, 503 mm_camera_event_t *evt, 504 void *user_data); 505 static void jpegEvtHandle(jpeg_job_status_t status, 506 uint32_t client_hdl, 507 uint32_t jobId, 508 mm_jpeg_output_t *p_buf, 509 void *userdata); 510 511 static void *evtNotifyRoutine(void *data); 512 513 // functions for different data notify cb 514 static void zsl_channel_cb(mm_camera_super_buf_t *recvd_frame, void *userdata); 515 static void capture_channel_cb_routine(mm_camera_super_buf_t *recvd_frame, 516 void *userdata); 517 static void postproc_channel_cb_routine(mm_camera_super_buf_t *recvd_frame, 518 void *userdata); 519 static void rdi_mode_stream_cb_routine(mm_camera_super_buf_t *frame, 520 QCameraStream *stream, 521 void *userdata); 522 static void nodisplay_preview_stream_cb_routine(mm_camera_super_buf_t *frame, 523 QCameraStream *stream, 524 void *userdata); 525 static void preview_stream_cb_routine(mm_camera_super_buf_t *frame, 526 QCameraStream *stream, 527 void *userdata); 528 static void synchronous_stream_cb_routine(mm_camera_super_buf_t *frame, 529 QCameraStream *stream, void *userdata); 530 static void postview_stream_cb_routine(mm_camera_super_buf_t *frame, 531 QCameraStream *stream, 532 void *userdata); 533 static void video_stream_cb_routine(mm_camera_super_buf_t *frame, 534 QCameraStream *stream, 535 void *userdata); 536 static void snapshot_channel_cb_routine(mm_camera_super_buf_t *frame, 537 void *userdata); 538 static void raw_channel_cb_routine(mm_camera_super_buf_t *frame, 539 void *userdata); 540 static void raw_stream_cb_routine(mm_camera_super_buf_t *frame, 541 QCameraStream *stream, 542 void *userdata); 543 static void preview_raw_stream_cb_routine(mm_camera_super_buf_t * super_frame, 544 QCameraStream * stream, 545 void * userdata); 546 static void snapshot_raw_stream_cb_routine(mm_camera_super_buf_t * super_frame, 547 QCameraStream * stream, 548 void * userdata); 549 static void metadata_stream_cb_routine(mm_camera_super_buf_t *frame, 550 QCameraStream *stream, 551 void *userdata); 552 static void callback_stream_cb_routine(mm_camera_super_buf_t *frame, 553 QCameraStream *stream, void *userdata); 554 static void reprocess_stream_cb_routine(mm_camera_super_buf_t *frame, 555 QCameraStream *stream, 556 void *userdata); 557 558 static void releaseCameraMemory(void *data, 559 void *cookie, 560 int32_t cbStatus); 561 static void returnStreamBuffer(void *data, 562 void *cookie, 563 int32_t cbStatus); 564 static void getLogLevel(); 565 566 int32_t startRAWChannel(QCameraChannel *pChannel); 567 int32_t stopRAWChannel(); 568 569 inline bool getNeedRestart() {return m_bNeedRestart;} 570 inline void setNeedRestart(bool needRestart) {m_bNeedRestart = needRestart;} 571 572 /*Start display skip. Skip starts after 573 skipCnt number of frames from current frame*/ 574 void setDisplaySkip(bool enabled, uint8_t skipCnt = 0); 575 /*Caller can specify range frameID to skip. 576 if end is 0, all the frames after start will be skipped*/ 577 void setDisplayFrameSkip(uint32_t start = 0, uint32_t end = 0); 578 /*Verifies if frameId is valid to skip*/ 579 bool isDisplayFrameToSkip(uint32_t frameId); 580 bool isDualCamera() { return mDualCamera; }; 581 void fillDualCameraFOVControl(); 582 uint8_t getStreamRefCount(cam_stream_type_t stream_type); 583 uint32_t getCamHandleForChannel(qcamera_ch_type_enum_t ch_type); 584 int32_t switchCameraCb(); 585 int32_t processCameraControl(uint32_t camState); 586 private: 587 camera_device_t mCameraDevice; 588 uint32_t mCameraId; 589 mm_camera_vtbl_t *mCameraHandle; 590 uint32_t m_ActiveHandle; 591 uint32_t mActiveCamera; 592 bool mCameraOpened; 593 bool mDualCamera; 594 595 cam_jpeg_metadata_t mJpegMetadata; 596 bool m_bRelCamCalibValid; 597 598 preview_stream_ops_t *mPreviewWindow; 599 QCameraParametersIntf mParameters; 600 int32_t mMsgEnabled; 601 int mStoreMetaDataInFrame; 602 603 camera_notify_callback mNotifyCb; 604 camera_data_callback mDataCb; 605 camera_data_timestamp_callback mDataCbTimestamp; 606 camera_request_memory mGetMemory; 607 jpeg_data_callback mJpegCb; 608 void *mCallbackCookie; 609 void *mJpegCallbackCookie; 610 bool m_bMpoEnabled; 611 612 QCameraStateMachine m_stateMachine; // state machine 613 bool m_smThreadActive; 614 QCameraPostProcessor m_postprocessor; // post processor 615 QCameraThermalAdapter &m_thermalAdapter; 616 QCameraCbNotifier m_cbNotifier; 617 QCameraPerfLock m_perfLock; 618 pthread_mutex_t m_lock; 619 pthread_cond_t m_cond; 620 api_result_list *m_apiResultList; 621 QCameraMemoryPool m_memoryPool; 622 623 pthread_mutex_t m_evtLock; 624 pthread_cond_t m_evtCond; 625 qcamera_api_result_t m_evtResult; 626 627 628 QCameraChannel *m_channels[QCAMERA_CH_TYPE_MAX]; // array holding channel ptr 629 630 bool m_bPreviewStarted; //flag indicates first preview frame callback is received 631 bool m_bRecordStarted; //flag indicates Recording is started for first time 632 633 // Signifies if ZSL Retro Snapshots are enabled 634 bool bRetroPicture; 635 // Signifies AEC locked during zsl snapshots 636 bool m_bLedAfAecLock; 637 cam_af_state_t m_currentFocusState; 638 639 uint32_t mDumpFrmCnt; // frame dump count 640 uint32_t mDumpSkipCnt; // frame skip count 641 mm_jpeg_exif_params_t mExifParams; 642 qcamera_thermal_level_enum_t mThermalLevel; 643 bool mActiveAF; 644 bool m_HDRSceneEnabled; 645 bool mLongshotEnabled; 646 647 pthread_t mLiveSnapshotThread; 648 pthread_t mIntPicThread; 649 bool mFlashNeeded; 650 bool mFlashConfigured; 651 uint32_t mDeviceRotation; 652 uint32_t mCaptureRotation; 653 uint32_t mJpegExifRotation; 654 bool mUseJpegExifRotation; 655 bool mIs3ALocked; 656 bool mPrepSnapRun; 657 int32_t mZoomLevel; 658 // Flag to indicate whether preview restart needed (for dual camera mode) 659 bool mPreviewRestartNeeded; 660 661 int mVFrameCount; 662 int mVLastFrameCount; 663 nsecs_t mVLastFpsTime; 664 double mVFps; 665 int mPFrameCount; 666 int mPLastFrameCount; 667 nsecs_t mPLastFpsTime; 668 double mPFps; 669 bool mLowLightConfigured; 670 uint8_t mInstantAecFrameCount; 671 672 //eztune variables for communication with eztune server at backend 673 bool m_bIntJpegEvtPending; 674 bool m_bIntRawEvtPending; 675 char m_BackendFileName[QCAMERA_MAX_FILEPATH_LENGTH]; 676 size_t mBackendFileSize; 677 pthread_mutex_t m_int_lock; 678 pthread_cond_t m_int_cond; 679 680 enum DeferredWorkCmd { 681 CMD_DEF_ALLOCATE_BUFF, 682 CMD_DEF_PPROC_START, 683 CMD_DEF_PPROC_INIT, 684 CMD_DEF_METADATA_ALLOC, 685 CMD_DEF_CREATE_JPEG_SESSION, 686 CMD_DEF_PARAM_ALLOC, 687 CMD_DEF_PARAM_INIT, 688 CMD_DEF_GENERIC, 689 CMD_DEF_MAX 690 }; 691 692 typedef struct { 693 QCameraChannel *ch; 694 cam_stream_type_t type; 695 } DeferAllocBuffArgs; 696 697 typedef struct { 698 uint8_t bufferCnt; 699 size_t size; 700 } DeferMetadataAllocArgs; 701 702 typedef struct { 703 jpeg_encode_callback_t jpeg_cb; 704 void *user_data; 705 } DeferPProcInitArgs; 706 707 typedef union { 708 DeferAllocBuffArgs allocArgs; 709 QCameraChannel *pprocArgs; 710 DeferMetadataAllocArgs metadataAllocArgs; 711 DeferPProcInitArgs pprocInitArgs; 712 BackgroundTask *genericArgs; 713 } DeferWorkArgs; 714 715 typedef struct { 716 uint32_t mDefJobId; 717 718 //Job status is needed to check job was successful or failed 719 //Error code when job was not sucessful and there is error 720 //0 when is initialized. 721 //for sucessfull job, do not need to maintain job status 722 int32_t mDefJobStatus; 723 } DefOngoingJob; 724 725 DefOngoingJob mDefOngoingJobs[MAX_ONGOING_JOBS]; 726 727 struct DefWork 728 { 729 DefWork(DeferredWorkCmd cmd_, 730 uint32_t id_, 731 DeferWorkArgs args_) 732 : cmd(cmd_), 733 id(id_), 734 args(args_){}; 735 736 DeferredWorkCmd cmd; 737 uint32_t id; 738 DeferWorkArgs args; 739 }; 740 741 QCameraCmdThread mDeferredWorkThread; 742 QCameraQueue mCmdQueue; 743 744 Mutex mDefLock; 745 Condition mDefCond; 746 747 uint32_t queueDeferredWork(DeferredWorkCmd cmd, 748 DeferWorkArgs args); 749 uint32_t dequeueDeferredWork(DefWork* dw, int32_t jobStatus); 750 int32_t waitDeferredWork(uint32_t &job_id); 751 static void *deferredWorkRoutine(void *obj); 752 bool checkDeferredWork(uint32_t &job_id); 753 int32_t getDefJobStatus(uint32_t &job_id); 754 755 uint32_t mReprocJob; 756 uint32_t mJpegJob; 757 uint32_t mMetadataAllocJob; 758 uint32_t mInitPProcJob; 759 uint32_t mParamAllocJob; 760 uint32_t mParamInitJob; 761 uint32_t mOutputCount; 762 uint32_t mInputCount; 763 bool mAdvancedCaptureConfigured; 764 bool mHDRBracketingEnabled; 765 int32_t mNumPreviewFaces; 766 // Jpeg Handle shared between HWI instances 767 mm_jpeg_ops_t mJpegHandle; 768 // MPO handle shared between HWI instances 769 // this is needed for MPO composition of related 770 // cam images 771 mm_jpeg_mpo_ops_t mJpegMpoHandle; 772 uint32_t mJpegClientHandle; 773 bool mJpegHandleOwner; 774 //ts add for makeup 775 #ifdef TARGET_TS_MAKEUP 776 TSRect mFaceRect; 777 bool TsMakeupProcess_Preview(mm_camera_buf_def_t *pFrame,QCameraStream * pStream); 778 bool TsMakeupProcess_Snapshot(mm_camera_buf_def_t *pFrame,QCameraStream * pStream); 779 bool TsMakeupProcess(mm_camera_buf_def_t *frame,QCameraStream * stream,TSRect& faceRect); 780 #endif 781 QCameraMemory *mMetadataMem; 782 783 static uint32_t sNextJobId; 784 785 //Gralloc memory details 786 pthread_mutex_t mGrallocLock; 787 uint8_t mEnqueuedBuffers; 788 bool mCACDoneReceived; 789 790 //GPU library to read buffer padding details. 791 void *lib_surface_utils; 792 int (*LINK_get_surface_pixel_alignment)(); 793 uint32_t mSurfaceStridePadding; 794 795 //QCamera Display Object 796 QCameraDisplay mCameraDisplay; 797 798 bool m_bNeedRestart; 799 Mutex mMapLock; 800 Condition mMapCond; 801 802 //Used to decide the next frameID to be skipped 803 uint32_t mLastPreviewFrameID; 804 //FrameID to start frame skip. 805 uint32_t mFrameSkipStart; 806 /*FrameID to stop frameskip. If this is not set, 807 all frames are skipped till we set this*/ 808 uint32_t mFrameSkipEnd; 809 //The offset between BOOTTIME and MONOTONIC timestamps 810 nsecs_t mBootToMonoTimestampOffset; 811 bool bDepthAFCallbacks; 812 int32_t prev_zoomLevel; 813 }; 814 815 }; // namespace qcamera 816 817 #endif /* __QCAMERA2HARDWAREINTERFACE_H__ */ 818