ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
 
#ifndef __HAL_CAMERA_HARDWARE_H__
#define __HAL_CAMERA_HARDWARE_H__
 
/*
 * Contains declaration of a class CameraHardware that encapsulates functionality
 * common to all V4L2Cameras ("fake", "webcam", "video file", etc.).
 * Instances of this class (for each V4L2Camera) are created during the
 * construction of the HALCameraFactory instance.
 * This class serves as an entry point for all camera API calls that defined
 * by camera_device_ops_t API.
 */
 
#include <utils/Mutex.h>
 
#include "CameraParameters.h"
 
#include "V4L2CameraDevice2.h"
#include "PreviewWindow.h"
#include "CallbackNotifier.h"
#include "CCameraConfig.h"
#ifdef __OPEN_FACEDECTION__
#include "libfacedetection/FaceDetectionApi.h"
#include "libfacedetection/SmileEyeBlinkAPI.h"
#include "libfacedetection/ApperceivePeopleApi.h"
#endif
#include "CameraPlatform.h"
#ifdef AWCAMRECORDER
#include "AWCamRecorder.h"
#endif
#ifdef CAMERA_MANAGER_ENABLE
#include "CameraManager.h"
#endif
 
#ifdef USE_CSI_VIN_DRIVER
#include <sunxi_camera_v2.h>
#endif
 
#define ENABLE_AUTO_FOCUS 0
namespace android {
 
#ifdef CAMERA_MANAGER_ENABLE
class CameraManager;
#endif
#ifdef AWCAMRECORDER
class AWCamRecorder;
#endif
 
#define KEY_CAMERA_HAL_VERSION            "camera-hal-version"
#define KEY_CAPTURE_SIZE_WIDTH            "capture-size-width"
#define KEY_CAPTURE_SIZE_HEIGHT            "capture-size-height"
#define KEY_PREVIEW_CAPTURE_SIZE_WIDTH    "preview_capture-size-width"
#define KEY_PREVIEW_CAPTURE_SIZE_HEIGHT    "preview_capture-size-height"
 
#define KEY_PICTURE_MODE                "picture-mode"
#define PICTURE_MODE_NORMAL                "normal"
#define PICTURE_MODE_BLINK                "blink"
#define PICTURE_MODE_SMILE                "smile"
#define PICTURE_MODE_SCENE_MODE            "scene-mode"
#define PICTURE_MODE_CONTINUOUS            "continuous"
#define PICTURE_MODE_CONTINUOUS_FAST    "continuous-fast"
#define KEY_CANCEL_CONTINUOUS_PICTURE    "cancel_continuous_picture"        // "true" for stopping
#define KEY_CONTINUOUS_PICTURE_PATH        "continuous-picture-path"
 
#define KEY_SNAP_PATH                    "snap-path"
 
#define KEY_IS_IMAGECAPTURE_INTENT        "is-imagecapture-intent"
#define KEY_CAPTURE_FORMAT              "capture-format"
typedef enum face_detection_states_t {
    FACE_DETECTION_UNINITIALIZED    = 0,
    FACE_DETECTION_INITIALIZED      = 1 << 0,
    FACE_DETECTION_STARTED          = 1 << 1,
    FACE_DETECTION_PREPARED         = 1 << 2,
    FACE_DETECTION_IDLE             = 1 << 3,
    FACE_DETECTION_STOPPED          = 1 << 4,
    FACE_DETECTION_STATE_ERROR      = 1 << 5,
}face_detection_states;
/* Encapsulates functionality common to all V4L2Cameras.
 *
 * Note that HALCameraFactory instantiates object of this class just once,
 * when HALCameraFactory instance gets constructed. Connection to /
 * disconnection from the actual camera device is handled by calls to connectDevice(),
 * and closeCamera() methods of this class that are ivoked in response to
 * hw_module_methods_t::open, and camera_device::close callbacks.
 */
class CameraHardware : public camera_device {
public:
    /* Constructs CameraHardware instance.
     * Param:
     *  module - V4L2Camera HAL module descriptor.
     */
    CameraHardware(struct hw_module_t* module, CCameraConfig* pCameraCfg);
 
    /* Destructs CameraHardware instance. */
    virtual ~CameraHardware();
 
    /****************************************************************************
     * Public API
     ***************************************************************************/
 
public:
    /* Initializes CameraHardware instance.
     * Return:
     *  NO_ERROR on success, or an appropriate error status on failure.
     */
    virtual status_t Initialize();
 
