Home | History | Annotate | Download | only in CameraHal
      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 
     26 #include <sys/wait.h>
     27 
     28 #include "camera_test.h"
     29 
     30 using namespace android;
     31 
     32 extern bool stopScript;
     33 extern bool hardwareActive;
     34 extern sp<Camera> camera;
     35 extern CameraParameters params;
     36 extern bool recordingMode;
     37 extern int camera_index;
     38 extern int rotation;
     39 extern const preview_size previewSize [];
     40 extern const Vcapture_size VcaptureSize [];
     41 extern const capture_Size captureSize[];
     42 extern const outformat outputFormat[];
     43 extern const video_Codecs videoCodecs[];
     44 extern const audio_Codecs audioCodecs[];
     45 extern const V_bitRate VbitRate[];
     46 extern const fps_ranges fpsRanges[];
     47 extern const fpsConst_Ranges fpsConstRanges[];
     48 extern const fpsConst_RangesSec fpsConstRangesSec[];
     49 extern const Zoom zoom [];
     50 extern int previewSizeIDX;
     51 extern bool reSizePreview;
     52 extern bool previewRunning;
     53 extern int captureSizeIDX;
     54 extern float compensation;
     55 extern int videoCodecIDX;
     56 extern int outputFormatIDX;
     57 extern int audioCodecIDX;
     58 extern int VcaptureSizeIDX;
     59 extern int VbitRateIDX;
     60 extern int thumbSizeIDX;
     61 extern int thumbQuality;
     62 extern int jpegQuality;
     63 extern int dump_preview;
     64 extern int ippIDX_old;
     65 extern const char *capture[];
     66 extern int capture_mode;
     67 extern int ippIDX;
     68 extern const char *ipp_mode[];
     69 extern int tempBracketRange;
     70 extern int iso_mode;
     71 extern int sharpness;
     72 extern int contrast;
     73 extern int zoomIDX;
     74 extern int brightness;
     75 extern int saturation;
     76 extern int fpsRangeIdx;
     77 extern timeval autofocus_start, picture_start;
     78 extern const char *cameras[];
     79 extern double latitude;
     80 extern double degree_by_step;
     81 extern double longitude;
     82 extern double altitude;
     83 extern char dir_path[80];
     84 extern int AutoConvergenceModeIDX;
     85 extern const char *autoconvergencemode[];
     86 extern const char *manualconvergencevalues[];
     87 extern const int ManualConvergenceDefaultValueIDX;
     88 extern size_t length_cam;
     89 extern char script_name[];
     90 extern int restartCount;
     91 extern bool bLogSysLinkTrace;
     92 extern int bufferStarvationTest;
     93 extern size_t length_previewSize;
     94 extern size_t lenght_Vcapture_size;
     95 extern size_t length_outformat;
     96 extern size_t length_capture_Size;
     97 extern size_t length_video_Codecs;
     98 extern size_t length_audio_Codecs;
     99 extern size_t length_V_bitRate;
    100 extern size_t length_Zoom;
    101 extern size_t length_fps_ranges;
    102 extern size_t length_fpsConst_Ranges;
    103 extern size_t length_fpsConst_RangesSec;
    104 
    105 
    106 int execute_functional_script(char *script) {
    107     char *cmd, *ctx, *cycle_cmd, *temp_cmd;
    108     char id;
    109     unsigned int i;
    110     int dly;
    111     int cycleCounter = 1;
    112     int tLen = 0;
    113     unsigned int iteration = 0;
    114     status_t ret = NO_ERROR;
    115     int frameR = 20;
    116     int frameRateIndex = 0;
    117 
    118     LOG_FUNCTION_NAME;
    119 
    120     dump_mem_status();
    121 
    122     cmd = strtok_r((char *) script, DELIMITER, &ctx);
    123 
    124     while ( NULL != cmd && (stopScript == false)) {
    125         id = cmd[0];
    126         printf("Full Command: %s \n", cmd);
    127         printf("Command: %c \n", cmd[0]);
    128 
    129         switch (id) {
    130 
    131             // Case for Suspend-Resume Feature
    132             case '!': {
    133                 // STEP 1: Mount Debugfs
    134                 system("mkdir /debug");
    135                 system("mount -t debugfs debugfs /debug");
    136 
    137                 // STEP 2: Set up wake up Timer - wake up happens after 5 seconds
    138                 system("echo 10 > /debug/pm_debug/wakeup_timer_seconds");
    139 
    140                 // STEP 3: Make system ready for Suspend
    141                 system("echo camerahal_test > /sys/power/wake_unlock");
    142                 // Release wake lock held by test app
    143                 printf(" Wake lock released ");
    144                 system("cat /sys/power/wake_lock");
    145                 system("sendevent /dev/input/event0 1 60 1");
    146                 system("sendevent /dev/input/event0 1 60 0");
    147                 // Simulate F2 key press to make display OFF
    148                 printf(" F2 event simulation complete ");
    149 
    150                 //STEP 4: Wait for system Resume and then simuate F1 key
    151                 sleep(50);//50s  // This delay is not related to suspend resume timer
    152                 printf(" After 30 seconds of sleep");
    153                 system("sendevent /dev/input/event0 1 59 0");
    154                 system("sendevent /dev/input/event0 1 59 1");
    155                 // Simulate F1 key press to make display ON
    156                 system("echo camerahal_test > /sys/power/wake_lock");
    157                 // Acquire wake lock for test app
    158 
    159                 break;
    160             }
    161 
    162             case '[':
    163                 if ( hardwareActive )
    164                     {
    165 
    166                     camera->setParameters(params.flatten());
    167 
    168                     printf("starting camera preview..");
    169                     status_t ret = camera->startPreview();
    170                     if(ret !=NO_ERROR)
    171                         {
    172                         printf("startPreview failed %d..", ret);
    173                         }
    174                     }
    175                 break;
    176             case '+': {
    177                 cycleCounter = atoi(cmd + 1);
    178                 cycle_cmd = get_cycle_cmd(ctx);
    179                 tLen = strlen(cycle_cmd);
    180                 temp_cmd = new char[tLen+1];
    181 
    182                 for (int ind = 0; ind < cycleCounter; ind++) {
    183                     strcpy(temp_cmd, cycle_cmd);
    184                     if ( execute_functional_script(temp_cmd) != 0 )
    185                       return -1;
    186                     temp_cmd[0] = '\0';
    187 
    188                     //patch for image capture
    189                     //[
    190                     if (ind < cycleCounter - 1) {
    191                         if (hardwareActive == false) {
    192                             if ( openCamera() < 0 ) {
    193                                 printf("Camera initialization failed\n");
    194 
    195                                 return -1;
    196                             }
    197 
    198                             initDefaults();
    199                         }
    200                     }
    201 
    202                     //]
    203                 }
    204 
    205                 ctx += tLen + 1;
    206 
    207                 if (temp_cmd) {
    208                     delete temp_cmd;
    209                     temp_cmd = NULL;
    210                 }
    211 
    212                 if (cycle_cmd) {
    213                     delete cycle_cmd;
    214                     cycle_cmd = NULL;
    215                 }
    216 
    217                 break;
    218             }
    219 
    220             case '0':
    221             {
    222                 initDefaults();
    223                 break;
    224             }
    225 
    226             case '1':
    227 
    228                 if ( startPreview() < 0 ) {
    229                     printf("Error while starting preview\n");
    230 
    231                     return -1;
    232                 }
    233 
    234                 break;
    235 
    236             case '2':
    237                 stopPreview();
    238 
    239                 if ( recordingMode ) {
    240 
    241                     camera->disconnect();
    242                     camera.clear();
    243                     stopRecording();
    244                     closeRecorder();
    245 
    246                     camera = Camera::connect(camera_index);
    247                       if ( NULL == camera.get() ) {
    248                           sleep(1);
    249                           camera = Camera::connect(camera_index);
    250 
    251                           if ( NULL == camera.get() ) {
    252                               return -1;
    253                           }
    254                       }
    255                       camera->setListener(new CameraHandler());
    256                       camera->setParameters(params.flatten());
    257 
    258                       recordingMode = false;
    259                 }
    260 
    261                 break;
    262 
    263             case '3':
    264                 rotation = atoi(cmd + 1);
    265                 params.set(CameraParameters::KEY_ROTATION, rotation);
    266 
    267                 if ( hardwareActive )
    268                     camera->setParameters(params.flatten());
    269 
    270                 break;
    271 
    272             case '4':
    273             {
    274                 printf("Setting resolution...");
    275                 int width, height;
    276                 for(i = 0; i < length_previewSize ; i++)
    277                 {
    278                     if( strcmp((cmd + 1), previewSize[i].desc) == 0)
    279                     {
    280                         width = previewSize[i].width;
    281                         height = previewSize[i].height;
    282                         previewSizeIDX = i;
    283                         break;
    284                     }
    285                 }
    286 
    287                 if (i == length_previewSize )   //if the resolution is not in the supported ones
    288                 {
    289                     char *res = NULL;
    290                     res = strtok(cmd + 1, "x");
    291                     width = atoi(res);
    292                     res = strtok(NULL, "x");
    293                     height = atoi(res);
    294                 }
    295 
    296                 if ( NULL != params.get(KEY_STEREO_CAMERA) ) {
    297                     if ( strcmp(params.get(KEY_STEREO_CAMERA), "true") == 0 ) {
    298                         height *=2;
    299                     }
    300                 }
    301 
    302                 printf("Resolution: %d x %d\n", width, height);
    303                 params.setPreviewSize(width, height);
    304                 reSizePreview = true;
    305 
    306                 if ( hardwareActive && previewRunning ) {
    307                     camera->stopPreview();
    308                     camera->setParameters(params.flatten());
    309                     camera->startPreview();
    310                 } else if ( hardwareActive ) {
    311                     camera->setParameters(params.flatten());
    312                 }
    313 
    314                 break;
    315             }
    316             case '5':
    317 
    318                 for (i = 0; i < length_capture_Size; i++) {
    319                     if ( strcmp((cmd + 1), captureSize[i].name) == 0)
    320                         break;
    321                 }
    322 
    323                 if (  i < length_capture_Size ) {
    324                     params.setPictureSize(captureSize[i].width, captureSize[i].height);
    325                     captureSizeIDX = i;
    326                 }
    327 
    328                 if ( hardwareActive )
    329                     camera->setParameters(params.flatten());
    330 
    331                 break;
    332 
    333             case '6':
    334 
    335                 if ( !recordingMode ) {
    336 
    337                     recordingMode = true;
    338 
    339                     if ( startPreview() < 0 ) {
    340                         printf("Error while starting preview\n");
    341 
    342                         return -1;
    343                     }
    344 
    345                     if ( openRecorder() < 0 ) {
    346                         printf("Error while openning video recorder\n");
    347 
    348                         return -1;
    349                     }
    350 
    351                     if ( configureRecorder() < 0 ) {
    352                         printf("Error while configuring video recorder\n");
    353 
    354                         return -1;
    355                     }
    356 
    357                     if ( startRecording() < 0 ) {
    358                         printf("Error while starting video recording\n");
    359 
    360                         return -1;
    361                     }
    362 
    363                 }
    364 
    365                 break;
    366 
    367             case '7':
    368                 compensation = atof(cmd + 1);
    369                 params.set(KEY_COMPENSATION, (int) (compensation * 10));
    370 
    371                 if ( hardwareActive )
    372                     camera->setParameters(params.flatten());
    373 
    374                 break;
    375 
    376             case '8':
    377                 params.set(params.KEY_WHITE_BALANCE, (cmd + 1));
    378 
    379                 if ( hardwareActive )
    380                     camera->setParameters(params.flatten());
    381 
    382                 break;
    383 
    384             case '9':
    385                 for(i = 0; i < length_video_Codecs; i++)
    386                 {
    387                     if( strcmp((cmd + 1), videoCodecs[i].desc) == 0)
    388                     {
    389                         videoCodecIDX = i;
    390                         printf("Video Codec Selected: %s\n",
    391                                 videoCodecs[i].desc);
    392                         break;
    393                     }
    394                 }
    395                 break;
    396 
    397             case 'v':
    398                 for(i = 0; i < length_outformat; i++)
    399 
    400                 {
    401                     if( strcmp((cmd + 1), outputFormat[i].desc) == 0)
    402                     {
    403                         outputFormatIDX = i;
    404                         printf("Video Codec Selected: %s\n",
    405                                 videoCodecs[i].desc);
    406                         break;
    407                     }
    408                 }
    409             break;
    410 
    411             case '~':
    412                 params.setPreviewFormat(cmd + 1);
    413                 if ( hardwareActive )
    414                     camera->setParameters(params.flatten());
    415 
    416                 break;
    417 
    418             case '$':
    419                 params.setPictureFormat(cmd + 1);
    420                 if ( hardwareActive )
    421                     camera->setParameters(params.flatten());
    422 
    423                 break;
    424             case '-':
    425                 for(i = 0; i < length_audio_Codecs; i++)
    426                 {
    427                     if( strcmp((cmd + 1), audioCodecs[i].desc) == 0)
    428                     {
    429                         audioCodecIDX = i;
    430                         printf("Selected Audio: %s\n", audioCodecs[i].desc);
    431                         break;
    432                     }
    433                 }
    434                 break;
    435 
    436             case 'A':
    437                 camera_index=atoi(cmd+1);
    438            //     camera_index %= ARRAY_SIZE(cameras);
    439                 camera_index %= length_cam;
    440                 if ( camera_index == 2)
    441                     params.set(KEY_STEREO_CAMERA, "true");
    442                 else
    443                     params.set(KEY_STEREO_CAMERA, "false");
    444 
    445                 printf("%s selected.\n", cameras[camera_index]);
    446 
    447                 if ( hardwareActive ) {
    448                     stopPreview();
    449                     closeCamera();
    450                     openCamera();
    451                 } else {
    452                     closeCamera();
    453                     openCamera();
    454                 }
    455 
    456                 if (camera_index == 0) params.setPreviewFrameRate(30);
    457                   else params.setPreviewFrameRate(27);
    458 
    459 
    460                 break;
    461 
    462             case 'a':
    463                 char * temp_str;
    464 
    465                 temp_str = strtok(cmd+1,"!");
    466                 printf("Latitude %s \n",temp_str);
    467                 params.set(params.KEY_GPS_LATITUDE, temp_str);
    468                 temp_str=strtok(NULL,"!");
    469                 printf("Longitude %s \n",temp_str);
    470                 params.set(params.KEY_GPS_LONGITUDE, temp_str);
    471                 temp_str=strtok(NULL,"!");
    472                 printf("Altitude %s \n",temp_str);
    473                 params.set(params.KEY_GPS_ALTITUDE, temp_str);
    474 
    475                 if ( hardwareActive )
    476                     camera->setParameters(params.flatten());
    477                 break;
    478 
    479             case 'l':
    480             case 'L':
    481                 for(i = 0; i < lenght_Vcapture_size; i++)
    482                 {
    483                     if( strcmp((cmd + 1), VcaptureSize[i].desc) == 0)
    484                     {
    485                         VcaptureSizeIDX = i;
    486                         printf("Video Capture Size: %s\n", VcaptureSize[i].desc);
    487                         break;
    488                     }
    489                 }
    490                 break;
    491             case ']':
    492                 for(i = 0; i < length_V_bitRate; i++)
    493                 {
    494                     if( strcmp((cmd + 1), VbitRate[i].desc) == 0)
    495                     {
    496                         VbitRateIDX = i;
    497                         printf("Video Bit Rate: %s\n", VbitRate[i].desc);
    498                         break;
    499                     }
    500                 }
    501                 break;
    502             case ':':
    503                 int width, height;
    504                 for(i = 0; i < length_previewSize ; i++)
    505                 {
    506                     if( strcmp((cmd + 1), previewSize[i].desc) == 0)
    507                     {
    508                         width = previewSize[i].width;
    509                         height = previewSize[i].height;
    510                         thumbSizeIDX = i;
    511                         break;
    512                     }
    513                 }
    514 
    515                 if (i == length_previewSize )   //if the resolution is not in the supported ones
    516                 {
    517                     char *res = NULL;
    518                     res = strtok(cmd + 1, "x");
    519                     width = atoi(res);
    520                     res = strtok(NULL, "x");
    521                     height = atoi(res);
    522                 }
    523 
    524                 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, width);
    525                 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, height);
    526 
    527                 if ( hardwareActive )
    528                     camera->setParameters(params.flatten());
    529 
    530                 break;
    531 
    532             case '\'':
    533                 thumbQuality = atoi(cmd + 1);
    534 
    535                 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, thumbQuality);
    536                 if ( hardwareActive )
    537                     camera->setParameters(params.flatten());
    538                 break;
    539 
    540             case '*':
    541                 if ( hardwareActive )
    542                     camera->startRecording();
    543                 break;
    544 
    545             case 't':
    546                 params.setPreviewFormat((cmd + 1));
    547                 if ( hardwareActive )
    548                     camera->setParameters(params.flatten());
    549                 break;
    550 
    551             case 'o':
    552                 jpegQuality = atoi(cmd + 1);
    553                 params.set(CameraParameters::KEY_JPEG_QUALITY, jpegQuality);
    554 
    555                 if ( hardwareActive )
    556                     camera->setParameters(params.flatten());
    557 
    558                 break;
    559 
    560 
    561             case '&':
    562                 printf("Enabling Preview Callback");
    563                 dump_preview = 1;
    564                 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK);
    565                 break;
    566 
    567 
    568             case 'k':
    569                 ippIDX_old = atoi(cmd + 1);
    570                 params.set(KEY_IPP, atoi(cmd + 1));
    571                 if ( hardwareActive )
    572                     camera->setParameters(params.flatten());
    573 
    574                 break;
    575 
    576             case 'K':
    577                 params.set(KEY_GBCE, (cmd+1));
    578                 if ( hardwareActive )
    579                     camera->setParameters(params.flatten());
    580 
    581                 break;
    582 
    583             case 'F':
    584                 if ( hardwareActive )
    585                     camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, 0, 0);
    586 
    587                 break;
    588 
    589             case 'T':
    590 
    591                 if ( hardwareActive )
    592                     camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0);
    593 
    594             case 'O':
    595                 params.set(KEY_GLBCE, (cmd+1));
    596                 if ( hardwareActive )
    597                     camera->setParameters(params.flatten());
    598 
    599                 break;
    600 
    601             case 'u':
    602                 // HQ should always be in ldc-nsf
    603                 // if not HQ, then return the ipp to its previous state
    604                 if( !strcmp(capture[capture_mode], "high-quality") ) {
    605                     ippIDX_old = ippIDX;
    606                     ippIDX = 3;
    607                     params.set(KEY_IPP, ipp_mode[ippIDX]);
    608                 } else {
    609                     ippIDX = ippIDX_old;
    610                 }
    611 
    612                 params.set(KEY_MODE, (cmd + 1));
    613                 if ( hardwareActive )
    614                     camera->setParameters(params.flatten());
    615 
    616                 break;
    617 
    618             case 'U':
    619 
    620                 params.set(KEY_TEMP_BRACKETING, (cmd + 1));
    621 
    622                 if ( hardwareActive )
    623                     camera->setParameters(params.flatten());
    624 
    625                 break;
    626 
    627             case 'W':
    628 
    629                 tempBracketRange = atoi(cmd + 1);
    630                 tempBracketRange %= TEMP_BRACKETING_MAX_RANGE;
    631                 if ( 0 == tempBracketRange ) {
    632                     tempBracketRange = 1;
    633                 }
    634 
    635                 params.set(KEY_TEMP_BRACKETING_NEG, tempBracketRange);
    636                 params.set(KEY_TEMP_BRACKETING_POS, tempBracketRange);
    637 
    638                 if ( hardwareActive )
    639                     camera->setParameters(params.flatten());
    640 
    641             break;
    642 
    643             case '#':
    644 
    645                 params.set(KEY_BURST, atoi(cmd + 1));
    646 
    647                 if ( hardwareActive )
    648                     camera->setParameters(params.flatten());
    649 
    650                 break;
    651 
    652             case 'J':
    653                 params.set(CameraParameters::KEY_FLASH_MODE, (cmd+1));
    654 
    655                 if ( hardwareActive )
    656                     camera->setParameters(params.flatten());
    657 
    658                 break;
    659 
    660             case 'w':
    661                 params.set(params.KEY_SCENE_MODE, (cmd + 1));
    662 
    663                 if ( hardwareActive )
    664                     camera->setParameters(params.flatten());
    665 
    666                 break;
    667 
    668             case 'B' :
    669                 params.set(KEY_VNF, (cmd + 1));
    670 
    671                 if ( hardwareActive )
    672                     camera->setParameters(params.flatten());
    673 
    674 
    675             case 'C' :
    676                 params.set(KEY_VSTAB, (cmd + 1));
    677 
    678                 if ( hardwareActive )
    679                     camera->setParameters(params.flatten());
    680                 break;
    681 
    682             case 'D':
    683                 if ( hardwareActive )
    684                     camera->stopRecording();
    685                 break;
    686 
    687             case 'E':
    688                 if(hardwareActive)
    689                     params.unflatten(camera->getParameters());
    690                 printSupportedParams();
    691                 break;
    692 
    693             case 'i':
    694                 iso_mode = atoi(cmd + 1);
    695                 params.set(KEY_ISO, iso_mode);
    696 
    697                 if ( hardwareActive )
    698                     camera->setParameters(params.flatten());
    699 
    700                 break;
    701 
    702             case 'h':
    703                 sharpness = atoi(cmd + 1);
    704                 params.set(KEY_SHARPNESS, sharpness);
    705 
    706                 if ( hardwareActive )
    707                     camera->setParameters(params.flatten());
    708 
    709                 break;
    710 
    711             case '@':
    712                 if ( hardwareActive ) {
    713 
    714                     closeCamera();
    715 
    716                     if ( 0 >= openCamera() ) {
    717                         printf( "Reconnected to CameraService \n");
    718                     }
    719                 }
    720 
    721                 break;
    722 
    723             case 'c':
    724                 contrast = atoi(cmd + 1);
    725                 params.set(KEY_CONTRAST, contrast);
    726 
    727                 if ( hardwareActive ) {
    728                     camera->setParameters(params.flatten());
    729                 }
    730 
    731                 break;
    732 
    733             case 'z':
    734             case 'Z':
    735 
    736 #if defined(OMAP_ENHANCEMENT) && defined(TARGET_OMAP3)
    737                 params.set(CameraParameters::KEY_ZOOM, atoi(cmd + 1));
    738 #else
    739 
    740                 for(i = 0; i < length_Zoom; i++)
    741                 {
    742                     if( strcmp((cmd + 1), zoom[i].zoom_description) == 0)
    743                     {
    744                         zoomIDX = i;
    745                         break;
    746                     }
    747                 }
    748 
    749                 params.set(CameraParameters::KEY_ZOOM, zoom[zoomIDX].idx);
    750 #endif
    751 
    752                 if ( hardwareActive )
    753                     camera->setParameters(params.flatten());
    754 
    755                 break;
    756 
    757             case 'j':
    758                 params.set(KEY_EXPOSURE, (cmd + 1));
    759 
    760                 if ( hardwareActive )
    761                     camera->setParameters(params.flatten());
    762 
    763                 break;
    764 
    765             case 'b':
    766                 brightness = atoi(cmd + 1);
    767                 params.set(KEY_BRIGHTNESS, brightness);
    768 
    769                 if ( hardwareActive )
    770                     camera->setParameters(params.flatten());
    771 
    772                 break;
    773 
    774             case 's':
    775                 saturation = atoi(cmd + 1);
    776                 params.set(KEY_SATURATION, saturation);
    777 
    778                 if ( hardwareActive )
    779                     camera->setParameters(params.flatten());
    780 
    781                 break;
    782 
    783             case 'e':
    784                 params.set(params.KEY_EFFECT, (cmd + 1));
    785 
    786                 if ( hardwareActive )
    787                     camera->setParameters(params.flatten());
    788 
    789                 break;
    790 
    791             case 'r':
    792 
    793                 frameR = atoi(cmd + 1);
    794 
    795 
    796                 if (camera_index == 0) {
    797                     for (i = 0; i < length_fpsConst_Ranges; i++) {
    798                         if (frameR == fpsConstRanges[i].constFramerate)
    799                             frameRateIndex = i;
    800 
    801                     }
    802                 } else {
    803                     for (i = 0; i < length_fpsConst_RangesSec; i++) {
    804                         if (frameR == fpsConstRangesSec[i].constFramerate)
    805                             frameRateIndex = i;
    806                     }
    807                 }
    808 
    809 
    810                 if (camera_index == 0)
    811                     params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fpsConstRanges[frameRateIndex].range);
    812                 else
    813                     params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fpsConstRangesSec[frameRateIndex].range);
    814 
    815 
    816                 if ( hardwareActive && previewRunning ) {
    817                     camera->stopPreview();
    818                     camera->setParameters(params.flatten());
    819                     camera->startPreview();
    820                 } else if ( hardwareActive ) {
    821                     camera->setParameters(params.flatten());
    822                 }
    823 
    824                 break;
    825 
    826             case 'R':
    827                 for(i = 0; i < length_fps_ranges; i++)
    828                 {
    829                     if( strcmp((cmd + 1), fpsRanges[i].rangeDescription) == 0)
    830                     {
    831                         fpsRangeIdx = i;
    832                         printf("Selected Framerate range: %s\n", fpsRanges[i].rangeDescription);
    833                         if ( hardwareActive ) {
    834                             params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fpsRanges[i].range);
    835                             params.remove(CameraParameters::KEY_PREVIEW_FRAME_RATE);
    836                             camera->setParameters(params.flatten());
    837                         }
    838                         break;
    839                     }
    840                 }
    841                 break;
    842 
    843             case 'x':
    844                 params.set(params.KEY_ANTIBANDING, (cmd + 1));
    845 
    846                 if ( hardwareActive )
    847                     camera->setParameters(params.flatten());
    848 
    849                 break;
    850 
    851             case 'g':
    852                 params.set(params.KEY_FOCUS_MODE, (cmd + 1));
    853 
    854                 if ( hardwareActive )
    855                     camera->setParameters(params.flatten());
    856 
    857                 break;
    858 
    859             case 'G':
    860 
    861                 params.set(CameraParameters::KEY_FOCUS_AREAS, (cmd + 1));
    862 
    863                 if ( hardwareActive )
    864                     camera->setParameters(params.flatten());
    865 
    866                 params.remove(CameraParameters::KEY_FOCUS_AREAS);
    867 
    868             case 'f':
    869                 gettimeofday(&autofocus_start, 0);
    870 
    871                 if ( hardwareActive )
    872                     camera->autoFocus();
    873 
    874                 break;
    875 
    876             case 'p':
    877                 gettimeofday(&picture_start, 0);
    878 
    879                 if ( hardwareActive )
    880                     ret = camera->takePicture(CAMERA_MSG_COMPRESSED_IMAGE|CAMERA_MSG_RAW_IMAGE);
    881 
    882                 if ( ret != NO_ERROR )
    883                     printf("Error returned while taking a picture");
    884                 break;
    885 
    886             case 'd':
    887                 dly = atoi(cmd + 1);
    888                 sleep(dly);
    889                 break;
    890 
    891             case 'q':
    892                 dump_mem_status();
    893                 stopPreview();
    894 
    895                 if ( recordingMode ) {
    896                     stopRecording();
    897                     closeRecorder();
    898 
    899                     recordingMode = false;
    900                 }
    901                 goto exit;
    902 
    903             case '\n':
    904                 printf("Iteration: %d \n", iteration);
    905                 iteration++;
    906                 break;
    907 
    908             case '{':
    909                 if ( atoi(cmd + 1) > 0 )
    910                     params.set(KEY_S3D2D_PREVIEW_MODE, "on");
    911                 else
    912                     params.set(KEY_S3D2D_PREVIEW_MODE, "off");
    913                 if ( hardwareActive )
    914                     camera->setParameters(params.flatten());
    915                 break;
    916 
    917             case 'M':
    918                 params.set(KEY_MEASUREMENT, (cmd + 1));
    919                 if ( hardwareActive )
    920                     camera->setParameters(params.flatten());
    921                 break;
    922             case 'm':
    923             {
    924                 params.set(KEY_METERING_MODE, (cmd + 1));
    925                 if ( hardwareActive )
    926                 {
    927                     camera->setParameters(params.flatten());
    928                 }
    929                 break;
    930             }
    931             case '<':
    932             {
    933                 char coord_str[8];
    934                 latitude += degree_by_step;
    935                 if (latitude > 90.0)
    936                 {
    937                     latitude -= 180.0;
    938                 }
    939                 snprintf(coord_str, 7, "%.7lf", latitude);
    940                 params.set(params.KEY_GPS_LATITUDE, coord_str);
    941                 if ( hardwareActive )
    942                 {
    943                     camera->setParameters(params.flatten());
    944                 }
    945                 break;
    946             }
    947 
    948             case '=':
    949             {
    950                 char coord_str[8];
    951                 longitude += degree_by_step;
    952                 if (longitude > 180.0)
    953                 {
    954                     longitude -= 360.0;
    955                 }
    956                 snprintf(coord_str, 7, "%.7lf", longitude);
    957                 params.set(params.KEY_GPS_LONGITUDE, coord_str);
    958                 if ( hardwareActive )
    959                 {
    960                     camera->setParameters(params.flatten());
    961                 }
    962                 break;
    963             }
    964 
    965             case '>':
    966             {
    967                 char coord_str[8];
    968                 altitude += 12345.67890123456789;
    969                 if (altitude > 100000.0)
    970                 {
    971                     altitude -= 200000.0;
    972                 }
    973                 snprintf(coord_str, 7, "%.7lf", altitude);
    974                 params.set(params.KEY_GPS_ALTITUDE, coord_str);
    975                 if ( hardwareActive )
    976                 {
    977                     camera->setParameters(params.flatten());
    978                 }
    979                 break;
    980             }
    981 
    982             case 'X':
    983             {
    984                 char rem_str[50];
    985                 printf("Deleting images from %s \n", dir_path);
    986                 if(!sprintf(rem_str,"rm %s/*.jpg",dir_path))
    987                     printf("Sprintf Error");
    988                 if(system(rem_str))
    989                     printf("Images were not deleted\n");
    990                 break;
    991             }
    992 
    993             case '_':
    994             {
    995                 AutoConvergenceModeIDX = atoi(cmd + 1);
    996                 if ( AutoConvergenceModeIDX < 0 || AutoConvergenceModeIDX > 4 )
    997                     AutoConvergenceModeIDX = 0;
    998                 params.set(KEY_AUTOCONVERGENCE, autoconvergencemode[AutoConvergenceModeIDX]);
    999                 if ( AutoConvergenceModeIDX != 4 )
   1000                     params.set(KEY_MANUALCONVERGENCE_VALUES, manualconvergencevalues[ManualConvergenceDefaultValueIDX]);
   1001                 if ( hardwareActive )
   1002                     camera->setParameters(params.flatten());
   1003                 break;
   1004             }
   1005 
   1006             case '^':
   1007             {
   1008                 char strtmpval[7];
   1009                 if ( strcmp (autoconvergencemode[AutoConvergenceModeIDX], AUTOCONVERGENCE_MODE_MANUAL) == 0) {
   1010                     sprintf(strtmpval,"%d", atoi(cmd + 1));
   1011                     params.set(KEY_MANUALCONVERGENCE_VALUES, strtmpval);
   1012                     if ( hardwareActive )
   1013                         camera->setParameters(params.flatten());
   1014                 }
   1015                 break;
   1016             }
   1017 
   1018             default:
   1019                 printf("Unrecognized command!\n");
   1020                 break;
   1021         }
   1022 
   1023         cmd = strtok_r(NULL, DELIMITER, &ctx);
   1024     }
   1025 
   1026 exit:
   1027     if (stopScript == true)
   1028       {
   1029         return -1;
   1030       }
   1031     else
   1032       {
   1033         return 0;
   1034       }
   1035 }
   1036 
   1037 
   1038 char * get_cycle_cmd(const char *aSrc) {
   1039     unsigned ind = 0;
   1040     char *cycle_cmd = new char[256];
   1041 
   1042     while ((*aSrc != '+') && (*aSrc != '\0')) {
   1043         cycle_cmd[ind++] = *aSrc++;
   1044     }
   1045     cycle_cmd[ind] = '\0';
   1046 
   1047     return cycle_cmd;
   1048 }
   1049 
   1050 status_t dump_mem_status() {
   1051   system(MEDIASERVER_DUMP);
   1052   return system(MEMORY_DUMP);
   1053 }
   1054 
   1055 char *load_script(char *config) {
   1056     FILE *infile;
   1057     size_t fileSize;
   1058     char *script;
   1059     size_t nRead = 0;
   1060     char dir_name[40];
   1061     size_t count;
   1062     char rCount [5];
   1063 
   1064     count = 0;
   1065 
   1066     infile = fopen(config, "r");
   1067 
   1068     strcpy(script_name,config);
   1069 
   1070     // remove just the '.txt' part of the config
   1071     while((config[count] != '.') && (count < sizeof(dir_name)/sizeof(dir_name[0])))
   1072         count++;
   1073 
   1074     printf("\n SCRIPT : <%s> is currently being executed \n",script_name);
   1075     if(strncpy(dir_name,config,count) == NULL)
   1076         printf("Strcpy error");
   1077 
   1078     dir_name[count]=NULL;
   1079 
   1080     if(strcat(dir_path,dir_name) == NULL)
   1081         printf("Strcat error");
   1082 
   1083     if(restartCount)
   1084     {
   1085       sprintf(rCount,"_%d",restartCount);
   1086       if(strcat(dir_path, rCount) == NULL)
   1087         printf("Strcat error RestartCount");
   1088     }
   1089 
   1090     printf("\n COMPLETE FOLDER PATH : %s \n",dir_path);
   1091     if(mkdir(dir_path,0777) == -1) {
   1092         printf("\n Directory %s was not created \n",dir_path);
   1093     } else {
   1094         printf("\n Directory %s was created \n",dir_path);
   1095     }
   1096     printf("\n DIRECTORY CREATED FOR TEST RESULT IMAGES IN MMC CARD : %s \n",dir_name);
   1097 
   1098     if( (NULL == infile)){
   1099         printf("Error while opening script file %s!\n", config);
   1100         return NULL;
   1101     }
   1102 
   1103     fseek(infile, 0, SEEK_END);
   1104     fileSize = ftell(infile);
   1105     fseek(infile, 0, SEEK_SET);
   1106 
   1107     script = (char *) malloc(fileSize);
   1108 
   1109     if ( NULL == script ) {
   1110         printf("Unable to allocate buffer for the script\n");
   1111 
   1112         return NULL;
   1113     }
   1114 
   1115     if ((nRead = fread(script, 1, fileSize, infile)) != fileSize) {
   1116         printf("Error while reading script file!\n");
   1117 
   1118         free(script);
   1119         fclose(infile);
   1120         return NULL;
   1121     }
   1122 
   1123     fclose(infile);
   1124 
   1125     return script;
   1126 }
   1127 
   1128 int start_logging(char *config, int &pid) {
   1129     char dir_name[40];
   1130     size_t count = 0;
   1131     int status = 0;
   1132 
   1133     // remove just the '.txt' part of the config
   1134     while((config[count] != '.') && (count < sizeof(dir_name)/sizeof(dir_name[0])))
   1135         count++;
   1136 
   1137     if(strncpy(dir_name,config,count) == NULL)
   1138         printf("Strcpy error");
   1139 
   1140     dir_name[count]=NULL;
   1141 
   1142     pid = fork();
   1143     if (pid == 0)
   1144     {
   1145         char *command_list[] = {"sh", "-c", NULL, NULL};
   1146         char log_cmd[120];
   1147         // child process to run logging
   1148 
   1149         // set group id of this process to itself
   1150         // we will use this group id to kill the
   1151         // application logging
   1152         setpgid(getpid(), getpid());
   1153 
   1154         /* Start logcat */
   1155         if(!sprintf(log_cmd,"logcat > /sdcard/%s/log.txt &",dir_name))
   1156             printf(" Sprintf Error");
   1157 
   1158         /* Start Syslink Trace */
   1159         if(bLogSysLinkTrace) {
   1160             if(!sprintf(log_cmd,"%s /system/bin/syslink_trace_daemon.out -l /sdcard/%s/syslink_trace.txt -f &",log_cmd, dir_name))
   1161                 printf(" Sprintf Error");
   1162         }
   1163 
   1164         command_list[2] = (char *)log_cmd;
   1165         execvp("/system/bin/sh", command_list);
   1166     } if(pid < 0)
   1167     {
   1168         printf("failed to fork logcat\n");
   1169         return -1;
   1170     }
   1171 
   1172     //wait for logging to start
   1173     if(waitpid(pid, &status, 0) != pid)
   1174     {
   1175         printf("waitpid failed in log fork\n");
   1176         return -1;
   1177     }else
   1178         printf("logging started... status=%d\n", status);
   1179 
   1180     return 0;
   1181 }
   1182 
   1183 int stop_logging(int &pid)
   1184 {
   1185     if(pid > 0)
   1186     {
   1187         if(killpg(pid, SIGKILL))
   1188         {
   1189             printf("Exit command failed");
   1190             return -1;
   1191         } else {
   1192             printf("\nlogging for script %s is complete\n   logcat saved @ location: %s\n",script_name,dir_path);
   1193             if (bLogSysLinkTrace)
   1194                 printf("   syslink_trace is saved @ location: %s\n\n",dir_path);
   1195         }
   1196     }
   1197     return 0;
   1198 }
   1199 
   1200 int execute_error_script(char *script) {
   1201     char *cmd, *ctx;
   1202     char id;
   1203     status_t stat = NO_ERROR;
   1204 
   1205     LOG_FUNCTION_NAME;
   1206 
   1207     cmd = strtok_r((char *) script, DELIMITER, &ctx);
   1208 
   1209     while ( NULL != cmd ) {
   1210         id = cmd[0];
   1211 
   1212         switch (id) {
   1213 
   1214             case '0': {
   1215                 bufferStarvationTest = 1;
   1216                 params.set(KEY_BUFF_STARV, bufferStarvationTest); //enable buffer starvation
   1217 
   1218                 if ( !recordingMode ) {
   1219 
   1220                     recordingMode = true;
   1221 
   1222                     if ( startPreview() < 0 ) {
   1223                         printf("Error while starting preview\n");
   1224 
   1225                         return -1;
   1226                     }
   1227 
   1228                     if ( openRecorder() < 0 ) {
   1229                         printf("Error while openning video recorder\n");
   1230 
   1231                         return -1;
   1232                     }
   1233 
   1234                     if ( configureRecorder() < 0 ) {
   1235                         printf("Error while configuring video recorder\n");
   1236 
   1237                         return -1;
   1238                     }
   1239 
   1240                     if ( startRecording() < 0 ) {
   1241                         printf("Error while starting video recording\n");
   1242 
   1243                         return -1;
   1244                     }
   1245 
   1246                 }
   1247 
   1248                 usleep(1000000);//1s
   1249 
   1250                 stopPreview();
   1251 
   1252                 if ( recordingMode ) {
   1253                     stopRecording();
   1254                     closeRecorder();
   1255 
   1256                     recordingMode = false;
   1257                 }
   1258 
   1259                 break;
   1260             }
   1261 
   1262             case '1': {
   1263                 int* tMemoryEater = new int[999999999];
   1264 
   1265                 if (!tMemoryEater) {
   1266                     printf("Not enough memory\n");
   1267                     return -1;
   1268                 } else {
   1269                     delete tMemoryEater;
   1270                 }
   1271 
   1272                 break;
   1273             }
   1274 
   1275             case '2': {
   1276                 //camera = Camera::connect();
   1277 
   1278                 if ( NULL == camera.get() ) {
   1279                     printf("Unable to connect to CameraService\n");
   1280                     return -1;
   1281                 }
   1282 
   1283                 break;
   1284             }
   1285 
   1286             case '3': {
   1287                 int err = 0;
   1288 
   1289                 err = open("/dev/video5", O_RDWR);
   1290 
   1291                 if (err < 0) {
   1292                     printf("Could not open the camera device5: %d\n",  err );
   1293                     return err;
   1294                 }
   1295 
   1296                 if ( startPreview() < 0 ) {
   1297                     printf("Error while starting preview\n");
   1298                     return -1;
   1299                 }
   1300 
   1301                 usleep(1000000);//1s
   1302 
   1303                 stopPreview();
   1304 
   1305                 close(err);
   1306                 break;
   1307             }
   1308 
   1309             case '4': {
   1310 
   1311                 if ( hardwareActive ) {
   1312 
   1313                     params.setPictureFormat("invalid-format");
   1314                     params.setPreviewFormat("invalid-format");
   1315 
   1316                     stat = camera->setParameters(params.flatten());
   1317 
   1318                     if ( NO_ERROR != stat ) {
   1319                         printf("Test passed!\n");
   1320                     } else {
   1321                         printf("Test failed!\n");
   1322                     }
   1323 
   1324                     initDefaults();
   1325                 }
   1326 
   1327                 break;
   1328             }
   1329 
   1330             case '5': {
   1331 
   1332                 if ( hardwareActive ) {
   1333 
   1334                     params.setPictureSize(-1, -1);
   1335                     params.setPreviewSize(-1, -1);
   1336 
   1337                     stat = camera->setParameters(params.flatten());
   1338 
   1339                     if ( NO_ERROR != stat ) {
   1340                         printf("Test passed!\n");
   1341                     } else {
   1342                         printf("Test failed!\n");
   1343                     }
   1344 
   1345                     initDefaults();
   1346                 }
   1347 
   1348                 break;
   1349             }
   1350 
   1351             case '6': {
   1352 
   1353                 if ( hardwareActive ) {
   1354 
   1355                     params.setPreviewFrameRate(-1);
   1356 
   1357                     stat = camera->setParameters(params.flatten());
   1358 
   1359                     if ( NO_ERROR != stat ) {
   1360                         printf("Test passed!\n");
   1361                     } else {
   1362                         printf("Test failed!\n");
   1363                     }
   1364 
   1365                     initDefaults();
   1366                 }
   1367 
   1368 
   1369                 break;
   1370             }
   1371 
   1372             case 'q': {
   1373                 goto exit;
   1374 
   1375                 break;
   1376             }
   1377 
   1378             default: {
   1379                 printf("Unrecognized command!\n");
   1380 
   1381                 break;
   1382             }
   1383         }
   1384 
   1385         cmd = strtok_r(NULL, DELIMITER, &ctx);
   1386     }
   1387 
   1388 exit:
   1389 
   1390     return 0;
   1391 }
   1392 
   1393 
   1394 
   1395