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