    /* Entry point for notifications that occur in camera device.
     * Param:
     *  err - CAMERA_ERROR_XXX error code.
     */
    virtual void onCameraDeviceError(int err);
 
    /****************************************************************************
     * Camera API implementation
     ***************************************************************************/
 
public:
    /* Creates connection to the V4L2Camera device.
     * This method is called in response to hw_module_methods_t::open callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t connectCamera(hw_device_t** device);
 
    /* Closes connection to the V4L2Camera.
     * This method is called in response to camera_device::close callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t closeCamera();
 
    /****************************************************************************
     * Camera API implementation.
     * These methods are called from the camera API callback routines.
     ***************************************************************************/
 
protected:
    /* Actual handler for camera_device_ops_t::set_preview_window callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t setPreviewWindow(struct preview_stream_ops *window);
 
    /* Actual handler for camera_device_ops_t::set_callbacks callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void setCallbacks(camera_notify_callback notify_cb,
                              camera_data_callback data_cb,
                              camera_data_timestamp_callback data_cb_timestamp,
                              camera_request_memory get_memory,
                              void* user);
 
    /* Actual handler for camera_device_ops_t::enable_msg_type callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void enableMsgType(int32_t msg_type);
 
    /* Actual handler for camera_device_ops_t::disable_msg_type callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void disableMsgType(int32_t msg_type);
 
    /* Actual handler for camera_device_ops_t::msg_type_enabled callback.
     * NOTE: When this method is called the object is locked.
     * Return:
     *  0 if message(s) is (are) disabled, != 0 if enabled.
     */
    virtual int isMsgTypeEnabled(int32_t msg_type);
 
    /* Actual handler for camera_device_ops_t::start_preview callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t startPreview();
 
    /* Actual handler for camera_device_ops_t::stop_preview callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void stopPreview();
 
    /* Actual handler for camera_device_ops_t::preview_enabled callback.
     * NOTE: When this method is called the object is locked.
     * Return:
     *  0 if preview is disabled, != 0 if enabled.
     */
    virtual int isPreviewEnabled();
 
    virtual status_t enablePreview();
 
    virtual status_t disablePreview();
 
    /* Actual handler for camera_device_ops_t::store_meta_data_in_buffers callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t storeMetaDataInBuffers(int enable);
 
    /* Actual handler for camera_device_ops_t::start_recording callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t startRecording();
 
    /* Actual handler for camera_device_ops_t::stop_recording callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void stopRecording();
 
    /* Actual handler for camera_device_ops_t::recording_enabled callback.
     * NOTE: When this method is called the object is locked.
     * Return:
     *  0 if recording is disabled, != 0 if enabled.
     */
    virtual int isRecordingEnabled();
 
    /* Actual handler for camera_device_ops_t::release_recording_frame callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void releaseRecordingFrame(const void* opaque);
 
    /* Actual handler for camera_device_ops_t::auto_focus callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t setAutoFocus();
 
    /* Actual handler for camera_device_ops_t::cancel_auto_focus callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t cancelAutoFocus();
 
    /* Actual handler for camera_device_ops_t::take_picture callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t takePicture();
 
    /* Actual handler for camera_device_ops_t::cancel_picture callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t cancelPicture();
 
    /* Actual handler for camera_device_ops_t::set_parameters callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t setParameters(const char* parms);
#ifdef WATERMARK
        virtual status_t setWaterMarkMultiple(char *mWaterMark, int dispMode);
#endif
 
 
    virtual status_t setFd(int fd);
    /* Actual handler for camera_device_ops_t::get_parameters callback.
     * NOTE: When this method is called the object is locked.
     * Return:
     *  Flattened parameters string. The caller will free the buffer allocated
     *  for the string by calling camera_device_ops_t::put_parameters callback.
     */
    virtual char* getParameters();
 
    /* Actual handler for camera_device_ops_t::put_parameters callback.
     * Called to free the string returned from camera_device_ops_t::get_parameters
     * callback. There is nothing more to it: the name of the callback is just
     * misleading.
     * NOTE: When this method is called the object is locked.
     */
    virtual void putParameters(char* params);
 
    /* Actual handler for camera_device_ops_t::send_command callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
    virtual status_t awCameraReleaseByIndex(int32_t index);
 
    /* Actual handler for camera_device_ops_t::release callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void releaseCamera();
 
    /* Actual handler for camera_device_ops_t::dump callback.
     * NOTE: When this method is called the object is locked.
     * Note that failures in this method are reported as negave EXXX statuses.
     */
    virtual status_t dumpCamera(int fd);
 
