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