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