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