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