cfc9708faca5a39189a246761ff804e526470fd0
[framework/multimedia/libmm-camcorder.git] / test / mm_camcorder_testsuite.c
1 /*
2  * mm_camcorder_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 for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 /* ===========================================================================================
23 EDIT HISTORY FOR MODULE
24         This section contains comments describing changes made to the module.
25         Notice that changes are listed in reverse chronological order.
26 when            who                                             what, where, why
27 ---------       --------------------    ----------------------------------------------------------
28 10/08/07        soyeon.kang@samsung.com         Created
29 10/10/07        wh01.cho@samsung.com            Created
30 12/30/08        jh1979.park@samsung.com         Modified
31 08/31/11        sc11.lee@samsung.com            Modified (Reorganized for easy look)
32 */
33
34
35 /*=======================================================================================
36 |  INCLUDE FILES                                                                        |
37 =======================================================================================*/
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <glib.h>
41 #include <gst/gst.h>
42 #include <sys/time.h>
43 #include "../src/include/mm_camcorder.h"
44 #include "../src/include/mm_camcorder_internal.h"
45 #include "../src/include/mm_camcorder_util.h"
46 #include <gst/interfaces/colorbalance.h>
47
48 /*-----------------------------------------------------------------------
49 |    GLOBAL VARIABLE DEFINITIONS:                                       |
50 -----------------------------------------------------------------------*/
51 #define EXPORT_API __attribute__((__visibility__("default")))
52
53 #define PACKAGE "mm_camcorder_testsuite"
54
55 GMainLoop *g_loop;
56 GIOChannel *stdin_channel;
57 int resolution_set;
58 int g_current_state;
59 int src_w, src_h;
60 GstCaps *filtercaps;
61 bool isMultishot;
62 MMCamPreset cam_info;
63 int mmcamcorder_state;
64 int mmcamcorder_print_state;
65 int multishot_num;
66 static int audio_stream_cb_cnt;
67 static int video_stream_cb_cnt;
68 static GTimer *timer = NULL;
69
70 /*-----------------------------------------------------------------------
71 |    GLOBAL CONSTANT DEFINITIONS:                                       |
72 -----------------------------------------------------------------------*/
73
74
75 /*-----------------------------------------------------------------------
76 |    IMPORTED VARIABLE DECLARATIONS:                                    |
77 -----------------------------------------------------------------------*/
78
79
80 /*-----------------------------------------------------------------------
81 |    IMPORTED FUNCTION DECLARATIONS:                                    |
82 -----------------------------------------------------------------------*/
83
84
85 /*-----------------------------------------------------------------------
86 |    LOCAL #defines:                                                    |
87 -----------------------------------------------------------------------*/
88 #define test_ffmux_mp4
89
90 // FULLHD(1080P)
91 #define SRC_W_1920                                                      1920
92 #define SRC_H_1080                                                      1080
93
94
95 // 2M
96 #define SRC_W_1600                                                      1600
97 #define SRC_H_1200                                                      1200
98
99 //VGA
100 #define SRC_W_640                                                       640
101 #define SRC_H_480                                                       480
102
103 //QVGA
104 #define SRC_W_320                                                       320                                     // video input width
105 #define SRC_H_240                                                       240                                             // video input height
106
107 //QCIF
108 #define SRC_W_176                                                       176                                     // video input width
109 #define SRC_H_144                                                       144                                             // video input height
110
111 //QQVGA
112 #define SRC_W_160                                                       160                                             // video input width
113 #define SRC_H_120                                                       120                                             // video input heith
114
115 //special resolution
116 #define SRC_W_400                                                       400                                     // video input width
117 #define SRC_H_300                                                       300                                             // video input height
118
119 #define SRC_W_192                                                       192                                     // video input width
120 #define SRC_H_256                                                       256                                             // video input height
121
122 #define SRC_W_144                                                       144                                     // video input width
123 #define SRC_H_176                                                       176                                             // video input height
124
125 #define SRC_W_300                                                       300
126 #define SRC_W_400                                                       400
127
128
129 #define DISPLAY_X_0                                                     0                                               //for direct FB
130 #define DISPLAY_Y_0                                                     0                                               //for direct FB
131
132 #define DISPLAY_W_320                                           320                                     //for direct FB
133 #define DISPLAY_H_240                                           240                                             //for direct FB
134
135
136 #define SRC_VIDEO_FRAME_RATE_15         15    // video input frame rate
137 #define SRC_VIDEO_FRAME_RATE_30         30    // video input frame rate
138 #define IMAGE_ENC_QUALITY               85    // quality of jpeg
139 #define IMAGE_CAPTURE_COUNT_STILL       1     // the number of still-shot
140 #define IMAGE_CAPTURE_COUNT_MULTI       3     // default the number of multi-shot
141 #define IMAGE_CAPTURE_COUNT_INTERVAL    100   // mili seconds
142
143 #define MAX_FILE_SIZE_FOR_MMS           (250 * 1024)
144
145 #define EXT_JPEG                        "jpg"
146 #define EXT_MP4                         "mp4"
147 #define EXT_3GP                         "3gp"
148 #define EXT_AMR                         "amr"
149 #define EXT_MKV                         "mkv"
150
151 #define TARGET_FILENAME_PATH            "/opt/usr/media/"
152 #define STILL_CAPTURE_FILE_PATH_NAME    TARGET_FILENAME_PATH"StillshotCapture"
153 #define MULTI_CAPTURE_FILE_PATH_NAME    TARGET_FILENAME_PATH"MultishotCapture"
154 #define IMAGE_CAPTURE_THUMBNAIL_PATH    TARGET_FILENAME_PATH"thumbnail.jpg"
155 #define IMAGE_CAPTURE_SCREENNAIL_PATH   TARGET_FILENAME_PATH"screennail.yuv"
156 #define IMAGE_CAPTURE_EXIF_PATH         TARGET_FILENAME_PATH"exif.raw"
157 #define TARGET_FILENAME_VIDEO           TARGET_FILENAME_PATH"test_rec_video.3gp"
158 #define TARGET_FILENAME_AUDIO           TARGET_FILENAME_PATH"test_rec_audio.m4a"
159 #define CAPTURE_FILENAME_LEN            256
160
161 #define AUDIO_SOURCE_SAMPLERATE_AAC     44100
162 #define AUDIO_SOURCE_SAMPLERATE_AMR     8000
163 #define AUDIO_SOURCE_FORMAT             MM_CAMCORDER_AUDIO_FORMAT_PCM_S16_LE
164 #define AUDIO_SOURCE_CHANNEL_AAC        2
165 #define AUDIO_SOURCE_CHANNEL_AMR        1
166 #define VIDEO_ENCODE_BITRATE            40000000 /* bps */
167
168 #define DEFAULT_CAM_DEVICE              MM_VIDEO_DEVICE_CAMERA1
169
170 /*
171  * D E B U G   M E S S A G E
172  */
173 #define MMF_DEBUG                       "** (mmcamcorder testsuite) DEBUG: "
174 #define MMF_ERR                         "** (mmcamcorder testsuite) ERROR: "
175 #define MMF_INFO                        "** (mmcamcorder testsuite) INFO: "
176 #define MMF_WARN                        "** (mmcamcorder testsuite) WARNING: "
177 #define MMF_TIME                        "** (mmcamcorder testsuite) TIME: "
178
179 #define CHECK_MM_ERROR(expr) \
180 do {\
181         int ret = 0; \
182         ret = expr; \
183         if (ret != MM_ERROR_NONE) {\
184                 printf("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
185                 return; \
186         }\
187 } while(0)
188
189 #define time_msg_t(fmt,arg...)  \
190 do { \
191         fprintf(stderr,"\x1b[44m\x1b[37m"MMF_TIME"[%s:%05d]  " fmt ,__func__, __LINE__, ##arg); \
192         fprintf(stderr,"\x1b[0m\n"); \
193 } while(0)
194
195  #define debug_msg_t(fmt,arg...)\
196  do { \
197         fprintf(stderr, MMF_DEBUG"[%s:%05d]  " fmt "\n",__func__, __LINE__, ##arg); \
198  } while(0)
199
200 #define err_msg_t(fmt,arg...)   \
201 do { \
202         fprintf(stderr, MMF_ERR"[%s:%05d]  " fmt "\n",__func__, __LINE__, ##arg); \
203 } while(0)
204
205 #define info_msg_t(fmt,arg...)  \
206 do { \
207         fprintf(stderr, MMF_INFO"[%s:%05d]  " fmt "\n",__func__, __LINE__, ##arg); \
208 } while(0)
209
210 #define warn_msg_t(fmt,arg...)  \
211 do { \
212         fprintf(stderr, MMF_WARN"[%s:%05d]  " fmt "\n",__func__, __LINE__, ##arg); \
213 } while(0)
214
215 #ifndef SAFE_FREE
216 #define SAFE_FREE(x)       if(x) {g_free(x); x = NULL;}
217 #endif
218
219
220 GTimeVal previous;
221 GTimeVal current;
222 GTimeVal result;
223 //temp
224
225 /**
226  * Enumerations for command
227  */
228 #define SENSOR_WHITEBALANCE_NUM         10
229 #define SENSOR_COLOR_TONE_NUM           31
230 #define SENSOR_FLIP_NUM                 3
231 #define SENSOR_PROGRAM_MODE_NUM         15
232 #define SENSOR_FOCUS_NUM                6
233 #define SENSOR_INPUT_ROTATION           4
234 #define SENSOR_AF_SCAN_NUM              4
235 #define SENSOR_ISO_NUM                  8
236 #define SENSOR_EXPOSURE_NUM             9
237 #define SENSOR_IMAGE_FORMAT             9
238
239
240 /*-----------------------------------------------------------------------
241 |    LOCAL CONSTANT DEFINITIONS:                                        |
242 -----------------------------------------------------------------------*/
243 enum
244 {
245         MODE_VIDEO_CAPTURE,     /* recording and image capture mode */
246         MODE_AUDIO,             /* audio recording*/
247         MODE_NUM,
248 };
249
250 enum
251 {
252         MENU_STATE_MAIN,
253         MENU_STATE_SETTING,
254         MENU_STATE_NUM,
255 };
256
257 /*-----------------------------------------------------------------------
258 |    LOCAL DATA TYPE DEFINITIONS:                                       |
259 -----------------------------------------------------------------------*/
260 typedef struct _cam_handle
261 {
262         MMHandleType camcorder;
263         int mode;                       /* image(capture)/video(recording) mode */
264         bool isMultishot;               /* flag for multishot mode */
265         int stillshot_count;            /* total stillshot count */
266         int multishot_count;            /* total multishot count */
267         const char *stillshot_filename;       /* stored filename of  stillshot  */
268         const char *multishot_filename;       /* stored filename of  multishot  */
269         int menu_state;
270         int fps;
271         bool isMute;
272         unsigned long long elapsed_time;
273 } cam_handle_t;
274
275 typedef struct _cam_xypair
276 {
277         const char *attr_subcat_x;
278         const char *attr_subcat_y;
279         int x;
280         int y;
281 } cam_xypair_t;
282
283 /*---------------------------------------------------------------------------
284 |    LOCAL VARIABLE DEFINITIONS:                                                                                        |
285 ---------------------------------------------------------------------------*/
286 static cam_handle_t *hcamcorder ;
287
288 const char *wb[SENSOR_WHITEBALANCE_NUM]={
289         "None",
290         "Auto",
291         "Daylight",
292         "Cloudy",
293         "Fluoroscent",
294         "Incandescent",
295         "Shade",
296         "Horizon",
297         "Flash",
298         "Custom",
299 };
300
301 const char *ct[SENSOR_COLOR_TONE_NUM] = {
302         "NONE",
303         "MONO",
304         "SEPIA",
305         "NEGATIVE",
306         "BLUE",
307         "GREEN",
308         "AQUA",
309         "VIOLET",
310         "ORANGE",
311         "GRAY",
312         "RED",
313         "ANTIQUE",
314         "WARM",
315         "PINK",
316         "YELLOW",
317         "PURPLE",
318         "EMBOSS",
319         "OUTLINE",
320         "SOLARIZATION",
321         "SKETCH",
322         "WASHED",
323         "VINTAGE_WARM",
324         "VINTAGE_COLD",
325         "POSTERIZATION",
326         "CARTOON",
327         "SELECTVE_COLOR_RED",
328         "SELECTVE_COLOR_GREEN",
329         "SELECTVE_COLOR_BLUE",
330         "SELECTVE_COLOR_YELLOW",
331         "SELECTVE_COLOR_RED_YELLOW",
332         "GRAPHICS"
333 };
334
335 const char *flip[SENSOR_FLIP_NUM] = {
336         "Horizontal",
337         "Vertical",
338         "Not flipped",
339 };
340
341 const char *program_mode[SENSOR_PROGRAM_MODE_NUM] = {
342         "NORMAL",
343         "PORTRAIT",
344         "LANDSCAPE",
345         "SPORTS",
346         "PARTY_N_INDOOR",
347         "BEACH_N_INDOOR",
348         "SUNSET",
349         "DUSK_N_DAWN",
350         "FALL_COLOR",
351         "NIGHT_SCENE",
352         "FIREWORK",
353         "TEXT",
354         "SHOW_WINDOW",
355         "CANDLE_LIGHT",
356         "BACKLIGHT",
357 };
358
359 const char *focus_mode[SENSOR_FOCUS_NUM] = {
360         "None",
361         "Pan",
362         "Auto",
363         "Manual",
364         "Touch Auto",
365         "Continuous Auto",
366 };
367
368 const char *camera_rotation[SENSOR_INPUT_ROTATION] = {
369         "None",
370         "90",
371         "180",
372         "270",
373 };
374
375 const char *af_scan[SENSOR_AF_SCAN_NUM] = {
376         "None",
377         "Normal",
378         "Macro mode",
379         "Full mode",
380 };
381
382 const char *iso_name[SENSOR_ISO_NUM] = {
383         "ISO Auto",
384         "ISO 50",
385         "ISO 100",
386         "ISO 200",
387         "ISO 400",
388         "ISO 800",
389         "ISO 1600",
390         "ISO 3200",
391 };
392
393 const char *exposure_mode[SENSOR_EXPOSURE_NUM] = {
394         "AE off",
395         "AE all mode",
396         "AE center 1 mode",
397         "AE center 2 mode",
398         "AE center 3 mode",
399         "AE spot 1 mode",
400         "AE spot 2 mode",
401         "AE custom 1 mode",
402         "AE custom 2 mode",
403 };
404
405 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
406         "NV12",
407         "NV12T",
408         "NV16",
409         "NV21",
410         "YUYV",
411         "UYVY",
412         "422P",
413         "I420",
414         "YV12",
415 };
416
417 const char *face_zoom_mode[] = {
418         "Face Zoom OFF",
419         "Face Zoom ON",
420 };
421
422 const char *display_mode[] = {
423         "Default",
424         "Primary Video ON and Secondary Video Full Screen",
425         "Primary Video OFF and Secondary Video Full Screen",
426 };
427
428 const char *output_mode[] = {
429         "Letter Box mode",
430         "Original Size mode",
431         "Full Screen mode",
432         "Cropped Full Screen mode",
433         "ROI mode",
434 };
435
436 const char *capture_sound[] = {
437         "Default",
438         "Extra 01",
439         "Extra 02",
440 };
441
442 const char *rotate_mode[] = {
443         "0",
444         "90",
445         "180",
446         "270",
447 };
448
449 const char* strobe_mode[] = {
450         "Strobe OFF",
451         "Strobe ON",
452         "Strobe Auto",
453         "Strobe RedEyeReduction",
454         "Strobe SlowSync",
455         "Strobe FrontCurtain",
456         "Strobe RearCurtain",
457         "Strobe Permanent",
458 };
459
460 const char *detection_mode[2] = {
461         "Face Detection OFF",
462         "Face Detection ON",
463 };
464
465 const char *wdr_mode[] = {
466         "WDR OFF",
467         "WDR ON",
468         "WDR AUTO",
469 };
470
471 const char *hdr_mode[] = {
472         "HDR OFF",
473         "HDR ON",
474         "HDR ON and Original",
475 };
476
477 const char *ahs_mode[] = {
478         "Anti-handshake OFF",
479         "Anti-handshake ON",
480         "Anti-handshake AUTO",
481         "Anti-handshake MOVIE",
482 };
483
484 const char *vs_mode[] = {
485         "Video-stabilization OFF",
486         "Video-stabilization ON",
487 };
488
489 const char *visible_mode[] = {
490         "Display OFF",
491         "Display ON",
492 };
493
494
495 /*---------------------------------------------------------------------------
496 |    LOCAL FUNCTION PROTOTYPES:                                                                                         |
497 ---------------------------------------------------------------------------*/
498 static void print_menu();
499 void  get_me_out();
500 static gboolean cmd_input(GIOChannel *channel);
501 //static bool filename_callback (int format, char *filename, void *user_param);
502 static gboolean msg_callback(int message, void *msg_param, void *user_param);
503 static gboolean init(int type);
504 static gboolean mode_change();
505 int camcordertest_set_attr_int(const char* attr_subcategory, int value);
506
507
508 static inline void flush_stdin()
509 {
510         int ch;
511         while((ch=getchar()) != EOF && ch != '\n');
512 }
513
514 void
515 cam_utils_convert_YUYV_to_UYVY(unsigned char* dst, unsigned char* src, gint length)
516 {
517         int i = 0;
518
519         //memset dst
520         memset(dst, 0x00, length);
521         memcpy(dst, src + 1, length-1);
522
523         for ( i = 0 ; i < length; i ++)
524         {
525                 if ( !(i % 2) )
526                 {
527                         dst[i+1] = src[i];
528                 }
529         }
530 }
531
532 #ifdef USE_AUDIO_STREAM_CB
533 static int camcordertest_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param)
534 {
535         audio_stream_cb_cnt++;
536         printf("audio_stream cb is called (stream:%p, data:%p, format:%d, channel:%d, volume_dB:%f, length:%d, timestamp:%d)\n",
537                stream, stream->data, stream->format, stream->channel, stream->volume_dB, stream->length, stream->timestamp);
538
539         return TRUE;
540 }
541 #endif /* USE_AUDIO_STREAM_CB */
542
543 static int camcordertest_video_stream_cb(MMCamcorderVideoStreamDataType *stream, void *user_param)
544 {
545         video_stream_cb_cnt++;
546
547         printf("VIDEO STREAM CALLBACK total length :%u, size %dx%d\n", stream->length_total, stream->width, stream->height);
548
549         return TRUE;
550 }
551
552 static void _file_write(char *path, void *data, int size)
553 {
554         FILE *fp = NULL;
555
556         if (!path || !data || size <= 0) {
557                 printf("ERROR %p %p %d\n", path, data, size);
558                 return;
559         }
560
561         fp = fopen(path, "w");
562         if (fp == NULL) {
563                 printf("open error! [%s], errno %d\n", path, errno);
564                 return;
565         } else {
566                 printf("open success [%s]\n", path);
567                 if (fwrite(data, size, 1, fp) != 1) {
568                         printf("write error! errno %d\n", errno);
569                 } else {
570                         printf("write success [%s]\n", path);
571                 }
572
573                 fclose(fp);
574                 fp = NULL;
575         }
576 }
577
578 static void _file_write2(const char *path, void *data, int size)
579 {
580         FILE *fp = NULL;
581
582         if (!path || !data || size <= 0) {
583                 printf("ERROR %p %p %d\n", path, data, size);
584                 return;
585         }
586
587         fp = fopen(path, "w");
588         if (fp == NULL) {
589                 printf("open error! [%s], errno %d\n", path, errno);
590                 return;
591         } else {
592                 printf("open success [%s]\n", path);
593                 if (fwrite(data, size, 1, fp) != 1) {
594                         printf("write error! errno %d\n", errno);
595                 } else {
596                         printf("write success [%s]\n", path);
597                 }
598
599                 fclose(fp);
600                 fp = NULL;
601         }
602 }
603
604
605 static int
606 camcordertest_video_capture_cb(MMCamcorderCaptureDataType *main, MMCamcorderCaptureDataType *thumb, void *data)
607 {
608         int nret = 0;
609         int scrnl_size = 0;
610         int exif_size = 0;
611         char m_filename[CAPTURE_FILENAME_LEN];
612         MMCamcorderCaptureDataType *scrnl = NULL;
613         unsigned char *exif_data = NULL;
614
615         if (main == NULL) {
616                 warn_msg_t("Capture callback : Main image buffer is NULL!!!");
617                 return FALSE;
618         }
619
620         if (hcamcorder->isMultishot) {
621                 snprintf(m_filename, CAPTURE_FILENAME_LEN, "%s%03d.jpg", hcamcorder->multishot_filename, hcamcorder->multishot_count++);
622         } else {
623                 snprintf(m_filename, CAPTURE_FILENAME_LEN, "%s%03d.jpg", hcamcorder->stillshot_filename, hcamcorder->stillshot_count++);
624         }
625
626         debug_msg_t("hcamcorder->isMultishot=%d =>1: MULTI, 0: STILL, filename : %s",
627                     hcamcorder->isMultishot, m_filename);
628
629         if (main->format != MM_PIXEL_FORMAT_ENCODED) {
630                 unsigned int dst_size = 0;
631                 void *dst = NULL;
632
633                 nret = _mmcamcorder_encode_jpeg(main->data, main->width, main->height, main->format,
634                                                 main->length, 90, &dst, &dst_size, 0);
635                 if (nret) {
636                         _file_write(m_filename, dst, dst_size);
637                 } else {
638                         printf("Failed to encode YUV(%d) -> JPEG. \n", main->format);
639                 }
640
641                 free(dst);
642                 dst = NULL;
643         } else if (!hcamcorder->isMultishot) {
644
645                 printf("MM_PIXEL_FORMAT_ENCODED main->data=%p main->length=%d, main->width=%d, main->heigtht=%d \n",
646                        main->data, main->length, main->width, main->height);
647
648                 /* main image */
649                 _file_write(m_filename, main->data, main->length);
650
651                 /* thumbnail */
652                 if (thumb != NULL) {
653                         _file_write2(IMAGE_CAPTURE_THUMBNAIL_PATH, thumb->data, thumb->length);
654                 }
655
656                 /* screennail */
657                 mm_camcorder_get_attributes(hcamcorder->camcorder, NULL,
658                                             "captured-screennail", &scrnl, &scrnl_size,
659                                             NULL);
660                 if (scrnl != NULL) {
661                         _file_write2(IMAGE_CAPTURE_SCREENNAIL_PATH, scrnl->data, scrnl->length);
662                 } else {
663                         printf( "Screennail buffer is NULL.\n" );
664                 }
665
666                 /* EXIF data */
667                 mm_camcorder_get_attributes(hcamcorder->camcorder, NULL,
668                                             "captured-exif-raw-data", &exif_data, &exif_size,
669                                             NULL);
670                 if (exif_data) {
671                         _file_write2(IMAGE_CAPTURE_EXIF_PATH, exif_data, exif_size);
672                 }
673         }
674
675         return TRUE;
676 }
677
678 static gboolean test_idle_capture_start()
679 {
680         int err;
681
682         camcordertest_set_attr_int(MMCAM_CAPTURE_FORMAT, MM_PIXEL_FORMAT_ENCODED);
683         camcordertest_set_attr_int(MMCAM_IMAGE_ENCODER, MM_IMAGE_CODEC_JPEG);
684
685         g_timer_reset(timer);
686         err = mm_camcorder_capture_start(hcamcorder->camcorder);
687
688         if (err < 0) {
689                 warn_msg_t("Multishot mm_camcorder_capture_start = %x", err);
690         }
691
692         return FALSE;
693 }
694
695 int camcordertest_set_attr_int(const char * attr_subcategory, int value)
696 {
697         char * err_attr_name = NULL;
698         int err;
699
700         if (hcamcorder) {
701                 if (hcamcorder->camcorder) {
702                         debug_msg_t("camcordertest_set_attr_int(%s, %d)", attr_subcategory, value);
703
704                         err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
705                                                           attr_subcategory, value,
706                                                           NULL);
707                         if (err != MM_ERROR_NONE) {
708                                 err_msg_t("camcordertest_set_attr_int : Error(%s:%x)!!!!!!!", err_attr_name, err);
709                                 SAFE_FREE(err_attr_name);
710                                 return FALSE;
711                         }
712
713                         //success
714                         return TRUE;
715                 }
716
717                 debug_msg_t("camcordertest_set_attr_int(!hcamcorder->camcorde)");
718         }
719
720         debug_msg_t("camcordertest_set_attr_int(!hcamcorder)");
721
722         return FALSE;
723 }
724
725 int camcordertest_set_attr_xypair(cam_xypair_t pair)
726 {
727         char * err_attr_name = NULL;
728         int err;
729
730         if (hcamcorder) {
731                 if (hcamcorder->camcorder) {
732                         debug_msg_t("camcordertest_set_attr_xypair((%s, %s), (%d, %d))",  pair.attr_subcat_x, pair.attr_subcat_y, pair.x, pair.y);
733
734                         err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
735                                                                         pair.attr_subcat_x, pair.x,
736                                                                         pair.attr_subcat_y, pair.y,
737                                                                         NULL);
738                         if (err < 0) {
739                                 err_msg_t("camcordertest_set_attr_xypair : Error(%s:%x)!!", err_attr_name, err);
740                                 SAFE_FREE (err_attr_name);
741                                 return FALSE;
742                         }
743
744                         //success
745                         return TRUE;
746                 }
747
748                 debug_msg_t("camcordertest_set_attr_xypair(!hcamcorder->camcorde)");
749         }
750
751         debug_msg_t("camcordertest_set_attr_xypair(!hcamcorder)");
752         return FALSE;
753 }
754
755 int camcordertest_get_attr_valid_intarray(const char * attr_name, int ** array, int *count)
756 {
757         MMCamAttrsInfo info;
758         int err;
759
760         if (hcamcorder)
761         {
762                 if (hcamcorder->camcorder)
763                 {
764                         debug_msg_t("camcordertest_get_attr_valid_intarray(%s)", attr_name);
765
766                         err = mm_camcorder_get_attribute_info(hcamcorder->camcorder, attr_name, &info);
767                         if (err != MM_ERROR_NONE) {
768                                 err_msg_t("camcordertest_get_attr_valid_intarray : Error(%x)!!", err);
769                                 return FALSE;
770                         } else {
771                                 if (info.type == MM_CAM_ATTRS_TYPE_INT) {
772                                         if (info.validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY) {
773                                                 *array = info.int_array.array;
774                                                 *count = info.int_array.count;
775                                                 debug_msg_t("INT ARRAY - default value : %d", info.int_array.def);
776                                                 return TRUE;
777                                         }
778                                 }
779
780                                 err_msg_t("camcordertest_get_attr_valid_intarray : Type mismatched!!");
781                                 return FALSE;
782                         }
783                         //success
784                 }
785
786                 debug_msg_t("camcordertest_get_attr_valid_intarray(!hcamcorder->camcorde)");
787         }
788
789         debug_msg_t("camcordertest_get_attr_valid_intarray(!hcamcorder)");
790         return FALSE;
791 }
792
793 int camcordertest_get_attr_valid_intrange(const char * attr_name, int *min, int *max)
794 {
795         MMCamAttrsInfo info;
796         int err;
797
798         if (hcamcorder)
799         {
800                 if (hcamcorder->camcorder)
801                 {
802                         debug_msg_t("camcordertest_get_attr_valid_intrange(%s)", attr_name);
803
804                         err = mm_camcorder_get_attribute_info(hcamcorder->camcorder, attr_name, &info);
805                         if (err != MM_ERROR_NONE) {
806                                 err_msg_t("camcordertest_get_attr_valid_intarray : Error(%x)!!",  err);
807                                 return FALSE;
808                         } else {
809                                 if (info.type == MM_CAM_ATTRS_TYPE_INT) {
810                                         if (info.validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_RANGE) {
811                                                 *min = info.int_range.min;
812                                                 *max = info.int_range.max;
813                                                 debug_msg_t("INT RANGE - default : %d", info.int_range.def);
814                                                 return TRUE;
815                                         }
816                                 }
817
818                                 err_msg_t("camcordertest_get_attr_valid_intarray : Type mismatched!!");
819                                 return FALSE;
820                         }
821                         //success
822
823                 }
824
825                 debug_msg_t("camcordertest_get_attr_valid_intarray(!hcamcorder->camcorde)");
826         }
827
828         debug_msg_t("camcordertest_get_attr_valid_intarray(!hcamcorder)");
829         return FALSE;
830 }
831
832
833 void  get_me_out()
834 {
835         mm_camcorder_capture_stop(hcamcorder->camcorder);
836 }
837
838 static void print_menu()
839 {
840         switch(hcamcorder->menu_state)
841         {
842                 case MENU_STATE_MAIN:
843                         if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
844                                 g_print("\n\t=======================================\n");
845                                 if ( cam_info.videodev_type == MM_VIDEO_DEVICE_CAMERA1 )
846                                         g_print("\t   Video Capture (Front camera)\n");
847                                 else if(  cam_info.videodev_type == MM_VIDEO_DEVICE_CAMERA0 )
848                                         g_print("\t   Video Capture (Rear camera)\n");
849                                 g_print("\t=======================================\n");
850
851                                 if(mmcamcorder_print_state <= MM_CAMCORDER_STATE_PREPARE) {
852                                         g_print("\t   '1' Take a photo\n");
853                                         g_print("\t   '2' Start Recording\n");
854                                         g_print("\t   '3' Setting\n");
855                                         g_print("\t   '4' Print FPS\n");
856                                         g_print("\t   'b' back\n");
857                                 } else if(mmcamcorder_print_state == MM_CAMCORDER_STATE_RECORDING) {
858                                         g_print("\t   'p' Pause Recording\n");
859                                         g_print("\t   'c' Cancel\n");
860                                         g_print("\t   's' Save\n");
861                                         g_print("\t   'n' Capture video snapshot\n");
862                                 } else if(mmcamcorder_print_state == MM_CAMCORDER_STATE_PAUSED) {
863                                         g_print("\t   'r' Resume Recording\n");
864                                         g_print("\t   'c' Cancel\n");
865                                         g_print("\t   's' Save\n");
866                                         g_print("\t   'n' Capture video snapshot\n");
867                                 }
868                                 g_print("\t=======================================\n");
869                         } else if (hcamcorder->mode == MODE_AUDIO) {
870                                 g_print("\n\t=======================================\n");
871                                 g_print("\t   Audio Recording\n");
872                                 g_print("\t=======================================\n");
873                                 if(mmcamcorder_print_state <= MM_CAMCORDER_STATE_PREPARE) {
874                                         g_print("\t   '1' Start Recording\n");
875                                         g_print("\t   'b' back\n");
876                                 }
877                                 else if(mmcamcorder_print_state == MM_CAMCORDER_STATE_RECORDING) {
878                                 g_print("\t   'p' Pause Recording\n");
879                                 g_print("\t   'c' Cancel\n");
880                                 g_print("\t   's' Save\n");
881                                 }
882                                 else if(mmcamcorder_print_state == MM_CAMCORDER_STATE_PAUSED) {
883                                         g_print("\t   'r' Resume Recording\n");
884                                         g_print("\t   'c' Cancel\n");
885                                         g_print("\t   's' Save\n");
886                                 }
887                                 g_print("\t=======================================\n");
888                         }
889                         break;
890
891                 case MENU_STATE_SETTING:
892                         g_print("\n\t=======================================\n");
893                         g_print("\t   Video Capture > Setting\n");
894                         g_print("\t=======================================\n");
895                         g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Camera]  \n");
896                         g_print("\t     '0' Preview resolution \n");
897                         g_print("\t     '1' Capture resolution \n");
898                         g_print("\t     '2' Digital zoom level \n");
899                         g_print("\t     '3' Optical zoom level \n");
900                         g_print("\t     '4' AF mode \n");
901                         g_print("\t     '5' AF scan range \n");
902                         g_print("\t     '6' Exposure mode \n");
903                         g_print("\t     '7' Exposure value \n");
904                         g_print("\t     '8' F number \n");
905                         g_print("\t     '9' Shutter speed \n");
906                         g_print("\t     'i' ISO \n");
907                         g_print("\t     'r' Rotate camera input \n");
908                         g_print("\t     'f' Flip camera input \n");
909                         g_print("\t     'j' Jpeg quality \n");
910                         g_print("\t     'p' Picture format \n");
911                         g_print("\t     'E' EXIF orientation \n");
912                         g_print("\t  >>>>>>>>>>>>>>>>>>>> [Display/Filter]\n");
913                         g_print("\t     'v' Visible \n");
914                         g_print("\t     'n' Display mode \n");
915                         g_print("\t     'o' Output mode \n");
916                         g_print("\t     'y' Rotate display \n");
917                         g_print("\t     'Y' Flip display \n");
918                         g_print("\t     'g' Brightness \n");
919                         g_print("\t     'c' Contrast \n");
920                         g_print("\t     's' Saturation \n");
921                         g_print("\t     'h' Hue \n");
922                         g_print("\t     'a' Sharpness \n");
923                         g_print("\t     'w' White balance \n");
924                         g_print("\t     't' Color tone \n");
925                         g_print("\t     'd' WDR \n");
926                         g_print("\t     'e' EV program mode \n");
927                         g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> [etc.]\n");
928                         g_print("\t     'z' Strobe (Flash) \n");
929                         g_print("\t     'x' Capture mode (Still/Multishot/HDR)\n");
930                         g_print("\t     'l' Face detection \n");
931                         g_print("\t     'k' Anti-handshake \n");
932                         g_print("\t     'K' Video-stabilization \n");
933                         g_print("\t     'u' Touch AF area \n");
934                         g_print("\t     'm' Stream callback function \n");
935                         g_print("\t     'M' Camcorder Motion Rate setting \n");
936                         g_print("\t     'b' back\n");
937                         g_print("\t=======================================\n");
938                         break;
939
940                 default:
941                         warn_msg_t("unknow menu state !!\n");
942                         break;
943         }
944
945         return;
946 }
947
948 static void main_menu(gchar buf)
949 {
950         int err = 0;
951         int current_fps = 0;
952         int average_fps = 0;
953         char *err_attr_name = NULL;
954
955         if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
956                 if (mmcamcorder_state == MM_CAMCORDER_STATE_PREPARE) {
957                         switch (buf) {
958                                 case '1' : //Capture
959                                         if(hcamcorder->isMultishot) {
960                                                 int interval = 0;
961                                                 flush_stdin();
962                                                 printf("\ninput interval(ms) \n");
963                                                 err = scanf("%d", &interval);
964                                                 if (err == EOF) {
965                                                         printf("\nscanf error : errno %d\n", errno);
966                                                         interval = 300;
967                                                 }
968                                                 err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
969                                                                                   MMCAM_CAPTURE_INTERVAL, interval,
970                                                                                   NULL);
971                                                 if (err != MM_ERROR_NONE) {
972                                                         err_msg_t("Attribute setting fail : (%s:%x)", err_attr_name, err);
973                                                         SAFE_FREE (err_attr_name);
974                                                 }
975                                         } else {
976                                                 err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
977                                                                                   MMCAM_CAPTURE_COUNT, IMAGE_CAPTURE_COUNT_STILL,
978                                                                                   NULL);
979                                                 if (err != MM_ERROR_NONE) {
980                                                         err_msg_t("Attribute setting fail : (%s:%x)", err_attr_name, err);
981                                                         SAFE_FREE (err_attr_name);
982                                                 }
983                                         }
984
985                                         g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, (GSourceFunc)test_idle_capture_start, NULL, NULL);
986                                         break;
987
988                                 case '2' : // Start Recording
989                                         g_print("*Recording start!\n");
990                                         video_stream_cb_cnt = 0;
991                                         audio_stream_cb_cnt = 0;
992
993                                         g_timer_reset(timer);
994                                         err = mm_camcorder_record(hcamcorder->camcorder);
995
996                                         if (err != MM_ERROR_NONE) {
997                                                 warn_msg_t("Rec start mm_camcorder_record 0x%x", err);
998                                         }
999
1000                                         mmcamcorder_print_state = MM_CAMCORDER_STATE_RECORDING;
1001                                         break;
1002
1003                                 case '3' : // Setting
1004                                         hcamcorder->menu_state = MENU_STATE_SETTING;
1005                                         break;
1006
1007                                 case '4' : // Print frame rate
1008                                         current_fps = _mmcamcorder_video_current_framerate(hcamcorder->camcorder);
1009                                         average_fps = _mmcamcorder_video_average_framerate(hcamcorder->camcorder);
1010                                         g_print("\tVideo Frame Rate[Current : %d.0 fps, Average : %d.0 fps]\n", current_fps, average_fps);
1011                                         break;
1012
1013                                 case 'b' : // back
1014                                         hcamcorder->menu_state = MENU_STATE_MAIN;
1015                                         mode_change();
1016                                         break;
1017
1018                                 default:
1019                                         g_print("\t Invalid input \n");
1020                                         break;
1021                         }
1022                 } else if (mmcamcorder_state == MM_CAMCORDER_STATE_RECORDING || mmcamcorder_state == MM_CAMCORDER_STATE_PAUSED) {
1023                         switch (buf) {
1024                                 if (mmcamcorder_state == MM_CAMCORDER_STATE_RECORDING) {
1025                                         case 'p'  : // Pause Recording
1026                                                 g_print("*Pause!\n");
1027                                                 err = mm_camcorder_pause(hcamcorder->camcorder);
1028
1029                                                 if (err < 0) {
1030                                                         warn_msg_t("Rec pause mm_camcorder_pause  = %x", err);
1031                                                 }
1032                                                 mmcamcorder_print_state = MM_CAMCORDER_STATE_PAUSED;
1033                                                 break;
1034
1035                                 } else {
1036                                         case 'r'  : // Resume Recording
1037                                                 g_print("*Resume!\n");
1038                                                 err = mm_camcorder_record(hcamcorder->camcorder);
1039                                                 if (err < 0) {
1040                                                         warn_msg_t("Rec start mm_camcorder_record  = %x", err);
1041                                                 }
1042                                                 mmcamcorder_print_state = MM_CAMCORDER_STATE_RECORDING;
1043                                                 break;
1044                                 }
1045
1046                                 case 'c' : // Cancel
1047                                         g_print("*Cancel Recording !\n");
1048
1049                                         err = mm_camcorder_cancel(hcamcorder->camcorder);
1050
1051                                         if (err < 0) {
1052                                                 warn_msg_t("Cancel recording mm_camcorder_cancel  = %x", err);
1053                                         }
1054                                         mmcamcorder_print_state = MM_CAMCORDER_STATE_PREPARE;
1055                                         break;
1056
1057                                 case 's' : // Save
1058                                         g_print("*Save Recording!\n");
1059                                         g_timer_reset(timer);
1060
1061                                         err = mm_camcorder_commit(hcamcorder->camcorder);
1062
1063                                         if (err < 0) {
1064                                                 warn_msg_t("Save recording mm_camcorder_commit  = %x", err);
1065                                         }
1066                                         mmcamcorder_print_state = MM_CAMCORDER_STATE_PREPARE;
1067                                         break;
1068
1069                                 case 'n' : /* Capture video snapshot */
1070                                         err = mm_camcorder_capture_start(hcamcorder->camcorder);
1071                                         break;
1072
1073                                 default :
1074                                         g_print("\t Invalid input \n");
1075                                         break;
1076                         } //switch
1077                 } else {
1078                         err_msg_t("Wrong camcorder state, check status!!");
1079                 }
1080         } else if (hcamcorder->mode == MODE_AUDIO) {
1081                 if (mmcamcorder_state == MM_CAMCORDER_STATE_PREPARE) {
1082                         switch(buf) {
1083                                 case '1' : //  Start Recording
1084                                         g_print("*Recording start!\n");
1085                                         g_timer_reset(timer);
1086                                         err = mm_camcorder_record(hcamcorder->camcorder);
1087
1088                                         if (err < 0) {
1089                                                 warn_msg_t("Rec start mm_camcorder_record  = %x", err);
1090                                         }
1091                                         mmcamcorder_print_state = MM_CAMCORDER_STATE_RECORDING;
1092                                         break;
1093
1094                                 case 'b' : // back
1095                                                 hcamcorder->menu_state = MENU_STATE_MAIN;
1096                                                 mode_change();
1097                                                 break;
1098
1099                                 default :
1100                                         g_print("\t Invalid input \n");
1101                                         break;
1102                         }
1103                 } else if (mmcamcorder_state == MM_CAMCORDER_STATE_RECORDING || mmcamcorder_state == MM_CAMCORDER_STATE_PAUSED) {
1104                         switch(buf) {
1105                                 if (mmcamcorder_state == MM_CAMCORDER_STATE_RECORDING) {
1106                                         case 'p' : // Pause Recording
1107                                                 g_print("*Pause!\n");
1108                                                 err = mm_camcorder_pause(hcamcorder->camcorder);
1109
1110                                                 if (err < 0)    {
1111                                                         warn_msg_t("Rec pause mm_camcorder_pause  = %x", err);
1112                                                 }
1113                                                 mmcamcorder_print_state = MM_CAMCORDER_STATE_PAUSED;
1114                                                 break;
1115                                 } else {
1116                                         case 'r'  : // Resume Recording
1117                                                 g_print("*Resume!\n");
1118                                                 err = mm_camcorder_record(hcamcorder->camcorder);
1119                                                 if (err < 0) {
1120                                                         warn_msg_t("Rec start mm_camcorder_record  = %x", err);
1121                                                 }
1122                                                 mmcamcorder_print_state = MM_CAMCORDER_STATE_RECORDING;
1123                                                 break;
1124                                 }
1125
1126                                 case 'c' : // Cancel
1127                                         g_print("*Cancel Recording !\n");
1128                                         err = mm_camcorder_cancel(hcamcorder->camcorder);
1129
1130                                         if (err < 0)    {
1131                                                 warn_msg_t("Cancel recording mm_camcorder_cancel  = %x", err);
1132                                         }
1133                                         mmcamcorder_print_state = MM_CAMCORDER_STATE_PREPARE;
1134                                         break;
1135
1136                                 case 's' : //  Save
1137                                         g_print("*Save Recording!\n");
1138                                         g_timer_reset(timer);
1139                                         err = mm_camcorder_commit(hcamcorder->camcorder);
1140
1141                                         if (err < 0)    {
1142                                                 warn_msg_t("Save recording mm_camcorder_commit  = %x", err);
1143                                         }
1144                                         mmcamcorder_print_state = MM_CAMCORDER_STATE_PREPARE;
1145                                         break;
1146
1147                                 default :
1148                                         g_print("\t Invalid input \n");
1149                                         break;
1150                         }
1151                 } else {
1152                         err_msg_t("Wrong camcorder state, check status!!");
1153                 }
1154         }
1155         else {
1156                 g_print("\t Invalid mode, back to upper menu \n");
1157                 hcamcorder->menu_state = MENU_STATE_MAIN;
1158                 mode_change();
1159         }
1160 }
1161
1162
1163 static void setting_menu(gchar buf)
1164 {
1165         gboolean bret = FALSE;
1166         int idx = 0;
1167         int min = 0;
1168         int max = 0;
1169         int width_count = 0;
1170         int height_count = 0;
1171         int i=0;
1172         int count = 0;
1173         int value = 0;
1174         int* array = NULL;
1175         int *width_array = NULL;
1176         int *height_array = NULL;
1177         char *err_attr_name = NULL;
1178         cam_xypair_t input_pair;
1179         int err = MM_ERROR_NONE;
1180         int x = 0, y = 0, width = 0, height = 0;
1181         gint error_num=0;
1182
1183         if (hcamcorder->mode == MODE_VIDEO_CAPTURE) {
1184                 switch (buf) {
1185                         /* Camera setting */
1186                         case '0':  // Setting > Preview Resolution setting
1187                                 g_print("*Select the preview resolution!\n");
1188                                 camcordertest_get_attr_valid_intarray(MMCAM_CAMERA_WIDTH, &width_array, &width_count);
1189                                 camcordertest_get_attr_valid_intarray(MMCAM_CAMERA_HEIGHT, &height_array, &height_count);
1190
1191                                 if(width_count != height_count) {
1192                                         err_msg_t("System has wrong information!!\n");
1193                                 } else if (width_count == 0) {
1194                                         g_print("Not supported!!\n");
1195                                 } else {
1196                                         flush_stdin();
1197
1198                                         for ( i = 0; i < width_count; i++) {
1199                                                 g_print("\t %d. %d*%d\n", i+1, width_array[i], height_array[i]);
1200                                         }
1201                                         err = scanf("%d",&idx);
1202                                         if (err == EOF) {
1203                                                 printf("\nscanf error : errno %d\n", errno);
1204                                         } else {
1205                                                 if( idx > 0 && idx <= width_count ) {
1206                                                         //Set capture size first
1207                                                         input_pair.attr_subcat_x = MMCAM_CAMERA_WIDTH;
1208                                                         input_pair.attr_subcat_y = MMCAM_CAMERA_HEIGHT;
1209                                                         input_pair.x = width_array[idx-1];
1210                                                         input_pair.y = height_array[idx-1];
1211                                                         bret = camcordertest_set_attr_xypair(input_pair);
1212                                                 }
1213                                         }
1214                                 }
1215                                 break;
1216                         case '1' : // Setting > Capture Resolution setting
1217                                 /* check recommend preview resolution */
1218                                 camcordertest_get_attr_valid_intarray(MMCAM_RECOMMEND_CAMERA_WIDTH, &width_array, &width_count);
1219                                 camcordertest_get_attr_valid_intarray(MMCAM_RECOMMEND_CAMERA_HEIGHT, &height_array, &height_count);
1220                                 if(width_count != height_count) {
1221                                         err_msg_t("System has wrong information!!\n");
1222                                 } else if (width_count == 0) {
1223                                         g_print("MMCAM_RECOMMEND_CAMERA_WIDTH/HEIGHT Not supported!!\n");
1224                                 } else {
1225                                         g_print("\n - MMCAM_RECOMMEND_CAMERA_WIDTH and HEIGHT (count %d) -\n", width_count);
1226                                         g_print("\t NORMAL ratio : %dx%d\n",
1227                                                 width_array[MM_CAMCORDER_PREVIEW_TYPE_NORMAL], height_array[MM_CAMCORDER_PREVIEW_TYPE_NORMAL]);
1228                                         if (width_count >= 2) {
1229                                                 g_print("\t WIDE ratio   : %dx%d\n\n",
1230                                                         width_array[MM_CAMCORDER_PREVIEW_TYPE_WIDE], height_array[MM_CAMCORDER_PREVIEW_TYPE_WIDE]);
1231                                         } else {
1232                                                 g_print("\t There is ONLY NORMAL resolution\n\n");
1233                                         }
1234                                 }
1235
1236                                 g_print("*Select the resolution!\n");
1237                                 camcordertest_get_attr_valid_intarray("capture-width", &width_array, &width_count);
1238                                 camcordertest_get_attr_valid_intarray("capture-height", &height_array, &height_count);
1239
1240                                 if(width_count != height_count) {
1241                                         err_msg_t("System has wrong information!!\n");
1242                                 } else if (width_count == 0) {
1243                                         g_print("Not supported!!\n");
1244                                 } else {
1245                                         g_print("\n Select  resolution \n");
1246                                         flush_stdin();
1247
1248                                         for ( i = 0; i < width_count; i++) {
1249                                                 g_print("\t %d. %d*%d\n", i+1, width_array[i], height_array[i]);
1250                                         }
1251                                         err = scanf("%d",&idx);
1252                                         if (err == EOF) {
1253                                                 printf("\nscanf error : errno %d\n", errno);
1254                                         } else {
1255                                                 if( idx > 0 && idx <= width_count ) {
1256                                                         //Set capture size first
1257                                                         input_pair.attr_subcat_x = "capture-width";
1258                                                         input_pair.attr_subcat_y = "capture-height";
1259                                                         input_pair.x = width_array[idx-1];
1260                                                         input_pair.y = height_array[idx-1];
1261                                                         bret = camcordertest_set_attr_xypair(input_pair);
1262                                                 }
1263                                         }
1264                                 }
1265                                 break;
1266
1267                         case '2' : // Setting > Digital zoom level
1268                                 g_print("*Digital zoom level  !\n");
1269                                 camcordertest_get_attr_valid_intrange("camera-digital-zoom", &min, &max);
1270
1271                                 if(min >= max) {
1272                                         g_print("Not supported !! \n");
1273                                 } else {
1274                                         flush_stdin();
1275                                         g_print("\n Select  Digital zoom level (%d ~ %d)\n", min, max);
1276                                         err = scanf("%d",&idx);
1277                                         bret = camcordertest_set_attr_int("camera-digital-zoom", idx);
1278                                 }
1279                                 break;
1280
1281                         case '3' : // Setting > Optical zoom level
1282                                 g_print("*Optical zoom level  !\n");
1283                                 camcordertest_get_attr_valid_intrange("camera-optical-zoom", &min, &max);
1284
1285                                 if(min >= max) {
1286                                         g_print("Not supported !! \n");
1287                                 } else {
1288                                         flush_stdin();
1289                                         g_print("\n Select  Optical zoom level (%d ~ %d)\n", min, max);
1290                                         err = scanf("%d",&idx);
1291                                         bret = camcordertest_set_attr_int("camera-optical-zoom", idx);
1292                                 }
1293                                 break;
1294
1295                         case '4' : // Setting > AF mode
1296                                 g_print("\t0. AF Mode setting !\n");
1297                                 g_print("\t1. AF Start !\n");
1298                                 g_print("\t2. AF Stop !\n\n");
1299
1300                                 flush_stdin();
1301                                 err = scanf("%d", &idx);
1302
1303                                 switch (idx) {
1304                                 case 0:
1305                                 {
1306                                         g_print("*Focus mode !\n");
1307                                         camcordertest_get_attr_valid_intarray("camera-focus-mode", &array, &count);
1308
1309                                         if(count <= 0) {
1310                                                 g_print("Not supported !! \n");
1311                                         } else {
1312                                                 g_print("\n Select Focus mode \n");
1313                                                 flush_stdin();
1314                                                 for (i = 0 ; i < count ; i++) {
1315                                                         g_print("\t %d. %s\n", array[i], focus_mode[array[i]]);
1316                                                 }
1317                                                 err = scanf("%d",&idx);
1318                                                 bret = camcordertest_set_attr_int("camera-focus-mode", idx);
1319                                         }
1320                                 }
1321                                         break;
1322                                 case 1:
1323                                         mm_camcorder_start_focusing(hcamcorder->camcorder);
1324                                         break;
1325                                 case 2:
1326                                         mm_camcorder_stop_focusing(hcamcorder->camcorder);
1327                                         break;
1328                                 default:
1329                                         g_print("Wrong Input[%d] !! \n", idx);
1330                                         break;
1331                                 }
1332                                 break;
1333
1334                         case '5' : // Setting > AF scan range
1335                                 g_print("*AF scan range !\n");
1336                                 camcordertest_get_attr_valid_intarray("camera-af-scan-range", &array, &count);
1337
1338                                 if(count <= 0) {
1339                                         g_print("Not supported !! \n");
1340                                 } else {
1341                                         g_print("\n Select AF scan range \n");
1342                                         flush_stdin();
1343                                         for ( i = 0; i < count; i++) {
1344                                                 g_print("\t %d. %s\n", array[i], af_scan[array[i]]);
1345                                         }
1346                                         err = scanf("%d",&idx);
1347                                         camcordertest_set_attr_int("camera-af-scan-range", idx);
1348                                 }
1349                                 break;
1350
1351                         case '6' : // Setting > Exposure mode
1352                                 g_print("* Exposure mode!\n");
1353                                 camcordertest_get_attr_valid_intarray("camera-exposure-mode", &array, &count);
1354
1355                                 if(count <= 0) {
1356                                         g_print("Not supported !! \n");
1357                                 } else {
1358                                         g_print("\n Select  Exposure mode \n");
1359                                         flush_stdin();
1360                                         for ( i = 0; i < count; i++) {
1361                                                 g_print("\t %d. %s\n", array[i], exposure_mode[array[i]]);
1362                                         }
1363                                         err = scanf("%d",&idx);
1364                                         bret = camcordertest_set_attr_int("camera-exposure-mode", idx);
1365                                 }
1366                                 break;
1367
1368                         case '7' :  // Setting > Exposure value
1369                                 g_print("*Exposure value  !\n");
1370                                 camcordertest_get_attr_valid_intrange("camera-exposure-value", &min, &max);
1371
1372                                 if(min >= max) {
1373                                         g_print("Not supported !! \n");
1374                                 } else {
1375                                         flush_stdin();
1376                                         g_print("\n Select  Exposure value(%d ~ %d)\n", min, max);
1377                                         err = scanf("%d",&idx);
1378                                         bret = camcordertest_set_attr_int("camera-exposure-value", idx);
1379                                 }
1380                                 break;
1381
1382                         case '8' : // Setting > F number
1383                                 g_print("Not supported !! \n");
1384                                 break;
1385
1386                         case '9' : // Setting > Shutter speed
1387                                 g_print("*Shutter speed !\n");
1388                                 camcordertest_get_attr_valid_intarray("camera-shutter-speed", &array, &count);
1389
1390                                 if(count <= 0) {
1391                                         g_print("Not supported !! \n");
1392                                 } else {
1393                                         g_print("\n Select Shutter speed \n");
1394                                         flush_stdin();
1395                                         for ( i = 0; i < count; i++) {
1396                                                 g_print("\t %d. %d \n", i+1, array[i]);
1397                                         }
1398                                         err = scanf("%d",&idx);
1399
1400                                         if( idx > 0 && idx <= count ) {
1401                                                 bret = camcordertest_set_attr_int("camera-shutter-speed", array[idx-1]);
1402                                         }
1403                                 }
1404                                 break;
1405
1406                         case 'i' : // Setting > ISO
1407                                 g_print("*ISO !\n");
1408                                 camcordertest_get_attr_valid_intarray("camera-iso", &array, &count);
1409
1410                                 if(count <= 0) {
1411                                         g_print("Not supported !! \n");
1412                                 } else {
1413                                         g_print("\n Select ISO \n");
1414                                         flush_stdin();
1415                                         for ( i = 0; i < count; i++) {
1416                                                 g_print("\t %d. %s\n", array[i], iso_name[array[i]]);
1417                                         }
1418                                         err = scanf("%d",&idx);
1419                                         bret = camcordertest_set_attr_int("camera-iso", idx);
1420                                 }
1421                                 break;
1422
1423                         case 'r' : // Setting > Rotate camera input when recording
1424                                 g_print("*Rotate camera input\n");
1425                                 camcordertest_get_attr_valid_intrange(MMCAM_CAMERA_ROTATION, &min, &max);
1426
1427                                 if(min >= max) {
1428                                         g_print("Not supported !! \n");
1429                                 } else {
1430                                         flush_stdin();
1431                                         for (i = min ; i <= max ; i++) {
1432                                                 g_print("\t %d. %s\n", i, camera_rotation[i]);
1433                                         }
1434                                         err = scanf("%d",&idx);
1435                                         CHECK_MM_ERROR(mm_camcorder_stop(hcamcorder->camcorder));
1436                                         bret = camcordertest_set_attr_int(MMCAM_CAMERA_ROTATION, idx);
1437                                         CHECK_MM_ERROR(mm_camcorder_start(hcamcorder->camcorder));
1438                                 }
1439                                 break;
1440
1441                         case 'f' : // Setting > Flip camera input
1442                                 flush_stdin();
1443                                 g_print("*Flip camera input\n");
1444                                 g_print(" 0. Flip NONE\n");
1445                                 g_print(" 1. Flip HORIZONTAL\n");
1446                                 g_print(" 2. Flip VERTICAL\n");
1447                                 g_print(" 3. Flip BOTH\n");
1448
1449                                 err = scanf("%d", &idx);
1450
1451                                 CHECK_MM_ERROR(mm_camcorder_stop(hcamcorder->camcorder));
1452                                 CHECK_MM_ERROR(mm_camcorder_unrealize(hcamcorder->camcorder));
1453
1454                                 camcordertest_set_attr_int(MMCAM_CAMERA_FLIP, idx);
1455
1456                                 CHECK_MM_ERROR(mm_camcorder_realize(hcamcorder->camcorder));
1457                                 CHECK_MM_ERROR(mm_camcorder_start(hcamcorder->camcorder));
1458                                 break;
1459
1460                         case 'j' : // Setting > Jpeg quality
1461                                 g_print("*Jpeg quality !\n");
1462                                 camcordertest_get_attr_valid_intrange("image-encoder-quality", &min, &max);
1463
1464                                 if(min >= max) {
1465                                         g_print("Not supported !! \n");
1466                                 } else {
1467                                         flush_stdin();
1468                                         g_print("\n Select  Jpeg quality (%d ~ %d)\n", min, max);
1469                                         err = scanf("%d",&idx);
1470                                         bret = camcordertest_set_attr_int("image-encoder-quality", idx);
1471                                 }
1472                                 break;
1473
1474                         case 'p' : // Setting > Picture format
1475                                 g_print("* Picture format!\n");
1476                                 camcordertest_get_attr_valid_intarray("camera-format", &array, &count);
1477
1478                                 if(count <= 0) {
1479                                         g_print("Not supported !! \n");
1480                                 } else {
1481                                         g_print("\n Select Picture format \n");
1482                                         flush_stdin();
1483                                         for ( i = 0; i < count; i++) {
1484                                                 g_print("\t %d. %s\n", array[i], image_fmt[array[i]]);
1485                                         }
1486                                         err = scanf("%d",&idx);
1487                                         bret = camcordertest_set_attr_int("camera-format", idx);
1488                                         CHECK_MM_ERROR(mm_camcorder_stop(hcamcorder->camcorder));
1489                                         CHECK_MM_ERROR(mm_camcorder_unrealize(hcamcorder->camcorder));
1490                                         CHECK_MM_ERROR(mm_camcorder_realize(hcamcorder->camcorder));
1491                                         CHECK_MM_ERROR(mm_camcorder_start(hcamcorder->camcorder));
1492                                 }
1493                                 break;
1494
1495                         case 'E' : // Setting > EXIF orientation
1496                                 g_print("* EXIF Orientation\n");
1497
1498                                 g_print("\t 1. TOP_LEFT\n");
1499                                 g_print("\t 2. TOP_RIGHT(flipped)\n");
1500                                 g_print("\t 3. BOTTOM_RIGHT\n");
1501                                 g_print("\t 4. BOTTOM_LEFT(flipped)\n");
1502                                 g_print("\t 5. LEFT_TOP(flipped)\n");
1503                                 g_print("\t 6. RIGHT_TOP\n");
1504                                 g_print("\t 7. RIGHT_BOTTOM(flipped)\n");
1505                                 g_print("\t 8. LEFT_BOTTOM\n");
1506
1507                                 flush_stdin();
1508                                 err = scanf("%d", &idx);
1509
1510                                 if (idx < 1 || idx > 8) {
1511                                         g_print("Wrong INPUT[%d]!! \n", idx);
1512                                 } else {
1513                                         camcordertest_set_attr_int(MMCAM_TAG_ORIENTATION, idx);
1514                                 }
1515
1516                                 break;
1517
1518                         /* Display / Filter setting */
1519                         case 'v' : // Display visible
1520                                 g_print("* Display visible setting !\n");
1521                                 camcordertest_get_attr_valid_intarray( "display-visible", &array, &count );
1522
1523                                 if( count < 1 ) {
1524                                         g_print("Not supported !! \n");
1525                                 } else {
1526                                         g_print("\n Select Display visible \n");
1527                                         flush_stdin();
1528                                         for ( i = 0; i < count; i++) {
1529                                                 g_print("\t %d. %s\n", array[i], visible_mode[array[i]]);
1530                                         }
1531                                         err = scanf("%d",&value);
1532                                         bret = camcordertest_set_attr_int( "display-visible", value );
1533                                 }
1534                                 break;
1535
1536                         case 'n' : //  Setting > Display mode
1537                                 g_print("* Display mode!\n");
1538                                 camcordertest_get_attr_valid_intarray(MMCAM_DISPLAY_MODE, &array, &count);
1539
1540                                 if (count <= 0 || count > 255) {
1541                                         g_print("Not supported !! \n");
1542                                 } else {
1543                                         flush_stdin();
1544                                         g_print("\n Select Display mode\n");
1545                                         for (i = 0 ; i < count ; i++) {
1546                                                 g_print("\t %d. %s\n", array[i], display_mode[array[i]]);
1547                                         }
1548                                         err = scanf("%d",&idx);
1549                                         bret = camcordertest_set_attr_int(MMCAM_DISPLAY_MODE, idx);
1550                                 }
1551                                 break;
1552
1553                         case 'o' : //  Setting > Output mode
1554                                 g_print("* Output mode!\n");
1555                                 camcordertest_get_attr_valid_intrange("display-geometry-method", &min, &max);
1556
1557                                 if( min > max ) {
1558                                         g_print("Not supported !! \n");
1559                                 } else {
1560                                         flush_stdin();
1561                                         g_print("\n Select Output mode(%d ~ %d)\n", min, max);
1562                                         for( i = min ; i <= max ; i++ ) {
1563                                                 g_print( "%d. %s\n", i, output_mode[i] );
1564                                         }
1565                                         err = scanf("%d",&idx);
1566                                         bret = camcordertest_set_attr_int("display-geometry-method", idx);
1567                                 }
1568                                 break;
1569
1570                         case 'y' : // Setting > Rotate Display
1571                                 camcordertest_get_attr_valid_intrange(MMCAM_DISPLAY_ROTATION, &min, &max);
1572
1573                                 if( min > max ) {
1574                                         g_print("Not supported !! \n");
1575                                 } else {
1576                                         flush_stdin();
1577                                         g_print("\n Select Rotate mode(%d ~ %d)\n", min, max);
1578                                         g_print("\t0. 0\n\t1. 90\n\t2. 180\n\t3. 270\n\n");
1579                                         err = scanf("%d",&idx);
1580                                         bret = camcordertest_set_attr_int(MMCAM_DISPLAY_ROTATION, idx);
1581                                 }
1582                                 break;
1583
1584                         case 'Y' : // Setting > Flip Display
1585                                 flush_stdin();
1586                                 g_print("\n Select Rotate mode(%d ~ %d)\n", min, max);
1587                                 g_print("\t0. NONE\n\t1. HORIZONTAL\n\t2. VERTICAL\n\t3. BOTH\n\n");
1588                                 err = scanf("%d",&idx);
1589                                 camcordertest_set_attr_int(MMCAM_DISPLAY_FLIP, idx);
1590                                 break;
1591
1592                         case 'g' : // Setting > Brightness
1593                                 g_print("*Brightness !\n");
1594                                 camcordertest_get_attr_valid_intrange("filter-brightness", &min, &max);
1595
1596                                 if(min >= max) {
1597                                         g_print("Not supported !! \n");
1598                                 } else {
1599                                         flush_stdin();
1600                                         g_print("\n Select  brightness (%d ~ %d)\n", min, max);
1601                                         err = scanf("%d",&idx);
1602                                         bret = camcordertest_set_attr_int("filter-brightness", idx);
1603                                 }
1604                                 break;
1605
1606                         case 'c' : // Setting > Contrast
1607                                 g_print("*Contrast !\n");
1608                                 camcordertest_get_attr_valid_intrange("filter-contrast", &min, &max);
1609
1610                                 if(min >= max) {
1611                                         g_print("Not supported !! \n");
1612                                 } else {
1613                                         flush_stdin();
1614                                         g_print("\n Select  Contrast (%d ~ %d)\n", min, max);
1615                                         err = scanf("%d",&idx);
1616                                         bret = camcordertest_set_attr_int("filter-contrast", idx);
1617                                 }
1618                                 break;
1619
1620                         case 's' : // Setting > Saturation
1621                                 g_print("*Saturation !\n");
1622                                 camcordertest_get_attr_valid_intrange("filter-saturation", &min, &max);
1623
1624                                 if(min >= max) {
1625                                         g_print("Not supported !! \n");
1626                                 } else {
1627                                         flush_stdin();
1628                                         g_print("\n Select  Saturation (%d ~ %d)\n", min, max);
1629                                         err = scanf("%d",&idx);
1630                                         bret = camcordertest_set_attr_int("filter-saturation", idx);
1631                                 }
1632                                 break;
1633
1634                         case 'h' : // Setting > Hue
1635                                 g_print("*Hue !\n");
1636                                 camcordertest_get_attr_valid_intrange("filter-hue", &min, &max);
1637
1638                                 if(min >= max) {
1639                                         g_print("Not supported !! \n");
1640                                 } else {
1641                                         flush_stdin();
1642                                         g_print("\n Select  Hue (%d ~ %d)\n", min, max);
1643                                         err = scanf("%d",&idx);
1644                                         bret = camcordertest_set_attr_int("filter-hue", idx);
1645                                 }
1646                                 break;
1647
1648                         case 'a' : // Setting > Sharpness
1649                                 g_print("*Sharpness !\n");
1650                                 camcordertest_get_attr_valid_intrange("filter-sharpness", &min, &max);
1651
1652                                 if(min >= max) {
1653                                         g_print("Not supported !! \n");
1654                                 } else {
1655                                         flush_stdin();
1656                                         g_print("\n Select  Sharpness (%d ~ %d)\n", min, max);
1657                                         err = scanf("%d",&idx);
1658                                         bret = camcordertest_set_attr_int("filter-sharpness", idx);
1659                                 }
1660                                 break;
1661
1662                         case 'w' : // Setting > White balance
1663                                 g_print("*White balance !\n");
1664                                 camcordertest_get_attr_valid_intarray("filter-wb", &array, &count);
1665
1666                                 if(count <= 0) {
1667                                         g_print("Not supported !! \n");
1668                                 } else {
1669                                         flush_stdin();
1670                                         g_print("\n Select White balance \n");
1671                                         for ( i = 0; i < count; i++) {
1672                                                 g_print("\t %d. %s\n", array[i], wb[array[i]]);
1673                                         }
1674                                         err = scanf("%d",&idx);
1675                                         bret = camcordertest_set_attr_int("filter-wb", idx);
1676                                 }
1677                                 break;
1678
1679                         case 't' : // Setting > Color tone
1680                                 g_print("*Color tone !\n");
1681                                 camcordertest_get_attr_valid_intarray("filter-color-tone", &array, &count);
1682
1683                                 if(count <= 0) {
1684                                         g_print("Not supported !! \n");
1685                                 } else {
1686                                         g_print("\n Select Color tone \n");
1687                                         flush_stdin();
1688                                         for ( i = 0; i < count; i++) {
1689                                                 g_print("\t %d. %s\n", array[i], ct[array[i]]);
1690                                         }
1691                                         err = scanf("%d",&idx);
1692                                         bret = camcordertest_set_attr_int("filter-color-tone", idx);
1693                                 }
1694                                 break;
1695
1696                         case 'd' : // Setting > WDR
1697                                 g_print("*WDR !\n");
1698                                 camcordertest_get_attr_valid_intarray("camera-wdr", &array, &count);
1699
1700                                 if(count <= 0) {
1701                                         g_print("Not supported !! \n");
1702                                 }
1703                                 else {
1704                                         g_print("\n Select WDR Mode \n");
1705                                         flush_stdin();
1706                                         for ( i = 0; i < count; i++) {
1707                                                 g_print("\t %d. %s\n", array[i], wdr_mode[array[i]]);
1708                                         }
1709                                         err = scanf("%d",&idx);
1710                                         bret = camcordertest_set_attr_int("camera-wdr", idx);
1711                                 }
1712                                 break;
1713
1714                         case 'e' : // Setting > EV program mode
1715                                 g_print("* EV program mode!\n");
1716                                 camcordertest_get_attr_valid_intarray("filter-scene-mode", &array, &count);
1717
1718                                 if(count <= 0) {
1719                                         g_print("Not supported !! \n");
1720                                 } else {
1721                                         g_print("\n Select EV program mode \n");
1722                                         flush_stdin();
1723                                         for ( i = 0; i < count; i++) {
1724                                                 g_print("\t %d. %s\n", array[i], program_mode[array[i]]);
1725                                         }
1726                                         err = scanf("%d",&idx);
1727                                         bret = camcordertest_set_attr_int("filter-scene-mode", idx);
1728                                 }
1729                                 break;
1730
1731                         /* ext. setting */
1732                         case 'z' : // Setting > Strobe setting
1733                                 g_print("*Strobe Mode\n");
1734                                 camcordertest_get_attr_valid_intarray("strobe-mode", &array, &count);
1735                                 if(count <= 0) {
1736                                         g_print("Not supported !! \n");
1737                                 } else {
1738                                         g_print("\n Select Strobe Mode \n");
1739                                         flush_stdin();
1740                                         for ( i = 0; i < count; i++) {
1741                                                 g_print("\t %d. %s\n", array[i], strobe_mode[array[i]]);
1742                                         }
1743                                         err = scanf("%d",&idx);
1744                                         bret = camcordertest_set_attr_int("strobe-mode", idx);
1745                                 }
1746                                 break;
1747
1748                         case 'x' : // Setting > Capture mode ,Muitishot?
1749                                 g_print("*Select Capture mode!\n");
1750                                 flush_stdin();
1751                                 g_print(" \n\t1. Stillshot mode\n\t2. Multishot mode\n\t3. HDR capture\n");
1752                                 err = scanf("%d",&idx);
1753
1754                                 switch (idx) {
1755                                 case 1:
1756                                         g_print("stillshot mode selected and capture callback is set!!!!\n");
1757                                         hcamcorder->isMultishot = FALSE;
1758                                         camcordertest_set_attr_int(MMCAM_CAMERA_HDR_CAPTURE, 0);
1759                                         break;
1760                                 case 2:
1761                                         g_print("Multilshot mode selected!!\n");
1762
1763                                         camcordertest_set_attr_int(MMCAM_CAMERA_HDR_CAPTURE, 0);
1764
1765                                         idx = 0;
1766                                         min = 0;
1767                                         max = 0;
1768
1769                                         camcordertest_get_attr_valid_intrange("capture-count", &min, &max);
1770                                         if(min >= max) {
1771                                                 g_print("Not supported !! \n");
1772                                         } else {
1773                                                 flush_stdin();
1774                                                 //g_print("\n Check Point!!! [Change resolution to 800x480]\n");
1775                                                 g_print("Select  mulitshot number (%d ~ %d)\n", min, max);
1776                                                 err = scanf("%d",&idx);
1777                                                 if( idx >= min && idx <= max ) {
1778                                                         multishot_num = idx;
1779                                                         mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
1780                                                                                     MMCAM_CAPTURE_COUNT, multishot_num,
1781                                                                                     NULL);
1782                                                         hcamcorder->isMultishot = TRUE;
1783                                                 } else {
1784                                                         g_print("Wrong input value, Multishot setting failed!!\n");
1785                                                 }
1786                                         }
1787                                         break;
1788                                 case 3:
1789                                         g_print("HDR Capture mode selected\n");
1790                                         hcamcorder->isMultishot = FALSE;
1791
1792                                         camcordertest_get_attr_valid_intarray(MMCAM_CAMERA_HDR_CAPTURE, &array, &count);
1793                                         if(count <= 0) {
1794                                                 g_print("Not supported !! \n");
1795                                         } else {
1796                                                 g_print("\nSelect HDR capture mode\n");
1797                                                 flush_stdin();
1798                                                 for ( i = 0; i < count; i++) {
1799                                                         g_print("\t %d. %s\n", array[i], hdr_mode[array[i]]);
1800                                                 }
1801                                                 err = scanf("%d",&idx);
1802                                                 bret = camcordertest_set_attr_int(MMCAM_CAMERA_HDR_CAPTURE, idx);
1803                                         }
1804                                         break;
1805                                 default:
1806                                         g_print("Wrong input, select again!!\n");
1807                                         break;
1808                                 }
1809                                 break;
1810
1811                         case 'l' : // Setting > Face detection setting
1812                                 //hcamcorder->menu_state = MENU_STATE_SETTING_DETECTION;
1813                                 g_print("* Face detect mode !\n");
1814
1815                                 camcordertest_get_attr_valid_intarray("detect-mode", &array, &count);
1816                                 if(count <= 0 || count > 256) {
1817                                         g_print("Not supported !! \n");
1818                                 } else {
1819                                         g_print("\n Face detect mode  \n");
1820                                         flush_stdin();
1821                                         for ( i = 0; i < count; i++) {
1822                                                 g_print("\t %d. %s \n", array[i], detection_mode[array[i]]);
1823                                         }
1824                                         err = scanf("%d",&idx);
1825
1826                                         if( idx >= 0 && idx < count ) {
1827                                                 bret = camcordertest_set_attr_int("detect-mode", array[idx]);
1828                                         } else {
1829                                                 g_print("Wrong input value. Try again!!\n");
1830                                                 bret = FALSE;
1831                                         }
1832                                 }
1833                                 break;
1834
1835                         case 'k' : // Setting > Anti-handshake
1836                                 g_print("*Anti-handshake !\n");
1837                                 camcordertest_get_attr_valid_intarray(MMCAM_CAMERA_ANTI_HANDSHAKE, &array, &count);
1838
1839                                 if(count <= 0) {
1840                                         g_print("Not supported !! \n");
1841                                 } else {
1842                                         g_print("\n Select Anti-handshake mode \n");
1843                                         flush_stdin();
1844                                         for ( i = 0; i < count; i++) {
1845                                                 g_print("\t %d. %s\n", array[i], ahs_mode[array[i]]);
1846                                         }
1847                                         err = scanf("%d",&idx);
1848                                         bret = camcordertest_set_attr_int(MMCAM_CAMERA_ANTI_HANDSHAKE, idx);
1849                                 }
1850                                 break;
1851
1852                         case 'K' : // Setting > Video-stabilization
1853                                 g_print("*Video-stabilization !\n");
1854                                 camcordertest_get_attr_valid_intarray(MMCAM_CAMERA_VIDEO_STABILIZATION, &array, &count);
1855
1856                                 if(count <= 0) {
1857                                         g_print("Not supported !! \n");
1858                                 } else {
1859                                         g_print("\n Select Video-stabilization mode \n");
1860                                         flush_stdin();
1861                                         for ( i = 0; i < count; i++) {
1862                                                 g_print("\t %d. %s\n", array[i], vs_mode[array[i]]);
1863                                         }
1864                                         err = scanf("%d",&idx);
1865
1866                                         if (idx == MM_CAMCORDER_VIDEO_STABILIZATION_ON) {
1867                                                 g_print("\n Restart preview with NV12 and 720p resolution\n");
1868
1869                                                 err = mm_camcorder_stop(hcamcorder->camcorder);
1870                                                 if (err == MM_ERROR_NONE) {
1871                                                         err = mm_camcorder_unrealize(hcamcorder->camcorder);
1872                                                 }
1873
1874                                                 input_pair.attr_subcat_x = MMCAM_CAMERA_WIDTH;
1875                                                 input_pair.attr_subcat_y = MMCAM_CAMERA_HEIGHT;
1876                                                 input_pair.x = 1280;
1877                                                 input_pair.y = 720;
1878                                                 camcordertest_set_attr_xypair(input_pair);
1879                                                 camcordertest_set_attr_int(MMCAM_CAMERA_FORMAT, MM_PIXEL_FORMAT_NV12);
1880                                                 camcordertest_set_attr_int(MMCAM_CAMERA_VIDEO_STABILIZATION, idx);
1881
1882                                                 if (err == MM_ERROR_NONE) {
1883                                                         err = mm_camcorder_realize(hcamcorder->camcorder);
1884                                                         if (err == MM_ERROR_NONE) {
1885                                                                 err = mm_camcorder_start(hcamcorder->camcorder);
1886                                                         }
1887                                                 }
1888
1889                                                 if (err != MM_ERROR_NONE) {
1890                                                         g_print("\n Restart FAILED! %x\n", err);
1891                                                 }
1892                                         } else {
1893                                                 camcordertest_set_attr_int(MMCAM_CAMERA_VIDEO_STABILIZATION, idx);
1894                                         }
1895                                 }
1896                                 break;
1897
1898                         case 'u': // Touch AF area
1899                                 g_print("* Touch AF area !\n");
1900                                 camcordertest_get_attr_valid_intrange("camera-af-touch-x", &min, &max);
1901                                 if( max < min ) {
1902                                         g_print( "Not Supported camera-af-touch-x !!\n" );
1903                                         break;
1904                                 }
1905                                 camcordertest_get_attr_valid_intrange("camera-af-touch-y", &min, &max);
1906                                 if( max < min ) {
1907                                         g_print( "Not Supported camera-af-touch-y !!\n" );
1908                                         break;
1909                                 }
1910                                 camcordertest_get_attr_valid_intrange("camera-af-touch-width", &min, &max);
1911                                 if( max < min ) {
1912                                         g_print( "Not Supported camera-af-touch-width !!\n" );
1913                                         break;
1914                                 }
1915                                 camcordertest_get_attr_valid_intrange("camera-af-touch-height", &min, &max);
1916                                 if( max < min ) {
1917                                         g_print( "Not Supported camera-af-touch-height!!\n" );
1918                                         break;
1919                                 }
1920
1921                                 flush_stdin();
1922                                 g_print( "\n Input x,y,width,height \n" );
1923                                 err = scanf( "%d,%d,%d,%d", &x, &y, &width, &height );
1924                                 err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
1925                                                                                                 MMCAM_CAMERA_AF_TOUCH_X, x,
1926                                                                                                 MMCAM_CAMERA_AF_TOUCH_Y, y,
1927                                                                                                 MMCAM_CAMERA_AF_TOUCH_WIDTH, width,
1928                                                                                                 MMCAM_CAMERA_AF_TOUCH_HEIGHT, height,
1929                                                                                                 NULL);
1930
1931                                 if( err != MM_ERROR_NONE ) {
1932                                         g_print( "Failed to set touch AF area.(%x)(%s)\n", err, err_attr_name );
1933                                         free( err_attr_name );
1934                                         err_attr_name = NULL;
1935                                 } else {
1936                                         g_print( "Succeed to set touch AF area.\n" );
1937                                 }
1938                                 break;
1939
1940                         case 'm' : // Setting > Stream callback function
1941                                 g_print("\n Select Stream Callback Function\n");
1942                                 g_print("\t 1. Set Video Stream Callback \n");
1943                                 g_print("\t 2. Unset Video Stream Callback \n");
1944                                 flush_stdin();
1945                                 err = scanf("%d", &idx);
1946                                 if(idx == 1) {
1947                                         video_stream_cb_cnt = 0;
1948                                         error_num = mm_camcorder_set_video_stream_callback(hcamcorder->camcorder, (mm_camcorder_video_stream_callback)camcordertest_video_stream_cb, (void*)hcamcorder->camcorder);
1949                                         if( error_num == MM_ERROR_NONE ) {
1950                                                 g_print("\n Setting Success\n");
1951                                         } else {
1952                                                 g_print("\n Setting Failure\n");
1953                                         }
1954                                 } else if(idx == 2) {
1955                                         mm_camcorder_set_video_stream_callback(hcamcorder->camcorder, NULL, (void*)hcamcorder->camcorder);
1956                                         video_stream_cb_cnt = 0;
1957                                         audio_stream_cb_cnt = 0;
1958                                         g_print("\n Unset stream callback success\n");
1959                                 } else {
1960                                         g_print("\t Invalid input \n");
1961                                 }
1962                                 break;
1963
1964                         case 'M':
1965                         {
1966                                 float motion_rate = 0.0;
1967
1968                                 flush_stdin();
1969
1970                                 g_print("*Camcorder Motion Rate setting! (should be bigger than zero)\n");
1971
1972                                 err = scanf("%f", &motion_rate);
1973                                 err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
1974                                                                   MMCAM_CAMERA_RECORDING_MOTION_RATE, motion_rate,
1975                                                                   NULL);
1976                                 if (err != MM_ERROR_NONE) {
1977                                         g_print("Failed to set Camcorder Motion Rate %f [err:0x%x]\n", motion_rate, err);
1978                                         free( err_attr_name );
1979                                         err_attr_name = NULL;
1980                                 } else {
1981                                         g_print("Succeed to set Motion Rate %f\n", motion_rate);
1982                                 }
1983                         }
1984                                 break;
1985
1986                         case 'b' : // back
1987                                 hcamcorder->menu_state = MENU_STATE_MAIN;
1988                                 break;
1989
1990                         default :
1991                                 g_print("\t Invalid input \n");
1992                                 break;
1993                 }
1994         } else {
1995                 g_print("\t Invalid mode, back to upper menu \n");
1996                 hcamcorder->menu_state = MENU_STATE_MAIN;
1997         }
1998
1999         if(err_attr_name){
2000                 free( err_attr_name );
2001                 err_attr_name = NULL;
2002         }
2003
2004         g_print("\t bret : 0x%x \n", bret);
2005 }
2006
2007
2008 /**
2009  * This function is to execute command.
2010  *
2011  * @param       channel [in]    1st parameter
2012  *
2013  * @return      This function returns TRUE/FALSE
2014  * @remark
2015  * @see
2016  */
2017 static gboolean cmd_input(GIOChannel *channel)
2018 {
2019         gchar *buf = NULL;
2020         gsize read_size;
2021         GError *g_error = NULL;
2022
2023         debug_msg_t("ENTER");
2024
2025         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
2026         if (g_error) {
2027                 debug_msg_t("g_io_channel_read_chars error");
2028                 g_error_free(g_error);
2029                 g_error = NULL;
2030         }
2031
2032         if (buf) {
2033                 g_strstrip(buf);
2034
2035                 debug_msg_t("Menu Status : %d", hcamcorder->menu_state);
2036                 switch(hcamcorder->menu_state)
2037                 {
2038                         case MENU_STATE_MAIN:
2039                                 main_menu(buf[0]);
2040                                 break;
2041                         case MENU_STATE_SETTING:
2042                                 setting_menu(buf[0]);
2043                                 break;
2044                         default:
2045                                 break;
2046                 }
2047
2048                 g_free(buf);
2049                 buf = NULL;
2050
2051                 print_menu();
2052         } else {
2053                 debug_msg_t("No read input");
2054         }
2055
2056         return TRUE;
2057 }
2058
2059 void validity_print(MMCamAttrsInfo *info)
2060 {
2061                         printf("info(%d,%d, %d))\n", info->type, info->flag, info->validity_type);
2062                         if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY)
2063                         {
2064                                 printf("int array(%p, %d)\n", info->int_array.array, info->int_array.count);
2065                         }
2066                         else if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_RANGE)
2067                         {
2068                                 printf("int range(%d, %d)\n", info->int_range.min, info->int_range.max);
2069                         }
2070                         else if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_DOUBLE_ARRAY)
2071                         {
2072                                 printf("double array(%p, %d)\n", info->double_array.array, info->double_array.count);
2073                         }
2074                         else if(info->validity_type == MM_CAM_ATTRS_VALID_TYPE_DOUBLE_RANGE)
2075                         {
2076                                 printf("double range(%f, %f)\n", info->double_range.min, info->double_range.max);
2077                         }
2078                         else
2079                         {
2080                                 printf("validity none\n");
2081                         }
2082                         return;
2083 }
2084
2085
2086 /**
2087  * This function is to initiate camcorder attributes .
2088  *
2089  * @param       type    [in]    image(capture)/video(recording) mode
2090  *
2091  * @return      This function returns TRUE/FALSE
2092  * @remark
2093  * @see         other functions
2094  */
2095 static gboolean init(int type)
2096 {
2097         int err;
2098         int size;
2099         int preview_format = MM_PIXEL_FORMAT_NV12;
2100         int support_zero_copy_format = 0;
2101         int support_media_packet_preview_cb = 0;
2102         MMHandleType cam_handle = 0;
2103
2104         char *err_attr_name = NULL;
2105
2106         if (!hcamcorder)
2107                 return FALSE;
2108
2109         if(!hcamcorder->camcorder)
2110                 return FALSE;
2111
2112         cam_handle = (MMHandleType)(hcamcorder->camcorder);
2113
2114         /*================================================================================
2115                 Video capture mode
2116         *=================================================================================*/
2117         if (type == MODE_VIDEO_CAPTURE) {
2118                 mm_camcorder_get_attributes((MMHandleType)cam_handle, NULL,
2119                                             MMCAM_RECOMMEND_PREVIEW_FORMAT_FOR_CAPTURE, &preview_format,
2120                                             MMCAM_SUPPORT_ZERO_COPY_FORMAT, &support_zero_copy_format,
2121                                             MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB, &support_media_packet_preview_cb,
2122                                             NULL);
2123
2124                 warn_msg_t("MMCAM_SUPPORT_ZERO_COPY_FORMAT %d", support_zero_copy_format);
2125                 warn_msg_t("MMCAM_SUPPORT_MEDIA_PACKET_PREVIEW_CB %d", support_media_packet_preview_cb);
2126
2127                 /* camcorder attribute setting */
2128                 err = mm_camcorder_set_attributes( (MMHandleType)cam_handle, &err_attr_name,
2129                                                    MMCAM_MODE, MM_CAMCORDER_MODE_VIDEO_CAPTURE,
2130                                                    MMCAM_CAMERA_FORMAT, preview_format,
2131                                                    //MMCAM_VIDEO_WIDTH, 1280,
2132                                                    //MMCAM_VIDEO_HEIGHT, 720,
2133                                                    "camera-delay-attr-setting", TRUE,
2134                                                    MMCAM_IMAGE_ENCODER, MM_IMAGE_CODEC_JPEG,
2135                                                    MMCAM_IMAGE_ENCODER_QUALITY, IMAGE_ENC_QUALITY,
2136                                                    MMCAM_TAG_ENABLE, 1,
2137                                                    MMCAM_TAG_LATITUDE, 35.3036944,
2138                                                    MMCAM_TAG_LONGITUDE, 176.67837,
2139                                                    MMCAM_TAG_ALTITUDE, 190.3455,
2140                                                    MMCAM_DISPLAY_DEVICE, MM_DISPLAY_DEVICE_MAINLCD,
2141                                                    MMCAM_DISPLAY_SURFACE, MM_DISPLAY_SURFACE_X,
2142                                                    MMCAM_DISPLAY_RECT_X, DISPLAY_X_0,
2143                                                    MMCAM_DISPLAY_RECT_Y, DISPLAY_Y_0,
2144                                                    MMCAM_DISPLAY_RECT_WIDTH, 480,
2145                                                    MMCAM_DISPLAY_RECT_HEIGHT, 640,
2146                                                    MMCAM_DISPLAY_ROTATION, MM_DISPLAY_ROTATION_270,
2147                                                    //MMCAM_DISPLAY_FLIP, MM_FLIP_HORIZONTAL,
2148                                                    MMCAM_DISPLAY_GEOMETRY_METHOD, MM_DISPLAY_METHOD_LETTER_BOX,
2149                                                    MMCAM_CAPTURE_COUNT, IMAGE_CAPTURE_COUNT_STILL,
2150                                                    MMCAM_TAG_GPS_ENABLE, TRUE,
2151                                                    "tag-gps-time-stamp", 72815.5436243543,
2152                                                    "tag-gps-date-stamp", "2010:09:20", 10,
2153                                                    "tag-gps-processing-method", "GPS NETWORK HYBRID ARE ALL FINE.", 32,
2154                                                    MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_MIC,
2155                                                    MMCAM_AUDIO_ENCODER, MM_AUDIO_CODEC_AAC,
2156                                                    MMCAM_VIDEO_ENCODER, MM_VIDEO_CODEC_MPEG4,
2157                                                    MMCAM_VIDEO_ENCODER_BITRATE, VIDEO_ENCODE_BITRATE,
2158                                                    MMCAM_FILE_FORMAT, MM_FILE_FORMAT_3GP,
2159                                                    //MMCAM_CAMERA_FPS, SRC_VIDEO_FRAME_RATE_30,
2160                                                    MMCAM_CAMERA_FPS_AUTO, 0,
2161                                                    MMCAM_CAMERA_ROTATION, MM_VIDEO_INPUT_ROTATION_NONE,
2162                                                    MMCAM_AUDIO_SAMPLERATE, AUDIO_SOURCE_SAMPLERATE_AAC,
2163                                                    MMCAM_AUDIO_FORMAT, AUDIO_SOURCE_FORMAT,
2164                                                    MMCAM_AUDIO_CHANNEL, AUDIO_SOURCE_CHANNEL_AAC,
2165                                                    //MMCAM_AUDIO_DISABLE, TRUE,
2166                                                    MMCAM_TARGET_FILENAME, TARGET_FILENAME_VIDEO, strlen(TARGET_FILENAME_VIDEO),
2167                                                    //MMCAM_TARGET_TIME_LIMIT, 360000,
2168                                                    //MMCAM_TARGET_MAX_SIZE, 102400,
2169                                                    NULL );
2170
2171                 if (err != MM_ERROR_NONE) {
2172                         warn_msg_t("Init fail. (%s:%x)", err_attr_name, err);
2173                         SAFE_FREE (err_attr_name);
2174                         goto ERROR;
2175                 }
2176
2177                 mm_camcorder_set_video_capture_callback(hcamcorder->camcorder, (mm_camcorder_video_capture_callback)camcordertest_video_capture_cb, hcamcorder);
2178         }
2179         /*================================================================================
2180                 Audio mode
2181         *=================================================================================*/
2182         else if (type == MODE_AUDIO)
2183         {
2184                 size = strlen(TARGET_FILENAME_AUDIO)+1;
2185
2186                 /* camcorder attribute setting */
2187                 err = mm_camcorder_set_attributes( hcamcorder->camcorder, &err_attr_name,
2188                                                    MMCAM_MODE, MM_CAMCORDER_MODE_AUDIO,
2189                                                    MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_MIC,
2190                                                    MMCAM_AUDIO_ENCODER, MM_AUDIO_CODEC_AAC,
2191                                                    MMCAM_FILE_FORMAT, MM_FILE_FORMAT_MP4,
2192                                                    MMCAM_AUDIO_SAMPLERATE, AUDIO_SOURCE_SAMPLERATE_AAC,
2193                                                    MMCAM_AUDIO_FORMAT, AUDIO_SOURCE_FORMAT,
2194                                                    MMCAM_AUDIO_CHANNEL, AUDIO_SOURCE_CHANNEL_AAC,
2195                                                    MMCAM_TARGET_FILENAME, TARGET_FILENAME_AUDIO, size,
2196                                                    MMCAM_TARGET_TIME_LIMIT, 360000,
2197                                                    //MMCAM_AUDIO_ENCODER_BITRATE, 12200,
2198                                                    MMCAM_TAG_GPS_ENABLE, TRUE,
2199                                                    MMCAM_TAG_LATITUDE, 35.3036944,
2200                                                    MMCAM_TAG_LONGITUDE, 176.67837,
2201                                                    MMCAM_TAG_ALTITUDE, 190.3455,
2202                                                    MMCAM_TARGET_MAX_SIZE, 300,
2203                                                    NULL);
2204
2205                 if (err < 0) {
2206                         warn_msg_t("Init fail. (%s:%x)", err_attr_name, err);
2207                         SAFE_FREE (err_attr_name);
2208                         goto ERROR;
2209                 }
2210
2211 #ifdef USE_AUDIO_STREAM_CB
2212                 mm_camcorder_set_audio_stream_callback(hcamcorder->camcorder, (mm_camcorder_audio_stream_callback)camcordertest_audio_stream_cb, (void*)hcamcorder->camcorder);
2213 #endif /* USE_AUDIO_STREAM_CB */
2214         }
2215
2216         debug_msg_t("Init DONE.");
2217
2218         return TRUE;
2219
2220 ERROR:
2221         err_msg_t("init failed.");
2222         return FALSE;
2223 }
2224
2225 /**
2226  * This function is to represent messagecallback
2227  *
2228  * @param       message [in]    Specifies the message
2229  * @param       param   [in]    Specifies the message type
2230  * @param       user_param      [in]    Specifies the user poiner for passing to callback function
2231  * @return      This function returns TRUE/FALSE
2232  * @remark
2233  * @see         other functions
2234  */
2235 static gboolean msg_callback(int message, void *msg_param, void *user_param)
2236 {
2237
2238         MMMessageParamType *param = (MMMessageParamType *) msg_param;
2239
2240         switch (message) {
2241                 case MM_MESSAGE_CAMCORDER_ERROR:
2242                         g_print("MM_MESSAGE_ERROR : code = %x", param->code);
2243                         break;
2244                 case MM_MESSAGE_CAMCORDER_STATE_CHANGED:
2245                         g_current_state = param->state.current;
2246                         switch(g_current_state)
2247                         {
2248                                 case MM_CAMCORDER_STATE_NULL :
2249                                         mmcamcorder_state = MM_CAMCORDER_STATE_NULL;
2250                                         debug_msg_t("Camcorder State is [NULL]");
2251                                         break;
2252                                 case MM_CAMCORDER_STATE_READY :
2253                                         mmcamcorder_state = MM_CAMCORDER_STATE_READY;
2254                                         debug_msg_t("Camcorder State is [READY]");
2255                                         break;
2256                                 case MM_CAMCORDER_STATE_PREPARE :
2257                                         mmcamcorder_state = MM_CAMCORDER_STATE_PREPARE;
2258                                         debug_msg_t("Camcorder State is [PREPARE]");
2259                                         break;
2260                                 case MM_CAMCORDER_STATE_CAPTURING :
2261                                         mmcamcorder_state = MM_CAMCORDER_STATE_CAPTURING;
2262                                         debug_msg_t("Camcorder State is [CAPTURING]");
2263                                         break;
2264                                 case MM_CAMCORDER_STATE_RECORDING :
2265                                         mmcamcorder_state = MM_CAMCORDER_STATE_RECORDING;
2266                                         time_msg_t("Recording start time  : %12.6lf s", g_timer_elapsed(timer, NULL));
2267                                         debug_msg_t("Camcorder State is [RECORDING]");
2268                                         break;
2269                                 case MM_CAMCORDER_STATE_PAUSED :
2270                                         mmcamcorder_state = MM_CAMCORDER_STATE_PAUSED;
2271                                         debug_msg_t("Camcorder State is [PAUSED]");
2272                                         break;
2273                                 default:
2274                                         debug_msg_t("Unknown State [%d]", g_current_state);
2275                                         break;
2276                         }
2277                         break;
2278
2279                 case MM_MESSAGE_CAMCORDER_CAPTURED:
2280                         time_msg_t("Stillshot capture  : %12.6lf s", g_timer_elapsed(timer, NULL));
2281                         if (hcamcorder->isMultishot) {
2282                                 //g_print("[CamcorderApp] Camcorder Captured(Capture Count=%d)\n", param->code);
2283                                 if (param->code >= multishot_num) {
2284                                         get_me_out();
2285 //                                      g_timeout_add (100, (GSourceFunc)get_me_out, NULL);
2286 //                                      hcamcorder->isMultishot = FALSE;
2287                                 }
2288                         } else {
2289                                 get_me_out();
2290 //                              g_timeout_add (1000, (GSourceFunc)get_me_out, NULL);
2291                         }
2292                         break;
2293                 case MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED:
2294                 case MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED:
2295                 {
2296                         MMCamRecordingReport* report ;
2297
2298                         time_msg_t("Recording commit time : %12.6lf s", g_timer_elapsed(timer, NULL));
2299
2300                         if (param) {
2301                                 report = (MMCamRecordingReport*)(param->data);
2302                         } else {
2303                                 return FALSE;
2304                         }
2305
2306                         if (report != NULL) {
2307                                 g_print("*******************************************************\n");
2308                                 g_print("[Camcorder Testsuite] Camcorder Captured(filename=%s)\n", report->recording_filename);
2309                                 g_print("*******************************************************\n");
2310
2311                                 SAFE_FREE (report->recording_filename);
2312                                 SAFE_FREE (report);
2313                         } else {
2314                                 g_print( "[Camcorder Testsuite] report is NULL.\n" );
2315                         }
2316                 }
2317                         break;
2318                 case MM_MESSAGE_CAMCORDER_TIME_LIMIT:
2319                 {
2320                         debug_msg_t("Got TIME LIMIT MESSAGE");
2321                 }
2322                         break;
2323                 case MM_MESSAGE_CAMCORDER_RECORDING_STATUS:
2324                 {
2325                         unsigned long long elapsed;
2326                         elapsed = param->recording_status.elapsed / 1000;
2327                         if (hcamcorder->elapsed_time != elapsed) {
2328                                 unsigned long temp_time;
2329                                 unsigned long long hour, minute, second;
2330                                 hcamcorder->elapsed_time = elapsed;
2331                                 temp_time = elapsed;
2332                                 hour = temp_time / 3600;
2333                                 temp_time = elapsed % 3600;
2334                                 minute = temp_time / 60;
2335                                 second = temp_time % 60;
2336                                 debug_msg_t("Current Time - %lld:%lld:%lld, remained %lld ms, filesize %lld KB",
2337                                              hour, minute, second, param->recording_status.remained_time, param->recording_status.filesize);
2338                         }
2339                 }
2340                         break;
2341                 case MM_MESSAGE_CAMCORDER_MAX_SIZE:
2342                 {
2343                         int err;
2344                         g_print("*Save Recording because receives message : MM_MESSAGE_CAMCORDER_MAX_SIZE\n");
2345                         g_timer_reset(timer);
2346                         err = mm_camcorder_commit(hcamcorder->camcorder);
2347
2348                         if (err < 0)
2349                         {
2350                                 warn_msg_t("Save recording mm_camcorder_commit  = %x", err);
2351 //                                      goto ERROR;
2352                         }
2353                 }
2354                         break;
2355                 case MM_MESSAGE_CAMCORDER_CURRENT_VOLUME:
2356                         break;
2357                 case MM_MESSAGE_CAMCORDER_NO_FREE_SPACE:
2358                 {
2359                         int err;
2360                         g_print("*Save Recording because receives message : MM_MESSAGE_CAMCORDER_NO_FREE_SPACE\n");
2361                         g_timer_reset(timer);
2362                         err = mm_camcorder_commit(hcamcorder->camcorder);
2363
2364                         if (err < 0)
2365                         {
2366                                 warn_msg_t("Save recording mm_camcorder_commit  = %x", err);
2367 //                                      goto ERROR;
2368                         }
2369                 }
2370                         break;
2371                 case MM_MESSAGE_CAMCORDER_FOCUS_CHANGED:
2372                 {
2373                         g_print( "Focus State changed. State:[%d]\n", param->code );
2374                 }
2375                         break;
2376                 case MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO:
2377                 {
2378                         MMCamFaceDetectInfo *cam_fd_info = NULL;
2379
2380                         cam_fd_info = (MMCamFaceDetectInfo *)(param->data);
2381
2382                         if (cam_fd_info) {
2383                                 int i = 0;
2384
2385                                 g_print("\tface detect num %d, pointer %p\n", cam_fd_info->num_of_faces, cam_fd_info);
2386
2387                                 for (i = 0 ; i < cam_fd_info->num_of_faces ; i++) {
2388                                         g_print("\t\t[%2d][score %d] position %d,%d %dx%d\n",
2389                                                 cam_fd_info->face_info[i].id,
2390                                                 cam_fd_info->face_info[i].score,
2391                                                 cam_fd_info->face_info[i].rect.x,
2392                                                 cam_fd_info->face_info[i].rect.y,
2393                                                 cam_fd_info->face_info[i].rect.width,
2394                                                 cam_fd_info->face_info[i].rect.height);
2395                                 }
2396                         }
2397                 }
2398                         break;
2399                 default:
2400                         g_print("Message %x received\n", message);
2401                         break;
2402         }
2403
2404         return TRUE;
2405 }
2406
2407 static gboolean init_handle()
2408 {
2409         hcamcorder->mode = MODE_VIDEO_CAPTURE;  /* image(capture)/video(recording) mode */
2410         hcamcorder->isMultishot =  FALSE;
2411         hcamcorder->stillshot_count = 0;        /* total stillshot count */
2412         hcamcorder->multishot_count = 0;        /* total multishot count */
2413         hcamcorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME;  /* stored filename of  stillshot  */
2414         hcamcorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME;  /* stored filename of  multishot  */
2415         hcamcorder->menu_state = MENU_STATE_MAIN;
2416         hcamcorder->isMute = FALSE;
2417         hcamcorder->elapsed_time = 0;
2418         hcamcorder->fps = SRC_VIDEO_FRAME_RATE_15; /*SRC_VIDEO_FRAME_RATE_30;*/
2419         multishot_num = IMAGE_CAPTURE_COUNT_MULTI;
2420
2421         return TRUE;
2422 }
2423 /**
2424  * This function is to change camcorder mode.
2425  *
2426  * @param       type    [in]    image(capture)/video(recording) mode
2427  *
2428  * @return      This function returns TRUE/FALSE
2429  * @remark
2430  * @see         other functions
2431  */
2432 static gboolean mode_change()
2433 {
2434         int err = MM_ERROR_NONE;
2435         int state = MM_CAMCORDER_STATE_NONE;
2436         int name_size = 0;
2437         int device_count = 0;
2438         int facing_direction = 0;
2439         char media_type = '\0';
2440         char *evassink_name = NULL;
2441         bool check= FALSE;
2442
2443         debug_msg_t("MMCamcorder State : %d", mmcamcorder_state);
2444
2445         err = mm_camcorder_get_state(hcamcorder->camcorder, (MMCamcorderStateType *)&state);
2446         if(state != MM_CAMCORDER_STATE_NONE)
2447         {
2448                 if ((state == MM_CAMCORDER_STATE_RECORDING)
2449                         || (state == MM_CAMCORDER_STATE_PAUSED))
2450                 {
2451                         debug_msg_t("mm_camcorder_cancel");
2452                         err = mm_camcorder_cancel(hcamcorder->camcorder);
2453
2454                         if (err < 0)
2455                         {
2456                                 warn_msg_t("exit mm_camcorder_cancel  = %x", err);
2457                                 return FALSE;
2458                         }
2459                 }
2460                 else if (state == MM_CAMCORDER_STATE_CAPTURING)
2461                 {
2462                         debug_msg_t("mm_camcorder_capture_stop");
2463                         err = mm_camcorder_capture_stop(hcamcorder->camcorder);
2464
2465                         if (err < 0)
2466                         {
2467                                 warn_msg_t("exit mmcamcorder_capture_stop  = %x", err);
2468                                 return FALSE;
2469                         }
2470                 }
2471
2472                 err = mm_camcorder_get_state(hcamcorder->camcorder, (MMCamcorderStateType *)&state);
2473                 if(state == MM_CAMCORDER_STATE_PREPARE)
2474                 {
2475                         debug_msg_t("mm_camcorder_stop");
2476                         mm_camcorder_stop(hcamcorder->camcorder);
2477                 }
2478
2479                 err = mm_camcorder_get_state(hcamcorder->camcorder, (MMCamcorderStateType *)&state);
2480                 if(state == MM_CAMCORDER_STATE_READY)
2481                 {
2482                         debug_msg_t("mm_camcorder_unrealize");
2483                         mm_camcorder_unrealize(hcamcorder->camcorder);
2484                 }
2485
2486                 err = mm_camcorder_get_state(hcamcorder->camcorder, (MMCamcorderStateType *)&state);
2487                 if(state == MM_CAMCORDER_STATE_NULL)
2488                 {
2489                         debug_msg_t("mm_camcorder_destroy");
2490                         mm_camcorder_destroy(hcamcorder->camcorder);
2491
2492                         mmcamcorder_state = MM_CAMCORDER_STATE_NONE;
2493                 }
2494         }
2495
2496         init_handle();
2497         mmcamcorder_print_state = MM_CAMCORDER_STATE_PREPARE;
2498         while(!check) {
2499                 g_print("\n\t=======================================\n");
2500                 g_print("\t   MM_CAMCORDER_TESTSUIT\n");
2501                 g_print("\t=======================================\n");
2502                 g_print("\t   '1' Video Capture - Front Camera\n");
2503                 g_print("\t   '2' Video Capture - Rear Camera\n");
2504                 g_print("\t   '3' Audio Recording - MIC\n");
2505                 g_print("\t   '4' Audio Recording - RADIO\n");
2506                 g_print("\t   'q' Exit\n");
2507                 g_print("\t=======================================\n");
2508
2509                 g_print("\t  Enter the media type:\n\t");
2510
2511                 err = scanf("%c", &media_type);
2512                 if (err == EOF) {
2513                         g_print("\t!!!read input error!!!\n");
2514                         continue;
2515                 }
2516
2517                 switch (media_type) {
2518                 case '1':
2519                         hcamcorder->mode= MODE_VIDEO_CAPTURE;
2520                         cam_info.videodev_type = MM_VIDEO_DEVICE_CAMERA1;
2521                         check = TRUE;
2522                         break;
2523                 case '2':
2524                         hcamcorder->mode= MODE_VIDEO_CAPTURE;
2525                         cam_info.videodev_type = MM_VIDEO_DEVICE_CAMERA0;
2526                         check = TRUE;
2527                         break;
2528                 case '3':
2529                         hcamcorder->mode= MODE_AUDIO;
2530                         cam_info.videodev_type = MM_VIDEO_DEVICE_NONE;
2531                         check = TRUE;
2532                         break;
2533                 case '4':
2534                         hcamcorder->mode= MODE_AUDIO;
2535                         cam_info.videodev_type = MM_VIDEO_DEVICE_NONE;
2536                         check = TRUE;
2537                         break;
2538                 case 'q':
2539                         g_print("\t Quit Camcorder Testsuite!!\n");
2540                         hcamcorder->mode = -1;
2541                         if(g_main_loop_is_running(g_loop)) {
2542                                 g_main_loop_quit(g_loop);
2543                         }
2544                         return FALSE;
2545                 default:
2546                         g_print("\t Invalid media type(%d)\n", media_type);
2547                         continue;
2548                 }
2549         }
2550
2551         debug_msg_t("mm_camcorder_create");
2552         g_get_current_time(&previous);
2553         g_timer_reset(timer);
2554
2555         err = mm_camcorder_create(&hcamcorder->camcorder, &cam_info);
2556         time_msg_t("mm_camcorder_create()  : %12.6lfs", g_timer_elapsed(timer, NULL));
2557
2558         if (err != MM_ERROR_NONE) {
2559                 err_msg_t("mmcamcorder_create = %x", err);
2560                 return -1;
2561         } else {
2562                 mmcamcorder_state = MM_CAMCORDER_STATE_NULL;
2563         }
2564
2565         /* get evassink name */
2566         mm_camcorder_get_attributes(hcamcorder->camcorder, NULL,
2567                                     MMCAM_DISPLAY_EVAS_SURFACE_SINK, &evassink_name, &name_size,
2568                                     MMCAM_CAMERA_DEVICE_COUNT, &device_count,
2569                                     MMCAM_CAMERA_FACING_DIRECTION, &facing_direction,
2570                                     NULL);
2571         debug_msg_t("evassink name[%s], device count[%d], facing direction[%d]",
2572                     evassink_name, device_count, facing_direction);
2573
2574         mm_camcorder_set_message_callback(hcamcorder->camcorder, (MMMessageCallback)msg_callback, hcamcorder);
2575
2576         if (media_type == '3') {
2577                 mm_camcorder_set_attributes(hcamcorder->camcorder, NULL,
2578                                             MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_MIC,
2579                                             NULL);
2580         } else if (media_type == '4') {
2581                 mm_camcorder_set_attributes(hcamcorder->camcorder, NULL,
2582                                             MMCAM_AUDIO_DEVICE, MM_AUDIO_DEVICE_RADIO,
2583                                             NULL);
2584         }
2585
2586         if (!init(hcamcorder->mode)) {
2587                 err_msg_t("testsuite init() failed.");
2588                 return -1;
2589         }
2590
2591         debug_msg_t("mm_camcorder_realize");
2592
2593         g_timer_reset(timer);
2594
2595         err =  mm_camcorder_realize(hcamcorder->camcorder);
2596         time_msg_t("mm_camcorder_realize()  : %12.6lfs", g_timer_elapsed(timer, NULL));
2597         if (err != MM_ERROR_NONE) {
2598                 err_msg_t("mm_camcorder_realize  = %x", err);
2599                 return -1;
2600         }
2601
2602         /* start camcorder */
2603         debug_msg_t("mm_camcorder_start");
2604
2605         g_timer_reset(timer);
2606
2607         err = mm_camcorder_start(hcamcorder->camcorder);
2608         time_msg_t("mm_camcorder_start()  : %12.6lfs", g_timer_elapsed(timer, NULL));
2609
2610         if (err != MM_ERROR_NONE) {
2611                 err_msg_t("mm_camcorder_start  = %x", err);
2612                 return -1;
2613         }
2614
2615         g_get_current_time(&current);
2616         timersub(&current, &previous, &result);
2617         time_msg_t("Camera Starting Time  : %ld.%lds", result.tv_sec, result.tv_usec);
2618
2619         return TRUE;
2620 }
2621
2622
2623 /**
2624  * This function is the example main function for mmcamcorder API.
2625  *
2626  * @param
2627  *
2628  * @return      This function returns 0.
2629  * @remark
2630  * @see         other functions
2631  */
2632 int main(int argc, char **argv)
2633 {
2634         int bret;
2635
2636         if (!g_thread_supported())
2637                 g_thread_init (NULL);
2638
2639         timer = g_timer_new();
2640
2641         gst_init(&argc, &argv);
2642
2643         time_msg_t("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
2644
2645         hcamcorder = (cam_handle_t *) g_malloc0(sizeof(cam_handle_t));
2646         mmcamcorder_state = MM_CAMCORDER_STATE_NONE;
2647
2648         g_timer_reset(timer);
2649
2650         bret = mode_change();
2651         if(!bret){
2652                 return bret;
2653         }
2654
2655         print_menu();
2656
2657         g_loop = g_main_loop_new(NULL, FALSE);
2658
2659         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
2660         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
2661
2662         debug_msg_t("RUN main loop");
2663
2664         g_main_loop_run(g_loop);
2665
2666         debug_msg_t("STOP main loop");
2667
2668         if (timer) {
2669                 g_timer_stop(timer);
2670                 g_timer_destroy(timer);
2671                 timer = NULL;
2672         }
2673         //g_print("\t Exit from the application.\n");
2674         g_free(hcamcorder);
2675         g_main_loop_unref(g_loop);
2676         g_io_channel_unref(stdin_channel);
2677
2678         return bret;
2679 }
2680
2681 /*EOF*/