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