OMXCapabilities.cpp revision bd9754a1b2c8d5e0a8788d0e42d018857bfef7a7
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* @file OMXCap.cpp 19* 20* This file implements the OMX Capabilities feature. 21* 22*/ 23 24#include "CameraHal.h" 25#include "OMXCameraAdapter.h" 26#include "ErrorUtils.h" 27#include "TICameraParameters.h" 28 29extern "C" { 30#include "memmgr.h" 31} 32 33namespace android { 34 35#undef LOG_TAG 36 37// Maintain a separate tag for OMXCameraAdapter logs to isolate issues OMX specific 38#define LOG_TAG "CameraHAL" 39 40/************************************ 41 * global constants and variables 42 *************************************/ 43 44#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0])) 45#define FPS_MIN 5 46#define FPS_STEP 5 47#define FPS_RANGE_STEP 5 48 49static const char PARAM_SEP[] = ","; 50static const int PARAM_SEP_CHAR = ','; 51static const uint32_t VFR_OFFSET = 8; 52static const char VFR_BACKET_START[] = "("; 53static const char VFR_BRACKET_END[] = ")"; 54static const char FRAMERATE_COUNT = 10; 55 56/**** look up tables to translate OMX Caps to Parameter ****/ 57 58const CapResolution OMXCameraAdapter::mImageCapRes [] = { 59 { 4032, 3024, "4032x3024" }, 60 { 4000, 3000, "4000x3000" }, 61 { 3648, 2736, "3648x2736" }, 62 { 3264, 2448, "3264x2448" }, 63 { 2592, 1944, "2592x1944" }, 64 { 2048, 1536, "2048x1536" }, 65 { 1600, 1200, "1600x1200" }, 66 { 1280, 1024, "1280x1024" }, 67 { 1152, 864, "1152x864" }, 68 { 1280, 960, "1280x960" }, 69 { 640, 480, "640x480" }, 70 { 320, 240, "320x240" }, 71}; 72 73const CapResolution OMXCameraAdapter::mPreviewRes [] = { 74 { 1920, 1080, "1920x1080" }, 75 { 1280, 720, "1280x720" }, 76 { 800, 480, "800x480" }, 77 { 720, 576, "720x576" }, 78 { 720, 480, "720x480" }, 79 { 768, 576, "768x576" }, 80 { 640, 480, "640x480" }, 81 { 320, 240, "320x240" }, 82 { 352, 288, "352x288" }, 83 { 240, 160, "240x160" }, 84 { 176, 144, "176x144" }, 85 { 128, 96, "128x96" }, 86}; 87 88const CapResolution OMXCameraAdapter::mThumbRes [] = { 89 { 640, 480, "640x480" }, 90 { 160, 120, "160x120" }, 91 { 200, 120, "200x120" }, 92 { 320, 240, "320x240" }, 93 { 512, 384, "512x384" }, 94 { 352, 144, "352x144" }, 95 { 176, 144, "176x144" }, 96 { 96, 96, "96x96" }, 97}; 98 99const CapPixelformat OMXCameraAdapter::mPixelformats [] = { 100 { OMX_COLOR_FormatCbYCrY, CameraParameters::PIXEL_FORMAT_YUV422I }, 101 { OMX_COLOR_FormatYUV420SemiPlanar, CameraParameters::PIXEL_FORMAT_YUV420SP }, 102 { OMX_COLOR_Format16bitRGB565, CameraParameters::PIXEL_FORMAT_RGB565 }, 103 { OMX_COLOR_FormatRawBayer10bit, TICameraParameters::PIXEL_FORMAT_RAW }, 104 { OMX_COLOR_FormatYUV420SemiPlanar, CameraParameters::PIXEL_FORMAT_YUV420P }, 105}; 106 107const CapFramerate OMXCameraAdapter::mFramerates [] = { 108 { 30, "30" }, 109 { 25, "25" }, 110 { 24, "24" }, 111 { 20, "20" }, 112 { 15, "15" }, 113 { 10, "10" }, 114}; 115 116const CapZoom OMXCameraAdapter::mZoomStages [] = { 117 { 65536, "100" }, 118 { 70124, "107" }, 119 { 75366, "115" }, 120 { 80609, "123" }, 121 { 86508, "132" }, 122 { 92406, "141" }, 123 { 99615, "152" }, 124 { 106168, "162" }, 125 { 114033, "174" }, 126 { 122552, "187" }, 127 { 131072, "200" }, 128 { 140247, "214" }, 129 { 150733, "230" }, 130 { 161219, "246" }, 131 { 173015, "264" }, 132 { 185467, "283" }, 133 { 198574, "303" }, 134 { 212992, "325" }, 135 { 228065, "348" }, 136 { 244449, "373" }, 137 { 262144, "400" }, 138 { 281149, "429" }, 139 { 300810, "459" }, 140 { 322437, "492" }, 141 { 346030, "528" }, 142 { 370934, "566" }, 143 { 397148, "606" }, 144 { 425984, "650" }, 145 { 456131, "696" }, 146 { 488899, "746" }, 147 { 524288, "800" }, 148}; 149 150const CapISO OMXCameraAdapter::mISOStages [] = { 151 { 0, "auto" }, 152 { 100, "100" }, 153 { 200, "200"}, 154 { 400, "400" }, 155 { 800, "800" }, 156 { 1000, "1000" }, 157 { 1200, "1200" }, 158 { 1600, "1600" }, 159}; 160 161// mapped values have to match with new_sensor_MSP.h 162const CapU32 OMXCameraAdapter::mSensorNames [] = { 163 { 300, "IMX060" }, 164 { 301, "OV5650" }, 165 { 305, "S5K4E1GA"}, 166 { 306, "S5K6A1GX03" } 167 // TODO(XXX): need to account for S3D camera later 168}; 169 170// values for supported variable framerates sorted in ascending order 171// CapU32Pair = (max fps, min fps, string representation) 172const CapU32Pair OMXCameraAdapter::mVarFramerates [] = { 173 { 15, 15, "(15000,15000)"}, 174 { 30, 15, "(15000,30000)" }, 175 { 30, 24, "(24000,30000)" }, 176 { 30, 30, "(30000,30000)" }, 177}; 178/************************************ 179 * static helper functions 180 *************************************/ 181 182// utility function to remove last seperator 183void remove_last_sep(char* buffer) { 184 char* last_sep = NULL; 185 last_sep = strrchr(buffer, PARAM_SEP_CHAR); 186 if (last_sep != NULL) { 187 last_sep[0] = '\0'; 188 } 189} 190 191 192/***************************************** 193 * internal static function declarations 194 *****************************************/ 195 196/**** Utility functions to help translate OMX Caps to Parameter ****/ 197 198status_t OMXCameraAdapter::encodePixelformatCap(OMX_COLOR_FORMATTYPE format, 199 const CapPixelformat *cap, 200 size_t capCount, 201 char * buffer, 202 size_t bufferSize) { 203 status_t ret = NO_ERROR; 204 205 LOG_FUNCTION_NAME; 206 207 if ( ( NULL == buffer ) || ( NULL == cap ) ) { 208 CAMHAL_LOGEA("Invalid input arguments"); 209 return -EINVAL; 210 } 211 212 for ( unsigned int i = 0; i < capCount; i++ ) { 213 if ( format == cap[i].pixelformat ) { 214 strncat(buffer, cap[i].param, bufferSize - 1); 215 strncat(buffer, PARAM_SEP, bufferSize - 1); 216 } 217 } 218 219 LOG_FUNCTION_NAME_EXIT; 220 221 return ret; 222} 223 224status_t OMXCameraAdapter::encodeFramerateCap(OMX_U32 framerateMax, 225 OMX_U32 framerateMin, 226 const CapFramerate *cap, 227 size_t capCount, 228 char * buffer, 229 size_t bufferSize) { 230 status_t ret = NO_ERROR; 231 bool minInserted = false; 232 bool maxInserted = false; 233 char tmpBuffer[FRAMERATE_COUNT]; 234 235 LOG_FUNCTION_NAME; 236 237 if ( ( NULL == buffer ) || ( NULL == cap ) ) { 238 CAMHAL_LOGEA("Invalid input arguments"); 239 return -EINVAL; 240 } 241 242 for ( unsigned int i = 0; i < capCount; i++ ) { 243 if ( (framerateMax >= cap[i].num) && (framerateMin <= cap[i].num) ) { 244 strncat(buffer, cap[i].param, bufferSize - 1); 245 strncat(buffer, PARAM_SEP, bufferSize - 1); 246 247 if ( cap[i].num == framerateMin ) { 248 minInserted = true; 249 } 250 } 251 if ( cap[i].num == framerateMax ) { 252 maxInserted = true; 253 } 254 } 255 256 if ( !maxInserted ) { 257 memset(tmpBuffer, 0, FRAMERATE_COUNT); 258 snprintf(tmpBuffer, FRAMERATE_COUNT - 1, "%u,", ( unsigned int ) framerateMax); 259 strncat(buffer, tmpBuffer, bufferSize - 1); 260 strncat(buffer, PARAM_SEP, bufferSize - 1); 261 } 262 263 if ( !minInserted ) { 264 memset(tmpBuffer, 0, FRAMERATE_COUNT); 265 snprintf(tmpBuffer, FRAMERATE_COUNT - 1, "%u,", ( unsigned int ) framerateMin); 266 strncat(buffer, tmpBuffer, bufferSize - 1); 267 strncat(buffer, PARAM_SEP, bufferSize - 1); 268 } 269 270 remove_last_sep(buffer); 271 272 LOG_FUNCTION_NAME_EXIT; 273 274 return ret; 275} 276 277status_t OMXCameraAdapter::encodeVFramerateCap(OMX_TI_CAPTYPE &caps, 278 const CapU32Pair *cap, 279 size_t capCount, 280 char *buffer, 281 char *defaultRange, 282 size_t bufferSize) { 283 status_t ret = NO_ERROR; 284 uint32_t minVFR, maxVFR; 285 int default_index = -1; 286 287 LOG_FUNCTION_NAME; 288 289 if ( (NULL == buffer) || (NULL == cap) ) { 290 CAMHAL_LOGEA("Invalid input arguments"); 291 return -EINVAL; 292 } 293 294 if(caps.ulPrvVarFPSModesCount < 1) { 295 return NO_ERROR; 296 } 297 298 // Assumption: last range in tPrvVarFPSModes will be for S30FPSHD mode 299 minVFR = caps.tPrvVarFPSModes[caps.ulPrvVarFPSModesCount-1].nVarFPSMin >> VFR_OFFSET; 300 maxVFR = caps.tPrvVarFPSModes[caps.ulPrvVarFPSModesCount-1].nVarFPSMax >> VFR_OFFSET; 301 302 if (minVFR < FPS_MIN) { 303 minVFR = FPS_MIN; 304 } 305 306 for (unsigned int i = 0; i < capCount; i++) { 307 // add cap[i] if it is in range and maxVFR != minVFR 308 if ((maxVFR >= cap[i].num1) && (minVFR <= cap[i].num2)) { 309 if (buffer[0] != '\0') { 310 strncat(buffer, PARAM_SEP, bufferSize - 1); 311 } 312 strncat(buffer, cap[i].param, bufferSize - 1); 313 314 // choose the max variable framerate as default 315 if (cap[i].num1 != cap[i].num2) { 316 default_index = i; 317 } 318 } 319 } 320 321 // if we haven't found any caps in the list to populate 322 // just use the min and max 323 if (buffer[0] == '\0') { 324 snprintf(buffer, bufferSize - 1, 325 "(%u,%u)", 326 minVFR * CameraHal::VFR_SCALE, 327 maxVFR * CameraHal::VFR_SCALE); 328 } 329 330 if (default_index != -1) { 331 snprintf(defaultRange, (MAX_PROP_VALUE_LENGTH - 1), "%lu,%lu", 332 cap[default_index].num2 * CameraHal::VFR_SCALE, 333 cap[default_index].num1 * CameraHal::VFR_SCALE); 334 } else { 335 snprintf(defaultRange, (MAX_PROP_VALUE_LENGTH - 1), "%u,%u", 336 minVFR * CameraHal::VFR_SCALE, maxVFR * CameraHal::VFR_SCALE); 337 } 338 339 LOG_FUNCTION_NAME_EXIT; 340 341 return ret; 342} 343 344size_t OMXCameraAdapter::encodeZoomCap(OMX_S32 maxZoom, 345 const CapZoom *cap, 346 size_t capCount, 347 char * buffer, 348 size_t bufferSize) { 349 status_t res = NO_ERROR; 350 size_t ret = 0; 351 352 LOG_FUNCTION_NAME; 353 354 if ( (NULL == buffer) || (NULL == cap) ) { 355 CAMHAL_LOGEA("Invalid input arguments"); 356 return -EINVAL; 357 } 358 359 360 for ( unsigned int i = 0; i < capCount; i++ ) { 361 if ( cap[i].num <= maxZoom ) { 362 strncat(buffer, cap[i].param, bufferSize - 1); 363 strncat(buffer, PARAM_SEP, bufferSize - 1); 364 ret++; 365 } 366 } 367 remove_last_sep(buffer); 368 369 LOG_FUNCTION_NAME_EXIT; 370 371 return ret; 372} 373 374status_t OMXCameraAdapter::encodeISOCap(OMX_U32 maxISO, 375 const CapISO *cap, 376 size_t capCount, 377 char * buffer, 378 size_t bufferSize) { 379 status_t ret = NO_ERROR; 380 381 LOG_FUNCTION_NAME; 382 383 if ( (NULL == buffer) || (NULL == cap) ) { 384 CAMHAL_LOGEA("Invalid input arguments"); 385 return -EINVAL; 386 } 387 388 for ( unsigned int i = 0; i < capCount; i++ ) { 389 if ( cap[i].num <= maxISO) { 390 strncat(buffer, cap[i].param, bufferSize - 1); 391 strncat(buffer, PARAM_SEP, bufferSize - 1); 392 } 393 } 394 remove_last_sep(buffer); 395 396 LOG_FUNCTION_NAME_EXIT; 397 398 return ret; 399} 400 401status_t OMXCameraAdapter::encodeSizeCap(OMX_TI_CAPRESTYPE &res, 402 const CapResolution *cap, 403 size_t capCount, 404 char * buffer, 405 size_t bufferSize) { 406 status_t ret = NO_ERROR; 407 408 LOG_FUNCTION_NAME; 409 410 if ( (NULL == buffer) || (NULL == cap) ) { 411 CAMHAL_LOGEA("Invalid input arguments"); 412 return -EINVAL; 413 } 414 415 for ( unsigned int i = 0 ; i < capCount ; i++ ) { 416 if ( (cap[i].width <= res.nWidthMax) && 417 (cap[i].height <= res.nHeightMax) && 418 (cap[i].width >= res.nWidthMin) && 419 (cap[i].height >= res.nHeightMin) ) { 420 strncat(buffer, cap[i].param, bufferSize -1); 421 strncat(buffer, PARAM_SEP, bufferSize - 1); 422 } 423 } 424 425 LOG_FUNCTION_NAME_EXIT; 426 427 return ret; 428} 429 430status_t OMXCameraAdapter::insertImageSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 431 status_t ret = NO_ERROR; 432 char supported[MAX_PROP_VALUE_LENGTH]; 433 434 LOG_FUNCTION_NAME; 435 436 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 437 438 ret = encodeSizeCap(caps.tImageResRange, 439 mImageCapRes, 440 ARRAY_SIZE(mImageCapRes), 441 supported, 442 MAX_PROP_VALUE_LENGTH); 443 444 if ( NO_ERROR != ret ) { 445 CAMHAL_LOGEB("Error inserting supported picture sizes 0x%x", ret); 446 } else { 447 remove_last_sep(supported); 448 params->set(CameraProperties::SUPPORTED_PICTURE_SIZES, supported); 449 } 450 451 LOG_FUNCTION_NAME; 452 453 return ret; 454} 455 456status_t OMXCameraAdapter::insertPreviewSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 457 status_t ret = NO_ERROR; 458 char supported[MAX_PROP_VALUE_LENGTH]; 459 460 LOG_FUNCTION_NAME; 461 462 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 463 464 ret = encodeSizeCap(caps.tPreviewResRange, 465 mPreviewRes, 466 ARRAY_SIZE(mPreviewRes), 467 supported, 468 MAX_PROP_VALUE_LENGTH); 469 470 if ( NO_ERROR != ret ) { 471 CAMHAL_LOGEB("Error inserting supported preview sizes 0x%x", ret); 472 } else { 473 remove_last_sep(supported); 474 params->set(CameraProperties::SUPPORTED_PREVIEW_SIZES, supported); 475 } 476 477 LOG_FUNCTION_NAME; 478 479 return ret; 480} 481 482status_t OMXCameraAdapter::insertThumbSizes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 483 status_t ret = NO_ERROR; 484 char supported[MAX_PROP_VALUE_LENGTH]; 485 486 LOG_FUNCTION_NAME; 487 488 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 489 490 ret = encodeSizeCap(caps.tThumbResRange, 491 mThumbRes, 492 ARRAY_SIZE(mThumbRes), 493 supported, 494 MAX_PROP_VALUE_LENGTH); 495 496 if ( NO_ERROR != ret ) { 497 CAMHAL_LOGEB("Error inserting supported thumbnail sizes 0x%x", ret); 498 } else { 499 //CTS Requirement: 0x0 should always be supported 500 strncat(supported, "0x0", MAX_PROP_NAME_LENGTH); 501 params->set(CameraProperties::SUPPORTED_THUMBNAIL_SIZES, supported); 502 } 503 504 LOG_FUNCTION_NAME; 505 506 return ret; 507} 508 509status_t OMXCameraAdapter::insertZoomStages(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) 510{ 511 status_t ret = NO_ERROR; 512 char supported[MAX_PROP_VALUE_LENGTH]; 513 size_t zoomStageCount = 0; 514 515 LOG_FUNCTION_NAME; 516 517 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 518 519 zoomStageCount = encodeZoomCap(caps.xMaxWidthZoom, 520 mZoomStages, 521 ARRAY_SIZE(mZoomStages), 522 supported, 523 MAX_PROP_VALUE_LENGTH); 524 525 params->set(CameraProperties::SUPPORTED_ZOOM_RATIOS, supported); 526 params->set(CameraProperties::SUPPORTED_ZOOM_STAGES, zoomStageCount - 1); //As per CTS requirement 527 528 if ( 0 == zoomStageCount ) { 529 params->set(CameraProperties::ZOOM_SUPPORTED, TICameraParameters::ZOOM_UNSUPPORTED); 530 params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, TICameraParameters::ZOOM_UNSUPPORTED); 531 } else { 532 params->set(CameraProperties::ZOOM_SUPPORTED, TICameraParameters::ZOOM_SUPPORTED); 533 params->set(CameraProperties::SMOOTH_ZOOM_SUPPORTED, TICameraParameters::ZOOM_SUPPORTED); 534 } 535 536 LOG_FUNCTION_NAME; 537 538 return ret; 539} 540 541status_t OMXCameraAdapter::insertImageFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 542 status_t ret = NO_ERROR; 543 char supported[MAX_PROP_VALUE_LENGTH]; 544 545 LOG_FUNCTION_NAME; 546 547 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 548 549 for ( int i = 0 ; i < caps.ulImageFormatCount ; i++ ) { 550 ret = encodePixelformatCap(caps.eImageFormats[i], 551 mPixelformats, 552 ARRAY_SIZE(mPixelformats), 553 supported, 554 MAX_PROP_VALUE_LENGTH); 555 if ( NO_ERROR != ret ) { 556 CAMHAL_LOGEB("Error inserting supported picture formats 0x%x", ret); 557 break; 558 } 559 } 560 561 if ( NO_ERROR == ret ) { 562 //jpeg is not supported in OMX capabilies yet 563 strncat(supported, CameraParameters::PIXEL_FORMAT_JPEG, MAX_PROP_VALUE_LENGTH - 1); 564 params->set(CameraProperties::SUPPORTED_PICTURE_FORMATS, supported); 565 } 566 567 LOG_FUNCTION_NAME; 568 569 return ret; 570} 571 572status_t OMXCameraAdapter::insertPreviewFormats(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 573 status_t ret = NO_ERROR; 574 char supported[MAX_PROP_VALUE_LENGTH]; 575 576 LOG_FUNCTION_NAME; 577 578 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 579 580 for ( int i = 0 ; i < caps.ulPreviewFormatCount; i++ ) { 581 ret = encodePixelformatCap(caps.ePreviewFormats[i], 582 mPixelformats, 583 ARRAY_SIZE(mPixelformats), 584 supported, 585 MAX_PROP_VALUE_LENGTH); 586 if ( NO_ERROR != ret ) { 587 CAMHAL_LOGEB("Error inserting supported preview formats 0x%x", ret); 588 break; 589 } 590 } 591 592 if ( NO_ERROR == ret ) { 593 // need to advertise we support YV12 format 594 // We will program preview port with NV21 when we see application set YV12 595 strncat(supported, CameraParameters::PIXEL_FORMAT_YUV420P, MAX_PROP_VALUE_LENGTH - 1); 596 params->set(CameraProperties::SUPPORTED_PREVIEW_FORMATS, supported); 597 } 598 599 LOG_FUNCTION_NAME; 600 601 return ret; 602} 603 604status_t OMXCameraAdapter::insertFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 605 status_t ret = NO_ERROR; 606 char supported[MAX_PROP_VALUE_LENGTH]; 607 608 LOG_FUNCTION_NAME; 609 610 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 611 612 ret = encodeFramerateCap(caps.xFramerateMax >> VFR_OFFSET, 613 caps.xFramerateMin >> VFR_OFFSET, 614 mFramerates, 615 ARRAY_SIZE(mFramerates), 616 supported, 617 MAX_PROP_VALUE_LENGTH); 618 619 if ( NO_ERROR != ret ) { 620 CAMHAL_LOGEB("Error inserting supported preview framerates 0x%x", ret); 621 } else { 622 params->set(CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES, supported); 623 } 624 625 LOG_FUNCTION_NAME; 626 627 return ret; 628} 629 630status_t OMXCameraAdapter::insertVFramerates(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 631 status_t ret = NO_ERROR; 632 char supported[MAX_PROP_VALUE_LENGTH]; 633 char defaultRange[MAX_PROP_VALUE_LENGTH]; 634 635 LOG_FUNCTION_NAME; 636 637 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 638 639 ret = encodeVFramerateCap(caps, 640 mVarFramerates, 641 ARRAY_SIZE(mVarFramerates), 642 supported, 643 defaultRange, 644 MAX_PROP_VALUE_LENGTH); 645 646 if ( NO_ERROR != ret ) { 647 CAMHAL_LOGEB("Error inserting supported preview framerate ranges 0x%x", ret); 648 } else { 649 params->set(CameraProperties::FRAMERATE_RANGE_SUPPORTED, supported); 650 CAMHAL_LOGDB("framerate ranges %s", supported); 651 params->set(CameraProperties::FRAMERATE_RANGE, defaultRange); 652 CAMHAL_LOGDB("Default framerate range: [%s]", defaultRange); 653 } 654 655 LOG_FUNCTION_NAME; 656 657 return ret; 658} 659 660status_t OMXCameraAdapter::insertEVs(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 661 status_t ret = NO_ERROR; 662 char supported[MAX_PROP_VALUE_LENGTH]; 663 664 LOG_FUNCTION_NAME; 665 666 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 667 668 snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMin * 10 )); 669 params->set(CameraProperties::SUPPORTED_EV_MIN, supported); 670 671 snprintf(supported, MAX_PROP_VALUE_LENGTH, "%d", ( int ) ( caps.xEVCompensationMax * 10 )); 672 params->set(CameraProperties::SUPPORTED_EV_MAX, supported); 673 674 LOG_FUNCTION_NAME; 675 676 return ret; 677} 678 679status_t OMXCameraAdapter::insertISOModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 680 status_t ret = NO_ERROR; 681 char supported[MAX_PROP_VALUE_LENGTH]; 682 683 LOG_FUNCTION_NAME; 684 685 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 686 687 ret = encodeISOCap(caps.nSensitivityMax, 688 mISOStages, 689 ARRAY_SIZE(mISOStages), 690 supported, 691 MAX_PROP_VALUE_LENGTH); 692 if ( NO_ERROR != ret ) { 693 CAMHAL_LOGEB("Error inserting supported ISO modes 0x%x", ret); 694 } else { 695 params->set(CameraProperties::SUPPORTED_ISO_VALUES, supported); 696 } 697 698 LOG_FUNCTION_NAME; 699 700 return ret; 701} 702 703status_t OMXCameraAdapter::insertIPPModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 704 status_t ret = NO_ERROR; 705 char supported[MAX_PROP_VALUE_LENGTH]; 706 707 LOG_FUNCTION_NAME; 708 709 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 710 711 //Off is always supported 712 strncat(supported, TICameraParameters::IPP_NONE, MAX_PROP_NAME_LENGTH); 713 strncat(supported, PARAM_SEP, 1); 714 715 if ( caps.bLensDistortionCorrectionSupported ) { 716 strncat(supported, TICameraParameters::IPP_LDC, MAX_PROP_NAME_LENGTH); 717 strncat(supported, PARAM_SEP, 1); 718 } 719 720 if ( caps.bISONoiseFilterSupported ) { 721 strncat(supported, TICameraParameters::IPP_NSF, MAX_PROP_NAME_LENGTH); 722 strncat(supported, PARAM_SEP, 1); 723 } 724 725 if ( caps.bISONoiseFilterSupported && caps.bLensDistortionCorrectionSupported ) { 726 strncat(supported, TICameraParameters::IPP_LDCNSF, MAX_PROP_NAME_LENGTH); 727 strncat(supported, PARAM_SEP, 1); 728 } 729 730 remove_last_sep(supported); 731 params->set(CameraProperties::SUPPORTED_IPP_MODES, supported); 732 733 LOG_FUNCTION_NAME; 734 735 return ret; 736} 737 738status_t OMXCameraAdapter::insertWBModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 739 status_t ret = NO_ERROR; 740 char supported[MAX_PROP_VALUE_LENGTH]; 741 const char *p; 742 743 LOG_FUNCTION_NAME; 744 745 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 746 747 for ( unsigned int i = 0 ; i < caps.ulWhiteBalanceCount ; i++ ) { 748 p = getLUTvalue_OMXtoHAL(caps.eWhiteBalanceModes[i], WBalLUT); 749 if ( NULL != p ) { 750 strncat(supported, p, MAX_PROP_NAME_LENGTH); 751 strncat(supported, PARAM_SEP, 1); 752 } 753 } 754 755 //These modes are not supported by the capability feature 756 strncat(supported, TICameraParameters::WHITE_BALANCE_FACE, MAX_PROP_NAME_LENGTH); 757 758 params->set(CameraProperties::SUPPORTED_WHITE_BALANCE, supported); 759 760 LOG_FUNCTION_NAME; 761 762 return ret; 763} 764 765status_t OMXCameraAdapter::insertEffects(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 766 status_t ret = NO_ERROR; 767 char supported[MAX_PROP_VALUE_LENGTH]; 768 const char *p; 769 770 LOG_FUNCTION_NAME; 771 772 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 773 774 for ( unsigned int i = 0 ; i < caps.ulColorEffectCount; i++ ) { 775 p = getLUTvalue_OMXtoHAL(caps.eColorEffects[i], EffLUT); 776 if ( NULL != p ) { 777 strncat(supported, p, MAX_PROP_NAME_LENGTH); 778 strncat(supported, PARAM_SEP, 1); 779 } 780 } 781 remove_last_sep(supported); 782 params->set(CameraProperties::SUPPORTED_EFFECTS, supported); 783 784 LOG_FUNCTION_NAME; 785 786 return ret; 787} 788 789status_t OMXCameraAdapter::insertExpModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 790 status_t ret = NO_ERROR; 791 char supported[MAX_PROP_VALUE_LENGTH]; 792 const char *p; 793 794 LOG_FUNCTION_NAME; 795 796 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 797 798 for ( unsigned int i = 0 ; i < caps.ulExposureModeCount; i++ ) { 799 p = getLUTvalue_OMXtoHAL(caps.eExposureModes[i], ExpLUT); 800 if ( NULL != p ) { 801 strncat(supported, p, MAX_PROP_NAME_LENGTH); 802 strncat(supported, PARAM_SEP, 1); 803 } 804 } 805 806 //These modes are not supported by the capability feature 807 strncat(supported, TICameraParameters::EXPOSURE_MODE_FACE, MAX_PROP_NAME_LENGTH); 808 809 params->set(CameraProperties::SUPPORTED_EXPOSURE_MODES, supported); 810 811 LOG_FUNCTION_NAME; 812 813 return ret; 814} 815 816status_t OMXCameraAdapter::insertFlashModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 817 status_t ret = NO_ERROR; 818 char supported[MAX_PROP_VALUE_LENGTH]; 819 const char *p; 820 821 LOG_FUNCTION_NAME; 822 823 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 824 825 for ( unsigned int i = 0 ; i < caps.ulFlashCount; i++ ) { 826 p = getLUTvalue_OMXtoHAL(caps.eFlashModes[i], FlashLUT); 827 if ( NULL != p ) { 828 strncat(supported, p, MAX_PROP_NAME_LENGTH); 829 strncat(supported, PARAM_SEP, 1); 830 } 831 } 832 833 remove_last_sep(supported); 834 params->set(CameraProperties::SUPPORTED_FLASH_MODES, supported); 835 836 LOG_FUNCTION_NAME; 837 838 return ret; 839} 840 841status_t OMXCameraAdapter::insertSceneModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 842 status_t ret = NO_ERROR; 843 char supported[MAX_PROP_VALUE_LENGTH]; 844 const char *p; 845 846 LOG_FUNCTION_NAME; 847 848 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 849 850 for ( unsigned int i = 0 ; i < caps.ulSceneCount; i++ ) { 851 p = getLUTvalue_OMXtoHAL(caps.eSceneModes[i], SceneLUT); 852 if ( NULL != p ) { 853 strncat(supported, p, MAX_PROP_NAME_LENGTH); 854 strncat(supported, PARAM_SEP, 1); 855 } 856 } 857 858 remove_last_sep(supported); 859 params->set(CameraProperties::SUPPORTED_SCENE_MODES, supported); 860 861 LOG_FUNCTION_NAME; 862 863 return ret; 864} 865 866status_t OMXCameraAdapter::insertFocusModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 867 status_t ret = NO_ERROR; 868 char supported[MAX_PROP_VALUE_LENGTH]; 869 const char *p; 870 871 LOG_FUNCTION_NAME; 872 873 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 874 875 for ( unsigned int i = 0 ; i < caps.ulFocusModeCount; i++ ) { 876 p = getLUTvalue_OMXtoHAL(caps.eFocusModes[i], FocusLUT); 877 if ( NULL != p ) { 878 strncat(supported, p, MAX_PROP_NAME_LENGTH); 879 strncat(supported, PARAM_SEP, 1); 880 } 881 } 882 883 // Check if focus is supported by camera 884 if (caps.ulFocusModeCount == 1 && 885 caps.eFocusModes[0] == OMX_IMAGE_FocusControlOff) { 886 // Focus is not supported by camera 887 // Advertise this to app as infinitiy focus mode 888 strncat(supported, CameraParameters::FOCUS_MODE_INFINITY, MAX_PROP_NAME_LENGTH); 889 } else { 890 // Focus is supported but these modes are not supported by the 891 // capability feature. Apply manually 892 strncat(supported, TICameraParameters::FOCUS_MODE_FACE, MAX_PROP_NAME_LENGTH); 893 strncat(supported, PARAM_SEP, 1); 894 strncat(supported, CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE, MAX_PROP_NAME_LENGTH); 895 } 896 897 params->set(CameraProperties::SUPPORTED_FOCUS_MODES, supported); 898 899 LOG_FUNCTION_NAME; 900 901 return ret; 902} 903 904status_t OMXCameraAdapter::insertFlickerModes(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 905 status_t ret = NO_ERROR; 906 char supported[MAX_PROP_VALUE_LENGTH]; 907 const char *p; 908 909 LOG_FUNCTION_NAME; 910 911 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 912 913 for ( unsigned int i = 0 ; i < caps.ulFlickerCount; i++ ) { 914 p = getLUTvalue_OMXtoHAL(caps.eFlicker[i], FlickerLUT); 915 if ( NULL != p ) { 916 strncat(supported, p, MAX_PROP_NAME_LENGTH); 917 strncat(supported, PARAM_SEP, 1); 918 } 919 } 920 remove_last_sep(supported); 921 params->set(CameraProperties::SUPPORTED_ANTIBANDING, supported); 922 923 LOG_FUNCTION_NAME; 924 925 return ret; 926} 927 928status_t OMXCameraAdapter::insertAreas(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 929 status_t ret = NO_ERROR; 930 char supported[MAX_PROP_VALUE_LENGTH]; 931 const char *p; 932 933 LOG_FUNCTION_NAME; 934 935 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 936 937 sprintf(supported, "%d", caps.ulAlgoAreasFocusCount); 938 params->set(CameraProperties::MAX_FOCUS_AREAS, supported); 939 CAMHAL_LOGDB("Maximum supported focus areas %s", supported); 940 941 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 942 sprintf(supported, "%d", caps.ulAlgoAreasExposureCount); 943 params->set(CameraProperties::MAX_NUM_METERING_AREAS, supported); 944 CAMHAL_LOGDB("Maximum supported exposure areas %s", supported); 945 946 LOG_FUNCTION_NAME; 947 948 return ret; 949} 950 951status_t OMXCameraAdapter::insertLocks(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 952 status_t ret = NO_ERROR; 953 954 LOG_FUNCTION_NAME 955 956 params->set(CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED, DEFAULT_LOCK_SUPPORTED); 957 params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED, DEFAULT_LOCK_SUPPORTED); 958 959 LOG_FUNCTION_NAME 960 961 return ret; 962} 963 964status_t OMXCameraAdapter::insertDefaults(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 965 status_t ret = NO_ERROR; 966 char supported[MAX_PROP_VALUE_LENGTH]; 967 const char *p; 968 969 LOG_FUNCTION_NAME; 970 971 params->set(CameraProperties::ANTIBANDING, DEFAULT_ANTIBANDING); 972 params->set(CameraProperties::BRIGHTNESS, DEFAULT_BRIGHTNESS); 973 params->set(CameraProperties::CONTRAST, DEFAULT_CONTRAST); 974 params->set(CameraProperties::EFFECT, DEFAULT_EFFECT); 975 params->set(CameraProperties::EV_COMPENSATION, DEFAULT_EV_COMPENSATION); 976 params->set(CameraProperties::SUPPORTED_EV_STEP, DEFAULT_EV_STEP); 977 params->set(CameraProperties::EXPOSURE_MODE, DEFAULT_EXPOSURE_MODE); 978 params->set(CameraProperties::FLASH_MODE, DEFAULT_FLASH_MODE); 979 params->set(CameraProperties::FOCUS_MODE, DEFAULT_FOCUS_MODE); 980 params->set(CameraProperties::IPP, DEFAULT_IPP); 981 params->set(CameraProperties::GBCE, DEFAULT_GBCE); 982 params->set(CameraProperties::ISO_MODE, DEFAULT_ISO_MODE); 983 params->set(CameraProperties::JPEG_QUALITY, DEFAULT_JPEG_QUALITY); 984 params->set(CameraProperties::JPEG_THUMBNAIL_QUALITY, DEFAULT_THUMBNAIL_QUALITY); 985 params->set(CameraProperties::JPEG_THUMBNAIL_SIZE, DEFAULT_THUMBNAIL_SIZE); 986 params->set(CameraProperties::PICTURE_FORMAT, DEFAULT_PICTURE_FORMAT); 987 params->set(CameraProperties::PICTURE_SIZE, DEFAULT_PICTURE_SIZE); 988 params->set(CameraProperties::PREVIEW_FORMAT, DEFAULT_PREVIEW_FORMAT); 989 params->set(CameraProperties::PREVIEW_FRAME_RATE, DEFAULT_FRAMERATE); 990 params->set(CameraProperties::PREVIEW_SIZE, DEFAULT_PREVIEW_SIZE); 991 params->set(CameraProperties::REQUIRED_PREVIEW_BUFS, DEFAULT_NUM_PREV_BUFS); 992 params->set(CameraProperties::REQUIRED_IMAGE_BUFS, DEFAULT_NUM_PIC_BUFS); 993 params->set(CameraProperties::SATURATION, DEFAULT_SATURATION); 994 params->set(CameraProperties::SCENE_MODE, DEFAULT_SCENE_MODE); 995 params->set(CameraProperties::SHARPNESS, DEFAULT_SHARPNESS); 996 params->set(CameraProperties::VSTAB, DEFAULT_VSTAB); 997 params->set(CameraProperties::WHITEBALANCE, DEFAULT_WB); 998 params->set(CameraProperties::ZOOM, DEFAULT_ZOOM); 999 params->set(CameraProperties::MAX_FD_HW_FACES, DEFAULT_MAX_FD_HW_FACES); 1000 params->set(CameraProperties::MAX_FD_SW_FACES, DEFAULT_MAX_FD_SW_FACES); 1001 params->set(CameraProperties::AUTO_EXPOSURE_LOCK, DEFAULT_AE_LOCK); 1002 params->set(CameraProperties::AUTO_WHITEBALANCE_LOCK, DEFAULT_AWB_LOCK); 1003 params->set(CameraProperties::FOCAL_LENGTH, DEFAULT_FOCAL_LENGTH); 1004 params->set(CameraProperties::HOR_ANGLE, DEFAULT_HOR_ANGLE); 1005 params->set(CameraProperties::VER_ANGLE, DEFAULT_VER_ANGLE); 1006 LOG_FUNCTION_NAME; 1007 1008 return ret; 1009} 1010 1011status_t OMXCameraAdapter::insertSenMount(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 1012 status_t ret = NO_ERROR; 1013 char supported[MAX_PROP_VALUE_LENGTH]; 1014 const char *p; 1015 unsigned int i = 0; 1016 1017 LOG_FUNCTION_NAME; 1018 1019 memset(supported, '\0', MAX_PROP_VALUE_LENGTH); 1020 1021 // 1) Look up and assign sensor name 1022 for (i = 0; i < ARRAY_SIZE(mSensorNames); i++) { 1023 if(mSensorNames[i].num == caps.tSenMounting.nSenId) { 1024 // sensor found 1025 break; 1026 } 1027 } 1028 if ( i == ARRAY_SIZE(mSensorNames) ) { 1029 p = "UNKNOWN_SENSOR"; 1030 } else { 1031 p = mSensorNames[i].param; 1032 } 1033 strncat(supported, p, MAX_PROP_NAME_LENGTH); 1034 params->set(CameraProperties::CAMERA_NAME, supported); 1035 1036 // 2) Assign mounting rotation 1037 params->set(CameraProperties::ORIENTATION_INDEX, caps.tSenMounting.nRotation); 1038 1039 LOG_FUNCTION_NAME; 1040 1041 return ret; 1042} 1043 1044status_t OMXCameraAdapter::insertCapabilities(CameraProperties::Properties* params, OMX_TI_CAPTYPE &caps) { 1045 status_t ret = NO_ERROR; 1046 char supported[MAX_PROP_VALUE_LENGTH]; 1047 1048 LOG_FUNCTION_NAME; 1049 1050 if ( NO_ERROR == ret ) { 1051 ret = insertImageSizes(params, caps); 1052 } 1053 1054 if ( NO_ERROR == ret ) { 1055 ret = insertPreviewSizes(params, caps); 1056 } 1057 1058 if ( NO_ERROR == ret ) { 1059 ret = insertThumbSizes(params, caps); 1060 } 1061 1062 if ( NO_ERROR == ret ) { 1063 ret = insertZoomStages(params, caps); 1064 } 1065 1066 if ( NO_ERROR == ret ) { 1067 ret = insertImageFormats(params, caps); 1068 } 1069 1070 if ( NO_ERROR == ret ) { 1071 ret = insertPreviewFormats(params, caps); 1072 } 1073 1074 if ( NO_ERROR == ret ) { 1075 ret = insertFramerates(params, caps); 1076 } 1077 1078 if ( NO_ERROR == ret ) { 1079 ret = insertVFramerates(params, caps); 1080 } 1081 1082 if ( NO_ERROR == ret ) { 1083 ret = insertEVs(params, caps); 1084 } 1085 1086 if ( NO_ERROR == ret ) { 1087 ret = insertISOModes(params, caps); 1088 } 1089 1090 if ( NO_ERROR == ret ) { 1091 ret = insertIPPModes(params, caps); 1092 } 1093 1094 if ( NO_ERROR == ret ) { 1095 ret = insertWBModes(params, caps); 1096 } 1097 1098 if ( NO_ERROR == ret ) { 1099 ret = insertEffects(params, caps); 1100 } 1101 1102 if ( NO_ERROR == ret ) { 1103 ret = insertExpModes(params, caps); 1104 } 1105 1106 if ( NO_ERROR == ret ) { 1107 ret = insertFlashModes(params, caps); 1108 } 1109 1110 if ( NO_ERROR == ret ) { 1111 ret = insertSceneModes(params, caps); 1112 } 1113 1114 if ( NO_ERROR == ret ) { 1115 ret = insertFocusModes(params, caps); 1116 } 1117 1118 if ( NO_ERROR == ret ) { 1119 ret = insertFlickerModes(params, caps); 1120 } 1121 1122 if ( NO_ERROR == ret ) { 1123 ret = insertSenMount(params, caps); 1124 } 1125 1126 if ( NO_ERROR == ret ) { 1127 ret = insertLocks(params, caps); 1128 } 1129 if ( NO_ERROR == ret) { 1130 ret = insertAreas(params, caps); 1131 1132 } 1133 1134 if ( NO_ERROR == ret ) { 1135 ret = insertDefaults(params, caps); 1136 } 1137 1138 1139 1140 LOG_FUNCTION_NAME_EXIT; 1141 1142 return ret; 1143} 1144 1145/***************************************** 1146 * public exposed function declarations 1147 *****************************************/ 1148 1149status_t OMXCameraAdapter::getCaps(CameraProperties::Properties* params, OMX_HANDLETYPE handle) { 1150 status_t ret = NO_ERROR; 1151 int caps_size = 0; 1152 OMX_ERRORTYPE eError = OMX_ErrorNone; 1153 OMX_TI_CAPTYPE** caps = NULL;; 1154 OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer; 1155 MemoryManager memMgr; 1156 1157 LOG_FUNCTION_NAME; 1158 1159 // allocate tiler (or ion) buffer for caps (size is always a multiple of 4K) 1160 caps_size = ((sizeof(OMX_TI_CAPTYPE)+4095)/4096)*4096; 1161 caps = (OMX_TI_CAPTYPE**) memMgr.allocateBuffer(0, 0, NULL, caps_size, 1); 1162 1163 if (!caps) { 1164 CAMHAL_LOGEB("Error allocating buffer for caps %d", eError); 1165 ret = -ENOMEM; 1166 goto EXIT; 1167 } 1168 1169 // initialize structures to be passed to OMX Camera 1170 OMX_INIT_STRUCT_PTR (caps[0], OMX_TI_CAPTYPE); 1171 caps[0]->nPortIndex = OMX_ALL; 1172 1173 OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER); 1174 sharedBuffer.nPortIndex = OMX_ALL; 1175 sharedBuffer.nSharedBuffSize = caps_size; 1176 sharedBuffer.pSharedBuff = (OMX_U8 *) caps[0]; 1177 1178 // Get capabilities from OMX Camera 1179 eError = OMX_GetConfig(handle, (OMX_INDEXTYPE) OMX_TI_IndexConfigCamCapabilities, &sharedBuffer); 1180 if ( OMX_ErrorNone != eError ) { 1181 CAMHAL_LOGEB("Error during capabilities query 0x%x", eError); 1182 ret = UNKNOWN_ERROR; 1183 goto EXIT; 1184 } else { 1185 CAMHAL_LOGDA("OMX capability query success"); 1186 } 1187 1188 // Translate and insert Ducati capabilities to CameraProperties 1189 if ( NO_ERROR == ret ) { 1190 ret = insertCapabilities(params, *caps[0]); 1191 } 1192 1193 CAMHAL_LOGDB("sen mount id=%u", (unsigned int)caps[0]->tSenMounting.nSenId); 1194 1195 1196 EXIT: 1197 if (caps) { 1198 memMgr.freeBuffer((void*) caps); 1199 caps = NULL; 1200 } 1201 1202 LOG_FUNCTION_NAME_EXIT; 1203 return ret; 1204} 1205 1206}; 1207 1208