camera_test_menu.cpp revision 46de639b23db99d7b99ff1c676ac98b84b6336c6
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 10#include <surfaceflinger/Surface.h> 11#include <surfaceflinger/ISurface.h> 12#include <surfaceflinger/ISurfaceComposer.h> 13#include <surfaceflinger/ISurfaceComposerClient.h> 14#include <surfaceflinger/SurfaceComposerClient.h> 15 16#include <camera/Camera.h> 17#include <camera/ICamera.h> 18#include <media/mediarecorder.h> 19 20#include <binder/IPCThreadState.h> 21#include <binder/ProcessState.h> 22#include <binder/IServiceManager.h> 23#include <cutils/properties.h> 24#include <camera/CameraParameters.h> 25#include <system/audio.h> 26#include <system/camera.h> 27 28#include <cutils/memory.h> 29#include <utils/Log.h> 30 31#include <sys/wait.h> 32 33#include "camera_test.h" 34 35using namespace android; 36 37int camera_index = 0; 38int print_menu; 39sp<Camera> camera; 40sp<MediaRecorder> recorder; 41sp<SurfaceComposerClient> client; 42sp<SurfaceControl> surfaceControl; 43sp<Surface> previewSurface; 44CameraParameters params; 45float compensation = 0.0; 46double latitude = 0.0; 47double longitude = 0.0; 48double degree_by_step = 17.5609756;//..0975609756097; 49double altitude = 0.0; 50int awb_mode = 0; 51int effects_mode = 0; 52int scene_mode = 0; 53int caf_mode = 0; 54int vnf_mode = 0; 55int vstab_mode = 0; 56 57int tempBracketRange = 1; 58int tempBracketIdx = 0; 59int measurementIdx = 0; 60int expBracketIdx = 0; 61int AutoConvergenceModeIDX = 0; 62int ManualConvergenceValuesIDX = 0; 63int ManualConvergenceDefaultValueIDX = 2; 64int gbceIDX = 0; 65int glbceIDX = 0; 66int rotation = 0; 67bool reSizePreview = true; 68bool hardwareActive = false; 69bool recordingMode = false; 70bool previewRunning = false; 71int saturation = 0; 72int zoomIDX = 0; 73int videoCodecIDX = 0; 74int audioCodecIDX = 0; 75int outputFormatIDX = 0; 76int contrast = 0; 77int brightness = 0; 78unsigned int burst = 0; 79int sharpness = 0; 80int iso_mode = 0; 81int capture_mode = 0; 82int exposure_mode = 0; 83int ippIDX = 0; 84int ippIDX_old = 0; 85int previewFormat = 0; 86int jpegQuality = 85; 87int thumbQuality = 85; 88int flashIdx = 0; 89int fpsRangeIdx = 0; 90timeval autofocus_start, picture_start; 91char script_name[80]; 92int prevcnt = 0; 93int videoFd = -1; 94int elockidx = 0; 95int wblockidx = 0; 96 97 98char dir_path[80] = SDCARD_PATH; 99 100const char *cameras[] = {"Primary Camera", "Secondary Camera 1", "Stereo Camera", "USB Camera", "Fake Camera"}; 101const char *measurement[] = {"disable", "enable"}; 102const char *expBracketing[] = {"disable", "enable"}; 103const char *expBracketingRange[] = {"", "-30,0,30,0,-30"}; 104const char *tempBracketing[] = {"disable", "enable"}; 105const char *faceDetection[] = {"disable", "enable"}; 106const char *lock[] = {"false", "true"}; 107 108#if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 109const char *ipp_mode[] = { "off", "Chroma Suppression", "Edge Enhancement" }; 110#else 111const char *ipp_mode[] = { "off", "ldc", "nsf", "ldc-nsf" }; 112#endif 113 114const char *iso [] = { "auto", "100", "200", "400", "800", "1200", "1600"}; 115 116const char *effects [] = { 117#if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 118 "none", 119 "mono", 120 "negative", 121 "solarize", 122 "sepia", 123 "whiteboard", 124 "blackboard", 125 "cool", 126 "emboss" 127#else 128 "none", 129 "mono", 130 "negative", 131 "solarize", 132 "sepia", 133 "vivid", 134 "whiteboard", 135 "blackboard", 136 "cool", 137 "emboss", 138 "blackwhite", 139 "aqua", 140 "posterize" 141#endif 142}; 143 144const char CameraParameters::FLASH_MODE_OFF[] = "off"; 145const char CameraParameters::FLASH_MODE_AUTO[] = "auto"; 146const char CameraParameters::FLASH_MODE_ON[] = "on"; 147const char CameraParameters::FLASH_MODE_RED_EYE[] = "red-eye"; 148const char CameraParameters::FLASH_MODE_TORCH[] = "torch"; 149 150const char *flashModes[] = { 151 "off", 152 "auto", 153 "on", 154 "red-eye", 155 "torch", 156 "fill-in", 157}; 158 159const char *caf [] = { "Off", "On" }; 160const char *vnf [] = { "Off", "On" }; 161const char *vstab [] = { "Off", "On" }; 162 163 164const char *scene [] = { 165#if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 166 "auto", 167 "portrait", 168 "landscape", 169 "night", 170 "night-portrait", 171 "fireworks", 172 "snow", 173 "action", 174#else 175 "auto", 176 "portrait", 177 "landscape", 178 "night", 179 "night-portrait", 180 "night-indoor", 181 "fireworks", 182 "sport", 183 "cine", 184 "beach", 185 "snow", 186 "mood", 187 "closeup", 188 "underwater", 189 "document", 190 "barcode", 191 "oldfilm", 192 "candlelight", 193 "party", 194 "steadyphoto", 195 "sunset", 196 "action", 197 "theatre" 198#endif 199}; 200const char *strawb_mode[] = { 201 "auto", 202 "incandescent", 203 "fluorescent", 204 "daylight", 205 "horizon", 206 "shadow", 207 "tungsten", 208 "shade", 209 "twilight", 210 "warm-fluorescent", 211 "facepriority", 212 "sunset" 213}; 214 215size_t length_cam = ARRAY_SIZE(cameras); 216 217 218preview_size previewSize [] = { 219 { 0, 0, "NULL"}, 220 { 128, 96, "SQCIF" }, 221 { 176, 144, "QCIF" }, 222 { 352, 288, "CIF" }, 223 { 320, 240, "QVGA" }, 224 { 352, 288, "CIF" }, 225 { 640, 480, "VGA" }, 226 { 720, 480, "NTSC" }, 227 { 720, 576, "PAL" }, 228 { 800, 480, "WVGA" }, 229 { 848, 480, "WVGA2"}, 230 { 864, 480, "WVGA3"}, 231 { 992, 560, "WVGA4"}, 232 { 1280, 720, "HD" }, 233 { 1920, 1080, "FULLHD"}, 234}; 235 236size_t length_previewSize = ARRAY_SIZE(previewSize); 237 238Vcapture_size VcaptureSize [] = { 239 { 128, 96, "SQCIF" }, 240 { 176, 144, "QCIF" }, 241 { 352, 288, "CIF" }, 242 { 320, 240, "QVGA" }, 243 { 640, 480, "VGA" }, 244 { 704, 480, "TVNTSC" }, 245 { 704, 576, "TVPAL" }, 246 { 720, 480, "D1NTSC" }, 247 { 720, 576, "D1PAL" }, 248 { 800, 480, "WVGA" }, 249 #if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 250 { 848, 480, "WVGA2"}, 251 { 864, 480, "WVGA3"}, 252 { 992, 560, "WVGA4"}, 253 #endif 254 { 1280, 720, "HD" }, 255 { 1920, 1080, "FULLHD"}, 256}; 257 258size_t lenght_Vcapture_size = ARRAY_SIZE(VcaptureSize); 259 260capture_Size captureSize[] = { 261 { 320, 240, "QVGA" }, 262 { 640, 480, "VGA" }, 263 { 800, 600, "SVGA" }, 264 { 1152, 864, "1MP" }, 265 { 1280, 1024, "1.3MP" }, 266 { 1600, 1200, "2MP" }, 267 { 2048, 1536, "3MP" }, 268 { 2592, 1944, "5MP" }, 269 { 2608, 1960, "5MP" }, 270 { 3264, 2448, "8MP" }, 271 { 3648, 2736, "10MP"}, 272 { 4032, 3024, "12MP"}, 273}; 274 275size_t length_capture_Size = ARRAY_SIZE(captureSize); 276 277 278outformat outputFormat[] = { 279 { OUTPUT_FORMAT_THREE_GPP, "3gp" }, 280 { OUTPUT_FORMAT_MPEG_4, "mp4" }, 281 }; 282 283size_t length_outformat = ARRAY_SIZE(outputFormat); 284 285video_Codecs videoCodecs[] = { 286 { VIDEO_ENCODER_H263, "H263" }, 287 { VIDEO_ENCODER_H264, "H264" }, 288 { VIDEO_ENCODER_MPEG_4_SP, "MPEG4"} 289}; 290 291size_t length_video_Codecs = ARRAY_SIZE(videoCodecs); 292 293audio_Codecs audioCodecs[] = { 294 { AUDIO_ENCODER_AMR_NB, "AMR_NB" }, 295 { AUDIO_ENCODER_AMR_WB, "AMR_WB" }, 296 { AUDIO_ENCODER_AAC, "AAC" }, 297 { AUDIO_ENCODER_AAC_PLUS, "AAC+" }, 298 { AUDIO_ENCODER_EAAC_PLUS, "EAAC+" }, 299 { AUDIO_ENCODER_LIST_END, "disabled"}, 300}; 301 302size_t length_audio_Codecs = ARRAY_SIZE(audioCodecs); 303 304V_bitRate VbitRate[] = { 305 { 64000, "64K" }, 306 { 128000, "128K" }, 307 { 192000, "192K" }, 308 { 240000, "240K" }, 309 { 320000, "320K" }, 310 { 360000, "360K" }, 311 { 384000, "384K" }, 312 { 420000, "420K" }, 313 { 768000, "768K" }, 314 { 1000000, "1M" }, 315 { 1500000, "1.5M" }, 316 { 2000000, "2M" }, 317 { 4000000, "4M" }, 318 { 6000000, "6M" }, 319 { 8000000, "8M" }, 320 { 10000000, "10M" }, 321}; 322 323size_t length_V_bitRate = ARRAY_SIZE(VbitRate); 324 325Zoom zoom[] = { 326 { 0, "1x" }, 327 { 12, "1.5x"}, 328 { 20, "2x" }, 329 { 27, "2.5x"}, 330 { 32, "3x" }, 331 { 36, "3.5x"}, 332 { 40, "4x" }, 333 { 60, "8x" }, 334}; 335 336size_t length_Zoom = ARRAY_SIZE(zoom); 337 338fps_ranges fpsRanges[] = { 339 { "5000,30000", "[5:30]" }, 340 { "5000,10000", "[5:10]" }, 341 { "5000,15000", "[5:15]" }, 342 { "5000,20000", "[5:20]" }, 343}; 344 345size_t length_fps_ranges = ARRAY_SIZE(fpsRanges); 346 347fpsConst_Ranges fpsConstRanges[] = { 348 { "5000,5000", "[5:5]", 5 }, 349 { "10000,10000", "[10:10]", 10 }, 350 { "15000,15000", "[15:15]", 15 }, 351 { "20000,20000", "[20:20]", 20 }, 352 { "25000,25000", "[25:25]", 25 }, 353 { "30000,30000", "[30:30]", 30 }, 354}; 355 356size_t length_fpsConst_Ranges = ARRAY_SIZE(fpsConstRanges); 357 358fpsConst_RangesSec fpsConstRangesSec[] = { 359 { "5000,5000", "[5:5]", 5 }, 360 { "10000,10000", "[10:10]", 10 }, 361 { "15000,15000", "[15:15]", 15 }, 362 { "20000,20000", "[20:20]", 20 }, 363 { "25000,25000", "[25:25]", 25 }, 364 { "27000,27000", "[27:27]", 27 }, 365}; 366 367size_t length_fpsConst_RangesSec = ARRAY_SIZE(fpsConstRangesSec); 368 369const char *antibanding[] = { 370 "off", 371 "auto", 372 "50hz", 373 "60hz", 374}; 375int antibanding_mode = 0; 376const char *focus[] = { 377 "auto", 378 "infinity", 379 "macro", 380 "continuous-video", 381 "extended", 382 "portrait", 383}; 384int focus_mode = 0; 385pixel_format pixelformat[] = { 386 { HAL_PIXEL_FORMAT_YCbCr_422_I, CameraParameters::PIXEL_FORMAT_YUV422I }, 387 { HAL_PIXEL_FORMAT_YCrCb_420_SP, CameraParameters::PIXEL_FORMAT_YUV420SP }, 388 { HAL_PIXEL_FORMAT_RGB_565, CameraParameters::PIXEL_FORMAT_RGB565 }, 389 { -1, CameraParameters::PIXEL_FORMAT_JPEG }, 390 { -1, "raw" }, 391 }; 392 393const char *codingformat[] = {"yuv422i-yuyv", "yuv420sp", "rgb565", "jpeg", "raw", "jps", "mpo", "raw+jpeg", "raw+mpo"}; 394const char *gbce[] = {"disable", "enable"}; 395int pictureFormat = 3; // jpeg 396const char *exposure[] = {"auto", "macro", "portrait", "landscape", "sports", "night", "night-portrait", "backlighting", "manual"}; 397const char *capture[] = { "high-performance", "high-quality", "video-mode" }; 398const char *autoconvergencemode[] = { "mode-disable", "mode-frame", "mode-center", "mode-fft", "mode-manual" }; 399const char *manualconvergencevalues[] = { "-100", "-50", "-30", "-25", "0", "25", "50", "100" }; 400 401const struct { 402 int fps; 403} frameRate[] = { 404 {0}, 405 {5}, 406 {10}, 407 {15}, 408 {20}, 409 {25}, 410 {30} 411}; 412 413int thumbSizeIDX = 3; 414int previewSizeIDX = ARRAY_SIZE(previewSize) - 1; 415int captureSizeIDX = ARRAY_SIZE(captureSize) - 1; 416int frameRateIDX = ARRAY_SIZE(fpsConstRanges) - 1; 417int frameRateIDXSec = ARRAY_SIZE(fpsConstRangesSec) - 1; 418int VcaptureSizeIDX = ARRAY_SIZE(VcaptureSize) - 1; 419int VbitRateIDX = ARRAY_SIZE(VbitRate) - 1; 420 421static unsigned int recording_counter = 1; 422 423int dump_preview = 0; 424int bufferStarvationTest = 0; 425bool showfps = false; 426 427const char *metering[] = { 428 "center", 429 "average", 430}; 431int meter_mode = 0; 432bool bLogSysLinkTrace = true; 433bool stressTest = false; 434bool stopScript = false; 435int restartCount = 0; 436 437/** Calculate delay from a reference time */ 438unsigned long long timeval_delay(const timeval *ref) { 439 unsigned long long st, end, delay; 440 timeval current_time; 441 442 gettimeofday(¤t_time, 0); 443 444 st = ref->tv_sec * 1000000 + ref->tv_usec; 445 end = current_time.tv_sec * 1000000 + current_time.tv_usec; 446 delay = end - st; 447 448 return delay; 449} 450 451/** Callback for takePicture() */ 452void my_raw_callback(const sp<IMemory>& mem) { 453 454 static int counter = 1; 455 unsigned char *buff = NULL; 456 int size; 457 int fd = -1; 458 char fn[256]; 459 460 LOG_FUNCTION_NAME; 461 462 if (mem == NULL) 463 goto out; 464 465 //Start preview after capture. 466 camera->startPreview(); 467 468 fn[0] = 0; 469 sprintf(fn, "/sdcard/img%03d.raw", counter); 470 fd = open(fn, O_CREAT | O_WRONLY | O_TRUNC, 0777); 471 472 if (fd < 0) 473 goto out; 474 475 size = mem->size(); 476 477 if (size <= 0) 478 goto out; 479 480 buff = (unsigned char *)mem->pointer(); 481 482 if (!buff) 483 goto out; 484 485 if (size != write(fd, buff, size)) 486 printf("Bad Write int a %s error (%d)%s\n", fn, errno, strerror(errno)); 487 488 counter++; 489 printf("%s: buffer=%08X, size=%d stored at %s\n", 490 __FUNCTION__, (int)buff, size, fn); 491 492out: 493 494 if (fd >= 0) 495 close(fd); 496 497 LOG_FUNCTION_NAME_EXIT; 498} 499 500void saveFile(const sp<IMemory>& mem) { 501 static int counter = 1; 502 unsigned char *buff = NULL; 503 int size; 504 int fd = -1; 505 char fn[256]; 506 507 LOG_FUNCTION_NAME; 508 509 if (mem == NULL) 510 goto out; 511 512 fn[0] = 0; 513 sprintf(fn, "/sdcard/preview%03d.yuv", counter); 514 fd = open(fn, O_CREAT | O_WRONLY | O_TRUNC, 0777); 515 if(fd < 0) { 516 ALOGE("Unable to open file %s: %s", fn, strerror(fd)); 517 goto out; 518 } 519 520 size = mem->size(); 521 if (size <= 0) { 522 ALOGE("IMemory object is of zero size"); 523 goto out; 524 } 525 526 buff = (unsigned char *)mem->pointer(); 527 if (!buff) { 528 ALOGE("Buffer pointer is invalid"); 529 goto out; 530 } 531 532 if (size != write(fd, buff, size)) 533 printf("Bad Write int a %s error (%d)%s\n", fn, errno, strerror(errno)); 534 535 counter++; 536 printf("%s: buffer=%08X, size=%d\n", 537 __FUNCTION__, (int)buff, size); 538 539out: 540 541 if (fd >= 0) 542 close(fd); 543 544 LOG_FUNCTION_NAME_EXIT; 545} 546 547 548void debugShowFPS() 549{ 550 static int mFrameCount = 0; 551 static int mLastFrameCount = 0; 552 static nsecs_t mLastFpsTime = 0; 553 static float mFps = 0; 554 mFrameCount++; 555 if ( ( mFrameCount % 30 ) == 0 ) { 556 nsecs_t now = systemTime(); 557 nsecs_t diff = now - mLastFpsTime; 558 mFps = ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff; 559 mLastFpsTime = now; 560 mLastFrameCount = mFrameCount; 561 printf("####### [%d] Frames, %f FPS", mFrameCount, mFps); 562 } 563} 564 565/** Callback for startPreview() */ 566void my_preview_callback(const sp<IMemory>& mem) { 567 568 printf("PREVIEW Callback 0x%x", ( unsigned int ) mem->pointer()); 569 if (dump_preview) { 570 571 if(prevcnt==50) 572 saveFile(mem); 573 574 prevcnt++; 575 576 uint8_t *ptr = (uint8_t*) mem->pointer(); 577 578 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]); 579 580 } 581 582 debugShowFPS(); 583} 584 585/** Callback for takePicture() */ 586void my_jpeg_callback(const sp<IMemory>& mem) { 587 static int counter = 1; 588 unsigned char *buff = NULL; 589 int size; 590 int fd = -1; 591 char fn[256]; 592 593 LOG_FUNCTION_NAME; 594 595 //Start preview after capture. 596 camera->startPreview(); 597 598 if (mem == NULL) 599 goto out; 600 601 fn[0] = 0; 602 sprintf(fn, "%s/img%03d.jpg", dir_path,counter); 603 fd = open(fn, O_CREAT | O_WRONLY | O_TRUNC, 0777); 604 605 if(fd < 0) { 606 ALOGE("Unable to open file %s: %s", fn, strerror(fd)); 607 goto out; 608 } 609 610 size = mem->size(); 611 if (size <= 0) { 612 ALOGE("IMemory object is of zero size"); 613 goto out; 614 } 615 616 buff = (unsigned char *)mem->pointer(); 617 if (!buff) { 618 ALOGE("Buffer pointer is invalid"); 619 goto out; 620 } 621 622 if (size != write(fd, buff, size)) 623 printf("Bad Write int a %s error (%d)%s\n", fn, errno, strerror(errno)); 624 625 counter++; 626 printf("%s: buffer=%08X, size=%d stored at %s\n", 627 __FUNCTION__, (int)buff, size, fn); 628 629out: 630 631 if (fd >= 0) 632 close(fd); 633 634 LOG_FUNCTION_NAME_EXIT; 635} 636 637void my_face_callback(camera_frame_metadata_t *metadata) { 638 int idx; 639 640 if ( NULL == metadata ) { 641 return; 642 } 643 644 for ( idx = 0 ; idx < metadata->number_of_faces ; idx++ ) { 645 printf("Face %d at %d,%d %d,%d \n", 646 idx, 647 metadata->faces[idx].rect[0], 648 metadata->faces[idx].rect[1], 649 metadata->faces[idx].rect[2], 650 metadata->faces[idx].rect[3]); 651 } 652 653} 654 655void CameraHandler::notify(int32_t msgType, int32_t ext1, int32_t ext2) { 656 657 printf("Notify cb: %d %d %d\n", msgType, ext1, ext2); 658 659 if ( msgType & CAMERA_MSG_FOCUS ) 660 printf("AutoFocus %s in %llu us\n", (ext1) ? "OK" : "FAIL", timeval_delay(&autofocus_start)); 661 662 if ( msgType & CAMERA_MSG_SHUTTER ) 663 printf("Shutter done in %llu us\n", timeval_delay(&picture_start)); 664 665 if ( msgType & CAMERA_MSG_ERROR && (ext1 == 1)) 666 { 667 printf("Camera Test CAMERA_MSG_ERROR.....\n"); 668 if (stressTest) 669 { 670 printf("Camera Test Notified of Error Restarting.....\n"); 671 stopScript = true; 672 } 673 else 674 { 675 printf("Camera Test Notified of Error Stopping.....\n"); 676 stopScript =false; 677 stopPreview(); 678 679 if (recordingMode) 680 { 681 stopRecording(); 682 closeRecorder(); 683 recordingMode = false; 684 } 685 } 686 } 687} 688 689void CameraHandler::postData(int32_t msgType, 690 const sp<IMemory>& dataPtr, 691 camera_frame_metadata_t *metadata) { 692 printf("Data cb: %d\n", msgType); 693 694 if ( msgType & CAMERA_MSG_PREVIEW_FRAME ) 695 my_preview_callback(dataPtr); 696 697 if ( msgType & CAMERA_MSG_RAW_IMAGE ) { 698 printf("RAW done in %llu us\n", timeval_delay(&picture_start)); 699 my_raw_callback(dataPtr); 700 } 701 702 if (msgType & CAMERA_MSG_POSTVIEW_FRAME) { 703 printf("Postview frame %llu us\n", timeval_delay(&picture_start)); 704 } 705 706 if (msgType & CAMERA_MSG_COMPRESSED_IMAGE ) { 707 printf("JPEG done in %llu us\n", timeval_delay(&picture_start)); 708 my_jpeg_callback(dataPtr); 709 } 710 711 if ( ( msgType & CAMERA_MSG_PREVIEW_METADATA ) && 712 ( NULL != metadata ) ) { 713 printf("Face detected %d \n", metadata->number_of_faces); 714 my_face_callback(metadata); 715 } 716} 717 718void CameraHandler::postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) 719 720{ 721 printf("Recording cb: %d %lld %p\n", msgType, timestamp, dataPtr.get()); 722 723 static uint32_t count = 0; 724 725 //if(count==100) 726 //saveFile(dataPtr); 727 728 count++; 729 730 uint8_t *ptr = (uint8_t*) dataPtr->pointer(); 731 732 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]); 733 734 camera->releaseRecordingFrame(dataPtr); 735} 736 737int createPreviewSurface(unsigned int width, unsigned int height, int32_t pixFormat) { 738 unsigned int previewWidth, previewHeight; 739 740 if ( MAX_PREVIEW_SURFACE_WIDTH < width ) { 741 previewWidth = MAX_PREVIEW_SURFACE_WIDTH; 742 } else { 743 previewWidth = width; 744 } 745 746 if ( MAX_PREVIEW_SURFACE_HEIGHT < height ) { 747 previewHeight = MAX_PREVIEW_SURFACE_HEIGHT; 748 } else { 749 previewHeight = height; 750 } 751 752 client = new SurfaceComposerClient(); 753 754 if ( NULL == client.get() ) { 755 printf("Unable to establish connection to Surface Composer \n"); 756 757 return -1; 758 } 759 760 surfaceControl = client->createSurface(0, 761 previewWidth, 762 previewHeight, 763 pixFormat); 764 765 previewSurface = surfaceControl->getSurface(); 766 767 client->openGlobalTransaction(); 768 surfaceControl->setLayer(0x7fffffff); 769 surfaceControl->setPosition(0, 0); 770 surfaceControl->setSize(previewWidth, previewHeight); 771 surfaceControl->show(); 772 client->closeGlobalTransaction(); 773 774 return 0; 775} 776 777void printSupportedParams() 778{ 779 printf("\n\r\tSupported Cameras: %s", params.get("camera-indexes")); 780 printf("\n\r\tSupported Picture Sizes: %s", params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES)); 781 printf("\n\r\tSupported Picture Formats: %s", params.get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS)); 782 printf("\n\r\tSupported Preview Sizes: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); 783 printf("\n\r\tSupported Preview Formats: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS)); 784 printf("\n\r\tSupported Preview Frame Rates: %s", params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES)); 785 printf("\n\r\tSupported Thumbnail Sizes: %s", params.get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES)); 786 printf("\n\r\tSupported Whitebalance Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE)); 787 printf("\n\r\tSupported Effects: %s", params.get(CameraParameters::KEY_SUPPORTED_EFFECTS)); 788 printf("\n\r\tSupported Scene Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES)); 789 printf("\n\r\tSupported Focus Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES)); 790 printf("\n\r\tSupported Antibanding Options: %s", params.get(CameraParameters::KEY_SUPPORTED_ANTIBANDING)); 791 printf("\n\r\tSupported Flash Modes: %s", params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES)); 792 printf("\n\r\tSupported Focus Areas: %d", params.getInt(CameraParameters::KEY_MAX_NUM_FOCUS_AREAS)); 793 794 if ( NULL != params.get(CameraParameters::KEY_FOCUS_DISTANCES) ) { 795 printf("\n\r\tFocus Distances: %s \n", params.get(CameraParameters::KEY_FOCUS_DISTANCES)); 796 } 797 798 return; 799} 800 801 802int destroyPreviewSurface() { 803 804 if ( NULL != previewSurface.get() ) { 805 previewSurface.clear(); 806 } 807 808 if ( NULL != surfaceControl.get() ) { 809 surfaceControl->clear(); 810 surfaceControl.clear(); 811 } 812 813 if ( NULL != client.get() ) { 814 client->dispose(); 815 client.clear(); 816 } 817 818 return 0; 819} 820 821int openRecorder() { 822 recorder = new MediaRecorder(); 823 824 if ( NULL == recorder.get() ) { 825 printf("Error while creating MediaRecorder\n"); 826 827 return -1; 828 } 829 830 return 0; 831} 832 833int closeRecorder() { 834 if ( NULL == recorder.get() ) { 835 printf("invalid recorder reference\n"); 836 837 return -1; 838 } 839 840 if ( recorder->init() < 0 ) { 841 printf("recorder failed to initialize\n"); 842 843 return -1; 844 } 845 846 if ( recorder->close() < 0 ) { 847 printf("recorder failed to close\n"); 848 849 return -1; 850 } 851 852 if ( recorder->release() < 0 ) { 853 printf("error while releasing recorder\n"); 854 855 return -1; 856 } 857 858 recorder.clear(); 859 860 return 0; 861} 862 863int configureRecorder() { 864 865 char videoFile[256],vbit_string[50]; 866 videoFd = -1; 867 868 if ( ( NULL == recorder.get() ) || ( NULL == camera.get() ) ) { 869 printf("invalid recorder and/or camera references\n"); 870 871 return -1; 872 } 873 874 camera->unlock(); 875 876 sprintf(vbit_string,"video-param-encoding-bitrate=%u", VbitRate[VbitRateIDX].bit_rate); 877 String8 bit_rate(vbit_string); 878 if ( recorder->setParameters(bit_rate) < 0 ) { 879 printf("error while configuring bit rate\n"); 880 881 return -1; 882 } 883 884 if ( recorder->setCamera(camera->remote(), camera->getRecordingProxy()) < 0 ) { 885 printf("error while setting the camera\n"); 886 887 return -1; 888 } 889 890 if ( recorder->setVideoSource(VIDEO_SOURCE_CAMERA) < 0 ) { 891 printf("error while configuring camera video source\n"); 892 893 return -1; 894 } 895 896 897 if ( AUDIO_ENCODER_LIST_END != audioCodecs[audioCodecIDX].type ) { 898 if ( recorder->setAudioSource(AUDIO_SOURCE_DEFAULT) < 0 ) { 899 printf("error while configuring camera audio source\n"); 900 901 return -1; 902 } 903 } 904 905 if ( recorder->setOutputFormat(outputFormat[outputFormatIDX].type) < 0 ) { 906 printf("error while configuring output format\n"); 907 908 return -1; 909 } 910 911 if(mkdir("/mnt/sdcard/videos",0777) == -1) 912 printf("\n Directory --videos-- was not created \n"); 913 sprintf(videoFile, "/mnt/sdcard/videos/video%d.%s", recording_counter,outputFormat[outputFormatIDX].desc); 914 915 videoFd = open(videoFile, O_CREAT | O_RDWR); 916 917 if(videoFd < 0){ 918 printf("Error while creating video filename\n"); 919 920 return -1; 921 } 922 923 if ( recorder->setOutputFile(videoFd, 0, 0) < 0 ) { 924 printf("error while configuring video filename\n"); 925 926 return -1; 927 } 928 929 recording_counter++; 930 931 if (camera_index == 0) { 932 if ( recorder->setVideoFrameRate(fpsConstRanges[frameRateIDX].constFramerate) < 0 ) { 933 printf("error while configuring video framerate\n"); 934 return -1; 935 } 936 } 937 else { 938 if ( recorder->setVideoFrameRate(fpsConstRangesSec[frameRateIDXSec].constFramerate) < 0 ) { 939 printf("error while configuring video framerate\n"); 940 return -1; 941 } 942 } 943 944 if ( recorder->setVideoSize(VcaptureSize[VcaptureSizeIDX].width, VcaptureSize[VcaptureSizeIDX].height) < 0 ) { 945 printf("error while configuring video size\n"); 946 947 return -1; 948 } 949 950 if ( recorder->setVideoEncoder(videoCodecs[videoCodecIDX].type) < 0 ) { 951 printf("error while configuring video codec\n"); 952 953 return -1; 954 } 955 956 if ( AUDIO_ENCODER_LIST_END != audioCodecs[audioCodecIDX].type ) { 957 if ( recorder->setAudioEncoder(audioCodecs[audioCodecIDX].type) < 0 ) { 958 printf("error while configuring audio codec\n"); 959 960 return -1; 961 } 962 } 963 964 if ( recorder->setPreviewSurface( surfaceControl->getSurface() ) < 0 ) { 965 printf("error while configuring preview surface\n"); 966 967 return -1; 968 } 969 970 return 0; 971} 972 973int startRecording() { 974 if ( ( NULL == recorder.get() ) || ( NULL == camera.get() ) ) { 975 printf("invalid recorder and/or camera references\n"); 976 977 return -1; 978 } 979 980 camera->unlock(); 981 982 if ( recorder->prepare() < 0 ) { 983 printf("recorder prepare failed\n"); 984 985 return -1; 986 } 987 988 if ( recorder->start() < 0 ) { 989 printf("recorder start failed\n"); 990 991 return -1; 992 } 993 994 return 0; 995} 996 997int stopRecording() { 998 if ( NULL == recorder.get() ) { 999 printf("invalid recorder reference\n"); 1000 1001 return -1; 1002 } 1003 1004 if ( recorder->stop() < 0 ) { 1005 printf("recorder failed to stop\n"); 1006 1007 return -1; 1008 } 1009 1010 if ( 0 < videoFd ) { 1011 close(videoFd); 1012 } 1013 1014 return 0; 1015} 1016 1017int openCamera() { 1018 printf("openCamera(camera_index=%d)\n", camera_index); 1019 camera = Camera::connect(camera_index); 1020 1021 if ( NULL == camera.get() ) { 1022 printf("Unable to connect to CameraService\n"); 1023 printf("Retrying... \n"); 1024 sleep(1); 1025 camera = Camera::connect(camera_index); 1026 1027 if ( NULL == camera.get() ) { 1028 printf("Giving up!! \n"); 1029 return -1; 1030 } 1031 } 1032 1033 params = camera->getParameters(); 1034 camera->setParameters(params.flatten()); 1035 1036 camera->setListener(new CameraHandler()); 1037 1038 hardwareActive = true; 1039 1040 return 0; 1041} 1042 1043int closeCamera() { 1044 if ( NULL == camera.get() ) { 1045 printf("invalid camera reference\n"); 1046 1047 return -1; 1048 } 1049 1050 camera->disconnect(); 1051 camera.clear(); 1052 1053 hardwareActive = false; 1054 1055 return 0; 1056} 1057 1058int startPreview() { 1059 int previewWidth, previewHeight; 1060 if (reSizePreview) { 1061 1062 if(recordingMode) 1063 { 1064 previewWidth = VcaptureSize[VcaptureSizeIDX].width; 1065 previewHeight = VcaptureSize[VcaptureSizeIDX].height; 1066 }else 1067 { 1068 previewWidth = previewSize[previewSizeIDX].width; 1069 previewHeight = previewSize[previewSizeIDX].height; 1070 } 1071 1072 if ( createPreviewSurface(previewWidth, 1073 previewHeight, 1074 pixelformat[previewFormat].pixelFormatDesc) < 0 ) { 1075 printf("Error while creating preview surface\n"); 1076 return -1; 1077 } 1078 1079 if ( !hardwareActive ) { 1080 openCamera(); 1081 } 1082 1083 params.setPreviewSize(previewWidth, previewHeight); 1084 params.setPictureSize(captureSize[captureSizeIDX].width, captureSize[captureSizeIDX].height); 1085 1086 camera->setParameters(params.flatten()); 1087 camera->setPreviewDisplay(previewSurface); 1088 1089 if(!hardwareActive) prevcnt = 0; 1090 1091 camera->startPreview(); 1092 1093 previewRunning = true; 1094 reSizePreview = false; 1095 1096 } 1097 1098 return 0; 1099} 1100 1101void stopPreview() { 1102 if ( hardwareActive ) { 1103 camera->stopPreview(); 1104 1105 destroyPreviewSurface(); 1106 1107 previewRunning = false; 1108 reSizePreview = true; 1109 closeCamera(); 1110 } 1111} 1112 1113void initDefaults() { 1114 camera_index = 0; 1115 antibanding_mode = 0; 1116 focus_mode = 0; 1117 fpsRangeIdx = 0; 1118 previewSizeIDX = 1; /* Default resolution set to WVGA */ 1119 captureSizeIDX = 3; /* Default capture resolution is 8MP */ 1120 frameRateIDX = ARRAY_SIZE(fpsConstRanges) - 1; /* Default frame rate is 30 FPS */ 1121#if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 1122 VcaptureSizeIDX = ARRAY_SIZE(VcaptureSize) - 6;/* Default video record is WVGA */ 1123#else 1124 VcaptureSizeIDX = ARRAY_SIZE(VcaptureSize) - 2;/* Default video record is WVGA */ 1125#endif 1126 VbitRateIDX = ARRAY_SIZE(VbitRate) - 4; /*Default video bit rate is 4M */ 1127 thumbSizeIDX = 0; 1128 compensation = 0.0; 1129 awb_mode = 0; 1130 effects_mode = 0; 1131 scene_mode = 0; 1132 caf_mode = 0; 1133 vnf_mode = 0; 1134 vstab_mode = 0; 1135 expBracketIdx = 0; 1136 flashIdx = 0; 1137 rotation = 0; 1138 zoomIDX = 0; 1139 videoCodecIDX = 0; 1140 gbceIDX = 0; 1141 glbceIDX = 0; 1142#ifdef TARGET_OMAP4 1143 ///Temporary fix until OMAP3 and OMAP4 3A values are synced 1144 contrast = 90; 1145 brightness = 50; 1146 sharpness = 0; 1147 saturation = 50; 1148#else 1149 contrast = 100; 1150 brightness = 100; 1151 sharpness = 0; 1152 saturation = 100; 1153#endif 1154 iso_mode = 0; 1155 capture_mode = 0; 1156 exposure_mode = 0; 1157 ippIDX = 0;//set the ipp to ldc-nsf as the capture mode is set to HQ by default 1158 ippIDX_old = ippIDX; 1159 jpegQuality = 85; 1160 bufferStarvationTest = 0; 1161 meter_mode = 0; 1162 previewFormat = 1; 1163 pictureFormat = 3; // jpeg 1164 params.setPreviewSize(previewSize[previewSizeIDX].width, previewSize[previewSizeIDX].height); 1165 params.setPictureSize(captureSize[captureSizeIDX].width, captureSize[captureSizeIDX].height); 1166 params.set(CameraParameters::KEY_ROTATION, rotation); 1167 params.set(KEY_COMPENSATION, (int) (compensation * 10)); 1168 params.set(params.KEY_WHITE_BALANCE, strawb_mode[awb_mode]); 1169 params.set(KEY_MODE, (capture[capture_mode])); 1170 params.set(params.KEY_SCENE_MODE, scene[scene_mode]); 1171 params.set(KEY_CAF, caf_mode); 1172 params.set(KEY_ISO, iso_mode); 1173 params.set(KEY_GBCE, gbce[gbceIDX]); 1174 params.set(KEY_GLBCE, gbce[glbceIDX]); 1175 params.set(KEY_SHARPNESS, sharpness); 1176 params.set(KEY_CONTRAST, contrast); 1177 params.set(CameraParameters::KEY_ZOOM, zoom[zoomIDX].idx); 1178 params.set(KEY_EXPOSURE, exposure[exposure_mode]); 1179 params.set(KEY_BRIGHTNESS, brightness); 1180 params.set(KEY_SATURATION, saturation); 1181 params.set(params.KEY_EFFECT, effects[effects_mode]); 1182 params.setPreviewFrameRate(frameRate[ARRAY_SIZE(frameRate) - 1].fps); 1183 params.set(params.KEY_ANTIBANDING, antibanding[antibanding_mode]); 1184 params.set(params.KEY_FOCUS_MODE, focus[focus_mode]); 1185 params.set(KEY_IPP, ipp_mode[ippIDX]); 1186 params.set(CameraParameters::KEY_JPEG_QUALITY, jpegQuality); 1187 params.setPreviewFormat(pixelformat[previewFormat].pixformat); 1188 params.setPictureFormat(codingformat[pictureFormat]); 1189 params.set(KEY_BUFF_STARV, bufferStarvationTest); //enable buffer starvation 1190 params.set(KEY_METERING_MODE, metering[meter_mode]); 1191 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, previewSize[thumbSizeIDX].width); 1192 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, previewSize[thumbSizeIDX].height); 1193 ManualConvergenceValuesIDX = ManualConvergenceDefaultValueIDX; 1194 params.set(KEY_MANUALCONVERGENCE_VALUES, manualconvergencevalues[ManualConvergenceValuesIDX]); 1195 params.set(KEY_S3D2D_PREVIEW_MODE, "off"); 1196 params.set(KEY_STEREO_CAMERA, "false"); 1197 params.set(KEY_EXIF_MODEL, MODEL); 1198 params.set(KEY_EXIF_MAKE, MAKE); 1199} 1200 1201int menu_gps() { 1202 char ch; 1203 char coord_str[100]; 1204 1205 if (print_menu) { 1206 printf("\n\n== GPS MENU ============================\n\n"); 1207 printf(" e. Latitude: %.7lf\n", latitude); 1208 printf(" d. Longitude: %.7lf\n", longitude); 1209 printf(" c. Altitude: %.7lf\n", altitude); 1210 printf("\n"); 1211 printf(" q. Return to main menu\n"); 1212 printf("\n"); 1213 printf(" Choice: "); 1214 } 1215 1216 ch = getchar(); 1217 printf("%c", ch); 1218 1219 print_menu = 1; 1220 1221 switch (ch) { 1222 1223 case 'e': 1224 latitude += degree_by_step; 1225 1226 if (latitude > 90.0) { 1227 latitude -= 180.0; 1228 } 1229 1230 snprintf(coord_str, 7, "%.7lf", latitude); 1231 params.set(params.KEY_GPS_LATITUDE, coord_str); 1232 1233 if ( hardwareActive ) 1234 camera->setParameters(params.flatten()); 1235 1236 break; 1237 1238 case 'd': 1239 longitude += degree_by_step; 1240 1241 if (longitude > 180.0) { 1242 longitude -= 360.0; 1243 } 1244 1245 snprintf(coord_str, 7, "%.7lf", longitude); 1246 params.set(params.KEY_GPS_LONGITUDE, coord_str); 1247 1248 if ( hardwareActive ) 1249 camera->setParameters(params.flatten()); 1250 1251 break; 1252 1253 case 'c': 1254 altitude += 12345.67890123456789; 1255 1256 if (altitude > 100000.0) { 1257 altitude -= 200000.0; 1258 } 1259 1260 snprintf(coord_str, 100, "%.20lf", altitude); 1261 params.set(params.KEY_GPS_ALTITUDE, coord_str); 1262 1263 if ( hardwareActive ) 1264 camera->setParameters(params.flatten()); 1265 1266 break; 1267 1268 case 'Q': 1269 case 'q': 1270 return -1; 1271 1272 default: 1273 print_menu = 0; 1274 break; 1275 } 1276 1277 return 0; 1278} 1279 1280int functional_menu() { 1281 char ch; 1282 1283 if (print_menu) { 1284 1285 printf("\n\n=========== FUNCTIONAL TEST MENU ===================\n\n"); 1286 1287 printf(" \n\nSTART / STOP / GENERAL SERVICES \n"); 1288 printf(" -----------------------------\n"); 1289 printf(" A Select Camera %s\n", cameras[camera_index]); 1290 printf(" [. Resume Preview after capture\n"); 1291 printf(" 0. Reset to defaults\n"); 1292 printf(" q. Quit\n"); 1293 printf(" @. Disconnect and Reconnect to CameraService \n"); 1294 printf(" /. Enable/Disable showfps: %s\n", ((showfps)? "Enabled":"Disabled")); 1295 printf(" a. GEO tagging settings menu\n"); 1296 printf(" E. Camera Capability Dump"); 1297 1298 1299 printf(" \n\n PREVIEW SUB MENU \n"); 1300 printf(" -----------------------------\n"); 1301 printf(" 1. Start Preview\n"); 1302 printf(" 2. Stop Preview\n"); 1303 printf(" ~. Preview format %s\n", pixelformat[previewFormat].pixformat); 1304#if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3) 1305 printf(" 4. Preview size: %4d x %4d - %s\n",previewSize[previewSizeIDX].width, previewSize[previewSizeIDX].height, previewSize[previewSizeIDX].desc); 1306#else 1307 printf(" 4. Preview size: %4d x %4d - %s\n",previewSize[previewSizeIDX].width, camera_index == 2 ? previewSize[previewSizeIDX].height*2 : previewSize[previewSizeIDX].height, previewSize[previewSizeIDX].desc); 1308#endif 1309 printf(" R. Preview framerate range: %s\n", fpsRanges[fpsRangeIdx].rangeDescription); 1310 printf(" &. Dump a preview frame\n"); 1311 printf(" _. Auto Convergence mode: %s\n", autoconvergencemode[AutoConvergenceModeIDX]); 1312 printf(" ^. Manual Convergence Value: %s\n", manualconvergencevalues[ManualConvergenceValuesIDX]); 1313 printf(" {. 2D Preview in 3D Stereo Mode: %s\n", params.get(KEY_S3D2D_PREVIEW_MODE)); 1314 1315 printf(" \n\n IMAGE CAPTURE SUB MENU \n"); 1316 printf(" -----------------------------\n"); 1317 printf(" p. Take picture/Full Press\n"); 1318 printf(" H. Exposure Bracketing: %s\n", expBracketing[expBracketIdx]); 1319 printf(" U. Temporal Bracketing: %s\n", tempBracketing[tempBracketIdx]); 1320 printf(" W. Temporal Bracketing Range: [-%d;+%d]\n", tempBracketRange, tempBracketRange); 1321 printf(" $. Picture Format: %s\n", codingformat[pictureFormat]); 1322 printf(" 3. Picture Rotation: %3d degree\n", rotation ); 1323 printf(" 5. Picture size: %4d x %4d - %s\n",captureSize[captureSizeIDX].width, captureSize[captureSizeIDX].height, captureSize[captureSizeIDX].name); 1324 printf(" i. ISO mode: %s\n", iso[iso_mode]); 1325 printf(" u. Capture Mode: %s\n", capture[capture_mode]); 1326 printf(" k. IPP Mode: %s\n", ipp_mode[ippIDX]); 1327 printf(" K. GBCE: %s\n", gbce[gbceIDX]); 1328 printf(" O. GLBCE %s\n", gbce[glbceIDX]); 1329 printf(" o. Jpeg Quality: %d\n", jpegQuality); 1330 printf(" #. Burst Images: %3d\n", burst); 1331 printf(" :. Thumbnail Size: %4d x %4d - %s\n",previewSize[thumbSizeIDX].width, previewSize[thumbSizeIDX].height, previewSize[thumbSizeIDX].desc); 1332 printf(" ': Thumbnail Quality %d\n", thumbQuality); 1333 1334 printf(" \n\n VIDEO CAPTURE SUB MENU \n"); 1335 printf(" -----------------------------\n"); 1336 1337 printf(" 6. Start Video Recording\n"); 1338 printf(" 2. Stop Recording\n"); 1339 printf(" l. Video Capture resolution: %4d x %4d - %s\n",VcaptureSize[VcaptureSizeIDX].width,VcaptureSize[VcaptureSizeIDX].height, VcaptureSize[VcaptureSizeIDX].desc); 1340 printf(" ]. Video Bit rate : %s\n", VbitRate[VbitRateIDX].desc); 1341 printf(" 9. Video Codec: %s\n", videoCodecs[videoCodecIDX].desc); 1342 printf(" D. Audio Codec: %s\n", audioCodecs[audioCodecIDX].desc); 1343 printf(" v. Output Format: %s\n", outputFormat[outputFormatIDX].desc); 1344 1345 if (camera_index == 1) { 1346 printf(" r. Framerate: %d\n", fpsConstRangesSec[frameRateIDXSec].constFramerate); 1347 } 1348 else { 1349 printf(" r. Framerate: %d\n", fpsConstRanges[frameRateIDX].constFramerate); 1350 } 1351 printf(" *. Start Video Recording dump ( 1 raw frame ) \n"); 1352 printf(" B VNF %s \n", vnf[vnf_mode]); 1353 printf(" C VSTAB %s", vstab[vstab_mode]); 1354 1355 printf(" \n\n 3A SETTING SUB MENU \n"); 1356 printf(" -----------------------------\n"); 1357 1358 printf(" M. Measurement Data: %s\n", measurement[measurementIdx]); 1359 printf(" F. Start face detection \n"); 1360 printf(" T. Stop face detection \n"); 1361 printf(" G. Touch/Focus area AF\n"); 1362 printf(" f. Auto Focus/Half Press\n"); 1363 printf(" J.Flash: %s\n", flashModes[flashIdx]); 1364 printf(" 7. EV offset: %4.1f\n", compensation); 1365 printf(" 8. AWB mode: %s\n", strawb_mode[awb_mode]); 1366 printf(" z. Zoom %s\n", zoom[zoomIDX].zoom_description); 1367 printf(" j. Exposure %s\n", exposure[exposure_mode]); 1368 printf(" e. Effect: %s\n", effects[effects_mode]); 1369 printf(" w. Scene: %s\n", scene[scene_mode]); 1370 printf(" s. Saturation: %d\n", saturation); 1371 printf(" c. Contrast: %d\n", contrast); 1372 printf(" h. Sharpness: %d\n", sharpness); 1373 printf(" b. Brightness: %d\n", brightness); 1374 printf(" x. Antibanding: %s\n", antibanding[antibanding_mode]); 1375 printf(" g. Focus mode: %s\n", focus[focus_mode]); 1376 printf(" m. Metering mode: %s\n" , metering[meter_mode]); 1377 printf(" <. Exposure Lock: %s\n", lock[elockidx]); 1378 printf(" >. WhiteBalance Lock: %s\n",lock[wblockidx]); 1379 printf("\n"); 1380 printf(" Choice: "); 1381 } 1382 1383 ch = getchar(); 1384 printf("%c", ch); 1385 1386 print_menu = 1; 1387 1388 switch (ch) { 1389 1390 case '_': 1391 AutoConvergenceModeIDX++; 1392 AutoConvergenceModeIDX %= ARRAY_SIZE(autoconvergencemode); 1393 params.set(KEY_AUTOCONVERGENCE, autoconvergencemode[AutoConvergenceModeIDX]); 1394 if ( strcmp (autoconvergencemode[AutoConvergenceModeIDX], AUTOCONVERGENCE_MODE_MANUAL) == 0) { 1395 params.set(KEY_MANUALCONVERGENCE_VALUES, manualconvergencevalues[ManualConvergenceValuesIDX]); 1396 } 1397 else { 1398 params.set(KEY_MANUALCONVERGENCE_VALUES, manualconvergencevalues[ManualConvergenceDefaultValueIDX]); 1399 ManualConvergenceValuesIDX = ManualConvergenceDefaultValueIDX; 1400 } 1401 camera->setParameters(params.flatten()); 1402 1403 break; 1404 case '^': 1405 if ( strcmp (autoconvergencemode[AutoConvergenceModeIDX], AUTOCONVERGENCE_MODE_MANUAL) == 0) { 1406 ManualConvergenceValuesIDX++; 1407 ManualConvergenceValuesIDX %= ARRAY_SIZE(manualconvergencevalues); 1408 params.set(KEY_MANUALCONVERGENCE_VALUES, manualconvergencevalues[ManualConvergenceValuesIDX]); 1409 camera->setParameters(params.flatten()); 1410 } 1411 break; 1412 case 'A': 1413 camera_index++; 1414 camera_index %= ARRAY_SIZE(cameras); 1415 if ( camera_index == 2) { 1416 params.set(KEY_STEREO_CAMERA, "true"); 1417 } else { 1418 params.set(KEY_STEREO_CAMERA, "false"); 1419 } 1420 closeCamera(); 1421 1422 openCamera(); 1423 1424 if (camera_index == 0) { 1425 params.setPreviewFrameRate(30); 1426 } else { 1427 params.setPreviewFrameRate(27); 1428 } 1429 1430 1431 break; 1432 case '[': 1433 if ( hardwareActive ) { 1434 camera->setParameters(params.flatten()); 1435 camera->startPreview(); 1436 } 1437 break; 1438 1439 case '0': 1440 initDefaults(); 1441 break; 1442 1443 case '1': 1444 1445 if ( startPreview() < 0 ) { 1446 printf("Error while starting preview\n"); 1447 1448 return -1; 1449 } 1450 1451 break; 1452 1453 case '2': 1454 stopPreview(); 1455 1456 if ( recordingMode ) { 1457 camera->disconnect(); 1458 camera.clear(); 1459 stopRecording(); 1460 closeRecorder(); 1461 1462 camera = Camera::connect(camera_index); 1463 if ( NULL == camera.get() ) { 1464 sleep(1); 1465 camera = Camera::connect(camera_index); 1466 if ( NULL == camera.get() ) { 1467 return -1; 1468 } 1469 } 1470 camera->setListener(new CameraHandler()); 1471 camera->setParameters(params.flatten()); 1472 recordingMode = false; 1473 } 1474 1475 break; 1476 1477 case '3': 1478 rotation += 90; 1479 rotation %= 360; 1480 params.set(CameraParameters::KEY_ROTATION, rotation); 1481 if ( hardwareActive ) 1482 camera->setParameters(params.flatten()); 1483 1484 break; 1485 1486 case '4': 1487 previewSizeIDX += 1; 1488 previewSizeIDX %= ARRAY_SIZE(previewSize); 1489 if ( NULL != params.get(KEY_STEREO_CAMERA) ) { 1490 if ( strcmp(params.get(KEY_STEREO_CAMERA), "false") == 0 ) { 1491 params.setPreviewSize(previewSize[previewSizeIDX].width, previewSize[previewSizeIDX].height); 1492 } else { 1493 params.setPreviewSize(previewSize[previewSizeIDX].width, previewSize[previewSizeIDX].height*2); 1494 } 1495 } 1496 reSizePreview = true; 1497 1498 if ( hardwareActive && previewRunning ) { 1499 camera->stopPreview(); 1500 camera->setParameters(params.flatten()); 1501 camera->startPreview(); 1502 } else if ( hardwareActive ) { 1503 camera->setParameters(params.flatten()); 1504 } 1505 1506 break; 1507 1508 case '5': 1509 captureSizeIDX += 1; 1510 captureSizeIDX %= ARRAY_SIZE(captureSize); 1511 params.setPictureSize(captureSize[captureSizeIDX].width, captureSize[captureSizeIDX].height); 1512 1513 if ( hardwareActive ) 1514 camera->setParameters(params.flatten()); 1515 break; 1516 1517 case 'l': 1518 case 'L': 1519 VcaptureSizeIDX++; 1520 VcaptureSizeIDX %= ARRAY_SIZE(VcaptureSize); 1521 break; 1522 1523 case ']': 1524 VbitRateIDX++; 1525 VbitRateIDX %= ARRAY_SIZE(VbitRate); 1526 break; 1527 1528 1529 case '6': 1530 1531 if ( !recordingMode ) { 1532 1533 recordingMode = true; 1534 1535 if ( startPreview() < 0 ) { 1536 printf("Error while starting preview\n"); 1537 1538 return -1; 1539 } 1540 1541 if ( openRecorder() < 0 ) { 1542 printf("Error while openning video recorder\n"); 1543 1544 return -1; 1545 } 1546 1547 if ( configureRecorder() < 0 ) { 1548 printf("Error while configuring video recorder\n"); 1549 1550 return -1; 1551 } 1552 1553 if ( startRecording() < 0 ) { 1554 printf("Error while starting video recording\n"); 1555 1556 return -1; 1557 } 1558 } 1559 1560 break; 1561 1562 case '7': 1563 1564 if ( compensation > 2.0) { 1565 compensation = -2.0; 1566 } else { 1567 compensation += 0.1; 1568 } 1569 1570 params.set(KEY_COMPENSATION, (int) (compensation * 10)); 1571 1572 if ( hardwareActive ) 1573 camera->setParameters(params.flatten()); 1574 1575 break; 1576 1577 case '8': 1578 awb_mode++; 1579 awb_mode %= ARRAY_SIZE(strawb_mode); 1580 params.set(params.KEY_WHITE_BALANCE, strawb_mode[awb_mode]); 1581 1582 if ( hardwareActive ) 1583 camera->setParameters(params.flatten()); 1584 1585 break; 1586 1587 case '9': 1588 videoCodecIDX++; 1589 videoCodecIDX %= ARRAY_SIZE(videoCodecs); 1590 break; 1591 case '~': 1592 previewFormat += 1; 1593 previewFormat %= ARRAY_SIZE(pixelformat) - 1; 1594 params.setPreviewFormat(pixelformat[previewFormat].pixformat); 1595 1596 if ( hardwareActive ) 1597 camera->setParameters(params.flatten()); 1598 1599 break; 1600 case '$': 1601 pictureFormat += 1; 1602 if ( NULL != params.get(KEY_STEREO_CAMERA) ) { 1603 if ( strcmp(params.get(KEY_STEREO_CAMERA), "false") == 0 && pictureFormat > 4 ) 1604 pictureFormat = 0; 1605 } 1606 pictureFormat %= ARRAY_SIZE(codingformat); 1607 params.setPictureFormat(codingformat[pictureFormat]); 1608 if ( hardwareActive ) 1609 camera->setParameters(params.flatten()); 1610 1611 break; 1612 1613 case '?' : 1614 ///Set mode=3 to select video mode 1615 params.set(KEY_MODE, 3); 1616 params.set(KEY_VNF, 1); 1617 params.set(KEY_VSTAB, 1); 1618 break; 1619 1620 case ':': 1621 thumbSizeIDX += 1; 1622 thumbSizeIDX %= ARRAY_SIZE(previewSize); 1623 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, previewSize[thumbSizeIDX].width); 1624 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, previewSize[thumbSizeIDX].height); 1625 1626 if ( hardwareActive ) 1627 camera->setParameters(params.flatten()); 1628 1629 break; 1630 1631 case '\'': 1632 if ( thumbQuality >= 100) { 1633 thumbQuality = 0; 1634 } else { 1635 thumbQuality += 5; 1636 } 1637 1638 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, thumbQuality); 1639 if ( hardwareActive ) 1640 camera->setParameters(params.flatten()); 1641 break; 1642 1643 case 'B' : 1644 vnf_mode++; 1645 vnf_mode %= ARRAY_SIZE(vnf); 1646 params.set(KEY_VNF, vnf_mode); 1647 1648 if ( hardwareActive ) 1649 camera->setParameters(params.flatten()); 1650 break; 1651 1652 case 'C' : 1653 vstab_mode++; 1654 vstab_mode %= ARRAY_SIZE(vstab); 1655 params.set(KEY_VSTAB, vstab_mode); 1656 1657 if ( hardwareActive ) 1658 camera->setParameters(params.flatten()); 1659 break; 1660 1661 case 'E': 1662 if(hardwareActive) 1663 params.unflatten(camera->getParameters()); 1664 printSupportedParams(); 1665 break; 1666 1667 case '*': 1668 if ( hardwareActive ) 1669 camera->startRecording(); 1670 break; 1671 1672 case 'o': 1673 if ( jpegQuality >= 100) { 1674 jpegQuality = 0; 1675 } else { 1676 jpegQuality += 5; 1677 } 1678 1679 params.set(CameraParameters::KEY_JPEG_QUALITY, jpegQuality); 1680 if ( hardwareActive ) 1681 camera->setParameters(params.flatten()); 1682 break; 1683 1684 case 'M': 1685 measurementIdx = (measurementIdx + 1)%ARRAY_SIZE(measurement); 1686 params.set(KEY_MEASUREMENT, measurement[measurementIdx]); 1687 if ( hardwareActive ) 1688 camera->setParameters(params.flatten()); 1689 break; 1690 case 'm': 1691 { 1692 meter_mode = (meter_mode + 1)%ARRAY_SIZE(metering); 1693 params.set(KEY_METERING_MODE, metering[meter_mode]); 1694 if ( hardwareActive ) 1695 camera->setParameters(params.flatten()); 1696 break; 1697 } 1698 1699 case 'k': 1700 ippIDX += 1; 1701 ippIDX %= ARRAY_SIZE(ipp_mode); 1702 ippIDX_old = ippIDX; 1703 1704 params.set(KEY_IPP, ipp_mode[ippIDX]); 1705 1706 if ( hardwareActive ) 1707 camera->setParameters(params.flatten()); 1708 1709 break; 1710 1711 case 'K': 1712 gbceIDX+= 1; 1713 gbceIDX %= ARRAY_SIZE(gbce); 1714 params.set(KEY_GBCE, gbce[gbceIDX]); 1715 1716 if ( hardwareActive ) 1717 camera->setParameters(params.flatten()); 1718 break; 1719 1720 case 'O': 1721 glbceIDX+= 1; 1722 glbceIDX %= ARRAY_SIZE(gbce); 1723 params.set(KEY_GLBCE, gbce[glbceIDX]); 1724 1725 if ( hardwareActive ) 1726 camera->setParameters(params.flatten()); 1727 break; 1728 1729 case 'F': 1730 if ( hardwareActive ) 1731 camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, 0, 0); 1732 1733 break; 1734 1735 case 'T': 1736 1737 if ( hardwareActive ) 1738 camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0); 1739 1740 break; 1741 1742 case '@': 1743 if ( hardwareActive ) { 1744 1745 closeCamera(); 1746 1747 if ( 0 >= openCamera() ) { 1748 printf( "Reconnected to CameraService \n"); 1749 } 1750 } 1751 1752 break; 1753 1754 case '#': 1755 1756 if ( burst >= MAX_BURST ) { 1757 burst = 0; 1758 } else { 1759 burst += BURST_INC; 1760 } 1761 params.set(KEY_BURST, burst); 1762 1763 if ( hardwareActive ) 1764 camera->setParameters(params.flatten()); 1765 1766 break; 1767 1768 case 'J': 1769 flashIdx++; 1770 flashIdx %= ARRAY_SIZE(flashModes); 1771 params.set(CameraParameters::KEY_FLASH_MODE, (flashModes[flashIdx])); 1772 1773 if ( hardwareActive ) 1774 camera->setParameters(params.flatten()); 1775 1776 break; 1777 1778 case 'u': 1779 capture_mode++; 1780 capture_mode %= ARRAY_SIZE(capture); 1781 1782 // HQ should always be in ldc-nsf 1783 // if not HQ, then return the ipp to its previous state 1784 if( !strcmp(capture[capture_mode], "high-quality") ) { 1785 ippIDX_old = ippIDX; 1786 ippIDX = 3; 1787 params.set(KEY_IPP, ipp_mode[ippIDX]); 1788 } else { 1789 ippIDX = ippIDX_old; 1790 } 1791 1792 params.set(KEY_MODE, (capture[capture_mode])); 1793 1794 if ( hardwareActive ) 1795 camera->setParameters(params.flatten()); 1796 1797 break; 1798 1799 case 'U': 1800 tempBracketIdx++; 1801 tempBracketIdx %= ARRAY_SIZE(tempBracketing); 1802 params.set(KEY_TEMP_BRACKETING, tempBracketing[tempBracketIdx]); 1803 1804 if ( hardwareActive ) 1805 camera->setParameters(params.flatten()); 1806 1807 break; 1808 1809 case 'H': 1810 expBracketIdx++; 1811 expBracketIdx %= ARRAY_SIZE(expBracketing); 1812 1813 params.set(KEY_EXP_BRACKETING_RANGE, expBracketingRange[expBracketIdx]); 1814 1815 if ( hardwareActive ) 1816 camera->setParameters(params.flatten()); 1817 1818 break; 1819 1820 case 'W': 1821 tempBracketRange++; 1822 tempBracketRange %= TEMP_BRACKETING_MAX_RANGE; 1823 if ( 0 == tempBracketRange ) { 1824 tempBracketRange = 1; 1825 } 1826 1827 params.set(KEY_TEMP_BRACKETING_NEG, tempBracketRange); 1828 params.set(KEY_TEMP_BRACKETING_POS, tempBracketRange); 1829 1830 if ( hardwareActive ) 1831 camera->setParameters(params.flatten()); 1832 1833 break; 1834 1835 case 'w': 1836 scene_mode++; 1837 scene_mode %= ARRAY_SIZE(scene); 1838 params.set(params.KEY_SCENE_MODE, scene[scene_mode]); 1839 1840 if ( hardwareActive ) 1841 camera->setParameters(params.flatten()); 1842 1843 break; 1844 1845 case 'i': 1846 iso_mode++; 1847 iso_mode %= ARRAY_SIZE(iso); 1848 params.set(KEY_ISO, iso[iso_mode]); 1849 1850 if ( hardwareActive ) 1851 camera->setParameters(params.flatten()); 1852 break; 1853 1854 case 'h': 1855 if ( sharpness >= 100) { 1856 sharpness = 0; 1857 } else { 1858 sharpness += 10; 1859 } 1860 params.set(KEY_SHARPNESS, sharpness); 1861 if ( hardwareActive ) 1862 camera->setParameters(params.flatten()); 1863 break; 1864 1865 case 'D': 1866 { 1867 audioCodecIDX++; 1868 audioCodecIDX %= ARRAY_SIZE(audioCodecs); 1869 break; 1870 } 1871 1872 case 'v': 1873 { 1874 outputFormatIDX++; 1875 outputFormatIDX %= ARRAY_SIZE(outputFormat); 1876 break; 1877 } 1878 1879 case 'z': 1880 zoomIDX++; 1881 zoomIDX %= ARRAY_SIZE(zoom); 1882 params.set(CameraParameters::KEY_ZOOM, zoom[zoomIDX].idx); 1883 1884 if ( hardwareActive ) 1885 camera->setParameters(params.flatten()); 1886 1887 break; 1888 1889 case 'j': 1890 exposure_mode++; 1891 exposure_mode %= ARRAY_SIZE(exposure); 1892 params.set(KEY_EXPOSURE, exposure[exposure_mode]); 1893 1894 if ( hardwareActive ) 1895 camera->setParameters(params.flatten()); 1896 1897 break; 1898 1899 case 'c': 1900 if( contrast >= 200){ 1901 contrast = 0; 1902 } else { 1903 contrast += 10; 1904 } 1905 params.set(KEY_CONTRAST, contrast); 1906 if ( hardwareActive ) 1907 camera->setParameters(params.flatten()); 1908 break; 1909 case 'b': 1910 if ( brightness >= 200) { 1911 brightness = 0; 1912 } else { 1913 brightness += 10; 1914 } 1915 1916 params.set(KEY_BRIGHTNESS, brightness); 1917 1918 if ( hardwareActive ) 1919 camera->setParameters(params.flatten()); 1920 1921 break; 1922 1923 case 's': 1924 case 'S': 1925 if ( saturation >= 100) { 1926 saturation = 0; 1927 } else { 1928 saturation += 10; 1929 } 1930 1931 params.set(KEY_SATURATION, saturation); 1932 1933 if ( hardwareActive ) 1934 camera->setParameters(params.flatten()); 1935 1936 break; 1937 1938 case 'e': 1939 effects_mode++; 1940 effects_mode %= ARRAY_SIZE(effects); 1941 params.set(params.KEY_EFFECT, effects[effects_mode]); 1942 1943 if ( hardwareActive ) 1944 camera->setParameters(params.flatten()); 1945 1946 break; 1947 1948 case 'r': 1949 1950 1951 if (camera_index == 0) { 1952 frameRateIDX += 1; 1953 frameRateIDX %= ARRAY_SIZE(fpsConstRanges); 1954 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fpsConstRanges[frameRateIDX].range); 1955 } else 1956 { 1957 frameRateIDXSec += 1; 1958 frameRateIDXSec %= ARRAY_SIZE(fpsConstRangesSec); 1959 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fpsConstRangesSec[frameRateIDXSec].range); 1960 1961 1962 } 1963 1964 if ( hardwareActive ) { 1965 camera->setParameters(params.flatten()); 1966 } 1967 1968 break; 1969 1970 case 'R': 1971 fpsRangeIdx += 1; 1972 fpsRangeIdx %= ARRAY_SIZE(fpsRanges); 1973 params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fpsRanges[fpsRangeIdx].range); 1974 1975 if ( hardwareActive ) { 1976 camera->setParameters(params.flatten()); 1977 } 1978 1979 break; 1980 1981 case 'x': 1982 antibanding_mode++; 1983 antibanding_mode %= ARRAY_SIZE(antibanding); 1984 params.set(params.KEY_ANTIBANDING, antibanding[antibanding_mode]); 1985 1986 if ( hardwareActive ) 1987 camera->setParameters(params.flatten()); 1988 1989 break; 1990 1991 case 'g': 1992 focus_mode++; 1993 focus_mode %= ARRAY_SIZE(focus); 1994 params.set(params.KEY_FOCUS_MODE, focus[focus_mode]); 1995 1996 if ( hardwareActive ) 1997 camera->setParameters(params.flatten()); 1998 1999 break; 2000 2001 case 'G': 2002 2003 params.set(CameraParameters::KEY_FOCUS_AREAS, TEST_FOCUS_AREA); 2004 2005 if ( hardwareActive ) 2006 camera->setParameters(params.flatten()); 2007 2008 params.remove(CameraParameters::KEY_FOCUS_AREAS); 2009 2010 case 'f': 2011 2012 gettimeofday(&autofocus_start, 0); 2013 2014 if ( hardwareActive ) 2015 camera->autoFocus(); 2016 2017 break; 2018 2019 case 'p': 2020 2021 gettimeofday(&picture_start, 0); 2022 2023 if ( hardwareActive ) 2024 camera->takePicture(CAMERA_MSG_COMPRESSED_IMAGE|CAMERA_MSG_RAW_IMAGE); 2025 2026 break; 2027 2028 case '&': 2029 printf("Enabling Preview Callback"); 2030 dump_preview = 1; 2031 if ( hardwareActive ) 2032 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK); 2033 break; 2034 2035 case '{': 2036 if ( strcmp(params.get(KEY_S3D2D_PREVIEW_MODE), "off") == 0 ) 2037 { 2038 params.set(KEY_S3D2D_PREVIEW_MODE, "on"); 2039 } 2040 else 2041 { 2042 params.set(KEY_S3D2D_PREVIEW_MODE, "off"); 2043 } 2044 if ( hardwareActive ) 2045 camera->setParameters(params.flatten()); 2046 break; 2047 2048 case 'a': 2049 2050 while (1) { 2051 if ( menu_gps() < 0) 2052 break; 2053 }; 2054 2055 break; 2056 2057 case 'q': 2058 2059 stopPreview(); 2060 2061 return -1; 2062 2063 case '/': 2064 { 2065 if (showfps) 2066 { 2067 property_set("debug.image.showfps", "0"); 2068 showfps = false; 2069 } 2070 else 2071 { 2072 property_set("debug.image.showfps", "1"); 2073 showfps = true; 2074 } 2075 break; 2076 } 2077 2078 case '<': 2079 elockidx += 1; 2080 elockidx %= ARRAY_SIZE(lock); 2081 params.set(KEY_AUTO_EXPOSURE_LOCK, lock[elockidx]); 2082 if ( hardwareActive ) 2083 camera->setParameters(params.flatten()); 2084 break; 2085 2086 case '>': 2087 wblockidx += 1; 2088 wblockidx %= ARRAY_SIZE(lock); 2089 params.set(KEY_AUTO_WHITEBALANCE_LOCK, lock[wblockidx]); 2090 if ( hardwareActive ) 2091 camera->setParameters(params.flatten()); 2092 break; 2093 2094 default: 2095 print_menu = 0; 2096 2097 break; 2098 } 2099 2100 return 0; 2101} 2102 2103void print_usage() { 2104 printf(" USAGE: camera_test <param> <script>\n"); 2105 printf(" <param>\n-----------\n\n"); 2106 printf(" F or f -> Functional tests \n"); 2107 printf(" A or a -> API tests \n"); 2108 printf(" E or e -> Error scenario tests \n"); 2109 printf(" S or s -> Stress tests; with syslink trace \n"); 2110 printf(" SN or sn -> Stress tests; No syslink trace \n\n"); 2111 printf(" <script>\n----------\n"); 2112 printf("Script name (Only for stress tests)\n\n"); 2113 return; 2114} 2115 2116int error_scenario() { 2117 char ch; 2118 status_t stat = NO_ERROR; 2119 2120 if (print_menu) { 2121 printf(" 0. Buffer need\n"); 2122 printf(" 1. Not enough memory\n"); 2123 printf(" 2. Media server crash\n"); 2124 printf(" 3. Overlay object request\n"); 2125 printf(" 4. Pass unsupported preview&picture format\n"); 2126 printf(" 5. Pass unsupported preview&picture resolution\n"); 2127 printf(" 6. Pass unsupported preview framerate\n"); 2128 2129 printf(" q. Quit\n"); 2130 printf(" Choice: "); 2131 } 2132 2133 print_menu = 1; 2134 ch = getchar(); 2135 printf("%c\n", ch); 2136 2137 switch (ch) { 2138 case '0': { 2139 printf("Case0:Buffer need\n"); 2140 bufferStarvationTest = 1; 2141 params.set(KEY_BUFF_STARV, bufferStarvationTest); //enable buffer starvation 2142 2143 if ( !recordingMode ) { 2144 recordingMode = true; 2145 if ( startPreview() < 0 ) { 2146 printf("Error while starting preview\n"); 2147 2148 return -1; 2149 } 2150 2151 if ( openRecorder() < 0 ) { 2152 printf("Error while openning video recorder\n"); 2153 2154 return -1; 2155 } 2156 2157 if ( configureRecorder() < 0 ) { 2158 printf("Error while configuring video recorder\n"); 2159 2160 return -1; 2161 } 2162 2163 if ( startRecording() < 0 ) { 2164 printf("Error while starting video recording\n"); 2165 2166 return -1; 2167 } 2168 2169 } 2170 2171 usleep(1000000);//1s 2172 2173 stopPreview(); 2174 2175 if ( recordingMode ) { 2176 stopRecording(); 2177 closeRecorder(); 2178 2179 recordingMode = false; 2180 } 2181 2182 break; 2183 } 2184 2185 case '1': { 2186 printf("Case1:Not enough memory\n"); 2187 int* tMemoryEater = new int[999999999]; 2188 2189 if (!tMemoryEater) { 2190 printf("Not enough memory\n"); 2191 return -1; 2192 } else { 2193 delete tMemoryEater; 2194 } 2195 2196 break; 2197 } 2198 2199 case '2': { 2200 printf("Case2:Media server crash\n"); 2201 //camera = Camera::connect(); 2202 2203 if ( NULL == camera.get() ) { 2204 printf("Unable to connect to CameraService\n"); 2205 return -1; 2206 } 2207 2208 break; 2209 } 2210 2211 case '3': { 2212 printf("Case3:Overlay object request\n"); 2213 int err = 0; 2214 2215 err = open("/dev/video5", O_RDWR); 2216 2217 if (err < 0) { 2218 printf("Could not open the camera device5: %d\n", err ); 2219 return err; 2220 } 2221 2222 if ( startPreview() < 0 ) { 2223 printf("Error while starting preview\n"); 2224 return -1; 2225 } 2226 2227 usleep(1000000);//1s 2228 2229 stopPreview(); 2230 2231 close(err); 2232 break; 2233 } 2234 2235 case '4': { 2236 2237 if ( hardwareActive ) { 2238 2239 params.setPictureFormat("invalid-format"); 2240 params.setPreviewFormat("invalid-format"); 2241 2242 stat = camera->setParameters(params.flatten()); 2243 2244 if ( NO_ERROR != stat ) { 2245 printf("Test passed!\n"); 2246 } else { 2247 printf("Test failed!\n"); 2248 } 2249 2250 initDefaults(); 2251 } 2252 2253 break; 2254 } 2255 2256 case '5': { 2257 2258 if ( hardwareActive ) { 2259 2260 params.setPictureSize(-1, -1); 2261 params.setPreviewSize(-1, -1); 2262 2263 stat = camera->setParameters(params.flatten()); 2264 2265 if ( NO_ERROR != stat ) { 2266 printf("Test passed!\n"); 2267 } else { 2268 printf("Test failed!\n"); 2269 } 2270 2271 initDefaults(); 2272 } 2273 2274 break; 2275 } 2276 2277 case '6': { 2278 2279 if ( hardwareActive ) { 2280 2281 params.setPreviewFrameRate(-1); 2282 2283 stat = camera->setParameters(params.flatten()); 2284 2285 if ( NO_ERROR != stat ) { 2286 printf("Test passed!\n"); 2287 } else { 2288 printf("Test failed!\n"); 2289 } 2290 2291 initDefaults(); 2292 } 2293 2294 2295 break; 2296 } 2297 2298 case 'q': { 2299 return -1; 2300 } 2301 2302 default: { 2303 print_menu = 0; 2304 break; 2305 } 2306 } 2307 2308 return 0; 2309} 2310 2311int restartCamera() { 2312 2313 const char dir_path_name[80] = SDCARD_PATH; 2314 2315 printf("+++Restarting Camera After Error+++\n"); 2316 stopPreview(); 2317 2318 if (recordingMode) { 2319 stopRecording(); 2320 closeRecorder(); 2321 2322 recordingMode = false; 2323 } 2324 2325 sleep(3); //Wait a bit before restarting 2326 2327 restartCount++; 2328 2329 if (strcpy(dir_path, dir_path_name) == NULL) 2330 { 2331 printf("Error reseting dir name"); 2332 return -1; 2333 } 2334 2335 if ( openCamera() < 0 ) 2336 { 2337 printf("+++Camera Restarted Failed+++\n"); 2338 system("echo camerahal_test > /sys/power/wake_unlock"); 2339 return -1; 2340 } 2341 2342 initDefaults(); 2343 2344 stopScript = false; 2345 2346 printf("+++Camera Restarted Successfully+++\n"); 2347 return 0; 2348} 2349 2350int main(int argc, char *argv[]) { 2351 char *cmd; 2352 int pid; 2353 sp<ProcessState> proc(ProcessState::self()); 2354 2355 unsigned long long st, end, delay; 2356 timeval current_time; 2357 2358 gettimeofday(¤t_time, 0); 2359 2360 st = current_time.tv_sec * 1000000 + current_time.tv_usec; 2361 2362 cmd = NULL; 2363 2364 if ( argc < 2 ) { 2365 printf(" Please enter atleast 1 argument\n"); 2366 print_usage(); 2367 2368 return 0; 2369 } 2370 system("echo camerahal_test > /sys/power/wake_lock"); 2371 if ( argc < 3 ) { 2372 switch (*argv[1]) { 2373 case 'S': 2374 case 's': 2375 printf("This is stress / regression tests \n"); 2376 printf("Provide script file as 2nd argument\n"); 2377 2378 break; 2379 2380 case 'F': 2381 case 'f': 2382 ProcessState::self()->startThreadPool(); 2383 2384 if ( openCamera() < 0 ) { 2385 printf("Camera initialization failed\n"); 2386 system("echo camerahal_test > /sys/power/wake_unlock"); 2387 return -1; 2388 } 2389 2390 initDefaults(); 2391 print_menu = 1; 2392 2393 while ( 1 ) { 2394 if ( functional_menu() < 0 ) 2395 break; 2396 }; 2397 2398 break; 2399 2400 case 'A': 2401 case 'a': 2402 printf("API level test cases coming soon ... \n"); 2403 2404 break; 2405 2406 case 'E': 2407 case 'e': { 2408 ProcessState::self()->startThreadPool(); 2409 2410 if ( openCamera() < 0 ) { 2411 printf("Camera initialization failed\n"); 2412 system("echo camerahal_test > /sys/power/wake_unlock"); 2413 return -1; 2414 } 2415 2416 initDefaults(); 2417 print_menu = 1; 2418 2419 while (1) { 2420 if (error_scenario() < 0) { 2421 break; 2422 } 2423 } 2424 2425 break; 2426 } 2427 2428 default: 2429 printf("INVALID OPTION USED\n"); 2430 print_usage(); 2431 2432 break; 2433 } 2434 } else if ( ( argc == 3) && ( ( *argv[1] == 'S' ) || ( *argv[1] == 's') ) ) { 2435 2436 if((argv[1][1] == 'N') || (argv[1][1] == 'n')) { 2437 bLogSysLinkTrace = false; 2438 } 2439 2440 ProcessState::self()->startThreadPool(); 2441 2442 if ( openCamera() < 0 ) { 2443 printf("Camera initialization failed\n"); 2444 system("echo camerahal_test > /sys/power/wake_unlock"); 2445 return -1; 2446 } 2447 2448 initDefaults(); 2449 2450 cmd = load_script(argv[2]); 2451 2452 if ( cmd != NULL) { 2453 start_logging(argv[2], pid); 2454 stressTest = true; 2455 2456 while (1) 2457 { 2458 if ( execute_functional_script(cmd) == 0 ) 2459 { 2460 break; 2461 } 2462 else 2463 { 2464 printf("CameraTest Restarting Camera...\n"); 2465 2466 free(cmd); 2467 cmd = NULL; 2468 2469 if ( (restartCamera() != 0) || ((cmd = load_script(argv[2])) == NULL) ) 2470 { 2471 printf("ERROR::CameraTest Restarting Camera...\n"); 2472 break; 2473 } 2474 } 2475 } 2476 free(cmd); 2477 stop_logging(pid); 2478 } 2479 } else if ( ( argc == 3) && ( ( *argv[1] == 'E' ) || ( *argv[1] == 'e') ) ) { 2480 2481 ProcessState::self()->startThreadPool(); 2482 2483 if ( openCamera() < 0 ) { 2484 printf("Camera initialization failed\n"); 2485 system("echo camerahal_test > /sys/power/wake_unlock"); 2486 return -1; 2487 } 2488 2489 initDefaults(); 2490 2491 cmd = load_script(argv[2]); 2492 2493 if ( cmd != NULL) { 2494 start_logging(argv[2], pid); 2495 execute_error_script(cmd); 2496 free(cmd); 2497 stop_logging(pid); 2498 } 2499 2500 } else { 2501 printf("INVALID OPTION USED\n"); 2502 print_usage(); 2503 } 2504 2505 gettimeofday(¤t_time, 0); 2506 end = current_time.tv_sec * 1000000 + current_time.tv_usec; 2507 delay = end - st; 2508 printf("Application clossed after: %llu ms\n", delay); 2509 system("echo camerahal_test > /sys/power/wake_unlock"); 2510 return 0; 2511} 2512 2513