1 /*
2 ** Copyright (c) 2011-2012 The Linux Foundation. All rights reserved.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 **     http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
17 #ifndef ANDROID_HARDWARE_QCAMERA_HARDWARE_INTERFACE_H
18 #define ANDROID_HARDWARE_QCAMERA_HARDWARE_INTERFACE_H
19 
20 
21 #include <utils/threads.h>
22 #include <hardware/camera2.h>
23 #include <binder/MemoryBase.h>
24 #include <binder/MemoryHeapBase.h>
25 #include <utils/threads.h>
26 #include <cutils/properties.h>
27 #include <camera/Camera.h>
28 //#include <QCameraParameters.h>
29 #include <system/window.h>
30 #include <system/camera.h>
31 #include <gralloc_priv.h>
32 //#include <QComOMXMetadata.h>
33 
34 extern "C" {
35 #include <linux/android_pmem.h>
36 #include <linux/msm_ion.h>
37 #include <mm_camera_interface.h>
38 #include "mm_jpeg_interface.h"
39 } //extern C
40 
41 #include "QCameraStream.h"
42 #include "QCamera_Intf.h"
43 
44 //Error codes
45 #define  NOT_FOUND -1
46 #define MAX_ZOOM_RATIOS 62
47 
48 #ifdef Q12
49 #undef Q12
50 #endif
51 
52 #define Q12 4096
53 #define QCAMERA_PARM_ENABLE   1
54 #define QCAMERA_PARM_DISABLE  0
55 #define PREVIEW_TBL_MAX_SIZE  14
56 #define VIDEO_TBL_MAX_SIZE    14
57 #define THUMB_TBL_MAX_SIZE    16
58 #define HFR_TBL_MAX_SIZE      2
59 //Default Video Width
60 #define DEFAULT_VIDEO_WIDTH 1920
61 #define DEFAULT_VIDEO_HEIGHT 1088
62 
63 #define DEFAULT_STREAM_WIDTH 640
64 #define DEFAULT_STREAM_HEIGHT 480
65 #define DEFAULT_LIVESHOT_WIDTH 2592
66 #define DEFAULT_LIVESHOT_HEIGHT 1944
67 
68 struct str_map {
69     const char *const desc;
70     int val;
71 };
72 
73 struct preview_format_info_t {
74    int Hal_format;
75    cam_format_t mm_cam_format;
76    cam_pad_format_t padding;
77    int num_planar;
78 };
79 
80 
81 typedef enum {
82   CAMERA_STATE_UNINITED,
83   CAMERA_STATE_READY,
84   CAMERA_STATE_PREVIEW_START_CMD_SENT,
85   CAMERA_STATE_PREVIEW_STOP_CMD_SENT,
86   CAMERA_STATE_PREVIEW,
87   CAMERA_STATE_RECORD_START_CMD_SENT,  /*5*/
88   CAMERA_STATE_RECORD_STOP_CMD_SENT,
89   CAMERA_STATE_RECORD,
90   CAMERA_STATE_SNAP_START_CMD_SENT,
91   CAMERA_STATE_SNAP_STOP_CMD_SENT,
92   CAMERA_STATE_SNAP_CMD_ACKED,  /*10 - snapshot comd acked, snapshot not done yet*/
93   CAMERA_STATE_ZSL_START_CMD_SENT,
94   CAMERA_STATE_ZSL,
95   CAMERA_STATE_AF_START_CMD_SENT,
96   CAMERA_STATE_AF_STOP_CMD_SENT,
97   CAMERA_STATE_ERROR, /*15*/
98 
99   /*Add any new state above*/
100   CAMERA_STATE_MAX
101 } HAL_camera_state_type_t;
102 
103 enum {
104   BUFFER_NOT_REGGED,
105   BUFFER_NOT_OWNED,
106   BUFFER_OWNED,
107   BUFFER_UNLOCKED,
108   BUFFER_LOCKED,
109 };
110 
111 typedef enum {
112   HAL_DUMP_FRM_PREVIEW = 1,
113   HAL_DUMP_FRM_VIDEO = 1<<1,
114   HAL_DUMP_FRM_MAIN = 1<<2,
115   HAL_DUMP_FRM_THUMBNAIL = 1<<3,
116 
117   /*8 bits mask*/
118   HAL_DUMP_FRM_MAX = 1 << 8
119 } HAL_cam_dump_frm_type_t;
120 
121 
122 typedef enum {
123   HAL_CAM_MODE_ZSL = 1,
124 
125   /*add new entry before and update the max entry*/
126   HAL_CAM_MODE_MAX = HAL_CAM_MODE_ZSL << 1,
127 } qQamera_mode_t;
128 
129 
130 typedef enum {
131     MM_CAMERA_OK,
132     MM_CAMERA_E_GENERAL,
133     MM_CAMERA_E_NO_MEMORY,
134     MM_CAMERA_E_NOT_SUPPORTED,
135     MM_CAMERA_E_INVALID_INPUT,
136     MM_CAMERA_E_INVALID_OPERATION, /* 5 */
137     MM_CAMERA_E_ENCODE,
138     MM_CAMERA_E_BUFFER_REG,
139     MM_CAMERA_E_PMEM_ALLOC,
140     MM_CAMERA_E_CAPTURE_FAILED,
141     MM_CAMERA_E_CAPTURE_TIMEOUT, /* 10 */
142 }mm_camera_status_type_t;
143 
144 
145 
146 #define HAL_DUMP_FRM_MASK_ALL ( HAL_DUMP_FRM_PREVIEW + HAL_DUMP_FRM_VIDEO + \
147     HAL_DUMP_FRM_MAIN + HAL_DUMP_FRM_THUMBNAIL)
148 #define QCAMERA_HAL_PREVIEW_STOPPED    0
149 #define QCAMERA_HAL_PREVIEW_START      1
150 #define QCAMERA_HAL_PREVIEW_STARTED    2
151 #define QCAMERA_HAL_RECORDING_STARTED  3
152 #define QCAMERA_HAL_TAKE_PICTURE       4
153 
154 //EXIF globals
155 static const char ExifAsciiPrefix[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x0, 0x0, 0x0 };          // "ASCII\0\0\0"
156 static const char ExifUndefinedPrefix[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };   // "\0\0\0\0\0\0\0\0"
157 
158 //EXIF detfines
159 #define MAX_EXIF_TABLE_ENTRIES           14
160 #define GPS_PROCESSING_METHOD_SIZE       101
161 #define FOCAL_LENGTH_DECIMAL_PRECISION   100
162 #define EXIF_ASCII_PREFIX_SIZE           8   //(sizeof(ExifAsciiPrefix))
163 
164 typedef struct{
165     //GPS tags
166     rat_t       latitude[3];
167     rat_t       longitude[3];
168     char        lonRef[2];
169     char        latRef[2];
170     rat_t       altitude;
171     rat_t       gpsTimeStamp[3];
172     char        gpsDateStamp[20];
173     char        gpsProcessingMethod[EXIF_ASCII_PREFIX_SIZE+GPS_PROCESSING_METHOD_SIZE];
174     //Other tags
175     char        dateTime[20];
176     rat_t       focalLength;
177     uint16_t    flashMode;
178     uint16_t    isoSpeed;
179 
180     bool        mAltitude;
181     bool        mLongitude;
182     bool        mLatitude;
183     bool        mTimeStamp;
184     bool        mGpsProcess;
185 
186     int         mAltitude_ref;
187     long        mGPSTimestamp;
188 
189 } exif_values_t;
190 
191 namespace android {
192 
193 class QCameraStream;
194 
195 class QCameraHardwareInterface : public virtual RefBase {
196 public:
197 
198     QCameraHardwareInterface(int  cameraId, int mode);
199 
200     int set_request_queue_src_ops(
201         const camera2_request_queue_src_ops_t *request_src_ops);
202     int notify_request_queue_not_empty();
203     int set_frame_queue_dst_ops(const camera2_frame_queue_dst_ops_t *frame_dst_ops);
204     int get_in_progress_count();
205     int construct_default_request(int request_template, camera_metadata_t **request);
206     int allocate_stream(uint32_t width,
207         uint32_t height, int format,
208         const camera2_stream_ops_t *stream_ops,
209         uint32_t *stream_id,
210         uint32_t *format_actual,
211         uint32_t *usage,
212         uint32_t *max_buffers);
213     int register_stream_buffers(uint32_t stream_id, int num_buffers,
214         buffer_handle_t *buffers);
215     int release_stream(uint32_t stream_id);
216     int allocate_reprocess_stream(
217         uint32_t width,
218         uint32_t height,
219         uint32_t format,
220         const camera2_stream_in_ops_t *reprocess_stream_ops,
221         uint32_t *stream_id,
222         uint32_t *consumer_usage,
223         uint32_t *max_buffers);
224     int release_reprocess_stream(
225         uint32_t stream_id);
226     int get_metadata_vendor_tag_ops(vendor_tag_query_ops_t **ops);
227     int set_notify_callback(camera2_notify_callback notify_cb,
228             void *user);
229 
230 
231     void runCommandThread(void *);
232 
233     int getBuf(uint32_t camera_handle,
234                         uint32_t ch_id, uint32_t stream_id,
235                         void *user_data,
236                         mm_camera_frame_len_offset *frame_offset_info,
237                         uint8_t num_bufs,
238                         uint8_t *initial_reg_flag,
239                         mm_camera_buf_def_t  *bufs);
240     int putBuf(uint32_t camera_handle,
241                         uint32_t ch_id, uint32_t stream_id,
242                         void *user_data, uint8_t num_bufs,
243                         mm_camera_buf_def_t *bufs);
244 
245 #if 0
246     static QCameraHardwareInterface *createInstance(int, int);
247     /** Set the ANativeWindow to which preview frames are sent */
248     int setPreviewWindow(preview_stream_ops_t* window);
249 
250     /** Set the notification and data callbacks */
251     void setCallbacks(camera_notify_callback notify_cb,
252             camera_data_callback data_cb,
253             camera_data_timestamp_callback data_cb_timestamp,
254             camera_request_memory get_memory,
255             void *user);
256 
257     /**
258      * The following three functions all take a msg_type, which is a bitmask of
259      * the messages defined in include/ui/Camera.h
260      */
261 
262     /**
263      * Enable a message, or set of messages.
264      */
265     void enableMsgType(int32_t msg_type);
266 
267     /**
268      * Disable a message, or a set of messages.
269      *
270      * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
271      * HAL should not rely on its client to call releaseRecordingFrame() to
272      * release video recording frames sent out by the cameral HAL before and
273      * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
274      * clients must not modify/access any video recording frame after calling
275      * disableMsgType(CAMERA_MSG_VIDEO_FRAME).
276      */
277     void disableMsgType(int32_t msg_type);
278 
279     /**
280      * Query whether a message, or a set of messages, is enabled.  Note that
281      * this is operates as an AND, if any of the messages queried are off, this
282      * will return false.
283      */
284     int msgTypeEnabled(int32_t msg_type);
285 
286     /**
287      * Start preview mode.
288      */
289     int startPreview();
290     int startPreview2();
291 
292     /**
293      * Stop a previously started preview.
294      */
295     void stopPreview();
296 
297     /**
298      * Returns true if preview is enabled.
299      */
300     int previewEnabled();
301 
302 
303     /**
304      * Request the camera HAL to store meta data or real YUV data in the video
305      * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
306      * it is not called, the default camera HAL behavior is to store real YUV
307      * data in the video buffers.
308      *
309      * This method should be called before startRecording() in order to be
310      * effective.
311      *
312      * If meta data is stored in the video buffers, it is up to the receiver of
313      * the video buffers to interpret the contents and to find the actual frame
314      * data with the help of the meta data in the buffer. How this is done is
315      * outside of the scope of this method.
316      *
317      * Some camera HALs may not support storing meta data in the video buffers,
318      * but all camera HALs should support storing real YUV data in the video
319      * buffers. If the camera HAL does not support storing the meta data in the
320      * video buffers when it is requested to do do, INVALID_OPERATION must be
321      * returned. It is very useful for the camera HAL to pass meta data rather
322      * than the actual frame data directly to the video encoder, since the
323      * amount of the uncompressed frame data can be very large if video size is
324      * large.
325      *
326      * @param enable if true to instruct the camera HAL to store
327      *        meta data in the video buffers; false to instruct
328      *        the camera HAL to store real YUV data in the video
329      *        buffers.
330      *
331      * @return OK on success.
332      */
333     int storeMetaDataInBuffers(int enable);
334 
335     /**
336      * Start record mode. When a record image is available, a
337      * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
338      * frame. Every record frame must be released by a camera HAL client via
339      * releaseRecordingFrame() before the client calls
340      * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
341      * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
342      * responsibility to manage the life-cycle of the video recording frames,
343      * and the client must not modify/access any video recording frames.
344      */
345     int startRecording();
346 
347     /**
348      * Stop a previously started recording.
349      */
350     void stopRecording();
351 
352     /**
353      * Returns true if recording is enabled.
354      */
355     int recordingEnabled();
356 
357     /**
358      * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
359      *
360      * It is camera HAL client's responsibility to release video recording
361      * frames sent out by the camera HAL before the camera HAL receives a call
362      * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
363      * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
364      * responsibility to manage the life-cycle of the video recording frames.
365      */
366     void releaseRecordingFrame(const void *opaque);
367 
368     /**
369      * Start auto focus, the notification callback routine is called with
370      * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
371      * called again if another auto focus is needed.
372      */
373     int autoFocus();
374 
375     /**
376      * Cancels auto-focus function. If the auto-focus is still in progress,
377      * this function will cancel it. Whether the auto-focus is in progress or
378      * not, this function will return the focus position to the default.  If
379      * the camera does not support auto-focus, this is a no-op.
380      */
381     int cancelAutoFocus();
382 
383     /**
384      * Take a picture.
385      */
386     int takePicture();
387 
388     /**
389      * Cancel a picture that was started with takePicture. Calling this method
390      * when no picture is being taken is a no-op.
391      */
392     int cancelPicture();
393 
394     /**
395      * Set the camera parameters. This returns BAD_VALUE if any parameter is
396      * invalid or not supported.
397      */
398     int setParameters(const char *parms);
399 
400     //status_t setParameters(const QCameraParameters& params);
401     /** Retrieve the camera parameters.  The buffer returned by the camera HAL
402         must be returned back to it with put_parameters, if put_parameters
403         is not NULL.
404      */
405     int getParameters(char **parms);
406 
407     /** The camera HAL uses its own memory to pass us the parameters when we
408         call get_parameters.  Use this function to return the memory back to
409         the camera HAL, if put_parameters is not NULL.  If put_parameters
410         is NULL, then you have to use free() to release the memory.
411     */
412     void putParameters(char *);
413 
414     /**
415      * Send command to camera driver.
416      */
417     int sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
418 
419 
420     /**
421      * Dump state of the camera hardware
422      */
423     int dump(int fd);
424 
425     //virtual sp<IMemoryHeap> getPreviewHeap() const;
426     //virtual sp<IMemoryHeap> getRawHeap() const;
427 
428 
429     status_t    takeLiveSnapshot();
430     status_t    takeFullSizeLiveshot();
431     bool        canTakeFullSizeLiveshot();
432 
433     //virtual status_t          getBufferInfo( sp<IMemory>& Frame,
434     //size_t *alignedSize);
435     void         getPictureSize(int *picture_width, int *picture_height) const;
436     void         getPreviewSize(int *preview_width, int *preview_height) const;
437     cam_format_t getPreviewFormat() const;
438 
439     cam_pad_format_t getPreviewPadding() const;
440 
441     //bool     useOverlay(void);
442     //virtual status_t setOverlay(const sp<Overlay> &overlay);
443     void processEvent(mm_camera_event_t *);
444     int  getJpegQuality() const;
445     int  getNumOfSnapshots(void) const;
446     int  getNumOfSnapshots(const QCameraParameters& params);
447     int  getThumbSizesFromAspectRatio(uint32_t aspect_ratio,
448                                      int *picture_width,
449                                      int *picture_height);
450     bool isRawSnapshot();
451     bool mShutterSoundPlayed;
452     void dumpFrameToFile(mm_camera_buf_def_t*, HAL_cam_dump_frm_type_t);
453 
454     status_t setZSLBurstLookBack(const QCameraParameters& params);
455     status_t setZSLBurstInterval(const QCameraParameters& params);
456     int getZSLBurstInterval(void);
457     int getZSLQueueDepth(void) const;
458     int getZSLBackLookCount(void) const;
459 #endif
460     /**
461      * Release the hardware resources owned by this object.  Note that this is
462      * *not* done in the destructor.
463      */
464     void release();
465 
466     bool isCameraReady();
467     ~QCameraHardwareInterface();
468 
469     mm_camear_mem_vtbl_t mMemHooks;
470     mm_camera_vtbl_t *mCameraHandle;
471     uint32_t mChannelId;
472 
473 #if 0
474     int initHeapMem( QCameraHalHeap_t *heap,
475                             int num_of_buf,
476                             int buf_len,
477                             int y_off,
478                             int cbcr_off,
479                             int pmem_type,
480                             mm_camera_buf_def_t *buf_def,
481                             uint8_t num_planes,
482                             uint32_t *planes);
483     int releaseHeapMem( QCameraHalHeap_t *heap);
484     status_t sendMappingBuf(int ext_mode, int idx, int fd, uint32_t size,
485       int cameraid, mm_camera_socket_msg_type msg_type);
486     status_t sendUnMappingBuf(int ext_mode, int idx, int cameraid,
487       mm_camera_socket_msg_type msg_type);
488 
489     int allocate_ion_memory(QCameraHalHeap_t *p_camera_memory, int cnt,
490       int ion_type);
491     int deallocate_ion_memory(QCameraHalHeap_t *p_camera_memory, int cnt);
492 
493     int allocate_ion_memory(QCameraStatHeap_t *p_camera_memory, int cnt,
494       int ion_type);
495     int deallocate_ion_memory(QCameraStatHeap_t *p_camera_memory, int cnt);
496 
497     int cache_ops(int ion_fd, struct ion_flush_data *cache_inv_data, int type);
498 
499     void dumpFrameToFile(const void * data, uint32_t size, char* name,
500       char* ext, int index);
501     preview_format_info_t getPreviewFormatInfo( );
502     bool isNoDisplayMode();
503 
504     int getBuf(uint32_t camera_handle,
505                         uint32_t ch_id, uint32_t stream_id,
506                         void *user_data,
507                         mm_camera_frame_len_offset *frame_offset_info,
508                         uint8_t num_bufs,
509                         uint8_t *initial_reg_flag,
510                         mm_camera_buf_def_t  *bufs);
511     int putBuf(uint32_t camera_handle,
512                         uint32_t ch_id, uint32_t stream_id,
513                         void *user_data, uint8_t num_bufs,
514                         mm_camera_buf_def_t *bufs);
515 
516 
517 private:
518     int16_t  zoomRatios[MAX_ZOOM_RATIOS];
519     struct camera_size_type default_preview_sizes[PREVIEW_TBL_MAX_SIZE];
520     struct camera_size_type default_video_sizes[VIDEO_TBL_MAX_SIZE];
521     struct camera_size_type default_hfr_sizes[HFR_TBL_MAX_SIZE];
522     struct camera_size_type default_thumbnail_sizes[THUMB_TBL_MAX_SIZE];
523     unsigned int preview_sizes_count;
524     unsigned int video_sizes_count;
525     unsigned int thumbnail_sizes_count;
526     unsigned int hfr_sizes_count;
527 
528 
529     bool mUseOverlay;
530 
531     void loadTables();
532     void initDefaultParameters();
533     bool getMaxPictureDimension(mm_camera_dimension_t *dim);
534 
535     status_t updateFocusDistances();
536 
537     bool native_set_parms(mm_camera_parm_type_t type, uint16_t length, void *value);
538     bool native_set_parms( mm_camera_parm_type_t type, uint16_t length, void *value, int *result);
539 
540     void hasAutoFocusSupport();
541     void debugShowPreviewFPS() const;
542     //void prepareSnapshotAndWait();
543 
544     bool isPreviewRunning();
545     bool isRecordingRunning();
546     bool isSnapshotRunning();
547 
548     void processChannelEvent(mm_camera_ch_event_t *, app_notify_cb_t *);
549     void processPreviewChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *);
550     void processRecordChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *);
551     void processSnapshotChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *);
552     void processCtrlEvent(mm_camera_ctrl_event_t *, app_notify_cb_t *);
553     void processStatsEvent(mm_camera_stats_event_t *, app_notify_cb_t *);
554     void processInfoEvent(mm_camera_info_event_t *event, app_notify_cb_t *);
555     void processprepareSnapshotEvent(cam_ctrl_status_t *);
556     void roiEvent(fd_roi_t roi, app_notify_cb_t *);
557     void zoomEvent(cam_ctrl_status_t *status, app_notify_cb_t *);
558     void autofocusevent(cam_ctrl_status_t *status, app_notify_cb_t *);
559     void handleZoomEventForPreview(app_notify_cb_t *);
560     void handleZoomEventForSnapshot(void);
561     status_t autoFocusEvent(cam_ctrl_status_t *, app_notify_cb_t *);
562 
563     void filterPictureSizes();
564     bool supportsSceneDetection();
565     bool supportsSelectableZoneAf();
566     bool supportsFaceDetection();
567     bool supportsRedEyeReduction();
568     bool preview_parm_config (cam_ctrl_dimension_t* dim,QCameraParameters& parm);
569 
570     void stopPreviewInternal();
571     void stopRecordingInternal();
572     //void stopPreviewZSL();
573     status_t cancelPictureInternal();
574     //status_t startPreviewZSL();
575     void pausePreviewForSnapshot();
576     void pausePreviewForZSL();
577     status_t resumePreviewAfterSnapshot();
578 
579     status_t runFaceDetection();
580 
581     status_t           setParameters(const QCameraParameters& params);
582     QCameraParameters&  getParameters() ;
583 
584     status_t setCameraMode(const QCameraParameters& params);
585     status_t setPictureSizeTable(void);
586     status_t setPreviewSizeTable(void);
587     status_t setVideoSizeTable(void);
588     status_t setPreviewSize(const QCameraParameters& params);
589     status_t setJpegThumbnailSize(const QCameraParameters& params);
590     status_t setPreviewFpsRange(const QCameraParameters& params);
591     status_t setPreviewFrameRate(const QCameraParameters& params);
592     status_t setPreviewFrameRateMode(const QCameraParameters& params);
593     status_t setVideoSize(const QCameraParameters& params);
594     status_t setPictureSize(const QCameraParameters& params);
595     status_t setJpegQuality(const QCameraParameters& params);
596     status_t setNumOfSnapshot(const QCameraParameters& params);
597     status_t setJpegRotation(int isZSL);
598     int getJpegRotation(void);
599     int getISOSpeedValue();
600     status_t setAntibanding(const QCameraParameters& params);
601     status_t setEffect(const QCameraParameters& params);
602     status_t setExposureCompensation(const QCameraParameters &params);
603     status_t setAutoExposure(const QCameraParameters& params);
604     status_t setWhiteBalance(const QCameraParameters& params);
605     status_t setFlash(const QCameraParameters& params);
606     status_t setGpsLocation(const QCameraParameters& params);
607     status_t setRotation(const QCameraParameters& params);
608     status_t setZoom(const QCameraParameters& params);
609     status_t setFocusMode(const QCameraParameters& params);
610     status_t setBrightness(const QCameraParameters& params);
611     status_t setSkinToneEnhancement(const QCameraParameters& params);
612     status_t setOrientation(const QCameraParameters& params);
613     status_t setLensshadeValue(const QCameraParameters& params);
614     status_t setMCEValue(const QCameraParameters& params);
615     status_t setISOValue(const QCameraParameters& params);
616     status_t setPictureFormat(const QCameraParameters& params);
617     status_t setSharpness(const QCameraParameters& params);
618     status_t setContrast(const QCameraParameters& params);
619     status_t setSaturation(const QCameraParameters& params);
620     status_t setWaveletDenoise(const QCameraParameters& params);
621     status_t setSceneMode(const QCameraParameters& params);
622     status_t setContinuousAf(const QCameraParameters& params);
623     status_t setFaceDetection(const char *str);
624     status_t setSceneDetect(const QCameraParameters& params);
625     status_t setStrTextures(const QCameraParameters& params);
626     status_t setPreviewFormat(const QCameraParameters& params);
627     status_t setSelectableZoneAf(const QCameraParameters& params);
628     status_t setOverlayFormats(const QCameraParameters& params);
629     status_t setHighFrameRate(const QCameraParameters& params);
630     status_t setRedeyeReduction(const QCameraParameters& params);
631     status_t setAEBracket(const QCameraParameters& params);
632     status_t setFaceDetect(const QCameraParameters& params);
633     status_t setDenoise(const QCameraParameters& params);
634     status_t setAecAwbLock(const QCameraParameters & params);
635     status_t setHistogram(int histogram_en);
636     status_t setRecordingHint(const QCameraParameters& params);
637     status_t setRecordingHintValue(const int32_t value);
638     status_t setFocusAreas(const QCameraParameters& params);
639     status_t setMeteringAreas(const QCameraParameters& params);
640     status_t setFullLiveshot(void);
641     status_t setDISMode(void);
642     status_t setCaptureBurstExp(void);
643     status_t setPowerMode(const QCameraParameters& params);
644     void takePicturePrepareHardware( );
645     status_t setNoDisplayMode(const QCameraParameters& params);
646 
647     isp3a_af_mode_t getAutoFocusMode(const QCameraParameters& params);
648     bool isValidDimension(int w, int h);
649 
650     String8 create_values_str(const str_map *values, int len);
651 
652     void setMyMode(int mode);
653     bool isZSLMode();
654     bool isWDenoiseEnabled();
655     void wdenoiseEvent(cam_ctrl_status_t status, void *cookie);
656     bool isLowPowerCamcorder();
657     void freePictureTable(void);
658     void freeVideoSizeTable(void);
659 
660     int32_t createPreview();
661     int32_t createRecord();
662     int32_t createSnapshot();
663 
664     int getHDRMode();
665     //EXIF
666     void addExifTag(exif_tag_id_t tagid, exif_tag_type_t type,
667                         uint32_t count, uint8_t copy, void *data);
668     void setExifTags();
669     void initExifData();
670     void deinitExifData();
671     void setExifTagsGPS();
672     exif_tags_info_t* getExifData(){ return mExifData; }
673     int getExifTableNumEntries() { return mExifTableNumEntries; }
674     void parseGPSCoordinate(const char *latlonString, rat_t* coord);
675     //added to support hdr
676     bool getHdrInfoAndSetExp(int max_num_frm, int *num_frame, int *exp);
677     void hdrEvent(cam_ctrl_status_t status, void *cookie);
678 
679     camera_mode_t myMode;
680 
681 
682 
683 
684     QCameraParameters    mParameters;
685     //sp<Overlay>         mOverlay;
686     int32_t             mMsgEnabled;
687 
688     camera_notify_callback         mNotifyCb;
689     camera_data_callback           mDataCb;
690     camera_data_timestamp_callback mDataCbTimestamp;
691     camera_request_memory          mGetMemory;
692     void                           *mCallbackCookie;
693 
694     //sp<MemoryHeapBase>  mPreviewHeap;  //@Guru : Need to remove
695     sp<AshmemPool>      mMetaDataHeap;
696 
697     mutable Mutex       mLock;
698     //mutable Mutex       eventLock;
699     Mutex         mCallbackLock;
700     Mutex         mRecordingMemoryLock;
701     Mutex         mAutofocusLock;
702     Mutex         mMetaDataWaitLock;
703     Mutex         mRecordFrameLock;
704     Mutex         mRecordLock;
705     Condition     mRecordWait;
706     pthread_mutex_t     mAsyncCmdMutex;
707     pthread_cond_t      mAsyncCmdWait;
708 
709     cam_ctrl_dimension_t mDimension;
710     int  mPreviewWidth, mPreviewHeight;
711     int  videoWidth, videoHeight;
712     int  thumbnailWidth, thumbnailHeight;
713     int  maxSnapshotWidth, maxSnapshotHeight;
714     int  mPreviewFormat;
715     int  mFps;
716     int  mDebugFps;
717     int  mBrightness;
718     int  mContrast;
719     int  mBestShotMode;
720     int  mEffects;
721     int  mSkinToneEnhancement;
722     int  mDenoiseValue;
723     int  mHJR;
724     int  mRotation;
725     int  mJpegQuality;
726     int  mThumbnailQuality;
727     int  mTargetSmoothZoom;
728     int  mSmoothZoomStep;
729     int  mMaxZoom;
730     int  mCurrentZoom;
731     int  mSupportedPictureSizesCount;
732     int  mFaceDetectOn;
733     int  mDumpFrmCnt;
734     int  mDumpSkipCnt;
735     int  mFocusMode;
736 
737     unsigned int mPictureSizeCount;
738     unsigned int mPreviewSizeCount;
739     int mPowerMode;
740     unsigned int mVideoSizeCount;
741 
742     bool mAutoFocusRunning;
743     bool mMultiTouch;
744     bool mHasAutoFocusSupport;
745     bool mInitialized;
746     bool mDisEnabled;
747     bool strTexturesOn;
748     bool mIs3DModeOn;
749     bool mSmoothZoomRunning;
750     bool mPreparingSnapshot;
751     bool mParamStringInitialized;
752     bool mZoomSupported;
753     bool mSendMetaData;
754     bool mFullLiveshotEnabled;
755     bool mRecordingHint;
756     bool mStartRecording;
757     bool mReleasedRecordingFrame;
758     int mHdrMode;
759     int mSnapshotFormat;
760     int mZslInterval;
761     bool mRestartPreview;
762 
763 /*for histogram*/
764     int            mStatsOn;
765     int            mCurrentHisto;
766     bool           mSendData;
767     sp<AshmemPool> mStatHeap;
768     camera_memory_t *mStatsMapped[3];
769     QCameraStatHeap_t mHistServer;
770     int32_t        mStatSize;
771 
772     bool mZslLookBackMode;
773     int mZslLookBackValue;
774 	int mHFRLevel;
775     bool mZslEmptyQueueFlag;
776     String8 mEffectValues;
777     String8 mIsoValues;
778     String8 mSceneModeValues;
779     String8 mSceneDetectValues;
780     String8 mFocusModeValues;
781     String8 mSelectableZoneAfValues;
782     String8 mAutoExposureValues;
783     String8 mWhitebalanceValues;
784     String8 mAntibandingValues;
785     String8 mFrameRateModeValues;
786     String8 mTouchAfAecValues;
787     String8 mPreviewSizeValues;
788     String8 mPictureSizeValues;
789     String8 mVideoSizeValues;
790     String8 mFlashValues;
791     String8 mLensShadeValues;
792     String8 mMceValues;
793     String8 mHistogramValues;
794     String8 mSkinToneEnhancementValues;
795     String8 mPictureFormatValues;
796     String8 mDenoiseValues;
797     String8 mZoomRatioValues;
798     String8 mPreviewFrameRateValues;
799     String8 mPreviewFormatValues;
800     String8 mFaceDetectionValues;
801     String8 mHfrValues;
802     String8 mHfrSizeValues;
803     String8 mRedeyeReductionValues;
804     String8 denoise_value;
805     String8 mFpsRangesSupportedValues;
806     String8 mZslValues;
807     String8 mFocusDistance;
808 
809 
810     android :: FPSRange* mSupportedFpsRanges;
811     int mSupportedFpsRangesCount;
812 
813     camera_size_type* mPictureSizes;
814     camera_size_type* mPreviewSizes;
815     camera_size_type* mVideoSizes;
816     const camera_size_type * mPictureSizesPtr;
817     HAL_camera_state_type_t mCameraState;
818 
819      /* Temporary - can be removed after Honeycomb*/
820 #ifdef USE_ION
821     sp<IonPool>  mPostPreviewHeap;
822 #else
823     sp<PmemPool> mPostPreviewHeap;
824 #endif
825     // mm_cameara_stream_buf_t mPrevForPostviewBuf;
826      int mStoreMetaDataInFrame;
827      preview_stream_ops_t *mPreviewWindow;
828      Mutex                mStateLock;
829      int                  mPreviewState;
830      /*preview memory without display case: memory is allocated
831       directly by camera */
832      QCameraHalHeap_t     mNoDispPreviewMemory;
833 
834      QCameraHalHeap_t     mSnapshotMemory;
835      QCameraHalHeap_t     mThumbnailMemory;
836      QCameraHalHeap_t     mRecordingMemory;
837      QCameraHalHeap_t     mJpegMemory;
838      QCameraHalHeap_t     mRawMemory;
839      camera_frame_metadata_t mMetadata;
840      camera_face_t           mFace[MAX_ROI];
841      preview_format_info_t  mPreviewFormatInfo;
842     // friend void liveshot_callback(mm_camera_ch_data_buf_t *frame,void *user_data);
843      //EXIF
844      exif_tags_info_t       mExifData[MAX_EXIF_TABLE_ENTRIES];  //Exif tags for JPEG encoder
845      exif_values_t          mExifValues;                        //Exif values in usable format
846      int                    mExifTableNumEntries;            //NUmber of entries in mExifData
847      int                 mNoDisplayMode;
848 #endif
849 private:
850     int           mCameraId;
851     camera_metadata_t *mStaticInfo;
852 
853     friend class QCameraStream;
854     friend class QCameraStream_record;
855     friend class QCameraStream_preview;
856     friend class QCameraStream_SnapshotMain;
857     friend class QCameraStream_SnapshotThumbnail;
858     friend class QCameraStream_Rdi;
859 
860     friend void stream_cb_routine(mm_camera_super_buf_t *bufs, void *userdata);
861     friend void superbuf_cb_routine(mm_camera_super_buf_t *bufs, void *userdata);
862     friend void *command_thread(void *);
863 
864     int tryRestartStreams(camera_metadata_entry_t& streams);
865 
866     QCameraStream       *mStreamDisplay;
867     QCameraStream       *mStreamRecord;
868     QCameraStream       *mStreamSnapMain;
869     QCameraStream       *mStreamSnapThumb;
870     QCameraStream       *mStreamLiveSnap;
871     QCameraStream       *mStreamRdi;
872 
873     const camera2_request_queue_src_ops *mRequestQueueSrc;
874     uint8_t mPendingRequests;
875     const camera2_frame_queue_dst_ops *mFrameQueueDst;
876     camera2_notify_callback mNotifyCb;
877     void *mNotifyUserPtr;
878     pthread_t mCommandThread;
879 };
880 
881 }; // namespace android
882 
883 #endif
884