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