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