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