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