Home | History | Annotate | Download | only in OMXCameraAdapter
      1 /*
      2  * Copyright (C) Texas Instruments - http://www.ti.com/
      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 
     18 
     19 #ifndef OMX_CAMERA_ADAPTER_H
     20 #define OMX_CAMERA_ADAPTER_H
     21 
     22 #include "CameraHal.h"
     23 #include "OMX_Types.h"
     24 #include "OMX_Core.h"
     25 #include "OMX_CoreExt.h"
     26 #include "OMX_IVCommon.h"
     27 #include "OMX_Component.h"
     28 #include "OMX_Index.h"
     29 #include "OMX_IndexExt.h"
     30 #include "OMX_TI_Index.h"
     31 #include "OMX_TI_IVCommon.h"
     32 #include "OMX_TI_Common.h"
     33 #include "OMX_TI_Image.h"
     34 #include "General3A_Settings.h"
     35 #include "OMXSceneModeTables.h"
     36 
     37 #include "BaseCameraAdapter.h"
     38 #include "Encoder_libjpeg.h"
     39 #include "DebugUtils.h"
     40 
     41 
     42 extern "C"
     43 {
     44 #include "timm_osal_error.h"
     45 #include "timm_osal_events.h"
     46 #include "timm_osal_trace.h"
     47 #include "timm_osal_semaphores.h"
     48 }
     49 
     50 
     51 namespace android {
     52 
     53 #define Q16_OFFSET                  16
     54 
     55 #define OMX_CMD_TIMEOUT             3000000  //3 sec.
     56 #define OMX_CAPTURE_TIMEOUT         5000000  //5 sec.
     57 
     58 #define FOCUS_THRESHOLD             5 //[s.]
     59 
     60 #define MIN_JPEG_QUALITY            1
     61 #define MAX_JPEG_QUALITY            100
     62 #define EXP_BRACKET_RANGE           10
     63 
     64 #define FOCUS_DIST_SIZE             100
     65 #define FOCUS_DIST_BUFFER_SIZE      500
     66 
     67 #define TOUCH_DATA_SIZE             200
     68 #define DEFAULT_THUMB_WIDTH         160
     69 #define DEFAULT_THUMB_HEIGHT        120
     70 #define FRAME_RATE_FULL_HD          27
     71 #define ZOOM_STAGES                 61
     72 
     73 #define FACE_DETECTION_BUFFER_SIZE  0x1000
     74 #define MAX_NUM_FACES_SUPPORTED     35
     75 
     76 #define EXIF_MODEL_SIZE             100
     77 #define EXIF_MAKE_SIZE              100
     78 #define EXIF_DATE_TIME_SIZE         20
     79 
     80 #define GPS_MIN_DIV                 60
     81 #define GPS_SEC_DIV                 60
     82 #define GPS_SEC_ACCURACY            1000
     83 #define GPS_TIMESTAMP_SIZE          6
     84 #define GPS_DATESTAMP_SIZE          11
     85 #define GPS_REF_SIZE                2
     86 #define GPS_MAPDATUM_SIZE           100
     87 #define GPS_PROCESSING_SIZE         100
     88 #define GPS_VERSION_SIZE            4
     89 #define GPS_NORTH_REF               "N"
     90 #define GPS_SOUTH_REF               "S"
     91 #define GPS_EAST_REF                "E"
     92 #define GPS_WEST_REF                "W"
     93 
     94 /* Default portstartnumber of Camera component */
     95 #define OMX_CAMERA_DEFAULT_START_PORT_NUM 0
     96 
     97 /* Define number of ports for differt domains */
     98 #define OMX_CAMERA_PORT_OTHER_NUM 1
     99 #define OMX_CAMERA_PORT_VIDEO_NUM 4
    100 #define OMX_CAMERA_PORT_IMAGE_NUM 1
    101 #define OMX_CAMERA_PORT_AUDIO_NUM 0
    102 #define OMX_CAMERA_NUM_PORTS (OMX_CAMERA_PORT_OTHER_NUM + OMX_CAMERA_PORT_VIDEO_NUM + OMX_CAMERA_PORT_IMAGE_NUM + OMX_CAMERA_PORT_AUDIO_NUM)
    103 
    104 /* Define start port number for differt domains */
    105 #define OMX_CAMERA_PORT_OTHER_START OMX_CAMERA_DEFAULT_START_PORT_NUM
    106 #define OMX_CAMERA_PORT_VIDEO_START (OMX_CAMERA_PORT_OTHER_START + OMX_CAMERA_PORT_OTHER_NUM)
    107 #define OMX_CAMERA_PORT_IMAGE_START (OMX_CAMERA_PORT_VIDEO_START + OMX_CAMERA_PORT_VIDEO_NUM)
    108 #define OMX_CAMERA_PORT_AUDIO_START (OMX_CAMERA_PORT_IMAGE_START + OMX_CAMERA_PORT_IMAGE_NUM)
    109 
    110 /* Port index for camera component */
    111 #define OMX_CAMERA_PORT_OTHER_IN (OMX_CAMERA_PORT_OTHER_START + 0)
    112 #define OMX_CAMERA_PORT_VIDEO_IN_VIDEO (OMX_CAMERA_PORT_VIDEO_START + 0)
    113 #define OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW (OMX_CAMERA_PORT_VIDEO_START + 1)
    114 #define OMX_CAMERA_PORT_VIDEO_OUT_VIDEO (OMX_CAMERA_PORT_VIDEO_START + 2)
    115 #define OMX_CAMERA_PORT_VIDEO_OUT_MEASUREMENT (OMX_CAMERA_PORT_VIDEO_START + 3)
    116 #define OMX_CAMERA_PORT_IMAGE_OUT_IMAGE (OMX_CAMERA_PORT_IMAGE_START + 0)
    117 
    118 
    119 #define OMX_INIT_STRUCT(_s_, _name_)	\
    120     memset(&(_s_), 0x0, sizeof(_name_));	\
    121     (_s_).nSize = sizeof(_name_);		\
    122     (_s_).nVersion.s.nVersionMajor = 0x1;	\
    123     (_s_).nVersion.s.nVersionMinor = 0x1;	\
    124     (_s_).nVersion.s.nRevision = 0x0;		\
    125     (_s_).nVersion.s.nStep = 0x0
    126 
    127 #define OMX_INIT_STRUCT_PTR(_s_, _name_)   \
    128     memset((_s_), 0x0, sizeof(_name_));         \
    129     (_s_)->nSize = sizeof(_name_);              \
    130     (_s_)->nVersion.s.nVersionMajor = 0x1;      \
    131     (_s_)->nVersion.s.nVersionMinor = 0x1;      \
    132     (_s_)->nVersion.s.nRevision = 0x0;          \
    133     (_s_)->nVersion.s.nStep = 0x0
    134 
    135 #define GOTO_EXIT_IF(_CONDITION,_ERROR) {                                       \
    136     if ((_CONDITION)) {                                                         \
    137         eError = (_ERROR);                                                      \
    138         goto EXIT;                                                              \
    139     }                                                                           \
    140 }
    141 
    142 const int64_t kCameraBufferLatencyNs = 250000000LL; // 250 ms
    143 
    144 ///OMX Specific Functions
    145 static OMX_ERRORTYPE OMXCameraAdapterEventHandler(OMX_IN OMX_HANDLETYPE hComponent,
    146                                         OMX_IN OMX_PTR pAppData,
    147                                         OMX_IN OMX_EVENTTYPE eEvent,
    148                                         OMX_IN OMX_U32 nData1,
    149                                         OMX_IN OMX_U32 nData2,
    150                                         OMX_IN OMX_PTR pEventData);
    151 
    152 static OMX_ERRORTYPE OMXCameraAdapterEmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
    153                                         OMX_IN OMX_PTR pAppData,
    154                                         OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
    155 
    156 static OMX_ERRORTYPE OMXCameraAdapterFillBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
    157                                         OMX_IN OMX_PTR pAppData,
    158                                         OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader);
    159 
    160 struct CapResolution {
    161     size_t width, height;
    162     const char *param;
    163 };
    164 
    165 struct CapPixelformat {
    166     OMX_COLOR_FORMATTYPE pixelformat;
    167     const char *param;
    168 };
    169 
    170 struct CapU32 {
    171     OMX_U32 num;
    172     const char *param;
    173 };
    174 
    175 struct CapU32Pair {
    176     OMX_U32 num1, num2;
    177     const char *param;
    178 };
    179 struct CapS32 {
    180     OMX_S32 num;
    181     const char *param;
    182 };
    183 
    184 typedef CapU32 CapFramerate;
    185 typedef CapU32 CapISO;
    186 typedef CapU32 CapSensorName;
    187 typedef CapS32 CapZoom;
    188 typedef CapS32 CapEVComp;
    189 
    190 /**
    191   * Class which completely abstracts the camera hardware interaction from camera hal
    192   * TODO: Need to list down here, all the message types that will be supported by this class
    193                 Need to implement BufferProvider interface to use AllocateBuffer of OMX if needed
    194   */
    195 class OMXCameraAdapter : public BaseCameraAdapter
    196 {
    197 public:
    198 
    199     /*--------------------Constant declarations----------------------------------------*/
    200     static const int32_t MAX_NO_BUFFERS = 20;
    201 
    202     ///@remarks OMX Camera has six ports - buffer input, time input, preview, image, video, and meta data
    203     static const int MAX_NO_PORTS = 6;
    204 
    205     ///Five second timeout
    206     static const int CAMERA_ADAPTER_TIMEOUT = 5000*1000;
    207 
    208     enum OMXCameraEvents
    209         {
    210         CAMERA_PORT_ENABLE  = 0x1,
    211         CAMERA_PORT_FLUSH   = 0x2,
    212         CAMERA_PORT_DISABLE = 0x4,
    213         };
    214 
    215     enum CaptureMode
    216         {
    217         HIGH_SPEED = 1,
    218         HIGH_QUALITY = 2,
    219         VIDEO_MODE = 3,
    220         HIGH_QUALITY_ZSL = 4,
    221         };
    222 
    223     enum IPPMode
    224         {
    225         IPP_NULL = -1,
    226         IPP_NONE = 0,
    227         IPP_NSF,
    228         IPP_LDC,
    229         IPP_LDCNSF,
    230         };
    231 
    232     enum CodingMode
    233         {
    234         CodingNone = 0,
    235         CodingJPS,
    236         CodingMPO,
    237         CodingRAWJPEG,
    238         CodingRAWMPO,
    239         };
    240 
    241     enum Algorithm3A
    242         {
    243         WHITE_BALANCE_ALGO = 0x1,
    244         EXPOSURE_ALGO = 0x2,
    245         FOCUS_ALGO = 0x4,
    246         };
    247 
    248     enum AlgoPriority
    249         {
    250         FACE_PRIORITY = 0,
    251         REGION_PRIORITY,
    252         };
    253 
    254     enum BrightnessMode
    255         {
    256         BRIGHTNESS_OFF = 0,
    257         BRIGHTNESS_ON,
    258         BRIGHTNESS_AUTO,
    259         };
    260 
    261     enum CaptureSettingsFlags {
    262         SetFormat               = 1 << 0,
    263         SetThumb                = 1 << 1,
    264         SetExpBracket           = 1 << 2,
    265         SetQuality              = 1 << 3,
    266         SetRotation             = 1 << 4,
    267         ECaptureSettingMax,
    268         ECapturesettingsAll = ( ((ECaptureSettingMax -1 ) << 1) -1 ) /// all possible flags raised
    269     };
    270 
    271     class GPSData
    272     {
    273         public:
    274                 int mLongDeg, mLongMin, mLongSec, mLongSecDiv;
    275                 char mLongRef[GPS_REF_SIZE];
    276                 bool mLongValid;
    277                 int mLatDeg, mLatMin, mLatSec, mLatSecDiv;
    278                 char mLatRef[GPS_REF_SIZE];
    279                 bool mLatValid;
    280                 int mAltitude;
    281                 unsigned char mAltitudeRef;
    282                 bool mAltitudeValid;
    283                 char mMapDatum[GPS_MAPDATUM_SIZE];
    284                 bool mMapDatumValid;
    285                 char mVersionId[GPS_VERSION_SIZE];
    286                 bool mVersionIdValid;
    287                 char mProcMethod[GPS_PROCESSING_SIZE];
    288                 bool mProcMethodValid;
    289                 char mDatestamp[GPS_DATESTAMP_SIZE];
    290                 bool mDatestampValid;
    291                 uint32_t mTimeStampHour;
    292                 uint32_t mTimeStampMin;
    293                 uint32_t mTimeStampSec;
    294                 bool mTimeStampValid;
    295     };
    296 
    297     class EXIFData
    298     {
    299         public:
    300             GPSData mGPSData;
    301             bool mMakeValid;
    302             bool mModelValid;
    303     };
    304 
    305     ///Parameters specific to any port of the OMX Camera component
    306     class OMXCameraPortParameters
    307     {
    308         public:
    309             OMX_U32                         mHostBufaddr[MAX_NO_BUFFERS];
    310             OMX_BUFFERHEADERTYPE           *mBufferHeader[MAX_NO_BUFFERS];
    311             OMX_U32                         mWidth;
    312             OMX_U32                         mHeight;
    313             OMX_U32                         mStride;
    314             OMX_U8                          mNumBufs;
    315 
    316             // defines maximum number of buffers our of mNumBufs
    317             // queueable at given moment
    318             OMX_U8                          mMaxQueueable;
    319 
    320             OMX_U32                         mBufSize;
    321             OMX_COLOR_FORMATTYPE            mColorFormat;
    322             OMX_PARAM_VIDEONOISEFILTERTYPE  mVNFMode;
    323             OMX_PARAM_VIDEOYUVRANGETYPE     mYUVRange;
    324             OMX_CONFIG_BOOLEANTYPE          mVidStabParam;
    325             OMX_CONFIG_FRAMESTABTYPE        mVidStabConfig;
    326             OMX_U32                         mCapFrame;
    327             OMX_U32                         mFrameRate;
    328             OMX_S32                         mMinFrameRate;
    329             OMX_S32                         mMaxFrameRate;
    330             CameraFrame::FrameType mImageType;
    331     };
    332 
    333     ///Context of the OMX Camera component
    334     class OMXCameraAdapterComponentContext
    335     {
    336         public:
    337             OMX_HANDLETYPE              mHandleComp;
    338             OMX_U32                     mNumPorts;
    339             OMX_STATETYPE               mState ;
    340             OMX_U32                     mVideoPortIndex;
    341             OMX_U32                     mPrevPortIndex;
    342             OMX_U32                     mImagePortIndex;
    343             OMX_U32                     mMeasurementPortIndex;
    344             OMXCameraPortParameters     mCameraPortParams[MAX_NO_PORTS];
    345     };
    346 
    347 public:
    348 
    349     OMXCameraAdapter(size_t sensor_index);
    350     ~OMXCameraAdapter();
    351 
    352     ///Initialzes the camera adapter creates any resources required
    353     virtual status_t initialize(CameraProperties::Properties*);
    354 
    355     //APIs to configure Camera adapter and get the current parameter set
    356     virtual status_t setParameters(const CameraParameters& params);
    357     virtual void getParameters(CameraParameters& params);
    358 
    359     // API
    360     virtual status_t UseBuffersPreview(void* bufArr, int num);
    361 
    362     //API to flush the buffers for preview
    363     status_t flushBuffers();
    364 
    365     // API
    366     virtual status_t setFormat(OMX_U32 port, OMXCameraPortParameters &cap);
    367 
    368     // Function to get and populate caps from handle
    369     static status_t getCaps(CameraProperties::Properties* props, OMX_HANDLETYPE handle);
    370     static const char* getLUTvalue_OMXtoHAL(int OMXValue, LUTtype LUT);
    371     static int getLUTvalue_HALtoOMX(const char * HalValue, LUTtype LUT);
    372 
    373  OMX_ERRORTYPE OMXCameraAdapterEventHandler(OMX_IN OMX_HANDLETYPE hComponent,
    374                                     OMX_IN OMX_EVENTTYPE eEvent,
    375                                     OMX_IN OMX_U32 nData1,
    376                                     OMX_IN OMX_U32 nData2,
    377                                     OMX_IN OMX_PTR pEventData);
    378 
    379  OMX_ERRORTYPE OMXCameraAdapterEmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
    380                                     OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
    381 
    382  OMX_ERRORTYPE OMXCameraAdapterFillBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
    383                                     OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader);
    384 
    385  static OMX_ERRORTYPE OMXCameraGetHandle(OMX_HANDLETYPE *handle, OMX_PTR pAppData=NULL);
    386 
    387 protected:
    388 
    389     //Parent class method implementation
    390     virtual status_t takePicture();
    391     virtual status_t stopImageCapture();
    392     virtual status_t startBracketing(int range);
    393     virtual status_t stopBracketing();
    394     virtual status_t autoFocus();
    395     virtual status_t cancelAutoFocus();
    396     virtual status_t startSmoothZoom(int targetIdx);
    397     virtual status_t stopSmoothZoom();
    398     virtual status_t startVideoCapture();
    399     virtual status_t stopVideoCapture();
    400     virtual status_t startPreview();
    401     virtual status_t stopPreview();
    402     virtual status_t useBuffers(CameraMode mode, void* bufArr, int num, size_t length, unsigned int queueable);
    403     virtual status_t fillThisBuffer(void* frameBuf, CameraFrame::FrameType frameType);
    404     virtual status_t getFrameSize(size_t &width, size_t &height);
    405     virtual status_t getPictureBufferSize(size_t &length, size_t bufferCount);
    406     virtual status_t getFrameDataSize(size_t &dataFrameSize, size_t bufferCount);
    407     virtual status_t startFaceDetection();
    408     virtual status_t stopFaceDetection();
    409     virtual status_t switchToExecuting();
    410     virtual void onOrientationEvent(uint32_t orientation, uint32_t tilt);
    411 
    412 private:
    413 
    414     status_t doSwitchToExecuting();
    415 
    416     void performCleanupAfterError();
    417 
    418     status_t switchToLoaded();
    419 
    420     OMXCameraPortParameters *getPortParams(CameraFrame::FrameType frameType);
    421 
    422     OMX_ERRORTYPE SignalEvent(OMX_IN OMX_HANDLETYPE hComponent,
    423                                                   OMX_IN OMX_EVENTTYPE eEvent,
    424                                                   OMX_IN OMX_U32 nData1,
    425                                                   OMX_IN OMX_U32 nData2,
    426                                                   OMX_IN OMX_PTR pEventData);
    427     OMX_ERRORTYPE RemoveEvent(OMX_IN OMX_HANDLETYPE hComponent,
    428                               OMX_IN OMX_EVENTTYPE eEvent,
    429                               OMX_IN OMX_U32 nData1,
    430                               OMX_IN OMX_U32 nData2,
    431                               OMX_IN OMX_PTR pEventData);
    432 
    433     status_t RegisterForEvent(OMX_IN OMX_HANDLETYPE hComponent,
    434                                           OMX_IN OMX_EVENTTYPE eEvent,
    435                                           OMX_IN OMX_U32 nData1,
    436                                           OMX_IN OMX_U32 nData2,
    437                                           OMX_IN Semaphore &semaphore);
    438 
    439     status_t setPictureRotation(unsigned int degree);
    440     status_t setSensorOrientation(unsigned int degree);
    441     status_t setImageQuality(unsigned int quality);
    442     status_t setThumbnailParams(unsigned int width, unsigned int height, unsigned int quality);
    443 
    444     //EXIF
    445     status_t setParametersEXIF(const CameraParameters &params,
    446                                BaseCameraAdapter::AdapterState state);
    447     status_t convertGPSCoord(double coord, int &deg, int &min, int &sec, int &secDivisor);
    448     status_t setupEXIF();
    449     status_t setupEXIF_libjpeg(ExifElementsTable*);
    450 
    451     //Focus functionality
    452     status_t doAutoFocus();
    453     status_t stopAutoFocus();
    454     status_t checkFocus(OMX_PARAM_FOCUSSTATUSTYPE *eFocusStatus);
    455     status_t returnFocusStatus(bool timeoutReached);
    456     status_t getFocusMode(OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE &focusMode);
    457 
    458 
    459     //Focus distances
    460     status_t setParametersFocus(const CameraParameters &params,
    461                                 BaseCameraAdapter::AdapterState state);
    462     status_t addFocusDistances(OMX_U32 &near,
    463                                OMX_U32 &optimal,
    464                                OMX_U32 &far,
    465                                CameraParameters& params);
    466     status_t encodeFocusDistance(OMX_U32 dist, char *buffer, size_t length);
    467     status_t getFocusDistances(OMX_U32 &near,OMX_U32 &optimal, OMX_U32 &far);
    468 
    469     //VSTAB and VNF Functionality
    470     status_t enableVideoNoiseFilter(bool enable);
    471     status_t enableVideoStabilization(bool enable);
    472 
    473     //Digital zoom
    474     status_t setParametersZoom(const CameraParameters &params,
    475                                BaseCameraAdapter::AdapterState state);
    476     status_t doZoom(int index);
    477     status_t advanceZoom();
    478 
    479     //3A related parameters
    480     status_t setParameters3A(const CameraParameters &params,
    481                              BaseCameraAdapter::AdapterState state);
    482 
    483     // scene modes
    484     status_t setScene(Gen3A_settings& Gen3A);
    485     // returns pointer to SceneModesEntry from the LUT for camera given 'name' and 'scene'
    486     static const SceneModesEntry* getSceneModeEntry(const char* name, OMX_SCENEMODETYPE scene);
    487 
    488 
    489     //Flash modes
    490     status_t setFlashMode(Gen3A_settings& Gen3A);
    491     status_t getFlashMode(Gen3A_settings& Gen3A);
    492 
    493     // Focus modes
    494     status_t setFocusMode(Gen3A_settings& Gen3A);
    495     status_t getFocusMode(Gen3A_settings& Gen3A);
    496 
    497     //Exposure Modes
    498     status_t setExposureMode(Gen3A_settings& Gen3A);
    499     status_t setEVCompensation(Gen3A_settings& Gen3A);
    500     status_t setWBMode(Gen3A_settings& Gen3A);
    501     status_t setFlicker(Gen3A_settings& Gen3A);
    502     status_t setBrightness(Gen3A_settings& Gen3A);
    503     status_t setContrast(Gen3A_settings& Gen3A);
    504     status_t setSharpness(Gen3A_settings& Gen3A);
    505     status_t setSaturation(Gen3A_settings& Gen3A);
    506     status_t setISO(Gen3A_settings& Gen3A);
    507     status_t setEffect(Gen3A_settings& Gen3A);
    508     status_t setMeteringAreas(Gen3A_settings& Gen3A);
    509 
    510     status_t getEVCompensation(Gen3A_settings& Gen3A);
    511     status_t getWBMode(Gen3A_settings& Gen3A);
    512     status_t getSharpness(Gen3A_settings& Gen3A);
    513     status_t getSaturation(Gen3A_settings& Gen3A);
    514     status_t getISO(Gen3A_settings& Gen3A);
    515 
    516     // 3A locks
    517     status_t setExposureLock(Gen3A_settings& Gen3A);
    518     status_t setFocusLock(Gen3A_settings& Gen3A);
    519     status_t setWhiteBalanceLock(Gen3A_settings& Gen3A);
    520     status_t set3ALock(OMX_BOOL toggleExp, OMX_BOOL toggleWb, OMX_BOOL toggleFocus);
    521 
    522     //API to set FrameRate using VFR interface
    523     status_t setVFramerate(OMX_U32 minFrameRate,OMX_U32 maxFrameRate);
    524 
    525     status_t setParametersAlgo(const CameraParameters &params,
    526                                BaseCameraAdapter::AdapterState state);
    527 
    528     //Noise filtering
    529     status_t setNSF(OMXCameraAdapter::IPPMode mode);
    530 
    531     //LDC
    532     status_t setLDC(OMXCameraAdapter::IPPMode mode);
    533 
    534     //GLBCE
    535     status_t setGLBCE(OMXCameraAdapter::BrightnessMode mode);
    536 
    537     //GBCE
    538     status_t setGBCE(OMXCameraAdapter::BrightnessMode mode);
    539 
    540     status_t printComponentVersion(OMX_HANDLETYPE handle);
    541 
    542     //Touch AF
    543     status_t setTouchFocus();
    544 
    545     //Face detection
    546     status_t setParametersFD(const CameraParameters &params,
    547                              BaseCameraAdapter::AdapterState state);
    548     status_t updateFocusDistances(CameraParameters &params);
    549     status_t setFaceDetection(bool enable, OMX_U32 orientation);
    550     status_t detectFaces(OMX_BUFFERHEADERTYPE* pBuffHeader,
    551                          sp<CameraFDResult> &result,
    552                          size_t previewWidth,
    553                          size_t previewHeight);
    554     status_t encodeFaceCoordinates(const OMX_FACEDETECTIONTYPE *faceData,
    555                                    camera_frame_metadata_t **pFaces,
    556                                    size_t previewWidth,
    557                                    size_t previewHeight);
    558     void pauseFaceDetection(bool pause);
    559 
    560     //3A Algorithms priority configuration
    561     status_t setAlgoPriority(AlgoPriority priority, Algorithm3A algo, bool enable);
    562 
    563     //Sensor overclocking
    564     status_t setSensorOverclock(bool enable);
    565 
    566     // Utility methods for OMX Capabilities
    567     static status_t insertCapabilities(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    568     static status_t encodeSizeCap(OMX_TI_CAPRESTYPE&, const CapResolution *, size_t, char *, size_t);
    569     static status_t encodeISOCap(OMX_U32, const CapISO*, size_t, char*, size_t);
    570     static size_t encodeZoomCap(OMX_S32, const CapZoom*, size_t, char*, size_t);
    571     static status_t encodeFramerateCap(OMX_U32, OMX_U32, const CapFramerate*, size_t, char*, size_t);
    572     static status_t encodeVFramerateCap(OMX_TI_CAPTYPE&, const CapU32Pair*, size_t, char*, char*, size_t);
    573     static status_t encodePixelformatCap(OMX_COLOR_FORMATTYPE,
    574                                          const CapPixelformat*,
    575                                          size_t,
    576                                          char*,
    577                                          size_t);
    578     static status_t insertImageSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    579     static status_t insertPreviewSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    580     static status_t insertThumbSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    581     static status_t insertZoomStages(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    582     static status_t insertImageFormats(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    583     static status_t insertPreviewFormats(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    584     static status_t insertFramerates(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    585     static status_t insertVFramerates(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    586     static status_t insertEVs(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    587     static status_t insertISOModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    588     static status_t insertIPPModes(CameraProperties::Properties*, OMX_TI_CAPTYPE &);
    589     static status_t insertWBModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    590     static status_t insertEffects(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    591     static status_t insertExpModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    592     static status_t insertSceneModes(CameraProperties::Properties*, OMX_TI_CAPTYPE &);
    593     static status_t insertFocusModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    594     static status_t insertFlickerModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    595     static status_t insertFlashModes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    596     static status_t insertSenMount(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    597     static status_t insertDefaults(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    598     static status_t insertLocks(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    599     static status_t insertAreas(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    600     static status_t insertVideoSizes(CameraProperties::Properties*, OMX_TI_CAPTYPE&);
    601 
    602     status_t setParametersCapture(const CameraParameters &params,
    603                                   BaseCameraAdapter::AdapterState state);
    604 
    605     //Exposure Bracketing
    606     status_t setExposureBracketing(int *evValues, size_t evCount, size_t frameCount);
    607     status_t parseExpRange(const char *rangeStr, int * expRange, size_t count, size_t &validEntries);
    608 
    609     //Temporal Bracketing
    610     status_t doBracketing(OMX_BUFFERHEADERTYPE *pBuffHeader, CameraFrame::FrameType typeOfFrame);
    611     status_t sendBracketFrames();
    612 
    613     // Image Capture Service
    614     status_t startImageCapture();
    615     status_t disableImagePort();
    616 
    617     //Shutter callback notifications
    618     status_t setShutterCallback(bool enabled);
    619 
    620     //Sets eithter HQ or HS mode and the frame count
    621     status_t setCaptureMode(OMXCameraAdapter::CaptureMode mode);
    622     status_t UseBuffersCapture(void* bufArr, int num);
    623     status_t UseBuffersPreviewData(void* bufArr, int num);
    624 
    625     //Used for calculation of the average frame rate during preview
    626     status_t recalculateFPS();
    627 
    628     //Helper method for initializing a CameFrame object
    629     status_t initCameraFrame(CameraFrame &frame, OMX_IN OMX_BUFFERHEADERTYPE *pBuffHeader, int typeOfFrame, OMXCameraPortParameters *port);
    630 
    631     //Sends the incoming OMX buffer header to subscribers
    632     status_t sendFrame(CameraFrame &frame);
    633 
    634     status_t sendCallBacks(CameraFrame frame, OMX_IN OMX_BUFFERHEADERTYPE *pBuffHeader, unsigned int mask, OMXCameraPortParameters *port);
    635 
    636     status_t apply3Asettings( Gen3A_settings& Gen3A );
    637     status_t apply3ADefaults(Gen3A_settings &Gen3A);
    638 
    639     // AutoConvergence
    640     status_t setAutoConvergence(OMX_TI_AUTOCONVERGENCEMODETYPE pACMode, OMX_S32 pManualConverence);
    641     status_t getAutoConvergence(OMX_TI_AUTOCONVERGENCEMODETYPE *pACMode, OMX_S32 *pManualConverence);
    642 
    643     OMX_OTHER_EXTRADATATYPE *getExtradata(OMX_OTHER_EXTRADATATYPE *extraData, OMX_EXTRADATATYPE type);
    644 
    645     class CommandHandler : public Thread {
    646         public:
    647             CommandHandler(OMXCameraAdapter* ca)
    648                 : Thread(false), mCameraAdapter(ca) { }
    649 
    650             virtual bool threadLoop() {
    651                 bool ret;
    652                 ret = Handler();
    653                 return ret;
    654             }
    655 
    656             status_t put(TIUTILS::Message* msg){
    657                 Mutex::Autolock lock(mLock);
    658                 return mCommandMsgQ.put(msg);
    659             }
    660 
    661             void clearCommandQ()
    662                 {
    663                 Mutex::Autolock lock(mLock);
    664                 mCommandMsgQ.clear();
    665                 }
    666 
    667             enum {
    668                 COMMAND_EXIT = -1,
    669                 CAMERA_START_IMAGE_CAPTURE = 0,
    670                 CAMERA_PERFORM_AUTOFOCUS = 1,
    671                 CAMERA_SWITCH_TO_EXECUTING
    672             };
    673 
    674         private:
    675             bool Handler();
    676             TIUTILS::MessageQueue mCommandMsgQ;
    677             OMXCameraAdapter* mCameraAdapter;
    678             Mutex mLock;
    679     };
    680     sp<CommandHandler> mCommandHandler;
    681 
    682 public:
    683 
    684     class OMXCallbackHandler : public Thread {
    685         public:
    686         OMXCallbackHandler(OMXCameraAdapter* ca)
    687             : Thread(false), mCameraAdapter(ca) { }
    688 
    689         virtual bool threadLoop() {
    690             bool ret;
    691             ret = Handler();
    692             return ret;
    693         }
    694 
    695         status_t put(TIUTILS::Message* msg){
    696             Mutex::Autolock lock(mLock);
    697             return mCommandMsgQ.put(msg);
    698         }
    699 
    700         void clearCommandQ()
    701             {
    702             Mutex::Autolock lock(mLock);
    703             mCommandMsgQ.clear();
    704             }
    705 
    706         enum {
    707             COMMAND_EXIT = -1,
    708             CAMERA_FILL_BUFFER_DONE,
    709         };
    710 
    711     private:
    712         bool Handler();
    713         TIUTILS::MessageQueue mCommandMsgQ;
    714         OMXCameraAdapter* mCameraAdapter;
    715         Mutex mLock;
    716     };
    717 
    718     sp<OMXCallbackHandler> mOMXCallbackHandler;
    719 
    720 private:
    721 
    722     //AF callback
    723     status_t setFocusCallback(bool enabled);
    724 
    725     //OMX Capabilities data
    726     static const CapResolution mImageCapRes [];
    727     static const CapResolution mPreviewRes [];
    728     static const CapResolution mThumbRes [];
    729     static const CapPixelformat mPixelformats [];
    730     static const CapFramerate mFramerates [];
    731     static const CapU32 mSensorNames[] ;
    732     static const CapZoom mZoomStages [];
    733     static const CapEVComp mEVCompRanges [];
    734     static const CapISO mISOStages [];
    735     static const CapU32Pair mVarFramerates [];
    736 
    737     // OMX Camera defaults
    738     static const char DEFAULT_ANTIBANDING[];
    739     static const char DEFAULT_BRIGHTNESS[];
    740     static const char DEFAULT_CONTRAST[];
    741     static const char DEFAULT_EFFECT[];
    742     static const char DEFAULT_EV_COMPENSATION[];
    743     static const char DEFAULT_EV_STEP[];
    744     static const char DEFAULT_EXPOSURE_MODE[];
    745     static const char DEFAULT_FLASH_MODE[];
    746     static const char DEFAULT_FOCUS_MODE_PREFERRED[];
    747     static const char DEFAULT_FOCUS_MODE[];
    748     static const char DEFAULT_FRAMERATE_RANGE_IMAGE[];
    749     static const char DEFAULT_FRAMERATE_RANGE_VIDEO[];
    750     static const char DEFAULT_IPP[];
    751     static const char DEFAULT_GBCE[];
    752     static const char DEFAULT_ISO_MODE[];
    753     static const char DEFAULT_JPEG_QUALITY[];
    754     static const char DEFAULT_THUMBNAIL_QUALITY[];
    755     static const char DEFAULT_THUMBNAIL_SIZE[];
    756     static const char DEFAULT_PICTURE_FORMAT[];
    757     static const char DEFAULT_PICTURE_SIZE[];
    758     static const char DEFAULT_PREVIEW_FORMAT[];
    759     static const char DEFAULT_FRAMERATE[];
    760     static const char DEFAULT_PREVIEW_SIZE[];
    761     static const char DEFAULT_NUM_PREV_BUFS[];
    762     static const char DEFAULT_NUM_PIC_BUFS[];
    763     static const char DEFAULT_MAX_FOCUS_AREAS[];
    764     static const char DEFAULT_SATURATION[];
    765     static const char DEFAULT_SCENE_MODE[];
    766     static const char DEFAULT_SHARPNESS[];
    767     static const char DEFAULT_VSTAB[];
    768     static const char DEFAULT_VSTAB_SUPPORTED[];
    769     static const char DEFAULT_WB[];
    770     static const char DEFAULT_ZOOM[];
    771     static const char DEFAULT_MAX_FD_HW_FACES[];
    772     static const char DEFAULT_MAX_FD_SW_FACES[];
    773     static const char DEFAULT_AE_LOCK[];
    774     static const char DEFAULT_AWB_LOCK[];
    775     static const char DEFAULT_MAX_NUM_METERING_AREAS[];
    776     static const char DEFAULT_LOCK_SUPPORTED[];
    777     static const char DEFAULT_LOCK_UNSUPPORTED[];
    778     static const char DEFAULT_FOCAL_LENGTH_PRIMARY[];
    779     static const char DEFAULT_FOCAL_LENGTH_SECONDARY[];
    780     static const char DEFAULT_HOR_ANGLE[];
    781     static const char DEFAULT_VER_ANGLE[];
    782     static const char DEFAULT_VIDEO_SNAPSHOT_SUPPORTED[];
    783     static const char DEFAULT_VIDEO_SIZE[];
    784     static const char DEFAULT_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[];
    785     static const size_t MAX_FOCUS_AREAS;
    786 
    787     OMX_VERSIONTYPE mCompRevision;
    788 
    789     //OMX Component UUID
    790     OMX_UUIDTYPE mCompUUID;
    791 
    792     //Current Focus distances
    793     char mFocusDistNear[FOCUS_DIST_SIZE];
    794     char mFocusDistOptimal[FOCUS_DIST_SIZE];
    795     char mFocusDistFar[FOCUS_DIST_SIZE];
    796     char mFocusDistBuffer[FOCUS_DIST_BUFFER_SIZE];
    797 
    798     // Current Focus areas
    799     Vector< sp<CameraArea> > mFocusAreas;
    800     mutable Mutex mFocusAreasLock;
    801 
    802     // Current Metering areas
    803     Vector< sp<CameraArea> > mMeteringAreas;
    804     mutable Mutex mMeteringAreasLock;
    805 
    806     CaptureMode mCapMode;
    807     size_t mBurstFrames;
    808     size_t mCapturedFrames;
    809 
    810     bool mMeasurementEnabled;
    811 
    812     //Exposure Bracketing
    813     int mExposureBracketingValues[EXP_BRACKET_RANGE];
    814     size_t mExposureBracketingValidEntries;
    815 
    816     mutable Mutex mFaceDetectionLock;
    817     //Face detection status
    818     bool mFaceDetectionRunning;
    819     bool mFaceDetectionPaused;
    820 
    821     camera_face_t  faceDetectionLastOutput [MAX_NUM_FACES_SUPPORTED];
    822     int faceDetectionNumFacesLastOutput;
    823 
    824     //Geo-tagging
    825     EXIFData mEXIFData;
    826 
    827     //Image post-processing
    828     IPPMode mIPP;
    829 
    830     //jpeg Picture Quality
    831     unsigned int mPictureQuality;
    832 
    833     //thumbnail resolution
    834     unsigned int mThumbWidth, mThumbHeight;
    835 
    836     //thumbnail quality
    837     unsigned int mThumbQuality;
    838 
    839     //variables holding the estimated framerate
    840     float mFPS, mLastFPS;
    841 
    842     //automatically disable AF after a given amount of frames
    843     unsigned int mFocusThreshold;
    844 
    845     //This is needed for the CTS tests. They falsely assume, that during
    846     //smooth zoom the current zoom stage will not change within the
    847     //zoom callback scope, which in a real world situation is not always the
    848     //case. This variable will "simulate" the expected behavior
    849     unsigned int mZoomParameterIdx;
    850 
    851     //current zoom
    852     Mutex mZoomLock;
    853     unsigned int mCurrentZoomIdx, mTargetZoomIdx, mPreviousZoomIndx;
    854     bool mZoomUpdating, mZoomUpdate;
    855     int mZoomInc;
    856     bool mReturnZoomStatus;
    857     static const int32_t ZOOM_STEPS [];
    858 
    859      //local copy
    860     OMX_VERSIONTYPE mLocalVersionParam;
    861 
    862     unsigned int mPending3Asettings;
    863     Mutex m3ASettingsUpdateLock;
    864     Gen3A_settings mParameters3A;
    865 
    866     OMX_TI_CONFIG_3A_FACE_PRIORITY mFacePriority;
    867     OMX_TI_CONFIG_3A_REGION_PRIORITY mRegionPriority;
    868 
    869     CameraParameters mParams;
    870     CameraProperties::Properties* mCapabilities;
    871     unsigned int mPictureRotation;
    872     bool mWaitingForSnapshot;
    873     int mSnapshotCount;
    874     bool mCaptureConfigured;
    875     unsigned int mPendingCaptureSettings;
    876 
    877     //Temporal bracketing management data
    878     mutable Mutex mBracketingLock;
    879     bool *mBracketingBuffersQueued;
    880     int mBracketingBuffersQueuedCount;
    881     int mLastBracetingBufferIdx;
    882     bool mBracketingEnabled;
    883     int mBracketingRange;
    884 
    885     CameraParameters mParameters;
    886     OMXCameraAdapterComponentContext mCameraAdapterParameters;
    887     bool mFirstTimeInit;
    888 
    889     ///Semaphores used internally
    890     Semaphore mDoAFSem;
    891     Semaphore mInitSem;
    892     Semaphore mFlushSem;
    893     Semaphore mUsePreviewDataSem;
    894     Semaphore mUsePreviewSem;
    895     Semaphore mUseCaptureSem;
    896     Semaphore mStartPreviewSem;
    897     Semaphore mStopPreviewSem;
    898     Semaphore mStartCaptureSem;
    899     Semaphore mStopCaptureSem;
    900     Semaphore mSwitchToLoadedSem;
    901     Semaphore mSwitchToExecSem;
    902 
    903     mutable Mutex mStateSwitchLock;
    904 
    905     Vector<struct TIUTILS::Message *> mEventSignalQ;
    906     Mutex mEventLock;
    907 
    908     OMX_STATETYPE mComponentState;
    909 
    910     bool mVnfEnabled;
    911     bool mVstabEnabled;
    912 
    913     int mSensorOrientation;
    914     int mDeviceOrientation;
    915     bool mSensorOverclock;
    916 
    917     //Indicates if we should leave
    918     //OMX_Executing state during
    919     //stop-/startPreview
    920     bool mOMXStateSwitch;
    921 
    922     int mFrameCount;
    923     int mLastFrameCount;
    924     unsigned int mIter;
    925     nsecs_t mLastFPSTime;
    926     Mutex mFrameCountMutex;
    927     Condition mFirstFrameCondition;
    928 
    929     size_t mSensorIndex;
    930     CodingMode mCodingMode;
    931 
    932     // Time source delta of ducati & system time
    933     OMX_TICKS mTimeSourceDelta;
    934     bool onlyOnce;
    935 
    936     Semaphore mCaptureSem;
    937     bool mCaptureSignalled;
    938 
    939     OMX_BOOL mUserSetExpLock;
    940     OMX_BOOL mUserSetWbLock;
    941 
    942 };
    943 }; //// namespace
    944 #endif //OMX_CAMERA_ADAPTER_H
    945 
    946