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