[ACR-987] Add interrupt started callback related 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 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 void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e state, void *user_data)
455 {
456         g_print("\ncamera interrupt started callback called[state %d, policy %d]\n", state, policy);
457         return;
458 }
459
460 static bool preview_resolution_cb(int width, int height, void *user_data)
461 {
462         resolution_stack *data = (resolution_stack *)user_data;
463
464         if (data == NULL) {
465                 g_print("NULL data\n");
466                 return false;
467         }
468
469         data->width[data->count] = width;
470         data->height[data->count] = height;
471
472         g_print("%d. %dx%d\n", data->count, width, height);
473
474         data->count++;
475
476         return true;
477 }
478
479 static bool capture_resolution_test_cb(int width, int height, void *user_data)
480 {
481         resolution_stack *data = (resolution_stack *)user_data;
482
483         if (data == NULL) {
484                 g_print("NULL data\n");
485                 return false;
486         }
487
488         data->width[data->count] = width;
489         data->height[data->count] = height;
490
491         g_print("%d. %dx%d\n", data->count, width, height);
492
493         data->count++;
494
495         return true;
496 }
497
498 static bool af_mode_foreach_cb(camera_attr_iso_e mode, void *user_data)
499 {
500         g_print("%d.%s\n", mode, af_scan[mode]);
501         return true;
502 }
503
504 static bool exposure_mode_cb(camera_attr_af_mode_e mode, void *user_data)
505 {
506         exposure_stack *data = (exposure_stack *)user_data;
507
508         if (data == NULL) {
509                 g_print("NULL data\n");
510                 return false;
511         }
512
513         data->mode = mode;
514         data->count++;
515
516         g_print("%d.%s\n", mode, exposure_mode[mode]);
517         return true;
518 }
519
520 static bool iso_mode_cb(camera_attr_iso_e mode, void *user_data)
521 {
522         g_print("%d.%s\n", mode, iso_mode[mode]);
523         return true;
524 }
525
526 static bool camera_rotation_cb(camera_rotation_e mode, void *user_data)
527 {
528         camera_rotation_stack *data = (camera_rotation_stack *)user_data;
529
530         if (data == NULL) {
531                 g_print("NULL data\n");
532                 return false;
533         }
534
535         data->mode = mode;
536         data->count++;
537
538         g_print("%d.%s\n", mode, camera_rotation[mode]);
539
540         return true;
541 }
542
543 static bool preview_format_cb(camera_pixel_format_e mode, void *user_data)
544 {
545         g_print("%d.%s\n", mode, image_fmt[mode]);
546         return true;
547 }
548
549 static bool white_balance_cb(camera_attr_whitebalance_e mode, void *user_data)
550 {
551         g_print("%d.%s\n", mode, wb[mode]);
552         return true;
553 }
554
555 static bool colortone_cb(camera_attr_effect_mode_e mode, void *user_data)
556 {
557         g_print("%d.%s\n", mode, ct[mode]);
558         return true;
559 }
560
561 static bool program_mode_cb(camera_attr_scene_mode_e mode, void *user_data)
562 {
563         g_print("%d.%s\n", mode, program_mode[mode]);
564         return true;
565 }
566
567 static bool strobe_mode_cb(camera_attr_flash_mode_e mode, void *user_data)
568 {
569         g_print("%d.%s\n", mode, strobe_mode[mode]);
570         return true;
571 }
572
573 static void _face_detected(camera_detected_face_s *faces, int count, void *user_data)
574 {
575         g_print("face detected!! - count %d\n", count);
576         int i;
577
578         for (i = 0 ; i < count ; i++)
579                 g_print("%d) - %dx%d\n", faces[i].id, faces[i].x, faces[i].y);
580
581         return;
582 }
583
584 static void _file_write(char *path, void *data, int size)
585 {
586         FILE *fp = NULL;
587
588         if (!path || !data || size <= 0) {
589                 g_print("ERROR %p %p %d\n", path, data, size);
590                 return;
591         }
592
593         fp = fopen(path, "w");
594         if (fp == NULL) {
595                 g_print("open error! [%s], errno %d\n", path, errno);
596                 return;
597         } else {
598                 g_print("open success [%s]\n", path);
599                 if (fwrite(data, size, 1, fp) != 1)
600                         g_print("write error! errno %d\n", errno);
601                 else
602                         g_print("write success [%s]\n", path);
603
604                 fclose(fp);
605                 fp = NULL;
606         }
607 }
608
609 static void capturing_cb(camera_image_data_s* image, camera_image_data_s* postview, camera_image_data_s* thumbnail, void *user_data)
610 {
611         char m_filename[MAX_FILE_NAME_LENGTH];
612
613         /* main image */
614         if (image) {
615                 if (hcamcorder->is_multishot) {
616                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/multishot%03d.jpg",
617                                 hcamcorder->file_path, hcamcorder->multishot_count++);
618                 } else {
619                         snprintf(m_filename, MAX_FILE_NAME_LENGTH, "%s/stillshot%03d.jpg",
620                                 hcamcorder->file_path, hcamcorder->stillshot_count++);
621                 }
622
623                 _file_write(m_filename, image->data, image->size);
624         }
625
626         return;
627 }
628
629 static void capture_completed_cb(void *user_data)
630 {
631         camera_start_preview(hcamcorder->camera);
632
633         print_menu();
634
635         return;
636 }
637
638 static void print_menu()
639 {
640         switch (hcamcorder->menu_state) {
641         case MENU_STATE_INIT:
642                 g_print("\n\t=======================================\n");
643                 g_print("\t   CAMERA_TESTSUITE\n");
644                 g_print("\t=======================================\n");
645                 g_print("\t   '1' Video Capture - Front Camera\n");
646                 g_print("\t   '2' Video Capture - Rear Camera\n");
647                 g_print("\t   '3' Add camera device state changed callback\n");
648                 g_print("\t   '4' Remove camera device state changed callback\n");
649                 g_print("\t   '5' Get camera device state\n");
650                 g_print("\t   'q' Exit\n");
651                 g_print("\t=======================================\n");
652
653                 g_print("\t  Enter the media type:\n\t");
654                 break;
655         case MENU_STATE_MAIN:
656                 g_print("\n\t=======================================\n");
657                 if (cam_info == CAMERA_DEVICE_CAMERA1)
658                         g_print("\t   Video Capture (Front camera)\n");
659                 else if (cam_info == CAMERA_DEVICE_CAMERA0)
660                         g_print("\t   Video Capture (Rear camera)\n");
661                 g_print("\t=======================================\n");
662
663                 g_print("\t   '1' Stillshot test\n");
664                 g_print("\t   '2' Multishot test\n");
665                 g_print("\t   '3' Setting\n");
666                 g_print("\t   '4' Change device (Rear <-> Front)\n");
667                 g_print("\t   'b' back\n");
668                 g_print("\t=======================================\n");
669                 break;
670         case MENU_STATE_SETTING:
671                 g_print("\n\t=======================================\n");
672                 g_print("\t   Video Capture > Setting\n");
673                 g_print("\t=======================================\n");
674                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera]  \n");
675                 g_print("\t     '0' Preview resolution \n");
676                 g_print("\t     '1' Capture resolution \n");
677                 g_print("\t     '2' Digital zoom level \n");
678                 g_print("\t     '3' AF mode \n");
679                 g_print("\t     '4' AF scan range \n");
680                 g_print("\t     '5' Exposure mode \n");
681                 g_print("\t     '6' Exposure value \n");
682                 g_print("\t     '7' F number \n");
683                 g_print("\t     '8' Display reuse hint \n");
684                 g_print("\t     'i' ISO \n");
685                 g_print("\t     'r' Rotate camera input \n");
686                 g_print("\t     'f' Flip camera input \n");
687                 g_print("\t     'j' Jpeg quality \n");
688                 g_print("\t     'p' Picture format \n");
689                 g_print("\t     'E' EXIF orientation \n");
690                 g_print("\t     'F' Get facing direction of camera module\n");
691                 g_print("\t  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
692                 g_print("\t     'v' Visible \n");
693                 g_print("\t     'o' Output mode \n");
694                 g_print("\t     'y' Rotate display \n");
695                 g_print("\t     'Y' Flip display \n");
696                 g_print("\t     'g' Brightness \n");
697                 g_print("\t     'c' Contrast \n");
698                 g_print("\t     'w' White balance \n");
699                 g_print("\t     't' Color tone \n");
700                 g_print("\t     'd' WDR \n");
701                 g_print("\t     'e' EV program mode \n");
702                 g_print("\t     'R' Display ROI area \n");
703                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
704                 g_print("\t     'z' Strobe (Flash) \n");
705                 g_print("\t     'S' Strobe (Flash) state\n");
706                 g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
707                 g_print("\t     'l' Face detection \n");
708                 g_print("\t     'k' Anti-handshake \n");
709                 g_print("\t     'K' Video-stabilization \n");
710                 g_print("\t     'u' Touch AF area \n");
711                 g_print("\t     'n' Set file path to write captured image\n");
712                 g_print("\t     'b' back\n");
713                 g_print("\t=======================================\n");
714                 break;
715         default:
716                 g_print("\n\tunknow menu state !!\n");
717                 break;
718         }
719
720         return;
721 }
722
723
724 static void main_menu(gchar buf)
725 {
726         int err = 0;
727         camera_state_e capi_state = CAMERA_STATE_NONE;
728
729         switch (buf) {
730         case '1': /* Capture */
731                 hcamcorder->is_multishot = FALSE;
732                 camera_get_state(hcamcorder->camera, &capi_state);
733                 camera_attr_set_image_quality(hcamcorder->camera, 100);
734                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
735                 camera_start_capture(hcamcorder->camera, capturing_cb, capture_completed_cb, hcamcorder);
736                 break;
737         case '2': /* multishot Capture */
738                 g_print("multishot capture");
739                 hcamcorder->is_multishot = TRUE;
740                 int interval = 0, count = 0;
741                 flush_stdin();
742                 g_print("\n\tinput interval(ms) : ");
743                 err = scanf("%d", &interval);
744                 flush_stdin();
745                 g_print("\n\tinput count : ");
746                 err = scanf("%d", &count);
747                 camera_attr_set_image_quality(hcamcorder->camera, 100);
748                 camera_set_capture_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_JPEG);
749                 camera_start_continuous_capture(hcamcorder->camera, count, interval, capturing_cb, NULL, NULL);
750                 sleep(3);
751                 camera_start_preview(hcamcorder->camera);
752                 break;
753         case '3': /* Setting */
754                 hcamcorder->menu_state = MENU_STATE_SETTING;
755                 break;
756         case '4': /* Change device (Rear <-> Front) */
757                 camera_set_display_reuse_hint(hcamcorder->camera, true);
758
759                 camera_stop_preview(hcamcorder->camera);
760
761                 if (hcamcorder->type == CAMERA_DEVICE_CAMERA0) {
762                         hcamcorder->type = CAMERA_DEVICE_CAMERA1;
763                 } else {
764                         hcamcorder->type = CAMERA_DEVICE_CAMERA0;
765                 }
766
767                 camera_change_device(hcamcorder->camera, hcamcorder->type);
768
769                 camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
770                 camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
771                 camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
772                 camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
773
774                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
775
776                 camera_start_preview(hcamcorder->camera);
777                 break;
778         case 'b': /* back */
779                 camera_stop_preview(hcamcorder->camera);
780                 camera_destroy(hcamcorder->camera);
781                 hcamcorder->camera = NULL;
782                 hcamcorder->menu_state = MENU_STATE_INIT;
783                 print_menu();
784                 break;
785         default:
786                 g_print("\t Invalid input \n");
787                 break;
788         }
789
790         return;
791 }
792
793
794 static void setting_menu(gchar buf)
795 {
796         int bret = FALSE;
797         int idx = 0;
798         int min = 0;
799         int max = 0;
800         int i = 0;
801         int err = 0;
802         int x = 0;
803         int y = 0;
804         int width = 0;
805         int height = 0;
806
807         switch (buf) {
808         /* Camera setting */
809         case '0':  /* Setting > Preview Resolution setting */
810                 g_print("*Select the preview resolution!\n");
811                 resolution_stack resolution_list;
812                 resolution_list.count = 0;
813
814                 camera_foreach_supported_preview_resolution(hcamcorder->camera,
815                         preview_resolution_cb, &resolution_list);
816
817                 flush_stdin();
818                 err = scanf("%d", &idx);
819                 int result = 0;
820                 if (resolution_list.count > idx && idx >= 0) {
821                         g_print("-----------------PREVIEW RESOLUTION (%dx%d)---------------------\n",
822                                 resolution_list.width[idx], resolution_list.height[idx]);
823
824                         result = camera_set_preview_resolution(hcamcorder->camera,
825                                 resolution_list.width[idx], resolution_list.height[idx]);
826                 } else {
827                         g_print("invalid input %d\n", idx);
828                         result = -1;
829                 }
830                 resolution_list.count = 0;
831                 if (result != 0)
832                         g_print("FAIL\n");
833                 else
834                         g_print("PASS\n");
835                 break;
836         case '1': /* Setting > Capture Resolution setting */
837                 g_print("*Select the preview resolution!\n");
838                 g_print("-----------------CAPTURE RESOLUTION TEST: ---------------------\n");
839                 resolution_list.count = 0;
840
841                 camera_foreach_supported_capture_resolution(hcamcorder->camera,
842                         capture_resolution_test_cb, &resolution_list);
843
844                 flush_stdin();
845                 err = scanf("%d", &idx);
846                 if (resolution_list.count > idx && idx >= 0) {
847
848                         result = camera_set_capture_resolution(hcamcorder->camera,
849                                 resolution_list.width[idx], resolution_list.height[idx]);
850
851                         g_print("camera_set_capture_resolution with width =%d, height=%d ret=0x%x\n",
852                                 resolution_list.width[idx], resolution_list.height[idx], result);
853                 } else {
854                         g_print("invalid input %d\n", idx);
855                         result = -1;
856                 }
857                 resolution_list.count = 0;
858                 if (result != 0)
859                         g_print("FAIL\n");
860                 else
861                         g_print("PASS\n");
862
863                 break;
864         case '2': /* Setting > Digital zoom level */
865                 g_print("*Digital zoom level  !\n");
866                 camera_attr_get_zoom_range(hcamcorder->camera, &min, &max);
867                 if (min >= max)
868                         g_print("Not supported !! \n");
869                 else {
870                         flush_stdin();
871                         g_print("\n Select  Digital zoom level min %d - max %d\n", min, max);
872                         err = scanf("%d", &idx);
873                         bret = camera_attr_set_zoom(hcamcorder->camera, idx);
874                 }
875                 break;
876         case '3': /* Setting > AF mode */
877                 g_print("*AF mode !\n");
878                 g_print("\t1. AF Start !\n");
879                 g_print("\t2. AF Stop !\n\n");
880                 flush_stdin();
881                 err = scanf("%d", &idx);
882                 switch (idx) {
883                 case 1:
884                         camera_start_focusing(hcamcorder->camera, 0);
885                         break;
886                 case 2:
887                         camera_cancel_focusing(hcamcorder->camera);
888                         break;
889                 default:
890                         g_print("Wrong Input[%d] !! \n", idx);
891                         break;
892                 }
893                 break;
894         case '4': /* Setting > AF scan range */
895                 g_print("*AF scan range !\n");
896                 camera_attr_foreach_supported_af_mode(hcamcorder->camera, (camera_attr_supported_af_mode_cb)af_mode_foreach_cb, NULL);
897                 flush_stdin();
898                 err = scanf("%d", &idx);
899                 bret = camera_attr_set_af_mode(hcamcorder->camera, idx);
900                 break;
901         case '5': /* Setting > Exposure mode */
902                 g_print("* Exposure mode!\n");
903                 camera_attr_foreach_supported_exposure_mode(hcamcorder->camera, (camera_attr_supported_exposure_mode_cb)exposure_mode_cb, NULL);
904                 flush_stdin();
905                 g_print("\n Select  Exposure mode \n");
906                 err = scanf("%d", &idx);
907                 bret = camera_attr_set_exposure_mode(hcamcorder->camera, idx);
908                 break;
909
910         case '6': /* Setting > Exposure value */
911                 camera_attr_get_exposure_range(hcamcorder->camera, &min, &max);
912                 if (min >= max)
913                         g_print("Not supported !! \n");
914                 else {
915                         flush_stdin();
916                         g_print("\n Select  Exposure mode min%d -max %d\n", min, max);
917                         err = scanf("%d", &idx);
918                         bret = camera_attr_set_exposure(hcamcorder->camera, idx);
919                 }
920                 break;
921         case '7': /* Setting > F number */
922                 g_print("Not supported !! \n");
923                 break;
924         case '8': /* Setting > Display reuse hint */
925                 {
926                         bool reuse_hint = false;
927
928                         err = camera_get_display_reuse_hint(hcamcorder->camera, &reuse_hint);
929                         if (err != CAMERA_ERROR_NONE) {
930                                 g_print("failed to get display reuse hint 0x%x\n", err);
931                                 break;
932                         }
933
934                         g_print("*Display reuse hint : current %d -> set %d\n", reuse_hint, !reuse_hint);
935                         reuse_hint = !reuse_hint;
936                         err = camera_set_display_reuse_hint(hcamcorder->camera, reuse_hint);
937                         g_print("set display reuse hint result : 0x%x\n", err);
938                 }
939                 break;
940         case 'i': /* Setting > ISO */
941                 g_print("*ISO !\n");
942                 camera_attr_foreach_supported_iso(hcamcorder->camera, iso_mode_cb, NULL);
943                 flush_stdin();
944                 err = scanf("%d", &idx);
945                 bret =  camera_attr_set_iso(hcamcorder->camera, idx);
946                 break;
947         case 'r': /* Setting > Rotate camera input when recording */
948                 g_print("*Rotate camera input\n");
949                 camera_attr_foreach_supported_stream_rotation(hcamcorder->camera, camera_rotation_cb, NULL);
950                 flush_stdin();
951                 err = scanf("%d", &idx);
952                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
953                 bret = camera_attr_set_stream_rotation(hcamcorder->camera, idx);
954                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
955                 break;
956         case 'f': /* Setting > Flip camera input */
957                 flush_stdin();
958                 g_print("*Flip camera input\n");
959                 g_print(" 0. Flip NONE\n");
960                 g_print(" 1. Flip HORIZONTAL\n");
961                 g_print(" 2. Flip VERTICAL\n");
962                 g_print(" 3. Flip BOTH\n");
963                 err = scanf("%d", &idx);
964                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
965                 camera_attr_set_stream_flip(hcamcorder->camera, idx);
966                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
967                 break;
968         case 'j': /* Setting > Jpeg quality */
969                 g_print("*Jpeg quality !\n");
970                 flush_stdin();
971                 g_print("\n Select  Jpeg quality \n");
972                 err = scanf("%d", &idx);
973                 bret = camera_attr_set_image_quality(hcamcorder->camera, idx);
974                 break;
975         case 'p': /* Setting > Picture format */
976                 g_print("* Picture format!\n");
977                 camera_foreach_supported_preview_format(hcamcorder->camera, preview_format_cb, NULL);
978                 flush_stdin();
979                 err = scanf("%d", &idx);
980                 bret = camera_set_preview_format(hcamcorder->camera, idx);
981                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
982                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
983                 break;
984         case 'E': /* Setting > EXIF orientation */
985                 g_print("* EXIF Orientation\n");
986                 g_print("\t 1. TOP_LEFT\n");
987                 g_print("\t 2. TOP_RIGHT(flipped)\n");
988                 g_print("\t 3. BOTTOM_RIGHT\n");
989                 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
990                 g_print("\t 5. LEFT_TOP(flipped)\n");
991                 g_print("\t 6. RIGHT_TOP\n");
992                 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
993                 g_print("\t 8. LEFT_BOTTOM\n");
994                 flush_stdin();
995                 err = scanf("%d", &idx);
996                 if (idx < 1 || idx > 8)
997                         g_print("Wrong INPUT[%d]!! \n", idx);
998                 else
999                         camera_attr_set_tag_orientation(hcamcorder->camera, idx);
1000                 break;
1001         case 'F': /* Getting > Get Facing direction */
1002                 g_print("* Get facing direction of camera module\n");
1003                 err = camera_get_facing_direction(hcamcorder->camera, (camera_facing_direction_e *)&idx);
1004                 if (CAMERA_ERROR_NONE == err)
1005                         g_print("* Facing direction : %s(%d)\n", facing_direction[idx], idx);
1006                 else
1007                         g_print("* Error : %d\n", err);
1008                 break;
1009                 /* Display / Filter setting */
1010         case 'v': /* Display visible */
1011                 g_print("* Display visible setting !\n");
1012                 g_print("\n Select Display visible \n");
1013                 flush_stdin();
1014                 for (i = 0 ; i < 2 ; i++)
1015                         g_print("\t %d. %s\n", i, visible_mode[i]);
1016                 err = scanf("%d", &idx);
1017                 if (idx == 0 || idx == 1)
1018                         bret = camera_set_display_visible(hcamcorder->camera, idx);
1019                 else
1020                         g_print("invalid input %d", idx);
1021                 break;
1022         case 'o': /* Setting > Display Mode */
1023                 g_print("* Display mode!\n");
1024                 flush_stdin();
1025                 for (i = 0 ; i < 5 ; i++)
1026                         g_print("%d. %s\n", i, display_mode[i]);
1027                 err = scanf("%d", &idx);
1028                 bret =  camera_set_display_mode(hcamcorder->camera, idx);
1029                 break;
1030         case 'y': /* Setting > Rotate Display */
1031                 flush_stdin();
1032                 g_print("\n Select Rotate mode\n");
1033                 g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1034                 err = scanf("%d", &idx);
1035                 CHECK_MM_ERROR(camera_stop_preview(hcamcorder->camera));
1036                 bret = camera_set_display_rotation(hcamcorder->camera, idx);
1037                 CHECK_MM_ERROR(camera_start_preview(hcamcorder->camera));
1038                 break;
1039         case 'Y': /* Setting > Flip Display */
1040                 flush_stdin();
1041                 g_print("\n Select Rotate mode\n");
1042                 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1043                 err = scanf("%d", &idx);
1044                 bret = camera_set_display_flip(hcamcorder->camera, idx);
1045                 break;
1046         case 'g': /* Setting > Brightness */
1047                 g_print("*Brightness !\n");
1048                 camera_attr_get_brightness_range(hcamcorder->camera, &min, &max);
1049                 flush_stdin();
1050                 g_print("\n Select  brightness min (%d) -max(%d)", min, max);
1051                 err = scanf("%d", &idx);
1052                 bret = camera_attr_set_brightness(hcamcorder->camera, idx);
1053                 break;
1054         case 'c': /* Setting > Contrast */
1055                 g_print("*Contrast !\n");
1056                 camera_attr_get_contrast_range(hcamcorder->camera, &min, &max);
1057                 flush_stdin();
1058                 g_print("\n Select  Contrast min(%d)-max(%d)", min, max);
1059                 err = scanf("%d", &idx);
1060                 bret = camera_attr_set_contrast(hcamcorder->camera, idx);
1061                 break;
1062         case 'w': /* Setting > White balance */
1063                 g_print("*White balance !\n");
1064                 flush_stdin();
1065                 g_print("\n Select White balance \n");
1066                 camera_attr_foreach_supported_whitebalance(hcamcorder->camera, white_balance_cb, NULL);
1067                 err = scanf("%d", &idx);
1068                 bret = camera_attr_set_whitebalance(hcamcorder->camera, idx);
1069                 break;
1070         case 't': /* Setting > Color tone */
1071                 g_print("*Color tone !\n");
1072                 camera_attr_foreach_supported_effect(hcamcorder->camera, colortone_cb, NULL);
1073                 g_print("\n Select Color tone \n");
1074                 flush_stdin();
1075                 err = scanf("%d", &idx);
1076                 bret = camera_attr_set_effect(hcamcorder->camera, idx);
1077                 break;
1078         case 'd': /* Setting > WDR */
1079                 g_print("*WDR !\n");
1080                 g_print("\n Select WDR Mode \n");
1081                 flush_stdin();
1082                 for (i = 0 ; i < 2 ; i++)
1083                         g_print("\t %d. %s\n", i+1, wdr_mode[i]);
1084                 err = scanf("%d", &idx);
1085                 if (idx == 1)
1086                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 0);
1087                 else if (idx == 2)
1088                         bret = camera_attr_enable_auto_contrast(hcamcorder->camera, 1);
1089                 break;
1090         case 'e': /* Setting > EV program mode */
1091                 g_print("* EV program mode!\n");
1092                 camera_attr_foreach_supported_scene_mode(hcamcorder->camera, program_mode_cb, NULL);
1093                 g_print("\n Select EV program mode \n");
1094                 flush_stdin();
1095                 err = scanf("%d", &idx);
1096                 bret = camera_attr_set_scene_mode(hcamcorder->camera, idx);
1097                 break;
1098         case 'R': /* Setting > Display ROI area */
1099                 g_print("* Set display roi area. Select x y width height \n");
1100                 flush_stdin();
1101                 err = scanf("%d %d %d %d", &x, &y, &width, &height);
1102                 camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_CUSTOM_ROI);
1103                 err = camera_attr_set_display_roi_area(hcamcorder->camera, x, y, width, height);
1104                 if (CAMERA_ERROR_NONE != err)
1105                         g_print("* Error : %d\n", err);
1106
1107                 err = camera_attr_get_display_roi_area(hcamcorder->camera, &x, &y, &width, &height);
1108                 if (CAMERA_ERROR_NONE == err)
1109                         g_print("Current display roi area : x %d, y %d, width %d, height %d\n", x, y, width, height);
1110                 else
1111                         g_print("* Error : %d\n", err);
1112                 break;
1113
1114                 /* ext. setting */
1115         case 'z': /* Setting > Strobe setting */
1116                 g_print("*Strobe Mode\n");
1117                 camera_attr_foreach_supported_flash_mode(hcamcorder->camera, strobe_mode_cb, NULL);
1118                 g_print("\n Select Strobe Mode \n");
1119                 flush_stdin();
1120                 err = scanf("%d", &idx);
1121                 bret = camera_attr_set_flash_mode(hcamcorder->camera, idx);
1122                 break;
1123         case 'S': /* Setting > flash state */
1124                 g_print("*flash state\n");
1125                 err = camera_get_flash_state(cam_info, (camera_flash_state_e *)&idx);
1126                 if (CAMERA_ERROR_NONE == err)
1127                         g_print("Current flash state = %s\n", idx ? "ON" : "OFF");
1128                 else
1129                         g_print("* Error : %d\n", err);
1130                 break;
1131         case 'x': /* Setting > Capture mode ,Muitishot? */
1132                 g_print("*Select Capture mode!\n");
1133                 flush_stdin();
1134                 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1135                 err = scanf("%d", &idx);
1136
1137                 switch (idx) {
1138                 case 1:
1139                         g_print("stillshot mode selected and capture callback is set!!!!\n");
1140                         hcamcorder->is_multishot = FALSE;
1141                         camera_attr_set_hdr_mode(hcamcorder->camera, 0);
1142                         break;
1143                 case 2:
1144                         g_print("HDR Capture mode selected\n");
1145                         hcamcorder->is_multishot = FALSE;
1146                         g_print("\nSelect HDR capture mode\n");
1147                         flush_stdin();
1148                         for (i = 0 ; i < 3 ; i++)
1149                                 g_print("\t %d. %s\n", i, hdr_mode[i]);
1150                         err = scanf("%d", &idx);
1151                         if (idx >= CAMERA_ATTR_HDR_MODE_DISABLE && idx <= CAMERA_ATTR_HDR_MODE_KEEP_ORIGINAL)
1152                                 bret = camera_attr_set_hdr_mode(hcamcorder->camera, idx);
1153                         else
1154                                 g_print("invalid input %d\n", idx);
1155                         break;
1156                 default:
1157                         g_print("Wrong input, select again!!\n");
1158                         break;
1159                 }
1160                 break;
1161         case 'l': /* Setting > Face detection setting */
1162                 if (camera_is_supported_face_detection(hcamcorder->camera)) {
1163                         g_print("* Face detect mode !\n");
1164                         flush_stdin();
1165                         for (i = 0 ; i < 2 ; i++)
1166                                 g_print("\t %d. %s \n", i, detection_mode[i]);
1167                         err = scanf("%d", &idx);
1168                         if (idx == 0)
1169                                 bret = camera_stop_face_detection(hcamcorder->camera);
1170                         else if (idx == 1)
1171                                 bret = camera_start_face_detection(hcamcorder->camera, _face_detected, NULL);
1172                         else
1173                                 g_print("\n invalid input [%d]\n\n", idx);
1174                 } else {
1175                         g_print("face detection_not supported");
1176                 }
1177                 break;
1178         case 'k': /* Setting > Anti-handshake */
1179                 g_print("*Anti-handshake !\n");
1180                 g_print("\n Select Anti-handshake mode \n");
1181                 flush_stdin();
1182                 for (i = 0; i < 2; i++)
1183                         g_print("\t %d. %s\n", i, ahs_mode[i]);
1184                 err = scanf("%d", &idx);
1185                 if (idx == 0 || idx == 1)
1186                         bret = camera_attr_enable_anti_shake(hcamcorder->camera, idx);
1187                 else
1188                         g_print("invalid input %d\n", idx);
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, vs_mode[i]);
1196                 err = scanf("%d", &idx);
1197
1198                 if (idx < 0 || idx > 1) {
1199                         g_print("invalid input %d\n", idx);
1200                         break;
1201                 }
1202
1203                 if (idx == 1) {
1204                         g_print("\n Restart preview with NV12 and 720p resolution\n");
1205                         err = camera_stop_preview(hcamcorder->camera);
1206                         camera_set_preview_resolution(hcamcorder->camera, 1280, 720);
1207                         camera_set_preview_format(hcamcorder->camera, CAMERA_PIXEL_FORMAT_NV12);
1208                 }
1209
1210                 bret = camera_attr_enable_video_stabilization(hcamcorder->camera, idx);
1211
1212                 if (idx == 1) {
1213                         err = camera_start_preview(hcamcorder->camera);
1214                         if (err != CAMERA_ERROR_NONE)
1215                                 g_print("\n Restart FAILED! 0x%x\n", err);
1216                 }
1217                 break;
1218         case 'u': /* Touch AF area */
1219                 g_print("* Touch AF area !\n");
1220                 flush_stdin();
1221                 g_print("\n Input x,y,width,height \n");
1222                 err = scanf("%d,%d,%d,%d", &x, &y, &width, &height);
1223                 err = camera_attr_set_af_area(hcamcorder->camera, width, height);
1224                 if (err != 0)
1225                         g_print("Failed to set touch AF area.(%x)\n", err);
1226                 else
1227                         g_print("Succeed to set touch AF area.\n");
1228                 break;
1229         case 'n': /* file path */
1230                 g_print("* File path !\n");
1231                 flush_stdin();
1232                 g_print("\n Input file path to save captured data(string) : ");
1233                 if (fgets(hcamcorder->file_path, sizeof(hcamcorder->file_path), stdin)) {
1234                         hcamcorder->file_path[strlen(hcamcorder->file_path) - 1] = '\0';
1235                         g_print("\ncaptured data will be saved in [%s]\n", hcamcorder->file_path);
1236                 } else {
1237                         g_print("\nset file path failed\n");
1238                 }
1239                 break;
1240         case 'b': /* back */
1241                 hcamcorder->menu_state = MENU_STATE_MAIN;
1242                 break;
1243         default:
1244                 g_print("\t Invalid input \n");
1245                 break;
1246         }
1247
1248         g_print("\t bret : 0x%x \n", bret);
1249
1250         return;
1251 }
1252
1253
1254 /**
1255  * This function is to execute command.
1256  *
1257  * @param   channel [in]    1st parameter
1258  *
1259  * @return  This function returns TRUE/FALSE
1260  * @remark
1261  * @see
1262  */
1263 static gboolean cmd_input(GIOChannel *channel)
1264 {
1265         gchar *buf = NULL;
1266         gsize read_size;
1267         GError *g_error = NULL;
1268
1269         g_print("\n\tENTER\n");
1270
1271         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
1272         if (g_error) {
1273                 g_print("\n\tg_io_channel_read_chars error\n");
1274                 g_error_free(g_error);
1275                 g_error = NULL;
1276         }
1277
1278         if (buf) {
1279                 g_strstrip(buf);
1280
1281                 g_print("\n\tMenu Status : %d\n", hcamcorder->menu_state);
1282                 switch (hcamcorder->menu_state) {
1283                 case MENU_STATE_INIT:
1284                         mode_change(buf[0]);
1285                         break;
1286                 case MENU_STATE_MAIN:
1287                         main_menu(buf[0]);
1288                         break;
1289                 case MENU_STATE_SETTING:
1290                         setting_menu(buf[0]);
1291                         break;
1292                 default:
1293                         break;
1294                 }
1295
1296                 g_free(buf);
1297                 buf = NULL;
1298
1299                 print_menu();
1300         } else {
1301                 g_print("\n\tNo read input\n");
1302         }
1303
1304         return TRUE;
1305 }
1306
1307 static gboolean init_handle()
1308 {
1309         hcamcorder->is_multishot =  FALSE;
1310         hcamcorder->stillshot_count = 0;
1311         hcamcorder->multishot_count = 0;
1312         snprintf(hcamcorder->file_path, MAX_FILE_PATH_LENGTH, DEFAULT_FILE_PATH);
1313         hcamcorder->menu_state = MENU_STATE_INIT;
1314         hcamcorder->elapsed_time = 0;
1315
1316         return TRUE;
1317 }
1318
1319 void _preview_cb(camera_preview_data_s *frame, void *user_data)
1320 {
1321 #if 0
1322         FILE *fp = fopen("/opt/usr/media/test.yuv", "a");
1323         if (fp == NULL) {
1324                 g_print("\n============ file open failed ===========================\n");
1325                 return;
1326         }
1327
1328         switch (frame->num_of_planes) {
1329         case 1:
1330                 fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp);
1331         case 2:
1332                 fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp);
1333                 fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp);
1334         case 3:
1335                 fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp);
1336                 fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp);
1337                 fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp);
1338         default:
1339                 break;
1340         }
1341
1342         g_print("file write done ---\n");
1343
1344         fclose(fp);
1345         fp = NULL;
1346 #else
1347         g_print("----- preview callback - format %d, %dx%d, num plane %d\n",
1348                         frame->format, frame->width, frame->height, frame->num_of_planes);
1349 #endif
1350
1351         return;
1352 }
1353
1354 /**
1355  * This function is to change camcorder mode.
1356  *
1357  * @param   buf    [in]    user input
1358  *
1359  * @return  This function returns TRUE/FALSE
1360  * @remark
1361  * @see     other functions
1362  */
1363 static gboolean mode_change(gchar buf)
1364 {
1365         int err = 0;
1366         camera_device_state_e device_state = CAMERA_DEVICE_STATE_NULL;
1367         char display_type = '\0';
1368         bool check = FALSE;
1369
1370         switch (buf) {
1371         case '1':
1372                 hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA1;
1373                 check = TRUE;
1374                 break;
1375         case '2':
1376                 hcamcorder->type = cam_info = CAMERA_DEVICE_CAMERA0;
1377                 check = TRUE;
1378                 break;
1379         case '3':
1380                 err = camera_add_device_state_changed_cb(_camera_device_state_changed_cb,
1381                         NULL, &g_camera_device_changed_cb_id);
1382                 g_print("add result 0x%x - cb id %d\n", err, g_camera_device_changed_cb_id);
1383                 return FALSE;
1384         case '4':
1385                 if (g_camera_device_changed_cb_id > 0) {
1386                         err = camera_remove_device_state_changed_cb(g_camera_device_changed_cb_id);
1387                         g_camera_device_changed_cb_id = 0;
1388                         g_print("remove result 0x%x\n", err);
1389                 } else {
1390                         g_print("invalid callback id %d\n", g_camera_device_changed_cb_id);
1391                 }
1392                 return FALSE;
1393         case '5':
1394                 err = camera_get_device_state(CAMERA_DEVICE_CAMERA0, &device_state);
1395                 g_print("get result 0x%x - state %d\n", err, device_state);
1396                 return FALSE;
1397         case 'q':
1398                 g_print("\t Quit Camcorder Testsuite!!\n");
1399                 elm_exit();
1400                 return FALSE;
1401         default:
1402                 g_print("\t Invalid media type(%c)\n", buf);
1403                 return FALSE;
1404         }
1405
1406         g_print("\n[camcorder_create - type %d]\n", cam_info);
1407
1408         g_get_current_time(&previous_time);
1409
1410         g_timer_reset(timer);
1411
1412         err = camera_create(cam_info, &hcamcorder->camera);
1413
1414         g_print("[camera_create()  : %12.6lfs]\n", g_timer_elapsed(timer, NULL));
1415
1416         if (err != 0) {
1417                 g_print("\n\tmmcamcorder_create = 0x%x\n", err);
1418                 return -1;
1419         }
1420
1421         check = FALSE;
1422         while (!check) {
1423                 g_print("\n\tEnter the Display Type\n");
1424                 g_print("\t'1' OVERLAY surface\n");
1425                 g_print("\t'2' EVAS surface\n");
1426                 g_print("\t'3' NONE surface\n");
1427
1428                 err = scanf("%c", &display_type);
1429                 if (err == EOF) {
1430                         g_print("\t!!!read input error!!!\n");
1431                         continue;
1432                 }
1433
1434                 switch (display_type) {
1435                 case '1':
1436                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(ad.win));
1437                         check = TRUE;
1438                         break;
1439                 case '2':
1440                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_EVAS, GET_DISPLAY(ad.eo));
1441                         check = TRUE;
1442                         break;
1443                 case '3':
1444                         camera_set_display(hcamcorder->camera, CAMERA_DISPLAY_TYPE_NONE, NULL);
1445                         check = TRUE;
1446                         break;
1447                 default:
1448                         g_print("\t Invalid display type(%c)\n", display_type);
1449                         break;
1450                 }
1451         }
1452
1453         camera_set_error_cb(hcamcorder->camera, _camera_error_cb, NULL);
1454         camera_set_state_changed_cb(hcamcorder->camera, _camera_state_changed_cb, NULL);
1455         camera_set_interrupted_cb(hcamcorder->camera, _camera_interrupted_cb, NULL);
1456         camera_set_interrupt_started_cb(hcamcorder->camera, _camera_interrupt_started_cb, NULL);
1457         camera_set_display_mode(hcamcorder->camera, CAMERA_DISPLAY_MODE_LETTER_BOX);
1458         /*camera_set_display_rotation(hcamcorder->camera, CAMERA_ROTATION_90);*/
1459         /*camera_set_display_flip(hcamcorder->camera, CAMERA_FLIP_VERTICAL);*/
1460         /*camera_set_preview_cb(hcamcorder->camera, _preview_cb, hcamcorder->camera);*/
1461
1462         camera_start_preview(hcamcorder->camera);
1463
1464         g_get_current_time(&current_time);
1465         timersub(&current_time, &previous_time, &result_time);
1466
1467         g_print("\n\tCamera Starting Time  : %ld.%lds\n", result_time.tv_sec, result_time.tv_usec);
1468
1469         hcamcorder->menu_state = MENU_STATE_MAIN;
1470
1471         print_menu();
1472
1473         return TRUE;
1474 }
1475
1476 static int app_create(void *data)
1477 {
1478         appdata *app_data = data;
1479         int w = 0;
1480         int h = 0;
1481         Evas_Object *win = NULL;
1482         Evas_Object *eo = NULL;
1483         Evas_Object *bg = NULL;
1484         Evas_Object *rect = NULL;
1485
1486         if (app_data == NULL) {
1487                 g_print("\t\nappdata is NULL\n");
1488                 return 0;
1489         }
1490
1491         /* use gl backend */
1492         elm_config_accel_preference_set("opengl");
1493
1494         win = elm_win_add(NULL, "camera_test", ELM_WIN_BASIC);
1495         if (win) {
1496                 elm_win_title_set(win, "camera_test");
1497                 elm_win_borderless_set(win, EINA_TRUE);
1498                 elm_win_screen_size_get(win, NULL, NULL, &w, &h);
1499                 g_print("\n\tscreen size %dx%d\n\n", w, h);
1500                 evas_object_resize(win, w, h);
1501                 elm_win_autodel_set(win, EINA_TRUE);
1502                 elm_win_alpha_set(win, EINA_TRUE);
1503         } else {
1504                 g_print("\n\tfailed to get window\n\n");
1505                 return 1;
1506         }
1507
1508         bg = elm_bg_add(win);
1509         if (bg) {
1510                 elm_win_resize_object_add(win, bg);
1511                 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1512                 evas_object_show(bg);
1513         } else {
1514                 g_print("\n\tfailed to get elm bg\n\n");
1515                 return 1;
1516         }
1517
1518         rect = evas_object_rectangle_add(evas_object_evas_get(win));
1519         if (rect) {
1520                 evas_object_color_set(rect, 0, 0, 0, 0);
1521                 evas_object_render_op_set(rect, EVAS_RENDER_COPY);
1522         } else {
1523                 g_print("\n\tfailed to get rectangle\n\n");
1524                 return 1;
1525         }
1526
1527         elm_win_resize_object_add(win, rect);
1528         evas_object_size_hint_weight_set(rect, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1529         evas_object_show(rect);
1530
1531         /* Create evas image object for EVAS surface */
1532         eo = evas_object_image_add(evas_object_evas_get(win));
1533         evas_object_image_size_set(eo, w, h);
1534         evas_object_image_fill_set(eo, 0, 0, w, h);
1535         evas_object_resize(eo, w, h);
1536         evas_object_show(eo);
1537
1538         elm_win_activate(win);
1539         evas_object_show(win);
1540
1541         app_data->win = win;
1542         app_data->eo = eo;
1543
1544         timer = g_timer_new();
1545         g_timer_reset(timer);
1546
1547         init_handle();
1548
1549         print_menu();
1550
1551         return 0;
1552 }
1553
1554 static int app_terminate(void *data)
1555 {
1556         appdata *app_data = data;
1557
1558         if (app_data == NULL) {
1559                 g_print("\n\tappdata is NULL\n");
1560                 return 0;
1561         }
1562
1563         if (timer) {
1564                 g_timer_stop(timer);
1565                 g_timer_destroy(timer);
1566                 timer = NULL;
1567         }
1568
1569         return 0;
1570 }
1571
1572
1573 /**
1574  * This function is the example main function for mmcamcorder API.
1575  *
1576  * @param
1577  *
1578  * @return  This function returns 0.
1579  * @remark
1580  * @see     other functions
1581  */
1582 int main(int argc, char **argv)
1583 {
1584         int bret;
1585
1586         hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
1587
1588         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1589         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1590
1591         memset(&ad, 0x0, sizeof(appdata));
1592         ops.data = &ad;
1593
1594         bret = appcore_efl_main(PACKAGE, &argc, &argv, &ops);
1595
1596         g_print("\n\treturn appcore_efl : %d\n\n", bret);
1597
1598         g_free(hcamcorder);
1599         g_io_channel_unref(stdin_channel);
1600
1601         return bret;
1602 }
1603 /*EOF*/