    /* Actual handler for face detection msg_type callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void enableSmartMsgType(int32_t msg_type);
 
    /* Actual handler for face detection msg_type callback.
     * NOTE: When this method is called the object is locked.
     */
    virtual void disableSmartMsgType(int32_t msg_type);
 
    /* Actual handler for face detection callback.
     * NOTE: When this method is called the object is locked.
     * Return:
     *  0 if message(s) is (are) disabled, != 0 if enabled.
     */
    virtual int isSmartMsgTypeEnabled(int32_t msg_type);
 
    /****************************************************************************
     * Preview management.
     ***************************************************************************/
 
protected:
public:
    /* Starts preview.
     * Note that when this method is called mPreviewWindow may be NULL,
     * indicating that framework has an intention to start displaying video
     * frames, but didn't create the preview window yet.
     * Return:
     *  NO_ERROR on success, or an appropriate error status on failure.
     */
    virtual status_t doStartPreview();
 
    /* Stops preview.
     * This method reverts DoStartPreview.
     * Return:
     *  NO_ERROR on success, or an appropriate error status on failure.
     */
    virtual status_t doStopPreview();
 
    status_t doTakePicture();
    status_t doTakePictureEnd();
    status_t doStartSmart();
    status_t doStopSmart();
 
    /****************************************************************************
     * Private API.
     ***************************************************************************/
 
protected:
    /* Cleans up camera when released. */
    virtual status_t cleanupCamera();
 
    /****************************************************************************
     * Camera API callbacks as defined by camera_device_ops structure.
     * See hardware/libhardware/include/hardware/camera.h for information on
     * each of these callbacks. Implemented in this class, these callbacks simply
     * dispatch the call into an instance of CameraHardware class defined by the
     * 'camera_device' parameter.
     ***************************************************************************/
 
private:
    static int set_preview_window(struct camera_device* dev,
                                   struct preview_stream_ops* window);
 
    static void set_callbacks(struct camera_device* dev,
                              camera_notify_callback notify_cb,
                              camera_data_callback data_cb,
                              camera_data_timestamp_callback data_cb_timestamp,
                              camera_request_memory get_memory,
                              void* user);
 
    static void enable_msg_type(struct camera_device* dev, int32_t msg_type);
 
    static void disable_msg_type(struct camera_device* dev, int32_t msg_type);
 
    static int msg_type_enabled(struct camera_device* dev, int32_t msg_type);
 
    static int start_preview(struct camera_device* dev);
 
    static void stop_preview(struct camera_device* dev);
 
    static int preview_enabled(struct camera_device* dev);
 
    static int enable_preview(struct camera_device* dev);
 
    static int disable_preview(struct camera_device* dev);
 
    static int store_meta_data_in_buffers(struct camera_device* dev, int enable);
 
    static int start_recording(struct camera_device* dev);
 
    static void stop_recording(struct camera_device* dev);
 
    static int recording_enabled(struct camera_device* dev);
 
    static void release_recording_frame(struct camera_device* dev,
                                        const void* opaque);
 
    static int auto_focus(struct camera_device* dev);
 
    static int cancel_auto_focus(struct camera_device* dev);
 
    static int take_picture(struct camera_device* dev);
 
    static int cancel_picture(struct camera_device* dev);
 
    static int set_parameters(struct camera_device* dev, const char* parms);
 
    static int set_fd(struct camera_device* dev, int fd);
#ifdef WATERMARK
    //for watermark setting
    static int set_waterMarkMultiple(struct camera_device *dev, const char *mWaterMark, int dispMode);
    //end
#endif
 
 
 
 
    static char* get_parameters(struct camera_device* dev);
 
    static void put_parameters(struct camera_device* dev, char* params);
 
    static int send_command(struct camera_device* dev,
                            int32_t cmd,
                            int32_t arg1,
                            int32_t arg2);
    static int awCamera_release_byIndex(struct camera_device* dev,int32_t index);
    static void release(struct camera_device* dev);
 
    static int dump(struct camera_device* dev, int fd);
 
    static int close(struct hw_device_t* device);
 
    /****************************************************************************
     * Data members
     ***************************************************************************/
public:
#ifdef CAMERA_MANAGER_ENABLE
        /* Preview window. */
        PreviewWindow               mPreviewWindow;
        CallbackNotifier            mCallbackNotifier;
        V4L2CameraDevice *          mV4L2CameraDevice;
        inline bool getHwEncoder(void)
        {
            return mUseHwEncoder;
        }
#endif
 
protected:
    /* Locks this instance for parameters, state, etc. change. */
    Mutex                           mObjectLock;
 
