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