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