Check build warning
[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 *width_array = NULL;
690         int *height_array = NULL;
691         str_xypair_t input_pair;
692         int err = MM_ERROR_NONE;
693
694         if (hstreamrecorder->mode == MODE_VIDEO_CAPTURE) {
695                 switch (buf) {
696                 case '0':  /* Setting */
697                         g_print("*Select the preview resolution!\n");
698                         streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_WIDTH, &width_array, &width_count);
699                         streamrecordertest_get_attr_valid_intarray(MMSTR_VIDEO_RESOLUTION_HEIGHT, &height_array, &height_count);
700
701                         if (width_count != height_count) {
702                                 err_msg_t("System has wrong information!!\n");
703                         } else if (width_count == 0) {
704                                 g_print("Not supported!!\n");
705                         } else {
706                                 flush_stdin();
707
708                                 for (i = 0; i < width_count; i++)
709                                         g_print("\t %d. %d*%d\n", i+1, width_array[i], height_array[i]);
710
711                                 err = scanf("%d", &index_menu);
712                                 if (err == EOF) {
713                                         printf("\nscanf error : errno %d\n", errno);
714                                 } else {
715                                         if (index_menu > 0 && index_menu <= width_count) {
716                                                 input_pair.x = width_array[index_menu-1];
717                                                 input_pair.y = height_array[index_menu-1];
718                                                 bret = streamrecordertest_set_attr_xypair(input_pair);
719                                         }
720                                 }
721                         }
722                         break;
723
724                 case '1': /* Setting > Capture Resolution setting */
725                         break;
726
727                 case 'r': /* Setting > Rotate input when recording */
728                         g_print("Not supported !! \n");
729                         break;
730
731                 case 'H': /* Setting > Hybrid mode */
732                         g_print("* Hybrid mode\n");
733
734                         g_print("\t 0. DISABLE\n");
735                         g_print("\t 1. ENABLE\n");
736
737                         flush_stdin();
738                         err = scanf("%d", &index_menu);
739
740                         if (index_menu < 0 || index_menu > 1)
741                                 g_print("Wrong INPUT[%d]!! \n", index_menu);
742
743                         break;
744
745                 case 'R': /*  Setting > Stream Recorder-rotation setting */
746                         g_print("*Stream Recorder-Rotation setting!\n");
747
748                         g_print("\t0.  0 degree\n");
749                         g_print("\t1.  90 degree\n");
750                         g_print("\t2.  180 degree\n");
751                         g_print("\t3.  270 degree\n");
752                         flush_stdin();
753                         err = scanf("%d", &index_menu);
754                         if (index_menu < 0 || index_menu > 3)
755                                 g_print("Wrong Input[%d] !!\n\n", index_menu);
756
757                         g_print("*Stream Recorder-Flip setting!\n");
758                         g_print("\t0.  NONE\n");
759                         g_print("\t1.  HORIZONTAL\n");
760                         g_print("\t2.  VERTICAL\n");
761                         g_print("\t3.  BOTH\n");
762                         flush_stdin();
763                         err = scanf("%d", &index_menu);
764                         if (index_menu < 0 || index_menu > 3)
765                                 g_print("Wrong Input[%d] !!\n\n", index_menu);
766
767                         break;
768
769                 case 'T': /* Setting > videobuffer-type setting */
770                         g_print("*videobuffer type  !\n");
771                         streamrecordertest_get_attr_valid_intrange("videobuffer-type", &min, &max);
772
773                         if (min >= max) {
774                                 g_print("Not supported !! \n");
775                         } else {
776                                 flush_stdin();
777                                 g_print("\n Select  videobuffer type (%d ~ %d)\n", min, max);
778                                 err = scanf("%d", &index_menu);
779                                 bret = streamrecordertest_set_attr_int("videobuffer-type", index_menu);
780                         }
781                         break;
782
783                 case 'F': /* Setting > videosource-format setting */
784                         g_print("*videosource  format  !\n");
785                         streamrecordertest_get_attr_valid_intrange("videosource-format", &min, &max);
786
787                         if (min >= max) {
788                                 g_print("Not supported !! \n");
789                         } else {
790                                 flush_stdin();
791                                 g_print("\n Select videosource-format (%d ~ %d)\n", min, max);
792                                 err = scanf("%d", &index_menu);
793                                 bret = streamrecordertest_set_attr_int("videosource-format", index_menu);
794                         }
795                         break;
796
797                 case 'A': /* Setting > video framerate setting */
798                         g_print("*video framerate  !\n");
799                         streamrecordertest_get_attr_valid_intrange("video-framerate", &min, &max);
800
801                         if (min >= max) {
802                                 g_print("Not supported !! \n");
803                         } else {
804                                 flush_stdin();
805                                 g_print("\n Select  video-framerate (%d ~ %d)\n", min, max);
806                                 err = scanf("%d", &index_menu);
807                                 bret = streamrecordertest_set_attr_int("video-framerate", index_menu);
808                         }
809                         break;
810
811                 case 'B': /* Setting > video bitrate setting */
812                         g_print("*video bitrate  !\n");
813                         streamrecordertest_get_attr_valid_intrange("video-bitrate", &min, &max);
814
815                         if (min >= max) {
816                                 g_print("Not supported !! \n");
817                         } else {
818                                 flush_stdin();
819                                 g_print("\n Select  video-bitrate (%d ~ %d)\n", min, max);
820                                 err = scanf("%d", &index_menu);
821                                 bret = streamrecordertest_set_attr_int("video-bitrate", index_menu);
822                         }
823                         break;
824
825                 case 'D': /* Setting > audio-source-format setting */
826                         g_print("*audio-source-format !\n");
827                         streamrecordertest_get_attr_valid_intrange("audio-source-format", &min, &max);
828
829                         if (min >= max) {
830                                 g_print("Not supported !! \n");
831                         } else {
832                                 flush_stdin();
833                                 g_print("\n Select  audio-source-format (%d ~ %d)\n", min, max);
834                                 err = scanf("%d", &index_menu);
835                                 bret = streamrecordertest_set_attr_int("audio-source-format", index_menu);
836                         }
837                         break;
838
839                 case 'I': /* Setting > audio-bitrate setting */
840                         g_print("*audio-bitrate !\n");
841                         streamrecordertest_get_attr_valid_intrange("audio-bitrate", &min, &max);
842
843                         if (min >= max) {
844                                 g_print("Not supported !! \n");
845                         } else {
846                                 flush_stdin();
847                                 g_print("\n Select  audio-bitrate (%d ~ %d)\n", min, max);
848                                 err = scanf("%d", &index_menu);
849                                 bret = streamrecordertest_set_attr_int("audio-bitrate", index_menu);
850                         }
851                         break;
852
853                 case 'S': /* Setting > audio-samplerate setting */
854                         g_print("*audio-samplerate !\n");
855                         streamrecordertest_get_attr_valid_intrange("audio-samplerate", &min, &max);
856
857                         if (min >= max) {
858                                 g_print("Not supported !! \n");
859                         } else {
860                                 flush_stdin();
861                                 g_print("\n Select  audio-samplerate (%d ~ %d)\n", min, max);
862                                 err = scanf("%d", &index_menu);
863                                 bret = streamrecordertest_set_attr_int("audio-samplerate", index_menu);
864                         }
865                         break;
866
867                 case 'O': /* Setting > video-encoder setting */
868                         g_print("*video-encoder!\n");
869                         streamrecordertest_get_attr_valid_intrange("video-encoder", &min, &max);
870
871                         if (min >= max) {
872                                 g_print("Not supported !! \n");
873                         } else {
874                                 flush_stdin();
875                                 g_print("\n Select  video-encoder (%d ~ %d)\n", min, max);
876                                 err = scanf("%d", &index_menu);
877                                 bret = streamrecordertest_set_attr_int("video-encoder", index_menu);
878                         }
879                         break;
880
881                 case 'C': /* Setting >audio-encoder setting */
882                         g_print("*audio-encoder!\n");
883                         streamrecordertest_get_attr_valid_intrange("audio-encoder", &min, &max);
884
885                         if (min >= max) {
886                                 g_print("Not supported !! \n");
887                         } else {
888                                 flush_stdin();
889                                 g_print("\n Select  audio-encoder (%d ~ %d)\n", min, max);
890                                 err = scanf("%d", &index_menu);
891                                 bret = streamrecordertest_set_attr_int("audio-encoder", index_menu);
892                         }
893                         break;
894
895                 case 'N': /* Setting >audio-channel-count setting */
896                         g_print("*audio-channel-count!\n");
897                         streamrecordertest_get_attr_valid_intrange("audio-channel-count", &min, &max);
898
899                         if (min >= max) {
900                                 g_print("Not supported !! \n");
901                         } else {
902                                 flush_stdin();
903                                 g_print("\n Select  audio-channel-count(%d ~ %d)\n", min, max);
904                                 err = scanf("%d", &index_menu);
905                                 bret = streamrecordertest_set_attr_int("audio-channel-count", index_menu);
906                         }
907                         break;
908
909                 case 'b': /* back */
910                         hstreamrecorder->menu_state = MENU_STATE_MAIN;
911                         break;
912
913                 default:
914                         g_print("\t Invalid input \n");
915                         break;
916                 }
917         } else {
918                 g_print("\t Invalid mode, back to upper menu \n");
919                 hstreamrecorder->menu_state = MENU_STATE_MAIN;
920         }
921 }
922
923
924 /**
925  * This function is to execute command.
926  *
927  * @param       channel [in]    1st parameter
928  *
929  * @return      This function returns TRUE/FALSE
930  * @remark
931  * @see
932  */
933 static gboolean cmd_input(GIOChannel *channel)
934 {
935         gchar *buf = NULL;
936         gsize read_size;
937         GError *g_error = NULL;
938
939         debug_msg_t("ENTER");
940
941         g_io_channel_read_line(channel, &buf, &read_size, NULL, &g_error);
942         if (g_error) {
943                 debug_msg_t("g_io_channel_read_chars error");
944                 g_error_free(g_error);
945                 g_error = NULL;
946         }
947
948         if (buf) {
949                 g_strstrip(buf);
950
951                 debug_msg_t("Menu Status : %d", hstreamrecorder->menu_state);
952                 switch (hstreamrecorder->menu_state) {
953                 case MENU_STATE_MAIN:
954                         main_menu(buf[0]);
955                         break;
956                 case MENU_STATE_SETTING:
957                         setting_menu(buf[0]);
958                         break;
959                 default:
960                         break;
961                 }
962
963                 g_free(buf);
964                 buf = NULL;
965
966                 print_menu();
967         } else {
968                 debug_msg_t("No read input");
969         }
970
971         return TRUE;
972 }
973
974 /**
975  * This function is to initiate streamrecorder attributes .
976  *
977  * @param       type    [in]    image(capture)/video(recording) mode
978  *
979  * @return      This function returns TRUE/FALSE
980  * @remark
981  * @see         other functions
982  */
983 static gboolean init(int type)
984 {
985         MMHandleType str_handle = 0;
986
987         char *err_attr_name = NULL;
988         int video_codec = MM_VIDEO_CODEC_INVALID;
989         int file_format = MM_FILE_FORMAT_INVALID;
990         int v_bitrate = 0;
991         int video_width = 0;
992         int video_height = 0;
993         int video_fps = 0;
994         int video_src_format = 0;
995         int rec_mode = 0;
996         const char *filename = "/opt/usr/media/test.mp4";
997
998         if (!hstreamrecorder)
999                 return FALSE;
1000
1001         if (!hstreamrecorder->streamrecorder)
1002                 return FALSE;
1003
1004         str_handle = (MMHandleType)(hstreamrecorder->streamrecorder);
1005
1006         /*================================================================================
1007                 Video capture mode
1008         *=================================================================================*/
1009         if (type == MODE_VIDEO_CAPTURE) {
1010                 video_codec = MM_VIDEO_CODEC_MPEG4;
1011                 /* audio_codec = MM_AUDIO_CODEC_AAC; */
1012                 file_format = MM_FILE_FORMAT_MP4;
1013                 /* audio_enc = MM_AUDIO_CODEC_PCM; */
1014                 /* channel = 1; */
1015                 /* v_bitrate = 8000000; */
1016                 /* a_bitrate = 64000; */
1017                 video_width = 640;
1018                 video_height = 480;
1019                 video_fps = 30;
1020                 /* audio_samplerate = 48000; */
1021                 /* audio_src_format = 2; */
1022                 rec_mode = 0;
1023                 video_src_format = MM_STREAMRECORDER_INPUT_FORMAT_NV12;
1024                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1025                                                                 MMSTR_VIDEO_ENABLE,  TRUE,
1026                                                                 MMSTR_AUDIO_ENABLE,  FALSE,
1027                                                                 NULL);
1028
1029                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1030                                                                 MMSTR_VIDEO_ENCODER, video_codec,
1031                                                                 /*MMSTR_AUDIO_ENCODER,  audio_codec,*/
1032                                                                 MMSTR_FILE_FORMAT, file_format,
1033                                                                 MMSTR_VIDEO_BITRATE, v_bitrate,
1034                                                                 MMSTR_VIDEO_RESOLUTION_WIDTH , video_width,
1035                                                                 MMSTR_VIDEO_RESOLUTION_HEIGHT, video_height,
1036                                                                 MMSTR_VIDEO_FRAMERATE, video_fps,
1037                                                                 /*MMSTR_AUDIO_CHANNEL, channel,*/
1038                                                                 /*MMSTR_AUDIO_SAMPLERATE, audio_samplerate,*/
1039                                                                 /*MMSTR_AUDIO_BITRATE, a_bitrate,*/
1040                                                                 /*MMSTR_AUDIO_SOURCE_FORMAT, audio_src_format,*/
1041                                                                 MMSTR_VIDEO_SOURCE_FORMAT, video_src_format,
1042                                                                 MMSTR_RECORDER_MODE, rec_mode,
1043                                                                 NULL);
1044                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, &err_attr_name,
1045                                                                 MMSTR_FILENAME, filename, strlen(filename), NULL);
1046
1047
1048         }
1049         /*================================================================================
1050                 Audio mode
1051         *=================================================================================*/
1052         debug_msg_t("Init DONE.");
1053
1054         return TRUE;
1055 }
1056
1057 static gboolean init_handle()
1058 {
1059         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;  /* image(capture)/video(recording) mode */
1060         hstreamrecorder->isMultishot =  FALSE;
1061         hstreamrecorder->stillshot_count = 0;        /* total stillshot count */
1062         hstreamrecorder->multishot_count = 0;        /* total multishot count */
1063         hstreamrecorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME;  /* stored filename of  stillshot  */
1064         hstreamrecorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME;  /* stored filename of  multishot  */
1065         hstreamrecorder->menu_state = MENU_STATE_MAIN;
1066         hstreamrecorder->isMute = FALSE;
1067         hstreamrecorder->elapsed_time = 0;
1068         hstreamrecorder->fps = SRC_VIDEO_FRAME_RATE_15; /*SRC_VIDEO_FRAME_RATE_30;*/
1069
1070         return TRUE;
1071 }
1072 /**
1073  * This function is to change streamrecorder mode.
1074  *
1075  * @param       type    [in]    image(capture)/video(recording) mode
1076  *
1077  * @return      This function returns TRUE/FALSE
1078  * @remark
1079  * @see         other functions
1080  */
1081 static gboolean mode_change()
1082 {
1083         int err = MM_ERROR_NONE;
1084         int state = STREAMRECORDER_NONE;
1085         int device_count = 0;
1086         int facing_direction = 0;
1087         char media_type = '\0';
1088         char *evassink_name = NULL;
1089         bool check = FALSE;
1090
1091         state = streamrecorder_get_state();
1092         debug_msg_t("MMStreamrecorder State : %d", state);
1093         if (state != STREAMRECORDER_NULL) {
1094                 if ((state == STREAMRECORDER_STARTED)) {
1095                         debug_msg_t("mm_streamrecorder_cancel");
1096                         err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
1097
1098                         if (err < 0) {
1099                                 warn_msg_t("exit mm_streamrecorder_cancel  = %x", err);
1100                                 return FALSE;
1101                         }
1102                 }
1103
1104                 state = streamrecorder_get_state();
1105                 if (state == STREAMRECORDER_CREATED) {
1106                         debug_msg_t("mm_streamreorder_unrealize");
1107                         mm_streamrecorder_unrealize(hstreamrecorder->streamrecorder);
1108                         streamrecorder_set_state(STREAMRECORDER_NONE);
1109                 }
1110
1111                 state = streamrecorder_get_state();
1112                 if (state == STREAMRECORDER_NONE) {
1113                         debug_msg_t("mm_streamrecorder_destroy");
1114                         mm_streamrecorder_destroy(hstreamrecorder->streamrecorder);
1115
1116                         streamrecorder_set_state(STREAMRECORDER_NULL);
1117                 }
1118         }
1119
1120         init_handle();
1121         while (!check) {
1122                 g_print("\n\t=======================================\n");
1123                 g_print("\t   MM_STREAMRECORDER_TESTSUIT\n");
1124                 g_print("\t=======================================\n");
1125                 g_print("\t   '1' STREAM RECORDER CREATE\n");
1126                 g_print("\t   'q' Exit\n");
1127                 g_print("\t=======================================\n");
1128
1129                 g_print("\t  Enter the media type:\n\t");
1130
1131                 err = scanf("%c", &media_type);
1132
1133                 switch (media_type) {
1134                 case '1':
1135                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1136                         check = TRUE;
1137                         break;
1138                 case '2':
1139                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1140                         check = TRUE;
1141                         break;
1142                 case '3':
1143                         hstreamrecorder->mode = MODE_AUDIO;
1144                         check = TRUE;
1145                         break;
1146                 case '4':
1147                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1148                         check = TRUE;
1149                         break;
1150                 case 'q':
1151                         g_print("\t Quit streamrecorder Testsuite!!\n");
1152                         hstreamrecorder->mode = -1;
1153                         if (g_main_loop_is_running(g_loop))
1154                                 g_main_loop_quit(g_loop);
1155
1156                         return FALSE;
1157                 default:
1158                         g_print("\t Invalid media type(%d)\n", media_type);
1159                         continue;
1160                 }
1161         }
1162
1163         debug_msg_t("mm_streamrecorder_create");
1164         g_get_current_time(&previous);
1165         g_timer_reset(timer);
1166
1167         FILE *fp = NULL;
1168         size_t nread;
1169         fp = fopen("/opt/usr/media/test.nv12", "a+");
1170         if (!fp)
1171                 return -1;
1172         nread = fread(&buffer, sizeof(char), sizeof(buffer), fp);
1173         time_msg_t("mm_streamrecorder_create()  : nread %d, sizeof(buffer) %d", nread, sizeof(buffer));
1174         fclose(fp);
1175
1176         err = mm_streamrecorder_create(&hstreamrecorder->streamrecorder);
1177         time_msg_t("mm_streamrecorder_create()  : %12.6lfs", g_timer_elapsed(timer, NULL));
1178
1179         if (err != MM_ERROR_NONE) {
1180                 err_msg_t("mmstreamrecorder_create = %x", err);
1181                 return -1;
1182         } else {
1183
1184         }
1185
1186         debug_msg_t("evassink name[%s], device count[%d], facing direction[%d]", evassink_name, device_count, facing_direction);
1187
1188         if (!init(hstreamrecorder->mode)) {
1189                 err_msg_t("testsuite init() failed.");
1190                 return -1;
1191         }
1192
1193         debug_msg_t("mm_streamrecorder_realize");
1194
1195         g_timer_reset(timer);
1196
1197         err =  mm_streamrecorder_realize(hstreamrecorder->streamrecorder);
1198         streamrecorder_set_state(STREAMRECORDER_CREATED);
1199         time_msg_t("mm_streamrecorder_realize()  : %12.6lfs", g_timer_elapsed(timer, NULL));
1200         if (err != MM_ERROR_NONE) {
1201                 err_msg_t("mm_streamrecorder_realize  = %x", err);
1202                 return -1;
1203         }
1204
1205         g_timer_reset(timer);
1206
1207         g_get_current_time(&current);
1208         timersub(&current, &previous, &result);
1209         time_msg_t("streamrecorder Starting Time  : %ld.%lds", result.tv_sec, result.tv_usec);
1210
1211         return TRUE;
1212 }
1213
1214
1215 /**
1216  * This function is the example main function for mmstreamrecorder API.
1217  *
1218  * @param
1219  *
1220  * @return      This function returns 0.
1221  * @remark
1222  * @see         other functions
1223  */
1224 int main(int argc, char **argv)
1225 {
1226         int bret;
1227
1228         timer = g_timer_new();
1229
1230         gst_init(&argc, &argv);
1231
1232         time_msg_t("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
1233
1234         hstreamrecorder = (streamrecorder_handle_t *) g_malloc0(sizeof(streamrecorder_handle_t));
1235
1236         g_timer_reset(timer);
1237
1238         bret = mode_change();
1239         if (!bret)
1240                 return bret;
1241
1242         print_menu();
1243
1244         g_loop = g_main_loop_new(NULL, FALSE);
1245
1246         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1247         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1248
1249         debug_msg_t("RUN main loop");
1250
1251         g_main_loop_run(g_loop);
1252
1253         debug_msg_t("STOP main loop");
1254
1255         if (timer) {
1256                 g_timer_stop(timer);
1257                 g_timer_destroy(timer);
1258                 timer = NULL;
1259         }
1260
1261         g_free(hstreamrecorder);
1262         g_main_loop_unref(g_loop);
1263         g_io_channel_unref(stdin_channel);
1264
1265         return bret;
1266 }
1267
1268 /*EOF*/