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