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