    /* Camera parameters. */
    CameraParameters                mParameters;
 
#ifndef CAMERA_MANAGER_ENABLE
    /* Preview window. */
    PreviewWindow                   mPreviewWindow;
 
    /* Callback notifier. */
    CallbackNotifier                mCallbackNotifier;
 
    V4L2CameraDevice *               mV4L2CameraDevice;
#endif
#ifdef AWCAMRECORDER
    AWCamRecorder*                  mAWCamRecorder;
    Mutex                           mAWCamRecLock;
#endif
 
private:
    /* Registered callbacks implementing camera API. */
    static camera_device_ops_t      mDeviceOps;
#ifdef CAMERA_MANAGER_ENABLE
    CameraManager *mCameraManager;
#endif
 
    /****************************************************************************
     * Common keys
     ***************************************************************************/
 
public:
    static const char FACING_KEY[];
    static const char ORIENTATION_KEY[];
    static const char RECORDING_HINT_KEY[];
 
     /****************************************************************************
     * Common string values
     ***************************************************************************/
 
    /* Possible values for FACING_KEY */
    static const char FACING_BACK[];
    static const char FACING_FRONT[];
#ifdef __OPEN_FACEDECTION__
    struct FrameFaceData                     mFrameFaceData;
    struct FacePosition                      mFacePosition;
    unsigned char*                           mSmartData;
#endif
    unsigned char*                           mFrameData;
 
 
 
    int mPreviewRotation;
    int mPreviewWidth;
    int mPreviewHeight;
#ifdef __OPEN_FACEDECTION__
 
    bool mSmileDetectionCmdEnable;
    bool mBlinkDetectionCmdEnable;
 
    bool mSmileDetectionEnable;
    bool mBlinkDetectionEnable;
    bool mSmartDetectionEnable;
 
    //face_detection_states mSmileDetectionState;
    //face_detection_states mBlinkDetectionState;
 
    bool mBlinkPictureStarted;
    bool mBlinkPictureResult;
    bool mSmilePictureResult;
#endif
    char                            mCallingProcessName[128];
    // -------------------------------------------------------------------------
    // extended interfaces here <***** star *****>
    // -------------------------------------------------------------------------
public:
    HALCameraInfo* get_halinfo();
    status_t setCameraHardwareInfo(HALCameraInfo * halInfo);
#ifdef CAMERA_MANAGER_ENABLE
    void setCameraManager(CameraManager * manager);
    void releasePreviewFrame(int index);
    int getFrameWidth();
    int getFrameHeight();
    status_t startPreview_h();
    void stopPreview_h();
    void releaseCamera_h();
 
#endif
    void initDefaultParameters();
 
    void notifyPictureMsg(const void* frame);
 
    void setNewCrop(Rect * rect);
    int setAutoFocusRange();
#ifdef __OPEN_FACEDECTION__
    int getCurrentFaceFrame(void* frame, int* width, int* height);
    int faceDetection(camera_frame_metadata_t *face);
    int smileDetection(camera_face_smile_status_t *smile);
    int blinkDetection(camera_face_blink_status_t *blink);
    int smartDetection(int type);
#endif //__OPEN_FACEDECTION__
    int parse_focus_areas(const char * str, bool is_face = false);
    bool checkFocusArea(const char * area);
    bool checkFocusMode(const char * mode);
 
    bool commandThread();
    bool autoFocusThread();
#ifdef  __OPEN_FACEDECTION__
 
    bool faceDetectionThread();
    bool smartThread();
#endif //__OPEN_FACEDECTION__
    void setVideoCaptureSize(int video_w, int video_h);
    void getCurrentOriention(int * oriention, int compensation = 0,bool reverse = 0,int re_direction = 0);
 
    bool isCameraIdle();
    void makeFDOrientionArray();
    void getHWOrientionInfo(void *);
    int setExifInfo(struct isp_exif_attribute exifinfo);
    int getPriviewSize(int* preview_width,int* preview_height,int capture_width,int capture_height);
 
#ifdef AWCAMRECORDER
    bool awCamRecIsStart(void);
    static void awCamRecReleaseFrame(void *owner,int index);
    bool awCamRecInputBuffer(V4L2BUF_t *cap_buffer);
#endif
 
protected:
    CCameraConfig *                 mCameraConfig;
 
    HALCameraInfo                    mHalCameraInfo;
 
    Mutex                           mCameraIdleLock;
    bool                            mIsCameraIdle;
 
