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 <camera/Camera.h>
     11 #include <camera/ICamera.h>
     12 #include <media/mediarecorder.h>
     13 
     14 #include <binder/IPCThreadState.h>
     15 #include <binder/ProcessState.h>
     16 #include <binder/IServiceManager.h>
     17 #include <cutils/properties.h>
     18 #include <camera/CameraParameters.h>
     19 #include <camera/ShotParameters.h>
     20 
     21 #include <sys/wait.h>
     22 
     23 #include "camera_test.h"
     24 #include "camera_test_surfacetexture.h"
     25 #ifdef ANDROID_API_JB_OR_LATER
     26 #include "camera_test_bufferqueue.h"
     27 #endif
     28 
     29 using namespace android;
     30 
     31 extern bool stopScript;
     32 extern bool hardwareActive;
     33 extern sp<Camera> camera;
     34 extern sp<BufferSourceThread> bufferSourceOutputThread;
     35 extern sp<BufferSourceInput> bufferSourceInput;
     36 extern CameraParameters params;
     37 extern ShotParameters shotParams;
     38 extern bool shotConfigFlush;
     39 extern bool streamCapture;
     40 extern bool recordingMode;
     41 extern int camera_index;
     42 extern int rotation;
     43 extern int previewRotation;
     44 extern const param_Array captureSize[];
     45 extern const param_Array VcaptureSize[];
     46 extern const outformat outputFormat[];
     47 extern const video_Codecs videoCodecs[];
     48 extern const audio_Codecs audioCodecs[];
     49 extern const V_bitRate VbitRate[];
     50 extern const Zoom zoom [];
     51 extern int previewSizeIDX;
     52 extern bool reSizePreview;
     53 extern bool previewRunning;
     54 extern int captureSizeIDX;
     55 extern float compensation;
     56 extern int videoCodecIDX;
     57 extern int outputFormatIDX;
     58 extern int audioCodecIDX;
     59 extern int VcaptureSizeIDX;
     60 extern int VbitRateIDX;
     61 extern int thumbSizeIDX;
     62 extern int thumbQuality;
     63 extern int jpegQuality;
     64 extern int dump_preview;
     65 extern int ippIDX_old;
     66 extern const char *capture[];
     67 extern int capture_mode;
     68 extern int ippIDX;
     69 extern const char *ipp_mode[];
     70 extern int tempBracketRange;
     71 extern int iso_mode;
     72 extern int sharpness;
     73 extern int contrast;
     74 extern int zoomIDX;
     75 extern int brightness;
     76 extern int saturation;
     77 extern int fpsRangeIdx;
     78 extern int numAntibanding;
     79 extern int numEffects;
     80 extern int numawb;
     81 extern int numExposureMode;
     82 extern int numscene;
     83 extern int numisoMode;
     84 extern int numflash;
     85 extern int numcaptureSize;
     86 extern int numVcaptureSize;
     87 extern int numpreviewSize;
     88 extern int numthumbnailSize;
     89 extern int numfocus;
     90 extern int numpreviewFormat;
     91 extern int numpictureFormat;
     92 extern int nummodevalues;
     93 extern int numLay;
     94 extern int numCLay;
     95 extern int constCnt;
     96 extern int rangeCnt;
     97 extern int * constFramerate;
     98 extern int frameRateIDX;
     99 extern int fpsRangeIdx;
    100 extern int stereoLayoutIDX;
    101 extern int stereoCapLayoutIDX;
    102 extern int expBracketIdx;
    103 int resol_index = 0;
    104 int a = 0;
    105 extern char * vstabstr;
    106 extern char * vnfstr;
    107 extern char * zoomstr;
    108 extern char * smoothzoomstr;
    109 extern char * videosnapshotstr;
    110 extern char ** antiband;
    111 extern char **effectss;
    112 extern bool firstTime;
    113 extern char **exposureMode;
    114 extern char **awb;
    115 extern char **scene;
    116 extern char ** isoMode;
    117 extern char ** modevalues;
    118 extern char **focus;
    119 extern char **flash;
    120 extern char **previewFormatArray;
    121 extern char **pictureFormatArray;
    122 extern char ** fps_const_str;
    123 extern char ** fps_range_str;
    124 extern char ** rangeDescription;
    125 extern param_Array ** capture_Array;
    126 extern param_Array ** Vcapture_Array;
    127 extern param_Array ** preview_Array;
    128 extern param_Array ** thumbnail_Array;
    129 extern timeval autofocus_start, picture_start;
    130 extern const char *cameras[];
    131 extern double latitude;
    132 extern double degree_by_step;
    133 extern double longitude;
    134 extern double altitude;
    135 extern char output_dir_path[];
    136 extern char images_dir_path[];
    137 extern int AutoConvergenceModeIDX;
    138 extern const char *autoconvergencemode[];
    139 extern int numCamera;
    140 extern bool stereoMode;
    141 extern char script_name[];
    142 extern int bufferStarvationTest;
    143 extern size_t length_previewSize;
    144 extern size_t length_thumbnailSize;
    145 extern size_t lenght_Vcapture_size;
    146 extern size_t length_outformat;
    147 extern size_t length_capture_Size;
    148 extern size_t length_video_Codecs;
    149 extern size_t length_audio_Codecs;
    150 extern size_t length_V_bitRate;
    151 extern size_t length_Zoom;
    152 extern size_t length_fps_ranges;
    153 extern size_t length_fpsConst_Ranges;
    154 extern size_t length_fpsConst_RangesSec;
    155 extern int platformID;
    156 extern char **stereoLayout;
    157 extern char **stereoCapLayout;
    158 extern void getSizeParametersFromCapabilities();
    159 extern int exposure_mode;
    160 int manE = 0;
    161 extern int manualExp ;
    162 extern int manualExpMin ;
    163 extern int manualExpMax ;
    164 int manG = 0;
    165 extern int manualGain ;
    166 extern int manualGainMin ;
    167 extern int manualGainMax ;
    168 int manC = 0;
    169 extern int manualConv ;
    170 extern int manualConvMin ;
    171 extern int manualConvMax ;
    172 extern bool faceDetectToggle;
    173 extern unsigned int burstCount;
    174 
    175 /** Buffer source reset */
    176 extern bool bufferSourceInputReset;
    177 extern bool bufferSourceOutputReset;
    178 
    179 void trim_script_cmd(char *cmd) {
    180     char *nl, *cr;
    181 
    182     // first remove all carriage return symbols
    183     while ( NULL != (cr = strchr(cmd, '\r'))) {
    184         for (char *c = cr; '\0' != *c; c++) {
    185             *c = *(c+1);
    186         }
    187     }
    188 
    189     // then remove all single line feed symbols
    190     while ( NULL != (nl = strchr(cmd, '\n'))) {
    191         if (*nl == *(nl+1)) {
    192             // two or more concatenated newlines:
    193             // end of script found
    194             break;
    195         }
    196         // clip the newline
    197         for (char *c = nl; '\0' != *c; c++) {
    198             *c = *(c+1);
    199         }
    200     }
    201 }
    202 
    203 int execute_functional_script(char *script) {
    204     char *cmd, *ctx, *cycle_cmd, *temp_cmd;
    205     char id;
    206     unsigned int i;
    207     int dly;
    208     int cycleCounter = 1;
    209     int tLen = 0;
    210     unsigned int iteration = 0;
    211     bool zoomtoggle = false;
    212     bool smoothzoomtoggle = false;
    213     status_t ret = NO_ERROR;
    214     //int frameR = 20;
    215     int frameRConst = 0;
    216     int frameRRange = 0;
    217     struct CameraInfo cameraInfo;
    218     bool queueEmpty = true;
    219 
    220     LOG_FUNCTION_NAME;
    221 
    222     dump_mem_status();
    223 
    224     cmd = strtok_r((char *) script, DELIMITER, &ctx);
    225 
    226     while ( NULL != cmd && (stopScript == false)) {
    227         trim_script_cmd(cmd);
    228         id = cmd[0];
    229         printf("Full Command: %s \n", cmd);
    230         printf("Command: %c \n", cmd[0]);
    231 
    232         switch (id) {
    233 
    234             // Case for Suspend-Resume Feature
    235             case '!': {
    236                 // STEP 1: Mount Debugfs
    237                 system("mkdir /debug");
    238                 system("mount -t debugfs debugfs /debug");
    239 
    240                 // STEP 2: Set up wake up Timer - wake up happens after 5 seconds
    241                 system("echo 10 > /debug/pm_debug/wakeup_timer_seconds");
    242 
    243                 // STEP 3: Make system ready for Suspend
    244                 system("echo camerahal_test > /sys/power/wake_unlock");
    245                 // Release wake lock held by test app
    246                 printf(" Wake lock released ");
    247                 system("cat /sys/power/wake_lock");
    248                 system("sendevent /dev/input/event0 1 60 1");
    249                 system("sendevent /dev/input/event0 1 60 0");
    250                 // Simulate F2 key press to make display OFF
    251                 printf(" F2 event simulation complete ");
    252 
    253                 //STEP 4: Wait for system Resume and then simuate F1 key
    254                 sleep(50);//50s  // This delay is not related to suspend resume timer
    255                 printf(" After 30 seconds of sleep");
    256                 system("sendevent /dev/input/event0 1 59 0");
    257                 system("sendevent /dev/input/event0 1 59 1");
    258                 // Simulate F1 key press to make display ON
    259                 system("echo camerahal_test > /sys/power/wake_lock");
    260                 // Acquire wake lock for test app
    261 
    262                 break;
    263             }
    264 
    265             case '[':
    266                 if ( hardwareActive )
    267                     {
    268 
    269                     camera->setParameters(params.flatten());
    270 
    271                     printf("starting camera preview..");
    272                     status_t ret = camera->startPreview();
    273                     if(ret !=NO_ERROR)
    274                         {
    275                         printf("startPreview failed %d..", ret);
    276                         }
    277                     }
    278                 break;
    279             case '+': {
    280                 cycleCounter = atoi(cmd + 1);
    281                 cycle_cmd = get_cycle_cmd(ctx);
    282                 tLen = strlen(cycle_cmd);
    283                 temp_cmd = new char[tLen+1];
    284 
    285                 for (int ind = 0; ind < cycleCounter; ind++) {
    286                     strcpy(temp_cmd, cycle_cmd);
    287                     if ( execute_functional_script(temp_cmd) != 0 )
    288                       return -1;
    289                     temp_cmd[0] = '\0';
    290 
    291                     //patch for image capture
    292                     //[
    293                     if (ind < cycleCounter - 1) {
    294                         if (hardwareActive == false) {
    295                             if ( openCamera() < 0 ) {
    296                                 printf("Camera initialization failed\n");
    297 
    298                                 return -1;
    299                             }
    300 
    301                             initDefaults();
    302                         }
    303                     }
    304 
    305                     //]
    306                 }
    307 
    308                 ctx += tLen + 1;
    309 
    310                 if (temp_cmd) {
    311                     delete temp_cmd;
    312                     temp_cmd = NULL;
    313                 }
    314 
    315                 if (cycle_cmd) {
    316                     delete cycle_cmd;
    317                     cycle_cmd = NULL;
    318                 }
    319 
    320                 break;
    321             }
    322 
    323             case '0':
    324             {
    325                 initDefaults();
    326                 break;
    327             }
    328 
    329             case '1':
    330 
    331                 if ( startPreview() < 0 ) {
    332                     printf("Error while starting preview\n");
    333 
    334                     return -1;
    335                 }
    336 
    337                 break;
    338 
    339             case '2':
    340                 if ( recordingMode ) {
    341                     stopRecording();
    342                     stopPreview();
    343                     closeRecorder();
    344                     camera->disconnect();
    345                     camera.clear();
    346                     camera = Camera::connect(camera_index);
    347                       if ( NULL == camera.get() ) {
    348                           sleep(1);
    349                           camera = Camera::connect(camera_index);
    350                           if ( NULL == camera.get() ) {
    351                               return -1;
    352                           }
    353                       }
    354                       camera->setListener(new CameraHandler());
    355                       camera->setParameters(params.flatten());
    356                       recordingMode = false;
    357                 } else {
    358                     stopPreview();
    359                 }
    360 
    361                 break;
    362 
    363             case '3':
    364                 rotation = atoi(cmd + 1);
    365                 params.set(CameraParameters::KEY_ROTATION, rotation);
    366 
    367                 if ( hardwareActive )
    368                     camera->setParameters(params.flatten());
    369 
    370                 break;
    371 
    372             case 'V':
    373                 previewRotation = atoi(cmd + 1);
    374                 params.set(KEY_SENSOR_ORIENTATION, previewRotation);
    375 
    376                 if ( hardwareActive )
    377                     camera->setParameters(params.flatten());
    378 
    379                 break;
    380 
    381             case '4':
    382                 printf("Setting resolution...");
    383 
    384                 a = checkSupportedParamScriptResol(preview_Array, numpreviewSize, cmd, &resol_index);
    385                 if (a > -1) {
    386                     params.setPreviewSize(preview_Array[resol_index]->width, preview_Array[resol_index]->height);
    387                     previewSizeIDX = resol_index;
    388                 } else {
    389                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    390                 }
    391                 if ( hardwareActive && previewRunning ) {
    392                     camera->stopPreview();
    393                     camera->setParameters(params.flatten());
    394                     camera->startPreview();
    395                 } else if ( hardwareActive ) {
    396                     camera->setParameters(params.flatten());
    397                 }
    398                 break;
    399 
    400             case '5':
    401                 if( strcmp((cmd + 1), "MAX_CAPTURE_SIZE") == 0) {
    402                     resol_index = 0;
    403                     for (int i=0; i<numcaptureSize; i++) {
    404                         if ((capture_Array[resol_index]->width * capture_Array[resol_index]->height) < (capture_Array[i]->width * capture_Array[i]->height)) {
    405                             resol_index = i;
    406                         }
    407                     }
    408                     if ((0 < capture_Array[resol_index]->width) && (0 < capture_Array[resol_index]->height)) {
    409                         params.setPictureSize(capture_Array[resol_index]->width, capture_Array[resol_index]->height);
    410                         captureSizeIDX = resol_index;
    411                         printf("Capture Size set: %dx%d\n", capture_Array[resol_index]->width, capture_Array[resol_index]->height);
    412                     } else {
    413                         printf("\nCapture size is 0!\n");
    414                     }
    415                 } else {
    416                     a = checkSupportedParamScriptResol(capture_Array, numcaptureSize, cmd, &resol_index);
    417                     if (camera_index != 2) {
    418                         if (a > -1) {
    419                             params.setPictureSize(capture_Array[resol_index]->width, capture_Array[resol_index]->height);
    420                             captureSizeIDX = resol_index;
    421                         } else {
    422                             printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    423                         }
    424                     } else {
    425                         int widthC, heightC;
    426                         char *resC = NULL;
    427                         resC = strtok(cmd + 1, "x");
    428                         widthC = atoi(resC);
    429                         resC = strtok(NULL, "x");
    430                         heightC = atoi(resC);
    431                         params.setPictureSize(widthC,heightC);
    432                     a = checkSupportedParamScriptResol(capture_Array, numcaptureSize,
    433                                                        widthC, heightC, &resol_index);
    434                     if (a > -1) captureSizeIDX = resol_index;
    435                     }
    436 
    437                     if ( hardwareActive ) {
    438                         camera->setParameters(params.flatten());
    439                     }
    440                 }
    441 
    442                 requestBufferSourceReset();
    443 
    444                 break;
    445 
    446             case '6':
    447 
    448                 if ( !recordingMode ) {
    449 
    450                     recordingMode = true;
    451 
    452                     if ( startPreview() < 0 ) {
    453                         printf("Error while starting preview\n");
    454 
    455                         return -1;
    456                     }
    457 
    458                     if ( openRecorder() < 0 ) {
    459                         printf("Error while openning video recorder\n");
    460 
    461                         return -1;
    462                     }
    463 
    464                     if ( configureRecorder() < 0 ) {
    465                         printf("Error while configuring video recorder\n");
    466 
    467                         return -1;
    468                     }
    469 
    470                     if ( startRecording() < 0 ) {
    471                         printf("Error while starting video recording\n");
    472 
    473                         return -1;
    474                     }
    475 
    476                 }
    477 
    478                 break;
    479 
    480             case '7':
    481                 compensation = atof(cmd + 1);
    482                 params.set(KEY_COMPENSATION, (int) (compensation * 10));
    483 
    484                 if ( hardwareActive )
    485                     camera->setParameters(params.flatten());
    486 
    487                 break;
    488 
    489             case '8':
    490 
    491                 a = checkSupportedParamScript(awb, numawb, cmd);
    492                 if (a > -1) {
    493                     params.set(params.KEY_WHITE_BALANCE, (cmd + 1));
    494                 } else {
    495                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    496                 }
    497 
    498                 if ( hardwareActive )
    499                     camera->setParameters(params.flatten());
    500 
    501                 break;
    502 
    503             case '9':
    504                 for(i = 0; i < length_video_Codecs; i++)
    505                 {
    506                     if( strcmp((cmd + 1), videoCodecs[i].desc) == 0)
    507                     {
    508                         videoCodecIDX = i;
    509                         printf("Video Codec Selected: %s\n",
    510                                 videoCodecs[i].desc);
    511                         break;
    512                     }
    513                 }
    514                 break;
    515 
    516             case 'v':
    517                 for(i = 0; i < length_outformat; i++)
    518 
    519                 {
    520                     if( strcmp((cmd + 1), outputFormat[i].desc) == 0)
    521                     {
    522                         outputFormatIDX = i;
    523                         printf("Video Codec Selected: %s\n",
    524                                 videoCodecs[i].desc);
    525                         break;
    526                     }
    527                 }
    528             break;
    529 
    530             case '~':
    531 
    532                 a = checkSupportedParamScript(previewFormatArray, numpreviewFormat, cmd);
    533                 if (a > -1) {
    534                     params.setPreviewFormat(cmd + 1);
    535                 } else {
    536                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    537                 }
    538 
    539                 if ( hardwareActive )
    540                     camera->setParameters(params.flatten());
    541 
    542                 break;
    543 
    544             case '$':
    545 
    546                 a = checkSupportedParamScript(pictureFormatArray, numpictureFormat, cmd);
    547                 if (a > -1) {
    548                     params.setPictureFormat(cmd + 1);
    549                 } else {
    550                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    551                 }
    552 
    553                 queueEmpty = true;
    554                 if ( bufferSourceOutputThread.get() ) {
    555                     if ( 0 < bufferSourceOutputThread->hasBuffer() ) {
    556                         queueEmpty = false;
    557                     }
    558                 }
    559                 if ( hardwareActive && queueEmpty ) {
    560                     camera->setParameters(params.flatten());
    561                 }
    562 
    563                 break;
    564             case '-':
    565                 for(i = 0; i < length_audio_Codecs; i++)
    566                 {
    567                     if( strcmp((cmd + 1), audioCodecs[i].desc) == 0)
    568                     {
    569                         audioCodecIDX = i;
    570                         printf("Selected Audio: %s\n", audioCodecs[i].desc);
    571                         break;
    572                     }
    573                 }
    574                 break;
    575 
    576             case 'A':
    577                 camera_index=atoi(cmd+1);
    578                 camera_index %= numCamera;
    579 
    580                 printf("%s selected.\n", cameras[camera_index]);
    581                 firstTime = true;
    582 
    583                 if ( hardwareActive ) {
    584                     stopPreview();
    585                     closeCamera();
    586                     openCamera();
    587                 } else {
    588                     closeCamera();
    589                     openCamera();
    590                 }
    591                 break;
    592 
    593             case 'a':
    594                 char * temp_str;
    595 
    596                 temp_str = strtok(cmd+1,"!");
    597                 printf("Latitude %s \n",temp_str);
    598                 params.set(params.KEY_GPS_LATITUDE, temp_str);
    599                 temp_str=strtok(NULL,"!");
    600                 printf("Longitude %s \n",temp_str);
    601                 params.set(params.KEY_GPS_LONGITUDE, temp_str);
    602                 temp_str=strtok(NULL,"!");
    603                 printf("Altitude %s \n",temp_str);
    604                 params.set(params.KEY_GPS_ALTITUDE, temp_str);
    605 
    606                 if ( hardwareActive )
    607                     camera->setParameters(params.flatten());
    608                 break;
    609 
    610             case 'l':
    611                 a = checkSupportedParamScriptResol(Vcapture_Array, numVcaptureSize, cmd, &resol_index);
    612                 if (a > -1) {
    613                     VcaptureSizeIDX = resol_index;
    614                 } else {
    615                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    616                 }
    617                 break;
    618 
    619             case 'L':
    620                 if(stereoMode)
    621                 {
    622                     a = checkSupportedParamScriptLayout(stereoLayout, numLay, cmd, &stereoLayoutIDX);
    623                     if (a > -1) {
    624                         params.set(KEY_S3D_PRV_FRAME_LAYOUT, cmd + 1);
    625                     } else {
    626                         printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    627                     }
    628 
    629 
    630                     getSizeParametersFromCapabilities();
    631                     if (hardwareActive && previewRunning) {
    632                         stopPreview();
    633                         camera->setParameters(params.flatten());
    634                         startPreview();
    635                     } else if (hardwareActive) {
    636                         camera->setParameters(params.flatten());
    637                     }
    638                 }
    639                 break;
    640 
    641 
    642             case '.':
    643                 if(stereoMode)
    644                 {
    645                     a = checkSupportedParamScriptLayout(stereoCapLayout, numCLay, cmd, &stereoCapLayoutIDX);
    646                     if (a > -1) {
    647                         params.set(KEY_S3D_CAP_FRAME_LAYOUT_VALUES, cmd + 1);
    648                     } else {
    649                         printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    650                     }
    651 
    652 
    653                     getSizeParametersFromCapabilities();
    654                     if (hardwareActive && previewRunning) {
    655                         stopPreview();
    656                         camera->setParameters(params.flatten());
    657                         startPreview();
    658                     } else if (hardwareActive) {
    659                         camera->setParameters(params.flatten());
    660                     }
    661                 }
    662                 break;
    663 
    664             case ']':
    665                 for(i = 0; i < length_V_bitRate; i++)
    666                 {
    667                     if( strcmp((cmd + 1), VbitRate[i].desc) == 0)
    668                     {
    669                         VbitRateIDX = i;
    670                         printf("Video Bit Rate: %s\n", VbitRate[i].desc);
    671                         break;
    672                     }
    673                 }
    674                 break;
    675             case ':':
    676 
    677                 a = checkSupportedParamScriptResol(thumbnail_Array, numthumbnailSize, cmd, &resol_index);
    678                 if (a > -1) {
    679                     params.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, thumbnail_Array[resol_index]->width);
    680                     params.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT,thumbnail_Array[resol_index]->height);
    681                     thumbSizeIDX = resol_index;
    682                 } else {
    683                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    684                 }
    685 
    686                 if ( hardwareActive ) {
    687                     camera->setParameters(params.flatten());
    688                 }
    689 
    690 
    691                 break;
    692 
    693             case '\'':
    694                 thumbQuality = atoi(cmd + 1);
    695 
    696                 params.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, thumbQuality);
    697                 if ( hardwareActive )
    698                     camera->setParameters(params.flatten());
    699                 break;
    700 
    701             case '*':
    702                 if ( hardwareActive )
    703                     camera->startRecording();
    704                 break;
    705 
    706             case 't':
    707                 params.setPreviewFormat((cmd + 1));
    708                 if ( hardwareActive )
    709                     camera->setParameters(params.flatten());
    710                 break;
    711 
    712             case 'o':
    713                 jpegQuality = atoi(cmd + 1);
    714                 params.set(CameraParameters::KEY_JPEG_QUALITY, jpegQuality);
    715 
    716                 if ( hardwareActive )
    717                     camera->setParameters(params.flatten());
    718 
    719                 break;
    720 
    721 
    722             case '&':
    723                 printf("Enabling Preview Callback");
    724                 dump_preview = 1;
    725                 camera->setPreviewCallbackFlags(CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK);
    726                 break;
    727 
    728 
    729             case 'k':
    730                 ippIDX_old = atoi(cmd + 1);
    731                 params.set(KEY_IPP, atoi(cmd + 1));
    732                 if ( hardwareActive )
    733                     camera->setParameters(params.flatten());
    734 
    735                 requestBufferSourceReset();
    736 
    737                 break;
    738 
    739             case 'K':
    740                 params.set(KEY_GBCE, (cmd+1));
    741                 if ( hardwareActive )
    742                     camera->setParameters(params.flatten());
    743 
    744                 break;
    745 
    746             case 'F':
    747                 if ( hardwareActive ) {
    748                     camera->sendCommand(CAMERA_CMD_START_FACE_DETECTION, 0, 0);
    749                     faceDetectToggle = true;
    750                 }
    751 
    752                 break;
    753 
    754             case 'I':
    755                 params.set(KEY_AF_TIMEOUT, (cmd + 1));
    756 
    757                 if ( hardwareActive )
    758                     camera->setParameters(params.flatten());
    759 
    760                 break;
    761 
    762             case 'T':
    763 
    764                 if ( hardwareActive ) {
    765                     camera->sendCommand(CAMERA_CMD_STOP_FACE_DETECTION, 0, 0);
    766                     faceDetectToggle = false;
    767                 }
    768 
    769                 break;
    770 
    771             case 'O':
    772                 params.set(KEY_GLBCE, (cmd+1));
    773                 if ( hardwareActive )
    774                     camera->setParameters(params.flatten());
    775 
    776                 break;
    777 
    778             case 'u':
    779                 // HQ should always be in ldc-nsf
    780                 // if not HQ, then return the ipp to its previous state
    781                 if ( !strcmp((cmd + 1), "high-quality") ) {
    782                     ippIDX_old = ippIDX;
    783                     ippIDX = 3;
    784                     params.set(KEY_IPP, ipp_mode[ippIDX]);
    785                     params.set(CameraParameters::KEY_RECORDING_HINT, CameraParameters::FALSE);
    786                     previewRotation = 0;
    787                     params.set(KEY_SENSOR_ORIENTATION, previewRotation);
    788                 } else if ( !strcmp((cmd + 1), "video-mode") ) {
    789                     params.set(CameraParameters::KEY_RECORDING_HINT, CameraParameters::TRUE);
    790                     camera->getCameraInfo(camera_index, &cameraInfo);
    791                     previewRotation = ((360-cameraInfo.orientation)%360);
    792                     if (previewRotation >= 0 || previewRotation <=360) {
    793                         params.set(KEY_SENSOR_ORIENTATION, previewRotation);
    794                     }
    795                     printf("previewRotation: %d\n", previewRotation);
    796                 } else {
    797                     ippIDX = ippIDX_old;
    798                     params.set(CameraParameters::KEY_RECORDING_HINT, CameraParameters::FALSE);
    799                     previewRotation = 0;
    800                     params.set(KEY_SENSOR_ORIENTATION, previewRotation);
    801                 }
    802                 a = checkSupportedParamScript(modevalues, nummodevalues, cmd);
    803                 if (a > -1) {
    804                     params.set(KEY_MODE, (cmd + 1));
    805                 } else {
    806                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    807                 }
    808 
    809                 if ( hardwareActive ) {
    810                     if (previewRunning) {
    811                         stopPreview();
    812                     }
    813                     camera->setParameters(params.flatten());
    814                     // Get parameters from capabilities for the new capture mode
    815                     params = camera->getParameters();
    816                     getSizeParametersFromCapabilities();
    817                     getParametersFromCapabilities();
    818                     // Set framerate 30fps and 12MP capture resolution if available for the new capture mode.
    819                     // If not available set framerate and capture mode under index 0 from fps_const_str and capture_Array.
    820                     frameRateIDX = getDefaultParameter("30000,30000", constCnt, fps_const_str);
    821                     captureSizeIDX = getDefaultParameterResol("12MP", numcaptureSize, capture_Array);
    822                     params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_const_str[frameRateIDX]);
    823                     params.setPictureSize(capture_Array[captureSizeIDX]->width, capture_Array[captureSizeIDX]->height);
    824                     camera->setParameters(params.flatten());
    825                 }
    826 
    827                 requestBufferSourceReset();
    828 
    829                 break;
    830 
    831             case 'U':
    832 
    833                 params.set(KEY_TEMP_BRACKETING, (cmd + 1));
    834 
    835                 if ( hardwareActive )
    836                     camera->setParameters(params.flatten());
    837 
    838                 break;
    839 
    840             case 'H':
    841 
    842                 setDefaultExpGainPreset(shotParams, atoi(cmd + 1));
    843                 break;
    844 
    845 
    846             case 'n':
    847 
    848             switch (*(cmd + 1)) {
    849                 case 0:
    850                 shotConfigFlush = false;
    851                     break;
    852                 case 1:
    853                 shotConfigFlush = true;
    854                     break;
    855                 default:
    856                 printf ("Mangling flush shot config command: \"%s\"\n", (cmd + 1));
    857                     break;
    858             }
    859 
    860             updateShotConfigFlushParam();
    861 
    862             break;
    863 
    864             case '?':
    865 
    866                 setExpGainPreset(shotParams, cmd + 1, true, PARAM_EXP_BRACKET_PARAM_NONE, shotConfigFlush);
    867 
    868                 break;
    869 
    870             case 'W':
    871 
    872                 tempBracketRange = atoi(cmd + 1);
    873                 tempBracketRange %= TEMP_BRACKETING_MAX_RANGE;
    874                 if ( 0 == tempBracketRange ) {
    875                     tempBracketRange = 1;
    876                 }
    877 
    878                 params.set(KEY_TEMP_BRACKETING_NEG, tempBracketRange);
    879                 params.set(KEY_TEMP_BRACKETING_POS, tempBracketRange);
    880 
    881                 if ( hardwareActive )
    882                     camera->setParameters(params.flatten());
    883 
    884             break;
    885 
    886             case '#':
    887 
    888                 params.set(KEY_TI_BURST, atoi(cmd + 1));
    889                 burstCount = atoi(cmd + 1);
    890 
    891                 if ( hardwareActive )
    892                     camera->setParameters(params.flatten());
    893 
    894                 break;
    895 
    896             case 'J':
    897 
    898                 a = checkSupportedParamScript(flash, numflash, cmd);
    899                 if (a > -1) {
    900                     params.set(CameraParameters::KEY_FLASH_MODE, (cmd + 1));
    901                 } else {
    902                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    903                 }
    904 
    905                 if ( hardwareActive )
    906                     camera->setParameters(params.flatten());
    907 
    908                 break;
    909 
    910             case 'w':
    911 
    912                 a = checkSupportedParamScript(scene, numscene, cmd);
    913                 if (a > -1) {
    914                     params.set(params.KEY_SCENE_MODE, (cmd + 1));
    915                 } else {
    916                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    917                 }
    918                 if ( hardwareActive )
    919                     camera->setParameters(params.flatten());
    920 
    921                 break;
    922 
    923             case 'B' :
    924                 if(strcmp(vnfstr, "true") == 0) {
    925                     if (strcmp(cmd + 1, "1") == 0) {
    926                         trySetVideoNoiseFilter(true);
    927                     }
    928                     else if (strcmp(cmd + 1, "0") == 0){
    929                         trySetVideoNoiseFilter(false);
    930                     }
    931                 } else {
    932                     trySetVideoNoiseFilter(false);
    933                     printf("\n VNF is not supported \n\n");
    934                 }
    935 
    936                 if ( hardwareActive ) {
    937                     camera->setParameters(params.flatten());
    938                 }
    939                 break;
    940 
    941 
    942             case 'C' :
    943 
    944                 if (strcmp(vstabstr, "true") == 0) {
    945                     if (strcmp(cmd + 1, "1") == 0) {
    946                         trySetVideoStabilization(true);
    947                     } else if (strcmp(cmd + 1, "0") == 0) {
    948                         trySetVideoStabilization(false);
    949                     } else {
    950                         printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
    951                     }
    952                 } else {
    953                     printf("\nNot supported parameter vstab from sensor %d\n\n", camera_index);
    954                 }
    955 
    956                 if ( hardwareActive ) {
    957                     camera->setParameters(params.flatten());
    958                 }
    959                 break;
    960 
    961             case 'D':
    962                 if ( hardwareActive )
    963                     camera->stopRecording();
    964                 break;
    965 
    966             case 'E':
    967                 if(hardwareActive)
    968                     params.unflatten(camera->getParameters());
    969                 printSupportedParams();
    970                 break;
    971 
    972             case 'i':
    973                 iso_mode = atoi(cmd + 1);
    974                 if (iso_mode < numisoMode) {
    975                     params.set(KEY_ISO, isoMode[iso_mode]);
    976                 } else {
    977                     printf("\nNot supported parameter %s for iso mode from sensor %d\n\n", cmd + 1, camera_index);
    978                 }
    979 
    980                 if ( hardwareActive )
    981                     camera->setParameters(params.flatten());
    982 
    983                 break;
    984 
    985             case 'h':
    986                 sharpness = atoi(cmd + 1);
    987                 params.set(KEY_SHARPNESS, sharpness);
    988 
    989                 if ( hardwareActive )
    990                     camera->setParameters(params.flatten());
    991 
    992                 break;
    993 
    994             case '@':
    995                 if ( hardwareActive ) {
    996 
    997                     closeCamera();
    998 
    999                     if ( 0 >= openCamera() ) {
   1000                         printf( "Reconnected to CameraService \n");
   1001                     }
   1002                 }
   1003 
   1004                 break;
   1005 
   1006             case 'c':
   1007                 contrast = atoi(cmd + 1);
   1008                 params.set(KEY_CONTRAST, contrast);
   1009 
   1010                 if ( hardwareActive ) {
   1011                     camera->setParameters(params.flatten());
   1012                 }
   1013 
   1014                 break;
   1015 
   1016             case 'z':
   1017                 zoomtoggle = false;
   1018 
   1019                 if(strcmp(zoomstr, "true") == 0) {
   1020                     for(i = 0; i < length_Zoom; i++) {
   1021                         if( strcmp((cmd + 1), zoom[i].zoom_description) == 0) {
   1022                             zoomIDX = i;
   1023                             zoomtoggle = true;
   1024                             break;
   1025                         }
   1026                     }
   1027 
   1028                     if (!zoomtoggle) {
   1029                         printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1030                     }
   1031 
   1032 
   1033                     params.set(CameraParameters::KEY_ZOOM, zoom[zoomIDX].idx);
   1034 
   1035                     if ( hardwareActive ) {
   1036                         camera->setParameters(params.flatten());
   1037                     }
   1038                 }
   1039 
   1040             case 'Z':
   1041                 smoothzoomtoggle = false;
   1042 
   1043                 if(strcmp(smoothzoomstr, "true") == 0) {
   1044                     for(i = 0; i < length_Zoom; i++) {
   1045                         if( strcmp((cmd + 1), zoom[i].zoom_description) == 0) {
   1046                             zoomIDX = i;
   1047                             smoothzoomtoggle = true;
   1048                             break;
   1049                         }
   1050                     }
   1051 
   1052                     if (!smoothzoomtoggle) {
   1053                         printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1054                     }
   1055 
   1056                     if ( hardwareActive ) {
   1057                         camera->sendCommand(CAMERA_CMD_START_SMOOTH_ZOOM, zoom[zoomIDX].idx, 0);
   1058                     }
   1059                 }
   1060                 break;
   1061 
   1062             case 'j':
   1063 
   1064                 a = checkSupportedParamScript(exposureMode, numExposureMode, cmd);
   1065                 if (a > -1) {
   1066                     params.set(KEY_EXPOSURE, (cmd + 1));
   1067                 } else {
   1068                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1069                 }
   1070 
   1071                 if ( hardwareActive )
   1072                     camera->setParameters(params.flatten());
   1073 
   1074                 break;
   1075 
   1076             case 'b':
   1077                 brightness = atoi(cmd + 1);
   1078                 params.set(KEY_BRIGHTNESS, brightness);
   1079 
   1080                 if ( hardwareActive )
   1081                     camera->setParameters(params.flatten());
   1082 
   1083                 break;
   1084 
   1085             case 's':
   1086                 saturation = atoi(cmd + 1);
   1087                 params.set(KEY_SATURATION, saturation);
   1088 
   1089                 if ( hardwareActive )
   1090                     camera->setParameters(params.flatten());
   1091 
   1092                 break;
   1093 
   1094             case 'e':
   1095                 a = checkSupportedParamScript(effectss, numEffects, cmd);
   1096                 if (a > -1) {
   1097                     params.set(params.KEY_EFFECT, (cmd + 1));
   1098                 } else {
   1099                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1100                 }
   1101 
   1102                 if ( hardwareActive )
   1103                     camera->setParameters(params.flatten());
   1104 
   1105                 break;
   1106 
   1107             case 'r':
   1108                 if (strcmp((cmd + 1), "MAX_FRAMERATE") == 0) {
   1109                     frameRConst = 0;
   1110                     for (int i=0; i<constCnt; i++) {
   1111                         if (constFramerate[frameRConst] < constFramerate[i]) {
   1112                             frameRConst = i;
   1113                         }
   1114                     }
   1115                     if (0 < constFramerate[frameRConst]) {
   1116                         params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_const_str[frameRConst]);
   1117                         frameRateIDX = frameRConst;
   1118                         printf("Framerate set: %d fps\n", constFramerate[frameRConst]);
   1119                     } else {
   1120                         printf("\nFramerate is 0!\n");
   1121                     }
   1122                 } else {
   1123                     a = checkSupportedParamScriptfpsConst(constFramerate, constCnt, cmd, &frameRConst);
   1124                     if (a > -1) {
   1125                         params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_const_str[frameRConst]);
   1126                         frameRateIDX = frameRConst;
   1127                     } else {
   1128                         printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1129                     }
   1130                 }
   1131                 if ( hardwareActive && previewRunning ) {
   1132                     camera->stopPreview();
   1133                     camera->setParameters(params.flatten());
   1134                     camera->startPreview();
   1135                 } else if ( hardwareActive ) {
   1136                     camera->setParameters(params.flatten());
   1137                 }
   1138                 break;
   1139 
   1140             case 'R':
   1141                 a = checkSupportedParamScriptfpsRange(rangeDescription, rangeCnt, cmd, &frameRRange);
   1142                 if (a > -1) {
   1143                     params.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, fps_range_str[frameRRange]);
   1144                     fpsRangeIdx = frameRRange;
   1145                 } else {
   1146                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1147                 }
   1148                 break;
   1149 
   1150             case 'x':
   1151                 a = checkSupportedParamScript(antiband, numAntibanding, cmd);
   1152                 if (a > -1) {
   1153                 params.set(params.KEY_ANTIBANDING, (cmd + 1));
   1154                 } else {
   1155                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1156                 }
   1157 
   1158                 if ( hardwareActive )
   1159                     camera->setParameters(params.flatten());
   1160                 break;
   1161 
   1162             case 'g':
   1163                 a = checkSupportedParamScript(focus, numfocus, cmd);
   1164                 if (a > -1) {
   1165                     params.set(params.KEY_FOCUS_MODE, (cmd + 1));
   1166                 } else {
   1167                     printf("\nNot supported parameter %s from sensor %d\n\n", cmd + 1, camera_index);
   1168                 }
   1169 
   1170                 if ( hardwareActive )
   1171                     camera->setParameters(params.flatten());
   1172                 break;
   1173 
   1174             case 'G':
   1175 
   1176                 params.set(CameraParameters::KEY_FOCUS_AREAS, (cmd + 1));
   1177 
   1178                 if ( hardwareActive )
   1179                     camera->setParameters(params.flatten());
   1180 
   1181                 break;
   1182 
   1183             case 'y':
   1184 
   1185                 params.set(CameraParameters::KEY_METERING_AREAS, (cmd + 1));
   1186 
   1187                 if ( hardwareActive ) {
   1188                     camera->setParameters(params.flatten());
   1189                 }
   1190 
   1191                 break;
   1192 
   1193             case 'f':
   1194                 gettimeofday(&autofocus_start, 0);
   1195 
   1196                 if ( hardwareActive )
   1197                     camera->autoFocus();
   1198 
   1199                 break;
   1200 
   1201             case 'p':
   1202             {
   1203                 int msgType = 0;
   1204                 const char *format = params.getPictureFormat();
   1205 
   1206                 if((0 == strcmp(modevalues[capture_mode], "video-mode")) &&
   1207                    (0 != strcmp(videosnapshotstr, "true"))) {
   1208                     printf("Video Snapshot is not supported\n");
   1209                 } else if ( hardwareActive ) {
   1210                     if((NULL != format) && isRawPixelFormat(format)) {
   1211                         createBufferOutputSource();
   1212                         if (bufferSourceOutputThread.get()) {
   1213                             bufferSourceOutputThread->setBuffer(shotParams);
   1214                             bufferSourceOutputThread->setStreamCapture(streamCapture, expBracketIdx);
   1215                         }
   1216                     } else if(strcmp(modevalues[capture_mode], "video-mode") == 0) {
   1217                         msgType = CAMERA_MSG_COMPRESSED_IMAGE |
   1218                                   CAMERA_MSG_RAW_IMAGE;
   1219 #ifdef OMAP_ENHANCEMENT_BURST_CAPTURE
   1220                         msgType |= CAMERA_MSG_RAW_BURST;
   1221 #endif
   1222                     } else {
   1223                         msgType = CAMERA_MSG_POSTVIEW_FRAME |
   1224                                   CAMERA_MSG_RAW_IMAGE_NOTIFY |
   1225                                   CAMERA_MSG_COMPRESSED_IMAGE |
   1226                                   CAMERA_MSG_SHUTTER;
   1227 #ifdef OMAP_ENHANCEMENT_BURST_CAPTURE
   1228                         msgType |= CAMERA_MSG_RAW_BURST;
   1229 #endif
   1230                     }
   1231 
   1232                     gettimeofday(&picture_start, 0);
   1233                     ret = camera->setParameters(params.flatten());
   1234                     if ( ret != NO_ERROR ) {
   1235                         printf("Error returned while setting parameters");
   1236                         break;
   1237                     }
   1238                     ret = camera->takePictureWithParameters(msgType, shotParams.flatten());
   1239                     if ( ret != NO_ERROR ) {
   1240                         printf("Error returned while taking a picture");
   1241                         break;
   1242                     }
   1243                 }
   1244                 break;
   1245             }
   1246 
   1247             case 'S':
   1248             {
   1249                 if (streamCapture) {
   1250                     streamCapture = false;
   1251                     expBracketIdx = BRACKETING_IDX_DEFAULT;
   1252                     setDefaultExpGainPreset(shotParams, expBracketIdx);
   1253                     // Stop streaming
   1254                     if (bufferSourceOutputThread.get()) {
   1255                         bufferSourceOutputThread->setStreamCapture(streamCapture, expBracketIdx);
   1256                     }
   1257                 } else {
   1258                     streamCapture = true;
   1259                     expBracketIdx = BRACKETING_IDX_STREAM;
   1260                     setSingleExpGainPreset(shotParams, expBracketIdx, 0, 0);
   1261                     // Queue more frames initially
   1262                     shotParams.set(ShotParameters::KEY_BURST, BRACKETING_STREAM_BUFFERS);
   1263                 }
   1264                 break;
   1265             }
   1266 
   1267             case 'P':
   1268             {
   1269                 int msgType = CAMERA_MSG_COMPRESSED_IMAGE;
   1270                 ShotParameters reprocParams;
   1271 
   1272                 gettimeofday(&picture_start, 0);
   1273 
   1274                 createBufferInputSource();
   1275 
   1276                 if (bufferSourceOutputThread.get() &&
   1277                     bufferSourceOutputThread->hasBuffer())
   1278                 {
   1279                     bufferSourceOutputThread->setStreamCapture(false, expBracketIdx);
   1280                     if (hardwareActive) camera->setParameters(params.flatten());
   1281 
   1282                     if (bufferSourceInput.get()) {
   1283                         buffer_info_t info = bufferSourceOutputThread->popBuffer();
   1284                         bufferSourceInput->setInput(info, params.getPictureFormat(), reprocParams);
   1285                         if (hardwareActive) camera->reprocess(msgType, String8());
   1286                     }
   1287                 }
   1288                 break;
   1289             }
   1290 
   1291             case 'd':
   1292                 dly = atoi(cmd + 1);
   1293                 sleep(dly);
   1294                 break;
   1295 
   1296             case 'q':
   1297                 dump_mem_status();
   1298                 stopPreview();
   1299 
   1300                 if ( recordingMode ) {
   1301                     stopRecording();
   1302                     closeRecorder();
   1303 
   1304                     recordingMode = false;
   1305                 }
   1306                 goto exit;
   1307 
   1308             case '\n':
   1309                 printf("Iteration: %d \n", iteration);
   1310                 iteration++;
   1311                 break;
   1312 
   1313             case '{':
   1314                 if ( atoi(cmd + 1) > 0 )
   1315                     params.set(KEY_S3D2D_PREVIEW_MODE, "on");
   1316                 else
   1317                     params.set(KEY_S3D2D_PREVIEW_MODE, "off");
   1318                 if ( hardwareActive )
   1319                     camera->setParameters(params.flatten());
   1320                 break;
   1321 
   1322             case 'M':
   1323                 params.set(KEY_MEASUREMENT, (cmd + 1));
   1324                 if ( hardwareActive )
   1325                     camera->setParameters(params.flatten());
   1326                 break;
   1327             case 'm':
   1328             {
   1329                 params.set(KEY_METERING_MODE, (cmd + 1));
   1330                 if ( hardwareActive )
   1331                 {
   1332                     camera->setParameters(params.flatten());
   1333                 }
   1334                 break;
   1335             }
   1336             case '<':
   1337             {
   1338                 char coord_str[8];
   1339                 latitude += degree_by_step;
   1340                 if (latitude > 90.0)
   1341                 {
   1342                     latitude -= 180.0;
   1343                 }
   1344                 snprintf(coord_str, 7, "%.7lf", latitude);
   1345                 params.set(params.KEY_GPS_LATITUDE, coord_str);
   1346                 if ( hardwareActive )
   1347                 {
   1348                     camera->setParameters(params.flatten());
   1349                 }
   1350                 break;
   1351             }
   1352 
   1353             case '=':
   1354             {
   1355                 char coord_str[8];
   1356                 longitude += degree_by_step;
   1357                 if (longitude > 180.0)
   1358                 {
   1359                     longitude -= 360.0;
   1360                 }
   1361                 snprintf(coord_str, 7, "%.7lf", longitude);
   1362                 params.set(params.KEY_GPS_LONGITUDE, coord_str);
   1363                 if ( hardwareActive )
   1364                 {
   1365                     camera->setParameters(params.flatten());
   1366                 }
   1367                 break;
   1368             }
   1369 
   1370             case '>':
   1371             {
   1372                 char coord_str[8];
   1373                 altitude += 12345.67890123456789;
   1374                 if (altitude > 100000.0)
   1375                 {
   1376                     altitude -= 200000.0;
   1377                 }
   1378                 snprintf(coord_str, 7, "%.7lf", altitude);
   1379                 params.set(params.KEY_GPS_ALTITUDE, coord_str);
   1380                 if ( hardwareActive )
   1381                 {
   1382                     camera->setParameters(params.flatten());
   1383                 }
   1384                 break;
   1385             }
   1386 
   1387             case 'X':
   1388             {
   1389                 char rem_str[384];
   1390                 printf("Deleting images from %s \n", images_dir_path);
   1391                 if (!sprintf(rem_str, "rm %s/*.jpg", images_dir_path)) {
   1392                     printf("Sprintf Error");
   1393                 }
   1394                 if (system(rem_str)) {
   1395                     printf("Images were not deleted\n");
   1396                 }
   1397                 break;
   1398             }
   1399 
   1400             case '_':
   1401             {
   1402                 AutoConvergenceModeIDX = atoi(cmd + 1);
   1403                 if ( AutoConvergenceModeIDX < 0 || AutoConvergenceModeIDX > 4 )
   1404                     AutoConvergenceModeIDX = 0;
   1405                 params.set(KEY_AUTOCONVERGENCE, autoconvergencemode[AutoConvergenceModeIDX]);
   1406                 if (AutoConvergenceModeIDX != 4) {
   1407                     params.set(KEY_MANUAL_CONVERGENCE, manualConv);
   1408                 }
   1409                 if (hardwareActive) {
   1410                     camera->setParameters(params.flatten());
   1411                 }
   1412                 break;
   1413             }
   1414 
   1415             case '^':
   1416                 if (strcmp(autoconvergencemode[AutoConvergenceModeIDX], "manual") == 0) {
   1417                     manC = atoi(cmd + 1);
   1418                     if(manC >= manualConvMin  &&  manC <= manualConvMax)
   1419                     {
   1420                         params.set(KEY_MANUAL_CONVERGENCE, manC);
   1421                     }
   1422                     else if(manC < manualConvMin)
   1423                     {
   1424                         printf(" wrong parameter for manual convergence \n");
   1425                         params.set(KEY_MANUAL_CONVERGENCE, manualConvMin);
   1426                     }
   1427                     else
   1428                     {
   1429                         printf(" wrong parameter for manual convergence \n");
   1430                         params.set(KEY_MANUAL_CONVERGENCE, manualConvMax);
   1431                     }
   1432                     if ( hardwareActive )
   1433                         camera->setParameters(params.flatten());
   1434                 }
   1435                 break;
   1436 
   1437 
   1438             case 'Q':
   1439                 if ( strcmp (exposureMode[exposure_mode], "manual") == 0) {
   1440                     manE = atoi(cmd + 1);
   1441                     if(manE >= manualExpMin  &&  manE <= manualExpMax)
   1442                     {
   1443                         params.set(KEY_MANUAL_EXPOSURE, manE);
   1444                         params.set(KEY_MANUAL_EXPOSURE_RIGHT, manE);
   1445                     }
   1446                     else if(manE < manualExpMin)
   1447                     {
   1448                         printf(" wrong parameter for manual exposure \n");
   1449                         params.set(KEY_MANUAL_EXPOSURE, manualExpMin);
   1450                         params.set(KEY_MANUAL_EXPOSURE_RIGHT, manualExpMin);
   1451                     }
   1452                     else
   1453                     {
   1454                         printf(" wrong parameter for manual exposure \n");
   1455                         params.set(KEY_MANUAL_EXPOSURE, manualExpMax);
   1456                         params.set(KEY_MANUAL_EXPOSURE_RIGHT, manualExpMax);
   1457                     }
   1458 
   1459                     if ( hardwareActive )
   1460                     camera->setParameters(params.flatten());
   1461                 }
   1462                 break;
   1463 
   1464             case ',':
   1465                 if ( strcmp (exposureMode[exposure_mode], "manual") == 0) {
   1466                     manG = atoi(cmd + 1);
   1467                     if(manG >= manualGainMin  &&  manG <= manualGainMax)
   1468                     {
   1469                         params.set(KEY_MANUAL_GAIN_ISO, manG);
   1470                         params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manG);
   1471                     }
   1472                     else if(manG < manualGainMin)
   1473                     {
   1474                         printf(" wrong parameter for manual gain \n");
   1475                         params.set(KEY_MANUAL_GAIN_ISO, manualGainMin);
   1476                         params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manualGainMin);
   1477                     }
   1478                     else
   1479                     {
   1480                         printf(" wrong parameter for manual gain \n");
   1481                         params.set(KEY_MANUAL_GAIN_ISO, manualGainMax);
   1482                         params.set(KEY_MANUAL_GAIN_ISO_RIGHT, manualGainMax);
   1483                     }
   1484 
   1485                     if ( hardwareActive )
   1486                     camera->setParameters(params.flatten());
   1487                 }
   1488                 break;
   1489 
   1490             default:
   1491                 printf("Unrecognized command!\n");
   1492                 break;
   1493         }
   1494 
   1495         cmd = strtok_r(NULL, DELIMITER, &ctx);
   1496     }
   1497 
   1498 exit:
   1499     if (stopScript == true)
   1500       {
   1501         return -1;
   1502       }
   1503     else
   1504       {
   1505         return 0;
   1506       }
   1507 }
   1508 
   1509 
   1510 int checkSupportedParamScript(char **array, int size, char *param) {
   1511     for (int i=0; i<size; i++) {
   1512         if (strcmp((param + 1), array[i]) == 0) {
   1513             return 0;
   1514         }
   1515     }
   1516     return -1;
   1517 }
   1518 
   1519 int checkSupportedParamScriptLayout(char **array, int size, char *param, int *index) {
   1520     for (int i=0; i<size; i++) {
   1521         if (strcmp((param + 1), array[i]) == 0) {
   1522             *index = i;
   1523             return 0;
   1524         }
   1525     }
   1526     return -1;
   1527 }
   1528 
   1529 int checkSupportedParamScriptResol(param_Array **array, int size, char *param, int *num) {
   1530     for (int i=0; i<size; i++) {
   1531         if (strcmp((param + 1), array[i]->name) == 0) {
   1532             *num = i;
   1533             return 0;
   1534         }
   1535     }
   1536     return -1;
   1537 }
   1538 
   1539 int checkSupportedParamScriptResol(param_Array **array, int size,
   1540                                    int width, int height, int *num) {
   1541     for (int i=0; i<size; i++) {
   1542         if ((width == array[i]->width) && (height == array[i]->height)) {
   1543             *num = i;
   1544             return 0;
   1545         }
   1546     }
   1547     return -1;
   1548 }
   1549 
   1550 int checkSupportedParamScriptfpsConst(int *array, int size, char *param, int *num) {
   1551     for (int i=0; i<size; i++) {
   1552         if (atoi(param + 1) == array[i]) {
   1553             *num = i;
   1554             return 0;
   1555         }
   1556     }
   1557     return -1;
   1558 }
   1559 
   1560 int checkSupportedParamScriptfpsRange(char **array, int size, char *param, int *num) {
   1561     for (int i=0; i<size; i++) {
   1562         if (strcmp(param + 1, array[i]) == 0) {
   1563             *num = i;
   1564             return 0;
   1565         }
   1566     }
   1567     return -1;
   1568 }
   1569 
   1570 char * get_cycle_cmd(const char *aSrc) {
   1571     unsigned ind = 0;
   1572     char *cycle_cmd = new char[256];
   1573 
   1574     while ((*aSrc != '+') && (*aSrc != '\0')) {
   1575         cycle_cmd[ind++] = *aSrc++;
   1576     }
   1577     cycle_cmd[ind] = '\0';
   1578 
   1579     return cycle_cmd;
   1580 }
   1581 
   1582 status_t dump_mem_status() {
   1583   system(MEDIASERVER_DUMP);
   1584   return system(MEMORY_DUMP);
   1585 }
   1586 
   1587 char *load_script(const char *config) {
   1588     FILE *infile;
   1589     size_t fileSize;
   1590     char *script;
   1591     size_t nRead = 0;
   1592 
   1593     infile = fopen(config, "r");
   1594 
   1595     strcpy(script_name,config);
   1596 
   1597     printf("\n SCRIPT : <%s> is currently being executed \n", script_name);
   1598 
   1599     printf("\n DIRECTORY CREATED FOR TEST RESULT IMAGES IN MMC CARD : %s \n", output_dir_path);
   1600 
   1601     if( (NULL == infile)){
   1602         printf("Error while opening script file %s!\n", config);
   1603         return NULL;
   1604     }
   1605 
   1606     fseek(infile, 0, SEEK_END);
   1607     fileSize = ftell(infile);
   1608     fseek(infile, 0, SEEK_SET);
   1609 
   1610     script = (char *) malloc(fileSize + 1);
   1611 
   1612     if ( NULL == script ) {
   1613         printf("Unable to allocate buffer for the script\n");
   1614 
   1615         return NULL;
   1616     }
   1617 
   1618     memset(script, 0, fileSize + 1);
   1619 
   1620     if ((nRead = fread(script, 1, fileSize, infile)) != fileSize) {
   1621         printf("Error while reading script file!\n");
   1622 
   1623         free(script);
   1624         fclose(infile);
   1625         return NULL;
   1626     }
   1627 
   1628     fclose(infile);
   1629 
   1630     return script;
   1631 }
   1632 
   1633 int start_logging(int flags, int &pid) {
   1634     int status = 0;
   1635 
   1636     if (flags == 0) {
   1637         pid = -1;
   1638         return 0;
   1639     }
   1640 
   1641     pid = fork();
   1642     if (pid == 0)
   1643     {
   1644         char *command_list[] = {"sh", "-c", NULL, NULL};
   1645         char log_cmd[1024];
   1646         // child process to run logging
   1647 
   1648         // set group id of this process to itself
   1649         // we will use this group id to kill the
   1650         // application logging
   1651         setpgid(getpid(), getpid());
   1652 
   1653         /* Start logcat */
   1654         if (flags & LOGGING_LOGCAT) {
   1655             if (!sprintf(log_cmd,"logcat > %s/log.txt &", output_dir_path)) {
   1656                 printf(" Sprintf Error");
   1657             }
   1658         }
   1659 
   1660         /* Start Syslink Trace */
   1661         if (flags & LOGGING_SYSLINK) {
   1662             if (!sprintf(log_cmd,"%s /system/bin/syslink_trace_daemon.out -l %s/syslink_trace.txt -f &", log_cmd, output_dir_path)) {
   1663                 printf(" Sprintf Error");
   1664             }
   1665         }
   1666 
   1667         command_list[2] = (char *)log_cmd;
   1668         execvp("/system/bin/sh", command_list);
   1669     } if(pid < 0)
   1670     {
   1671         printf("failed to fork logcat\n");
   1672         return -1;
   1673     }
   1674 
   1675     //wait for logging to start
   1676     if(waitpid(pid, &status, 0) != pid)
   1677     {
   1678         printf("waitpid failed in log fork\n");
   1679         return -1;
   1680     }else
   1681         printf("logging started... status=%d\n", status);
   1682 
   1683     return 0;
   1684 }
   1685 
   1686 int stop_logging(int flags, int &pid)
   1687 {
   1688     if (pid > 0) {
   1689         if (killpg(pid, SIGKILL)) {
   1690             printf("Exit command failed");
   1691             return -1;
   1692         } else {
   1693             printf("\nlogging for script %s is complete\n", script_name);
   1694 
   1695             if (flags & LOGGING_LOGCAT) {
   1696                 printf("   logcat saved @ location: %s\n", output_dir_path);
   1697             }
   1698 
   1699             if (flags & LOGGING_SYSLINK) {
   1700                 printf("   syslink_trace is saved @ location: %s\n\n", output_dir_path);
   1701             }
   1702         }
   1703     }
   1704     return 0;
   1705 }
   1706 
   1707 int execute_error_script(char *script) {
   1708     char *cmd, *ctx;
   1709     char id;
   1710     status_t stat = NO_ERROR;
   1711 
   1712     LOG_FUNCTION_NAME;
   1713 
   1714     cmd = strtok_r((char *) script, DELIMITER, &ctx);
   1715 
   1716     while ( NULL != cmd ) {
   1717         id = cmd[0];
   1718 
   1719         switch (id) {
   1720 
   1721             case '0': {
   1722                 bufferStarvationTest = 1;
   1723                 params.set(KEY_BUFF_STARV, bufferStarvationTest); //enable buffer starvation
   1724 
   1725                 if ( !recordingMode ) {
   1726 
   1727                     recordingMode = true;
   1728 
   1729                     if ( startPreview() < 0 ) {
   1730                         printf("Error while starting preview\n");
   1731 
   1732                         return -1;
   1733                     }
   1734 
   1735                     if ( openRecorder() < 0 ) {
   1736                         printf("Error while openning video recorder\n");
   1737 
   1738                         return -1;
   1739                     }
   1740 
   1741                     if ( configureRecorder() < 0 ) {
   1742                         printf("Error while configuring video recorder\n");
   1743 
   1744                         return -1;
   1745                     }
   1746 
   1747                     if ( startRecording() < 0 ) {
   1748                         printf("Error while starting video recording\n");
   1749 
   1750                         return -1;
   1751                     }
   1752 
   1753                 }
   1754 
   1755                 usleep(1000000);//1s
   1756 
   1757                 stopPreview();
   1758 
   1759                 if ( recordingMode ) {
   1760                     stopRecording();
   1761                     closeRecorder();
   1762 
   1763                     recordingMode = false;
   1764                 }
   1765 
   1766                 break;
   1767             }
   1768 
   1769             case '1': {
   1770                 int* tMemoryEater = new int[999999999];
   1771 
   1772                 if (!tMemoryEater) {
   1773                     printf("Not enough memory\n");
   1774                     return -1;
   1775                 } else {
   1776                     delete tMemoryEater;
   1777                 }
   1778 
   1779                 break;
   1780             }
   1781 
   1782             case '2': {
   1783                 //camera = Camera::connect();
   1784 
   1785                 if ( NULL == camera.get() ) {
   1786                     printf("Unable to connect to CameraService\n");
   1787                     return -1;
   1788                 }
   1789 
   1790                 break;
   1791             }
   1792 
   1793             case '3': {
   1794                 int err = 0;
   1795 
   1796                 err = open("/dev/video5", O_RDWR);
   1797 
   1798                 if (err < 0) {
   1799                     printf("Could not open the camera device5: %d\n",  err );
   1800                     return err;
   1801                 }
   1802 
   1803                 if ( startPreview() < 0 ) {
   1804                     printf("Error while starting preview\n");
   1805                     return -1;
   1806                 }
   1807 
   1808                 usleep(1000000);//1s
   1809 
   1810                 stopPreview();
   1811 
   1812                 close(err);
   1813                 break;
   1814             }
   1815 
   1816             case '4': {
   1817 
   1818                 if ( hardwareActive ) {
   1819 
   1820                     params.setPictureFormat("invalid-format");
   1821                     params.setPreviewFormat("invalid-format");
   1822 
   1823                     stat = camera->setParameters(params.flatten());
   1824 
   1825                     if ( NO_ERROR != stat ) {
   1826                         printf("Test passed!\n");
   1827                     } else {
   1828                         printf("Test failed!\n");
   1829                     }
   1830 
   1831                     initDefaults();
   1832                 }
   1833 
   1834                 break;
   1835             }
   1836 
   1837             case '5': {
   1838 
   1839                 if ( hardwareActive ) {
   1840 
   1841                     params.setPictureSize(-1, -1);
   1842                     params.setPreviewSize(-1, -1);
   1843 
   1844                     stat = camera->setParameters(params.flatten());
   1845 
   1846                     if ( NO_ERROR != stat ) {
   1847                         printf("Test passed!\n");
   1848                     } else {
   1849                         printf("Test failed!\n");
   1850                     }
   1851 
   1852                     initDefaults();
   1853                 }
   1854 
   1855                 break;
   1856             }
   1857 
   1858             case '6': {
   1859 
   1860                 if ( hardwareActive ) {
   1861 
   1862                     params.setPreviewFrameRate(-1);
   1863 
   1864                     stat = camera->setParameters(params.flatten());
   1865 
   1866                     if ( NO_ERROR != stat ) {
   1867                         printf("Test passed!\n");
   1868                     } else {
   1869                         printf("Test failed!\n");
   1870                     }
   1871 
   1872                     initDefaults();
   1873                 }
   1874 
   1875 
   1876                 break;
   1877             }
   1878 
   1879             case 'q': {
   1880                 goto exit;
   1881 
   1882                 break;
   1883             }
   1884 
   1885             default: {
   1886                 printf("Unrecognized command!\n");
   1887 
   1888                 break;
   1889             }
   1890         }
   1891 
   1892         cmd = strtok_r(NULL, DELIMITER, &ctx);
   1893     }
   1894 
   1895 exit:
   1896 
   1897     return 0;
   1898 }
   1899 
   1900 
   1901 
   1902