1 #include <stdlib.h> 2 #include <unistd.h> 3 #include <sys/types.h> 4 #include <sys/stat.h> 5 #include <fcntl.h> 6 #include <time.h> 7 #include <semaphore.h> 8 #include <pthread.h> 9 #include <string.h> 10 #include <assert.h> 11 #include <climits> 12 13 #include <ui/DisplayInfo.h> 14 15 #include <gui/GLConsumer.h> 16 #include <gui/Surface.h> 17 #include <ui/GraphicBuffer.h> 18 19 #include <camera/Camera.h> 20 #include <camera/ICamera.h> 21 #include <media/mediarecorder.h> 22 23 #include <binder/IPCThreadState.h> 24 #include <binder/ProcessState.h> 25 #include <binder/IServiceManager.h> 26 #include <cutils/properties.h> 27 #include <camera/CameraParameters.h> 28 #include <camera/ShotParameters.h> 29 #include <system/audio.h> 30 #include <system/camera.h> 31 32 #include <binder/IMemory.h> 33 #include <binder/MemoryBase.h> 34 #include <binder/MemoryHeapBase.h> 35 36 #include <cutils/memory.h> 37 #include <utils/Log.h> 38 39 #include <sys/wait.h> 40 41 #include "camera_test.h" 42 #include "camera_test_surfacetexture.h" 43 #ifdef ANDROID_API_JB_OR_LATER 44 #include "camera_test_bufferqueue.h" 45 #endif 46 47 using namespace android; 48 49 int camera_index = 0; 50 int print_menu; 51 52 sp<Camera> camera; 53 sp<MediaRecorder> recorder; 54 sp<SurfaceComposerClient> client; 55 sp<SurfaceControl> surfaceControl; 56 sp<Surface> previewSurface; 57 sp<BufferSourceThread> bufferSourceOutputThread; 58 sp<BufferSourceInput> bufferSourceInput; 59 60 CameraParameters params; 61 ShotParameters shotParams; 62 float compensation = 0.0; 63 double latitude = 0.0; 64 double longitude = 0.0; 65 double degree_by_step = 17.5609756; 66 double altitude = 0.0; 67 int awb_mode = 0; 68 int effects_mode = 0; 69 int scene_mode = 0; 70 int caf_mode = 0; 71 int tempBracketRange = 1; 72 int tempBracketIdx = 0; 73 int measurementIdx = 0; 74 int expBracketIdx = BRACKETING_IDX_DEFAULT; 75 int AutoConvergenceModeIDX = 0; 76 int gbceIDX = 0; 77 int glbceIDX = 0; 78 int rotation = 0; 79 int previewRotation = 0; 80 bool reSizePreview = true; 81 bool hardwareActive = false; 82 bool recordingMode = false; 83 bool previewRunning = false; 84 bool vstabtoggle = false; 85 bool AutoExposureLocktoggle = false; 86 bool AutoWhiteBalanceLocktoggle = false; 87 bool vnftoggle = false; 88 bool faceDetectToggle = false; 89 bool metaDataToggle = false; 90 bool shotConfigFlush = false; 91 bool streamCapture = false; 92 int saturation = 0; 93 int zoomIDX = 0; 94 int videoCodecIDX = 0; 95 int audioCodecIDX = 0; 96 int outputFormatIDX = 0; 97 int contrast = 0; 98 int brightness = 0; 99 unsigned int burst = 0; 100 unsigned int burstCount = 0; 101 int sharpness = 0; 102 int iso_mode = 0; 103 int capture_mode = 0; 104 int exposure_mode = 0; 105 int ippIDX = 0; 106 int ippIDX_old = 0; 107 int previewFormat = 0; 108 int pictureFormat = 0; 109 int jpegQuality = 85; 110 int thumbQuality = 85; 111 int flashIdx = 0; 112 int fpsRangeIdx = 0; 113 timeval autofocus_start, picture_start; 114 char script_name[80]; 115 int prevcnt = 0; 116 int videoFd = -1; 117 int afTimeoutIdx = 0; 118 int platformID = BLAZE_TABLET2; 119 int numAntibanding = 0; 120 int numEffects = 0; 121 int numcaptureSize = 0; 122 int nummodevalues = 0; 123 int numVcaptureSize = 0; 124 int numpreviewSize = 0; 125 int numthumbnailSize = 0; 126 int numawb = 0; 127 int numscene = 0; 128 int numfocus = 0; 129 int numflash = 0; 130 int numExposureMode = 0; 131 int numisoMode = 0; 132 int antibanding_mode = 0; 133 int effectsStrLenght = 0; 134 int numfps = 0; 135 int numpreviewFormat = 0; 136 int numpictureFormat = 0; 137 int *constFramerate = 0; 138 int rangeCnt = 0; 139 int constCnt = 0; 140 int focus_mode = 0; 141 int thumbSizeIDX = 0; 142 int previewSizeIDX = 1; 143 int captureSizeIDX = 0; 144 int VcaptureSizeIDX = 1; 145 int frameRateIDX = 0; 146 char *str; 147 char *param; 148 char *antibandStr = 0; 149 char *exposureModeStr = 0; 150 char *isoModeStr = 0; 151 char *effectssStr = 0; 152 char *captureSizeStr = 0; 153 char *modevaluesstr = 0; 154 char *videosnapshotstr = 0; 155 char *autoconvergencestr = 0; 156 char *VcaptureSizeStr = 0; 157 char *thumbnailSizeStr = 0; 158 char *vstabstr = 0; 159 char *vnfstr = 0; 160 char *zoomstr = 0; 161 char *smoothzoomstr = 0; 162 char *AutoExposureLockstr = 0; 163 char *AutoWhiteBalanceLockstr = 0; 164 char *previewSizeStr = 0; 165 char *awbStr = 0; 166 char *sceneStr = 0; 167 char *focusStr = 0; 168 char *flashStr = 0; 169 char *fpsstr = 0; 170 char *previewFormatStr = 0; 171 char *pictureFormatStr = 0; 172 char **modevalues = 0; 173 char **elem; 174 char **antiband = 0; 175 char **effectss = 0; 176 char **awb = 0; 177 char **scene = 0; 178 char **focus = 0; 179 char **flash = 0; 180 char **exposureMode = 0; 181 char **isoMode = 0; 182 char **previewFormatArray = 0; 183 char **pictureFormatArray = 0; 184 char **fps_const_str = 0; 185 char **rangeDescription = 0; 186 char **fps_range_str = 0; 187 param_Array ** capture_Array = 0; 188 param_Array ** Vcapture_Array = 0; 189 param_Array ** preview_Array = 0; 190 param_Array ** thumbnail_Array = 0; 191 fps_Array * fpsArray = 0; 192 193 int enableMisalignmentCorrectionIdx = 0; 194 195 char **autoconvergencemode = 0; 196 int numAutoConvergence = 0; 197 const char MeteringAreas[] = "(-656,-671,188,454,1)"; 198 199 char **stereoLayout; 200 int numLay = 0; 201 202 char **stereoCapLayout; 203 int numCLay = 0; 204 205 int stereoLayoutIDX = 1; 206 int stereoCapLayoutIDX = 0; 207 208 char *layoutstr =0; 209 char *capturelayoutstr =0; 210 211 char output_dir_path[256]; 212 char videos_dir_path[256 + 8]; 213 char images_dir_path[256 + 8]; 214 215 const char *cameras[] = {"Primary Camera", "Secondary Camera 1", "Stereo Camera"}; 216 const char *measurement[] = {"disable", "enable"}; 217 218 param_NamedExpBracketList_t expBracketing[] = { 219 { 220 "Disabled", 221 PARAM_EXP_BRACKET_PARAM_NONE, 222 PARAM_EXP_BRACKET_VALUE_NONE, 223 PARAM_EXP_BRACKET_APPLY_NONE, 224 "0" 225 }, 226 { 227 "Relative exposure compensation", 228 PARAM_EXP_BRACKET_PARAM_COMP, 229 PARAM_EXP_BRACKET_VALUE_REL, 230 PARAM_EXP_BRACKET_APPLY_ADJUST, 231 "-300,-150,0,150,300,150,0,-150,-300" 232 }, 233 { 234 "Relative exposure compensation (forced)", 235 PARAM_EXP_BRACKET_PARAM_COMP, 236 PARAM_EXP_BRACKET_VALUE_REL, 237 PARAM_EXP_BRACKET_APPLY_FORCED, 238 "-300F,-150F,0F,150F,300F,150F,0F,-150F,-300F" 239 }, 240 { 241 "Absolute exposure and gain", 242 PARAM_EXP_BRACKET_PARAM_PAIR, 243 PARAM_EXP_BRACKET_VALUE_ABS, 244 PARAM_EXP_BRACKET_APPLY_ADJUST, 245 "(33000,10),(0,70),(33000,100),(0,130),(33000,160),(0,180),(33000,200),(0,130),(33000,200)" 246 }, 247 { 248 "Absolute exposure and gain (forced)", 249 PARAM_EXP_BRACKET_PARAM_PAIR, 250 PARAM_EXP_BRACKET_VALUE_ABS, 251 PARAM_EXP_BRACKET_APPLY_FORCED, 252 "(33000,10)F,(0,70)F,(33000,100)F,(0,130)F,(33000,160)F,(0,180)F,(33000,200)F,(0,130)F,(33000,200)F" 253 }, 254 { 255 "Relative exposure and gain", 256 PARAM_EXP_BRACKET_PARAM_PAIR, 257 PARAM_EXP_BRACKET_VALUE_REL, 258 PARAM_EXP_BRACKET_APPLY_ADJUST, 259 "(-300,-100),(-300,+0),(-100, +0),(-100,+100),(+0,+0),(+100,-100),(+100,+0),(+300,+0),(+300,+100)" 260 }, 261 { 262 "Relative exposure and gain (forced)", 263 PARAM_EXP_BRACKET_PARAM_PAIR, 264 PARAM_EXP_BRACKET_VALUE_REL, 265 PARAM_EXP_BRACKET_APPLY_FORCED, 266 "(-300,-100)F,(-300,+0)F,(-100, +0)F,(-100,+100)F,(+0,+0)F,(+100,-100)F,(+100,+0)F,(+300,+0)F,(+300,+100)F" 267 }, 268 }; 269 270 const char *tempBracketing[] = {"false", "true"}; 271 const char *faceDetection[] = {"disable", "enable"}; 272 const char *afTimeout[] = {"enable", "disable" }; 273 274 const char *misalignmentCorrection[] = {"enable", "disable" }; 275 276 #if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 277 const char *ipp_mode[] = { "off", "Chroma Suppression", "Edge Enhancement" }; 278 #else 279 const char *ipp_mode[] = { "off", "ldc", "nsf", "ldc-nsf" }; 280 #endif 281 282 283 const char *caf [] = { "Off", "On" }; 284 285 int numCamera = 0; 286 bool stereoMode = false; 287 288 int manualExp = 0; 289 int manualExpMin = 0; 290 int manualExpMax = 0; 291 int manualExpStep = 0; 292 int manualGain = 0; 293 int manualGainMin = 0; 294 int manualGainMax = 0; 295 int manualGainStep = 0; 296 int manualConv = 0; 297 int manualConvMin = 0; 298 int manualConvMax = 0; 299 int manualConvStep = 0; 300 301 param_Array previewSize [] = { 302 { 0, 0, "NULL"}, 303 { 128, 96, "SQCIF" }, 304 { 176, 144, "QCIF" }, 305 { 352, 288, "CIF" }, 306 { 320, 240, "QVGA" }, 307 { 352, 288, "CIF" }, 308 { 640, 480, "VGA" }, 309 { 720, 480, "NTSC" }, 310 { 720, 576, "PAL" }, 311 { 800, 480, "WVGA" }, 312 { 848, 480, "WVGA2"}, 313 { 864, 480, "WVGA3"}, 314 { 992, 560, "WVGA4"}, 315 { 1280, 720, "HD" }, 316 { 1920, 1080, "FULLHD"}, 317 { 240, 160,"240x160"}, 318 { 768, 576, "768x576" }, 319 { 960, 720, "960x720"}, 320 { 256, 96,"SQCIF"},// stereo 321 { 128, 192, "SQCIF"}, 322 { 352, 144,"QCIF"}, 323 { 176, 288, "QCIF"}, 324 { 480, 160, "240x160"}, 325 { 240, 320, "240x160"}, 326 { 704, 288, "CIF"}, 327 { 352, 576, "CIF"}, 328 { 640, 240,"QVGA"}, 329 { 320, 480, "QVGA"}, 330 { 1280, 480,"VGA"}, 331 { 640, 960, "VGA"}, 332 { 1536, 576,"768x576"}, 333 { 768, 1152, "768x576"}, 334 { 1440, 480,"NTSC"}, 335 { 720, 960,"NTSC"}, 336 { 1440, 576, "PAL"}, 337 { 720, 1152, "PAL"}, 338 { 1600, 480, "WVGA"}, 339 { 800, 960,"WVGA"}, 340 { 2560, 720, "HD"}, 341 { 1280, 1440, "HD"} 342 }; 343 344 size_t length_previewSize = ARRAY_SIZE(previewSize); 345 346 param_Array thumbnailSize [] = { 347 { 0, 0, "NULL"}, 348 { 128, 96, "SQCIF" }, 349 { 176, 144, "QCIF" }, 350 { 352, 288, "CIF" }, 351 { 320, 240, "QVGA" }, 352 { 352, 288, "CIF" }, 353 { 640, 480, "VGA" }, 354 }; 355 356 size_t length_thumbnailSize = ARRAY_SIZE(thumbnailSize); 357 358 param_Array VcaptureSize [] = { 359 { 0, 0, "NULL"}, 360 { 128, 96, "SQCIF" }, 361 { 176, 144, "QCIF" }, 362 { 352, 288, "CIF" }, 363 { 320, 240, "QVGA" }, 364 { 352, 288, "CIF" }, 365 { 640, 480, "VGA" }, 366 { 720, 480, "NTSC" }, 367 { 720, 576, "PAL" }, 368 { 800, 480, "WVGA" }, 369 #if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 370 { 848, 480, "WVGA2"}, 371 { 864, 480, "WVGA3"}, 372 { 992, 560, "WVGA4"}, 373 #endif 374 { 1280, 720, "HD" }, 375 { 1920, 1080, "FULLHD"}, 376 { 240, 160,"240x160"}, 377 { 768, 576, "768x576" }, 378 { 960, 720, "960x720"}, 379 { 256, 96,"SQCIF"},// stereo 380 { 128, 192, "SQCIF"}, 381 { 352, 144,"QCIF"}, 382 { 176, 288, "QCIF"}, 383 { 480, 160, "240x160"}, 384 { 240, 320, "240x160"}, 385 { 704, 288, "CIF"}, 386 { 352, 576, "CIF"}, 387 { 640, 240,"QVGA"}, 388 { 320, 480, "QVGA"}, 389 { 1280, 480,"VGA"}, 390 { 640, 960, "VGA"}, 391 { 1536, 576,"768x576"}, 392 { 768, 1152, "768x576"}, 393 { 1440, 480,"NTSC"}, 394 { 720, 960,"NTSC"}, 395 { 1440, 576, "PAL"}, 396 { 720, 1152, "PAL"}, 397 { 1600, 480, "WVGA"}, 398 { 800, 960,"WVGA"}, 399 { 2560, 720, "HD"}, 400 { 1280, 1440, "HD"} 401 }; 402 403 size_t lenght_Vcapture_size = ARRAY_SIZE(VcaptureSize); 404 405 param_Array captureSize[] = { 406 { 320, 240, "QVGA" }, 407 { 640, 480, "VGA" }, 408 { 800, 600, "SVGA" }, 409 { 1152, 864, "1MP" }, 410 { 1280, 1024, "1.3MP" }, 411 { 1600, 1200, "2MP" }, 412 { 2016, 1512, "3MP" }, 413 { 2592, 1944, "5MP" }, 414 { 2608, 1960, "5MP" }, 415 { 3264, 2448, "8MP" }, 416 { 3648, 2736, "10MP"}, 417 { 4032, 3024, "12MP"}, 418 { 640, 240, "QVGA"}, //stereo 419 { 320, 480, "QVGA"}, 420 { 1280, 480, "VGA"}, 421 { 640, 960, "VGA"}, 422 { 2560, 960, "1280x960"}, 423 { 1280, 1920, "1280x960"}, 424 { 2304, 864, "1MP"}, 425 { 1152, 1728, "1MP"}, 426 { 2560, 1024, "1.3MP"}, 427 { 1280, 2048, "1.3MP"}, 428 { 3200, 1200, "2MP"}, 429 { 1600, 2400, "2MP"}, 430 { 4096, 1536, "3MP"}, 431 { 2048, 3072, "3MP"} 432 }; 433 434 size_t length_capture_Size = ARRAY_SIZE(captureSize); 435 436 outformat outputFormat[] = { 437 { OUTPUT_FORMAT_THREE_GPP, "3gp" }, 438 { OUTPUT_FORMAT_MPEG_4, "mp4" }, 439 }; 440 441 size_t length_outformat = ARRAY_SIZE(outputFormat); 442 443 video_Codecs videoCodecs[] = { 444 { VIDEO_ENCODER_H263, "H263" }, 445 { VIDEO_ENCODER_H264, "H264" }, 446 { VIDEO_ENCODER_MPEG_4_SP, "MPEG4"} 447 }; 448 449 size_t length_video_Codecs = ARRAY_SIZE(videoCodecs); 450 451 audio_Codecs audioCodecs[] = { 452 { AUDIO_ENCODER_AMR_NB, "AMR_NB" }, 453 { AUDIO_ENCODER_AMR_WB, "AMR_WB" }, 454 { AUDIO_ENCODER_AAC, "AAC" }, 455 { AUDIO_ENCODER_HE_AAC, "AAC+" }, 456 { AUDIO_ENCODER_LIST_END, "disabled"}, 457 }; 458 459 size_t length_audio_Codecs = ARRAY_SIZE(audioCodecs); 460 461 V_bitRate VbitRate[] = { 462 { 64000, "64K" }, 463 { 128000, "128K" }, 464 { 192000, "192K" }, 465 { 240000, "240K" }, 466 { 320000, "320K" }, 467 { 360000, "360K" }, 468 { 384000, "384K" }, 469 { 420000, "420K" }, 470 { 768000, "768K" }, 471 { 1000000, "1M" }, 472 { 1500000, "1.5M" }, 473 { 2000000, "2M" }, 474 { 4000000, "4M" }, 475 { 6000000, "6M" }, 476 { 8000000, "8M" }, 477 { 10000000, "10M" }, 478 }; 479 480 size_t length_V_bitRate = ARRAY_SIZE(VbitRate); 481 482 Zoom zoom[] = { 483 { 0, "1x" }, 484 { 12, "1.5x"}, 485 { 20, "2x" }, 486 { 28, "2.5x"}, 487 { 32, "3x" }, 488 { 36, "3.5x"}, 489 { 40, "4x" }, 490 { 60, "8x" }, 491 }; 492 493 size_t length_Zoom = ARRAY_SIZE(zoom); 494 495 pixel_format pixelformat[] = { 496 { HAL_PIXEL_FORMAT_YCbCr_422_I, CameraParameters::PIXEL_FORMAT_YUV422I }, 497 { HAL_PIXEL_FORMAT_YCrCb_420_SP, CameraParameters::PIXEL_FORMAT_YUV420SP }, 498 { HAL_PIXEL_FORMAT_RGB_565, CameraParameters::PIXEL_FORMAT_RGB565 }, 499 { -1, CameraParameters::PIXEL_FORMAT_JPEG }, 500 { -1, CameraParameters::PIXEL_FORMAT_BAYER_RGGB }, 501 }; 502 503 const char *gbce[] = {"disable", "enable"}; 504 505 int VbitRateIDX = ARRAY_SIZE(VbitRate) - 1; 506 507 static unsigned int recording_counter = 1; 508 509 int dump_preview = 0; 510 int bufferStarvationTest = 0; 511 bool showfps = false; 512 513 const char *metering[] = { 514 "center", 515 "average", 516 }; 517 int meter_mode = 0; 518 bool stressTest = false; 519 bool stopScript = false; 520 int restartCount = 0; 521 bool firstTime = true; 522 bool firstTimeStereo = true; 523 524 //TI extensions for enable/disable algos 525 const char *algoFixedGamma[] = {CameraParameters::FALSE, CameraParameters::TRUE}; 526 const char *algoNSF1[] = {CameraParameters::FALSE, CameraParameters::TRUE}; 527 const char *algoNSF2[] = {CameraParameters::FALSE, CameraParameters::TRUE}; 528 const char *algoSharpening[] = {CameraParameters::FALSE, CameraParameters::TRUE}; 529 const char *algoThreeLinColorMap[] = {CameraParameters::FALSE, CameraParameters::TRUE}; 530 const char *algoGIC[] = {CameraParameters::FALSE, CameraParameters::TRUE}; 531 int algoFixedGammaIDX = 1; 532 int algoNSF1IDX = 1; 533 int algoNSF2IDX = 1; 534 int algoSharpeningIDX = 1; 535 int algoThreeLinColorMapIDX = 1; 536 int algoGICIDX = 1; 537 538 /** Buffer source reset */ 539 bool bufferSourceInputReset = false; 540 bool bufferSourceOutputReset = false; 541 542 /** Calculate delay from a reference time */ 543 unsigned long long timeval_delay(const timeval *ref) { 544 unsigned long long st, end, delay; 545 timeval current_time; 546 547 gettimeofday(¤t_time, 0); 548 549 st = ref->tv_sec * 1000000 + ref->tv_usec; 550 end = current_time.tv_sec * 1000000 + current_time.tv_usec; 551 delay = end - st; 552 553 return delay; 554 } 555 556 /** Callback for takePicture() */ 557 void my_raw_callback(const sp<IMemory>& mem) { 558 559 static int counter = 1; 560 unsigned char *buff = NULL; 561 int size; 562 int fd = -1; 563 char fn[384]; 564 565 LOG_FUNCTION_NAME; 566 567 if (mem == NULL) 568 goto out; 569 570 if( strcmp(modevalues[capture_mode], "cp-cam") ) { 571 //Start preview after capture. 572 camera->startPreview(); 573 } 574 575 fn[0] = 0; 576 sprintf(fn, "%s/img%03d.raw", images_dir_path, counter); 577 fd = open(fn, O_CREAT | O_WRONLY | O_TRUNC, 0777); 578 579 if (fd < 0) 580 goto out; 581 582 size = mem->size(); 583 584 if (size <= 0) 585 goto out; 586 587 buff = (unsigned char *)mem->pointer(); 588 589 if (!buff) 590 goto out; 591 592 if (size != write(fd, buff, size)) 593 printf("Bad Write int a %s error (%d)%s\n", fn, errno, strerror(errno)); 594 595 counter++; 596 printf("%s: buffer=%08X, size=%d stored at %s\n", 597 __FUNCTION__, (int)buff, size, fn); 598 599 out: 600 601 if (fd >= 0) 602 close(fd); 603 604 LOG_FUNCTION_NAME_EXIT; 605 } 606 607 void saveFile(const sp<IMemory>& mem) { 608 static int counter = 1; 609 unsigned char *buff = NULL; 610 int size; 611 int fd = -1; 612 char fn[384]; 613 614 LOG_FUNCTION_NAME; 615 616 if (mem == NULL) 617 goto out; 618 619 fn[0] = 0; 620 sprintf(fn, "%s/preview%03d.yuv", images_dir_path, counter); 621 fd = open(fn, O_CREAT | O_WRONLY | O_TRUNC, 0777); 622 if(fd < 0) { 623 CAMHAL_LOGE("Unable to open file %s: %s", fn, strerror(fd)); 624 goto out; 625 } 626 627 size = mem->size(); 628 if (size <= 0) { 629 CAMHAL_LOGE("IMemory object is of zero size"); 630 goto out; 631 } 632 633 buff = (unsigned char *)mem->pointer(); 634 if (!buff) { 635 CAMHAL_LOGE("Buffer pointer is invalid"); 636 goto out; 637 } 638 639 if (size != write(fd, buff, size)) 640 printf("Bad Write int a %s error (%d)%s\n", fn, errno, strerror(errno)); 641 642 counter++; 643 printf("%s: buffer=%08X, size=%d\n", 644 __FUNCTION__, (int)buff, size); 645 646 out: 647 648 if (fd >= 0) 649 close(fd); 650 651 LOG_FUNCTION_NAME_EXIT; 652 } 653 654 655 void debugShowFPS() 656 { 657 static int mFrameCount = 0; 658 static int mLastFrameCount = 0; 659 static nsecs_t mLastFpsTime = 0; 660 static float mFps = 0; 661 mFrameCount++; 662 if ( ( mFrameCount % 30 ) == 0 ) { 663 nsecs_t now = systemTime(); 664 nsecs_t diff = now - mLastFpsTime; 665 mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff; 666 mLastFpsTime = now; 667 mLastFrameCount = mFrameCount; 668 printf("####### [%d] Frames, %f FPS", mFrameCount, mFps); 669 } 670 } 671 672 /** Callback for startPreview() */ 673 void my_preview_callback(const sp<IMemory>& mem) { 674 675 printf("PREVIEW Callback 0x%x", ( unsigned int ) mem->pointer()); 676 if (dump_preview) { 677 678 if(prevcnt==50) 679 saveFile(mem); 680 681 prevcnt++; 682 683 uint8_t *ptr = (uint8_t*) mem->pointer(); 684 685 printf("PRV_CB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9]); 686 687 } 688 689 debugShowFPS(); 690 } 691 692 /** Callback for takePicture() */ 693 void my_jpeg_callback(const sp<IMemory>& mem) { 694 static int counter = 1; 695 unsigned char *buff = NULL; 696 int size; 697 int fd = -1; 698 char fn[384]; 699 700 LOG_FUNCTION_NAME; 701 702 if( strcmp(modevalues[capture_mode], "cp-cam")) { 703 if(burstCount > 1) { 704 burstCount --; 705 // Restart preview if taking a single capture 706 // or after the last iteration of burstCount 707 } else if(burstCount == 0 || burstCount == 1) { 708 camera->startPreview(); 709 burstCount = burst; 710 } 711 } 712 713 if (mem == NULL) 714 goto out; 715 716 fn[0] = 0; 717 sprintf(fn, "%s/img%03d.jpg", images_dir_path, counter); 718 fd = open(fn, O_CREAT | O_WRONLY | O_TRUNC, 0777); 719 720 if(fd < 0) { 721 CAMHAL_LOGE("Unable to open file %s: %s", fn, strerror(fd)); 722 goto out; 723 } 724 725 size = mem->size(); 726 if (size <= 0) { 727 CAMHAL_LOGE("IMemory object is of zero size"); 728 goto out; 729 } 730 731 buff = (unsigned char *)mem->pointer(); 732 if (!buff) { 733 CAMHAL_LOGE("Buffer pointer is invalid"); 734 goto out; 735 } 736 737 if (size != write(fd, buff, size)) 738 printf("Bad Write int a %s error (%d)%s\n", fn, errno, strerror(errno)); 739 740 counter++; 741 printf("%s: buffer=%08X, size=%d stored at %s\n", 742 __FUNCTION__, (int)buff, size, fn); 743 744 out: 745 746 if (fd >= 0) 747 close(fd); 748 749 LOG_FUNCTION_NAME_EXIT; 750 } 751 752 void my_face_callback(camera_frame_metadata_t *metadata) { 753 int idx; 754 755 if ( NULL == metadata ) { 756 return; 757 } 758 759 for ( idx = 0 ; idx < metadata->number_of_faces ; idx++ ) { 760 printf("Face %d at %d,%d %d,%d \n", 761 idx, 762 metadata->faces[idx].rect[0], 763 metadata->faces[idx].rect[1], 764 metadata->faces[idx].rect[2], 765 metadata->faces[idx].rect[3]); 766 } 767 768 } 769 770 void CameraHandler::notify(int32_t msgType, int32_t ext1, int32_t ext2) { 771 772 printf("Notify cb: %d %d %d\n", msgType, ext1, ext2); 773 774 if ( msgType & CAMERA_MSG_FOCUS ) 775 printf("AutoFocus %s in %llu us\n", (ext1) ? "OK" : "FAIL", timeval_delay(&autofocus_start)); 776 777 if ( msgType & CAMERA_MSG_SHUTTER ) 778 printf("Shutter done in %llu us\n", timeval_delay(&picture_start)); 779 780 if ( msgType & CAMERA_MSG_ERROR && (ext1 == 1)) 781 { 782 printf("Camera Test CAMERA_MSG_ERROR.....\n"); 783 if (stressTest) 784 { 785 printf("Camera Test Notified of Error Restarting.....\n"); 786 stopScript = true; 787 } 788 else 789 { 790 printf("Camera Test Notified of Error Stopping.....\n"); 791 stopScript =false; 792 stopPreview(); 793 794 if (recordingMode) 795 { 796 stopRecording(); 797 closeRecorder(); 798 recordingMode = false; 799 } 800 } 801 } 802 } 803 804 void CameraHandler::postData(int32_t msgType, 805 const sp<IMemory>& dataPtr, 806 camera_frame_metadata_t *metadata) { 807 int32_t msgMask; 808 printf("Data cb: %d\n", msgType); 809 810 if ( msgType & CAMERA_MSG_PREVIEW_FRAME ) 811 my_preview_callback(dataPtr); 812 813 msgMask = CAMERA_MSG_RAW_IMAGE; 814 #ifdef OMAP_ENHANCEMENT_BURST_CAPTURE 815 msgMask |= CAMERA_MSG_RAW_BURST; 816 #endif 817 if ( msgType & msgMask) { 818 printf("RAW done in %llu us\n", timeval_delay(&picture_start)); 819 my_raw_callback(dataPtr); 820 } 821 822 if (msgType & CAMERA_MSG_POSTVIEW_FRAME) { 823 printf("Postview frame %llu us\n", timeval_delay(&picture_start)); 824 } 825 826 if (msgType & CAMERA_MSG_COMPRESSED_IMAGE ) { 827 printf("JPEG done in %llu us\n", timeval_delay(&picture_start)); 828 my_jpeg_callback(dataPtr); 829 } 830 831 if ( ( msgType & CAMERA_MSG_PREVIEW_METADATA ) && 832 ( NULL != metadata ) ) { 833 if (metaDataToggle) { 834 printf("Preview exposure: %6d Preview gain: %4d\n", 835 metadata->exposure_time, metadata->analog_gain); 836 } 837 838 if (faceDetectToggle) { 839 printf("Face detected %d \n", metadata->number_of_faces); 840 my_face_callback(metadata); 841 } 842 } 843 } 844 845 void CameraHandler::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) 846 847 { 848 static uint32_t count = 0; 849 850 //if(count==100) 851 //saveFile(dataPtr); 852 853 count++; 854 855 uint8_t *ptr = (uint8_t*) dataPtr->pointer(); 856 857 #ifdef OMAP_ENHANCEMENT_BURST_CAPTURE 858 if ( msgType & CAMERA_MSG_RAW_BURST) { 859 printf("RAW done timestamp: %llu\n", timestamp); 860 my_raw_callback(dataPtr); 861 } else 862 #endif 863 { 864 printf("Recording cb: %d %lld %p\n", msgType, timestamp, dataPtr.get()); 865 printf("VID_CB: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9]); 866 camera->releaseRecordingFrame(dataPtr); 867 } 868 } 869 870 int createPreviewSurface(unsigned int width, unsigned int height, int32_t pixFormat) { 871 unsigned int previewWidth, previewHeight; 872 DisplayInfo dinfo; 873 SurfaceComposerClient::getDisplayInfo(0, &dinfo); 874 875 const unsigned MAX_PREVIEW_SURFACE_WIDTH = dinfo.w; 876 const unsigned MAX_PREVIEW_SURFACE_HEIGHT = dinfo.h; 877 878 if ( MAX_PREVIEW_SURFACE_WIDTH < width ) { 879 previewWidth = MAX_PREVIEW_SURFACE_WIDTH; 880 } else { 881 previewWidth = width; 882 } 883 884 if ( MAX_PREVIEW_SURFACE_HEIGHT < height ) { 885 previewHeight = MAX_PREVIEW_SURFACE_HEIGHT; 886 } else { 887 previewHeight = height; 888 } 889 890 client = new SurfaceComposerClient(); 891 892 if ( NULL == client.get() ) { 893 printf("Unable to establish connection to Surface Composer \n"); 894 895 return -1; 896 } 897 898 surfaceControl = client->createSurface(0, 899 previewWidth, 900 previewHeight, 901 pixFormat); 902 903 previewSurface = surfaceControl->getSurface(); 904 905 client->openGlobalTransaction(); 906 surfaceControl->setLayer(0x7fffffff); 907 surfaceControl->setPosition(0, 0); 908 surfaceControl->setSize(previewWidth, previewHeight); 909 surfaceControl->show(); 910 client->closeGlobalTransaction(); 911 912 return 0; 913 } 914 915 void printSupportedParams() 916 { 917 printf("\n\r\tSupported Cameras: %s", params.get("camera-indexes")); 918 printf("\n\r\tSupported Picture Sizes: %s", params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES)); 919 printf("\n\r\tSupported Picture Formats: %s", params.get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS)); 920 printf("\n\r\tSupported Video Formats: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 921 printf("\n\r\tSupported Preview Sizes: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 922 printf("\n\r\tSupported Preview Formats: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS)); 923 printf("\n\r\tSupported Preview Frame Rates: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES)); 924 printf("\n\r\tSupported Thumbnail Sizes: %s", params.get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES)); 925 printf("\n\r\tSupported Whitebalance Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE)); 926 printf("\n\r\tSupported Effects: %s", params.get(CameraParameters::KEY_SUPPORTED_EFFECTS)); 927 printf("\n\r\tSupported Scene Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES)); 928 printf("\n\r\tSupported ISO Modes: %s", params.get("iso-mode-values")); 929 printf("\n\r\tSupported Focus Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES)); 930 printf("\n\r\tSupported Antibanding Options: %s", params.get(CameraParameters::KEY_SUPPORTED_ANTIBANDING)); 931 printf("\n\r\tSupported Flash Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES)); 932 printf("\n\r\tSupported Focus Areas: %d", params.getInt(CameraParameters::KEY_MAX_NUM_FOCUS_AREAS)); 933 printf("\n\r\tSupported Metering Areas: %d", params.getInt(CameraParameters::KEY_MAX_NUM_METERING_AREAS)); 934 printf("\n\r\tSupported Preview FPS Range: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE)); 935 printf("\n\r\tSupported Exposure modes: %s", params.get("exposure-mode-values")); 936 printf("\n\r\tSupported VSTAB modes: %s", params.get(CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED)); 937 printf("\n\r\tSupported VNF modes: %s", params.get("vnf-supported")); 938 printf("\n\r\tSupported AutoExposureLock: %s", params.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED)); 939 printf("\n\r\tSupported AutoWhiteBalanceLock: %s", params.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED)); 940 printf("\n\r\tSupported Zoom: %s", params.get(CameraParameters::KEY_ZOOM_SUPPORTED)); 941 printf("\n\r\tSupported Smooth Zoom: %s", params.get(CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED)); 942 printf("\n\r\tSupported Video Snapshot: %s", params.get(CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED)); 943 printf("\n\r\tSupported Capture modes: %s", params.get("mode-values")); 944 945 if ( NULL != params.get(CameraParameters::KEY_FOCUS_DISTANCES) ) { 946 printf("\n\r\tFocus Distances: %s \n", params.get(CameraParameters::KEY_FOCUS_DISTANCES)); 947 } 948 949 return; 950 } 951 952 953 int destroyPreviewSurface() { 954 955 if ( NULL != previewSurface.get() ) { 956 previewSurface.clear(); 957 } 958 959 if ( NULL != surfaceControl.get() ) { 960 surfaceControl->clear(); 961 surfaceControl.clear(); 962 } 963 964 if ( NULL != client.get() ) { 965 client->dispose(); 966 client.clear(); 967 } 968 969 return 0; 970 } 971 972 int openRecorder() { 973 recorder = new MediaRecorder(); 974 975 if ( NULL == recorder.get() ) { 976 printf("Error while creating MediaRecorder\n"); 977 978 return -1; 979 } 980 981 return 0; 982 } 983 984 int closeRecorder() { 985 if ( NULL == recorder.get() ) { 986 printf("invalid recorder reference\n"); 987 988 return -1; 989 } 990 991 if ( recorder->init() < 0 ) { 992 printf("recorder failed to initialize\n"); 993 994 return -1; 995 } 996 997 if ( recorder->close() < 0 ) { 998 printf("recorder failed to close\n"); 999 1000 return -1; 1001 } 1002 1003 if ( recorder->release() < 0 ) { 1004 printf("error while releasing recorder\n"); 1005 1006 return -1; 1007 } 1008 1009 recorder.clear(); 1010 1011 return 0; 1012 } 1013 1014 int configureRecorder() { 1015 1016 char videoFile[384],vbit_string[50]; 1017 videoFd = -1; 1018 struct CameraInfo cameraInfo; 1019 camera->getCameraInfo(camera_index, &cameraInfo); 1020 1021 if ( ( NULL == recorder.get() ) || ( NULL == camera.get() ) ) { 1022 printf("invalid recorder and/or camera references\n"); 1023 1024 return -1; 1025 } 1026 1027 camera->unlock(); 1028 1029 sprintf(vbit_string,"video-param-encoding-bitrate=%u", VbitRate[VbitRateIDX].bit_rate); 1030 String8 bit_rate(vbit_string); 1031 if ( recorder->setParameters(bit_rate) < 0 ) { 1032 printf("error while configuring bit rate\n"); 1033 1034 return -1; 1035 } 1036 1037 if ( recorder->setCamera(camera->remote(), camera->getRecordingProxy()) < 0 ) { 1038 printf("error while setting the camera\n"); 1039 1040 return -1; 1041 } 1042 1043 if ( recorder->setVideoSource(VIDEO_SOURCE_CAMERA) < 0 ) { 1044 printf("error while configuring camera video source\n"); 1045 1046 return -1; 1047 } 1048 1049 1050 if ( AUDIO_ENCODER_LIST_END != audioCodecs[audioCodecIDX].type ) { 1051 if ( recorder->setAudioSource(AUDIO_SOURCE_DEFAULT) < 0 ) { 1052 printf("error while configuring camera audio source\n"); 1053 1054 return -1; 1055 } 1056 } 1057 1058 if ( recorder->setOutputFormat(outputFormat[outputFormatIDX].type) < 0 ) { 1059 printf("error while configuring output format\n"); 1060 1061 return -1; 1062 } 1063 1064 sprintf(videoFile, "%s/video%d.%s", videos_dir_path, recording_counter, outputFormat[outputFormatIDX].desc); 1065 1066 videoFd = open(videoFile, O_CREAT | O_RDWR); 1067 1068 if(videoFd < 0){ 1069 printf("Error while creating video filename\n"); 1070 1071 return -1; 1072 } 1073 1074 if ( recorder->setOutputFile(videoFd, 0, 0) < 0 ) { 1075 printf("error while configuring video filename\n"); 1076 1077 return -1; 1078 } 1079 1080 recording_counter++; 1081 1082 if (cameraInfo.orientation == 90 || cameraInfo.orientation == 270 ) { 1083 if ( recorder->setVideoSize(Vcapture_Array[VcaptureSizeIDX]->height, Vcapture_Array[VcaptureSizeIDX]->width) < 0 ) { 1084 printf("error while configuring video size\n"); 1085 return -1; 1086 } 1087 } else { 1088 if ( recorder->setVideoSize(Vcapture_Array[VcaptureSizeIDX]->width, Vcapture_Array[VcaptureSizeIDX]->height) < 0 ) { 1089 printf("error while configuring video size\n"); 1090 return -1; 1091 } 1092 } 1093 1094 if ( recorder->setVideoEncoder(videoCodecs[videoCodecIDX].type) < 0 ) { 1095 printf("error while configuring video codec\n"); 1096 1097 return -1; 1098 } 1099 1100 if ( AUDIO_ENCODER_LIST_END != audioCodecs[audioCodecIDX].type ) { 1101 if ( recorder->setAudioEncoder(audioCodecs[audioCodecIDX].type) < 0 ) { 1102 printf("error while configuring audio codec\n"); 1103 1104 return -1; 1105 } 1106 } 1107 1108 if ( recorder->setPreviewSurface( surfaceControl->getSurface()->getIGraphicBufferProducer() ) < 0 ) { 1109 printf("error while configuring preview surface\n"); 1110 1111 return -1; 1112 } 1113 1114 return 0; 1115 } 1116 1117 int startRecording() { 1118 if ( ( NULL == recorder.get() ) || ( NULL == camera.get() ) ) { 1119 printf("invalid recorder and/or camera references\n"); 1120 1121 return -1; 1122 } 1123 1124 camera->unlock(); 1125 1126 if ( recorder->prepare() < 0 ) { 1127 printf("recorder prepare failed\n"); 1128 1129 return -1; 1130 } 1131 1132 if ( recorder->start() < 0 ) { 1133 printf("recorder start failed\n"); 1134 1135 return -1; 1136 } 1137 1138 return 0; 1139 } 1140 1141 int stopRecording() { 1142 if ( NULL == recorder.get() ) { 1143 printf("invalid recorder reference\n"); 1144 1145 return -1; 1146 } 1147 1148 if ( recorder->stop() < 0 ) { 1149 printf("recorder failed to stop\n"); 1150 1151 return -1; 1152 } 1153 1154 if ( 0 < videoFd ) { 1155 close(videoFd); 1156 } 1157 1158 return 0; 1159 } 1160 1161 int openCamera() { 1162 1163 antibandStr = new char [256]; 1164 effectssStr = new char [256]; 1165 exposureModeStr = new char [256]; 1166 captureSizeStr = new char [500]; 1167 VcaptureSizeStr = new char [500]; 1168 previewSizeStr = new char [500]; 1169 thumbnailSizeStr = new char [500]; 1170 awbStr = new char [400]; 1171 sceneStr = new char [400]; 1172 isoModeStr = new char [256]; 1173 focusStr = new char [256]; 1174 flashStr = new char [256]; 1175 fpsstr = new char [256]; 1176 previewFormatStr = new char [256]; 1177 pictureFormatStr = new char [256]; 1178 constFramerate = new int[32]; 1179 vstabstr = new char[256]; 1180 vnfstr = new char[256]; 1181 AutoExposureLockstr = new char[256]; 1182 AutoWhiteBalanceLockstr = new char[256]; 1183 zoomstr = new char[256]; 1184 smoothzoomstr = new char[256]; 1185 modevaluesstr = new char[256]; 1186 videosnapshotstr = new char[256]; 1187 autoconvergencestr = new char[256]; 1188 layoutstr = new char[256]; 1189 capturelayoutstr = new char[256]; 1190 1191 requestBufferSourceReset(); 1192 1193 printf("openCamera(camera_index=%d)\n", camera_index); 1194 camera = Camera::connect(camera_index); 1195 1196 if ( NULL == camera.get() ) { 1197 printf("Unable to connect to CameraService\n"); 1198 printf("Retrying... \n"); 1199 sleep(1); 1200 camera = Camera::connect(camera_index); 1201 1202 if ( NULL == camera.get() ) { 1203 printf("Giving up!! \n"); 1204 return -1; 1205 } 1206 } 1207 1208 if ( firstTime ) { 1209 params = camera->getParameters(); 1210 firstTime = false; 1211 } 1212 getParametersFromCapabilities(); 1213 getSizeParametersFromCapabilities(); 1214 camera->setParameters(params.flatten()); 1215 camera->setListener(new CameraHandler()); 1216 1217 hardwareActive = true; 1218 1219 1220 1221 return 0; 1222 } 1223 1224 int closeCamera() { 1225 if ( NULL == camera.get() ) { 1226 printf("invalid camera reference\n"); 1227 1228 return -1; 1229 } 1230 1231 deleteAllocatedMemory(); 1232 1233 camera->disconnect(); 1234 camera.clear(); 1235 1236 hardwareActive = false; 1237 return 0; 1238 } 1239 1240 void createBufferOutputSource() { 1241 if(bufferSourceOutputThread.get() && bufferSourceOutputReset) { 1242 bufferSourceOutputThread->requestExit(); 1243 bufferSourceOutputThread.clear(); 1244 } 1245 if(!bufferSourceOutputThread.get()) { 1246 #ifdef ANDROID_API_JB_OR_LATER 1247 bufferSourceOutputThread = new BQ_BufferSourceThread(123, camera); 1248 #else 1249 bufferSourceOutputThread = new ST_BufferSourceThread(false, 123, camera); 1250 #endif 1251 bufferSourceOutputThread->run(); 1252 } 1253 bufferSourceOutputReset = false; 1254 } 1255 1256 void createBufferInputSource() { 1257 if (bufferSourceInput.get() && bufferSourceInputReset) { 1258 bufferSourceInput.clear(); 1259 } 1260 if (!bufferSourceInput.get()) { 1261 #ifdef ANDROID_API_JB_OR_LATER 1262 bufferSourceInput = new BQ_BufferSourceInput(1234, camera); 1263 #else 1264 bufferSourceInput = new ST_BufferSourceInput(1234, camera); 1265 #endif 1266 } 1267 bufferSourceInputReset = false; 1268 } 1269 1270 void requestBufferSourceReset() { 1271 bufferSourceInputReset = true; 1272 bufferSourceOutputReset = true; 1273 } 1274 1275 int startPreview() { 1276 int previewWidth, previewHeight; 1277 struct CameraInfo cameraInfo; 1278 DisplayInfo dinfo; 1279 int orientation; 1280 unsigned int correctedHeight; 1281 1282 SurfaceComposerClient::getDisplayInfo(0, &dinfo); 1283 1284 printf ("dinfo.orientation = %d\n", dinfo.orientation); 1285 printf ("dinfo.w = %d\n", dinfo.w); 1286 printf ("dinfo.h = %d\n", dinfo.h); 1287 1288 // calculate display orientation from sensor orientation 1289 camera->getCameraInfo(camera_index, &cameraInfo); 1290 if (cameraInfo.facing == CAMERA_FACING_FRONT) { 1291 orientation = (cameraInfo.orientation + dinfo.orientation) % 360; 1292 orientation = (360 - orientation) % 360; // compensate the mirror 1293 } else { // back-facing 1294 orientation = (cameraInfo.orientation - dinfo.orientation + 360) % 360; 1295 } 1296 1297 1298 if (reSizePreview) { 1299 int orientedWidth, orientedHeight; 1300 1301 if(recordingMode) 1302 { 1303 previewWidth = Vcapture_Array[VcaptureSizeIDX]->width; 1304 previewHeight = Vcapture_Array[VcaptureSizeIDX]->height; 1305 }else 1306 { 1307 previewWidth = preview_Array[previewSizeIDX]->width; 1308 previewHeight = preview_Array[previewSizeIDX]->height; 1309 } 1310 1311 // corrected height for aspect ratio 1312 if ((orientation == 90) || (orientation == 270)) { 1313 orientedHeight = previewWidth; 1314 orientedWidth = previewHeight; 1315 } else { 1316 orientedHeight = previewHeight; 1317 orientedWidth = previewWidth; 1318 } 1319 correctedHeight = (dinfo.w * orientedHeight) / orientedWidth; 1320 printf("correctedHeight = %d", correctedHeight); 1321 1322 if ( createPreviewSurface(dinfo.w, correctedHeight, 1323 pixelformat[previewFormat].pixelFormatDesc) < 0 ) { 1324 printf("Error while creating preview surface\n"); 1325 return -1; 1326 } 1327 1328 if ( !hardwareActive ) { 1329 openCamera(); 1330 } 1331 if(stereoMode && firstTimeStereo) 1332 { 1333 params.set(KEY_S3D_PRV_FRAME_LAYOUT, stereoLayout[stereoLayoutIDX]); 1334 params.set(KEY_S3D_CAP_FRAME_LAYOUT, stereoCapLayout[stereoCapLayoutIDX]); 1335 } 1336 1337 if ((cameraInfo.orientation == 90 || cameraInfo.orientation == 270) && recordingMode) { 1338 params.setPreviewSize(previewHeight, previewWidth); 1339 } else { 1340 params.setPreviewSize(previewWidth, previewHeight); 1341 } 1342 params.setPictureSize(capture_Array[captureSizeIDX]->width, capture_Array[captureSizeIDX]->height); 1343 1344 // calculate display orientation from sensor orientation 1345 camera->getCameraInfo(camera_index, &cameraInfo); 1346 if (cameraInfo.facing == CAMERA_FACING_FRONT) { 1347 orientation = (cameraInfo.orientation + dinfo.orientation) % 360; 1348 orientation= (360 - orientation) % 360; // compensate the mirror 1349 } else { // back-facing 1350 orientation = (cameraInfo.orientation - dinfo.orientation + 360) % 360; 1351 } 1352 1353 if(!strcmp(params.get(KEY_MODE), "video-mode") ) { 1354 orientation = 0; 1355 } 1356 1357 camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, orientation, 0); 1358 1359 camera->setParameters(params.flatten()); 1360 camera->setPreviewTexture(previewSurface->getIGraphicBufferProducer()); 1361 } 1362 1363 if(hardwareActive) prevcnt = 0; 1364 camera->startPreview(); 1365 previewRunning = true; 1366 reSizePreview = false; 1367 1368 const char *format = params.getPictureFormat(); 1369 if((NULL != format) && isRawPixelFormat(format)) { 1370 createBufferOutputSource(); 1371 createBufferInputSource(); 1372 } 1373 1374 return 0; 1375 } 1376 1377 int getParametersFromCapabilities() { 1378 const char *valstr = NULL; 1379 1380 numCamera = camera->getNumberOfCameras(); 1381 1382 params.unflatten(camera->getParameters()); 1383 1384 valstr = params.get(KEY_AUTOCONVERGENCE_MODE_VALUES); 1385 if (NULL != valstr) { 1386 strcpy(autoconvergencestr, valstr); 1387 getSupportedParameters(autoconvergencestr,&numAutoConvergence,(char***)&autoconvergencemode); 1388 } else { 1389 printf("no supported parameteters for autoconvergence\n\t"); 1390 } 1391 1392 valstr = params.get(CameraParameters::KEY_SUPPORTED_EFFECTS); 1393 if (NULL != valstr) { 1394 strcpy(effectssStr, valstr); 1395 getSupportedParameters(effectssStr, &numEffects, (char***)&effectss); 1396 } else { 1397 printf("Color effects are not supported\n"); 1398 } 1399 1400 valstr = params.get(CameraParameters::KEY_SUPPORTED_ANTIBANDING); 1401 if (NULL != valstr) { 1402 strcpy(antibandStr, valstr); 1403 getSupportedParameters(antibandStr, &numAntibanding, (char***)&antiband); 1404 } else { 1405 printf("Antibanding not supported\n"); 1406 } 1407 1408 valstr = params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE); 1409 if (NULL != valstr) { 1410 strcpy(awbStr, valstr); 1411 getSupportedParameters(awbStr, &numawb, (char***)&awb); 1412 } else { 1413 printf("White balance is not supported\n"); 1414 } 1415 1416 valstr = params.get(KEY_S3D_PRV_FRAME_LAYOUT_VALUES); 1417 if ((NULL != valstr) && (0 != strcmp(valstr, "none"))) { 1418 stereoMode = true; 1419 strcpy(layoutstr, valstr); 1420 getSupportedParameters(layoutstr,&numLay,(char***)&stereoLayout); 1421 } else { 1422 stereoMode = false; 1423 printf("layout is not supported\n"); 1424 } 1425 1426 valstr = params.get(KEY_S3D_CAP_FRAME_LAYOUT_VALUES); 1427 if ((NULL != valstr) && (0 != strcmp(valstr, "none"))) { 1428 strcpy(capturelayoutstr, valstr); 1429 getSupportedParameters(capturelayoutstr,&numCLay,(char***)&stereoCapLayout); 1430 } else { 1431 printf("capture layout is not supported\n"); 1432 } 1433 1434 valstr = params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES); 1435 if (NULL != valstr) { 1436 strcpy(sceneStr, valstr); 1437 getSupportedParameters(sceneStr, &numscene, (char***)&scene); 1438 } else { 1439 printf("Scene modes are not supported\n"); 1440 } 1441 1442 valstr = params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES); 1443 if (NULL != valstr) { 1444 strcpy(focusStr, valstr); 1445 getSupportedParameters(focusStr, &numfocus, (char***)&focus); 1446 } else { 1447 printf("Focus modes are not supported\n"); 1448 } 1449 1450 valstr = params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES); 1451 if (NULL != valstr) { 1452 strcpy(flashStr, valstr); 1453 getSupportedParameters(flashStr, &numflash, (char***)&flash); 1454 } else { 1455 printf("Flash modes are not supported\n"); 1456 } 1457 1458 valstr = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); 1459 if (NULL != valstr) { 1460 strcpy(VcaptureSizeStr, valstr); 1461 getSupportedParametersVideoCaptureSize(VcaptureSizeStr, &numVcaptureSize, VcaptureSize, lenght_Vcapture_size); 1462 } else { 1463 printf("Preview sizes are not supported\n"); 1464 } 1465 1466 valstr = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE); 1467 if (NULL != valstr) { 1468 strcpy(fpsstr, valstr); 1469 getSupportedParametersfps(fpsstr, &numfps); 1470 } else { 1471 printf("Preview fps range is not supported\n"); 1472 } 1473 1474 valstr = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); 1475 if (NULL != valstr) { 1476 strcpy(previewFormatStr, valstr); 1477 getSupportedParameters(previewFormatStr, &numpreviewFormat, (char ***)&previewFormatArray); 1478 } else { 1479 printf("Preview formats are not supported\n"); 1480 } 1481 1482 valstr = params.get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS); 1483 if (NULL != valstr) { 1484 strcpy(pictureFormatStr, valstr); 1485 getSupportedParameters(pictureFormatStr, &numpictureFormat, (char ***)&pictureFormatArray); 1486 } else { 1487 printf("Picture formats are not supported\n"); 1488 } 1489 1490 valstr = params.get("exposure-mode-values"); 1491 if (NULL != valstr) { 1492 strcpy(exposureModeStr, valstr); 1493 getSupportedParameters(exposureModeStr, &numExposureMode, (char***)&exposureMode); 1494 } else { 1495 printf("Exposure modes are not supported\n"); 1496 } 1497 1498 valstr = params.get("iso-mode-values"); 1499 if (NULL != valstr) { 1500 strcpy(isoModeStr, valstr); 1501 getSupportedParameters(isoModeStr, &numisoMode , (char***)&isoMode); 1502 } else { 1503 printf("iso modes are not supported\n"); 1504 } 1505 1506 valstr = params.get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES); 1507 if (NULL != valstr) { 1508 strcpy(thumbnailSizeStr, valstr); 1509 getSupportedParametersThumbnailSize(thumbnailSizeStr, &numthumbnailSize, thumbnailSize, length_thumbnailSize); 1510 } else { 1511 printf("Thumbnail sizes are not supported\n"); 1512 } 1513 1514 valstr = params.get(CameraParameters::KEY_VIDEO_STABILIZATION_SUPPORTED); 1515 if (NULL != valstr) { 1516 strcpy(vstabstr, valstr); 1517 } else { 1518 printf("VSTAB is not supported\n"); 1519 } 1520 1521 valstr = params.get("vnf-supported"); 1522 if (NULL != valstr) { 1523 strcpy(vnfstr, valstr); 1524 } else { 1525 printf("VNF is not supported\n"); 1526 } 1527 1528 valstr = params.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED); 1529 if (NULL != valstr) { 1530 strcpy(AutoExposureLockstr, valstr); 1531 } else { 1532 printf("AutoExposureLock is not supported\n"); 1533 } 1534 1535 valstr = params.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED); 1536 if (NULL != valstr) { 1537 strcpy(AutoWhiteBalanceLockstr, valstr); 1538 } else { 1539 printf("AutoWhiteBalanceLock is not supported\n"); 1540 } 1541 1542 valstr = params.get(CameraParameters::KEY_ZOOM_SUPPORTED); 1543 if (NULL != valstr) { 1544 strcpy(zoomstr, valstr); 1545 } else { 1546 printf("Zoom is not supported\n"); 1547 } 1548 1549 valstr = params.get(CameraParameters::KEY_SMOOTH_ZOOM_SUPPORTED); 1550 if (NULL != valstr) { 1551 strcpy(smoothzoomstr, valstr); 1552 } else { 1553 printf("SmoothZoom is not supported\n"); 1554 } 1555 1556 valstr = params.get("mode-values"); 1557 if (NULL != valstr) { 1558 strcpy(modevaluesstr, valstr); 1559 getSupportedParameters(modevaluesstr, &nummodevalues , (char***)&modevalues); 1560 } else { 1561 printf("Mode values is not supported\n"); 1562 } 1563 1564 valstr = params.get(CameraParameters::KEY_VIDEO_SNAPSHOT_SUPPORTED); 1565 if (NULL != valstr) { 1566 strcpy(videosnapshotstr, valstr); 1567 } else { 1568 printf("Video Snapshot is not supported\n"); 1569 } 1570 1571 if (params.get(KEY_SUPPORTED_MANUAL_CONVERGENCE_MIN) != NULL) { 1572 manualConvMin = params.getInt(KEY_SUPPORTED_MANUAL_CONVERGENCE_MIN); 1573 } else { 1574 printf("no supported parameteters for manual convergence min\n\t"); 1575 } 1576 1577 if (params.get(KEY_SUPPORTED_MANUAL_CONVERGENCE_MAX) != NULL) { 1578 manualConvMax = params.getInt(KEY_SUPPORTED_MANUAL_CONVERGENCE_MAX); 1579 } else { 1580 printf("no supported parameteters for manual convergence max\n\t"); 1581 } 1582 1583 if (params.get(KEY_SUPPORTED_MANUAL_CONVERGENCE_STEP) != NULL) { 1584 manualConvStep = params.getInt(KEY_SUPPORTED_MANUAL_CONVERGENCE_STEP); 1585 } else { 1586 printf("no supported parameteters for manual convergence step\n\t"); 1587 } 1588 1589 if (params.get(KEY_SUPPORTED_MANUAL_EXPOSURE_MIN) != NULL) { 1590 manualExpMin = params.getInt(KEY_SUPPORTED_MANUAL_EXPOSURE_MIN); 1591 } else { 1592 printf("no supported parameteters for manual exposure min\n\t"); 1593 } 1594 1595 if (params.get(KEY_SUPPORTED_MANUAL_EXPOSURE_MAX) != NULL) { 1596 manualExpMax = params.getInt(KEY_SUPPORTED_MANUAL_EXPOSURE_MAX); 1597 } else { 1598 printf("no supported parameteters for manual exposure max\n\t"); 1599 } 1600 1601 if (params.get(KEY_SUPPORTED_MANUAL_EXPOSURE_STEP) != NULL) { 1602 manualExpStep = params.getInt(KEY_SUPPORTED_MANUAL_EXPOSURE_STEP); 1603 } else { 1604 printf("no supported parameteters for manual exposure step\n\t"); 1605 } 1606 1607 if (params.get(KEY_SUPPORTED_MANUAL_GAIN_ISO_MIN) != NULL) { 1608 manualGainMin = params.getInt(KEY_SUPPORTED_MANUAL_GAIN_ISO_MIN); 1609 } else { 1610 printf("no supported parameteters for manual gain min\n\t"); 1611 } 1612 1613 if (params.get(KEY_SUPPORTED_MANUAL_GAIN_ISO_MAX) != NULL) { 1614 manualGainMax = params.getInt(KEY_SUPPORTED_MANUAL_GAIN_ISO_MAX); 1615 } else { 1616 printf("no supported parameteters for manual gain max\n\t"); 1617 } 1618 1619 if (params.get(KEY_SUPPORTED_MANUAL_GAIN_ISO_STEP) != NULL) { 1620 manualGainStep = params.getInt(KEY_SUPPORTED_MANUAL_GAIN_ISO_STEP); 1621 } else { 1622 printf("no supported parameteters for manual gain step\n\t"); 1623 } 1624 1625 return 0; 1626 } 1627 1628 void getSizeParametersFromCapabilities() { 1629 if(!stereoMode) { 1630 if (params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES) != NULL) { 1631 strcpy(captureSizeStr, params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES)); 1632 } else { 1633 printf("Picture sizes are not supported\n"); 1634 } 1635 1636 if (params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES) != NULL) { 1637 strcpy(previewSizeStr, params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 1638 strcpy(VcaptureSizeStr, params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 1639 } else { 1640 printf("Preview sizes are not supported\n"); 1641 } 1642 } else { //stereo 1643 if(strcmp(stereoLayout[stereoLayoutIDX],"tb-full") == 0) 1644 { 1645 if (params.get(KEY_SUPPORTED_PREVIEW_TOPBOTTOM_SIZES) != NULL) { 1646 strcpy(previewSizeStr, params.get(KEY_SUPPORTED_PREVIEW_TOPBOTTOM_SIZES)); 1647 strcpy(VcaptureSizeStr, params.get(KEY_SUPPORTED_PREVIEW_TOPBOTTOM_SIZES)); 1648 } else { 1649 printf("Preview sizes are not supported\n"); 1650 } 1651 } 1652 else if(strcmp(stereoLayout[stereoLayoutIDX],"ss-full") == 0) 1653 { 1654 if (params.get(KEY_SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES) != NULL) { 1655 strcpy(previewSizeStr, params.get(KEY_SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES)); 1656 strcpy(VcaptureSizeStr, params.get(KEY_SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES)); 1657 } else { 1658 printf("Preview sizes are not supported\n"); 1659 } 1660 } 1661 else if(strcmp(stereoLayout[stereoLayoutIDX],"tb-subsampled") == 0) 1662 { 1663 if (params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES) != NULL) { 1664 strcpy(previewSizeStr, params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 1665 strcpy(VcaptureSizeStr, params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 1666 } else { 1667 printf("Preview sizes are not supported\n"); 1668 } 1669 } 1670 else if(strcmp(stereoLayout[stereoLayoutIDX],"ss-subsampled") == 0) 1671 { 1672 if (params.get(KEY_SUPPORTED_PREVIEW_SUBSAMPLED_SIZES) != NULL) { 1673 strcpy(previewSizeStr, params.get(KEY_SUPPORTED_PREVIEW_SUBSAMPLED_SIZES)); 1674 strcpy(VcaptureSizeStr, params.get(KEY_SUPPORTED_PREVIEW_SUBSAMPLED_SIZES)); 1675 } else { 1676 printf("Preview sizes are not supported\n"); 1677 } 1678 } 1679 else 1680 { 1681 printf("Preview sizes are not supported\n"); 1682 } 1683 if(strcmp(stereoCapLayout[stereoCapLayoutIDX],"tb-full") == 0) 1684 { 1685 if (params.get(KEY_SUPPORTED_PICTURE_TOPBOTTOM_SIZES) != NULL) { 1686 strcpy(captureSizeStr, params.get(KEY_SUPPORTED_PICTURE_TOPBOTTOM_SIZES)); 1687 } else { 1688 printf("Picture sizes are not supported\n"); 1689 } 1690 } 1691 else if(strcmp(stereoCapLayout[stereoCapLayoutIDX],"ss-full") == 0) 1692 { 1693 if (params.get(KEY_SUPPORTED_PICTURE_SIDEBYSIDE_SIZES) != NULL) { 1694 strcpy(captureSizeStr, params.get(KEY_SUPPORTED_PICTURE_SIDEBYSIDE_SIZES)); 1695 } else { 1696 printf("Picture sizes are not supported\n"); 1697 } 1698 } 1699 else 1700 { 1701 printf("Picture sizes are not supported\n"); 1702 } 1703 1704 } 1705 getSupportedParametersCaptureSize(captureSizeStr, &numcaptureSize, captureSize, length_capture_Size); 1706 getSupportedParametersPreviewSize(previewSizeStr, &numpreviewSize, previewSize, length_previewSize); 1707 getSupportedParametersVideoCaptureSize(VcaptureSizeStr, &numVcaptureSize, VcaptureSize, lenght_Vcapture_size); 1708 } 1709 1710 int getDefaultParameter(const char* val, int numOptions, char **array) { 1711 int cnt = 0; 1712 1713 if ((NULL == val) || (NULL == array)) { 1714 printf("Some default parameters are not valid"); 1715 return 0; 1716 } 1717 1718 for(cnt=0;cnt<numOptions;cnt++) { 1719 if (NULL == array[cnt]) { 1720 printf("Some parameter arrays are not valid"); 1721 continue; 1722 } 1723 if (strcmp(val, array[cnt]) ==0 ) { 1724 return cnt; 1725 } 1726 } 1727 return 0; 1728 } 1729 1730 int getDefaultParameterResol(const char* val, int numOptions, param_Array **array) { 1731 int cnt = 0; 1732 1733 for(cnt=0;cnt<numOptions;cnt++) { 1734 if (strcmp(val, array[cnt]->name) ==0 ) { 1735 return cnt; 1736 } 1737 } 1738 return 0; 1739 } 1740 1741 int getSupportedParameters(char* parameters, int *optionsCount, char ***elem) { 1742 str = new char [400]; 1743 param = new char [400]; 1744 int cnt = 0; 1745 1746 strcpy(str, parameters); 1747 param = strtok(str, ","); 1748 *elem = new char*[30]; 1749 1750 while (param != NULL) { 1751 (*elem)[cnt] = new char[strlen(param) + 1]; 1752 strcpy((*elem)[cnt], param); 1753 param = strtok (NULL, ","); 1754 cnt++; 1755 } 1756 *optionsCount = cnt; 1757 return 0; 1758 } 1759 1760 int getSupportedParametersfps(char* parameters, int *optionsCount) { 1761 str = new char [400]; 1762 param = new char [400]; 1763 int cnt = 0; 1764 constCnt = 0; 1765 rangeCnt = 0; 1766 strcpy(str, parameters); 1767 fps_const_str = new char*[32]; 1768 fps_range_str = new char*[32]; 1769 rangeDescription = new char*[32]; 1770 fpsArray = new fps_Array[50]; 1771 param = strtok(str, "(,)"); 1772 1773 while (param != NULL) { 1774 fps_const_str[constCnt] = new char; 1775 fps_range_str[rangeCnt] = new char; 1776 rangeDescription[rangeCnt] = new char; 1777 fpsArray[cnt].rangeMin = atoi(param); 1778 param = strtok (NULL, "(,)"); 1779 fpsArray[cnt].rangeMax = atoi(param); 1780 param = strtok (NULL, "(,)"); 1781 if (fpsArray[cnt].rangeMin == fpsArray[cnt].rangeMax) { 1782 sprintf(fps_const_str[constCnt], "%d,%d", fpsArray[cnt].rangeMin, fpsArray[cnt].rangeMax); 1783 constFramerate[constCnt] = fpsArray[cnt].rangeMin/1000; 1784 sprintf(fps_range_str[rangeCnt], "%d,%d", fpsArray[cnt].rangeMin, fpsArray[cnt].rangeMax); 1785 sprintf(rangeDescription[rangeCnt], "[%d:%d]", fpsArray[cnt].rangeMin/1000, fpsArray[cnt].rangeMax/1000); 1786 constCnt ++; 1787 rangeCnt ++; 1788 1789 } else { 1790 sprintf(fps_range_str[rangeCnt], "%d,%d", fpsArray[cnt].rangeMin, fpsArray[cnt].rangeMax); 1791 sprintf(rangeDescription[rangeCnt], "[%d:%d]", fpsArray[cnt].rangeMin/1000, fpsArray[cnt].rangeMax/1000); 1792 rangeCnt ++; 1793 } 1794 1795 cnt++; 1796 } 1797 *optionsCount = cnt; 1798 return 0; 1799 } 1800 1801 1802 int getSupportedParametersCaptureSize(char* parameters, int *optionsCount, param_Array array[], int arraySize) { 1803 str = new char [400]; 1804 param = new char [400]; 1805 int cnt = 0; 1806 strcpy(str, parameters); 1807 param = strtok(str, ",x"); 1808 capture_Array = new param_Array*[50]; 1809 while (param != NULL) { 1810 1811 capture_Array[cnt] = new param_Array; 1812 capture_Array[cnt]->width = atoi(param); 1813 param = strtok (NULL, ",x"); 1814 capture_Array[cnt]->height = atoi(param); 1815 param = strtok (NULL, ",x"); 1816 1817 int x = getSupportedParametersNames(capture_Array[cnt]->width, 1818 capture_Array[cnt]->height, array, arraySize); 1819 1820 if (x > -1) { 1821 strcpy(capture_Array[cnt]->name, array[x].name); 1822 } else { 1823 strcpy(capture_Array[cnt]->name, "Needs to be added/Not supported"); 1824 } 1825 1826 cnt++; 1827 } 1828 1829 *optionsCount = cnt; 1830 return 0; 1831 } 1832 1833 int getSupportedParametersVideoCaptureSize(char* parameters, int *optionsCount, param_Array array[], int arraySize) { 1834 str = new char [800]; 1835 param = new char [800]; 1836 int cnt = 0; 1837 strcpy(str, parameters); 1838 param = strtok(str, ",x"); 1839 Vcapture_Array = new param_Array*[100]; 1840 while (param != NULL) { 1841 1842 Vcapture_Array[cnt] = new param_Array; 1843 Vcapture_Array[cnt]->width = atoi(param); 1844 param = strtok (NULL, ",x"); 1845 Vcapture_Array[cnt]->height = atoi(param); 1846 param = strtok (NULL, ",x"); 1847 1848 int x = getSupportedParametersNames(Vcapture_Array[cnt]->width, 1849 Vcapture_Array[cnt]->height, array, arraySize); 1850 1851 if (x > -1) { 1852 strcpy(Vcapture_Array[cnt]->name, array[x].name); 1853 } else { 1854 strcpy(Vcapture_Array[cnt]->name, "Needs to be added/Not supported"); 1855 } 1856 1857 cnt++; 1858 } 1859 1860 *optionsCount = cnt; 1861 return 0; 1862 } 1863 1864 int getSupportedParametersPreviewSize(char* parameters, int *optionsCount, param_Array array[], int arraySize) { 1865 str = new char [500]; 1866 param = new char [500]; 1867 int cnt = 0; 1868 strcpy(str, parameters); 1869 param = strtok(str, ",x"); 1870 preview_Array = new param_Array*[60]; 1871 while (param != NULL) { 1872 preview_Array[cnt] = new param_Array; 1873 preview_Array[cnt]->width = atoi(param); 1874 param = strtok (NULL, ",x"); 1875 preview_Array[cnt]->height = atoi(param); 1876 param = strtok (NULL, ",x"); 1877 1878 int x = getSupportedParametersNames(preview_Array[cnt]->width, 1879 preview_Array[cnt]->height, array, arraySize); 1880 if (x > -1) { 1881 strcpy(preview_Array[cnt]->name, array[x].name); 1882 } else { 1883 strcpy(preview_Array[cnt]->name, "Needs to be added/Not supported"); 1884 } 1885 1886 cnt++; 1887 } 1888 1889 *optionsCount = cnt; 1890 return 0; 1891 } 1892 1893 int getSupportedParametersThumbnailSize(char* parameters, int *optionsCount, param_Array array[], int arraySize) { 1894 str = new char [500]; 1895 param = new char [500]; 1896 int cnt = 0; 1897 strcpy(str, parameters); 1898 param = strtok(str, ",x"); 1899 thumbnail_Array = new param_Array*[60]; 1900 while (param != NULL) { 1901 thumbnail_Array[cnt] = new param_Array; 1902 thumbnail_Array[cnt]->width = atoi(param); 1903 param = strtok (NULL, ",x"); 1904 thumbnail_Array[cnt]->height = atoi(param); 1905 param = strtok (NULL, ",x"); 1906 1907 int x = getSupportedParametersNames(thumbnail_Array[cnt]->width, 1908 thumbnail_Array[cnt]->height, array, arraySize); 1909 if (x > -1) { 1910 strcpy(thumbnail_Array[cnt]->name, array[x].name); 1911 } else { 1912 strcpy(thumbnail_Array[cnt]->name, "Needs to be added/Not supported"); 1913 } 1914 1915 cnt++; 1916 } 1917 1918 *optionsCount = cnt; 1919 return 0; 1920 } 1921 1922 int getSupportedParametersNames(int width, int height, param_Array array[], int arraySize) { 1923 for (int i = 0; i<arraySize; i++) { 1924 1925 if ((width == array[i].width) && (height == array[i].height)) { 1926 return (i); 1927 } 1928 } 1929 return -1; 1930 } 1931 1932 int deleteAllocatedMemory() { 1933 int i; 1934 1935 for (i=0; i<numAntibanding; i++){ 1936 delete [] antiband[i]; 1937 } 1938 1939 1940 1941 1942 for (i=0; i<numEffects; i++){ 1943 delete [] effectss[i]; 1944 } 1945 1946 for (i=0; i<numExposureMode; i++){ 1947 delete [] exposureMode[i]; 1948 } 1949 1950 for (i=0; i<numawb; i++) { 1951 delete [] awb[i]; 1952 } 1953 1954 for (i=0; i<numscene; i++){ 1955 delete [] scene[i]; 1956 } 1957 1958 for (i=0; i<numfocus; i++){ 1959 delete [] focus[i]; 1960 } 1961 1962 for (i=0; i<numflash; i++){ 1963 delete [] flash[i]; 1964 } 1965 1966 for (i=0; i<numpreviewSize; i++){ 1967 delete [] preview_Array[i]; 1968 } 1969 1970 for (i=0; i<numcaptureSize; i++){ 1971 delete [] capture_Array[i]; 1972 } 1973 1974 for (i=0; i<numVcaptureSize; i++){ 1975 delete [] Vcapture_Array[i]; 1976 } 1977 1978 for (i=0; i<numthumbnailSize; i++){ 1979 delete [] thumbnail_Array[i]; 1980 } 1981 1982 for (i=0; i<constCnt; i++){ 1983 delete [] fps_const_str[i]; 1984 } 1985 1986 for (i=0; i<rangeCnt; i++){ 1987 delete [] fps_range_str[i]; 1988 } 1989 1990 for (i=0; i<rangeCnt; i++){ 1991 delete [] rangeDescription[i]; 1992 } 1993 1994 for (i=0; i<numpreviewFormat; i++){ 1995 delete [] previewFormatArray[i]; 1996 } 1997 1998 for (i=0; i<numpictureFormat; i++){ 1999 delete [] pictureFormatArray[i]; 2000 } 2001 2002 for (i=0; i<nummodevalues; i++){ 2003 delete [] modevalues[i]; 2004 } 2005 2006 if (numLay) { 2007 for (i = 0; i < numLay; i++) { 2008 delete [] stereoLayout[i]; 2009 } 2010 numLay = 0; 2011 } 2012 2013 if (numCLay) { 2014 for (i = 0; i < numCLay; i++) { 2015 delete [] stereoCapLayout[i]; 2016 } 2017 numCLay = 0; 2018 } 2019 2020 delete [] antibandStr; 2021 delete [] effectssStr; 2022 delete [] exposureModeStr; 2023 delete [] awbStr; 2024 delete [] sceneStr; 2025 delete [] focusStr; 2026 delete [] flashStr; 2027 delete [] previewSizeStr; 2028 delete [] captureSizeStr; 2029 delete [] VcaptureSizeStr; 2030 delete [] thumbnailSizeStr; 2031 delete [] fpsstr; 2032 delete [] previewFormatStr; 2033 delete [] pictureFormatStr; 2034 delete [] fpsArray; 2035 delete [] vstabstr; 2036 delete [] vnfstr; 2037 delete [] isoModeStr; 2038 delete [] AutoExposureLockstr; 2039 delete [] AutoWhiteBalanceLockstr; 2040 delete [] zoomstr; 2041 delete [] smoothzoomstr; 2042 delete [] modevaluesstr; 2043 delete [] videosnapshotstr; 2044 delete [] autoconvergencestr; 2045 delete [] layoutstr; 2046 delete [] capturelayoutstr; 2047 2048 // Release buffer sources if any 2049 if (bufferSourceOutputThread.get()) { 2050 bufferSourceOutputThread->requestExit(); 2051 bufferSourceOutputThread.clear(); 2052 } 2053 if ( bufferSourceInput.get() ) { 2054 bufferSourceInput.clear(); 2055 } 2056 2057 return 0; 2058 } 2059 2060 int trySetVideoStabilization(bool toggle) { 2061 if (strcmp(vstabstr, "true") == 0) { 2062 params.set(params.KEY_VIDEO_STABILIZATION, toggle ? params.TRUE : params.FALSE); 2063 return 0; 2064 } 2065 return 0; 2066 } 2067 2068 int trySetVideoNoiseFilter(bool toggle) { 2069 if (strcmp(vnfstr, "true") == 0) { 2070 params.set("vnf", toggle ? params.TRUE : params.FALSE); 2071 return 0; 2072 } 2073 return 0; 2074 } 2075 2076 int trySetAutoExposureLock(bool toggle) { 2077 if (strcmp(AutoExposureLockstr, "true") == 0) { 2078 params.set(KEY_AUTO_EXPOSURE_LOCK, toggle ? params.TRUE : params.FALSE); 2079 return 0; 2080 } 2081 return 0; 2082 } 2083 2084 int trySetAutoWhiteBalanceLock(bool toggle) { 2085 if (strcmp(AutoWhiteBalanceLockstr, "true") == 0) { 2086 params.set(KEY_AUTO_WHITEBALANCE_LOCK, toggle ? params.TRUE : params.FALSE); 2087 return 0; 2088 } 2089 return 0; 2090 } 2091 2092 bool isRawPixelFormat (const char *format) { 2093 bool ret = false; 2094 if ((0 == strcmp (format, CameraParameters::PIXEL_FORMAT_YUV422I)) || 2095 (0 == strcmp (format, CameraParameters::PIXEL_FORMAT_YUV420SP)) || 2096 (0 == strcmp (format, CameraParameters::PIXEL_FORMAT_RGB565)) || 2097 (0 == strcmp (format, CameraParameters::PIXEL_FORMAT_BAYER_RGGB))) { 2098 ret = true; 2099 } 2100 return ret; 2101 } 2102 2103 void stopPreview() { 2104 if ( hardwareActive ) { 2105 camera->stopPreview(); 2106 2107 destroyPreviewSurface(); 2108 2109 previewRunning = false; 2110 reSizePreview = true; 2111 } 2112 } 2113 2114 void initDefaults() { 2115 2116 struct CameraInfo cameraInfo; 2117 2118 camera->getCameraInfo(camera_index, &cameraInfo); 2119 if (cameraInfo.facing == CAMERA_FACING_FRONT) { 2120 rotation = cameraInfo.orientation; 2121 } else { // back-facing 2122 rotation = cameraInfo.orientation; 2123 } 2124 2125 antibanding_mode = getDefaultParameter("off", numAntibanding, antiband); 2126 focus_mode = getDefaultParameter("auto", numfocus, focus); 2127 fpsRangeIdx = getDefaultParameter("5000,30000", rangeCnt, fps_range_str); 2128 afTimeoutIdx = 0; 2129 previewSizeIDX = getDefaultParameterResol("VGA", numpreviewSize, preview_Array); 2130 captureSizeIDX = getDefaultParameterResol("12MP", numcaptureSize, capture_Array); 2131 frameRateIDX = getDefaultParameter("30000,30000", constCnt, fps_const_str); 2132 VcaptureSizeIDX = getDefaultParameterResol("HD", numVcaptureSize, Vcapture_Array); 2133 VbitRateIDX = 0; 2134 thumbSizeIDX = getDefaultParameterResol("VGA", numthumbnailSize, thumbnail_Array); 2135 compensation = 0.0; 2136 awb_mode = getDefaultParameter("auto", numawb, awb); 2137 effects_mode = getDefaultParameter("none", numEffects, effectss); 2138 scene_mode = getDefaultParameter("auto", numscene, scene); 2139 caf_mode = 0; 2140 2141 shotConfigFlush = false; 2142 streamCapture = false; 2143 vstabtoggle = false; 2144 vnftoggle = false; 2145 AutoExposureLocktoggle = false; 2146 AutoWhiteBalanceLocktoggle = false; 2147 faceDetectToggle = false; 2148 metaDataToggle = false; 2149 expBracketIdx = BRACKETING_IDX_DEFAULT; 2150 flashIdx = getDefaultParameter("off", numflash, flash); 2151 previewRotation = 0; 2152 zoomIDX = 0; 2153 videoCodecIDX = 0; 2154 gbceIDX = 0; 2155 glbceIDX = 0; 2156 contrast = 100; 2157 #ifdef TARGET_OMAP4 2158 ///Temporary fix until OMAP3 and OMAP4 3A values are synced 2159 brightness = 50; 2160 sharpness = 100; 2161 #else 2162 brightness = 100; 2163 sharpness = 0; 2164 #endif 2165 saturation = 100; 2166 iso_mode = getDefaultParameter("auto", numisoMode, isoMode); 2167 capture_mode = getDefaultParameter("high-quality", nummodevalues, modevalues); 2168 exposure_mode = getDefaultParameter("auto", numExposureMode, exposureMode); 2169 ippIDX = 0; 2170 ippIDX_old = ippIDX; 2171 jpegQuality = 85; 2172 bufferStarvationTest = 0; 2173 meter_mode = 0; 2174 previewFormat = getDefaultParameter("yuv420sp", numpreviewFormat, previewFormatArray); 2175 pictureFormat = getDefaultParameter("jpeg", numpictureFormat, pictureFormatArray); 2176 stereoCapLayoutIDX = 0; 2177 stereoLayoutIDX = 1; 2178 manualConv = 0; 2179 manualExp = manualExpMin; 2180 manualGain = manualGainMin; 2181 2182 algoFixedGammaIDX = 1; 2183 algoNSF1IDX = 1; 2184 algoNSF2IDX = 1; 2185 algoSharpeningIDX = 1; 2186 algoThreeLinColorMapIDX = 1; 2187 algoGICIDX = 1; 2188 2189 params.set(params.KEY_VIDEO_STABILIZATION, params.FALSE); 2190 params.set("vnf", params.FALSE); 2191 params.setPreviewSize(preview_Array[previewSizeIDX]->width, preview_Array[previewSizeIDX]->height); 2192 params.setPictureSize(capture_Array[captureSizeIDX]->width, capture_Array[captureSizeIDX]->height); 2193 params.set(CameraParameters::KEY_ROTATION, rotation); 2194 params.set(KEY_SENSOR_ORIENTATION, previewRotation); 2195 params.set(KEY_COMPENSATION, (int) (compensation * 10)); 2196 params.set(params.KEY_WHITE_BALANCE, awb[awb_mode]); 2197 params.set(KEY_MODE, (modevalues[capture_mode])); 2198 params.set(params.KEY_SCENE_MODE, scene[scene_mode]); 2199 params.set(KEY_CAF, caf_mode); 2200 params.set(KEY_ISO, isoMode[iso_mode]); 2201 params.set(KEY_GBCE, gbce[gbceIDX]); 2202 params.set(KEY_GLBCE, gbce[glbceIDX]); 2203 params.set(KEY_SHARPNESS, sharpness); 2204 params.set(KEY_CONTRAST, contrast); 2205 params.set(CameraParameters::KEY_ZOOM, zoom[zoomIDX].idx); 2206 params.set(KEY_EXPOSURE, exposureMode[exposure_mode]); 2207 params.set(KEY_BRIGHTNESS, brightness); 2208 params.set(KEY_SATURATION, saturation); 2209 params.set(params.KEY_EFFECT, effectss[effects_mode]); 2210 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_const_str[frameRateIDX]); 2211 params.set(params.KEY_ANTIBANDING, antiband[antibanding_mode]); 2212 params.set(params.KEY_FOCUS_MODE, focus[focus_mode]); 2213 params.set(KEY_IPP, ipp_mode[ippIDX]); 2214 params.set(CameraParameters::KEY_JPEG_QUALITY, jpegQuality); 2215 params.setPreviewFormat(previewFormatArray[previewFormat]); 2216 params.setPictureFormat(pictureFormatArray[pictureFormat]); 2217 params.set(KEY_BUFF_STARV, bufferStarvationTest); 2218 params.set(KEY_METERING_MODE, metering[meter_mode]); 2219 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, thumbnail_Array[thumbSizeIDX]->width); 2220 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, thumbnail_Array[thumbSizeIDX]->height); 2221 params.set(KEY_MANUAL_CONVERGENCE, manualConv); 2222 params.set(KEY_MANUAL_EXPOSURE, manualExp); 2223 params.set(KEY_MANUAL_GAIN_ISO, manualGain); 2224 params.set(KEY_MANUAL_EXPOSURE_RIGHT, manualExp); 2225 params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manualGain); 2226 params.set(KEY_S3D2D_PREVIEW_MODE, "off"); 2227 params.set(KEY_EXIF_MODEL, MODEL); 2228 params.set(KEY_EXIF_MAKE, MAKE); 2229 2230 setDefaultExpGainPreset(shotParams, expBracketIdx); 2231 } 2232 2233 void setDefaultExpGainPreset(ShotParameters ¶ms, int idx) { 2234 if ( ((int)ARRAY_SIZE(expBracketing) > idx) && (0 <= idx) ) { 2235 setExpGainPreset(params, expBracketing[idx].value, false, expBracketing[idx].param_type, shotConfigFlush); 2236 } else { 2237 printf("setDefaultExpGainPreset: Index (%d) is out of range 0 ~ %u\n", idx, ARRAY_SIZE(expBracketing) - 1); 2238 } 2239 } 2240 2241 void setSingleExpGainPreset(ShotParameters ¶ms, int idx, int exp, int gain) { 2242 String8 val; 2243 2244 if (PARAM_EXP_BRACKET_PARAM_PAIR == expBracketing[idx].param_type) { 2245 val.append("("); 2246 } 2247 2248 if (PARAM_EXP_BRACKET_VALUE_REL == expBracketing[idx].value_type) { 2249 val.appendFormat("%+d", exp); 2250 } else { 2251 val.appendFormat("%u", (unsigned int) exp); 2252 } 2253 2254 if (PARAM_EXP_BRACKET_PARAM_PAIR == expBracketing[idx].param_type) { 2255 if (PARAM_EXP_BRACKET_VALUE_REL == expBracketing[idx].value_type) { 2256 val.appendFormat(",%+d)", gain); 2257 } else { 2258 val.appendFormat(",%u)", (unsigned int) gain); 2259 } 2260 } 2261 2262 if (PARAM_EXP_BRACKET_APPLY_FORCED == expBracketing[idx].apply_type) { 2263 val.append("F"); 2264 } 2265 2266 setExpGainPreset(params, val, false, expBracketing[idx].param_type, false); 2267 } 2268 2269 void setExpGainPreset(ShotParameters ¶ms, const char *input, bool force, param_ExpBracketParamType_t type, bool flush) { 2270 const char *startPtr = NULL; 2271 size_t i = 0; 2272 2273 if (NULL == input) { 2274 printf("setExpGainPreset: missing input string\n"); 2275 } else if ( (force && (NULL == strpbrk(input, "()"))) || 2276 (PARAM_EXP_BRACKET_PARAM_COMP == type) ) { 2277 // parse for the number of inputs (count the number of ',' + 1) 2278 startPtr = strchr(input, ','); 2279 while (startPtr != NULL) { 2280 i++; 2281 startPtr = strchr(startPtr + 1, ','); 2282 } 2283 i++; 2284 printf("relative EV input: \"%s\"\nnumber of relative EV values: %d (%s)\n", 2285 input, i, flush ? "reset" : "append"); 2286 burst = i; 2287 burstCount = i; 2288 params.set(ShotParameters::KEY_BURST, burst); 2289 params.set(ShotParameters::KEY_EXP_COMPENSATION, input); 2290 params.remove(ShotParameters::KEY_EXP_GAIN_PAIRS); 2291 params.set(ShotParameters::KEY_FLUSH_CONFIG, 2292 flush ? ShotParameters::TRUE : ShotParameters::FALSE); 2293 } else if ( force || (PARAM_EXP_BRACKET_PARAM_PAIR == type) ) { 2294 // parse for the number of inputs (count the number of '(') 2295 startPtr = strchr(input, '('); 2296 while (startPtr != NULL) { 2297 i++; 2298 startPtr = strchr(startPtr + 1, '('); 2299 } 2300 printf("absolute exposure,gain input: \"%s\"\nNumber of brackets: %d (%s)\n", 2301 input, i, flush ? "reset" : "append"); 2302 burst = i; 2303 burstCount = i; 2304 params.set(ShotParameters::KEY_BURST, burst); 2305 params.set(ShotParameters::KEY_EXP_GAIN_PAIRS, input); 2306 params.remove(ShotParameters::KEY_EXP_COMPENSATION); 2307 params.set(ShotParameters::KEY_FLUSH_CONFIG, 2308 flush ? ShotParameters::TRUE : ShotParameters::FALSE); 2309 } else { 2310 printf("no bracketing input: \"%s\"\n", input); 2311 params.remove(ShotParameters::KEY_EXP_GAIN_PAIRS); 2312 params.remove(ShotParameters::KEY_EXP_COMPENSATION); 2313 params.remove(ShotParameters::KEY_BURST); 2314 params.remove(ShotParameters::KEY_FLUSH_CONFIG); 2315 } 2316 } 2317 2318 void calcNextSingleExpGainPreset(int idx, int &exp, int &gain) { 2319 if (PARAM_EXP_BRACKET_VALUE_ABS == expBracketing[idx].value_type) { 2320 // absolute 2321 if ( (0 == exp) && (0 == gain) ) { 2322 exp=100; 2323 gain = 150; 2324 printf("Streaming: Init default absolute exp./gain: %d,%d\n", exp, gain); 2325 } 2326 2327 exp *= 2; 2328 if (1000000 < exp) { 2329 exp = 100; 2330 gain += 50; 2331 if(400 < gain) { 2332 gain = 50; 2333 } 2334 } 2335 } else { 2336 // relative 2337 exp += 50; 2338 if (200 < exp) { 2339 exp = -200; 2340 gain += 50; 2341 if(200 < gain) { 2342 gain = -200; 2343 } 2344 } 2345 } 2346 } 2347 2348 void updateShotConfigFlushParam() { 2349 // Will update flush shot config parameter if already present 2350 // Otherwise, keep empty (will be set later in setExpGainPreset()) 2351 if (NULL != shotParams.get(ShotParameters::KEY_FLUSH_CONFIG)) { 2352 shotParams.set(ShotParameters::KEY_FLUSH_CONFIG, 2353 shotConfigFlush ? ShotParameters::TRUE : ShotParameters::FALSE); 2354 } 2355 } 2356 2357 int menu_gps() { 2358 char ch; 2359 char coord_str[100]; 2360 2361 if (print_menu) { 2362 printf("\n\n== GPS MENU ============================\n\n"); 2363 printf(" e. Latitude: %.7lf\n", latitude); 2364 printf(" d. Longitude: %.7lf\n", longitude); 2365 printf(" c. Altitude: %.7lf\n", altitude); 2366 printf("\n"); 2367 printf(" q. Return to main menu\n"); 2368 printf("\n"); 2369 printf(" Choice: "); 2370 } 2371 2372 ch = getchar(); 2373 printf("%c", ch); 2374 2375 print_menu = 1; 2376 2377 switch (ch) { 2378 2379 case 'e': 2380 latitude += degree_by_step; 2381 2382 if (latitude > 90.0) { 2383 latitude -= 180.0; 2384 } 2385 2386 snprintf(coord_str, 7, "%.7lf", latitude); 2387 params.set(params.KEY_GPS_LATITUDE, coord_str); 2388 2389 if ( hardwareActive ) 2390 camera->setParameters(params.flatten()); 2391 2392 break; 2393 2394 case 'd': 2395 longitude += degree_by_step; 2396 2397 if (longitude > 180.0) { 2398 longitude -= 360.0; 2399 } 2400 2401 snprintf(coord_str, 7, "%.7lf", longitude); 2402 params.set(params.KEY_GPS_LONGITUDE, coord_str); 2403 2404 if ( hardwareActive ) 2405 camera->setParameters(params.flatten()); 2406 2407 break; 2408 2409 case 'c': 2410 altitude += 12345.67890123456789; 2411 2412 if (altitude > 100000.0) { 2413 altitude -= 200000.0; 2414 } 2415 2416 snprintf(coord_str, 100, "%.20lf", altitude); 2417 params.set(params.KEY_GPS_ALTITUDE, coord_str); 2418 2419 if ( hardwareActive ) 2420 camera->setParameters(params.flatten()); 2421 2422 break; 2423 2424 case 'q': 2425 return -1; 2426 2427 default: 2428 print_menu = 0; 2429 break; 2430 } 2431 2432 return 0; 2433 } 2434 2435 int menu_algo() { 2436 char ch; 2437 2438 if (print_menu) { 2439 printf("\n\n== ALGO ENABLE/DISABLE MENU ============\n\n"); 2440 printf(" a. Fixed Gamma: %s\n", algoFixedGamma[algoFixedGammaIDX]); 2441 printf(" s. NSF1: %s\n", algoNSF1[algoNSF1IDX]); 2442 printf(" d. NSF2: %s\n", algoNSF2[algoNSF2IDX]); 2443 printf(" f. Sharpening: %s\n", algoSharpening[algoSharpeningIDX]); 2444 printf(" g. Color Conversion: %s\n", algoThreeLinColorMap[algoThreeLinColorMapIDX]); 2445 printf(" h. Green Inballance Correction: %s\n", algoGIC[algoGICIDX]); 2446 printf("\n"); 2447 printf(" q. Return to main menu\n"); 2448 printf("\n"); 2449 printf(" Choice: "); 2450 } 2451 2452 ch = getchar(); 2453 printf("%c", ch); 2454 2455 print_menu = 1; 2456 2457 switch (ch) { 2458 2459 case 'a': 2460 case 'A': 2461 algoFixedGammaIDX++; 2462 algoFixedGammaIDX %= ARRAY_SIZE(algoFixedGamma); 2463 params.set(KEY_ALGO_FIXED_GAMMA, (algoFixedGamma[algoFixedGammaIDX])); 2464 2465 if ( hardwareActive ) 2466 camera->setParameters(params.flatten()); 2467 2468 break; 2469 2470 case 's': 2471 case 'S': 2472 algoNSF1IDX++; 2473 algoNSF1IDX %= ARRAY_SIZE(algoNSF1); 2474 params.set(KEY_ALGO_NSF1, (algoNSF1[algoNSF1IDX])); 2475 2476 if ( hardwareActive ) 2477 camera->setParameters(params.flatten()); 2478 2479 break; 2480 2481 case 'd': 2482 case 'D': 2483 algoNSF2IDX++; 2484 algoNSF2IDX %= ARRAY_SIZE(algoNSF2); 2485 params.set(KEY_ALGO_NSF2, (algoNSF2[algoNSF2IDX])); 2486 2487 if ( hardwareActive ) 2488 camera->setParameters(params.flatten()); 2489 2490 break; 2491 2492 case 'f': 2493 case 'F': 2494 algoSharpeningIDX++; 2495 algoSharpeningIDX %= ARRAY_SIZE(algoSharpening); 2496 params.set(KEY_ALGO_SHARPENING, (algoSharpening[algoSharpeningIDX])); 2497 2498 if ( hardwareActive ) 2499 camera->setParameters(params.flatten()); 2500 2501 break; 2502 2503 case 'g': 2504 case 'G': 2505 algoThreeLinColorMapIDX++; 2506 algoThreeLinColorMapIDX %= ARRAY_SIZE(algoThreeLinColorMap); 2507 params.set(KEY_ALGO_THREELINCOLORMAP, (algoThreeLinColorMap[algoThreeLinColorMapIDX])); 2508 2509 if ( hardwareActive ) 2510 camera->setParameters(params.flatten()); 2511 2512 break; 2513 2514 case 'h': 2515 case 'H': 2516 algoGICIDX++; 2517 algoGICIDX %= ARRAY_SIZE(algoGIC); 2518 params.set(KEY_ALGO_GIC, (algoGIC[algoGICIDX])); 2519 2520 if ( hardwareActive ) 2521 camera->setParameters(params.flatten()); 2522 2523 break; 2524 2525 case 'Q': 2526 case 'q': 2527 return -1; 2528 2529 default: 2530 print_menu = 0; 2531 break; 2532 } 2533 2534 return 0; 2535 } 2536 2537 int functional_menu() { 2538 char ch; 2539 char area1[MAX_LINES][MAX_SYMBOLS+1]; 2540 char area2[MAX_LINES][MAX_SYMBOLS+1]; 2541 int j = 0; 2542 int k = 0; 2543 const char *valstr = NULL; 2544 struct CameraInfo cameraInfo; 2545 bool queueEmpty = true; 2546 2547 memset(area1, '\0', MAX_LINES*(MAX_SYMBOLS+1)); 2548 memset(area2, '\0', MAX_LINES*(MAX_SYMBOLS+1)); 2549 2550 if (print_menu) { 2551 2552 printf("\n========================================= FUNCTIONAL TEST MENU =========================================\n"); 2553 2554 snprintf(area1[j++], MAX_SYMBOLS, " START / STOP / GENERAL SERVICES"); 2555 snprintf(area1[j++], MAX_SYMBOLS, " -----------------------------"); 2556 snprintf(area1[j++], MAX_SYMBOLS, "A Select Camera %s", cameras[camera_index]); 2557 snprintf(area1[j++], MAX_SYMBOLS, "[. Resume Preview after capture"); 2558 snprintf(area1[j++], MAX_SYMBOLS, "0. Reset to defaults"); 2559 snprintf(area1[j++], MAX_SYMBOLS, "q. Quit"); 2560 snprintf(area1[j++], MAX_SYMBOLS, "@. Disconnect and Reconnect to CameraService"); 2561 snprintf(area1[j++], MAX_SYMBOLS, "/. Enable/Disable showfps: %s", ((showfps)? "Enabled":"Disabled")); 2562 snprintf(area1[j++], MAX_SYMBOLS, "a. GEO tagging settings menu"); 2563 snprintf(area1[j++], MAX_SYMBOLS, "E. Camera Capability Dump"); 2564 2565 snprintf(area1[j++], MAX_SYMBOLS, " PREVIEW SUB MENU"); 2566 snprintf(area1[j++], MAX_SYMBOLS, " -----------------------------"); 2567 snprintf(area1[j++], MAX_SYMBOLS, "1. Start Preview"); 2568 snprintf(area1[j++], MAX_SYMBOLS, "2. Stop Preview"); 2569 snprintf(area1[j++], MAX_SYMBOLS, "~. Preview format %s", previewFormatArray[previewFormat]); 2570 #if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 2571 snprintf(area1[j++], MAX_SYMBOLS, "4. Preview size: %4d x %4d - %s",preview_Array[previewSizeIDX]->width, preview_Array[previewSizeIDX]->height, preview_Array[previewSizeIDX]->name); 2572 #else 2573 snprintf(area1[j++], MAX_SYMBOLS, "4. Preview size: %4d x %4d - %s",preview_Array[previewSizeIDX]->width, stereoMode ? preview_Array[previewSizeIDX]->height*2 : preview_Array[previewSizeIDX]->height, preview_Array[previewSizeIDX]->name); 2574 #endif 2575 snprintf(area1[j++], MAX_SYMBOLS, "R. Preview framerate range: %s", rangeDescription[fpsRangeIdx]); 2576 snprintf(area1[j++], MAX_SYMBOLS, "&. Dump a preview frame"); 2577 if (stereoMode) { 2578 snprintf(area1[j++], MAX_SYMBOLS, "_. Auto Convergence mode: %s", autoconvergencemode[AutoConvergenceModeIDX]); 2579 snprintf(area1[j++], MAX_SYMBOLS, "^. Manual Convergence Value: %d\n", manualConv); 2580 snprintf(area1[j++], MAX_SYMBOLS, "L. Stereo Preview Layout: %s\n", stereoLayout[stereoLayoutIDX]); 2581 snprintf(area1[j++], MAX_SYMBOLS, ". Stereo Capture Layout: %s\n", stereoCapLayout[stereoCapLayoutIDX]); 2582 } 2583 snprintf(area1[j++], MAX_SYMBOLS, "{. 2D Preview in 3D Stereo Mode: %s", params.get(KEY_S3D2D_PREVIEW_MODE)); 2584 2585 snprintf(area1[j++], MAX_SYMBOLS, " IMAGE CAPTURE SUB MENU"); 2586 snprintf(area1[j++], MAX_SYMBOLS, " -----------------------------"); 2587 snprintf(area1[j++], MAX_SYMBOLS, "p. Take picture/Full Press"); 2588 snprintf(area1[j++], MAX_SYMBOLS, "n. Flush shot config queue: %s", shotConfigFlush ? "On" : "Off"); 2589 snprintf(area1[j++], MAX_SYMBOLS, "H. Exposure Bracketing: %s", expBracketing[expBracketIdx].desc); 2590 snprintf(area1[j++], MAX_SYMBOLS, "U. Temporal Bracketing: %s", tempBracketing[tempBracketIdx]); 2591 snprintf(area1[j++], MAX_SYMBOLS, "W. Temporal Bracketing Range: [-%d;+%d]", tempBracketRange, tempBracketRange); 2592 snprintf(area1[j++], MAX_SYMBOLS, "$. Picture Format: %s", pictureFormatArray[pictureFormat]); 2593 snprintf(area1[j++], MAX_SYMBOLS, "3. Picture Rotation: %3d degree", rotation ); 2594 snprintf(area1[j++], MAX_SYMBOLS, "V. Preview Rotation: %3d degree", previewRotation ); 2595 snprintf(area1[j++], MAX_SYMBOLS, "5. Picture size: %4d x %4d - %s",capture_Array[captureSizeIDX]->width, capture_Array[captureSizeIDX]->height, capture_Array[captureSizeIDX]->name); 2596 snprintf(area1[j++], MAX_SYMBOLS, "i. ISO mode: %s", isoMode[iso_mode]); 2597 snprintf(area1[j++], MAX_SYMBOLS, ", Manual gain iso value = %d\n", manualGain); 2598 snprintf(area1[j++], MAX_SYMBOLS, "u. Capture Mode: %s", modevalues[capture_mode]); 2599 snprintf(area1[j++], MAX_SYMBOLS, "k. IPP Mode: %s", ipp_mode[ippIDX]); 2600 snprintf(area1[j++], MAX_SYMBOLS, "K. GBCE: %s", gbce[gbceIDX]); 2601 snprintf(area1[j++], MAX_SYMBOLS, "O. GLBCE %s", gbce[glbceIDX]); 2602 snprintf(area1[j++], MAX_SYMBOLS, "o. Jpeg Quality: %d", jpegQuality); 2603 snprintf(area1[j++], MAX_SYMBOLS, "#. Burst Images: %3d", burst); 2604 snprintf(area1[j++], MAX_SYMBOLS, ":. Thumbnail Size: %4d x %4d - %s",thumbnail_Array[thumbSizeIDX]->width, thumbnail_Array[thumbSizeIDX]->height, thumbnail_Array[thumbSizeIDX]->name); 2605 snprintf(area1[j++], MAX_SYMBOLS, "': Thumbnail Quality %d", thumbQuality); 2606 2607 snprintf(area2[k++], MAX_SYMBOLS, " VIDEO CAPTURE SUB MENU"); 2608 snprintf(area2[k++], MAX_SYMBOLS, " -----------------------------"); 2609 snprintf(area2[k++], MAX_SYMBOLS, "6. Start Video Recording"); 2610 snprintf(area2[k++], MAX_SYMBOLS, "2. Stop Recording"); 2611 snprintf(area2[k++], MAX_SYMBOLS, "l. Video Capture resolution: %4d x %4d - %s",Vcapture_Array[VcaptureSizeIDX]->width,Vcapture_Array[VcaptureSizeIDX]->height, Vcapture_Array[VcaptureSizeIDX]->name); 2612 snprintf(area2[k++], MAX_SYMBOLS, "]. Video Bit rate : %s", VbitRate[VbitRateIDX].desc); 2613 snprintf(area2[k++], MAX_SYMBOLS, "9. Video Codec: %s", videoCodecs[videoCodecIDX].desc); 2614 snprintf(area2[k++], MAX_SYMBOLS, "D. Audio Codec: %s", audioCodecs[audioCodecIDX].desc); 2615 snprintf(area2[k++], MAX_SYMBOLS, "v. Output Format: %s", outputFormat[outputFormatIDX].desc); 2616 snprintf(area2[k++], MAX_SYMBOLS, "r. Framerate: %d", constFramerate[frameRateIDX]); 2617 snprintf(area2[k++], MAX_SYMBOLS, "*. Start Video Recording dump ( 1 raw frame )"); 2618 snprintf(area2[k++], MAX_SYMBOLS, "B VNF %s", vnftoggle? "On" : "Off"); 2619 snprintf(area2[k++], MAX_SYMBOLS, "C VSTAB %s", vstabtoggle? "On" : "Off"); 2620 2621 snprintf(area2[k++], MAX_SYMBOLS, " 3A SETTING SUB MENU"); 2622 snprintf(area2[k++], MAX_SYMBOLS, " -----------------------------"); 2623 snprintf(area2[k++], MAX_SYMBOLS, "M. Measurement Data: %s", measurement[measurementIdx]); 2624 snprintf(area2[k++], MAX_SYMBOLS, "F. Toggle face detection: %s", faceDetectToggle ? "On" : "Off"); 2625 snprintf(area2[k++], MAX_SYMBOLS, "T. Toggle metadata: %s", metaDataToggle ? "On" : "Off"); 2626 snprintf(area2[k++], MAX_SYMBOLS, "G. Touch/Focus area AF"); 2627 snprintf(area2[k++], MAX_SYMBOLS, "y. Metering area"); 2628 snprintf(area2[k++], MAX_SYMBOLS, "Y. Metering area center"); 2629 snprintf(area2[k++], MAX_SYMBOLS, "N. Metering area average"); 2630 snprintf(area2[k++], MAX_SYMBOLS, "f. Auto Focus/Half Press"); 2631 snprintf(area2[k++], MAX_SYMBOLS, "I. AF Timeout %s", afTimeout[afTimeoutIdx]); 2632 snprintf(area2[k++], MAX_SYMBOLS, "J.Flash: %s", flash[flashIdx]); 2633 snprintf(area2[k++], MAX_SYMBOLS, "7. EV offset: %4.1f", compensation); 2634 snprintf(area2[k++], MAX_SYMBOLS, "8. AWB mode: %s", awb[awb_mode]); 2635 snprintf(area2[k++], MAX_SYMBOLS, "z. Zoom %s", zoom[zoomIDX].zoom_description); 2636 snprintf(area2[k++], MAX_SYMBOLS, "Z. Smooth Zoom %s", zoom[zoomIDX].zoom_description); 2637 snprintf(area2[k++], MAX_SYMBOLS, "j. Exposure %s", exposureMode[exposure_mode]); 2638 snprintf(area2[k++], MAX_SYMBOLS, "Q. manual exposure value = %d\n", manualExp); 2639 snprintf(area2[k++], MAX_SYMBOLS, "e. Effect: %s", effectss[effects_mode]); 2640 snprintf(area2[k++], MAX_SYMBOLS, "w. Scene: %s", scene[scene_mode]); 2641 snprintf(area2[k++], MAX_SYMBOLS, "s. Saturation: %d", saturation); 2642 snprintf(area2[k++], MAX_SYMBOLS, "c. Contrast: %d", contrast); 2643 snprintf(area2[k++], MAX_SYMBOLS, "h. Sharpness: %d", sharpness); 2644 snprintf(area2[k++], MAX_SYMBOLS, "b. Brightness: %d", brightness); 2645 snprintf(area2[k++], MAX_SYMBOLS, "x. Antibanding: %s", antiband[antibanding_mode]); 2646 snprintf(area2[k++], MAX_SYMBOLS, "g. Focus mode: %s", focus[focus_mode]); 2647 snprintf(area2[k++], MAX_SYMBOLS, "m. Metering mode: %s" , metering[meter_mode]); 2648 snprintf(area2[k++], MAX_SYMBOLS, "<. Exposure Lock: %s", AutoExposureLocktoggle ? "On" : "Off"); 2649 snprintf(area2[k++], MAX_SYMBOLS, ">. WhiteBalance Lock: %s",AutoWhiteBalanceLocktoggle ? "On": "Off"); 2650 snprintf(area2[k++], MAX_SYMBOLS, "). Mechanical Misalignment Correction: %s",misalignmentCorrection[enableMisalignmentCorrectionIdx]); 2651 snprintf(area2[k++], MAX_SYMBOLS, "d. Algo enable/disable functions menu"); 2652 2653 printf("\n"); 2654 for (int i=0; (i<j || i < k) && i<MAX_LINES; i++) { 2655 printf("%-65s \t %-65s\n", area1[i], area2[i]); 2656 } 2657 printf(" Choice:"); 2658 } 2659 2660 ch = getchar(); 2661 printf("%c", ch); 2662 2663 print_menu = 1; 2664 2665 switch (ch) { 2666 2667 case '_': 2668 AutoConvergenceModeIDX++; 2669 AutoConvergenceModeIDX %= numAutoConvergence; 2670 params.set(KEY_AUTOCONVERGENCE, autoconvergencemode[AutoConvergenceModeIDX]); 2671 if ( strcmp (autoconvergencemode[AutoConvergenceModeIDX], "manual") == 0) { 2672 params.set(KEY_MANUAL_CONVERGENCE, manualConv); 2673 } else { 2674 if ( strcmp (autoconvergencemode[AutoConvergenceModeIDX], "touch") == 0) { 2675 params.set(CameraParameters::KEY_METERING_AREAS, MeteringAreas); 2676 } 2677 manualConv = 0; 2678 params.set(KEY_MANUAL_CONVERGENCE, manualConv); 2679 } 2680 camera->setParameters(params.flatten()); 2681 2682 break; 2683 case '^': 2684 if ( strcmp (autoconvergencemode[AutoConvergenceModeIDX], "manual") == 0) { 2685 manualConv += manualConvStep; 2686 if( manualConv > manualConvMax) { 2687 manualConv = manualConvMin; 2688 } 2689 params.set(KEY_MANUAL_CONVERGENCE, manualConv); 2690 camera->setParameters(params.flatten()); 2691 } 2692 break; 2693 case 'A': 2694 camera_index++; 2695 camera_index %= numCamera; 2696 firstTime = true; 2697 closeCamera(); 2698 openCamera(); 2699 initDefaults(); 2700 2701 2702 break; 2703 case '[': 2704 if ( hardwareActive ) { 2705 camera->setParameters(params.flatten()); 2706 camera->startPreview(); 2707 } 2708 break; 2709 2710 case '0': 2711 initDefaults(); 2712 camera_index = 0; 2713 break; 2714 2715 case '1': 2716 2717 if ( startPreview() < 0 ) { 2718 printf("Error while starting preview\n"); 2719 2720 return -1; 2721 } 2722 2723 break; 2724 2725 case '2': 2726 if ( recordingMode ) { 2727 stopRecording(); 2728 stopPreview(); 2729 closeRecorder(); 2730 camera->disconnect(); 2731 camera.clear(); 2732 camera = Camera::connect(camera_index); 2733 if ( NULL == camera.get() ) { 2734 sleep(1); 2735 camera = Camera::connect(camera_index); 2736 if ( NULL == camera.get() ) { 2737 return -1; 2738 } 2739 } 2740 camera->setListener(new CameraHandler()); 2741 camera->setParameters(params.flatten()); 2742 recordingMode = false; 2743 } else { 2744 stopPreview(); 2745 } 2746 2747 break; 2748 2749 case '3': 2750 rotation += 90; 2751 rotation %= 360; 2752 params.set(CameraParameters::KEY_ROTATION, rotation); 2753 if ( hardwareActive ) 2754 camera->setParameters(params.flatten()); 2755 2756 break; 2757 2758 case 'V': 2759 previewRotation += 90; 2760 previewRotation %= 360; 2761 params.set(KEY_SENSOR_ORIENTATION, previewRotation); 2762 2763 if ( hardwareActive ) 2764 camera->setParameters(params.flatten()); 2765 2766 break; 2767 2768 case '4': 2769 previewSizeIDX += 1; 2770 previewSizeIDX %= numpreviewSize; 2771 params.setPreviewSize(preview_Array[previewSizeIDX]->width, preview_Array[previewSizeIDX]->height); 2772 2773 reSizePreview = true; 2774 2775 if ( hardwareActive && previewRunning ) { 2776 camera->stopPreview(); 2777 camera->setParameters(params.flatten()); 2778 camera->startPreview(); 2779 } else if ( hardwareActive ) { 2780 camera->setParameters(params.flatten()); 2781 } 2782 2783 break; 2784 2785 case '5': 2786 captureSizeIDX += 1; 2787 captureSizeIDX %= numcaptureSize; 2788 printf("CaptureSizeIDX %d \n", captureSizeIDX); 2789 params.setPictureSize(capture_Array[captureSizeIDX]->width, capture_Array[captureSizeIDX]->height); 2790 2791 if ( hardwareActive ) 2792 camera->setParameters(params.flatten()); 2793 2794 requestBufferSourceReset(); 2795 2796 break; 2797 2798 case 'l': 2799 2800 VcaptureSizeIDX++; 2801 VcaptureSizeIDX %= numVcaptureSize; 2802 break; 2803 2804 case 'L' : 2805 stereoLayoutIDX++; 2806 stereoLayoutIDX %= numLay; 2807 2808 if (stereoMode) { 2809 firstTimeStereo = false; 2810 params.set(KEY_S3D_PRV_FRAME_LAYOUT, stereoLayout[stereoLayoutIDX]); 2811 } 2812 2813 getSizeParametersFromCapabilities(); 2814 2815 if (hardwareActive && previewRunning) { 2816 stopPreview(); 2817 camera->setParameters(params.flatten()); 2818 startPreview(); 2819 } else if (hardwareActive) { 2820 camera->setParameters(params.flatten()); 2821 } 2822 2823 break; 2824 2825 case '.' : 2826 stereoCapLayoutIDX++; 2827 stereoCapLayoutIDX %= numCLay; 2828 2829 if (stereoMode) { 2830 firstTimeStereo = false; 2831 params.set(KEY_S3D_CAP_FRAME_LAYOUT, stereoCapLayout[stereoCapLayoutIDX]); 2832 } 2833 2834 getSizeParametersFromCapabilities(); 2835 2836 if (hardwareActive && previewRunning) { 2837 stopPreview(); 2838 camera->setParameters(params.flatten()); 2839 startPreview(); 2840 } else if (hardwareActive) { 2841 camera->setParameters(params.flatten()); 2842 } 2843 2844 break; 2845 2846 case ']': 2847 VbitRateIDX++; 2848 VbitRateIDX %= ARRAY_SIZE(VbitRate); 2849 break; 2850 2851 2852 case '6': 2853 2854 if ( !recordingMode ) { 2855 2856 recordingMode = true; 2857 2858 if ( startPreview() < 0 ) { 2859 printf("Error while starting preview\n"); 2860 2861 return -1; 2862 } 2863 2864 if ( openRecorder() < 0 ) { 2865 printf("Error while openning video recorder\n"); 2866 2867 return -1; 2868 } 2869 2870 if ( configureRecorder() < 0 ) { 2871 printf("Error while configuring video recorder\n"); 2872 2873 return -1; 2874 } 2875 2876 if ( startRecording() < 0 ) { 2877 printf("Error while starting video recording\n"); 2878 2879 return -1; 2880 } 2881 } 2882 2883 break; 2884 2885 case '7': 2886 2887 if ( compensation > 2.0) { 2888 compensation = -2.0; 2889 } else { 2890 compensation += 0.1; 2891 } 2892 2893 params.set(KEY_COMPENSATION, (int) (compensation * 10)); 2894 2895 if ( hardwareActive ) 2896 camera->setParameters(params.flatten()); 2897 2898 break; 2899 2900 case '8': 2901 awb_mode++; 2902 awb_mode %= numawb; 2903 params.set(params.KEY_WHITE_BALANCE, awb[awb_mode]); 2904 2905 if ( hardwareActive ) 2906 camera->setParameters(params.flatten()); 2907 2908 break; 2909 2910 case '9': 2911 videoCodecIDX++; 2912 videoCodecIDX %= ARRAY_SIZE(videoCodecs); 2913 break; 2914 case '~': 2915 previewFormat += 1; 2916 previewFormat %= numpreviewFormat; 2917 params.setPreviewFormat(previewFormatArray[previewFormat]); 2918 2919 if ( hardwareActive ) 2920 camera->setParameters(params.flatten()); 2921 2922 break; 2923 case '$': 2924 pictureFormat += 1; 2925 pictureFormat %= numpictureFormat; 2926 printf("pictureFormat %d\n", pictureFormat); 2927 printf("numpreviewFormat %d\n", numpictureFormat); 2928 params.setPictureFormat(pictureFormatArray[pictureFormat]); 2929 2930 queueEmpty = true; 2931 if ( bufferSourceOutputThread.get() ) { 2932 if ( 0 < bufferSourceOutputThread->hasBuffer() ) { 2933 queueEmpty = false; 2934 } 2935 } 2936 if ( hardwareActive && queueEmpty ) 2937 camera->setParameters(params.flatten()); 2938 2939 break; 2940 2941 case ':': 2942 thumbSizeIDX += 1; 2943 thumbSizeIDX %= numthumbnailSize; 2944 printf("ThumbnailSizeIDX %d \n", thumbSizeIDX); 2945 2946 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, thumbnail_Array[thumbSizeIDX]->width); 2947 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT,thumbnail_Array[thumbSizeIDX]->height); 2948 2949 if ( hardwareActive ) 2950 camera->setParameters(params.flatten()); 2951 2952 break; 2953 2954 case '\'': 2955 if ( thumbQuality >= 100) { 2956 thumbQuality = 0; 2957 } else { 2958 thumbQuality += 5; 2959 } 2960 2961 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, thumbQuality); 2962 if ( hardwareActive ) 2963 camera->setParameters(params.flatten()); 2964 break; 2965 2966 case 'B' : 2967 if(strcmp(vnfstr, "true") == 0) { 2968 if(vnftoggle == false) { 2969 trySetVideoNoiseFilter(true); 2970 vnftoggle = true; 2971 } else { 2972 trySetVideoNoiseFilter(false); 2973 vnftoggle = false; 2974 } 2975 2976 }else { 2977 trySetVideoNoiseFilter(false); 2978 vnftoggle = false; 2979 printf("VNF is not supported\n"); 2980 } 2981 if ( hardwareActive ) 2982 camera->setParameters(params.flatten()); 2983 2984 break; 2985 2986 case 'C' : 2987 if(strcmp(vstabstr, "true") == 0) { 2988 if(vstabtoggle == false) { 2989 trySetVideoStabilization(true); 2990 vstabtoggle = true; 2991 } else { 2992 trySetVideoStabilization(false); 2993 vstabtoggle = false; 2994 } 2995 2996 } else { 2997 trySetVideoStabilization(false); 2998 vstabtoggle = false; 2999 printf("VSTAB is not supported\n"); 3000 } 3001 if ( hardwareActive ) 3002 camera->setParameters(params.flatten()); 3003 3004 break; 3005 3006 case 'E': 3007 if(hardwareActive) 3008 params.unflatten(camera->getParameters()); 3009 printSupportedParams(); 3010 break; 3011 3012 case '*': 3013 if ( hardwareActive ) 3014 camera->startRecording(); 3015 break; 3016 3017 case 'o': 3018 if ( jpegQuality >= 100) { 3019 jpegQuality = 0; 3020 } else { 3021 jpegQuality += 5; 3022 } 3023 3024 params.set(CameraParameters::KEY_JPEG_QUALITY, jpegQuality); 3025 if ( hardwareActive ) 3026 camera->setParameters(params.flatten()); 3027 break; 3028 3029 case 'M': 3030 measurementIdx = (measurementIdx + 1)%ARRAY_SIZE(measurement); 3031 params.set(KEY_MEASUREMENT, measurement[measurementIdx]); 3032 if ( hardwareActive ) 3033 camera->setParameters(params.flatten()); 3034 break; 3035 3036 case 'm': 3037 meter_mode = (meter_mode + 1)%ARRAY_SIZE(metering); 3038 params.set(KEY_METERING_MODE, metering[meter_mode]); 3039 if ( hardwareActive ) 3040 camera->setParameters(params.flatten()); 3041 break; 3042 3043 case 'k': 3044 ippIDX += 1; 3045 ippIDX %= ARRAY_SIZE(ipp_mode); 3046 ippIDX_old = ippIDX; 3047 3048 params.set(KEY_IPP, ipp_mode[ippIDX]); 3049 3050 if ( hardwareActive ) 3051 camera->setParameters(params.flatten()); 3052 3053 requestBufferSourceReset(); 3054 3055 break; 3056 3057 case 'K': 3058 gbceIDX+= 1; 3059 gbceIDX %= ARRAY_SIZE(gbce); 3060 params.set(KEY_GBCE, gbce[gbceIDX]); 3061 3062 if ( hardwareActive ) 3063 camera->setParameters(params.flatten()); 3064 break; 3065 3066 case 'O': 3067 glbceIDX+= 1; 3068 glbceIDX %= ARRAY_SIZE(gbce); 3069 params.set(KEY_GLBCE, gbce[glbceIDX]); 3070 3071 if ( hardwareActive ) 3072 camera->setParameters(params.flatten()); 3073 break; 3074 3075 case 'F': 3076 faceDetectToggle = !faceDetectToggle; 3077 if ( hardwareActive ) { 3078 if (faceDetectToggle) 3079 camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, 0, 0); 3080 else 3081 camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0); 3082 } 3083 break; 3084 3085 case 'I': 3086 afTimeoutIdx++; 3087 afTimeoutIdx %= ARRAY_SIZE(afTimeout); 3088 params.set(KEY_AF_TIMEOUT, afTimeout[afTimeoutIdx]); 3089 if ( hardwareActive ) 3090 camera->setParameters(params.flatten()); 3091 3092 break; 3093 3094 case 'T': 3095 metaDataToggle = !metaDataToggle; 3096 break; 3097 3098 case '@': 3099 if ( hardwareActive ) { 3100 3101 closeCamera(); 3102 3103 if ( 0 >= openCamera() ) { 3104 printf( "Reconnected to CameraService \n"); 3105 } 3106 } 3107 3108 break; 3109 3110 case '#': 3111 3112 if ( burst >= MAX_BURST ) { 3113 burst = 0; 3114 } else { 3115 burst += BURST_INC; 3116 } 3117 burstCount = burst; 3118 params.set(KEY_TI_BURST, burst); 3119 3120 if ( hardwareActive ) 3121 camera->setParameters(params.flatten()); 3122 3123 break; 3124 3125 case 'J': 3126 flashIdx++; 3127 flashIdx %= numflash; 3128 params.set(CameraParameters::KEY_FLASH_MODE, (flash[flashIdx])); 3129 3130 if ( hardwareActive ) 3131 camera->setParameters(params.flatten()); 3132 3133 break; 3134 3135 case 'u': 3136 capture_mode++; 3137 capture_mode %= nummodevalues; 3138 3139 // HQ should always be in ldc-nsf 3140 // if not HQ, then return the ipp to its previous state 3141 if( !strcmp(modevalues[capture_mode], "high-quality") ) { 3142 ippIDX_old = ippIDX; 3143 ippIDX = 3; 3144 params.set(KEY_IPP, ipp_mode[ippIDX]); 3145 params.set(CameraParameters::KEY_RECORDING_HINT, CameraParameters::FALSE); 3146 previewRotation = 0; 3147 params.set(KEY_SENSOR_ORIENTATION, previewRotation); 3148 } else if ( !strcmp(modevalues[capture_mode], "video-mode") ) { 3149 params.set(CameraParameters::KEY_RECORDING_HINT, CameraParameters::TRUE); 3150 camera->getCameraInfo(camera_index, &cameraInfo); 3151 previewRotation = ((360-cameraInfo.orientation)%360); 3152 if (previewRotation >= 0 || previewRotation <=360) { 3153 params.set(KEY_SENSOR_ORIENTATION, previewRotation); 3154 } 3155 } else { 3156 ippIDX = ippIDX_old; 3157 params.set(CameraParameters::KEY_RECORDING_HINT, CameraParameters::FALSE); 3158 previewRotation = 0; 3159 params.set(KEY_SENSOR_ORIENTATION, previewRotation); 3160 } 3161 3162 params.set(KEY_MODE, (modevalues[capture_mode])); 3163 3164 if ( hardwareActive ) { 3165 if (previewRunning) { 3166 stopPreview(); 3167 } 3168 camera->setParameters(params.flatten()); 3169 // Get parameters from capabilities for the new capture mode 3170 params = camera->getParameters(); 3171 getSizeParametersFromCapabilities(); 3172 getParametersFromCapabilities(); 3173 // Set framerate 30fps and 12MP capture resolution if available for the new capture mode. 3174 // If not available set framerate and capture mode under index 0 from fps_const_str and capture_Array. 3175 frameRateIDX = getDefaultParameter("30000,30000", constCnt, fps_const_str); 3176 captureSizeIDX = getDefaultParameterResol("12MP", numcaptureSize, capture_Array); 3177 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_const_str[frameRateIDX]); 3178 params.setPictureSize(capture_Array[captureSizeIDX]->width, capture_Array[captureSizeIDX]->height); 3179 camera->setParameters(params.flatten()); 3180 } 3181 3182 requestBufferSourceReset(); 3183 3184 break; 3185 3186 case 'U': 3187 tempBracketIdx++; 3188 tempBracketIdx %= ARRAY_SIZE(tempBracketing); 3189 params.set(KEY_TEMP_BRACKETING, tempBracketing[tempBracketIdx]); 3190 3191 if ( hardwareActive ) 3192 camera->setParameters(params.flatten()); 3193 3194 break; 3195 3196 case 'H': 3197 expBracketIdx++; 3198 expBracketIdx %= ARRAY_SIZE(expBracketing); 3199 setDefaultExpGainPreset(shotParams, expBracketIdx); 3200 3201 break; 3202 3203 case 'n': 3204 if (shotConfigFlush) 3205 shotConfigFlush = false; 3206 else 3207 shotConfigFlush = true; 3208 3209 updateShotConfigFlushParam(); 3210 3211 break; 3212 3213 case '(': 3214 { 3215 char input[256]; 3216 input[0] = ch; 3217 scanf("%254s", input+1); 3218 setExpGainPreset(shotParams, input, true, PARAM_EXP_BRACKET_PARAM_NONE, shotConfigFlush); 3219 break; 3220 } 3221 case 'W': 3222 tempBracketRange++; 3223 tempBracketRange %= TEMP_BRACKETING_MAX_RANGE; 3224 if ( 0 == tempBracketRange ) { 3225 tempBracketRange = 1; 3226 } 3227 3228 params.set(KEY_TEMP_BRACKETING_NEG, tempBracketRange); 3229 params.set(KEY_TEMP_BRACKETING_POS, tempBracketRange); 3230 3231 if ( hardwareActive ) 3232 camera->setParameters(params.flatten()); 3233 3234 break; 3235 3236 case 'w': 3237 scene_mode++; 3238 scene_mode %= numscene; 3239 params.set(params.KEY_SCENE_MODE, scene[scene_mode]); 3240 3241 if ( hardwareActive ) 3242 camera->setParameters(params.flatten()); 3243 3244 break; 3245 3246 case 'i': 3247 iso_mode++; 3248 iso_mode %= numisoMode; 3249 params.set(KEY_ISO, isoMode[iso_mode]); 3250 if ( hardwareActive ) 3251 camera->setParameters(params.flatten()); 3252 break; 3253 3254 3255 case 'h': 3256 #ifdef TARGET_OMAP4 3257 if ( sharpness >= 200) 3258 #else 3259 if ( sharpness >= 100) 3260 #endif 3261 { 3262 sharpness = 0; 3263 } else { 3264 sharpness += 10; 3265 } 3266 params.set(KEY_SHARPNESS, sharpness); 3267 if ( hardwareActive ) 3268 camera->setParameters(params.flatten()); 3269 break; 3270 3271 case 'D': 3272 { 3273 audioCodecIDX++; 3274 audioCodecIDX %= ARRAY_SIZE(audioCodecs); 3275 break; 3276 } 3277 3278 case 'v': 3279 { 3280 outputFormatIDX++; 3281 outputFormatIDX %= ARRAY_SIZE(outputFormat); 3282 break; 3283 } 3284 3285 case 'z': 3286 if(strcmp(zoomstr, "true") == 0) { 3287 zoomIDX++; 3288 zoomIDX %= ARRAY_SIZE(zoom); 3289 params.set(CameraParameters::KEY_ZOOM, zoom[zoomIDX].idx); 3290 3291 if ( hardwareActive ) 3292 camera->setParameters(params.flatten()); 3293 } 3294 break; 3295 3296 case 'Z': 3297 if(strcmp(smoothzoomstr, "true") == 0) { 3298 zoomIDX++; 3299 zoomIDX %= ARRAY_SIZE(zoom); 3300 3301 if ( hardwareActive ) 3302 camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, zoom[zoomIDX].idx, 0); 3303 } 3304 break; 3305 3306 case 'j': 3307 exposure_mode++; 3308 exposure_mode %= numExposureMode; 3309 params.set(KEY_EXPOSURE, exposureMode[exposure_mode]); 3310 if ( strcmp (exposureMode[exposure_mode], "manual") == 0) { 3311 params.set(KEY_MANUAL_EXPOSURE, manualExp); 3312 params.set(KEY_MANUAL_GAIN_ISO, manualGain); 3313 params.set(KEY_MANUAL_EXPOSURE_RIGHT, manualExp); 3314 params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manualGain); 3315 } 3316 else 3317 { 3318 manualExp = manualExpMin; 3319 params.set(KEY_MANUAL_EXPOSURE, manualExp); 3320 params.set(KEY_MANUAL_EXPOSURE_RIGHT, manualExp); 3321 manualGain = manualGainMin; 3322 params.set(KEY_MANUAL_GAIN_ISO, manualGain); 3323 params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manualGain); 3324 } 3325 3326 if ( hardwareActive ) { 3327 camera->setParameters(params.flatten()); 3328 } 3329 3330 break; 3331 3332 case 'Q': 3333 if ( strcmp (exposureMode[exposure_mode], "manual") == 0) { 3334 manualExp += manualExpStep; 3335 if( manualExp > manualExpMax) { 3336 manualExp = manualExpMin; 3337 } 3338 params.set(KEY_MANUAL_EXPOSURE, manualExp); 3339 params.set(KEY_MANUAL_EXPOSURE_RIGHT, manualExp); 3340 camera->setParameters(params.flatten()); 3341 } 3342 break; 3343 3344 case ',': 3345 if ( strcmp (exposureMode[exposure_mode], "manual") == 0) { 3346 manualGain += manualGainStep; 3347 if( manualGain > manualGainMax) { 3348 manualGain = manualGainMin; 3349 } 3350 params.set(KEY_MANUAL_GAIN_ISO, manualGain); 3351 params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manualGain); 3352 camera->setParameters(params.flatten()); 3353 } 3354 break; 3355 3356 case 'c': 3357 if( contrast >= 200){ 3358 contrast = 0; 3359 } else { 3360 contrast += 10; 3361 } 3362 params.set(KEY_CONTRAST, contrast); 3363 if ( hardwareActive ) { 3364 camera->setParameters(params.flatten()); 3365 } 3366 break; 3367 case 'b': 3368 #ifdef TARGET_OMAP4 3369 if ( brightness >= 100) 3370 #else 3371 if ( brightness >= 200) 3372 #endif 3373 { 3374 brightness = 0; 3375 } else { 3376 brightness += 10; 3377 } 3378 3379 params.set(KEY_BRIGHTNESS, brightness); 3380 3381 if ( hardwareActive ) { 3382 camera->setParameters(params.flatten()); 3383 } 3384 3385 break; 3386 3387 case 's': 3388 if ( saturation >= 200) { 3389 saturation = 0; 3390 } else { 3391 saturation += 10; 3392 } 3393 3394 params.set(KEY_SATURATION, saturation); 3395 3396 if ( hardwareActive ) 3397 camera->setParameters(params.flatten()); 3398 3399 break; 3400 3401 case 'e': 3402 effects_mode++; 3403 effects_mode %= numEffects; 3404 printf("%d", numEffects); 3405 params.set(params.KEY_EFFECT, effectss[effects_mode]); 3406 printf("Effects_mode %d", effects_mode); 3407 3408 if ( hardwareActive ) 3409 camera->setParameters(params.flatten()); 3410 3411 break; 3412 3413 case 'r': 3414 frameRateIDX++; 3415 frameRateIDX %= constCnt; 3416 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_const_str[frameRateIDX]); 3417 printf("fps_const_str[frameRateIDX] %s\n", fps_const_str[frameRateIDX]); 3418 3419 if ( hardwareActive ) { 3420 camera->setParameters(params.flatten()); 3421 } 3422 3423 break; 3424 3425 case 'R': 3426 fpsRangeIdx += 1; 3427 fpsRangeIdx %= rangeCnt; 3428 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_range_str[fpsRangeIdx]); 3429 printf("fps_range_str[fpsRangeIdx] %s\n", fps_range_str[fpsRangeIdx]); 3430 3431 if ( hardwareActive ) { 3432 camera->setParameters(params.flatten()); 3433 } 3434 3435 break; 3436 3437 case 'x': 3438 antibanding_mode++; 3439 antibanding_mode %= numAntibanding; 3440 printf("%d", numAntibanding); 3441 params.set(params.KEY_ANTIBANDING, antiband[antibanding_mode]); 3442 3443 if ( hardwareActive ) 3444 camera->setParameters(params.flatten()); 3445 3446 break; 3447 3448 case 'g': 3449 focus_mode++; 3450 focus_mode %= numfocus; 3451 params.set(params.KEY_FOCUS_MODE, focus[focus_mode]); 3452 3453 if ( hardwareActive ) 3454 camera->setParameters(params.flatten()); 3455 3456 break; 3457 3458 case 'G': 3459 params.set(CameraParameters::KEY_FOCUS_AREAS, TEST_FOCUS_AREA); 3460 3461 if ( hardwareActive ) 3462 camera->setParameters(params.flatten()); 3463 3464 break; 3465 3466 case 'y': 3467 params.set(CameraParameters::KEY_METERING_AREAS, TEST_METERING_AREA); 3468 3469 if ( hardwareActive ) { 3470 camera->setParameters(params.flatten()); 3471 } 3472 3473 break; 3474 3475 case 'Y': 3476 3477 params.set(CameraParameters::KEY_METERING_AREAS, TEST_METERING_AREA_CENTER); 3478 3479 if ( hardwareActive ) { 3480 camera->setParameters(params.flatten()); 3481 } 3482 3483 break; 3484 3485 case 'N': 3486 3487 params.set(CameraParameters::KEY_METERING_AREAS, TEST_METERING_AREA_AVERAGE); 3488 3489 if ( hardwareActive ) { 3490 camera->setParameters(params.flatten()); 3491 } 3492 3493 break; 3494 3495 case 'f': 3496 gettimeofday(&autofocus_start, 0); 3497 3498 if ( hardwareActive ) 3499 camera->autoFocus(); 3500 3501 break; 3502 3503 case 'p': 3504 { 3505 int msgType = 0; 3506 3507 if((0 == strcmp(modevalues[capture_mode], "video-mode")) && 3508 (0 != strcmp(videosnapshotstr, "true"))) { 3509 printf("Video Snapshot is not supported\n"); 3510 } else if ( hardwareActive ) { 3511 if(isRawPixelFormat(pictureFormatArray[pictureFormat])) { 3512 createBufferOutputSource(); 3513 if (bufferSourceOutputThread.get()) { 3514 bufferSourceOutputThread->setBuffer(shotParams); 3515 bufferSourceOutputThread->setStreamCapture(streamCapture, expBracketIdx); 3516 } 3517 } else { 3518 msgType = CAMERA_MSG_COMPRESSED_IMAGE | 3519 CAMERA_MSG_RAW_IMAGE; 3520 #ifdef OMAP_ENHANCEMENT_BURST_CAPTURE 3521 msgType |= CAMERA_MSG_RAW_BURST; 3522 #endif 3523 } 3524 3525 gettimeofday(&picture_start, 0); 3526 camera->setParameters(params.flatten()); 3527 camera->takePictureWithParameters(msgType, shotParams.flatten()); 3528 } 3529 break; 3530 } 3531 3532 case 'S': 3533 { 3534 if (streamCapture) { 3535 streamCapture = false; 3536 setDefaultExpGainPreset(shotParams, expBracketIdx); 3537 // Stop streaming 3538 if (bufferSourceOutputThread.get()) { 3539 bufferSourceOutputThread->setStreamCapture(streamCapture, expBracketIdx); 3540 } 3541 } else { 3542 streamCapture = true; 3543 setSingleExpGainPreset(shotParams, expBracketIdx, 0, 0); 3544 // Queue more frames initially 3545 shotParams.set(ShotParameters::KEY_BURST, BRACKETING_STREAM_BUFFERS); 3546 } 3547 break; 3548 } 3549 3550 case 'P': 3551 { 3552 int msgType = CAMERA_MSG_COMPRESSED_IMAGE; 3553 ShotParameters reprocParams; 3554 3555 gettimeofday(&picture_start, 0); 3556 createBufferInputSource(); 3557 if (bufferSourceOutputThread.get() && 3558 bufferSourceOutputThread->hasBuffer()) 3559 { 3560 bufferSourceOutputThread->setStreamCapture(false, expBracketIdx); 3561 if (hardwareActive) camera->setParameters(params.flatten()); 3562 3563 if (bufferSourceInput.get()) { 3564 buffer_info_t info = bufferSourceOutputThread->popBuffer(); 3565 bufferSourceInput->setInput(info, pictureFormatArray[pictureFormat], reprocParams); 3566 if (hardwareActive) camera->reprocess(msgType, reprocParams.flatten()); 3567 } 3568 } 3569 break; 3570 } 3571 3572 case '&': 3573 printf("Enabling Preview Callback"); 3574 dump_preview = 1; 3575 if ( hardwareActive ) 3576 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK); 3577 break; 3578 3579 case '{': 3580 valstr = params.get(KEY_S3D2D_PREVIEW_MODE); 3581 if ( (NULL != valstr) && (0 == strcmp(valstr, "on")) ) 3582 { 3583 params.set(KEY_S3D2D_PREVIEW_MODE, "off"); 3584 } 3585 else 3586 { 3587 params.set(KEY_S3D2D_PREVIEW_MODE, "on"); 3588 } 3589 if ( hardwareActive ) 3590 camera->setParameters(params.flatten()); 3591 break; 3592 3593 case 'a': 3594 3595 while (1) { 3596 if ( menu_gps() < 0) 3597 break; 3598 }; 3599 3600 break; 3601 3602 case 'q': 3603 stopPreview(); 3604 deleteAllocatedMemory(); 3605 3606 return -1; 3607 3608 case '/': 3609 { 3610 if (showfps) 3611 { 3612 property_set("debug.image.showfps", "0"); 3613 showfps = false; 3614 } 3615 else 3616 { 3617 property_set("debug.image.showfps", "1"); 3618 showfps = true; 3619 } 3620 break; 3621 } 3622 3623 case '<': 3624 if(strcmp(AutoExposureLockstr, "true") == 0) { 3625 if(AutoExposureLocktoggle == false) { 3626 trySetAutoExposureLock(true); 3627 AutoExposureLocktoggle = true; 3628 } else { 3629 trySetAutoExposureLock(false); 3630 AutoExposureLocktoggle = false; 3631 printf("ExposureLock is not supported\n"); 3632 } 3633 } 3634 3635 if ( hardwareActive ) 3636 camera->setParameters(params.flatten()); 3637 3638 break; 3639 3640 case '>': 3641 if(strcmp(AutoWhiteBalanceLockstr, "true") == 0) { 3642 if(AutoWhiteBalanceLocktoggle == false) { 3643 trySetAutoWhiteBalanceLock(true); 3644 AutoWhiteBalanceLocktoggle = true; 3645 } else { 3646 trySetAutoWhiteBalanceLock(false); 3647 AutoWhiteBalanceLocktoggle = false; 3648 printf("ExposureLock is not supported\n"); 3649 } 3650 } 3651 3652 if ( hardwareActive ) { 3653 camera->setParameters(params.flatten()); 3654 } 3655 3656 break; 3657 3658 case ')': 3659 enableMisalignmentCorrectionIdx++; 3660 enableMisalignmentCorrectionIdx %= ARRAY_SIZE(misalignmentCorrection); 3661 params.set(KEY_MECHANICAL_MISALIGNMENT_CORRECTION, misalignmentCorrection[enableMisalignmentCorrectionIdx]); 3662 if ( hardwareActive ) { 3663 camera->setParameters(params.flatten()); 3664 } 3665 break; 3666 3667 case 'd': 3668 while (1) { 3669 if ( menu_algo() < 0) 3670 break; 3671 } 3672 break; 3673 3674 default: 3675 print_menu = 0; 3676 3677 break; 3678 } 3679 3680 return 0; 3681 } 3682 3683 void print_usage() { 3684 printf(" USAGE: camera_test <options>\n"); 3685 printf(" <options> (case insensitive)\n"); 3686 printf("-----------\n"); 3687 printf(" -f -> Functional tests.\n"); 3688 printf(" -a -> API tests.\n"); 3689 printf(" -e [<script>] -> Error scenario tests. If no script file is provided\n"); 3690 printf(" the test is run in interactive mode.\n"); 3691 printf(" -s <script> -c <sensorID> -> Stress / regression tests.\n"); 3692 printf(" -l [<flags>] -> Enable different kinds of logging capture. Multiple flags\n"); 3693 printf(" should be combined into a string. If flags are not provided\n"); 3694 printf(" no logs are captured.\n"); 3695 printf(" <flags>\n"); 3696 printf(" ---------\n"); 3697 printf(" l -> logcat [default]\n"); 3698 printf(" s -> syslink [default]\n"); 3699 printf(" -o <path> -> Output directory to store the test results. Image and video\n"); 3700 printf(" files are stored in corresponding sub-directories.\n"); 3701 printf(" -p <platform> -> Target platform. Only for stress tests.\n"); 3702 printf(" <platform>\n"); 3703 printf(" ------------\n"); 3704 printf(" blaze or B -> BLAZE\n"); 3705 printf(" tablet1 or T1 -> Blaze TABLET-1\n"); 3706 printf(" tablet2 or T2 -> Blaze TABLET-2 [default]\n\n"); 3707 return; 3708 } 3709 3710 int error_scenario() { 3711 char ch; 3712 status_t stat = NO_ERROR; 3713 3714 if (print_menu) { 3715 printf(" 0. Buffer need\n"); 3716 printf(" 1. Not enough memory\n"); 3717 printf(" 2. Media server crash\n"); 3718 printf(" 3. Overlay object request\n"); 3719 printf(" 4. Pass unsupported preview&picture format\n"); 3720 printf(" 5. Pass unsupported preview&picture resolution\n"); 3721 printf(" 6. Pass unsupported preview framerate\n"); 3722 3723 printf(" q. Quit\n"); 3724 printf(" Choice: "); 3725 } 3726 3727 print_menu = 1; 3728 ch = getchar(); 3729 printf("%c\n", ch); 3730 3731 switch (ch) { 3732 case '0': { 3733 printf("Case0:Buffer need\n"); 3734 bufferStarvationTest = 1; 3735 params.set(KEY_BUFF_STARV, bufferStarvationTest); //enable buffer starvation 3736 3737 if ( !recordingMode ) { 3738 recordingMode = true; 3739 if ( startPreview() < 0 ) { 3740 printf("Error while starting preview\n"); 3741 3742 return -1; 3743 } 3744 3745 if ( openRecorder() < 0 ) { 3746 printf("Error while openning video recorder\n"); 3747 3748 return -1; 3749 } 3750 3751 if ( configureRecorder() < 0 ) { 3752 printf("Error while configuring video recorder\n"); 3753 3754 return -1; 3755 } 3756 3757 if ( startRecording() < 0 ) { 3758 printf("Error while starting video recording\n"); 3759 3760 return -1; 3761 } 3762 3763 } 3764 3765 usleep(1000000);//1s 3766 3767 stopPreview(); 3768 3769 if ( recordingMode ) { 3770 stopRecording(); 3771 closeRecorder(); 3772 3773 recordingMode = false; 3774 } 3775 3776 break; 3777 } 3778 3779 case '1': { 3780 printf("Case1:Not enough memory\n"); 3781 int* tMemoryEater = new int[999999999]; 3782 3783 if (!tMemoryEater) { 3784 printf("Not enough memory\n"); 3785 return -1; 3786 } else { 3787 delete tMemoryEater; 3788 } 3789 3790 break; 3791 } 3792 3793 case '2': { 3794 printf("Case2:Media server crash\n"); 3795 //camera = Camera::connect(); 3796 3797 if ( NULL == camera.get() ) { 3798 printf("Unable to connect to CameraService\n"); 3799 return -1; 3800 } 3801 3802 break; 3803 } 3804 3805 case '3': { 3806 printf("Case3:Overlay object request\n"); 3807 int err = 0; 3808 3809 err = open("/dev/video5", O_RDWR); 3810 3811 if (err < 0) { 3812 printf("Could not open the camera device5: %d\n", err ); 3813 return err; 3814 } 3815 3816 if ( startPreview() < 0 ) { 3817 printf("Error while starting preview\n"); 3818 return -1; 3819 } 3820 3821 usleep(1000000);//1s 3822 3823 stopPreview(); 3824 3825 close(err); 3826 break; 3827 } 3828 3829 case '4': { 3830 3831 if ( hardwareActive ) { 3832 3833 params.setPictureFormat("invalid-format"); 3834 params.setPreviewFormat("invalid-format"); 3835 3836 stat = camera->setParameters(params.flatten()); 3837 3838 if ( NO_ERROR != stat ) { 3839 printf("Test passed!\n"); 3840 } else { 3841 printf("Test failed!\n"); 3842 } 3843 3844 initDefaults(); 3845 } 3846 3847 break; 3848 } 3849 3850 case '5': { 3851 3852 if ( hardwareActive ) { 3853 3854 params.setPictureSize(-1, -1); 3855 params.setPreviewSize(-1, -1); 3856 3857 stat = camera->setParameters(params.flatten()); 3858 3859 if ( NO_ERROR != stat ) { 3860 printf("Test passed!\n"); 3861 } else { 3862 printf("Test failed!\n"); 3863 } 3864 3865 initDefaults(); 3866 } 3867 3868 break; 3869 } 3870 3871 case '6': { 3872 3873 if ( hardwareActive ) { 3874 3875 params.setPreviewFrameRate(-1); 3876 3877 stat = camera->setParameters(params.flatten()); 3878 3879 if ( NO_ERROR != stat ) { 3880 printf("Test passed!\n"); 3881 } else { 3882 printf("Test failed!\n"); 3883 } 3884 3885 initDefaults(); 3886 } 3887 3888 3889 break; 3890 } 3891 3892 case 'q': { 3893 return -1; 3894 } 3895 3896 default: { 3897 print_menu = 0; 3898 break; 3899 } 3900 } 3901 3902 return 0; 3903 } 3904 3905 int restartCamera() { 3906 3907 printf("+++Restarting Camera After Error+++\n"); 3908 stopPreview(); 3909 3910 if (recordingMode) { 3911 stopRecording(); 3912 closeRecorder(); 3913 3914 recordingMode = false; 3915 } 3916 3917 sleep(3); //Wait a bit before restarting 3918 3919 restartCount++; 3920 3921 if ( openCamera() < 0 ) 3922 { 3923 printf("+++Camera Restarted Failed+++\n"); 3924 system("echo camerahal_test > /sys/power/wake_unlock"); 3925 return -1; 3926 } 3927 3928 initDefaults(); 3929 3930 stopScript = false; 3931 3932 printf("+++Camera Restarted Successfully+++\n"); 3933 return 0; 3934 } 3935 3936 int parseCommandLine(int argc, char *argv[], cmd_args_t *cmd_args) { 3937 if (argc < 2) { 3938 printf("Please enter at least 1 argument\n"); 3939 return -2; 3940 } 3941 3942 // Set defaults 3943 memset(cmd_args, 0, sizeof(*cmd_args)); 3944 cmd_args->logging = LOGGING_LOGCAT | LOGGING_SYSLINK; 3945 cmd_args->platform_id = BLAZE_TABLET2; 3946 3947 for (int a = 1; a < argc; a++) { 3948 const char * const arg = argv[a]; 3949 if (arg[0] != '-') { 3950 printf("Error: Invalid argument \"%s\"\n", arg); 3951 return -2; 3952 } 3953 3954 switch (arg[1]) { 3955 case 's': 3956 cmd_args->test_type = TEST_TYPE_REGRESSION; 3957 if (a < argc - 1) { 3958 cmd_args->script_file_name = argv[++a]; 3959 } else { 3960 printf("Error: No script is specified for stress / regression test.\n"); 3961 return -2; 3962 } 3963 break; 3964 3965 case 'f': 3966 cmd_args->test_type = TEST_TYPE_FUNCTIONAL; 3967 break; 3968 3969 case 'a': 3970 cmd_args->test_type = TEST_TYPE_API; 3971 break; 3972 3973 case 'e': 3974 cmd_args->test_type = TEST_TYPE_ERROR; 3975 if (a < argc - 1) { 3976 cmd_args->script_file_name = argv[++a]; 3977 } 3978 break; 3979 3980 case 'l': 3981 cmd_args->logging = 0; 3982 3983 if (a < argc - 1 && argv[a + 1][0] != '-') { 3984 const char *flags = argv[++a]; 3985 while (*flags) { 3986 char flag = *flags++; 3987 switch (flag) { 3988 case 'l': 3989 cmd_args->logging |= LOGGING_LOGCAT; 3990 break; 3991 3992 case 's': 3993 cmd_args->logging |= LOGGING_SYSLINK; 3994 break; 3995 3996 default: 3997 printf("Error: Unknown logging type \"%c\"\n", flag); 3998 return -2; 3999 } 4000 } 4001 } 4002 break; 4003 4004 case 'p': 4005 if (a < argc - 1) { 4006 const char *platform = argv[++a]; 4007 if( strcasecmp(platform,"blaze") == 0 || strcasecmp(platform,"B") == 0 ){ 4008 cmd_args->platform_id = BLAZE; 4009 } 4010 else if( (strcasecmp(platform,"tablet1") == 0) || (strcasecmp(platform,"T1") == 0) ) { 4011 cmd_args->platform_id = BLAZE_TABLET1; 4012 } 4013 else if( (strcasecmp(platform,"tablet2") == 0) || (strcasecmp(platform,"T2") == 0) ) { 4014 cmd_args->platform_id = BLAZE_TABLET2; 4015 } 4016 else { 4017 printf("Error: Unknown argument for platform ID.\n"); 4018 return -2; 4019 } 4020 } else { 4021 printf("Error: No argument is specified for platform ID.\n"); 4022 return -2; 4023 } 4024 break; 4025 4026 case 'o': 4027 if (a < argc - 1) { 4028 cmd_args->output_path = argv[++a]; 4029 } else { 4030 printf("Error: No output path is specified.\n"); 4031 return -2; 4032 } 4033 break; 4034 4035 case 'c': 4036 if (a < argc -1) { 4037 camera_index = atoi(argv[++a]); 4038 } else { 4039 printf("Error: No sensorID is specified.\n"); 4040 return -2; 4041 } 4042 break; 4043 4044 default: 4045 printf("Error: Unknown option \"%s\"\n", argv[a]); 4046 return -2; 4047 } 4048 } 4049 4050 return 0; 4051 } 4052 4053 int setOutputDirPath(cmd_args_t *cmd_args, int restart_count) { 4054 if ((cmd_args->output_path != NULL) && 4055 (strlen(cmd_args->output_path) < sizeof(output_dir_path))) { 4056 strcpy(output_dir_path, cmd_args->output_path); 4057 } else { 4058 strcpy(output_dir_path, SDCARD_PATH); 4059 4060 if (cmd_args->script_file_name != NULL) { 4061 const char *config = cmd_args->script_file_name; 4062 char dir_name[40]; 4063 size_t count = 0; 4064 char *p; 4065 4066 // remove just the '.txt' part of the config 4067 while ((config[count] != '.') && ((count + 1) < sizeof(dir_name))) { 4068 count++; 4069 } 4070 4071 strncpy(dir_name, config, count); 4072 4073 dir_name[count] = NULL; 4074 p = dir_name; 4075 while (*p != '\0') { 4076 if (*p == '/') { 4077 printf("SDCARD_PATH is not added to the output directory.\n"); 4078 // Needed when camera_test script is executed using the OTC 4079 strcpy(output_dir_path, ""); 4080 break; 4081 } 4082 } 4083 4084 strcat(output_dir_path, dir_name); 4085 if (camera_index == 1) { 4086 strcat(output_dir_path, SECONDARY_SENSOR); 4087 }else if (camera_index == 2) { 4088 strcat(output_dir_path, S3D_SENSOR); 4089 } 4090 } 4091 } 4092 4093 if (restart_count && (strlen(output_dir_path) + 16) < sizeof(output_dir_path)) { 4094 char count[16]; 4095 sprintf(count, "_%d", restart_count); 4096 strcat(output_dir_path, count); 4097 } 4098 4099 if (access(output_dir_path, F_OK) == -1) { 4100 if (mkdir(output_dir_path, 0777) == -1) { 4101 printf("\nError: Output directory \"%s\" was not created\n", output_dir_path); 4102 return -1; 4103 } 4104 } 4105 4106 sprintf(videos_dir_path, "%s/videos", output_dir_path); 4107 4108 if (access(videos_dir_path, F_OK) == -1) { 4109 if (mkdir(videos_dir_path, 0777) == -1) { 4110 printf("\nError: Videos directory \"%s\" was not created\n", videos_dir_path); 4111 return -1; 4112 } 4113 } 4114 4115 sprintf(images_dir_path, "%s/images", output_dir_path); 4116 4117 if (access(images_dir_path, F_OK) == -1) { 4118 if (mkdir(images_dir_path, 0777) == -1) { 4119 printf("\nError: Images directory \"%s\" was not created\n", images_dir_path); 4120 return -1; 4121 } 4122 } 4123 4124 return 0; 4125 } 4126 4127 int startTest() { 4128 ProcessState::self()->startThreadPool(); 4129 4130 if (openCamera() < 0) { 4131 printf("Camera initialization failed\n"); 4132 return -1; 4133 } 4134 4135 initDefaults(); 4136 4137 return 0; 4138 } 4139 4140 int runRegressionTest(cmd_args_t *cmd_args) { 4141 char *cmd; 4142 int pid; 4143 4144 platformID = cmd_args->platform_id; 4145 4146 int res = startTest(); 4147 if (res != 0) { 4148 return res; 4149 } 4150 4151 cmd = load_script(cmd_args->script_file_name); 4152 4153 if (cmd != NULL) { 4154 start_logging(cmd_args->logging, pid); 4155 stressTest = true; 4156 4157 while (1) { 4158 if (execute_functional_script(cmd) == 0) { 4159 break; 4160 } 4161 4162 printf("CameraTest Restarting Camera...\n"); 4163 4164 free(cmd); 4165 cmd = NULL; 4166 4167 if ( (restartCamera() != 0) || ((cmd = load_script(cmd_args->script_file_name)) == NULL) ) { 4168 printf("ERROR::CameraTest Restarting Camera...\n"); 4169 res = -1; 4170 break; 4171 } 4172 4173 res = setOutputDirPath(cmd_args, restartCount); 4174 if (res != 0) { 4175 break; 4176 } 4177 } 4178 4179 free(cmd); 4180 stop_logging(cmd_args->logging, pid); 4181 } 4182 4183 return 0; 4184 } 4185 4186 int runFunctionalTest() { 4187 int res = startTest(); 4188 if (res != 0) { 4189 return res; 4190 } 4191 4192 print_menu = 1; 4193 4194 while (1) { 4195 if (functional_menu() < 0) { 4196 break; 4197 } 4198 } 4199 4200 return 0; 4201 } 4202 4203 int runApiTest() { 4204 printf("API level test cases coming soon ... \n"); 4205 return 0; 4206 } 4207 4208 int runErrorTest(cmd_args_t *cmd_args) { 4209 int res = startTest(); 4210 if (res != 0) { 4211 return res; 4212 } 4213 4214 if (cmd_args->script_file_name != NULL) { 4215 char *cmd; 4216 int pid; 4217 4218 cmd = load_script(cmd_args->script_file_name); 4219 4220 if (cmd != NULL) { 4221 start_logging(cmd_args->logging, pid); 4222 execute_error_script(cmd); 4223 free(cmd); 4224 stop_logging(cmd_args->logging, pid); 4225 } 4226 } else { 4227 print_menu = 1; 4228 4229 while (1) { 4230 if (error_scenario() < 0) { 4231 break; 4232 } 4233 } 4234 } 4235 4236 return 0; 4237 } 4238 4239 int main(int argc, char *argv[]) { 4240 sp<ProcessState> proc(ProcessState::self()); 4241 4242 unsigned long long st, end, delay; 4243 timeval current_time; 4244 cmd_args_t cmd_args; 4245 int res; 4246 4247 res = parseCommandLine(argc, argv, &cmd_args); 4248 if (res != 0) { 4249 print_usage(); 4250 return res; 4251 } 4252 4253 res = setOutputDirPath(&cmd_args, 0); 4254 if (res != 0) { 4255 return res; 4256 } 4257 4258 gettimeofday(¤t_time, 0); 4259 4260 st = current_time.tv_sec * 1000000 + current_time.tv_usec; 4261 4262 system("echo camerahal_test > /sys/power/wake_lock"); 4263 4264 switch (cmd_args.test_type) { 4265 case TEST_TYPE_REGRESSION: 4266 res = runRegressionTest(&cmd_args); 4267 break; 4268 4269 case TEST_TYPE_FUNCTIONAL: 4270 res = runFunctionalTest(); 4271 break; 4272 4273 case TEST_TYPE_API: 4274 res = runApiTest(); 4275 break; 4276 4277 case TEST_TYPE_ERROR: 4278 res = runErrorTest(&cmd_args); 4279 break; 4280 } 4281 4282 system("echo camerahal_test > /sys/power/wake_unlock"); 4283 4284 gettimeofday(¤t_time, 0); 4285 end = current_time.tv_sec * 1000000 + current_time.tv_usec; 4286 delay = end - st; 4287 printf("Application closed after: %llu ms\n", delay); 4288 4289 return res; 4290 } 4291