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 ¶ms, 446 BaseCameraAdapter::AdapterState state); 447 status_t convertGPSCoord(double coord, int °, 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 ¶ms, 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 ¶ms, 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 ¶ms, 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 ¶ms, 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 ¶ms, 547 BaseCameraAdapter::AdapterState state); 548 status_t updateFocusDistances(CameraParameters ¶ms); 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 ¶ms, 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 class CommandHandler : public Thread { 644 public: 645 CommandHandler(OMXCameraAdapter* ca) 646 : Thread(false), mCameraAdapter(ca) { } 647 648 virtual bool threadLoop() { 649 bool ret; 650 ret = Handler(); 651 return ret; 652 } 653 654 status_t put(TIUTILS::Message* msg){ 655 return mCommandMsgQ.put(msg); 656 } 657 658 enum { 659 COMMAND_EXIT = -1, 660 CAMERA_START_IMAGE_CAPTURE = 0, 661 CAMERA_PERFORM_AUTOFOCUS = 1, 662 CAMERA_SWITCH_TO_EXECUTING 663 }; 664 665 private: 666 bool Handler(); 667 TIUTILS::MessageQueue mCommandMsgQ; 668 OMXCameraAdapter* mCameraAdapter; 669 }; 670 sp<CommandHandler> mCommandHandler; 671 672 public: 673 674 class OMXCallbackHandler : public Thread { 675 public: 676 OMXCallbackHandler(OMXCameraAdapter* ca) 677 : Thread(false), mCameraAdapter(ca) { } 678 679 virtual bool threadLoop() { 680 bool ret; 681 ret = Handler(); 682 return ret; 683 } 684 685 status_t put(TIUTILS::Message* msg){ 686 return mCommandMsgQ.put(msg); 687 } 688 689 enum { 690 COMMAND_EXIT = -1, 691 CAMERA_FILL_BUFFER_DONE, 692 }; 693 694 private: 695 bool Handler(); 696 TIUTILS::MessageQueue mCommandMsgQ; 697 OMXCameraAdapter* mCameraAdapter; 698 }; 699 700 sp<OMXCallbackHandler> mOMXCallbackHandler; 701 702 private: 703 704 //AF callback 705 status_t setFocusCallback(bool enabled); 706 707 //OMX Capabilities data 708 static const CapResolution mImageCapRes []; 709 static const CapResolution mPreviewRes []; 710 static const CapResolution mThumbRes []; 711 static const CapPixelformat mPixelformats []; 712 static const CapFramerate mFramerates []; 713 static const CapU32 mSensorNames[] ; 714 static const CapZoom mZoomStages []; 715 static const CapEVComp mEVCompRanges []; 716 static const CapISO mISOStages []; 717 static const CapU32Pair mVarFramerates []; 718 719 // OMX Camera defaults 720 static const char DEFAULT_ANTIBANDING[]; 721 static const char DEFAULT_BRIGHTNESS[]; 722 static const char DEFAULT_CONTRAST[]; 723 static const char DEFAULT_EFFECT[]; 724 static const char DEFAULT_EV_COMPENSATION[]; 725 static const char DEFAULT_EV_STEP[]; 726 static const char DEFAULT_EXPOSURE_MODE[]; 727 static const char DEFAULT_FLASH_MODE[]; 728 static const char DEFAULT_FOCUS_MODE_PREFERRED[]; 729 static const char DEFAULT_FOCUS_MODE[]; 730 static const char DEFAULT_FRAMERATE_RANGE_IMAGE[]; 731 static const char DEFAULT_FRAMERATE_RANGE_VIDEO[]; 732 static const char DEFAULT_IPP[]; 733 static const char DEFAULT_GBCE[]; 734 static const char DEFAULT_ISO_MODE[]; 735 static const char DEFAULT_JPEG_QUALITY[]; 736 static const char DEFAULT_THUMBNAIL_QUALITY[]; 737 static const char DEFAULT_THUMBNAIL_SIZE[]; 738 static const char DEFAULT_PICTURE_FORMAT[]; 739 static const char DEFAULT_PICTURE_SIZE[]; 740 static const char DEFAULT_PREVIEW_FORMAT[]; 741 static const char DEFAULT_FRAMERATE[]; 742 static const char DEFAULT_PREVIEW_SIZE[]; 743 static const char DEFAULT_NUM_PREV_BUFS[]; 744 static const char DEFAULT_NUM_PIC_BUFS[]; 745 static const char DEFAULT_MAX_FOCUS_AREAS[]; 746 static const char DEFAULT_SATURATION[]; 747 static const char DEFAULT_SCENE_MODE[]; 748 static const char DEFAULT_SHARPNESS[]; 749 static const char DEFAULT_VSTAB[]; 750 static const char DEFAULT_VSTAB_SUPPORTED[]; 751 static const char DEFAULT_WB[]; 752 static const char DEFAULT_ZOOM[]; 753 static const char DEFAULT_MAX_FD_HW_FACES[]; 754 static const char DEFAULT_MAX_FD_SW_FACES[]; 755 static const char DEFAULT_AE_LOCK[]; 756 static const char DEFAULT_AWB_LOCK[]; 757 static const char DEFAULT_MAX_NUM_METERING_AREAS[]; 758 static const char DEFAULT_LOCK_SUPPORTED[]; 759 static const char DEFAULT_LOCK_UNSUPPORTED[]; 760 static const char DEFAULT_FOCAL_LENGTH_PRIMARY[]; 761 static const char DEFAULT_FOCAL_LENGTH_SECONDARY[]; 762 static const char DEFAULT_HOR_ANGLE[]; 763 static const char DEFAULT_VER_ANGLE[]; 764 static const char DEFAULT_VIDEO_SNAPSHOT_SUPPORTED[]; 765 static const char DEFAULT_VIDEO_SIZE[]; 766 static const char DEFAULT_PREFERRED_PREVIEW_SIZE_FOR_VIDEO[]; 767 static const size_t MAX_FOCUS_AREAS; 768 769 OMX_VERSIONTYPE mCompRevision; 770 771 //OMX Component UUID 772 OMX_UUIDTYPE mCompUUID; 773 774 //Current Focus distances 775 char mFocusDistNear[FOCUS_DIST_SIZE]; 776 char mFocusDistOptimal[FOCUS_DIST_SIZE]; 777 char mFocusDistFar[FOCUS_DIST_SIZE]; 778 char mFocusDistBuffer[FOCUS_DIST_BUFFER_SIZE]; 779 780 // Current Focus areas 781 Vector< sp<CameraArea> > mFocusAreas; 782 mutable Mutex mFocusAreasLock; 783 784 // Current Metering areas 785 Vector< sp<CameraArea> > mMeteringAreas; 786 mutable Mutex mMeteringAreasLock; 787 788 CaptureMode mCapMode; 789 size_t mBurstFrames; 790 size_t mCapturedFrames; 791 792 bool mMeasurementEnabled; 793 794 //Exposure Bracketing 795 int mExposureBracketingValues[EXP_BRACKET_RANGE]; 796 size_t mExposureBracketingValidEntries; 797 798 mutable Mutex mFaceDetectionLock; 799 //Face detection status 800 bool mFaceDetectionRunning; 801 bool mFaceDetectionPaused; 802 803 camera_face_t faceDetectionLastOutput [MAX_NUM_FACES_SUPPORTED]; 804 int faceDetectionNumFacesLastOutput; 805 806 //Geo-tagging 807 EXIFData mEXIFData; 808 809 //Image post-processing 810 IPPMode mIPP; 811 812 //jpeg Picture Quality 813 unsigned int mPictureQuality; 814 815 //thumbnail resolution 816 unsigned int mThumbWidth, mThumbHeight; 817 818 //thumbnail quality 819 unsigned int mThumbQuality; 820 821 //variables holding the estimated framerate 822 float mFPS, mLastFPS; 823 824 //automatically disable AF after a given amount of frames 825 unsigned int mFocusThreshold; 826 827 //This is needed for the CTS tests. They falsely assume, that during 828 //smooth zoom the current zoom stage will not change within the 829 //zoom callback scope, which in a real world situation is not always the 830 //case. This variable will "simulate" the expected behavior 831 unsigned int mZoomParameterIdx; 832 833 //current zoom 834 Mutex mZoomLock; 835 unsigned int mCurrentZoomIdx, mTargetZoomIdx, mPreviousZoomIndx; 836 bool mZoomUpdating, mZoomUpdate; 837 int mZoomInc; 838 bool mReturnZoomStatus; 839 static const int32_t ZOOM_STEPS []; 840 841 //local copy 842 OMX_VERSIONTYPE mLocalVersionParam; 843 844 unsigned int mPending3Asettings; 845 Mutex m3ASettingsUpdateLock; 846 Gen3A_settings mParameters3A; 847 848 OMX_TI_CONFIG_3A_FACE_PRIORITY mFacePriority; 849 OMX_TI_CONFIG_3A_REGION_PRIORITY mRegionPriority; 850 851 CameraParameters mParams; 852 CameraProperties::Properties* mCapabilities; 853 unsigned int mPictureRotation; 854 bool mWaitingForSnapshot; 855 int mSnapshotCount; 856 bool mCaptureConfigured; 857 unsigned int mPendingCaptureSettings; 858 859 //Temporal bracketing management data 860 mutable Mutex mBracketingLock; 861 bool *mBracketingBuffersQueued; 862 int mBracketingBuffersQueuedCount; 863 int mLastBracetingBufferIdx; 864 bool mBracketingEnabled; 865 int mBracketingRange; 866 867 CameraParameters mParameters; 868 OMXCameraAdapterComponentContext mCameraAdapterParameters; 869 bool mFirstTimeInit; 870 871 ///Semaphores used internally 872 Semaphore mDoAFSem; 873 Semaphore mInitSem; 874 Semaphore mFlushSem; 875 Semaphore mUsePreviewDataSem; 876 Semaphore mUsePreviewSem; 877 Semaphore mUseCaptureSem; 878 Semaphore mStartPreviewSem; 879 Semaphore mStopPreviewSem; 880 Semaphore mStartCaptureSem; 881 Semaphore mStopCaptureSem; 882 Semaphore mSwitchToLoadedSem; 883 Semaphore mSwitchToExecSem; 884 885 mutable Mutex mStateSwitchLock; 886 887 Vector<struct TIUTILS::Message *> mEventSignalQ; 888 Mutex mEventLock; 889 890 OMX_STATETYPE mComponentState; 891 892 bool mVnfEnabled; 893 bool mVstabEnabled; 894 895 int mSensorOrientation; 896 int mDeviceOrientation; 897 bool mSensorOverclock; 898 899 //Indicates if we should leave 900 //OMX_Executing state during 901 //stop-/startPreview 902 bool mOMXStateSwitch; 903 904 int mFrameCount; 905 int mLastFrameCount; 906 unsigned int mIter; 907 nsecs_t mLastFPSTime; 908 Mutex mFrameCountMutex; 909 Condition mFirstFrameCondition; 910 911 size_t mSensorIndex; 912 CodingMode mCodingMode; 913 914 // Time source delta of ducati & system time 915 OMX_TICKS mTimeSourceDelta; 916 bool onlyOnce; 917 918 Semaphore mCaptureSem; 919 bool mCaptureSignalled; 920 921 OMX_BOOL mUserSetExpLock; 922 OMX_BOOL mUserSetWbLock; 923 924 }; 925 }; //// namespace 926 #endif //OMX_CAMERA_ADAPTER_H 927 928