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