[libmm-streamrecorder] initial code for new feature of streamrecorder
[platform/core/multimedia/libmm-streamrecorder.git] / test / mm_streamrecorder_testsuite.c
1 /*
2  * mm_streamrecorder_testsuite
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyuntae Kim <ht1211.kim@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 |  INCLUDE FILES                                                                        |
24 =======================================================================================*/
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <glib.h>
28 #include <gst/gst.h>
29 #include <sys/time.h>
30 #include "../src/include/mm_streamrecorder.h"
31 #include "../src/include/mm_streamrecorder_internal.h"
32 #include "../src/include/mm_streamrecorder_util.h"
33 #include "../src/include/mm_streamrecorder_attribute.h"
34 #include <gst/video/colorbalance.h>
35
36 /*-----------------------------------------------------------------------
37 |    GLOBAL VARIABLE DEFINITIONS:                                       |
38 -----------------------------------------------------------------------*/
39 #define EXPORT_API __attribute__((__visibility__("default")))
40
41 #define PACKAGE "mm_streamrecorder_testsuite"
42
43 GMainLoop *g_loop;
44 GIOChannel *stdin_channel;
45 int resolution_set;
46 int g_current_state;
47 int src_w, src_h;
48 GstCaps *filtercaps;
49 bool isMultishot;
50 int multishot_num;
51 static int audio_stream_cb_cnt;
52 static int video_stream_cb_cnt;
53 static GTimer *timer = NULL;
54 int g_state;
55
56 enum {
57         STREAMRECORDER_NULL,
58         STREAMRECORDER_NONE,
59         STREAMRECORDER_CREATED,
60         STREAMRECORDER_STARTED,
61         STREAMRECORDER_COMMITED
62 };
63
64 void streamrecorder_set_state(int new_state)
65 {
66         g_state = new_state;
67         return;
68 }
69
70 int streamrecorder_get_state()
71 {
72         return g_state;
73 }
74
75
76
77 /*-----------------------------------------------------------------------
78 |    GLOBAL CONSTANT DEFINITIONS:                                       |
79 -----------------------------------------------------------------------*/
80
81
82 /*-----------------------------------------------------------------------
83 |    IMPORTED VARIABLE DECLARATIONS:                                    |
84 -----------------------------------------------------------------------*/
85
86
87 /*-----------------------------------------------------------------------
88 |    IMPORTED FUNCTION DECLARATIONS:                                    |
89 -----------------------------------------------------------------------*/
90
91
92 /*-----------------------------------------------------------------------
93 |    LOCAL #defines:                                                    |
94 -----------------------------------------------------------------------*/
95 #define test_ffmux_mp4
96
97 #define DISPLAY_X_0                                                     0                                               /* for direct FB */
98 #define DISPLAY_Y_0                                                     0                                               /* for direct FB */
99
100 #define SRC_VIDEO_FRAME_RATE_15         15    /* video input frame rate */
101 #define SRC_VIDEO_FRAME_RATE_30         30    /* video input frame rate */
102
103 #define STILL_CAPTURE_FILE_PATH_NAME    "/opt/StillshotCapture"
104 #define MULTI_CAPTURE_FILE_PATH_NAME    "/opt/MultishotCapture"
105 #define TARGET_FILENAME_PATH            "/opt/"
106 #define CAPTURE_FILENAME_LEN            256
107
108 #define AUDIO_SOURCE_SAMPLERATE_AAC     44100
109 #define AUDIO_SOURCE_SAMPLERATE_AMR     8000
110 #define AUDIO_SOURCE_FORMAT             MM_STREAMRECORDER_AUDIO_FORMAT_PCM_S16_LE
111 #define AUDIO_SOURCE_CHANNEL_AAC        2
112 #define AUDIO_SOURCE_CHANNEL_AMR        1
113 #define VIDEO_ENCODE_BITRATE            40000000 /* bps */
114 /*
115  * D E B U G   M E S S A G E
116  */
117 #define MMF_DEBUG                       "** (mmstreamrecorder testsuite) DEBUG: "
118 #define MMF_ERR                         "** (mmstreamrecorder testsuite) ERROR: "
119 #define MMF_INFO                        "** (mmstreamrecorder testsuite) INFO: "
120 #define MMF_WARN                        "** (mmstreamrecorder testsuite) WARNING: "
121 #define MMF_TIME                        "** (mmstreamrecorder testsuite) TIME: "
122
123 #define CHECK_MM_ERROR(expr) \
124 do {\
125         int ret = 0; \
126         ret = expr; \
127         if (ret != MM_ERROR_NONE) {\
128                 printf("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
129                 return; \
130         } \
131 } while (0)
132
133 #define time_msg_t(fmt, arg...) \
134 do { \
135         fprintf(stderr, "\x1b[44m\x1b[37m"MMF_TIME"[%s:%05d]  " fmt , __func__, __LINE__, ##arg); \
136         fprintf(stderr, "\x1b[0m\n"); \
137 } while (0)
138
139 #define debug_msg_t(fmt, arg...)\
140 do { \
141         fprintf(stderr, MMF_DEBUG"[%s:%05d]  " fmt "\n", __func__, __LINE__, ##arg); \
142 } while (0)
143
144 #define err_msg_t(fmt, arg...)  \
145 do { \
146         fprintf(stderr, MMF_ERR"[%s:%05d]  " fmt "\n", __func__, __LINE__, ##arg); \
147 } while (0)
148
149 #define info_msg_t(fmt, arg...) \
150 do { \
151         fprintf(stderr, MMF_INFO"[%s:%05d]  " fmt "\n", __func__, __LINE__, ##arg); \
152 } while (0)
153
154 #define warn_msg_t(fmt, arg...) \
155 do { \
156         fprintf(stderr, MMF_WARN"[%s:%05d]  " fmt "\n", __func__, __LINE__, ##arg); \
157 } while (0)
158
159 #ifndef SAFE_FREE
160 #define SAFE_FREE(x)       if (x) {g_free(x); x = NULL; }
161 #endif
162
163
164 GTimeVal previous;
165 GTimeVal current;
166 GTimeVal result;
167 /* temporary buffer */
168 char buffer[460800] = {0x0,};
169
170
171 /**
172  * Enumerations for command
173  */
174 #define SENSOR_FLIP_NUM                 3
175 #define SENSOR_PROGRAM_MODE_NUM         15
176 #define SENSOR_FOCUS_NUM                6
177 #define SENSOR_INPUT_ROTATION           4
178 #define SENSOR_AF_SCAN_NUM              4
179 #define SENSOR_ISO_NUM                  8
180 #define SENSOR_EXPOSURE_NUM             9
181 #define SENSOR_IMAGE_FORMAT             9
182
183
184 /*-----------------------------------------------------------------------
185 |    LOCAL CONSTANT DEFINITIONS:                                        |
186 -----------------------------------------------------------------------*/
187 enum {
188         MODE_VIDEO_CAPTURE,     /* recording and image capture mode */
189         MODE_AUDIO,             /* audio recording*/
190         MODE_NUM,
191 };
192
193 enum {
194         MENU_STATE_MAIN,
195         MENU_STATE_SETTING,
196         MENU_STATE_NUM,
197 };
198
199 /*-----------------------------------------------------------------------
200 |    LOCAL DATA TYPE DEFINITIONS:                                       |
201 -----------------------------------------------------------------------*/
202 typedef struct _streamrecorder_handle {
203         MMHandleType streamrecorder;
204         int mode;                       /* image(capture)/video(recording) mode */
205         bool isMultishot;               /* flag for multishot mode */
206         int stillshot_count;            /* total stillshot count */
207         int multishot_count;            /* total multishot count */
208         const char *stillshot_filename;       /* stored filename of  stillshot  */
209         const char *multishot_filename;       /* stored filename of  multishot  */
210         int menu_state;
211         int fps;
212         bool isMute;
213         unsigned long long elapsed_time;
214 } streamrecorder_handle_t;
215
216 typedef struct _str_xypair {
217         char* attr_subcat_x;
218         char* attr_subcat_y;
219         int x;
220         int y;
221 } str_xypair_t;
222
223 /*---------------------------------------------------------------------------
224 |    LOCAL VARIABLE DEFINITIONS:                                                                                        |
225 ---------------------------------------------------------------------------*/
226 static streamrecorder_handle_t *hstreamrecorder ;
227
228 const char *image_fmt[SENSOR_IMAGE_FORMAT] = {
229         "NV12",
230         "NV12T",
231         "NV16",
232         "NV21",
233         "YUYV",
234         "UYVY",
235         "422P",
236         "I420",
237         "YV12",
238 };
239
240 const char *face_zoom_mode[] = {
241         "Face Zoom OFF",
242         "Face Zoom ON",
243 };
244
245 const char *display_mode[] = {
246         "Default",
247         "Primary Video ON and Secondary Video Full Screen",
248         "Primary Video OFF and Secondary Video Full Screen",
249 };
250
251 const char *output_mode[] = {
252         "Letter Box mode",
253         "Original Size mode",
254         "Full Screen mode",
255         "Cropped Full Screen mode",
256         "ROI mode",
257 };
258
259 const char *rotate_mode[] = {
260         "0",
261         "90",
262         "180",
263         "270",
264 };
265
266 const char* strobe_mode[] = {
267         "Strobe OFF",
268         "Strobe ON",
269         "Strobe Auto",
270         "Strobe RedEyeReduction",
271         "Strobe SlowSync",
272         "Strobe FrontCurtain",
273         "Strobe RearCurtain",
274         "Strobe Permanent",
275 };
276
277 const char *detection_mode[2] = {
278         "Face Detection OFF",
279         "Face Detection ON",
280 };
281
282 const char *wdr_mode[] = {
283         "WDR OFF",
284         "WDR ON",
285         "WDR AUTO",
286 };
287
288 const char *hdr_mode[] = {
289         "HDR OFF",
290         "HDR ON",
291         "HDR ON and Original",
292 };
293
294 const char *ahs_mode[] = {
295         "Anti-handshake OFF",
296         "Anti-handshake ON",
297         "Anti-handshake AUTO",
298         "Anti-handshake MOVIE",
299 };
300
301 const char *vs_mode[] = {
302         "Video-stabilization OFF",
303         "Video-stabilization ON",
304 };
305
306 const char *visible_mode[] = {
307         "Display OFF",
308         "Display ON",
309 };
310
311
312 /*---------------------------------------------------------------------------
313 |    LOCAL FUNCTION PROTOTYPES:                                                                                         |
314 ---------------------------------------------------------------------------*/
315 static void print_menu();
316 void  get_me_out();
317 static gboolean cmd_input(GIOChannel *channel);
318 static gboolean init(int type);
319 static gboolean mode_change();
320 int streamrecordertest_set_attr_int(const char* attr_subcategory, int value);
321
322
323 static inline void flush_stdin()
324 {
325         int ch;
326         while ((ch = getchar()) != EOF && ch != '\n');
327 }
328
329 #if 0
330 static gboolean test_idle_capture_start()
331 {
332         int err;
333
334         streamrecordertest_set_attr_int(MMSTR_VIDEO_SOURCE_FORMAT, MM_STREAMRECORDER_INPUT_FORMAT_NV12);
335         streamrecordertest_set_attr_int(MMSTR_VIDEO_ENCODER, MM_VIDEO_CODEC_H264);
336         streamrecordertest_set_attr_int(MMSTR_AUDIO_SOURCE_FORMAT, MM_STREAMRECORDER_AUDIO_FORMAT_PCM_U8);
337         streamrecordertest_set_attr_int(MMSTR_AUDIO_ENCODER, MM_AUDIO_CODEC_AAC);
338
339         g_timer_reset(timer);
340         err = mm_streamrecorder_record(hstreamrecorder->streamrecorder);
341
342         return FALSE;
343 }
344 #endif
345
346 int streamrecordertest_set_attr_int(const char * attr_subcategory, int value)
347 {
348         char * err_attr_name = NULL;
349         int err;
350
351         if (hstreamrecorder) {
352                 if (hstreamrecorder->streamrecorder) {
353                         debug_msg_t("streamrecordertest_set_attr_int(%s, %d)", attr_subcategory, value);
354
355                         err = mm_streamrecorder_set_attributes(hstreamrecorder->streamrecorder, &err_attr_name, attr_subcategory, value, NULL);
356                         if (err != MM_ERROR_NONE) {
357                                 err_msg_t("streamrecordertest_set_attr_int : Error(%s:%x)!!!!!!!", err_attr_name, err);
358                                 SAFE_FREE(err_attr_name);
359                                 return FALSE;
360                         }
361
362                         return TRUE;
363                 }
364
365                 debug_msg_t("streamrecordertest_set_attr_int(!hstreamrecorder->streamrecorder)");
366         }
367
368         debug_msg_t("streamrecordertest_set_attr_int(!hstreamrecorder)");
369
370         return FALSE;
371 }
372
373 int streamrecordertest_set_attr_string(const char * attr_subcategory, char  *value)
374 {
375         char * err_attr_name = NULL;
376         int err;
377         if (value == NULL) {
378                 err_msg_t("streamrecordertest_set_attr_string : value is null !");
379                 return FALSE;
380         }
381         if (hstreamrecorder) {
382                 if (hstreamrecorder->streamrecorder) {
383                         debug_msg_t("streamrecordertest_set_attr_string(%s, %s)", attr_subcategory, value);
384
385                         err = mm_streamrecorder_set_attributes(hstreamrecorder->streamrecorder, &err_attr_name, attr_subcategory, value, NULL);
386                         if (err != MM_ERROR_NONE) {
387                                 err_msg_t("streamrecordertest_set_attr_string : Error(%s:%x)!!!!!!!", err_attr_name, err);
388                                 SAFE_FREE(err_attr_name);
389                                 return FALSE;
390                         }
391
392                         return TRUE;
393                 }
394
395                 debug_msg_t("streamrecordertest_set_attr_string(!hstreamrecorder->streamrecorder)");
396         }
397
398         debug_msg_t("streamrecordertest_set_attr_string(!hstreamrecorder)");
399
400         return FALSE;
401 }
402
403 int streamrecordertest_set_attr_xypair(str_xypair_t pair)
404 {
405         char * err_attr_name = NULL;
406         int err;
407
408         if (hstreamrecorder) {
409                 if (hstreamrecorder->streamrecorder) {
410                         debug_msg_t("streamrecordertest_set_attr_xypair((%s, %s), (%d, %d))",  pair.attr_subcat_x, pair.attr_subcat_y, pair.x, pair.y);
411
412                         err = mm_streamrecorder_set_attributes(hstreamrecorder->streamrecorder, &err_attr_name,
413                                                                         pair.attr_subcat_x, pair.x,
414                                                                         pair.attr_subcat_y, pair.y,
415                                                                         NULL);
416                         if (err < 0) {
417                                 err_msg_t("streamrecordertest_set_attr_xypair : Error(%s:%x)!!", err_attr_name, err);
418                                 SAFE_FREE(err_attr_name);
419                                 return FALSE;
420                         }
421
422                         return TRUE;
423                 }
424
425                 debug_msg_t("streamrecordertest_set_attr_xypair(!hstreamrecorder->streamrecorder)");
426         }
427
428         debug_msg_t("streamrecordertest_set_attr_xypair(!hstreamrecorder)");
429         return FALSE;
430 }
431
432 int streamrecordertest_get_attr_valid_intarray(const char * attr_name, int ** array, int *count)
433 {
434         MMStreamRecorderAttrsInfo info;
435         int err = MM_ERROR_NONE;
436
437         if (hstreamrecorder) {
438                 if (hstreamrecorder->streamrecorder) {
439                         debug_msg_t("streamrecordertest_get_attr_valid_intarray(%s)", attr_name);
440
441                         err = mm_streamrecorder_get_attribute_info(hstreamrecorder->streamrecorder, attr_name, &info);
442                         if (err != MM_ERROR_NONE) {
443                                 err_msg_t("streamrecordertest_get_attr_valid_intarray : Error(%x)!!", err);
444                                 return FALSE;
445                         } else {
446                                 if (info.type == MM_STR_REC_ATTRS_TYPE_INT) {
447                                         if (info.validity_type == MM_STR_REC_ATTRS_VALID_TYPE_INT_ARRAY) {
448                                                 *array = info.int_array.array;
449                                                 *count = info.int_array.count;
450                                                 debug_msg_t("INT ARRAY - default value : %d", info.int_array.def);
451                                                 return TRUE;
452                                         }
453                                 }
454
455                                 err_msg_t("streamrecordertest_get_attr_valid_intarray : Type mismatched!!");
456                                 return FALSE;
457                         }
458                 }
459
460                 debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder->streamrecorder)");
461         }
462
463
464         debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder)");
465         return FALSE;
466 }
467
468 int streamrecordertest_get_attr_valid_intrange(const char * attr_name, int *min, int *max)
469 {
470         MMStreamRecorderAttrsInfo info;
471         int err = MM_ERROR_NONE;
472
473         if (hstreamrecorder) {
474                 if (hstreamrecorder->streamrecorder) {
475                         debug_msg_t("streamrecordertest_get_attr_valid_intrange(%s)", attr_name);
476
477                         err = mm_streamrecorder_get_attribute_info(hstreamrecorder->streamrecorder, attr_name, &info);
478                         if (err != MM_ERROR_NONE) {
479                                 err_msg_t("streamrecordertest_get_attr_valid_intarray : Error(%x)!!",  err);
480                                 return FALSE;
481                         } else {
482                                 if (info.type == MM_STR_REC_ATTRS_TYPE_INT) {
483                                         if (info.validity_type == MM_STR_REC_ATTRS_VALID_TYPE_INT_RANGE) {
484                                                 *min = info.int_range.min;
485                                                 *max = info.int_range.max;
486                                                 debug_msg_t("INT RANGE - default : %d", info.int_range.def);
487                                                 return TRUE;
488                                         }
489                                 }
490
491                                 err_msg_t("streamrecordertest_get_attr_valid_intarray : Type mismatched!!");
492                                 return FALSE;
493                         }
494
495                 }
496
497                 debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder->streamrecorder)");
498         }
499
500         debug_msg_t("streamrecordertest_get_attr_valid_intarray(!hstreamrecorder)");
501         return FALSE;
502 }
503
504
505 void  get_me_out()
506 {
507 }
508
509 static void print_menu()
510 {
511         switch (hstreamrecorder->menu_state) {
512         case MENU_STATE_MAIN:
513                         g_print("\n\t=======================================\n");
514                         g_print("\t   Stream Recorder Menu \n");
515                         g_print("\t=======================================\n");
516                         if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
517                                 if (streamrecorder_get_state() <= STREAMRECORDER_CREATED) {
518                                         g_print("\t   '1' Start Recording\n");
519                                         g_print("\t   '2' Setting\n");
520                                         g_print("\t   '3' Print frame rate\n");
521                                         g_print("\t   'b' back\n");
522                                 } else if (streamrecorder_get_state() == STREAMRECORDER_STARTED) {
523                                         g_print("\t   'r' Resume\n");
524                                         g_print("\t   'c' Cancel Recording\n");
525                                         g_print("\t   's' Save\n");
526                                 }
527                         } else if (hstreamrecorder->mode == MODE_AUDIO) {
528                                 if (streamrecorder_get_state() <= STREAMRECORDER_CREATED) {
529                                         g_print("\t   '1' Start Recording\n");
530                                         g_print("\t   'b' back\n");
531                                 } else if (streamrecorder_get_state() == STREAMRECORDER_STARTED) {
532                                         g_print("\t   'r' Resume Recording\n");
533                                         g_print("\t   'c' Cancel Recording\n");
534                                         g_print("\t   's' Save Recording\n");
535                                 }
536                         }
537                 break;
538         case MENU_STATE_SETTING:
539                 g_print("\n\t=======================================\n");
540                 g_print("\t   Stream Recorder > Setting\n");
541                 g_print("\t=======================================\n");
542                 g_print("\t  >>>>>>>>>>>>>>>>>>>>>>>>>>>> [Stream Recorder]  \n");
543                 g_print("\t     'T' videobuffer type \n");
544                 g_print("\t     'F' videosource  format \n");
545                 g_print("\t     'A' video framerate \n");
546                 g_print("\t     'B' video bitrate \n");
547                 g_print("\t     'D' audio source format\n");
548                 g_print("\t     'I'  audio bitrate \n");
549                 g_print("\t     'S' audio samplerate \n");
550                 g_print("\t     'O' video encoder \n");
551                 g_print("\t     'C' audio encoder \n");
552                 g_print("\t     'N' audio channel count \n");
553                 g_print("\t     'm' file format\n");
554                 g_print("\t     'b'  back \n");
555                 g_print("\t=======================================\n");
556                 break;
557         default:
558                 warn_msg_t("unknow menu state !!\n");
559                 break;
560         }
561
562         return;
563 }
564
565 static void main_menu(gchar buf)
566 {
567         int err = 0;
568
569         if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
570                 if (streamrecorder_get_state() == STREAMRECORDER_CREATED) {
571                         switch (buf) {
572                         case '1': /* Start Recording */
573                                 g_print("*Recording start!\n");
574                                 video_stream_cb_cnt = 0;
575                                 audio_stream_cb_cnt = 0;
576
577                                 g_timer_reset(timer);
578                                 err = mm_streamrecorder_record(hstreamrecorder->streamrecorder);
579
580                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 1000, buffer, (640*480*3/2));
581                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 2000, buffer, (640*480*3/2));
582                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 3000, buffer, (640*480*3/2));
583                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 4000, buffer, (640*480*3/2));
584                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 5000, buffer, (640*480*3/2));
585                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 6000, buffer, (640*480*3/2));
586                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 7000, buffer, (640*480*3/2));
587                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 8000, buffer, (640*480*3/2));
588                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 9000, buffer, (640*480*3/2));
589                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 10000, buffer, (640*480*3/2));
590                                 mm_streamrecorder_push_stream_buffer(hstreamrecorder->streamrecorder, MM_STREAM_TYPE_VIDEO, 11000, buffer, (640*480*3/2));
591
592                                 if (err != MM_ERROR_NONE)
593                                         warn_msg_t("Rec start mm_streamrecorder_record 0x%x", err);
594
595                                 streamrecorder_set_state(STREAMRECORDER_STARTED);
596                                 break;
597
598                         case '2': /* Setting */
599                                 hstreamrecorder->menu_state = MENU_STATE_SETTING;
600                                 break;
601
602                         case '3': /* Print frame rate */
603                                 break;
604
605                         case 'b': /* back */
606                                 hstreamrecorder->menu_state = MENU_STATE_MAIN;
607                                 mode_change();
608                                 break;
609
610                         default:
611                                 g_print("\t Invalid input \n");
612                                 break;
613                         }
614                 } else if (streamrecorder_get_state() == STREAMRECORDER_STARTED) {
615                         switch (buf) {
616                         case 'r': /* Resume Recording */
617                                 g_print("*Resume!\n");
618                                 break;
619
620                         case 'c': /* Cancel */
621                                 g_print("*Cancel Recording !\n");
622                                 err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
623
624                                 if (err < 0)
625                                         warn_msg_t("Cancel recording mm_streamrecorder_cancel  = %x", err);
626
627                                 break;
628
629                         case 's': /* Save */
630                                 g_print("*Save Recording!\n");
631                                 g_timer_reset(timer);
632
633                                 err = mm_streamrecorder_commit(hstreamrecorder->streamrecorder);
634                                 streamrecorder_set_state(STREAMRECORDER_CREATED);
635
636                                 if (err < 0)
637                                         warn_msg_t("Save recording mm_streamrecorder_commit  = %x", err);
638
639                                 break;
640
641                         case 'n': /* Capture video snapshot */
642                                 break;
643
644                         default:
645                                 g_print("\t Invalid input \n");
646                                 break;
647                         } /* switch */
648                 } else {
649                         err_msg_t("Wrong streamrecorder state, check status!!");
650                 }
651         } else if (hstreamrecorder->mode == MODE_AUDIO) {
652                         switch (buf) {
653                         case '1': /* Start Recording */
654                                 g_print("*Recording start!\n");
655                                 g_timer_reset(timer);
656                                 err = mm_streamrecorder_record(hstreamrecorder->streamrecorder);
657
658                                 if (err < 0)
659                                         warn_msg_t("Rec start mm_streamrecorder_record  = %x", err);
660
661                                 break;
662
663                         case 'b': /* back */
664                                         hstreamrecorder->menu_state = MENU_STATE_MAIN;
665                                         mode_change();
666                                         break;
667
668                         default:
669                                 g_print("\t Invalid input \n");
670                                 break;
671                         }
672         } else {
673                 g_print("\t Invalid mode, back to upper menu \n");
674                 hstreamrecorder->menu_state = MENU_STATE_MAIN;
675                 mode_change();
676         }
677 }
678
679
680 static void setting_menu(gchar buf)
681 {
682         gboolean bret = FALSE;
683         int index_menu = 0;
684         int min = 0;
685         int max = 0;
686         int width_count = 0;
687         int height_count = 0;
688         int i = 0;
689         int count = 0;
690         int value = 0;
691         int* array = NULL;
692         int *width_array = NULL;
693         int *height_array = NULL;
694         char *err_attr_name = NULL;
695         str_xypair_t input_pair;
696         char filename[100];
697         int err = MM_ERROR_NONE;
698         int x = 0, y = 0, width = 0, height = 0;
699
700         if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
701                 switch (buf) {
702                 case '0':  /* Setting */
703                         g_print("*Select the preview resolution!\n");
704                         streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_WIDTH, &width_array, &width_count);
705                         streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_HEIGHT, &height_array, &height_count);
706
707                         if (width_count != height_count) {
708                                 err_msg_t("System has wrong information!!\n");
709                         } else if (width_count == 0) {
710                                 g_print("Not supported!!\n");
711                         } else {
712                                 flush_stdin();
713
714                                 for (i = 0; i < width_count; i++)
715                                         g_print("\t %d. %d*%d\n", i+1, width_array[i], height_array[i]);
716
717                                 err = scanf("%d", &index_menu);
718                                 if (err == EOF) {
719                                         printf("\nscanf error : errno %d\n", errno);
720                                 } else {
721                                         if (index_menu > 0 && index_menu <= width_count) {
722                                                 input_pair.x = width_array[index_menu-1];
723                                                 input_pair.y = height_array[index_menu-1];
724                                                 bret = streamrecordertest_set_attr_xypair(input_pair);
725                                         }
726                                 }
727                         }
728                         break;
729
730                 case '1': /* Setting > Capture Resolution setting */
731                         break;
732
733                 case 'r': /* Setting > Rotate input when recording */
734                         g_print("Not supported !! \n");
735                         break;
736
737                 case 'H': /* Setting > Hybrid mode */
738                         g_print("* Hybrid mode\n");
739
740                         g_print("\t 0. DISABLE\n");
741                         g_print("\t 1. ENABLE\n");
742
743                         flush_stdin();
744                         err = scanf("%d", &index_menu);
745
746                         if (index_menu < 0 || index_menu > 1)
747                                 g_print("Wrong INPUT[%d]!! \n", index_menu);
748
749                         break;
750
751                 case 'R': /*  Setting > Stream Recorder-rotation setting */
752                         g_print("*Stream Recorder-Rotation setting!\n");
753
754                         g_print("\t0.  0 degree\n");
755                         g_print("\t1.  90 degree\n");
756                         g_print("\t2.  180 degree\n");
757                         g_print("\t3.  270 degree\n");
758                         flush_stdin();
759                         err = scanf("%d", &index_menu);
760                         if (index_menu < 0 || index_menu > 3)
761                                 g_print("Wrong Input[%d] !!\n\n", index_menu);
762
763                         g_print("*Stream Recorder-Flip setting!\n");
764                         g_print("\t0.  NONE\n");
765                         g_print("\t1.  HORIZONTAL\n");
766                         g_print("\t2.  VERTICAL\n");
767                         g_print("\t3.  BOTH\n");
768                         flush_stdin();
769                         err = scanf("%d", &index_menu);
770                         if (index_menu < 0 || index_menu > 3)
771                                 g_print("Wrong Input[%d] !!\n\n", index_menu);
772
773                         break;
774
775                 case 'T': /* Setting > videobuffer-type setting */
776                         g_print("*videobuffer type  !\n");
777                         streamrecordertest_get_attr_valid_intrange("videobuffer-type", &min, &max);
778
779                         if (min >= max) {
780                                 g_print("Not supported !! \n");
781                         } else {
782                                 flush_stdin();
783                                 g_print("\n Select  videobuffer type (%d ~ %d)\n", min, max);
784                                 err = scanf("%d", &index_menu);
785                                 bret = streamrecordertest_set_attr_int("videobuffer-type", index_menu);
786                         }
787                         break;
788
789                 case 'F': /* Setting > videosource-format setting */
790                         g_print("*videosource  format  !\n");
791                         streamrecordertest_get_attr_valid_intrange("videosource-format", &min, &max);
792
793                         if (min >= max) {
794                                 g_print("Not supported !! \n");
795                         } else {
796                                 flush_stdin();
797                                 g_print("\n Select videosource-format (%d ~ %d)\n", min, max);
798                                 err = scanf("%d", &index_menu);
799                                 bret = streamrecordertest_set_attr_int("videosource-format", index_menu);
800                         }
801                         break;
802
803                 case 'A': /* Setting > video framerate setting */
804                         g_print("*video framerate  !\n");
805                         streamrecordertest_get_attr_valid_intrange("video-framerate", &min, &max);
806
807                         if (min >= max) {
808                                 g_print("Not supported !! \n");
809                         } else {
810                                 flush_stdin();
811                                 g_print("\n Select  video-framerate (%d ~ %d)\n", min, max);
812                                 err = scanf("%d", &index_menu);
813                                 bret = streamrecordertest_set_attr_int("video-framerate", index_menu);
814                         }
815                         break;
816
817                 case 'B': /* Setting > video bitrate setting */
818                         g_print("*video bitrate  !\n");
819                         streamrecordertest_get_attr_valid_intrange("video-bitrate", &min, &max);
820
821                         if (min >= max) {
822                                 g_print("Not supported !! \n");
823                         } else {
824                                 flush_stdin();
825                                 g_print("\n Select  video-bitrate (%d ~ %d)\n", min, max);
826                                 err = scanf("%d", &index_menu);
827                                 bret = streamrecordertest_set_attr_int("video-bitrate", index_menu);
828                         }
829                         break;
830
831                 case 'D': /* Setting > audio-source-format setting */
832                         g_print("*audio-source-format !\n");
833                         streamrecordertest_get_attr_valid_intrange("audio-source-format", &min, &max);
834
835                         if (min >= max) {
836                                 g_print("Not supported !! \n");
837                         } else {
838                                 flush_stdin();
839                                 g_print("\n Select  audio-source-format (%d ~ %d)\n", min, max);
840                                 err = scanf("%d", &index_menu);
841                                 bret = streamrecordertest_set_attr_int("audio-source-format", index_menu);
842                         }
843                         break;
844
845                 case 'I': /* Setting > audio-bitrate setting */
846                         g_print("*audio-bitrate !\n");
847                         streamrecordertest_get_attr_valid_intrange("audio-bitrate", &min, &max);
848
849                         if (min >= max) {
850                                 g_print("Not supported !! \n");
851                         } else {
852                                 flush_stdin();
853                                 g_print("\n Select  audio-bitrate (%d ~ %d)\n", min, max);
854                                 err = scanf("%d", &index_menu);
855                                 bret = streamrecordertest_set_attr_int("audio-bitrate", index_menu);
856                         }
857                         break;
858
859                 case 'S': /* Setting > audio-samplerate setting */
860                         g_print("*audio-samplerate !\n");
861                         streamrecordertest_get_attr_valid_intrange("audio-samplerate", &min, &max);
862
863                         if (min >= max) {
864                                 g_print("Not supported !! \n");
865                         } else {
866                                 flush_stdin();
867                                 g_print("\n Select  audio-samplerate (%d ~ %d)\n", min, max);
868                                 err = scanf("%d", &index_menu);
869                                 bret = streamrecordertest_set_attr_int("audio-samplerate", index_menu);
870                         }
871                         break;
872
873                 case 'O': /* Setting > video-encoder setting */
874                         g_print("*video-encoder!\n");
875                         streamrecordertest_get_attr_valid_intrange("video-encoder", &min, &max);
876
877                         if (min >= max) {
878                                 g_print("Not supported !! \n");
879                         } else {
880                                 flush_stdin();
881                                 g_print("\n Select  video-encoder (%d ~ %d)\n", min, max);
882                                 err = scanf("%d", &index_menu);
883                                 bret = streamrecordertest_set_attr_int("video-encoder", index_menu);
884                         }
885                         break;
886
887                 case 'C': /* Setting >audio-encoder setting */
888                         g_print("*audio-encoder!\n");
889                         streamrecordertest_get_attr_valid_intrange("audio-encoder", &min, &max);
890
891                         if (min >= max) {
892                                 g_print("Not supported !! \n");
893                         } else {
894                                 flush_stdin();
895                                 g_print("\n Select  audio-encoder (%d ~ %d)\n", min, max);
896                                 err = scanf("%d", &index_menu);
897                                 bret = streamrecordertest_set_attr_int("audio-encoder", index_menu);
898                         }
899                         break;
900
901                 case 'N': /* Setting >audio-channel-count setting */
902                         g_print("*audio-channel-count!\n");
903                         streamrecordertest_get_attr_valid_intrange("audio-channel-count", &min, &max);
904
905                         if (min >= max) {
906                                 g_print("Not supported !! \n");
907                         } else {
908                                 flush_stdin();
909                                 g_print("\n Select  audio-channel-count(%d ~ %d)\n", min, max);
910                                 err = scanf("%d", &index_menu);
911                                 bret = streamrecordertest_set_attr_int("audio-channel-count", index_menu);
912                         }
913                         break;
914
915                 case 'b': /* back */
916                         hstreamrecorder->menu_state = MENU_STATE_MAIN;
917                         break;
918
919                 default:
920                         g_print("\t Invalid input \n");
921                         break;
922                 }
923         } else {
924                 g_print("\t Invalid mode, back to upper menu \n");
925                 hstreamrecorder->menu_state = MENU_STATE_MAIN;
926         }
927 }
928
929
930 /**
931  * This function is to execute command.
932  *
933  * @param       channel [in]    1st parameter
934  *
935  * @return      This function returns TRUE/FALSE
936  * @remark
937  * @see
938  */
939 static gboolean cmd_input(GIOChannel *channel)
940 {
941         gchar *buf = NULL;
942         gsize read_size;
943         GError *g_error = NULL;
944
945         debug_msg_t("ENTER");
946
947         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
948         if (g_error) {
949                 debug_msg_t("g_io_channel_read_chars error");
950                 g_error_free(g_error);
951                 g_error = NULL;
952         }
953
954         if (buf) {
955                 g_strstrip(buf);
956
957                 debug_msg_t("Menu Status : %d", hstreamrecorder->menu_state);
958                 switch (hstreamrecorder->menu_state) {
959                 case MENU_STATE_MAIN:
960                         main_menu(buf[0]);
961                         break;
962                 case MENU_STATE_SETTING:
963                         setting_menu(buf[0]);
964                         break;
965                 default:
966                         break;
967                 }
968
969                 g_free(buf);
970                 buf = NULL;
971
972                 print_menu();
973         } else {
974                 debug_msg_t("No read input");
975         }
976
977         return TRUE;
978 }
979
980 /**
981  * This function is to initiate streamrecorder attributes .
982  *
983  * @param       type    [in]    image(capture)/video(recording) mode
984  *
985  * @return      This function returns TRUE/FALSE
986  * @remark
987  * @see         other functions
988  */
989 static gboolean init(int type)
990 {
991         MMHandleType str_handle = 0;
992
993         char *err_attr_name = NULL;
994         int video_codec = MM_VIDEO_CODEC_INVALID;
995         int audio_codec = MM_AUDIO_CODEC_INVALID;
996         int file_format = MM_FILE_FORMAT_INVALID;
997         int audio_enc = MM_AUDIO_CODEC_INVALID;
998         int channel = 0;
999         int v_bitrate = 0;
1000         int a_bitrate = 0;
1001         int video_width = 0;
1002         int video_height = 0;
1003         int video_fps = 0;
1004         int audio_samplerate = 0;
1005         int audio_src_format = 0;
1006         int video_src_format = 0;
1007         int rec_mode = 0;
1008         const char *filename = "/opt/usr/media/test.mp4";
1009
1010         if (!hstreamrecorder)
1011                 return FALSE;
1012
1013         if (!hstreamrecorder->streamrecorder)
1014                 return FALSE;
1015
1016         str_handle = (MMHandleType)(hstreamrecorder->streamrecorder);
1017
1018         /*================================================================================
1019                 Video capture mode
1020         *=================================================================================*/
1021         if (type == MODE_VIDEO_CAPTURE) {
1022                 video_codec = MM_VIDEO_CODEC_MPEG4;
1023                 /*audio_codec = MM_AUDIO_CODEC_AAC;*/
1024                 file_format = MM_FILE_FORMAT_MP4;
1025                 /*audio_enc = MM_AUDIO_CODEC_PCM;*/
1026                 /*channel = 1;
1027                 v_bitrate = 8000000;
1028                 /*a_bitrate = 64000;*/
1029                 video_width = 640;
1030                 video_height = 480;
1031                 video_fps = 30;
1032                 /*audio_samplerate = 48000;*/
1033                 /*audio_src_format = 2;*/
1034                 rec_mode = 0;
1035                 video_src_format = MM_STREAMRECORDER_INPUT_FORMAT_NV12;
1036                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1037                                                                 MMSTR_VIDEO_ENABLE,  TRUE,
1038                                                                 MMSTR_AUDIO_ENABLE,  FALSE,
1039                                                                 NULL);
1040
1041                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1042                                                                 MMSTR_VIDEO_ENCODER, video_codec,
1043                                                                 /*MMSTR_AUDIO_ENCODER,  audio_codec,*/
1044                                                                 MMSTR_FILE_FORMAT, file_format,
1045                                                                 MMSTR_VIDEO_BITRATE, v_bitrate,
1046                                                                 MMSTR_VIDEO_RESOLUTION_WIDTH , video_width,
1047                                                                 MMSTR_VIDEO_RESOLUTION_HEIGHT, video_height,
1048                                                                 MMSTR_VIDEO_FRAMERATE, video_fps,
1049                                                                 /*MMSTR_AUDIO_CHANNEL, channel,*/
1050                                                                 /*MMSTR_AUDIO_SAMPLERATE, audio_samplerate,*/
1051                                                                 /*MMSTR_AUDIO_BITRATE, a_bitrate,*/
1052                                                                 /*MMSTR_AUDIO_SOURCE_FORMAT, audio_src_format,*/
1053                                                                 MMSTR_VIDEO_SOURCE_FORMAT, video_src_format,
1054                                                                 MMSTR_RECORDER_MODE, rec_mode,
1055                                                                 NULL);
1056                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1057                                                                 MMSTR_FILENAME, filename, strlen(filename), NULL);
1058
1059
1060         }
1061         /*================================================================================
1062                 Audio mode
1063         *=================================================================================*/
1064         debug_msg_t("Init DONE.");
1065
1066         return TRUE;
1067 }
1068
1069 static gboolean init_handle()
1070 {
1071         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;  /* image(capture)/video(recording) mode */
1072         hstreamrecorder->isMultishot =  FALSE;
1073         hstreamrecorder->stillshot_count = 0;        /* total stillshot count */
1074         hstreamrecorder->multishot_count = 0;        /* total multishot count */
1075         hstreamrecorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME;  /* stored filename of  stillshot  */
1076         hstreamrecorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME;  /* stored filename of  multishot  */
1077         hstreamrecorder->menu_state = MENU_STATE_MAIN;
1078         hstreamrecorder->isMute = FALSE;
1079         hstreamrecorder->elapsed_time = 0;
1080         hstreamrecorder->fps = SRC_VIDEO_FRAME_RATE_15; /*SRC_VIDEO_FRAME_RATE_30;*/
1081
1082         return TRUE;
1083 }
1084 /**
1085  * This function is to change streamrecorder mode.
1086  *
1087  * @param       type    [in]    image(capture)/video(recording) mode
1088  *
1089  * @return      This function returns TRUE/FALSE
1090  * @remark
1091  * @see         other functions
1092  */
1093 static gboolean mode_change()
1094 {
1095         int err = MM_ERROR_NONE;
1096         int state = STREAMRECORDER_NONE;
1097         int device_count = 0;
1098         int facing_direction = 0;
1099         char media_type = '\0';
1100         char *evassink_name = NULL;
1101         bool check = FALSE;
1102
1103         state = streamrecorder_get_state();
1104         debug_msg_t("MMStreamrecorder State : %d", state);
1105         if (state != STREAMRECORDER_NULL) {
1106                 if ((state == STREAMRECORDER_STARTED)) {
1107                         debug_msg_t("mm_streamrecorder_cancel");
1108                         err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
1109
1110                         if (err < 0) {
1111                                 warn_msg_t("exit mm_streamrecorder_cancel  = %x", err);
1112                                 return FALSE;
1113                         }
1114                 }
1115
1116                 state = streamrecorder_get_state();
1117                 if (state == STREAMRECORDER_CREATED) {
1118                         debug_msg_t("mm_streamreorder_unrealize");
1119                         mm_streamrecorder_unrealize(hstreamrecorder->streamrecorder);
1120                         streamrecorder_set_state(STREAMRECORDER_NONE);
1121                 }
1122
1123                 state = streamrecorder_get_state();
1124                 if (state == STREAMRECORDER_NONE) {
1125                         debug_msg_t("mm_streamrecorder_destroy");
1126                         mm_streamrecorder_destroy(hstreamrecorder->streamrecorder);
1127
1128                         streamrecorder_set_state(STREAMRECORDER_NULL);
1129                 }
1130         }
1131
1132         init_handle();
1133         while (!check) {
1134                 g_print("\n\t=======================================\n");
1135                 g_print("\t   MM_STREAMRECORDER_TESTSUIT\n");
1136                 g_print("\t=======================================\n");
1137                 g_print("\t   '1' STREAM RECORDER CREATE\n");
1138                 g_print("\t   'q' Exit\n");
1139                 g_print("\t=======================================\n");
1140
1141                 g_print("\t  Enter the media type:\n\t");
1142
1143                 err = scanf("%c", &media_type);
1144
1145                 switch (media_type) {
1146                 case '1':
1147                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1148                         check = TRUE;
1149                         break;
1150                 case '2':
1151                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1152                         check = TRUE;
1153                         break;
1154                 case '3':
1155                         hstreamrecorder->mode = MODE_AUDIO;
1156                         check = TRUE;
1157                         break;
1158                 case '4':
1159                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1160                         check = TRUE;
1161                         break;
1162                 case 'q':
1163                         g_print("\t Quit streamrecorder Testsuite!!\n");
1164                         hstreamrecorder->mode = -1;
1165                         if (g_main_loop_is_running(g_loop))
1166                                 g_main_loop_quit(g_loop);
1167
1168                         return FALSE;
1169                 default:
1170                         g_print("\t Invalid media type(%d)\n", media_type);
1171                         continue;
1172                 }
1173         }
1174
1175         debug_msg_t("mm_streamrecorder_create");
1176         g_get_current_time(&previous);
1177         g_timer_reset(timer);
1178
1179         FILE *fp = NULL;
1180         size_t nread;
1181         fp = fopen("/opt/usr/media/test.nv12", "a+");
1182         if (!fp)
1183                 return -1;
1184         nread = fread(&buffer, sizeof(char), sizeof(buffer), fp);
1185         time_msg_t("mm_streamrecorder_create()  : nread %d, sizeof(buffer) %d", nread, sizeof(buffer));
1186         fclose(fp);
1187
1188         err = mm_streamrecorder_create(&hstreamrecorder->streamrecorder);
1189         time_msg_t("mm_streamrecorder_create()  : %12.6lfs", g_timer_elapsed(timer, NULL));
1190
1191         if (err != MM_ERROR_NONE) {
1192                 err_msg_t("mmstreamrecorder_create = %x", err);
1193                 return -1;
1194         } else {
1195
1196         }
1197
1198         debug_msg_t("evassink name[%s], device count[%d], facing direction[%d]", evassink_name, device_count, facing_direction);
1199
1200         if (!init(hstreamrecorder->mode)) {
1201                 err_msg_t("testsuite init() failed.");
1202                 return -1;
1203         }
1204
1205         debug_msg_t("mm_streamrecorder_realize");
1206
1207         g_timer_reset(timer);
1208
1209         err =  mm_streamrecorder_realize(hstreamrecorder->streamrecorder);
1210         streamrecorder_set_state(STREAMRECORDER_CREATED);
1211         time_msg_t("mm_streamrecorder_realize()  : %12.6lfs", g_timer_elapsed(timer, NULL));
1212         if (err != MM_ERROR_NONE) {
1213                 err_msg_t("mm_streamrecorder_realize  = %x", err);
1214                 return -1;
1215         }
1216
1217         g_timer_reset(timer);
1218
1219         g_get_current_time(&current);
1220         timersub(&current, &previous, &result);
1221         time_msg_t("streamrecorder Starting Time  : %ld.%lds", result.tv_sec, result.tv_usec);
1222
1223         return TRUE;
1224 }
1225
1226
1227 /**
1228  * This function is the example main function for mmstreamrecorder API.
1229  *
1230  * @param
1231  *
1232  * @return      This function returns 0.
1233  * @remark
1234  * @see         other functions
1235  */
1236 int main(int argc, char **argv)
1237 {
1238         int bret;
1239
1240         timer = g_timer_new();
1241
1242         gst_init(&argc, &argv);
1243
1244         time_msg_t("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
1245
1246         hstreamrecorder = (streamrecorder_handle_t *) g_malloc0(sizeof(streamrecorder_handle_t));
1247
1248         g_timer_reset(timer);
1249
1250         bret = mode_change();
1251         if (!bret)
1252                 return bret;
1253
1254         print_menu();
1255
1256         g_loop = g_main_loop_new(NULL, FALSE);
1257
1258         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1259         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1260
1261         debug_msg_t("RUN main loop");
1262
1263         g_main_loop_run(g_loop);
1264
1265         debug_msg_t("STOP main loop");
1266
1267         if (timer) {
1268                 g_timer_stop(timer);
1269                 g_timer_destroy(timer);
1270                 timer = NULL;
1271         }
1272
1273         g_free(hstreamrecorder);
1274         g_main_loop_unref(g_loop);
1275         g_io_channel_unref(stdin_channel);
1276
1277         return bret;
1278 }
1279
1280 /*EOF*/