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