    bool                            mFirstSetParameters;
#if ENABLE_AUTO_FOCUS
    bool                            mIsSupportFocus;
#endif
    bool                            mIsSupportEffect;
    bool                            mIsSupportFlash;
    bool                            mIsSupportScene;
    bool                            mIsSupportWhiteBlance;
    bool                            mIsSupportExposure;
 
    int                                mFullSizeWidth;
    int                                mFullSizeHeight;
    int                                mCaptureWidth;
    int                                mCaptureHeight;
    int                                mVideoCaptureWidth;
    int                                mVideoCaptureHeight;
    bool                            mUseHwEncoder;
 
#ifdef __OPEN_FACEDECTION__
    FaceDetectionDev *                mFaceDetection;
    SmileDetectionDev *                mSmileDetection;
    EyeBlinkDetectionDev *          mBlinkDetection;
    ApperceivePeopleDev *           mSmartDetection;
#endif
    int                                mFDOriention[4];
    Rect                            mFrameRectCrop;        // current frame buffer crop for focus
    char                            mFocusAreasStr[32];
    struct v4l2_win_coordinate        mLastFocusAreas;
 
    typedef enum CMD_QUEUE_t{
        CMD_QUEUE_SET_COLOR_EFFECT     = 0,
        CMD_QUEUE_SET_WHITE_BALANCE,
        CMD_QUEUE_SET_FLASH_MODE,
        CMD_QUEUE_SET_FOCUS_MODE,
        CMD_QUEUE_SET_FOCUS_AREA,
        CMD_QUEUE_SET_EXPOSURE_COMPENSATION,
 
        CMD_QUEUE_START_FACE_DETECTE,
        CMD_QUEUE_STOP_FACE_DETECTE,
        CMD_QUEUE_START_SMILE_DETECTE,
        CMD_QUEUE_STOP_SMILE_DETECTE,
        CMD_QUEUE_START_BLINK_DETECTE,
        CMD_QUEUE_STOP_BLINK_DETECTE,
 
        CMD_QUEUE_TAKE_PICTURE,
        CMD_QUEUE_PICTURE_MSG,
        CMD_QUEUE_STOP_CONTINUOUSSNAP,
 
        CMD_QUEUE_SET_FOCUS_STATUS,
 
#ifdef WATERMARK
        CMD_QUEUE_START_WATER_MARK,
        CMD_QUEUE_STOP_WATER_MARK,
#endif
        CMD_QUEUE_MAX
    }CMD_QUEUE;
 
    OSAL_QUEUE                        mQueueCommand;
 
    typedef struct Queue_Element_t {
        CMD_QUEUE cmd;
        unsigned long data;
    }Queue_Element;
 
    Queue_Element                    mQueueElement[CMD_QUEUE_MAX];
 
    class DoCommandThread : public Thread {
        CameraHardware* mCameraHardware;
        ThreadState        mThreadStatus;
    public:
        DoCommandThread(CameraHardware* hw) :
            Thread(false),
            mCameraHardware(hw),
            mThreadStatus(THREAD_STATE_NULL) {
        }
        void startThread() {
            mThreadStatus = THREAD_STATE_RUNNING;
            run("CameraCommandThread", PRIORITY_NORMAL);
        }
        void stopThread() {
            mThreadStatus = THREAD_STATE_EXIT;
        }
        ThreadState getThreadStatus() {
            return mThreadStatus;
        }
        bool isThreadStarted() {
            return (mThreadStatus == THREAD_STATE_PAUSED) || (mThreadStatus == THREAD_STATE_RUNNING);
        }
        virtual bool threadLoop() {
            return mCameraHardware->commandThread();
        }
    };
    sp<DoCommandThread>                mCommandThread;
 
    pthread_mutex_t                 mCommandMutex;
    pthread_cond_t                    mCommandCond;
 
#if ENABLE_AUTO_FOCUS
    class DoAutoFocusThread : public Thread {
        CameraHardware* mCameraHardware;
        ThreadState        mThreadStatus;
    public:
        DoAutoFocusThread(CameraHardware* hw) :
            Thread(false),
            mCameraHardware(hw),
            mThreadStatus(THREAD_STATE_NULL) {
        }
        void startThread() {
            mThreadStatus = THREAD_STATE_RUNNING;
            run("CameraAutoFocusThread", PRIORITY_NORMAL);
        }
        void stopThread() {
            mThreadStatus = THREAD_STATE_EXIT;
        }
        ThreadState getThreadStatus() {
            return mThreadStatus;
        }
        bool isThreadStarted() {
            return (mThreadStatus == THREAD_STATE_PAUSED) || (mThreadStatus == THREAD_STATE_RUNNING);
        }
        virtual bool threadLoop() {
            return mCameraHardware->autoFocusThread();
        }
    };
    sp<DoAutoFocusThread>            mAutoFocusThread;
 
