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