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