Fix build warnings
[platform/core/api/camera.git] / test / camera_test.c
1 /*
2  * camera_test
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jeongmo Yang <jm80.yang@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License f(r the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /*=======================================================================================
23 |  INCLUDE FILES                                                                        |
24 =======================================================================================*/
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <glib.h>
28 #include <sys/time.h>
29 #include <dlog.h>
30 #include <camera.h>
31 #include <Ecore.h>
32 #include <Elementary.h>
33 #include <appcore-efl.h>
34
35 /*-----------------------------------------------------------------------
36 |    GLOBAL VARIABLE DEFINITIONS:                                       |
37 -----------------------------------------------------------------------*/
38 #define EXPORT_API __attribute__((__visibility__("default")))
39
40 #ifdef PACKAGE
41 #undef PACKAGE
42 #endif
43 #define PACKAGE "camera_test"
44
45
46 static int app_create(void *data);
47 static int app_terminate(void *data);
48
49 struct _appdata {
50         Evas_Object *win;
51         Evas_Object *eo;
52         Evas_Object *bg;
53         Evas_Object *rect;
54 };
55 typedef struct _appdata appdata;
56
57 struct appcore_ops ops = {
58         .create = app_create,
59         .terminate = app_terminate,
60 };
61
62 appdata ad;
63 GIOChannel *stdin_channel;
64 camera_device_e cam_info;
65 static GTimer *timer;
66 static int g_camera_device_changed_cb_id;
67
68 static struct timeval previous_time;
69 static struct timeval current_time;
70 static struct timeval result_time;
71
72 /*-----------------------------------------------------------------------
73 |    GLOBAL CONSTANT DEFINITIONS:                                       |
74 -----------------------------------------------------------------------*/
75
76
77 /*-----------------------------------------------------------------------
78 |    IMPORTED VARIABLE DECLARATIONS:                                    |
79 -----------------------------------------------------------------------*/
80
81
82 /*-----------------------------------------------------------------------
83 |    IMPORTED FUNCTION DECLARATIONS:                                    |
84 -----------------------------------------------------------------------*/
85
86
87 /*-----------------------------------------------------------------------
88 |    LOCAL #defines:                                                    |
89 -----------------------------------------------------------------------*/
90 #define DEFAULT_FILE_PATH               "/home/owner/media"
91 #define PREVIEW_CB_DUMP_FILE_NAME       "preview.data"
92 #define MAX_FILE_NAME_LENGTH            256
93 #define MAX_FILE_PATH_LENGTH            (MAX_FILE_NAME_LENGTH - 20)
94
95 #define CHECK_MM_ERROR(expr) \
96         do {\
97                 int ret = 0; \
98                 ret = expr; \
99                 if (ret != 0) {\
100                         g_print("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
101                         return; \
102                 } \
103         } while (0)
104
105
106 #ifndef SAFE_FREE
107 #define SAFE_FREE(x) \
108         if (x) {\
109                 g_free(x);\
110                 x = NULL;\
111         }
112 #endif
113
114 #define SENSOR_WHITEBALANCE_NUM     10
115 #define SENSOR_COLOR_TONE_NUM       31
116 #define SENSOR_FLIP_NUM         4
117 #define SENSOR_PROGRAM_MODE_NUM     15
118 #define SENSOR_FOCUS_NUM        6
119 #define SENSOR_INPUT_ROTATION       4
120 #define SENSOR_AF_SCAN_NUM      4
121 #define SENSOR_ISO_NUM          8
122 #define SENSOR_EXPOSURE_NUM     9
123 #define SENSOR_IMAGE_FORMAT     9
124
125
126 /*-----------------------------------------------------------------------
127   |    LOCAL CONSTANT DEFINITIONS:                                        |
128   -----------------------------------------------------------------------*/
129 enum {
130         MODE_VIDEO_CAPTURE, /* recording and image capture mode */
131         MODE_AUDIO,     /* audio recording*/
132         MODE_NUM,
133 };
134
135 enum {
136         MENU_STATE_INIT,
137         MENU_STATE_MAIN,
138         MENU_STATE_SETTING,
139         MENU_STATE_NUM,
140 };
141
142 /*-----------------------------------------------------------------------
143   |    LOCAL DATA TYPE DEFINITIONS:                   |
144   -----------------------------------------------------------------------*/
145 typedef struct _cam_handle {
146         camera_h camera;
147         int type;
148         int is_multishot;                           /* flag for multishot mode */
149         int stillshot_count;                        /* stillshot count */
150         int multishot_count;                        /* multishot count */
151         char file_path[MAX_FILE_PATH_LENGTH];  /* file path for captured data */
152         int menu_state;
153         unsigned long long elapsed_time;
154 } cam_handle_t;
155
156 typedef struct {
157         int width[100];
158         int height[100];
159         int count;
160 } resolution_stack;
161
162 typedef struct {
163         camera_attr_exposure_mode_e mode;
164         int count;
165 } exposure_stack;
166
167 typedef struct {
168         camera_attr_iso_e mode;
169         int count;
170 } iso_stack;
171
172
173 /*---------------------------------------------------------------------------
174   |    LOCAL VARIABLE DEFINITIONS:                                            |
175   ---------------------------------------------------------------------------*/
176 static cam_handle_t *hcamcorder;
177
178 const char *wb[SENSOR_WHITEBALANCE_NUM] = {
179         "None",
180         "Auto",
181         "Daylight",
182         "Cloudy",
183         "Fluoroscent",
184         "Incandescent",
185         "Shade",
186         "Horizon",
187         "Flash",
188         "Custom",
189 };
190
191 const char *ct[SENSOR_COLOR_TONE_NUM] = {
192         "NONE",
193         "MONO",
194         "SEPIA",
195         "NEGATIVE",
196         "BLUE",
197         "GREEN",
198         "AQUA",
199         "VIOLET",
200         "ORANGE",
201         "GRAY",
202         "RED",
203         "ANTIQUE",
204         "WARM",
205         "PINK",
206         "YELLOW",
207         "PURPLE",
208         "EMBOSS",
209         "OUTLINE",
210         "SOLARIZATION",
211         "SKETCH",
212         "WASHED",
213         "VINTAGE_WARM",
214         "VINTAGE_COLD",
215         "POSTERIZATION",
216         "CARTOON",
217         "SELECTVE_COLOR_RED",
218         "SELECTVE_COLOR_GREEN",
219         "SELECTVE_COLOR_BLUE",
220         "SELECTVE_COLOR_YELLOW",
221         "SELECTVE_COLOR_RED_YELLOW",
222         "GRAPHICS"
223 };
224
225 const char *sensor_flip[SENSOR_FLIP_NUM] = {
226         "NONE",
227         "HORIZONTAL",
228         "VERTICAL",
229         "BOTH"
230 };
231
232 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
233         "NORMAL",
234         "PORTRAIT",
235         "LANDSCAPE",
236         "SPORTS",
237         "PARTY_N_INDOOR",
238         "BEACH_N_INDOOR",
239         "SUNSET",
240         "DUSK_N_DAWN",
241         "FALL_COLOR",
242         "NIGHT_SCENE",
243         "FIREWORK",
244         "TEXT",
245         "SHOW_WINDOW",
246         "CANDLE_LIGHT",
247         "BACKLIGHT",
248 };
249
250 const char *focus_mode[SENSOR_FOCUS_NUM] = {
251         "None",
252         "Pan",
253         "Auto",
254         "Manual",
255         "Touch Auto",
256         "Continuous Auto",
257 };
258
259 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
260         "None",
261         "90",
262         "180",
263         "270",
264 };
265
266 const char *iso_mode[SENSOR_ISO_NUM] = {
267         "ISO Auto",
268         "ISO 50",
269         "ISO 100",
270         "ISO 200",
271         "ISO 400",
272         "ISO 800",
273         "ISO 1600",
274         "ISO 3200",
275 };
276
277 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
278         "AE off",
279         "AE all mode",
280         "AE center mode",
281         "AE spot 1 mode",
282         "AE custom mode",
283 };
284
285 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
286         "NV12",
287         "NV12T",
288         "NV16",
289         "NV21",
290         "YUYV",
291         "UYVY",
292         "422P",
293         "I420",
294         "YV12",
295 };
296
297 const char *face_zoom_mode[] = {
298         "Face Zoom OFF",
299         "Face Zoom ON",
300 };
301
302 const char *display_mode[] = {
303         "Letter Box mode",
304         "Original Size mode",
305         "Full Screen mode",
306         "Cropped Full Screen mode",
307         "ROI mode",
308 };
309
310 const char *capture_sound[] = {
311         "Default",
312         "Extra 01",
313         "Extra 02",
314 };
315
316 const char *rotate_mode[] = {
317         "0",
318         "90",
319         "180",
320         "270",
321 };
322
323 const char* strobe_mode[] = {
324         "Strobe OFF",
325         "Strobe ON",
326         "Strobe Auto",
327         "Strobe RedEyeReduction",
328         "Strobe SlowSync",
329         "Strobe FrontCurtain",
330         "Strobe RearCurtain",
331         "Strobe Permanent",
332 };
333
334 const char *detection_mode[2] = {
335         "Face Detection OFF",
336         "Face Detection ON",
337 };
338
339 const char *wdr_mode[] = {
340         "WDR OFF",
341         "WDR ON",
342         "WDR AUTO",
343 };
344
345 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
346         "None",
347         "Normal",
348         "Macro mode",
349         "Full mode",
350 };
351
352 const char *hdr_mode[] = {
353         "HDR OFF",
354         "HDR ON",
355         "HDR ON and Original",
356 };
357
358 const char *ahs_mode[] = {
359         "Anti-handshake OFF",
360         "Anti-handshake ON",
361         "Anti-handshake AUTO",
362         "Anti-handshake MOVIE",
363 };
364
365 const char *vs_mode[] = {
366         "Video-stabilization OFF",
367         "Video-stabilization ON",
368 };
369
370 const char *visible_mode[] = {
371         "Display OFF",
372         "Display ON",
373 };
374
375 const char *facing_direction[] = {
376         "REAR",
377         "FRONT",
378 };
379
380
381 /*---------------------------------------------------------------------------
382   |    LOCAL FUNCTION PROTOTYPES:                                             |
383   ---------------------------------------------------------------------------*/
384 static void print_menu();
385 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data);
386 static gboolean mode_change(gchar buf);
387 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
388
389
390 static inline void flush_stdin()
391 {
392         int ch;
393         while ((ch = getchar()) != EOF && ch != '\n');
394 }
395
396 static gboolean _release_idle_event_callback(void *data)
397 {
398         g_print("destroy camera handle\n\n");
399
400         camera_destroy(hcamcorder->camera);
401         hcamcorder->camera = NULL;
402         hcamcorder->menu_state = MENU_STATE_INIT;
403
404         print_menu();
405
406         return 0;
407 }
408
409 static void _camera_error_cb(int error, camera_state_e current_state, void *user_data)
410 {
411         g_print("\n\n\tERROR [0x%x], current state %d\n", error, current_state);
412
413         switch (error) {
414         case CAMERA_ERROR_RESOURCE_CONFLICT:
415                 g_print("\t\t[CAMERA_ERROR_RESOURCE_CONFLICT]\n\n");
416                 break;
417         case CAMERA_ERROR_SECURITY_RESTRICTED:
418                 g_print("\t\t[CAMERA_ERROR_SECURITY_RESTRICTED]\n\n");
419                 break;
420         case CAMERA_ERROR_SERVICE_DISCONNECTED:
421                 g_print("\t\t[CAMERA_ERROR_SERVICE_DISCONNECTED]\n\n");
422                 g_idle_add_full(G_PRIORITY_DEFAULT,
423                         (GSourceFunc)_release_idle_event_callback,
424                         NULL, NULL);
425                 break;
426         default:
427                 break;
428         }
429
430         return;
431 }
432
433 static void _camera_state_changed_cb(camera_state_e previous, camera_state_e current, bool by_policy, void *user_data)
434 {
435         g_print("\n\tcamera state changed %d -> %d\n", previous, current);
436
437         return;
438 }
439
440 static void _camera_device_state_changed_cb(camera_device_e device, camera_device_state_e state, void *user_data)
441 {
442         g_print("\n\tcamera device[%d] state changed to %d\n", device, state);
443
444         return;
445 }
446
447 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
448 {
449         g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
450                 previous, current, policy);
451
452         return;
453 }
454
455 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
456 {
457         g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
458
459         return;
460 }
461
462 void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
463 {
464 #if 1
465         char preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',};
466         FILE *fp = NULL;
467
468         snprintf(preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, PREVIEW_CB_DUMP_FILE_NAME);
469
470         fp = fopen(preview_dump, "a");
471         if (fp == NULL) {
472                 g_print("\n==== file[%s] open failed ====\n", preview_dump);
473                 return;
474         }
475
476         if (frame->format == CAMERA_PIXEL_FORMAT_RGBA ||
477                 frame->format == CAMERA_PIXEL_FORMAT_ARGB) {
478                 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
479         } else if (frame->format == CAMERA_PIXEL_FORMAT_INVZ) {
480                 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
481         } else if (frame->format == CAMERA_PIXEL_FORMAT_MJPEG) {
482                 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
483         } else {
484                 switch (frame->num_of_planes) {
485                 case 1:
486                         fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
487                         break;
488                 case 2:
489                         fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
490                         fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
491                         break;
492                 case 3:
493                         fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
494                         fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
495                         fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
496                         break;
497                 default:
498                         break;
499                 }
500         }
501
502         g_print("==== file[%s] write done ====\n", preview_dump);
503
504         fclose(fp);
505         fp = NULL;
506 #else
507         g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
508                         frame->format, frame->width, frame->height, frame->num_of_planes);
509 #endif
510
511         return;
512 }
513
514
515 static bool preview_resolution_cb(int width, int height, void *user_data)
516 {
517         resolution_stack *data = (resolution_stack *)user_data;
518
519         if (data == NULL) {
520                 g_print("NULL data\n");
521                 return false;
522         }
523
524         data->width[data->count] = width;
525         data->height[data->count] = height;
526
527         g_print("\t%d. %dx%d\n", data->count, width, height);
528
529         data->count++;
530
531         return true;
532 }
533
534 static bool capture_resolution_test_cb(int width, int height, void *user_data)
535 {
536         resolution_stack *data = (resolution_stack *)user_data;
537
538         if (data == NULL) {
539                 g_print("NULL data\n");
540                 return false;
541         }
542
543         data->width[data->count] = width;
544         data->height[data->count] = height;
545
546         g_print("\t%d. %dx%d\n", data->count, width, height);
547
548         data->count++;
549
550         return true;
551 }
552
553 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
554 {
555         g_print("\t%d. %s\n", mode, af_scan[mode]);
556         return true;
557 }
558
559 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
560 {
561         exposure_stack *data = (exposure_stack *)user_data;
562
563         if (data == NULL) {
564                 g_print("NULL data\n");
565                 return false;
566         }
567
568         data->mode = mode;
569         data->count++;
570
571         g_print("\t%d. %s\n", mode, exposure_mode[mode]);
572         return true;
573 }
574
575 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
576 {
577         g_print("\t%d. %s\n", mode, iso_mode[mode]);
578         return true;
579 }
580
581 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
582 {
583         g_print("\t%d. %s\n", mode, camera_rotation[mode]);
584         return true;
585 }
586
587 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
588 {
589         g_print("\t%d. %s\n", mode, sensor_flip[mode]);
590         return true;
591 }
592
593 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
594 {
595         g_print("\t%d. %s\n", mode, image_fmt[mode]);
596         return true;
597 }
598
599 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
600 {
601         g_print("\t%d. %s\n", mode, wb[mode]);
602         return true;
603 }
604
605 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
606 {
607         g_print("\t%d. %s\n", mode, ct[mode]);
608         return true;
609 }
610
611 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
612 {
613         g_print("\t%d. %s\n", mode, program_mode[mode]);
614         return true;
615 }
616
617 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
618 {
619         g_print("\t%d. %s\n", mode, strobe_mode[mode]);
620         return true;
621 }
622
623 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
624 {
625         g_print("\tface detected!! - count %d\n", count);
626         int i;
627
628         for (i = 0 ; i < count ; i++)
629                 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
630
631         return;
632 }
633
634 static void _file_write(char *path, void *data, int size)
635 {
636         FILE *fp = NULL;
637
638         if (!path || !data || size <= 0) {
639                 g_print("\n\tERROR %p %p %d\n", path, data, size);
640                 return;
641         }
642
643         fp = fopen(path, "w");
644         if (fp) {
645                 g_print("\n\topen success [%s]\n", path);
646                 if (fwrite(data, size, 1, fp) != 1)
647                         g_print("\n\twrite error! errno %d\n", errno);
648                 else
649                         g_print("\n\twrite success [%s]\n", path);
650
651                 fclose(fp);
652                 fp = NULL;
653         } else {
654                 g_print("\n\topen error! [%s], errno %d\n", path, errno);
655         }
656
657         return;
658 }
659
660 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
661 {
662         char m_filename[MAX_FILE_NAME_LENGTH];
663
664         /* main image */
665         if (image) {
666                 if (hcamcorder->is_multishot) {
667                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
668                                 hcamcorder->file_path, hcamcorder->multishot_count++);
669                 } else {
670                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
671                                 hcamcorder->file_path, hcamcorder->stillshot_count++);
672                 }
673
674                 _file_write(m_filename, image->data, image->size);
675         }
676
677         return;
678 }
679
680 static void capture_completed_cb(void *user_data)
681 {
682         camera_start_preview(hcamcorder->camera);
683
684         return;
685 }
686
687 static void print_menu()
688 {
689         switch (hcamcorder->menu_state) {
690         case MENU_STATE_INIT:
691                 g_print("\n\t=======================================\n");
692                 g_print("\t   CAMERA_TESTSUITE\n");
693                 g_print("\t=======================================\n");
694                 g_print("\t   '1' Video Capture\n");
695                 g_print("\t   '2' Add camera device state changed callback\n");
696                 g_print("\t   '3' Remove camera device state changed callback\n");
697                 g_print("\t   '4' Get camera device state\n");
698                 g_print("\t   'q' Exit\n");
699                 g_print("\t=======================================\n");
700                 break;
701         case MENU_STATE_MAIN:
702                 g_print("\n\t=======================================\n");
703                 g_print("\t   Video Capture (CAMERA%d)\n", cam_info);
704                 g_print("\t=======================================\n");
705                 g_print("\t   '1' Stillshot test\n");
706                 g_print("\t   '2' Multishot test\n");
707                 g_print("\t   '3' Setting\n");
708                 g_print("\t   '4' Change device (CAMERA0 <-> CAMERA1)\n");
709                 g_print("\t   '5' Add preview callback\n");
710                 g_print("\t   '6' Remove preview callback\n");
711                 g_print("\t   'b' back\n");
712                 g_print("\t=======================================\n");
713                 break;
714         case MENU_STATE_SETTING:
715                 g_print("\n\t=======================================\n");
716                 g_print("\t   Video Capture > Setting\n");
717                 g_print("\t=======================================\n");
718                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera]  \n");
719                 g_print("\t     '0' Preview resolution \n");
720                 g_print("\t     '1' Capture resolution \n");
721                 g_print("\t     '2' Digital zoom level \n");
722                 g_print("\t     '3' AF mode \n");
723                 g_print("\t     '4' AF scan range \n");
724                 g_print("\t     '5' Exposure mode \n");
725                 g_print("\t     '6' Exposure value \n");
726                 g_print("\t     '7' F number \n");
727                 g_print("\t     '8' Display reuse hint \n");
728                 g_print("\t     'i' ISO \n");
729                 g_print("\t     'r' Rotate camera input \n");
730                 g_print("\t     'f' Flip camera input \n");
731                 g_print("\t     'j' Jpeg quality \n");
732                 g_print("\t     'p' Picture format \n");
733                 g_print("\t     'E' EXIF orientation \n");
734                 g_print("\t     'F' Get facing direction of camera module\n");
735                 g_print("\t  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
736                 g_print("\t     'v' Visible \n");
737                 g_print("\t     'o' Output mode \n");
738                 g_print("\t     'y' Rotate display \n");
739                 g_print("\t     'Y' Flip display \n");
740                 g_print("\t     'g' Brightness \n");
741                 g_print("\t     'c' Contrast \n");
742                 g_print("\t     'h' Hue \n");
743                 g_print("\t     'w' White balance \n");
744                 g_print("\t     't' Color tone \n");
745                 g_print("\t     'd' WDR \n");
746                 g_print("\t     'e' EV program mode \n");
747                 g_print("\t     'R' Display ROI area \n");
748                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
749                 g_print("\t     'z' Strobe (Flash) \n");
750                 g_print("\t     'S' Strobe (Flash) state\n");
751                 g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
752                 g_print("\t     'l' Face detection \n");
753                 g_print("\t     'k' Anti-handshake \n");
754                 g_print("\t     'K' Video-stabilization \n");
755                 g_print("\t     'u' Touch AF area \n");
756                 g_print("\t     'n' Set file path to write captured image\n");
757                 g_print("\t     'b' back\n");
758                 g_print("\t=======================================\n");
759                 break;
760         default:
761                 g_print("\n\tunknow menu state !!\n");
762                 return;
763         }
764
765         g_print("\tCommand >> ");
766
767         return;
768 }
769
770
771 static void main_menu(gchar buf)
772 {
773         int err = 0;
774         int interval = 0;
775         int count = 0;
776
777         switch (buf) {
778         case '1': /* Capture */
779                 hcamcorder->is_multishot = FALSE;
780                 camera_attr_set_image_quality(hcamcorder->camera, 100);
781                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
782                 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
783                 break;
784         case '2': /* multishot Capture */
785                 g_print("multishot capture");
786                 hcamcorder->is_multishot = TRUE;
787                 g_print("\n\tinput interval(ms) : ");
788                 err = scanf("%d", &interval);
789                 flush_stdin();
790                 g_print("\n\tinput count : ");
791                 err = scanf("%d", &count);
792                 flush_stdin();
793                 camera_attr_set_image_quality(hcamcorder->camera, 100);
794                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
795                 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
796                 sleep(3);
797                 camera_start_preview(hcamcorder->camera);
798                 break;
799         case '3': /* Setting */
800                 hcamcorder->menu_state = MENU_STATE_SETTING;
801                 break;
802         case '4': /* Change device (CAMERA0 <-> CAMERA1) */
803                 camera_set_display_reuse_hint(hcamcorder->camera, true);
804
805                 camera_stop_preview(hcamcorder->camera);
806
807                 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
808                         hcamcorder->type = CAMERA_DEVICE_CAMERA1;
809                 else
810                         hcamcorder->type = CAMERA_DEVICE_CAMERA0;
811
812                 camera_change_device(hcamcorder->camera, hcamcorder->type);
813
814                 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
815                 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
816                 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
817                 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
818
819                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
820
821                 camera_start_preview(hcamcorder->camera);
822                 break;
823         case '5':
824                 camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
825                 break;
826         case '6':
827                 camera_unset_preview_cb(hcamcorder->camera);
828                 break;
829         case 'b': /* back */
830                 camera_stop_preview(hcamcorder->camera);
831                 camera_destroy(hcamcorder->camera);
832                 hcamcorder->camera = NULL;
833                 hcamcorder->menu_state = MENU_STATE_INIT;
834                 break;
835         default:
836                 g_print("\t Invalid input \n");
837                 break;
838         }
839
840         return;
841 }
842
843
844 static void setting_menu(gchar buf)
845 {
846         int bret = FALSE;
847         int idx = 0;
848         int min = 0;
849         int max = 0;
850         int i = 0;
851         int err = 0;
852         int x = 0;
853         int y = 0;
854         int width = 0;
855         int height = 0;
856         int result = 0;
857
858         switch (buf) {
859         /* Camera setting */
860         case '0':  /* Setting > Preview Resolution setting */
861                 g_print("\t* Select the preview resolution!\n");
862                 resolution_stack resolution_list;
863                 resolution_list.count = 0;
864
865                 camera_foreach_supported_preview_resolution(hcamcorder->camera,
866                         preview_resolution_cb, &resolution_list);
867
868                 g_print("\tCommand >> ");
869
870                 err = scanf("%d", &idx);
871                 flush_stdin();
872                 if (resolution_list.count > idx && idx >= 0) {
873                         g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
874                                 resolution_list.width[idx], resolution_list.height[idx]);
875
876                         result = camera_set_preview_resolution(hcamcorder->camera,
877                                 resolution_list.width[idx], resolution_list.height[idx]);
878                 } else {
879                         g_print("\tInvalid command [%d]\n", idx);
880                         result = -1;
881                 }
882                 resolution_list.count = 0;
883                 if (result == CAMERA_ERROR_NONE)
884                         g_print("\tPASS\n");
885                 else
886                         g_print("\tFAIL\n");
887                 break;
888         case '1': /* Setting > Capture Resolution setting */
889                 g_print("\t* Select the preview resolution!\n");
890                 resolution_list.count = 0;
891
892                 camera_foreach_supported_capture_resolution(hcamcorder->camera,
893                         capture_resolution_test_cb, &resolution_list);
894
895                 g_print("\tCommand > ");
896
897                 err = scanf("%d", &idx);
898                 flush_stdin();
899                 if (resolution_list.count > idx && idx >= 0) {
900                         g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
901                                 resolution_list.width[idx], resolution_list.height[idx]);
902
903                         result = camera_set_capture_resolution(hcamcorder->camera,
904                                 resolution_list.width[idx], resolution_list.height[idx]);
905                 } else {
906                         g_print("\tInvalid command [%d]\n", idx);
907                         result = -1;
908                 }
909                 resolution_list.count = 0;
910                 if (result == CAMERA_ERROR_NONE)
911                         g_print("\tPASS\n");
912                 else
913                         g_print("\tFAIL\n");
914                 break;
915         case '2': /* Setting > Digital zoom level */
916                 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
917                 if (min > max) {
918                         g_print("\tDigital Zoom Not supported\n");
919                 } else {
920                         g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
921                         err = scanf("%d", &idx);
922                         flush_stdin();
923                         bret = camera_attr_set_zoom(hcamcorder->camera, idx);
924                 }
925                 break;
926         case '3': /* Setting > AF mode */
927                 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
928                 err = scanf("%d", &idx);
929                 flush_stdin();
930                 switch (idx) {
931                 case 1:
932                         camera_start_focusing(hcamcorder->camera, 0);
933                         break;
934                 case 2:
935                         camera_cancel_focusing(hcamcorder->camera);
936                         break;
937                 default:
938                         g_print("\tInvalid command [%d]\n", idx);
939                         break;
940                 }
941                 break;
942         case '4': /* Setting > AF scan range */
943                 g_print("\t* AF scan range !\n");
944                 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
945                 g_print("\tCommand > ");
946                 err = scanf("%d", &idx);
947                 flush_stdin();
948                 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
949                 break;
950         case '5': /* Setting > Exposure mode */
951                 g_print("* Exposure mode!\n");
952                 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
953                 g_print("\n Select  Exposure mode \n");
954                 err = scanf("%d", &idx);
955                 flush_stdin();
956                 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
957                 break;
958
959         case '6': /* Setting > Exposure value */
960                 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
961                 if (min >= max)
962                         g_print("Not supported !! \n");
963                 else {
964                         g_print("\n Select  Exposure mode min%d -max %d\n", min, max);
965                         err = scanf("%d", &idx);
966                         flush_stdin();
967                         bret = camera_attr_set_exposure(hcamcorder->camera, idx);
968                 }
969                 break;
970         case '7': /* Setting > F number */
971                 g_print("Not supported !! \n");
972                 break;
973         case '8': /* Setting > Display reuse hint */
974                 {
975                         bool reuse_hint = false;
976
977                         err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
978                         if (err != CAMERA_ERROR_NONE) {
979                                 g_print("failed to get display reuse hint 0x%x\n", err);
980                                 break;
981                         }
982
983                         g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
984                         reuse_hint = !reuse_hint;
985                         err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
986                         g_print("set display reuse hint result : 0x%x\n", err);
987                 }
988                 break;
989         case 'i': /* Setting > ISO */
990                 g_print("*ISO !\n");
991                 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
992                 err = scanf("%d", &idx);
993                 flush_stdin();
994                 bret =  camera_attr_set_iso(hcamcorder->camera, idx);
995                 break;
996         case 'r': /* Setting > Rotate camera input when recording */
997                 g_print("*Rotate camera input\n");
998                 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
999                 err = scanf("%d", &idx);
1000                 flush_stdin();
1001                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1002                 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1003                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1004                 break;
1005         case 'f': /* Setting > Flip camera input */
1006                 g_print("*Flip camera input\n");
1007                 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1008                 err = scanf("%d", &idx);
1009                 flush_stdin();
1010                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1011                 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1012                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1013                 break;
1014         case 'j': /* Setting > Jpeg quality */
1015                 g_print("*Jpeg quality !\n");
1016                 g_print("\n Select  Jpeg quality \n");
1017                 err = scanf("%d", &idx);
1018                 flush_stdin();
1019                 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1020                 break;
1021         case 'p': /* Setting > Picture format */
1022                 g_print("* Picture format!\n");
1023                 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1024                 err = scanf("%d", &idx);
1025                 flush_stdin();
1026                 bret = camera_set_preview_format(hcamcorder->camera, idx);
1027                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1028                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1029                 break;
1030         case 'E': /* Setting > EXIF orientation */
1031                 g_print("* EXIF Orientation\n");
1032                 g_print("\t 1. TOP_LEFT\n");
1033                 g_print("\t 2. TOP_RIGHT(flipped)\n");
1034                 g_print("\t 3. BOTTOM_RIGHT\n");
1035                 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1036                 g_print("\t 5. LEFT_TOP(flipped)\n");
1037                 g_print("\t 6. RIGHT_TOP\n");
1038                 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1039                 g_print("\t 8. LEFT_BOTTOM\n");
1040                 err = scanf("%d", &idx);
1041                 flush_stdin();
1042                 if (idx < 1 || idx > 8)
1043                         g_print("Wrong INPUT[%d]!! \n", idx);
1044                 else
1045                         camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1046                 break;
1047         case 'F': /* Getting > Get Facing direction */
1048                 g_print("* Get facing direction of camera module\n");
1049                 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1050                 if (CAMERA_ERROR_NONE == err)
1051                         g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1052                 else
1053                         g_print("* Error : %d\n", err);
1054                 break;
1055                 /* Display / Filter setting */
1056         case 'v': /* Display visible */
1057                 g_print("* Display visible setting !\n");
1058                 g_print("\n Select Display visible \n");
1059                 for (i = 0 ; i < 2 ; i++)
1060                         g_print("\t %d. %s\n", i, visible_mode[i]);
1061                 err = scanf("%d", &idx);
1062                 flush_stdin();
1063                 if (idx == 0 || idx == 1)
1064                         bret = camera_set_display_visible(hcamcorder->camera, idx);
1065                 else
1066                         g_print("invalid input %d", idx);
1067                 break;
1068         case 'o': /* Setting > Display Mode */
1069                 g_print("* Display mode!\n");
1070                 for (i = 0 ; i < 5 ; i++)
1071                         g_print("%d. %s\n", i, display_mode[i]);
1072                 err = scanf("%d", &idx);
1073                 flush_stdin();
1074                 bret =  camera_set_display_mode(hcamcorder->camera, idx);
1075                 break;
1076         case 'y': /* Setting > Rotate Display */
1077                 g_print("\n Select Rotate mode\n");
1078                 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1079                 err = scanf("%d", &idx);
1080                 flush_stdin();
1081                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1082                 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1083                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1084                 break;
1085         case 'Y': /* Setting > Flip Display */
1086                 g_print("\n Select Rotate mode\n");
1087                 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1088                 err = scanf("%d", &idx);
1089                 flush_stdin();
1090                 bret = camera_set_display_flip(hcamcorder->camera, idx);
1091                 break;
1092         case 'g': /* Setting > Brightness */
1093                 g_print("*Brightness !\n");
1094                 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1095                 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1096                 err = scanf("%d", &idx);
1097                 flush_stdin();
1098                 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1099                 break;
1100         case 'c': /* Setting > Contrast */
1101                 g_print("*Contrast !\n");
1102                 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1103                 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1104                 err = scanf("%d", &idx);
1105                 flush_stdin();
1106                 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1107                 break;
1108         case 'h': /* Setting > Hue */
1109                 g_print("*Hue !\n");
1110                 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1111                 if (max >= min) {
1112                         g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1113                         err = scanf("%d", &idx);
1114                         flush_stdin();
1115                         bret = camera_attr_set_hue(hcamcorder->camera, idx);
1116                 } else {
1117                         g_print("\n Hue is not supported (%d,%d)\n", min, max);
1118                 }
1119                 break;
1120         case 'w': /* Setting > White balance */
1121                 g_print("*White balance !\n");
1122                 g_print("\n Select White balance \n");
1123                 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1124                 err = scanf("%d", &idx);
1125                 flush_stdin();
1126                 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1127                 break;
1128         case 't': /* Setting > Color tone */
1129                 g_print("*Color tone !\n");
1130                 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1131                 g_print("\n Select Color tone \n");
1132                 err = scanf("%d", &idx);
1133                 flush_stdin();
1134                 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1135                 break;
1136         case 'd': /* Setting > WDR */
1137                 g_print("*WDR !\n");
1138                 g_print("\n Select WDR Mode \n");
1139                 for (i = 0 ; i < 2 ; i++)
1140                         g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1141                 err = scanf("%d", &idx);
1142                 flush_stdin();
1143                 if (idx == 1)
1144                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1145                 else if (idx == 2)
1146                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1147                 break;
1148         case 'e': /* Setting > EV program mode */
1149                 g_print("* EV program mode!\n");
1150                 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1151                 g_print("\n Select EV program mode \n");
1152                 err = scanf("%d", &idx);
1153                 flush_stdin();
1154                 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1155                 break;
1156         case 'R': /* Setting > Display ROI area */
1157                 g_print("* Set display roi area. Select x y width height \n");
1158                 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1159                 flush_stdin();
1160                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1161                 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1162                 if (CAMERA_ERROR_NONE != err)
1163                         g_print("* Error : %d\n", err);
1164
1165                 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1166                 if (CAMERA_ERROR_NONE == err)
1167                         g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1168                 else
1169                         g_print("* Error : %d\n", err);
1170                 break;
1171
1172                 /* ext. setting */
1173         case 'z': /* Setting > Strobe setting */
1174                 g_print("*Strobe Mode\n");
1175                 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1176                 g_print("\n Select Strobe Mode \n");
1177                 err = scanf("%d", &idx);
1178                 flush_stdin();
1179                 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1180                 break;
1181         case 'S': /* Setting > flash state */
1182                 g_print("*flash state\n");
1183                 err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx);
1184                 if (CAMERA_ERROR_NONE == err)
1185                         g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1186                 else
1187                         g_print("* Error : %d\n", err);
1188                 break;
1189         case 'x': /* Setting > Capture mode ,Muitishot? */
1190                 g_print("*Select Capture mode!\n");
1191                 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1192                 err = scanf("%d", &idx);
1193                 flush_stdin();
1194
1195                 switch (idx) {
1196                 case 1:
1197                         g_print("stillshot mode selected and capture callback is set!!!!\n");
1198                         hcamcorder->is_multishot = FALSE;
1199                         camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1200                         break;
1201                 case 2:
1202                         g_print("HDR Capture mode selected\n");
1203                         hcamcorder->is_multishot = FALSE;
1204                         g_print("\nSelect HDR capture mode\n");
1205                         for (i = 0 ; i < 3 ; i++)
1206                                 g_print("\t %d. %s\n", i, hdr_mode[i]);
1207                         err = scanf("%d", &idx);
1208                         flush_stdin();
1209                         if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1210                                 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1211                         else
1212                                 g_print("invalid input %d\n", idx);
1213                         break;
1214                 default:
1215                         g_print("Wrong input, select again!!\n");
1216                         break;
1217                 }
1218                 break;
1219         case 'l': /* Setting > Face detection setting */
1220                 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1221                         g_print("* Face detect mode !\n");
1222                         for (i = 0 ; i < 2 ; i++)
1223                                 g_print("\t %d. %s \n", i, detection_mode[i]);
1224                         err = scanf("%d", &idx);
1225                         flush_stdin();
1226                         if (idx == 0)
1227                                 bret = camera_stop_face_detection(hcamcorder->camera);
1228                         else if (idx == 1)
1229                                 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1230                         else
1231                                 g_print("\n invalid input [%d]\n\n", idx);
1232                 } else {
1233                         g_print("face detection_not supported");
1234                 }
1235                 break;
1236         case 'k': /* Setting > Anti-handshake */
1237                 g_print("*Anti-handshake !\n");
1238                 g_print("\n Select Anti-handshake mode \n");
1239                 for (i = 0; i < 2; i++)
1240                         g_print("\t %d. %s\n", i, ahs_mode[i]);
1241                 err = scanf("%d", &idx);
1242                 flush_stdin();
1243                 if (idx == 0 || idx == 1)
1244                         bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1245                 else
1246                         g_print("invalid input %d\n", idx);
1247                 break;
1248         case 'K': /* Setting > Video-stabilization */
1249                 g_print("*Video-stabilization !\n");
1250                 g_print("\n Select Video-stabilization mode \n");
1251                 for (i = 0 ; i < 2 ; i++)
1252                         g_print("\t %d. %s\n", i, vs_mode[i]);
1253                 err = scanf("%d", &idx);
1254                 flush_stdin();
1255                 if (idx < 0 || idx > 1) {
1256                         g_print("invalid input %d\n", idx);
1257                         break;
1258                 }
1259
1260                 if (idx == 1) {
1261                         g_print("\n Restart preview with NV12 and 720p resolution\n");
1262                         err = camera_stop_preview(hcamcorder->camera);
1263                         g_print("stop preview result 0x%x\n", err);
1264                         camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1265                         camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1266                 }
1267
1268                 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1269
1270                 if (idx == 1) {
1271                         err = camera_start_preview(hcamcorder->camera);
1272                         if (err != CAMERA_ERROR_NONE)
1273                                 g_print("\n Restart FAILED! 0x%x\n", err);
1274                 }
1275                 break;
1276         case 'u': /* Touch AF area */
1277                 g_print("* Touch AF area !\n");
1278                 g_print("\n Input x,y,width,height \n");
1279                 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1280                 flush_stdin();
1281                 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1282                 if (err != 0)
1283                         g_print("Failed to set touch AF area.(%x)\n", err);
1284                 else
1285                         g_print("Succeed to set touch AF area.\n");
1286                 break;
1287         case 'n': /* file path */
1288                 g_print("* File path !\n");
1289                 g_print("\n Input file path to save captured data(string) : ");
1290                 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1291                         hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1292                         g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1293                 } else {
1294                         g_print("\nset file path failed\n");
1295                 }
1296                 break;
1297         case 'b': /* back */
1298                 hcamcorder->menu_state = MENU_STATE_MAIN;
1299                 break;
1300         default:
1301                 g_print("\t Invalid input \n");
1302                 break;
1303         }
1304
1305         g_print("\t bret : 0x%x \n", bret);
1306
1307         return;
1308 }
1309
1310
1311 /**
1312  * This function is to execute command.
1313  *
1314  * @param   channel [in]    1st parameter
1315  *
1316  * @return  This function returns TRUE/FALSE
1317  * @remark
1318  * @see
1319  */
1320 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1321 {
1322         gchar *buf = NULL;
1323         gsize read_size;
1324         GError *g_error = NULL;
1325
1326         g_print("\n\tENTER\n");
1327
1328         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1329         if (g_error) {
1330                 g_print("\n\tg_io_channel_read_chars error\n");
1331                 g_error_free(g_error);
1332                 g_error = NULL;
1333         }
1334
1335         if (buf) {
1336                 g_strstrip(buf);
1337
1338                 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1339                 switch (hcamcorder->menu_state) {
1340                 case MENU_STATE_INIT:
1341                         mode_change(buf[0]);
1342                         break;
1343                 case MENU_STATE_MAIN:
1344                         main_menu(buf[0]);
1345                         break;
1346                 case MENU_STATE_SETTING:
1347                         setting_menu(buf[0]);
1348                         break;
1349                 default:
1350                         break;
1351                 }
1352
1353                 g_free(buf);
1354                 buf = NULL;
1355
1356                 print_menu();
1357         } else {
1358                 g_print("\n\tNo read input\n");
1359         }
1360
1361         return TRUE;
1362 }
1363
1364 static gboolean init_handle()
1365 {
1366         hcamcorder->is_multishot =  FALSE;
1367         hcamcorder->stillshot_count = 0;
1368         hcamcorder->multishot_count = 0;
1369         snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1370         hcamcorder->menu_state = MENU_STATE_INIT;
1371         hcamcorder->elapsed_time = 0;
1372
1373         return TRUE;
1374 }
1375
1376
1377 /**
1378  * This function is to change camcorder mode.
1379  *
1380  * @param   buf    [in]    user input
1381  *
1382  * @return  This function returns TRUE/FALSE
1383  * @remark
1384  * @see     other functions
1385  */
1386 static gboolean mode_change(gchar buf)
1387 {
1388         int err = 0;
1389         camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1390         char camera_type = '\0';
1391         char display_type = '\0';
1392         bool check = FALSE;
1393
1394         switch (buf) {
1395         case '1':
1396                 while (1) {
1397                         g_print("\n\tEnter the Camera Type[0 ~ 9] : ");
1398
1399                         err = scanf("%c", &camera_type);
1400                         flush_stdin();
1401                         if (err == EOF) {
1402                                 g_print("\t!!!read input error!!!\n");
1403                                 continue;
1404                         }
1405
1406                         if (camera_type < '0' || camera_type > '9') {
1407                                 g_print("\t Invalid camera type(%c)\n", camera_type);
1408                                 continue;
1409                         }
1410
1411                         hcamcorder->type = cam_info = camera_type - '0';
1412
1413                         break;
1414                 }
1415                 break;
1416         case '2':
1417                 err = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1418                         NULL, &g_camera_device_changed_cb_id);
1419                 g_print("add result 0x%x - cb id %d\n", err, g_camera_device_changed_cb_id);
1420                 return FALSE;
1421         case '3':
1422                 if (g_camera_device_changed_cb_id > 0) {
1423                         err = camera_remove_device_state_changed_cb(g_camera_device_changed_cb_id);
1424                         g_camera_device_changed_cb_id = 0;
1425                         g_print("remove result 0x%x\n", err);
1426                 } else {
1427                         g_print("invalid callback id %d\n", g_camera_device_changed_cb_id);
1428                 }
1429                 return FALSE;
1430         case '4':
1431                 err = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &device_state);
1432                 g_print("get result 0x%x - state %d\n", err, device_state);
1433                 return FALSE;
1434         case 'q':
1435                 g_print("\t Quit Camcorder Testsuite!!\n");
1436                 elm_exit();
1437                 return FALSE;
1438         default:
1439                 g_print("\t Invalid media type(%c)\n", buf);
1440                 return FALSE;
1441         }
1442
1443         g_print("\n[camcorder_create - type %d]\n", cam_info);
1444
1445         gettimeofday(&previous_time, NULL);
1446
1447         g_timer_reset(timer);
1448
1449         err = camera_create(cam_info, &hcamcorder->camera);
1450
1451         g_print("[camera_create()  : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1452
1453         if (err != 0) {
1454                 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1455                 return -1;
1456         }
1457
1458         while (!check) {
1459                 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1460
1461                 err = scanf("%c", &display_type);
1462                 flush_stdin();
1463                 if (err == EOF) {
1464                         g_print("\t!!!read input error!!!\n");
1465                         continue;
1466                 }
1467
1468                 switch (display_type) {
1469                 case '1':
1470                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1471                         check = TRUE;
1472                         break;
1473                 case '2':
1474                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1475                         check = TRUE;
1476                         break;
1477                 case '3':
1478                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1479                         check = TRUE;
1480                         break;
1481                 default:
1482                         g_print("\t Invalid display type(%c)\n", display_type);
1483                         break;
1484                 }
1485         }
1486
1487         camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1488         camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1489         camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1490         camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1491         camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1492         /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1493         /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1494         /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1495
1496         camera_start_preview(hcamcorder->camera);
1497
1498         gettimeofday(&current_time, NULL);
1499         timersub(&current_time, &previous_time, &result_time);
1500
1501         g_print("\n\tCamera Starting Time  : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1502
1503         hcamcorder->menu_state = MENU_STATE_MAIN;
1504
1505         return TRUE;
1506 }
1507
1508 static int app_create(void *data)
1509 {
1510         appdata *app_data = data;
1511         int w = 0;
1512         int h = 0;
1513         Evas_Object *win = NULL;
1514         Evas_Object *eo = NULL;
1515         Evas_Object *bg = NULL;
1516         Evas_Object *rect = NULL;
1517
1518         if (app_data == NULL) {
1519                 g_print("\t\nappdata is NULL\n");
1520                 return 0;
1521         }
1522
1523         /* use gl backend */
1524         elm_config_accel_preference_set("opengl");
1525
1526         win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1527         if (win) {
1528                 elm_win_title_set(win, "camera_test");
1529                 elm_win_borderless_set(win, EINA_TRUE);
1530                 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1531                 g_print("\n\tscreen size %dx%d\n\n", w, h);
1532                 evas_object_resize(win, w, h);
1533                 elm_win_autodel_set(win, EINA_TRUE);
1534                 elm_win_alpha_set(win, EINA_TRUE);
1535         } else {
1536                 g_print("\n\tfailed to get window\n\n");
1537                 return 1;
1538         }
1539
1540         bg = elm_bg_add(win);
1541         if (bg) {
1542                 elm_win_resize_object_add(win, bg);
1543                 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1544                 evas_object_show(bg);
1545         } else {
1546                 g_print("\n\tfailed to get elm bg\n\n");
1547                 return 1;
1548         }
1549
1550         rect = evas_object_rectangle_add(evas_object_evas_get(win));
1551         if (rect) {
1552                 evas_object_color_set(rect, 0, 0, 0, 0);
1553                 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1554         } else {
1555                 g_print("\n\tfailed to get rectangle\n\n");
1556                 return 1;
1557         }
1558
1559         elm_win_resize_object_add(win, rect);
1560         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1561         evas_object_show(rect);
1562
1563         /* Create evas image object for EVAS surface */
1564         eo = evas_object_image_add(evas_object_evas_get(win));
1565         evas_object_image_size_set(eo, w, h);
1566         evas_object_image_fill_set(eo, 0, 0, w, h);
1567         evas_object_resize(eo, w, h);
1568         evas_object_show(eo);
1569
1570         elm_win_activate(win);
1571         evas_object_show(win);
1572
1573         app_data->win = win;
1574         app_data->eo = eo;
1575
1576         timer = g_timer_new();
1577         g_timer_reset(timer);
1578
1579         init_handle();
1580
1581         print_menu();
1582
1583         return 0;
1584 }
1585
1586 static int app_terminate(void *data)
1587 {
1588         appdata *app_data = data;
1589
1590         if (app_data == NULL) {
1591                 g_print("\n\tappdata is NULL\n");
1592                 return 0;
1593         }
1594
1595         if (timer) {
1596                 g_timer_stop(timer);
1597                 g_timer_destroy(timer);
1598                 timer = NULL;
1599         }
1600
1601         return 0;
1602 }
1603
1604
1605 /**
1606  * This function is the example main function for mmcamcorder API.
1607  *
1608  * @param
1609  *
1610  * @return  This function returns 0.
1611  * @remark
1612  * @see     other functions
1613  */
1614 int main(int argc, char **argv)
1615 {
1616         int bret;
1617
1618         hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1619
1620         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1621         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1622
1623         memset(&ad, 0x0, sizeof(appdata));
1624         ops.data = &ad;
1625
1626         bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1627
1628         g_print("\n\treturn appcore_efl : %d\n\n", bret);
1629
1630         g_free(hcamcorder);
1631         g_io_channel_unref(stdin_channel);
1632
1633         return bret;
1634 }
1635 /*EOF*/