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