Add new internal APIs for extra preview bitrate
[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  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
931                 g_print("\t     'v' Visible \n");
932                 g_print("\t     'o' Output mode \n");
933                 g_print("\t     'y' Rotate display \n");
934                 g_print("\t     'Y' Flip display \n");
935                 g_print("\t     'g' Brightness \n");
936                 g_print("\t     'c' Contrast \n");
937                 g_print("\t     'h' Hue \n");
938                 g_print("\t     'w' White balance \n");
939                 g_print("\t     't' Color tone \n");
940                 g_print("\t     'd' WDR \n");
941                 g_print("\t     'e' EV program mode \n");
942                 g_print("\t     'R' Display ROI area \n");
943                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
944                 g_print("\t     'z' Strobe (Flash) \n");
945                 g_print("\t     'S' Strobe (Flash) state\n");
946                 g_print("\t     'G' Strobe (Flash) brightness\n");
947                 g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
948                 g_print("\t     'l' Face detection \n");
949                 g_print("\t     'k' Anti-handshake \n");
950                 g_print("\t     'K' Video-stabilization \n");
951                 g_print("\t     'u' Touch AF area \n");
952                 g_print("\t     'n' Set file path to write captured image\n");
953                 g_print("\t     'm' Set media bridge\n");
954                 g_print("\t     'b' back\n");
955                 g_print("\t=======================================\n");
956                 break;
957         default:
958                 g_print("\n\tunknow menu state !!\n");
959                 return;
960         }
961
962         g_print("\tCommand >> ");
963
964         return;
965 }
966
967
968 static void main_menu(gchar buf)
969 {
970         int err = 0;
971         int interval = 0;
972         int count = 0;
973         int set_cb = 0;
974
975         switch (buf) {
976         case '1': /* Capture */
977                 hcamcorder->is_multishot = FALSE;
978                 camera_attr_set_image_quality(hcamcorder->camera, 100);
979                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
980                 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
981                 break;
982         case '2': /* multishot Capture */
983                 g_print("multishot capture");
984                 hcamcorder->is_multishot = TRUE;
985                 g_print("\n\tinput interval(ms) : ");
986                 err = scanf("%d", &interval);
987                 flush_stdin();
988                 g_print("\n\tinput count : ");
989                 err = scanf("%d", &count);
990                 flush_stdin();
991                 camera_attr_set_image_quality(hcamcorder->camera, 100);
992                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
993                 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
994                 sleep(3);
995                 camera_start_preview(hcamcorder->camera);
996                 break;
997         case '3': /* Setting */
998                 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
999                 break;
1000         case '4': /* Change device (CAMERA0 <-> CAMERA1) */
1001                 camera_set_display_reuse_hint(hcamcorder->camera, true);
1002
1003                 camera_stop_preview(hcamcorder->camera);
1004
1005                 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
1006                         hcamcorder->type = CAMERA_DEVICE_CAMERA1;
1007                 else
1008                         hcamcorder->type = CAMERA_DEVICE_CAMERA0;
1009
1010                 camera_change_device(hcamcorder->camera, hcamcorder->type);
1011
1012                 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1013                 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1014                 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1015                 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1016
1017                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1018
1019                 camera_start_preview(hcamcorder->camera);
1020                 break;
1021         case '5':
1022                 g_print("* Preview Callback\n");
1023                 g_print("\tUnset[0] / Set[Others] :");
1024                 err = scanf("%d", &set_cb);
1025                 flush_stdin();
1026                 if (set_cb) {
1027                         g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
1028                         err = scanf("%d", &g_camera_preview_cb_dump);
1029                         flush_stdin();
1030                         err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
1031                 } else {
1032                         err = camera_unset_preview_cb(hcamcorder->camera);
1033                 }
1034                 g_print("\tresult[0x%x]\n\n", err);
1035                 break;
1036         case '6':
1037                 g_print("* Extra Preview Callback\n");
1038                 g_print("\tUnset[0] / Set[Others] :");
1039                 err = scanf("%d", &set_cb);
1040                 flush_stdin();
1041                 if (set_cb) {
1042                         g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
1043                         err = scanf("%d", &g_camera_extra_preview_cb_dump);
1044                         flush_stdin();
1045                         err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
1046                 } else {
1047                         err = camera_unset_extra_preview_cb(hcamcorder->camera);
1048                 }
1049                 g_print("\tresult[0x%x]\n\n", err);
1050                 break;
1051         case '7':
1052                 g_print("* Media Packet Preview Callback\n");
1053                 g_print("\tUnset[0] / Set[Others] :");
1054                 err = scanf("%d", &set_cb);
1055                 flush_stdin();
1056                 if (set_cb) {
1057                         g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
1058                         err = scanf("%d", &g_camera_mp_preview_cb_dump);
1059                         flush_stdin();
1060                         err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
1061                 } else {
1062                         err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
1063                 }
1064                 g_print("\tresult[0x%x]\n\n", err);
1065                 break;
1066         case 'b': /* back */
1067                 __release_media_bridge();
1068
1069                 camera_stop_preview(hcamcorder->camera);
1070                 camera_destroy(hcamcorder->camera);
1071                 hcamcorder->camera = NULL;
1072                 hcamcorder->menu_state = MENU_STATE_INIT;
1073                 break;
1074         default:
1075                 g_print("\t Invalid input \n");
1076                 break;
1077         }
1078
1079         return;
1080 }
1081
1082
1083 static void setting_menu(gchar buf)
1084 {
1085         int bret = FALSE;
1086         int idx = 0;
1087         int min = 0;
1088         int max = 0;
1089         int i = 0;
1090         int err = 0;
1091         int x = 0;
1092         int y = 0;
1093         int width = 0;
1094         int height = 0;
1095         int result = 0;
1096         int set_bridge = 0;
1097         int stream_id;
1098         int pixel_format;
1099         int fps;
1100         int bitrate;
1101
1102         switch (buf) {
1103         /* Camera setting */
1104         case '0':  /* Setting > Preview Resolution setting */
1105                 g_print("\t* Select the preview resolution!\n");
1106                 resolution_stack resolution_list;
1107                 resolution_list.count = 0;
1108
1109                 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1110                         preview_resolution_cb, &resolution_list);
1111
1112                 g_print("\tCommand >> ");
1113
1114                 err = scanf("%d", &idx);
1115                 flush_stdin();
1116                 if (resolution_list.count > idx && idx >= 0) {
1117                         g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1118                                 resolution_list.width[idx], resolution_list.height[idx]);
1119
1120                         result = camera_set_preview_resolution(hcamcorder->camera,
1121                                 resolution_list.width[idx], resolution_list.height[idx]);
1122                 } else {
1123                         g_print("\tInvalid command [%d]\n", idx);
1124                         result = -1;
1125                 }
1126                 resolution_list.count = 0;
1127                 if (result == CAMERA_ERROR_NONE)
1128                         g_print("\tPASS\n");
1129                 else
1130                         g_print("\tFAIL\n");
1131                 break;
1132         case '1': /* Setting > Capture Resolution setting */
1133                 g_print("\t* Select the preview resolution!\n");
1134                 resolution_list.count = 0;
1135
1136                 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1137                         capture_resolution_test_cb, &resolution_list);
1138
1139                 g_print("\tCommand > ");
1140
1141                 err = scanf("%d", &idx);
1142                 flush_stdin();
1143                 if (resolution_list.count > idx && idx >= 0) {
1144                         g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1145                                 resolution_list.width[idx], resolution_list.height[idx]);
1146
1147                         result = camera_set_capture_resolution(hcamcorder->camera,
1148                                 resolution_list.width[idx], resolution_list.height[idx]);
1149                 } else {
1150                         g_print("\tInvalid command [%d]\n", idx);
1151                         result = -1;
1152                 }
1153                 resolution_list.count = 0;
1154                 if (result == CAMERA_ERROR_NONE)
1155                         g_print("\tPASS\n");
1156                 else
1157                         g_print("\tFAIL\n");
1158                 break;
1159         case '2': /* Setting > Digital zoom level */
1160                 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1161                 if (min > max) {
1162                         g_print("\tDigital Zoom Not supported\n");
1163                 } else {
1164                         g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1165                         err = scanf("%d", &idx);
1166                         flush_stdin();
1167                         bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1168                 }
1169                 break;
1170         case '3': /* Setting > AF mode */
1171                 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1172                 err = scanf("%d", &idx);
1173                 flush_stdin();
1174                 switch (idx) {
1175                 case 1:
1176                         camera_start_focusing(hcamcorder->camera, 0);
1177                         break;
1178                 case 2:
1179                         camera_cancel_focusing(hcamcorder->camera);
1180                         break;
1181                 default:
1182                         g_print("\tInvalid command [%d]\n", idx);
1183                         break;
1184                 }
1185                 break;
1186         case '4': /* Setting > AF scan range */
1187                 g_print("\t* AF scan range !\n");
1188                 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1189                 g_print("\tCommand > ");
1190                 err = scanf("%d", &idx);
1191                 flush_stdin();
1192                 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1193                 break;
1194         case '5': /* Setting > Exposure mode */
1195                 g_print("* Exposure mode!\n");
1196                 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1197                 g_print("\n Select  Exposure mode \n");
1198                 err = scanf("%d", &idx);
1199                 flush_stdin();
1200                 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1201                 break;
1202
1203         case '6': /* Setting > Exposure value */
1204                 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1205                 if (min >= max)
1206                         g_print("Not supported !! \n");
1207                 else {
1208                         g_print("\n Select  Exposure mode min%d -max %d\n", min, max);
1209                         err = scanf("%d", &idx);
1210                         flush_stdin();
1211                         bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1212                 }
1213                 break;
1214         case '7': /* Setting > F number */
1215                 g_print("Not supported !! \n");
1216                 break;
1217         case '8': /* Setting > Display reuse hint */
1218                 {
1219                         bool reuse_hint = false;
1220
1221                         err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1222                         if (err != CAMERA_ERROR_NONE) {
1223                                 g_print("failed to get display reuse hint 0x%x\n", err);
1224                                 break;
1225                         }
1226
1227                         g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1228                         reuse_hint = !reuse_hint;
1229                         err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1230                         g_print("set display reuse hint result : 0x%x\n", err);
1231                 }
1232                 break;
1233         case '9': /* Setting > Manual focus */
1234                 g_print("*Manual focus !\n");
1235                 camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
1236                 if (min > max) {
1237                         g_print("\n\tManual focus is NOT SUPPORTED\n");
1238                         break;
1239                 }
1240                 camera_attr_get_focus_level(hcamcorder->camera, &idx);
1241                 g_print("\tCurrent focus level (%d)\n", idx);
1242                 g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
1243                 err = scanf("%d", &idx);
1244                 flush_stdin();
1245                 bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
1246                 idx = -1;
1247                 if (bret == CAMERA_ERROR_NONE) {
1248                         bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
1249                         g_print("\tfocus level[%d] after set\n", idx);
1250                 } else {
1251                         g_print("\tset focus level failed[0x%x]\n", bret);
1252                 }
1253                 break;
1254         case 'i': /* Setting > ISO */
1255                 g_print("*ISO !\n");
1256                 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1257                 err = scanf("%d", &idx);
1258                 flush_stdin();
1259                 bret =  camera_attr_set_iso(hcamcorder->camera, idx);
1260                 break;
1261         case 'r': /* Setting > Rotate camera input when recording */
1262                 g_print("*Rotate camera input\n");
1263                 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1264                 err = scanf("%d", &idx);
1265                 flush_stdin();
1266                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1267                 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1268                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1269                 break;
1270         case 'f': /* Setting > Flip camera input */
1271                 g_print("*Flip camera input\n");
1272                 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1273                 err = scanf("%d", &idx);
1274                 flush_stdin();
1275                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1276                 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1277                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1278                 break;
1279         case 'j': /* Setting > Jpeg quality */
1280                 g_print("*Jpeg quality !\n");
1281                 g_print("\n Select  Jpeg quality \n");
1282                 err = scanf("%d", &idx);
1283                 flush_stdin();
1284                 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1285                 break;
1286         case 'p': /* Setting > Picture format */
1287                 g_print("* Picture format!\n");
1288                 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1289                 err = scanf("%d", &idx);
1290                 flush_stdin();
1291                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1292                 bret = camera_set_preview_format(hcamcorder->camera, idx);
1293                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1294                 break;
1295         case 'E': /* Setting > EXIF orientation */
1296                 g_print("* EXIF Orientation\n");
1297                 g_print("\t 1. TOP_LEFT\n");
1298                 g_print("\t 2. TOP_RIGHT(flipped)\n");
1299                 g_print("\t 3. BOTTOM_RIGHT\n");
1300                 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1301                 g_print("\t 5. LEFT_TOP(flipped)\n");
1302                 g_print("\t 6. RIGHT_TOP\n");
1303                 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1304                 g_print("\t 8. LEFT_BOTTOM\n");
1305                 err = scanf("%d", &idx);
1306                 flush_stdin();
1307                 if (idx < 1 || idx > 8)
1308                         g_print("Wrong INPUT[%d]!! \n", idx);
1309                 else
1310                         camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1311                 break;
1312         case 'F': /* Setting > Get Facing direction */
1313                 g_print("* Get facing direction of camera module\n");
1314                 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1315                 if (CAMERA_ERROR_NONE == err)
1316                         g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1317                 else
1318                         g_print("* Error : %d\n", err);
1319                 break;
1320         case 's': /* Setting > Set extra preview stream format */
1321                 g_print("* Set extra preview stream format\n");
1322
1323                 g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
1324                 err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
1325                 flush_stdin();
1326
1327                 err = camera_set_extra_preview_stream_format(hcamcorder->camera,
1328                         stream_id, pixel_format, width, height, fps);
1329                 if (err != CAMERA_ERROR_NONE) {
1330                         g_print("* Set Error : 0x%x\n", err);
1331                         break;
1332                 }
1333
1334                 pixel_format = width = height = fps = -1;
1335
1336                 err = camera_get_extra_preview_stream_format(hcamcorder->camera,
1337                         stream_id, &pixel_format, &width, &height, &fps);
1338                 if (err != CAMERA_ERROR_NONE) {
1339                         g_print("* Get Error : 0x%x\n", err);
1340                         break;
1341                 }
1342
1343                 g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
1344                         stream_id, pixel_format, width, height, fps);
1345                 break;
1346         case 'B': /* Setting > Set extra preview bitrate */
1347                 g_print("* Set extra preview bitrate\n");
1348
1349                 g_print("\tstream_id,bitrate : ");
1350                 err = scanf("%d,%d", &stream_id, &bitrate);
1351                 flush_stdin();
1352
1353                 err = camera_attr_set_extra_preview_bitrate(hcamcorder->camera, stream_id, bitrate);
1354                 if (err != CAMERA_ERROR_NONE) {
1355                         g_print("* Set Error : 0x%x\n", err);
1356                         break;
1357                 }
1358
1359                 bitrate = -1;
1360
1361                 err = camera_attr_get_extra_preview_bitrate(hcamcorder->camera, stream_id, &bitrate);
1362                 if (err != CAMERA_ERROR_NONE) {
1363                         g_print("* Get Error : 0x%x\n", err);
1364                         break;
1365                 }
1366
1367                 g_print("\tGet stream_id[%d],bitrate[%d]\n", stream_id, bitrate);
1368                 break;
1369                 /* Display / Filter setting */
1370         case 'v': /* Display visible */
1371                 g_print("* Display visible setting !\n");
1372                 g_print("\n Select Display visible \n");
1373                 for (i = 0 ; i < 2 ; i++)
1374                         g_print("\t %d. %s\n", i, visible_mode[i]);
1375                 err = scanf("%d", &idx);
1376                 flush_stdin();
1377                 if (idx == 0 || idx == 1)
1378                         bret = camera_set_display_visible(hcamcorder->camera, idx);
1379                 else
1380                         g_print("invalid input %d", idx);
1381                 break;
1382         case 'o': /* Setting > Display Mode */
1383                 g_print("* Display mode!\n");
1384                 for (i = 0 ; i < 5 ; i++)
1385                         g_print("%d. %s\n", i, display_mode[i]);
1386                 err = scanf("%d", &idx);
1387                 flush_stdin();
1388                 bret =  camera_set_display_mode(hcamcorder->camera, idx);
1389                 break;
1390         case 'y': /* Setting > Rotate Display */
1391                 g_print("\n Select Rotate mode\n");
1392                 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1393                 err = scanf("%d", &idx);
1394                 flush_stdin();
1395                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1396                 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1397                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1398                 break;
1399         case 'Y': /* Setting > Flip Display */
1400                 g_print("\n Select Rotate mode\n");
1401                 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1402                 err = scanf("%d", &idx);
1403                 flush_stdin();
1404                 bret = camera_set_display_flip(hcamcorder->camera, idx);
1405                 break;
1406         case 'g': /* Setting > Brightness */
1407                 g_print("*Brightness !\n");
1408                 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1409                 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1410                 err = scanf("%d", &idx);
1411                 flush_stdin();
1412                 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1413                 break;
1414         case 'c': /* Setting > Contrast */
1415                 g_print("*Contrast !\n");
1416                 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1417                 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1418                 err = scanf("%d", &idx);
1419                 flush_stdin();
1420                 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1421                 break;
1422         case 'h': /* Setting > Hue */
1423                 g_print("*Hue !\n");
1424                 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1425                 if (max >= min) {
1426                         g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1427                         err = scanf("%d", &idx);
1428                         flush_stdin();
1429                         bret = camera_attr_set_hue(hcamcorder->camera, idx);
1430                 } else {
1431                         g_print("\n Hue is not supported (%d,%d)\n", min, max);
1432                 }
1433                 break;
1434         case 'w': /* Setting > White balance */
1435                 g_print("*White balance !\n");
1436                 g_print("\n Select White balance \n");
1437                 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1438                 err = scanf("%d", &idx);
1439                 flush_stdin();
1440                 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1441                 break;
1442         case 't': /* Setting > Color tone */
1443                 g_print("*Color tone !\n");
1444                 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1445                 g_print("\n Select Color tone \n");
1446                 err = scanf("%d", &idx);
1447                 flush_stdin();
1448                 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1449                 break;
1450         case 'd': /* Setting > WDR */
1451                 g_print("*WDR !\n");
1452                 g_print("\n Select WDR Mode \n");
1453                 for (i = 0 ; i < 2 ; i++)
1454                         g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1455                 err = scanf("%d", &idx);
1456                 flush_stdin();
1457                 if (idx == 1)
1458                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1459                 else if (idx == 2)
1460                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1461                 break;
1462         case 'e': /* Setting > EV program mode */
1463                 g_print("* EV program mode!\n");
1464                 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1465                 g_print("\n Select EV program mode \n");
1466                 err = scanf("%d", &idx);
1467                 flush_stdin();
1468                 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1469                 break;
1470         case 'R': /* Setting > Display ROI area */
1471                 g_print("* Set display roi area. Select x y width height \n");
1472                 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1473                 flush_stdin();
1474                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1475                 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1476                 if (CAMERA_ERROR_NONE != err)
1477                         g_print("* Error : %d\n", err);
1478
1479                 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1480                 if (CAMERA_ERROR_NONE == err)
1481                         g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1482                 else
1483                         g_print("* Error : %d\n", err);
1484                 break;
1485
1486                 /* ext. setting */
1487         case 'z': /* Setting > Strobe setting */
1488                 g_print("*Strobe Mode\n");
1489                 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1490                 g_print("\n Select Strobe Mode \n");
1491                 err = scanf("%d", &idx);
1492                 flush_stdin();
1493                 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1494                 break;
1495         case 'S': /* Setting > flash state */
1496                 g_print("*flash state\n");
1497                 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1498                 if (CAMERA_ERROR_NONE == err)
1499                         g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1500                 else
1501                         g_print("* Error : %d\n", err);
1502                 break;
1503         case 'G': /* Setting > flash brightness */
1504                 g_print("*Flash brightness !\n");
1505                 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1506                 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1507                 err = scanf("%d", &idx);
1508                 flush_stdin();
1509                 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1510                 break;
1511         case 'x': /* Setting > Capture mode ,Muitishot? */
1512                 g_print("*Select Capture mode!\n");
1513                 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1514                 err = scanf("%d", &idx);
1515                 flush_stdin();
1516
1517                 switch (idx) {
1518                 case 1:
1519                         g_print("stillshot mode selected and capture callback is set!!!!\n");
1520                         hcamcorder->is_multishot = FALSE;
1521                         camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1522                         break;
1523                 case 2:
1524                         g_print("HDR Capture mode selected\n");
1525                         hcamcorder->is_multishot = FALSE;
1526                         g_print("\nSelect HDR capture mode\n");
1527                         for (i = 0 ; i < 3 ; i++)
1528                                 g_print("\t %d. %s\n", i, hdr_mode[i]);
1529                         err = scanf("%d", &idx);
1530                         flush_stdin();
1531                         if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1532                                 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1533                         else
1534                                 g_print("invalid input %d\n", idx);
1535                         break;
1536                 default:
1537                         g_print("Wrong input, select again!!\n");
1538                         break;
1539                 }
1540                 break;
1541         case 'l': /* Setting > Face detection setting */
1542                 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1543                         g_print("* Face detect mode !\n");
1544                         for (i = 0 ; i < 2 ; i++)
1545                                 g_print("\t %d. %s \n", i, detection_mode[i]);
1546                         err = scanf("%d", &idx);
1547                         flush_stdin();
1548                         if (idx == 0)
1549                                 bret = camera_stop_face_detection(hcamcorder->camera);
1550                         else if (idx == 1)
1551                                 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1552                         else
1553                                 g_print("\n invalid input [%d]\n\n", idx);
1554                 } else {
1555                         g_print("face detection_not supported");
1556                 }
1557                 break;
1558         case 'k': /* Setting > Anti-handshake */
1559                 g_print("*Anti-handshake !\n");
1560                 g_print("\n Select Anti-handshake mode \n");
1561                 for (i = 0; i < 2; i++)
1562                         g_print("\t %d. %s\n", i, ahs_mode[i]);
1563                 err = scanf("%d", &idx);
1564                 flush_stdin();
1565                 if (idx == 0 || idx == 1)
1566                         bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1567                 else
1568                         g_print("invalid input %d\n", idx);
1569                 break;
1570         case 'K': /* Setting > Video-stabilization */
1571                 g_print("*Video-stabilization !\n");
1572                 g_print("\n Select Video-stabilization mode \n");
1573                 for (i = 0 ; i < 2 ; i++)
1574                         g_print("\t %d. %s\n", i, vs_mode[i]);
1575                 err = scanf("%d", &idx);
1576                 flush_stdin();
1577                 if (idx < 0 || idx > 1) {
1578                         g_print("invalid input %d\n", idx);
1579                         break;
1580                 }
1581
1582                 if (idx == 1) {
1583                         g_print("\n Restart preview with NV12 and 720p resolution\n");
1584                         err = camera_stop_preview(hcamcorder->camera);
1585                         g_print("stop preview result 0x%x\n", err);
1586                         camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1587                         camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1588                 }
1589
1590                 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1591
1592                 if (idx == 1) {
1593                         err = camera_start_preview(hcamcorder->camera);
1594                         if (err != CAMERA_ERROR_NONE)
1595                                 g_print("\n Restart FAILED! 0x%x\n", err);
1596                 }
1597                 break;
1598         case 'u': /* Touch AF area */
1599                 g_print("* Touch AF area !\n");
1600                 g_print("\n Input x,y,width,height \n");
1601                 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1602                 flush_stdin();
1603                 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1604                 if (err != 0)
1605                         g_print("Failed to set touch AF area.(%x)\n", err);
1606                 else
1607                         g_print("Succeed to set touch AF area.\n");
1608                 break;
1609         case 'n': /* file path */
1610                 g_print("* File path !\n");
1611                 g_print("\n Input file path to save captured data(string) : ");
1612                 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1613                         hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1614                         g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1615                 } else {
1616                         g_print("\nset file path failed\n");
1617                 }
1618                 break;
1619         case 'm': /* media bridge */
1620                 g_print("* Media Bridge !\n");
1621                 g_print("\tUnset[0] / Set[Others] :");
1622                 err = scanf("%d", &set_bridge);
1623                 flush_stdin();
1624                 if (set_bridge) {
1625                         __release_media_bridge();
1626
1627                         err = media_bridge_create(&bridge);
1628                         err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
1629                 } else {
1630                         __release_media_bridge();
1631                 }
1632                 g_print("\tresult[0x%x]\n\n", err);
1633                 break;
1634         case 'b': /* back */
1635                 hcamcorder->menu_state = MENU_STATE_MAIN;
1636                 break;
1637         default:
1638                 g_print("\t Invalid input \n");
1639                 break;
1640         }
1641
1642         g_print("\t bret : 0x%x \n", bret);
1643
1644         return;
1645 }
1646
1647
1648 static void device_state_menu(gchar buf)
1649 {
1650         int ret = 0;
1651         camera_device_e device = CAMERA_DEVICE_CAMERA0;
1652         camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1653
1654         switch (buf) {
1655         case '1': /* Get device state */
1656                 while (1) {
1657                         g_print("\n\tEnter Camera Index[0~9]: ");
1658
1659                         ret = scanf("%d", (int *)&device);
1660                         flush_stdin();
1661
1662                         if (ret == EOF) {
1663                                 g_print("\n\t!!!read input error!!!\n");
1664                                 return;
1665                         }
1666
1667                         if (device < CAMERA_DEVICE_CAMERA0 ||
1668                                 device > CAMERA_DEVICE_CAMERA9) {
1669                                 g_print("\n\tinvalid input:[%d], try again...\n", device);
1670                                 continue;
1671                         }
1672
1673                         ret = camera_get_device_state(device, &device_state);
1674                         g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1675                                 device, device_state, ret);
1676                         break;
1677                 }
1678                 break;
1679         case '2': /* Add device state changed callback */
1680                 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1681                         NULL, &g_camera_device_state_changed_cb_id);
1682                 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1683                 break;
1684         case '3': /* Remove device state changed callback */
1685                 if (g_camera_device_state_changed_cb_id > 0) {
1686                         ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1687                         g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1688                         g_camera_device_state_changed_cb_id = 0;
1689                 } else {
1690                         g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1691                 }
1692                 break;
1693         case 'b': /* back */
1694                 hcamcorder->menu_state = MENU_STATE_INIT;
1695                 break;
1696         default:
1697                 g_print("\n\tinvalid input[%c]\n", buf);
1698                 break;
1699         }
1700
1701         return;
1702 }
1703
1704 static void device_list_menu(gchar buf)
1705 {
1706         int ret = 0;
1707         unsigned int i = 0;
1708         camera_device_list_s device_list;
1709
1710         switch (buf) {
1711         case '1': /* Initialize device manager */
1712                 ret = camera_device_manager_initialize(&g_device_manager);
1713                 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1714                         g_device_manager, ret);
1715                 break;
1716         case '2': /* Get device list */
1717                 memset(&device_list, 0x0, sizeof(camera_device_list_s));
1718                 ret = camera_device_manager_get_device_list(g_device_manager, &device_list);
1719                 if (ret != CAMERA_ERROR_NONE) {
1720                         g_print("\n\tGet device list failed[0x%x]\n", ret);
1721                         return;
1722                 }
1723
1724                 g_print("\n\tDevice list[count:%d]\n", device_list.count);
1725
1726                 for (i = 0 ; i < device_list.count ; i++) {
1727                         g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
1728                                 i, device_list.device[i].type, device_list.device[i].index,
1729                                 device_list.device[i].name, device_list.device[i].id);
1730                 }
1731                 break;
1732         case '3': /* Add device connection changed callback */
1733                 ret = camera_device_manager_add_device_connection_changed_cb(g_device_manager,
1734                         _camera_device_connection_changed_cb, NULL, &g_camera_device_connection_changed_cb_id);
1735                 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1736                 break;
1737         case '4': /* Remove device connection changed callback */
1738                 if (g_camera_device_connection_changed_cb_id > 0) {
1739                         ret = camera_device_manager_remove_device_connection_changed_cb(g_device_manager,
1740                                 g_camera_device_connection_changed_cb_id);
1741                         g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_connection_changed_cb_id);
1742                         g_camera_device_connection_changed_cb_id = 0;
1743                 } else {
1744                         g_print("\n\tinvalid cb id[%d]\n", g_camera_device_connection_changed_cb_id);
1745                 }
1746                 break;
1747         case '9': /* Deinitialize device manager */
1748                 ret = camera_device_manager_deinitialize(g_device_manager);
1749                 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1750                         g_device_manager, ret);
1751                 g_device_manager = NULL;
1752                 break;
1753         case 'b': /* back */
1754                 hcamcorder->menu_state = MENU_STATE_INIT;
1755                 break;
1756         default:
1757                 g_print("\n\tinvalid input[%c]\n", buf);
1758                 break;
1759         }
1760
1761         return;
1762 }
1763
1764
1765 /**
1766  * This function is to execute command.
1767  *
1768  * @param   channel [in]    1st parameter
1769  *
1770  * @return  This function returns TRUE/FALSE
1771  * @remark
1772  * @see
1773  */
1774 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1775 {
1776         gchar *buf = NULL;
1777         gsize read_size;
1778         GError *g_error = NULL;
1779
1780         g_print("\n\tENTER\n");
1781
1782         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1783         if (g_error) {
1784                 g_print("\n\tg_io_channel_read_chars error\n");
1785                 g_error_free(g_error);
1786                 g_error = NULL;
1787         }
1788
1789         if (buf) {
1790                 g_strstrip(buf);
1791
1792                 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1793                 switch (hcamcorder->menu_state) {
1794                 case MENU_STATE_INIT:
1795                         mode_change(buf[0]);
1796                         break;
1797                 case MENU_STATE_MAIN:
1798                         main_menu(buf[0]);
1799                         break;
1800                 case MENU_STATE_MAIN_SETTING:
1801                         setting_menu(buf[0]);
1802                         break;
1803                 case MENU_STATE_DEVICE_STATE:
1804                         device_state_menu(buf[0]);
1805                         break;
1806                 case MENU_STATE_DEVICE_LIST:
1807                         device_list_menu(buf[0]);
1808                         break;
1809                 default:
1810                         break;
1811                 }
1812
1813                 g_free(buf);
1814                 buf = NULL;
1815
1816                 print_menu();
1817         } else {
1818                 g_print("\n\tNo read input\n");
1819         }
1820
1821         return TRUE;
1822 }
1823
1824 static gboolean init_handle()
1825 {
1826         hcamcorder->is_multishot =  FALSE;
1827         hcamcorder->stillshot_count = 0;
1828         hcamcorder->multishot_count = 0;
1829         snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1830         hcamcorder->menu_state = MENU_STATE_INIT;
1831         hcamcorder->elapsed_time = 0;
1832
1833         return TRUE;
1834 }
1835
1836
1837 /**
1838  * This function is to change camcorder mode.
1839  *
1840  * @param   buf    [in]    user input
1841  *
1842  * @return  This function returns TRUE/FALSE
1843  * @remark
1844  * @see     other functions
1845  */
1846 static gboolean mode_change(gchar buf)
1847 {
1848         int err = 0;
1849         int camera_type = 0;
1850         int display_type = 0;
1851         bool check = FALSE;
1852
1853         switch (buf) {
1854         case '1':
1855                 while (1) {
1856                         g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1857                         err = scanf("%d", &camera_type);
1858                         flush_stdin();
1859                         if (err == EOF) {
1860                                 g_print("\t!!!read input error!!!\n");
1861                                 continue;
1862                         }
1863
1864                         if (camera_type != 0 && camera_type != 1) {
1865                                 g_print("\t Invalid camera type(%d)\n", camera_type);
1866                                 continue;
1867                         }
1868
1869                         g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1870                         err = scanf("%d", (int *)&camera_device);
1871                         flush_stdin();
1872                         if (err == EOF) {
1873                                 g_print("\t!!!read input error!!!\n");
1874                                 continue;
1875                         }
1876
1877                         if (camera_device < 0 || camera_device > 9) {
1878                                 g_print("\t Invalid camera device(%d)\n", camera_device);
1879                                 continue;
1880                         }
1881
1882                         hcamcorder->type = camera_device;
1883
1884                         break;
1885                 }
1886                 break;
1887         case '2':
1888                 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1889                 return TRUE;
1890         case '3':
1891                 hcamcorder->menu_state = MENU_STATE_DEVICE_LIST;
1892                 return TRUE;
1893         case 'q':
1894                 g_print("\t Quit Camcorder Testsuite!!\n");
1895                 elm_exit();
1896                 return FALSE;
1897         default:
1898                 g_print("\t Invalid media type(%c)\n", buf);
1899                 return FALSE;
1900         }
1901
1902         g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
1903
1904         gettimeofday(&previous_time, NULL);
1905
1906         g_timer_reset(timer);
1907
1908         if (camera_type)
1909                 err = camera_create_network(camera_device, &hcamcorder->camera);
1910         else
1911                 err = camera_create(camera_device, &hcamcorder->camera);
1912
1913         g_print("[camera_create()  : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1914
1915         if (err != 0) {
1916                 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1917                 return -1;
1918         }
1919
1920         while (!check) {
1921                 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1922                 err = scanf("%d", &display_type);
1923                 flush_stdin();
1924                 if (err == EOF) {
1925                         g_print("\t!!!read input error!!!\n");
1926                         continue;
1927                 }
1928
1929                 switch (display_type) {
1930                 case 1:
1931                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1932                         check = TRUE;
1933                         break;
1934                 case 2:
1935                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1936                         check = TRUE;
1937                         break;
1938                 case 3:
1939                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1940                         check = TRUE;
1941                         break;
1942                 default:
1943                         g_print("\t Invalid display type(%d)\n", display_type);
1944                         break;
1945                 }
1946         }
1947
1948         camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1949         camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1950         camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1951         camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1952         camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1953         /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1954         /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1955         /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1956
1957         camera_start_preview(hcamcorder->camera);
1958
1959         gettimeofday(&current_time, NULL);
1960         timersub(&current_time, &previous_time, &result_time);
1961
1962         g_print("\n\tCamera Starting Time  : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1963
1964         hcamcorder->menu_state = MENU_STATE_MAIN;
1965
1966         return TRUE;
1967 }
1968
1969 static int app_create(void *data)
1970 {
1971         appdata *app_data = data;
1972         int w = 0;
1973         int h = 0;
1974         Evas_Object *win = NULL;
1975         Evas_Object *eo = NULL;
1976         Evas_Object *bg = NULL;
1977         Evas_Object *rect = NULL;
1978
1979         if (app_data == NULL) {
1980                 g_print("\t\nappdata is NULL\n");
1981                 return 0;
1982         }
1983
1984         /* use gl backend */
1985         elm_config_accel_preference_set("opengl");
1986
1987         win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1988         if (win) {
1989                 elm_win_title_set(win, "camera_test");
1990                 elm_win_borderless_set(win, EINA_TRUE);
1991                 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1992                 g_print("\n\tscreen size %dx%d\n\n", w, h);
1993                 evas_object_resize(win, w, h);
1994                 elm_win_autodel_set(win, EINA_TRUE);
1995                 elm_win_alpha_set(win, EINA_TRUE);
1996         } else {
1997                 g_print("\n\tfailed to get window\n\n");
1998                 return 1;
1999         }
2000
2001         bg = elm_bg_add(win);
2002         if (bg) {
2003                 elm_win_resize_object_add(win, bg);
2004                 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2005                 evas_object_show(bg);
2006         } else {
2007                 g_print("\n\tfailed to get elm bg\n\n");
2008                 return 1;
2009         }
2010
2011         rect = evas_object_rectangle_add(evas_object_evas_get(win));
2012         if (rect) {
2013                 evas_object_color_set(rect, 0, 0, 0, 0);
2014                 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
2015         } else {
2016                 g_print("\n\tfailed to get rectangle\n\n");
2017                 return 1;
2018         }
2019
2020         elm_win_resize_object_add(win, rect);
2021         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2022         evas_object_show(rect);
2023
2024         /* Create evas image object for EVAS surface */
2025         eo = evas_object_image_add(evas_object_evas_get(win));
2026         evas_object_image_size_set(eo, w, h);
2027         evas_object_image_fill_set(eo, 0, 0, w, h);
2028         evas_object_resize(eo, w, h);
2029         evas_object_show(eo);
2030
2031         elm_win_activate(win);
2032         evas_object_show(win);
2033
2034         app_data->win = win;
2035         app_data->eo = eo;
2036
2037         timer = g_timer_new();
2038         g_timer_reset(timer);
2039
2040         init_handle();
2041
2042         print_menu();
2043
2044         return 0;
2045 }
2046
2047 static int app_terminate(void *data)
2048 {
2049         appdata *app_data = data;
2050
2051         if (app_data == NULL) {
2052                 g_print("\n\tappdata is NULL\n");
2053                 return 0;
2054         }
2055
2056         if (timer) {
2057                 g_timer_stop(timer);
2058                 g_timer_destroy(timer);
2059                 timer = NULL;
2060         }
2061
2062         return 0;
2063 }
2064
2065
2066 /**
2067  * This function is the example main function for mmcamcorder API.
2068  *
2069  * @param
2070  *
2071  * @return  This function returns 0.
2072  * @remark
2073  * @see     other functions
2074  */
2075 int main(int argc, char **argv)
2076 {
2077         int bret;
2078
2079         hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
2080
2081         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
2082         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
2083
2084         memset(&ad, 0x0, sizeof(appdata));
2085         ops.data = &ad;
2086
2087         bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
2088
2089         g_print("\n\treturn appcore_efl : %d\n\n", bret);
2090
2091         g_free(hcamcorder);
2092         g_io_channel_unref(stdin_channel);
2093
2094         return bret;
2095 }
2096 /*EOF*/