Add new internal APIs for extra preview stream format
[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_list_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_list_changed_cb(camera_device_list_s *device_list, void *user_data)
470 {
471         unsigned int i = 0;
472
473         if (!device_list) {
474                 g_print("NULL list");
475                 return;
476         }
477
478         g_print("\n\tcamera device list changed[count:%d]\n", device_list->count);
479
480         for (i = 0 ; i < device_list->count ; i++) {
481                 g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
482                         i, device_list->device[i].type, device_list->device[i].index,
483                         device_list->device[i].name, device_list->device[i].id);
484         }
485
486         return;
487 }
488
489 static void _camera_interrupted_cb(camera_policy_e policy, camera_state_e previous, camera_state_e current, void *user_data)
490 {
491         g_print("\n\tcamera interrupted callback called[state %d -> %d, policy %d]\n",
492                 previous, current, policy);
493
494         return;
495 }
496
497 static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
498 {
499         g_print("\n\tcamera interrupt started callback called[state %d, policy %d]\n", state, policy);
500
501         return;
502 }
503
504 static void _dump_preview_data(camera_preview_data_s *frame, const char *file_name)
505 {
506         char dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
507         FILE *fp = NULL;
508
509         if (!frame) {
510                 g_print("\n[DUMP_PREVIEW_DATA] NULL frame\n");
511                 return;
512         }
513
514         snprintf(dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, file_name);
515
516         fp = fopen(dump_path, "a");
517         if (fp == NULL) {
518                 g_print("\n[DUMP_PREVIEW_DATA] file[%s] open failed\n", dump_path);
519                 return;
520         }
521
522         switch (frame->format) {
523         case CAMERA_PIXEL_FORMAT_RGBA:
524                 /* fall through */
525         case CAMERA_PIXEL_FORMAT_ARGB:
526                 fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp);
527                 break;
528         case CAMERA_PIXEL_FORMAT_INVZ:
529                 fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp);
530                 break;
531         case CAMERA_PIXEL_FORMAT_H264:
532                 /* fall through */
533         case CAMERA_PIXEL_FORMAT_MJPEG:
534                 /* fall through */
535         case CAMERA_PIXEL_FORMAT_VP8:
536                 /* fall through */
537         case CAMERA_PIXEL_FORMAT_VP9:
538                 fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp);
539                 break;
540         default:
541                 switch (frame->num_of_planes) {
542                 case 1:
543                         fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
544                         break;
545                 case 2:
546                         fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
547                         fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
548                         break;
549                 case 3:
550                         fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
551                         fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
552                         fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
553                         break;
554                 default:
555                         break;
556                 }
557                 break;
558         }
559
560         g_print("[DUMP_PREVIEW_DATA] file[%s] write done\n", dump_path);
561
562         fclose(fp);
563 }
564
565 static void _camera_print_preview_info(camera_preview_data_s *frame)
566 {
567         if (!frame) {
568                 g_print("\n[PREVIEW_CB] NULL frame!\n");
569                 return;
570         }
571
572         g_print("format[%d] res[%dx%d] num plane[%d] ",
573                 frame->format, frame->width, frame->height, frame->num_of_planes);
574
575         if (frame->num_of_planes == 1) {
576                 g_print("size [%d]\n",
577                         frame->data.single_plane.size);
578         } else if (frame->num_of_planes == 2) {
579                 g_print("size Y[%d] UV[%d]\n",
580                         frame->data.double_plane.y_size,
581                         frame->data.double_plane.uv_size);
582         } else if (frame->num_of_planes == 3) {
583                 g_print("size Y[%d] U[%d] V[%d]\n",
584                         frame->data.triple_plane.y_size,
585                         frame->data.triple_plane.u_size,
586                         frame->data.triple_plane.v_size);
587         }
588 }
589
590 static void _camera_preview_cb(camera_preview_data_s *frame, void *user_data)
591 {
592         if (!frame) {
593                 g_print("\n[PREVIEW_CB] NULL frame!\n");
594                 return;
595         }
596
597         g_print("[PREVIEW_CB] preview callback - ");
598
599         _camera_print_preview_info(frame);
600
601         if (g_camera_preview_cb_dump)
602                 _dump_preview_data(frame, PREVIEW_CB_DUMP_FILE_NAME);
603 }
604
605 static void _camera_extra_preview_cb(camera_preview_data_s *frame, int stream_id, void *user_data)
606 {
607         if (!frame) {
608                 g_print("\n[PREVIEW_CB] NULL frame!\n");
609                 return;
610         }
611
612         g_print("[EXTRA_PREVIEW_CB][stream_id:%d] preview callback - ", stream_id);
613
614         _camera_print_preview_info(frame);
615
616         if (g_camera_extra_preview_cb_dump)
617                 _dump_preview_data(frame, EXTRA_PREVIEW_CB_DUMP_FILE_NAME);
618 }
619
620
621 static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data)
622 {
623         int ret = 0;
624         int width = 0;
625         int height = 0;
626         unsigned int i = 0;
627         char mp_dump_path[MAX_FILE_NAME_LENGTH] = {'\0',};
628         FILE *fp = NULL;
629         media_format_h fmt = NULL;
630         media_format_mimetype_e type = MEDIA_FORMAT_I420;
631         tbm_surface_h surface = NULL;
632         tbm_surface_info_s s_info;
633
634         if (!pkt) {
635                 g_print("\n[MP_PREVIEW_CB] NULL packet!\n");
636                 return;
637         }
638
639         ret = media_packet_get_format(pkt, &fmt);
640         if (ret != MEDIA_PACKET_ERROR_NONE) {
641                 g_print("\n[MP_PREVIEW_CB] get media format failed[0x%x]", ret);
642                 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
643         }
644
645         ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL);
646         if (ret != MEDIA_FORMAT_ERROR_NONE) {
647                 g_print("\n[MP_PREVIEW_CB] get video info failed[0x%x]", ret);
648                 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
649         }
650
651         g_print("[MP_PREVIEW_CB] media_packet_preview_cb[mimetype:0x%x, %dx%d]\n", type, width, height);
652
653         ret = media_packet_get_tbm_surface(pkt, &surface);
654         if (ret != MEDIA_PACKET_ERROR_NONE) {
655                 g_print("\n[MP_PREVIEW_CB] get tbm surface failed[0x%x] ====\n", ret);
656                 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
657         }
658
659         ret = tbm_surface_get_info(surface, &s_info);
660         if (ret != TBM_SURFACE_ERROR_NONE) {
661                 g_print("\n[MP_PREVIEW_CB] get tbm surface info failed[0x%x] ====\n", ret);
662                 goto _MEDIA_PACKET_PREVIEW_CB_OUT;
663         }
664
665         g_print("                tbm surface [%dx%d], total size[%u]\n",
666                 s_info.width, s_info.height, s_info.size);
667
668         if (g_camera_mp_preview_cb_dump) {
669                 snprintf(mp_dump_path, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, MP_PREVIEW_CB_DUMP_FILE_NAME);
670                 fp = fopen(mp_dump_path, "a");
671                 if (fp == NULL) {
672                         g_print("\n[MP_PREVIEW_CB] file[%s] open failed ====\n", mp_dump_path);
673                         goto _MEDIA_PACKET_PREVIEW_CB_OUT;
674                 }
675         }
676
677         for (i = 0 ; i < s_info.num_planes ; i++) {
678                 g_print("                    plane[%d][%p] stride[%u] size[%u]\n",
679                         i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size);
680                 if (fp)
681                         fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp);
682         }
683
684 _MEDIA_PACKET_PREVIEW_CB_OUT:
685         if (fp)
686                 fclose(fp);
687
688         media_packet_unref(pkt);
689 }
690
691
692 static bool preview_resolution_cb(int width, int height, void *user_data)
693 {
694         resolution_stack *data = (resolution_stack *)user_data;
695
696         if (data == NULL) {
697                 g_print("NULL data\n");
698                 return false;
699         }
700
701         data->width[data->count] = width;
702         data->height[data->count] = height;
703
704         g_print("\t%d. %dx%d\n", data->count, width, height);
705
706         data->count++;
707
708         return true;
709 }
710
711 static bool capture_resolution_test_cb(int width, int height, void *user_data)
712 {
713         resolution_stack *data = (resolution_stack *)user_data;
714
715         if (data == NULL) {
716                 g_print("NULL data\n");
717                 return false;
718         }
719
720         data->width[data->count] = width;
721         data->height[data->count] = height;
722
723         g_print("\t%d. %dx%d\n", data->count, width, height);
724
725         data->count++;
726
727         return true;
728 }
729
730 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
731 {
732         g_print("\t%d. %s\n", mode, af_scan[mode]);
733         return true;
734 }
735
736 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
737 {
738         exposure_stack *data = (exposure_stack *)user_data;
739
740         if (data == NULL) {
741                 g_print("NULL data\n");
742                 return false;
743         }
744
745         data->mode = mode;
746         data->count++;
747
748         g_print("\t%d. %s\n", mode, exposure_mode[mode]);
749         return true;
750 }
751
752 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
753 {
754         g_print("\t%d. %s\n", mode, iso_mode[mode]);
755         return true;
756 }
757
758 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
759 {
760         g_print("\t%d. %s\n", mode, camera_rotation[mode]);
761         return true;
762 }
763
764 static bool camera_flip_cb(camera_flip_e mode, void *user_data)
765 {
766         g_print("\t%d. %s\n", mode, sensor_flip[mode]);
767         return true;
768 }
769
770 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
771 {
772         g_print("\t%d. %s\n", mode, image_fmt[mode]);
773         return true;
774 }
775
776 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
777 {
778         g_print("\t%d. %s\n", mode, wb[mode]);
779         return true;
780 }
781
782 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
783 {
784         g_print("\t%d. %s\n", mode, ct[mode]);
785         return true;
786 }
787
788 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
789 {
790         g_print("\t%d. %s\n", mode, program_mode[mode]);
791         return true;
792 }
793
794 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
795 {
796         g_print("\t%d. %s\n", mode, strobe_mode[mode]);
797         return true;
798 }
799
800 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
801 {
802         g_print("\tface detected!! - count %d\n", count);
803         int i;
804
805         for (i = 0 ; i < count ; i++)
806                 g_print("\t%d] %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
807
808         return;
809 }
810
811 static void _file_write(char *path, void *data, int size)
812 {
813         FILE *fp = NULL;
814
815         if (!path || !data || size <= 0) {
816                 g_print("\n\tERROR %p %p %d\n", path, data, size);
817                 return;
818         }
819
820         fp = fopen(path, "w");
821         if (fp) {
822                 g_print("\n\topen success [%s]\n", path);
823                 if (fwrite(data, size, 1, fp) != 1)
824                         g_print("\n\twrite error! errno %d\n", errno);
825                 else
826                         g_print("\n\twrite success [%s]\n", path);
827
828                 fclose(fp);
829                 fp = NULL;
830         } else {
831                 g_print("\n\topen error! [%s], errno %d\n", path, errno);
832         }
833
834         return;
835 }
836
837 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
838 {
839         char m_filename[MAX_FILE_NAME_LENGTH];
840
841         /* main image */
842         if (image) {
843                 if (hcamcorder->is_multishot) {
844                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
845                                 hcamcorder->file_path, hcamcorder->multishot_count++);
846                 } else {
847                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
848                                 hcamcorder->file_path, hcamcorder->stillshot_count++);
849                 }
850
851                 _file_write(m_filename, image->data, image->size);
852         }
853
854         return;
855 }
856
857 static void capture_completed_cb(void *user_data)
858 {
859         camera_start_preview(hcamcorder->camera);
860
861         return;
862 }
863
864 static void print_menu()
865 {
866         switch (hcamcorder->menu_state) {
867         case MENU_STATE_INIT:
868                 g_print("\n\t=======================================\n");
869                 g_print("\t   CAMERA_TESTSUITE\n");
870                 g_print("\t=======================================\n");
871                 g_print("\t   '1' Video Capture\n");
872                 g_print("\t   '2' Device State\n");
873                 g_print("\t   '3' Device List\n");
874                 g_print("\t   'q' Exit\n");
875                 g_print("\t=======================================\n");
876                 break;
877         case MENU_STATE_MAIN:
878                 g_print("\n\t=======================================\n");
879                 g_print("\t   Video Capture (CAMERA%d)\n", camera_device);
880                 g_print("\t=======================================\n");
881                 g_print("\t   '1' Stillshot test\n");
882                 g_print("\t   '2' Multishot test\n");
883                 g_print("\t   '3' Setting\n");
884                 g_print("\t   '4' Change device (CAMERA0 <-> CAMERA1)\n");
885                 g_print("\t   '5' Set/Unset preview callback\n");
886                 g_print("\t   '6' Set/Unset extra preview callback\n");
887                 g_print("\t   '7' Set/Unset media packet preview callback\n");
888                 g_print("\t   'b' back\n");
889                 g_print("\t=======================================\n");
890                 break;
891         case MENU_STATE_DEVICE_STATE:
892                 g_print("\n\t=======================================\n");
893                 g_print("\t   Device State\n");
894                 g_print("\t=======================================\n");
895                 g_print("\t   '1' Get camera device state\n");
896                 g_print("\t   '2' Add camera device state changed callback\n");
897                 g_print("\t   '3' Remove camera device state changed callback\n");
898                 g_print("\t   'b' back\n");
899                 g_print("\t=======================================\n");
900                 break;
901         case MENU_STATE_DEVICE_LIST:
902                 g_print("\n\t=======================================\n");
903                 g_print("\t   Device List\n");
904                 g_print("\t=======================================\n");
905                 g_print("\t   '1' Initialize device manager\n");
906                 g_print("\t   '2' Get camera device list\n");
907                 g_print("\t   '3' Add camera device list changed callback\n");
908                 g_print("\t   '4' Remove camera device list changed callback\n");
909                 g_print("\t   '5' Deinitialize device manager\n");
910                 g_print("\t   'b' back\n");
911                 g_print("\t=======================================\n");
912                 break;
913         case MENU_STATE_MAIN_SETTING:
914                 g_print("\n\t=======================================\n");
915                 g_print("\t   Video Capture > Setting\n");
916                 g_print("\t=======================================\n");
917                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera]  \n");
918                 g_print("\t     '0' Preview resolution \n");
919                 g_print("\t     '1' Capture resolution \n");
920                 g_print("\t     '2' Digital zoom level \n");
921                 g_print("\t     '3' AF mode \n");
922                 g_print("\t     '4' AF scan range \n");
923                 g_print("\t     '5' Exposure mode \n");
924                 g_print("\t     '6' Exposure value \n");
925                 g_print("\t     '7' F number \n");
926                 g_print("\t     '8' Display reuse hint \n");
927                 g_print("\t     '9' Manual Focus \n");
928                 g_print("\t     'i' ISO \n");
929                 g_print("\t     'r' Rotate camera input \n");
930                 g_print("\t     'f' Flip camera input \n");
931                 g_print("\t     'j' Jpeg quality \n");
932                 g_print("\t     'p' Picture format \n");
933                 g_print("\t     'E' EXIF orientation \n");
934                 g_print("\t     'F' Get facing direction of camera module\n");
935                 g_print("\t     's' Extra preview stream format\n");
936                 g_print("\t  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
937                 g_print("\t     'v' Visible \n");
938                 g_print("\t     'o' Output mode \n");
939                 g_print("\t     'y' Rotate display \n");
940                 g_print("\t     'Y' Flip display \n");
941                 g_print("\t     'g' Brightness \n");
942                 g_print("\t     'c' Contrast \n");
943                 g_print("\t     'h' Hue \n");
944                 g_print("\t     'w' White balance \n");
945                 g_print("\t     't' Color tone \n");
946                 g_print("\t     'd' WDR \n");
947                 g_print("\t     'e' EV program mode \n");
948                 g_print("\t     'R' Display ROI area \n");
949                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
950                 g_print("\t     'z' Strobe (Flash) \n");
951                 g_print("\t     'S' Strobe (Flash) state\n");
952                 g_print("\t     'G' Strobe (Flash) brightness\n");
953                 g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
954                 g_print("\t     'l' Face detection \n");
955                 g_print("\t     'k' Anti-handshake \n");
956                 g_print("\t     'K' Video-stabilization \n");
957                 g_print("\t     'u' Touch AF area \n");
958                 g_print("\t     'n' Set file path to write captured image\n");
959                 g_print("\t     'm' Set media bridge\n");
960                 g_print("\t     'b' back\n");
961                 g_print("\t=======================================\n");
962                 break;
963         default:
964                 g_print("\n\tunknow menu state !!\n");
965                 return;
966         }
967
968         g_print("\tCommand >> ");
969
970         return;
971 }
972
973
974 static void main_menu(gchar buf)
975 {
976         int err = 0;
977         int interval = 0;
978         int count = 0;
979         int set_cb = 0;
980
981         switch (buf) {
982         case '1': /* Capture */
983                 hcamcorder->is_multishot = FALSE;
984                 camera_attr_set_image_quality(hcamcorder->camera, 100);
985                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
986                 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
987                 break;
988         case '2': /* multishot Capture */
989                 g_print("multishot capture");
990                 hcamcorder->is_multishot = TRUE;
991                 g_print("\n\tinput interval(ms) : ");
992                 err = scanf("%d", &interval);
993                 flush_stdin();
994                 g_print("\n\tinput count : ");
995                 err = scanf("%d", &count);
996                 flush_stdin();
997                 camera_attr_set_image_quality(hcamcorder->camera, 100);
998                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
999                 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
1000                 sleep(3);
1001                 camera_start_preview(hcamcorder->camera);
1002                 break;
1003         case '3': /* Setting */
1004                 hcamcorder->menu_state = MENU_STATE_MAIN_SETTING;
1005                 break;
1006         case '4': /* Change device (CAMERA0 <-> CAMERA1) */
1007                 camera_set_display_reuse_hint(hcamcorder->camera, true);
1008
1009                 camera_stop_preview(hcamcorder->camera);
1010
1011                 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0)
1012                         hcamcorder->type = CAMERA_DEVICE_CAMERA1;
1013                 else
1014                         hcamcorder->type = CAMERA_DEVICE_CAMERA0;
1015
1016                 camera_change_device(hcamcorder->camera, hcamcorder->type);
1017
1018                 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1019                 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1020                 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1021                 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1022
1023                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1024
1025                 camera_start_preview(hcamcorder->camera);
1026                 break;
1027         case '5':
1028                 g_print("* Preview Callback\n");
1029                 g_print("\tUnset[0] / Set[Others] :");
1030                 err = scanf("%d", &set_cb);
1031                 flush_stdin();
1032                 if (set_cb) {
1033                         g_print("\n\tDump preview data to file - NO[0], YES[Others] : ");
1034                         err = scanf("%d", &g_camera_preview_cb_dump);
1035                         flush_stdin();
1036                         err = camera_set_preview_cb(hcamcorder->camera, _camera_preview_cb, hcamcorder->camera);
1037                 } else {
1038                         err = camera_unset_preview_cb(hcamcorder->camera);
1039                 }
1040                 g_print("\tresult[0x%x]\n\n", err);
1041                 break;
1042         case '6':
1043                 g_print("* Extra Preview Callback\n");
1044                 g_print("\tUnset[0] / Set[Others] :");
1045                 err = scanf("%d", &set_cb);
1046                 flush_stdin();
1047                 if (set_cb) {
1048                         g_print("\n\tDump extra preview data to file - NO[0], YES[Others] : ");
1049                         err = scanf("%d", &g_camera_extra_preview_cb_dump);
1050                         flush_stdin();
1051                         err = camera_set_extra_preview_cb(hcamcorder->camera, _camera_extra_preview_cb, hcamcorder->camera);
1052                 } else {
1053                         err = camera_unset_extra_preview_cb(hcamcorder->camera);
1054                 }
1055                 g_print("\tresult[0x%x]\n\n", err);
1056                 break;
1057         case '7':
1058                 g_print("* Media Packet Preview Callback\n");
1059                 g_print("\tUnset[0] / Set[Others] :");
1060                 err = scanf("%d", &set_cb);
1061                 flush_stdin();
1062                 if (set_cb) {
1063                         g_print("\n\tDump media packet preview data to file - NO[0], YES[Others] : ");
1064                         err = scanf("%d", &g_camera_mp_preview_cb_dump);
1065                         flush_stdin();
1066                         err = camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera);
1067                 } else {
1068                         err = camera_unset_media_packet_preview_cb(hcamcorder->camera);
1069                 }
1070                 g_print("\tresult[0x%x]\n\n", err);
1071                 break;
1072         case 'b': /* back */
1073                 __release_media_bridge();
1074
1075                 camera_stop_preview(hcamcorder->camera);
1076                 camera_destroy(hcamcorder->camera);
1077                 hcamcorder->camera = NULL;
1078                 hcamcorder->menu_state = MENU_STATE_INIT;
1079                 break;
1080         default:
1081                 g_print("\t Invalid input \n");
1082                 break;
1083         }
1084
1085         return;
1086 }
1087
1088
1089 static void setting_menu(gchar buf)
1090 {
1091         int bret = FALSE;
1092         int idx = 0;
1093         int min = 0;
1094         int max = 0;
1095         int i = 0;
1096         int err = 0;
1097         int x = 0;
1098         int y = 0;
1099         int width = 0;
1100         int height = 0;
1101         int result = 0;
1102         int set_bridge = 0;
1103         int stream_id;
1104         int pixel_format;
1105         int fps;
1106
1107         switch (buf) {
1108         /* Camera setting */
1109         case '0':  /* Setting > Preview Resolution setting */
1110                 g_print("\t* Select the preview resolution!\n");
1111                 resolution_stack resolution_list;
1112                 resolution_list.count = 0;
1113
1114                 camera_foreach_supported_preview_resolution(hcamcorder->camera,
1115                         preview_resolution_cb, &resolution_list);
1116
1117                 g_print("\tCommand >> ");
1118
1119                 err = scanf("%d", &idx);
1120                 flush_stdin();
1121                 if (resolution_list.count > idx && idx >= 0) {
1122                         g_print("\t-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
1123                                 resolution_list.width[idx], resolution_list.height[idx]);
1124
1125                         result = camera_set_preview_resolution(hcamcorder->camera,
1126                                 resolution_list.width[idx], resolution_list.height[idx]);
1127                 } else {
1128                         g_print("\tInvalid command [%d]\n", idx);
1129                         result = -1;
1130                 }
1131                 resolution_list.count = 0;
1132                 if (result == CAMERA_ERROR_NONE)
1133                         g_print("\tPASS\n");
1134                 else
1135                         g_print("\tFAIL\n");
1136                 break;
1137         case '1': /* Setting > Capture Resolution setting */
1138                 g_print("\t* Select the preview resolution!\n");
1139                 resolution_list.count = 0;
1140
1141                 camera_foreach_supported_capture_resolution(hcamcorder->camera,
1142                         capture_resolution_test_cb, &resolution_list);
1143
1144                 g_print("\tCommand > ");
1145
1146                 err = scanf("%d", &idx);
1147                 flush_stdin();
1148                 if (resolution_list.count > idx && idx >= 0) {
1149                         g_print("\t-----------------CAPTURE RESOLUTION (%dx%d)---------------------\n",
1150                                 resolution_list.width[idx], resolution_list.height[idx]);
1151
1152                         result = camera_set_capture_resolution(hcamcorder->camera,
1153                                 resolution_list.width[idx], resolution_list.height[idx]);
1154                 } else {
1155                         g_print("\tInvalid command [%d]\n", idx);
1156                         result = -1;
1157                 }
1158                 resolution_list.count = 0;
1159                 if (result == CAMERA_ERROR_NONE)
1160                         g_print("\tPASS\n");
1161                 else
1162                         g_print("\tFAIL\n");
1163                 break;
1164         case '2': /* Setting > Digital zoom level */
1165                 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
1166                 if (min > max) {
1167                         g_print("\tDigital Zoom Not supported\n");
1168                 } else {
1169                         g_print("\tDigital zoom level [%d ~ %d] > ", min, max);
1170                         err = scanf("%d", &idx);
1171                         flush_stdin();
1172                         bret = camera_attr_set_zoom(hcamcorder->camera, idx);
1173                 }
1174                 break;
1175         case '3': /* Setting > AF mode */
1176                 g_print("\tAuto Focus [1:Start, 2:Stop] > ");
1177                 err = scanf("%d", &idx);
1178                 flush_stdin();
1179                 switch (idx) {
1180                 case 1:
1181                         camera_start_focusing(hcamcorder->camera, 0);
1182                         break;
1183                 case 2:
1184                         camera_cancel_focusing(hcamcorder->camera);
1185                         break;
1186                 default:
1187                         g_print("\tInvalid command [%d]\n", idx);
1188                         break;
1189                 }
1190                 break;
1191         case '4': /* Setting > AF scan range */
1192                 g_print("\t* AF scan range !\n");
1193                 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
1194                 g_print("\tCommand > ");
1195                 err = scanf("%d", &idx);
1196                 flush_stdin();
1197                 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
1198                 break;
1199         case '5': /* Setting > Exposure mode */
1200                 g_print("* Exposure mode!\n");
1201                 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
1202                 g_print("\n Select  Exposure mode \n");
1203                 err = scanf("%d", &idx);
1204                 flush_stdin();
1205                 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
1206                 break;
1207
1208         case '6': /* Setting > Exposure value */
1209                 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
1210                 if (min >= max)
1211                         g_print("Not supported !! \n");
1212                 else {
1213                         g_print("\n Select  Exposure mode min%d -max %d\n", min, max);
1214                         err = scanf("%d", &idx);
1215                         flush_stdin();
1216                         bret = camera_attr_set_exposure(hcamcorder->camera, idx);
1217                 }
1218                 break;
1219         case '7': /* Setting > F number */
1220                 g_print("Not supported !! \n");
1221                 break;
1222         case '8': /* Setting > Display reuse hint */
1223                 {
1224                         bool reuse_hint = false;
1225
1226                         err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
1227                         if (err != CAMERA_ERROR_NONE) {
1228                                 g_print("failed to get display reuse hint 0x%x\n", err);
1229                                 break;
1230                         }
1231
1232                         g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
1233                         reuse_hint = !reuse_hint;
1234                         err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
1235                         g_print("set display reuse hint result : 0x%x\n", err);
1236                 }
1237                 break;
1238         case '9': /* Setting > Manual focus */
1239                 g_print("*Manual focus !\n");
1240                 camera_attr_get_focus_level_range(hcamcorder->camera, &min, &max);
1241                 if (min > max) {
1242                         g_print("\n\tManual focus is NOT SUPPORTED\n");
1243                         break;
1244                 }
1245                 camera_attr_get_focus_level(hcamcorder->camera, &idx);
1246                 g_print("\tCurrent focus level (%d)\n", idx);
1247                 g_print("\tSelect focus level min(%d) - max(%d) > ", min, max);
1248                 err = scanf("%d", &idx);
1249                 flush_stdin();
1250                 bret = camera_attr_set_focus_level(hcamcorder->camera, idx);
1251                 idx = -1;
1252                 if (bret == CAMERA_ERROR_NONE) {
1253                         bret = camera_attr_get_focus_level(hcamcorder->camera, &idx);
1254                         g_print("\tfocus level[%d] after set\n", idx);
1255                 } else {
1256                         g_print("\tset focus level failed[0x%x]\n", bret);
1257                 }
1258                 break;
1259         case 'i': /* Setting > ISO */
1260                 g_print("*ISO !\n");
1261                 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
1262                 err = scanf("%d", &idx);
1263                 flush_stdin();
1264                 bret =  camera_attr_set_iso(hcamcorder->camera, idx);
1265                 break;
1266         case 'r': /* Setting > Rotate camera input when recording */
1267                 g_print("*Rotate camera input\n");
1268                 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
1269                 err = scanf("%d", &idx);
1270                 flush_stdin();
1271                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1272                 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
1273                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1274                 break;
1275         case 'f': /* Setting > Flip camera input */
1276                 g_print("*Flip camera input\n");
1277                 camera_attr_foreach_supported_stream_flip(hcamcorder->camera, camera_flip_cb, NULL);
1278                 err = scanf("%d", &idx);
1279                 flush_stdin();
1280                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1281                 bret = camera_attr_set_stream_flip(hcamcorder->camera, idx);
1282                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1283                 break;
1284         case 'j': /* Setting > Jpeg quality */
1285                 g_print("*Jpeg quality !\n");
1286                 g_print("\n Select  Jpeg quality \n");
1287                 err = scanf("%d", &idx);
1288                 flush_stdin();
1289                 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
1290                 break;
1291         case 'p': /* Setting > Picture format */
1292                 g_print("* Picture format!\n");
1293                 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
1294                 err = scanf("%d", &idx);
1295                 flush_stdin();
1296                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1297                 bret = camera_set_preview_format(hcamcorder->camera, idx);
1298                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1299                 break;
1300         case 'E': /* Setting > EXIF orientation */
1301                 g_print("* EXIF Orientation\n");
1302                 g_print("\t 1. TOP_LEFT\n");
1303                 g_print("\t 2. TOP_RIGHT(flipped)\n");
1304                 g_print("\t 3. BOTTOM_RIGHT\n");
1305                 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1306                 g_print("\t 5. LEFT_TOP(flipped)\n");
1307                 g_print("\t 6. RIGHT_TOP\n");
1308                 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1309                 g_print("\t 8. LEFT_BOTTOM\n");
1310                 err = scanf("%d", &idx);
1311                 flush_stdin();
1312                 if (idx < 1 || idx > 8)
1313                         g_print("Wrong INPUT[%d]!! \n", idx);
1314                 else
1315                         camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1316                 break;
1317         case 'F': /* Setting > Get Facing direction */
1318                 g_print("* Get facing direction of camera module\n");
1319                 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1320                 if (CAMERA_ERROR_NONE == err)
1321                         g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1322                 else
1323                         g_print("* Error : %d\n", err);
1324                 break;
1325         case 's': /* Setting > Set extra preview stream format */
1326                 g_print("* Set extra preview stream format\n");
1327
1328                 g_print("\tstream_id,pixel format[NV12:0,H264:15,VP8:18],width,height,fps : ");
1329                 err = scanf("%d,%d,%d,%d,%d", &stream_id, &pixel_format, &width, &height, &fps);
1330                 flush_stdin();
1331
1332                 err = camera_set_extra_preview_stream_format(hcamcorder->camera,
1333                         stream_id, pixel_format, width, height, fps);
1334                 if (err != CAMERA_ERROR_NONE) {
1335                         g_print("* Set Error : 0x%x\n", err);
1336                         break;
1337                 }
1338
1339                 pixel_format = width = height = fps = -1;
1340
1341                 err = camera_get_extra_preview_stream_format(hcamcorder->camera,
1342                         stream_id, &pixel_format, &width, &height, &fps);
1343                 if (err != CAMERA_ERROR_NONE) {
1344                         g_print("* Get Error : 0x%x\n", err);
1345                         break;
1346                 }
1347
1348                 g_print("\tGet stream_id[%d],pixel format[%d],res[%dx%d],fps[%d]\n",
1349                         stream_id, pixel_format, width, height, fps);
1350                 break;
1351                 /* Display / Filter setting */
1352         case 'v': /* Display visible */
1353                 g_print("* Display visible setting !\n");
1354                 g_print("\n Select Display visible \n");
1355                 for (i = 0 ; i < 2 ; i++)
1356                         g_print("\t %d. %s\n", i, visible_mode[i]);
1357                 err = scanf("%d", &idx);
1358                 flush_stdin();
1359                 if (idx == 0 || idx == 1)
1360                         bret = camera_set_display_visible(hcamcorder->camera, idx);
1361                 else
1362                         g_print("invalid input %d", idx);
1363                 break;
1364         case 'o': /* Setting > Display Mode */
1365                 g_print("* Display mode!\n");
1366                 for (i = 0 ; i < 5 ; i++)
1367                         g_print("%d. %s\n", i, display_mode[i]);
1368                 err = scanf("%d", &idx);
1369                 flush_stdin();
1370                 bret =  camera_set_display_mode(hcamcorder->camera, idx);
1371                 break;
1372         case 'y': /* Setting > Rotate Display */
1373                 g_print("\n Select Rotate mode\n");
1374                 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1375                 err = scanf("%d", &idx);
1376                 flush_stdin();
1377                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1378                 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1379                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1380                 break;
1381         case 'Y': /* Setting > Flip Display */
1382                 g_print("\n Select Rotate mode\n");
1383                 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1384                 err = scanf("%d", &idx);
1385                 flush_stdin();
1386                 bret = camera_set_display_flip(hcamcorder->camera, idx);
1387                 break;
1388         case 'g': /* Setting > Brightness */
1389                 g_print("*Brightness !\n");
1390                 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1391                 g_print("\n Select brightness min (%d) -max(%d) > ", min, max);
1392                 err = scanf("%d", &idx);
1393                 flush_stdin();
1394                 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1395                 break;
1396         case 'c': /* Setting > Contrast */
1397                 g_print("*Contrast !\n");
1398                 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1399                 g_print("\n Select Contrast min(%d)-max(%d) > ", min, max);
1400                 err = scanf("%d", &idx);
1401                 flush_stdin();
1402                 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1403                 break;
1404         case 'h': /* Setting > Hue */
1405                 g_print("*Hue !\n");
1406                 camera_attr_get_hue_range(hcamcorder->camera, &min, &max);
1407                 if (max >= min) {
1408                         g_print("\n Select Hue min(%d)-max(%d) > ", min, max);
1409                         err = scanf("%d", &idx);
1410                         flush_stdin();
1411                         bret = camera_attr_set_hue(hcamcorder->camera, idx);
1412                 } else {
1413                         g_print("\n Hue is not supported (%d,%d)\n", min, max);
1414                 }
1415                 break;
1416         case 'w': /* Setting > White balance */
1417                 g_print("*White balance !\n");
1418                 g_print("\n Select White balance \n");
1419                 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1420                 err = scanf("%d", &idx);
1421                 flush_stdin();
1422                 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1423                 break;
1424         case 't': /* Setting > Color tone */
1425                 g_print("*Color tone !\n");
1426                 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1427                 g_print("\n Select Color tone \n");
1428                 err = scanf("%d", &idx);
1429                 flush_stdin();
1430                 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1431                 break;
1432         case 'd': /* Setting > WDR */
1433                 g_print("*WDR !\n");
1434                 g_print("\n Select WDR Mode \n");
1435                 for (i = 0 ; i < 2 ; i++)
1436                         g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1437                 err = scanf("%d", &idx);
1438                 flush_stdin();
1439                 if (idx == 1)
1440                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1441                 else if (idx == 2)
1442                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1443                 break;
1444         case 'e': /* Setting > EV program mode */
1445                 g_print("* EV program mode!\n");
1446                 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1447                 g_print("\n Select EV program mode \n");
1448                 err = scanf("%d", &idx);
1449                 flush_stdin();
1450                 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1451                 break;
1452         case 'R': /* Setting > Display ROI area */
1453                 g_print("* Set display roi area. Select x y width height \n");
1454                 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1455                 flush_stdin();
1456                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1457                 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1458                 if (CAMERA_ERROR_NONE != err)
1459                         g_print("* Error : %d\n", err);
1460
1461                 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1462                 if (CAMERA_ERROR_NONE == err)
1463                         g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1464                 else
1465                         g_print("* Error : %d\n", err);
1466                 break;
1467
1468                 /* ext. setting */
1469         case 'z': /* Setting > Strobe setting */
1470                 g_print("*Strobe Mode\n");
1471                 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1472                 g_print("\n Select Strobe Mode \n");
1473                 err = scanf("%d", &idx);
1474                 flush_stdin();
1475                 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1476                 break;
1477         case 'S': /* Setting > flash state */
1478                 g_print("*flash state\n");
1479                 err = camera_get_flash_state(camera_device, (camera_flash_state_e *)&idx);
1480                 if (CAMERA_ERROR_NONE == err)
1481                         g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1482                 else
1483                         g_print("* Error : %d\n", err);
1484                 break;
1485         case 'G': /* Setting > flash brightness */
1486                 g_print("*Flash brightness !\n");
1487                 camera_attr_get_flash_brightness_range(hcamcorder->camera, &min, &max);
1488                 g_print("\n Select flash brightness min(%d) - max(%d) > ", min, max);
1489                 err = scanf("%d", &idx);
1490                 flush_stdin();
1491                 bret = camera_attr_set_flash_brightness(hcamcorder->camera, idx);
1492                 break;
1493         case 'x': /* Setting > Capture mode ,Muitishot? */
1494                 g_print("*Select Capture mode!\n");
1495                 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1496                 err = scanf("%d", &idx);
1497                 flush_stdin();
1498
1499                 switch (idx) {
1500                 case 1:
1501                         g_print("stillshot mode selected and capture callback is set!!!!\n");
1502                         hcamcorder->is_multishot = FALSE;
1503                         camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1504                         break;
1505                 case 2:
1506                         g_print("HDR Capture mode selected\n");
1507                         hcamcorder->is_multishot = FALSE;
1508                         g_print("\nSelect HDR capture mode\n");
1509                         for (i = 0 ; i < 3 ; i++)
1510                                 g_print("\t %d. %s\n", i, hdr_mode[i]);
1511                         err = scanf("%d", &idx);
1512                         flush_stdin();
1513                         if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1514                                 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1515                         else
1516                                 g_print("invalid input %d\n", idx);
1517                         break;
1518                 default:
1519                         g_print("Wrong input, select again!!\n");
1520                         break;
1521                 }
1522                 break;
1523         case 'l': /* Setting > Face detection setting */
1524                 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1525                         g_print("* Face detect mode !\n");
1526                         for (i = 0 ; i < 2 ; i++)
1527                                 g_print("\t %d. %s \n", i, detection_mode[i]);
1528                         err = scanf("%d", &idx);
1529                         flush_stdin();
1530                         if (idx == 0)
1531                                 bret = camera_stop_face_detection(hcamcorder->camera);
1532                         else if (idx == 1)
1533                                 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1534                         else
1535                                 g_print("\n invalid input [%d]\n\n", idx);
1536                 } else {
1537                         g_print("face detection_not supported");
1538                 }
1539                 break;
1540         case 'k': /* Setting > Anti-handshake */
1541                 g_print("*Anti-handshake !\n");
1542                 g_print("\n Select Anti-handshake mode \n");
1543                 for (i = 0; i < 2; i++)
1544                         g_print("\t %d. %s\n", i, ahs_mode[i]);
1545                 err = scanf("%d", &idx);
1546                 flush_stdin();
1547                 if (idx == 0 || idx == 1)
1548                         bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1549                 else
1550                         g_print("invalid input %d\n", idx);
1551                 break;
1552         case 'K': /* Setting > Video-stabilization */
1553                 g_print("*Video-stabilization !\n");
1554                 g_print("\n Select Video-stabilization mode \n");
1555                 for (i = 0 ; i < 2 ; i++)
1556                         g_print("\t %d. %s\n", i, vs_mode[i]);
1557                 err = scanf("%d", &idx);
1558                 flush_stdin();
1559                 if (idx < 0 || idx > 1) {
1560                         g_print("invalid input %d\n", idx);
1561                         break;
1562                 }
1563
1564                 if (idx == 1) {
1565                         g_print("\n Restart preview with NV12 and 720p resolution\n");
1566                         err = camera_stop_preview(hcamcorder->camera);
1567                         g_print("stop preview result 0x%x\n", err);
1568                         camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1569                         camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1570                 }
1571
1572                 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1573
1574                 if (idx == 1) {
1575                         err = camera_start_preview(hcamcorder->camera);
1576                         if (err != CAMERA_ERROR_NONE)
1577                                 g_print("\n Restart FAILED! 0x%x\n", err);
1578                 }
1579                 break;
1580         case 'u': /* Touch AF area */
1581                 g_print("* Touch AF area !\n");
1582                 g_print("\n Input x,y,width,height \n");
1583                 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1584                 flush_stdin();
1585                 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1586                 if (err != 0)
1587                         g_print("Failed to set touch AF area.(%x)\n", err);
1588                 else
1589                         g_print("Succeed to set touch AF area.\n");
1590                 break;
1591         case 'n': /* file path */
1592                 g_print("* File path !\n");
1593                 g_print("\n Input file path to save captured data(string) : ");
1594                 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1595                         hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1596                         g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1597                 } else {
1598                         g_print("\nset file path failed\n");
1599                 }
1600                 break;
1601         case 'm': /* media bridge */
1602                 g_print("* Media Bridge !\n");
1603                 g_print("\tUnset[0] / Set[Others] :");
1604                 err = scanf("%d", &set_bridge);
1605                 flush_stdin();
1606                 if (set_bridge) {
1607                         __release_media_bridge();
1608
1609                         err = media_bridge_create(&bridge);
1610                         err |= media_bridge_set_source(bridge, MEDIA_BRIDGE_MODULE_CAMERA, hcamcorder->camera);
1611                 } else {
1612                         __release_media_bridge();
1613                 }
1614                 g_print("\tresult[0x%x]\n\n", err);
1615                 break;
1616         case 'b': /* back */
1617                 hcamcorder->menu_state = MENU_STATE_MAIN;
1618                 break;
1619         default:
1620                 g_print("\t Invalid input \n");
1621                 break;
1622         }
1623
1624         g_print("\t bret : 0x%x \n", bret);
1625
1626         return;
1627 }
1628
1629
1630 static void device_state_menu(gchar buf)
1631 {
1632         int ret = 0;
1633         camera_device_e device = CAMERA_DEVICE_CAMERA0;
1634         camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1635
1636         switch (buf) {
1637         case '1': /* Get device state */
1638                 while (1) {
1639                         g_print("\n\tEnter Camera Index[0~9]: ");
1640
1641                         ret = scanf("%d", (int *)&device);
1642                         flush_stdin();
1643
1644                         if (ret == EOF) {
1645                                 g_print("\n\t!!!read input error!!!\n");
1646                                 return;
1647                         }
1648
1649                         if (device < CAMERA_DEVICE_CAMERA0 ||
1650                                 device > CAMERA_DEVICE_CAMERA9) {
1651                                 g_print("\n\tinvalid input:[%d], try again...\n", device);
1652                                 continue;
1653                         }
1654
1655                         ret = camera_get_device_state(device, &device_state);
1656                         g_print("\n\tDevice[%d] state[%d], ret[0x%x]",
1657                                 device, device_state, ret);
1658                         break;
1659                 }
1660                 break;
1661         case '2': /* Add device state changed callback */
1662                 ret = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1663                         NULL, &g_camera_device_state_changed_cb_id);
1664                 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1665                 break;
1666         case '3': /* Remove device state changed callback */
1667                 if (g_camera_device_state_changed_cb_id > 0) {
1668                         ret = camera_remove_device_state_changed_cb(g_camera_device_state_changed_cb_id);
1669                         g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_state_changed_cb_id);
1670                         g_camera_device_state_changed_cb_id = 0;
1671                 } else {
1672                         g_print("\n\tinvalid cb id[%d]\n", g_camera_device_state_changed_cb_id);
1673                 }
1674                 break;
1675         case 'b': /* back */
1676                 hcamcorder->menu_state = MENU_STATE_INIT;
1677                 break;
1678         default:
1679                 g_print("\n\tinvalid input[%c]\n", buf);
1680                 break;
1681         }
1682
1683         return;
1684 }
1685
1686 static void device_list_menu(gchar buf)
1687 {
1688         int ret = 0;
1689         unsigned int i = 0;
1690         camera_device_list_s device_list;
1691
1692         switch (buf) {
1693         case '1': /* Initialize device manager */
1694                 ret = camera_device_manager_initialize(&g_device_manager);
1695                 g_print("\n\tDevice manager[%p] initialize result[0x%x]\n",
1696                         g_device_manager, ret);
1697                 break;
1698         case '2': /* Get device list */
1699                 memset(&device_list, 0x0, sizeof(camera_device_list_s));
1700                 ret = camera_device_manager_get_device_list(g_device_manager, &device_list);
1701                 if (ret != CAMERA_ERROR_NONE) {
1702                         g_print("\n\tGet device list failed[0x%x]\n", ret);
1703                         return;
1704                 }
1705
1706                 g_print("\n\tDevice list[count:%d]\n", device_list.count);
1707
1708                 for (i = 0 ; i < device_list.count ; i++) {
1709                         g_print("\t[%d] : type[%d], index[%d], name[%s], id[%s]\n",
1710                                 i, device_list.device[i].type, device_list.device[i].index,
1711                                 device_list.device[i].name, device_list.device[i].id);
1712                 }
1713                 break;
1714         case '3': /* Add device list changed callback */
1715                 ret = camera_device_manager_add_device_list_changed_cb(g_device_manager,
1716                         _camera_device_list_changed_cb, NULL, &g_camera_device_list_changed_cb_id);
1717                 g_print("\n\tadd result[0x%x] - cb id[%d]\n", ret, g_camera_device_list_changed_cb_id);
1718                 break;
1719         case '4': /* Remove device list changed callback */
1720                 if (g_camera_device_list_changed_cb_id > 0) {
1721                         ret = camera_device_manager_remove_device_list_changed_cb(g_device_manager,
1722                                 g_camera_device_list_changed_cb_id);
1723                         g_print("\n\tremove result[0x%x] - cb id[%d]\n", ret, g_camera_device_list_changed_cb_id);
1724                         g_camera_device_list_changed_cb_id = 0;
1725                 } else {
1726                         g_print("\n\tinvalid cb id[%d]\n", g_camera_device_list_changed_cb_id);
1727                 }
1728                 break;
1729         case '5': /* Deinitialize device manager */
1730                 ret = camera_device_manager_deinitialize(g_device_manager);
1731                 g_print("\n\tDevice manager[%p] deinitialize result[0x%x]\n",
1732                         g_device_manager, ret);
1733                 g_device_manager = NULL;
1734                 break;
1735         case 'b': /* back */
1736                 hcamcorder->menu_state = MENU_STATE_INIT;
1737                 break;
1738         default:
1739                 g_print("\n\tinvalid input[%c]\n", buf);
1740                 break;
1741         }
1742
1743         return;
1744 }
1745
1746
1747 /**
1748  * This function is to execute command.
1749  *
1750  * @param   channel [in]    1st parameter
1751  *
1752  * @return  This function returns TRUE/FALSE
1753  * @remark
1754  * @see
1755  */
1756 static gboolean cmd_input(GIOChannel *channel, GIOCondition condition, gpointer data)
1757 {
1758         gchar *buf = NULL;
1759         gsize read_size;
1760         GError *g_error = NULL;
1761
1762         g_print("\n\tENTER\n");
1763
1764         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1765         if (g_error) {
1766                 g_print("\n\tg_io_channel_read_chars error\n");
1767                 g_error_free(g_error);
1768                 g_error = NULL;
1769         }
1770
1771         if (buf) {
1772                 g_strstrip(buf);
1773
1774                 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1775                 switch (hcamcorder->menu_state) {
1776                 case MENU_STATE_INIT:
1777                         mode_change(buf[0]);
1778                         break;
1779                 case MENU_STATE_MAIN:
1780                         main_menu(buf[0]);
1781                         break;
1782                 case MENU_STATE_MAIN_SETTING:
1783                         setting_menu(buf[0]);
1784                         break;
1785                 case MENU_STATE_DEVICE_STATE:
1786                         device_state_menu(buf[0]);
1787                         break;
1788                 case MENU_STATE_DEVICE_LIST:
1789                         device_list_menu(buf[0]);
1790                         break;
1791                 default:
1792                         break;
1793                 }
1794
1795                 g_free(buf);
1796                 buf = NULL;
1797
1798                 print_menu();
1799         } else {
1800                 g_print("\n\tNo read input\n");
1801         }
1802
1803         return TRUE;
1804 }
1805
1806 static gboolean init_handle()
1807 {
1808         hcamcorder->is_multishot =  FALSE;
1809         hcamcorder->stillshot_count = 0;
1810         hcamcorder->multishot_count = 0;
1811         snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1812         hcamcorder->menu_state = MENU_STATE_INIT;
1813         hcamcorder->elapsed_time = 0;
1814
1815         return TRUE;
1816 }
1817
1818
1819 /**
1820  * This function is to change camcorder mode.
1821  *
1822  * @param   buf    [in]    user input
1823  *
1824  * @return  This function returns TRUE/FALSE
1825  * @remark
1826  * @see     other functions
1827  */
1828 static gboolean mode_change(gchar buf)
1829 {
1830         int err = 0;
1831         int camera_type = 0;
1832         int display_type = 0;
1833         bool check = FALSE;
1834
1835         switch (buf) {
1836         case '1':
1837                 while (1) {
1838                         g_print("\n\tEnter the Camera Type[0:Local, 1:Network] : ");
1839                         err = scanf("%d", &camera_type);
1840                         flush_stdin();
1841                         if (err == EOF) {
1842                                 g_print("\t!!!read input error!!!\n");
1843                                 continue;
1844                         }
1845
1846                         if (camera_type != 0 && camera_type != 1) {
1847                                 g_print("\t Invalid camera type(%d)\n", camera_type);
1848                                 continue;
1849                         }
1850
1851                         g_print("\n\tEnter the Camera Device[0 ~ 9] : ");
1852                         err = scanf("%d", (int *)&camera_device);
1853                         flush_stdin();
1854                         if (err == EOF) {
1855                                 g_print("\t!!!read input error!!!\n");
1856                                 continue;
1857                         }
1858
1859                         if (camera_device < 0 || camera_device > 9) {
1860                                 g_print("\t Invalid camera device(%d)\n", camera_device);
1861                                 continue;
1862                         }
1863
1864                         hcamcorder->type = camera_device;
1865
1866                         break;
1867                 }
1868                 break;
1869         case '2':
1870                 hcamcorder->menu_state = MENU_STATE_DEVICE_STATE;
1871                 return TRUE;
1872         case '3':
1873                 hcamcorder->menu_state = MENU_STATE_DEVICE_LIST;
1874                 return TRUE;
1875         case 'q':
1876                 g_print("\t Quit Camcorder Testsuite!!\n");
1877                 elm_exit();
1878                 return FALSE;
1879         default:
1880                 g_print("\t Invalid media type(%c)\n", buf);
1881                 return FALSE;
1882         }
1883
1884         g_print("\n[camcorder_create - type %d, device %d]\n", camera_type, camera_device);
1885
1886         gettimeofday(&previous_time, NULL);
1887
1888         g_timer_reset(timer);
1889
1890         if (camera_type)
1891                 err = camera_create_network(camera_device, &hcamcorder->camera);
1892         else
1893                 err = camera_create(camera_device, &hcamcorder->camera);
1894
1895         g_print("[camera_create()  : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1896
1897         if (err != 0) {
1898                 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1899                 return -1;
1900         }
1901
1902         while (!check) {
1903                 g_print("\n\tEnter the Display Type [1:Overlay, 2:Evas, 3:None] : ");
1904                 err = scanf("%d", &display_type);
1905                 flush_stdin();
1906                 if (err == EOF) {
1907                         g_print("\t!!!read input error!!!\n");
1908                         continue;
1909                 }
1910
1911                 switch (display_type) {
1912                 case 1:
1913                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1914                         check = TRUE;
1915                         break;
1916                 case 2:
1917                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1918                         check = TRUE;
1919                         break;
1920                 case 3:
1921                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1922                         check = TRUE;
1923                         break;
1924                 default:
1925                         g_print("\t Invalid display type(%d)\n", display_type);
1926                         break;
1927                 }
1928         }
1929
1930         camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1931         camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1932         camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1933         camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1934         camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1935         /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1936         /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1937         /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1938
1939         camera_start_preview(hcamcorder->camera);
1940
1941         gettimeofday(&current_time, NULL);
1942         timersub(&current_time, &previous_time, &result_time);
1943
1944         g_print("\n\tCamera Starting Time  : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1945
1946         hcamcorder->menu_state = MENU_STATE_MAIN;
1947
1948         return TRUE;
1949 }
1950
1951 static int app_create(void *data)
1952 {
1953         appdata *app_data = data;
1954         int w = 0;
1955         int h = 0;
1956         Evas_Object *win = NULL;
1957         Evas_Object *eo = NULL;
1958         Evas_Object *bg = NULL;
1959         Evas_Object *rect = NULL;
1960
1961         if (app_data == NULL) {
1962                 g_print("\t\nappdata is NULL\n");
1963                 return 0;
1964         }
1965
1966         /* use gl backend */
1967         elm_config_accel_preference_set("opengl");
1968
1969         win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1970         if (win) {
1971                 elm_win_title_set(win, "camera_test");
1972                 elm_win_borderless_set(win, EINA_TRUE);
1973                 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1974                 g_print("\n\tscreen size %dx%d\n\n", w, h);
1975                 evas_object_resize(win, w, h);
1976                 elm_win_autodel_set(win, EINA_TRUE);
1977                 elm_win_alpha_set(win, EINA_TRUE);
1978         } else {
1979                 g_print("\n\tfailed to get window\n\n");
1980                 return 1;
1981         }
1982
1983         bg = elm_bg_add(win);
1984         if (bg) {
1985                 elm_win_resize_object_add(win, bg);
1986                 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1987                 evas_object_show(bg);
1988         } else {
1989                 g_print("\n\tfailed to get elm bg\n\n");
1990                 return 1;
1991         }
1992
1993         rect = evas_object_rectangle_add(evas_object_evas_get(win));
1994         if (rect) {
1995                 evas_object_color_set(rect, 0, 0, 0, 0);
1996                 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1997         } else {
1998                 g_print("\n\tfailed to get rectangle\n\n");
1999                 return 1;
2000         }
2001
2002         elm_win_resize_object_add(win, rect);
2003         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2004         evas_object_show(rect);
2005
2006         /* Create evas image object for EVAS surface */
2007         eo = evas_object_image_add(evas_object_evas_get(win));
2008         evas_object_image_size_set(eo, w, h);
2009         evas_object_image_fill_set(eo, 0, 0, w, h);
2010         evas_object_resize(eo, w, h);
2011         evas_object_show(eo);
2012
2013         elm_win_activate(win);
2014         evas_object_show(win);
2015
2016         app_data->win = win;
2017         app_data->eo = eo;
2018
2019         timer = g_timer_new();
2020         g_timer_reset(timer);
2021
2022         init_handle();
2023
2024         print_menu();
2025
2026         return 0;
2027 }
2028
2029 static int app_terminate(void *data)
2030 {
2031         appdata *app_data = data;
2032
2033         if (app_data == NULL) {
2034                 g_print("\n\tappdata is NULL\n");
2035                 return 0;
2036         }
2037
2038         if (timer) {
2039                 g_timer_stop(timer);
2040                 g_timer_destroy(timer);
2041                 timer = NULL;
2042         }
2043
2044         return 0;
2045 }
2046
2047
2048 /**
2049  * This function is the example main function for mmcamcorder API.
2050  *
2051  * @param
2052  *
2053  * @return  This function returns 0.
2054  * @remark
2055  * @see     other functions
2056  */
2057 int main(int argc, char **argv)
2058 {
2059         int bret;
2060
2061         hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
2062
2063         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
2064         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
2065
2066         memset(&ad, 0x0, sizeof(appdata));
2067         ops.data = &ad;
2068
2069         bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
2070
2071         g_print("\n\treturn appcore_efl : %d\n\n", bret);
2072
2073         g_free(hcamcorder);
2074         g_io_channel_unref(stdin_channel);
2075
2076         return bret;
2077 }
2078 /*EOF*/