    pthread_mutex_t                 mAutoFocusMutex;
    pthread_cond_t                    mAutoFocusCond;
    bool                            mAutoFocusThreadExit;
#endif
 
public:
    typedef enum FocusStatus_t {
        FOCUS_STATUS_IDLE        = 0x0,
        FOCUS_STATUS_SUCCESS    = 0x1,
        FOCUS_STATUS_FAIL        = 0x2,
        FOCUS_STATUS_DONE        = FOCUS_STATUS_SUCCESS | FOCUS_STATUS_FAIL,
        FOCUS_STATUS_BUSY        = 0x4,
    }FocusStatus;
 
protected:
#if ENABLE_AUTO_FOCUS
    FocusStatus                        mFocusStatus;
    bool                            mIsSingleFocus;
#endif
    int                                mOriention;
 
    int                                mZoomRatio;
    bool                            mIsImageCaptureIntent;
#ifdef __OPEN_FACEDECTION__
    class DoFaceDetectionThread : public Thread {
        CameraHardware* mCameraHardware;
        ThreadState        mThreadStatus;
    public:
        DoFaceDetectionThread(CameraHardware* hw) :
            Thread(false),
            mCameraHardware(hw),
            mThreadStatus(THREAD_STATE_NULL) {
        }
        void startThread() {
            mThreadStatus = THREAD_STATE_RUNNING;
            run("faceDetectionThread", PRIORITY_NORMAL);
        }
        void stopThread() {
            mThreadStatus = THREAD_STATE_EXIT;
        }
        ThreadState getThreadStatus() {
            return mThreadStatus;
        }
        bool isThreadStarted() {
            return (mThreadStatus == THREAD_STATE_PAUSED) || (mThreadStatus == THREAD_STATE_RUNNING);
        }
        virtual bool threadLoop() {
            return mCameraHardware->faceDetectionThread();
        }
    };
    sp<DoFaceDetectionThread>        mFaceDetectionThread;
#endif //__OPEN_FACEDECTION__
 
#ifdef __OPEN_SMARTDECTION__
public:
    class DoSmartThread : public Thread {
        CameraHardware* mCameraHardware;
        ThreadState        mThreadStatus;
    public:
        DoSmartThread(CameraHardware* hw) :
            Thread(false),
            mCameraHardware(hw),
            mThreadStatus(THREAD_STATE_NULL) {
        }
        void startThread() {
            mThreadStatus = THREAD_STATE_RUNNING;
            run("smartThread", PRIORITY_NORMAL);
        }
        void stopThread() {
            mThreadStatus = THREAD_STATE_EXIT;
        }
        ThreadState getThreadStatus() {
            return mThreadStatus;
        }
        bool isThreadStarted() {
            return (mThreadStatus == THREAD_STATE_PAUSED) || (mThreadStatus == THREAD_STATE_RUNNING);
        }
        virtual bool threadLoop() {
            return mCameraHardware->smartThread();
        }
    };
    sp<DoSmartThread>        mSmartThread;
#endif //__OPEN_SMARTDECTION__
private:
#ifdef __OPEN_FACEDECTION__
    pthread_mutex_t                 mFaceDetectionMutex;
    pthread_cond_t                    mFaceDetectionCond;
    bool                            mFaceDetectionThreadExit;
 
    pthread_mutex_t                 mFaceDetectionStateMutex;
#endif //__OPEN_FACEDECTION__
#ifdef __OPEN_SMILEDECTION__
    face_detection_states mSmileDetectionState;
#endif //__OPEN_SMILEDECTION__
#ifdef __OPEN_BLINKDECTION__
    face_detection_states mBlinkDetectionState;
#endif //__OPEN_BLINKDECTION__
#ifdef __OPEN_SMARTDECTION__
    pthread_mutex_t                 mSmartMutex;
    pthread_cond_t                    mSmartCond;
    bool                            mSmartThreadExit;
    int                             mSmartMode;
    int                             mSmartDiscardFrameNum;
#endif //__OPEN_SMARTDECTION__
};
 
}; /* namespace android */
 
#endif  /* __HAL_CAMERA_HARDWARE_H__ */