Change muxer avmux_mp4 to avimux
[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         int video_codec = MM_VIDEO_CODEC_INVALID;
988         int file_format = MM_FILE_FORMAT_INVALID;
989         int v_bitrate = 0;
990         int video_width = 0;
991         int video_height = 0;
992         int video_fps = 0;
993         int video_src_format = 0;
994         int rec_mode = 0;
995         const char *filename = "/opt/usr/media/test.mp4";
996
997         if (!hstreamrecorder)
998                 return FALSE;
999
1000         if (!hstreamrecorder->streamrecorder)
1001                 return FALSE;
1002
1003         str_handle = (MMHandleType)(hstreamrecorder->streamrecorder);
1004
1005         /*================================================================================
1006                 Video capture mode
1007         *=================================================================================*/
1008         if (type == MODE_VIDEO_CAPTURE) {
1009                 video_codec = MM_VIDEO_CODEC_MPEG4;
1010                 /* audio_codec = MM_AUDIO_CODEC_AAC; */
1011                 file_format = MM_FILE_FORMAT_MP4;
1012                 /* audio_enc = MM_AUDIO_CODEC_PCM; */
1013                 /* channel = 1; */
1014                 /* v_bitrate = 8000000; */
1015                 /* a_bitrate = 64000; */
1016                 video_width = 640;
1017                 video_height = 480;
1018                 video_fps = 30;
1019                 /* audio_samplerate = 48000; */
1020                 /* audio_src_format = 2; */
1021                 rec_mode = 0;
1022                 video_src_format = MM_STREAMRECORDER_INPUT_FORMAT_NV12;
1023                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, NULL,
1024                                                                 MMSTR_VIDEO_ENABLE,  TRUE,
1025                                                                 MMSTR_AUDIO_ENABLE,  FALSE,
1026                                                                 NULL);
1027
1028                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, NULL,
1029                                                                 MMSTR_VIDEO_ENCODER, video_codec,
1030                                                                 /*MMSTR_AUDIO_ENCODER,  audio_codec,*/
1031                                                                 MMSTR_FILE_FORMAT, file_format,
1032                                                                 MMSTR_VIDEO_BITRATE, v_bitrate,
1033                                                                 MMSTR_VIDEO_RESOLUTION_WIDTH , video_width,
1034                                                                 MMSTR_VIDEO_RESOLUTION_HEIGHT, video_height,
1035                                                                 MMSTR_VIDEO_FRAMERATE, video_fps,
1036                                                                 /*MMSTR_AUDIO_CHANNEL, channel,*/
1037                                                                 /*MMSTR_AUDIO_SAMPLERATE, audio_samplerate,*/
1038                                                                 /*MMSTR_AUDIO_BITRATE, a_bitrate,*/
1039                                                                 /*MMSTR_AUDIO_SOURCE_FORMAT, audio_src_format,*/
1040                                                                 MMSTR_VIDEO_SOURCE_FORMAT, video_src_format,
1041                                                                 MMSTR_RECORDER_MODE, rec_mode,
1042                                                                 NULL);
1043                 mm_streamrecorder_set_attributes((MMHandleType)str_handle, NULL,
1044                                                                 MMSTR_FILENAME, filename, strlen(filename), NULL);
1045
1046
1047         }
1048         /*================================================================================
1049                 Audio mode
1050         *=================================================================================*/
1051         debug_msg_t("Init DONE.");
1052
1053         return TRUE;
1054 }
1055
1056 static gboolean init_handle()
1057 {
1058         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;  /* image(capture)/video(recording) mode */
1059         hstreamrecorder->isMultishot =  FALSE;
1060         hstreamrecorder->stillshot_count = 0;        /* total stillshot count */
1061         hstreamrecorder->multishot_count = 0;        /* total multishot count */
1062         hstreamrecorder->stillshot_filename = STILL_CAPTURE_FILE_PATH_NAME;  /* stored filename of  stillshot  */
1063         hstreamrecorder->multishot_filename = MULTI_CAPTURE_FILE_PATH_NAME;  /* stored filename of  multishot  */
1064         hstreamrecorder->menu_state = MENU_STATE_MAIN;
1065         hstreamrecorder->isMute = FALSE;
1066         hstreamrecorder->elapsed_time = 0;
1067         hstreamrecorder->fps = SRC_VIDEO_FRAME_RATE_15; /*SRC_VIDEO_FRAME_RATE_30;*/
1068
1069         return TRUE;
1070 }
1071 /**
1072  * This function is to change streamrecorder mode.
1073  *
1074  * @param       type    [in]    image(capture)/video(recording) mode
1075  *
1076  * @return      This function returns TRUE/FALSE
1077  * @remark
1078  * @see         other functions
1079  */
1080 static gboolean mode_change()
1081 {
1082         int err = MM_ERROR_NONE;
1083         int state = STREAMRECORDER_NONE;
1084         int device_count = 0;
1085         int facing_direction = 0;
1086         char media_type = '\0';
1087         char *evassink_name = NULL;
1088         bool check = FALSE;
1089
1090         state = streamrecorder_get_state();
1091         debug_msg_t("MMStreamrecorder State : %d", state);
1092         if (state != STREAMRECORDER_NULL) {
1093                 if ((state == STREAMRECORDER_STARTED)) {
1094                         debug_msg_t("mm_streamrecorder_cancel");
1095                         err = mm_streamrecorder_cancel(hstreamrecorder->streamrecorder);
1096
1097                         if (err < 0) {
1098                                 warn_msg_t("exit mm_streamrecorder_cancel  = %x", err);
1099                                 return FALSE;
1100                         }
1101                 }
1102
1103                 state = streamrecorder_get_state();
1104                 if (state == STREAMRECORDER_CREATED) {
1105                         debug_msg_t("mm_streamreorder_unrealize");
1106                         mm_streamrecorder_unrealize(hstreamrecorder->streamrecorder);
1107                         streamrecorder_set_state(STREAMRECORDER_NONE);
1108                 }
1109
1110                 state = streamrecorder_get_state();
1111                 if (state == STREAMRECORDER_NONE) {
1112                         debug_msg_t("mm_streamrecorder_destroy");
1113                         mm_streamrecorder_destroy(hstreamrecorder->streamrecorder);
1114
1115                         streamrecorder_set_state(STREAMRECORDER_NULL);
1116                 }
1117         }
1118
1119         init_handle();
1120         while (!check) {
1121                 g_print("\n\t=======================================\n");
1122                 g_print("\t   MM_STREAMRECORDER_TESTSUIT\n");
1123                 g_print("\t=======================================\n");
1124                 g_print("\t   '1' STREAM RECORDER CREATE\n");
1125                 g_print("\t   'q' Exit\n");
1126                 g_print("\t=======================================\n");
1127
1128                 g_print("\t  Enter the media type:\n\t");
1129
1130                 err = scanf("%c", &media_type);
1131
1132                 switch (media_type) {
1133                 case '1':
1134                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1135                         check = TRUE;
1136                         break;
1137                 case '2':
1138                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1139                         check = TRUE;
1140                         break;
1141                 case '3':
1142                         hstreamrecorder->mode = MODE_AUDIO;
1143                         check = TRUE;
1144                         break;
1145                 case '4':
1146                         hstreamrecorder->mode = MODE_VIDEO_CAPTURE;
1147                         check = TRUE;
1148                         break;
1149                 case 'q':
1150                         g_print("\t Quit streamrecorder Testsuite!!\n");
1151                         hstreamrecorder->mode = -1;
1152                         if (g_main_loop_is_running(g_loop))
1153                                 g_main_loop_quit(g_loop);
1154
1155                         return FALSE;
1156                 default:
1157                         g_print("\t Invalid media type(%d)\n", media_type);
1158                         continue;
1159                 }
1160         }
1161
1162         debug_msg_t("mm_streamrecorder_create");
1163         g_get_current_time(&previous);
1164         g_timer_reset(timer);
1165
1166         FILE *fp = NULL;
1167         size_t nread;
1168         fp = fopen("/opt/usr/media/test.nv12", "a+");
1169         if (!fp)
1170                 return -1;
1171         nread = fread(&buffer, sizeof(char), sizeof(buffer), fp);
1172         time_msg_t("mm_streamrecorder_create()  : nread %zu, sizeof(buffer) %zu", nread, sizeof(buffer));
1173         fclose(fp);
1174
1175         err = mm_streamrecorder_create(&hstreamrecorder->streamrecorder);
1176         time_msg_t("mm_streamrecorder_create()  : %12.6lfs", g_timer_elapsed(timer, NULL));
1177
1178         if (err != MM_ERROR_NONE) {
1179                 err_msg_t("mmstreamrecorder_create = %x", err);
1180                 return -1;
1181         } else {
1182
1183         }
1184
1185         debug_msg_t("evassink name[%s], device count[%d], facing direction[%d]", evassink_name, device_count, facing_direction);
1186
1187         if (!init(hstreamrecorder->mode)) {
1188                 err_msg_t("testsuite init() failed.");
1189                 return -1;
1190         }
1191
1192         debug_msg_t("mm_streamrecorder_realize");
1193
1194         g_timer_reset(timer);
1195
1196         err =  mm_streamrecorder_realize(hstreamrecorder->streamrecorder);
1197         streamrecorder_set_state(STREAMRECORDER_CREATED);
1198         time_msg_t("mm_streamrecorder_realize()  : %12.6lfs", g_timer_elapsed(timer, NULL));
1199         if (err != MM_ERROR_NONE) {
1200                 err_msg_t("mm_streamrecorder_realize  = %x", err);
1201                 return -1;
1202         }
1203
1204         g_timer_reset(timer);
1205
1206         g_get_current_time(&current);
1207         timersub(&current, &previous, &result);
1208         time_msg_t("streamrecorder Starting Time  : %ld.%lds", result.tv_sec, result.tv_usec);
1209
1210         return TRUE;
1211 }
1212
1213
1214 /**
1215  * This function is the example main function for mmstreamrecorder API.
1216  *
1217  * @param
1218  *
1219  * @return      This function returns 0.
1220  * @remark
1221  * @see         other functions
1222  */
1223 int main(int argc, char **argv)
1224 {
1225         int bret;
1226
1227         timer = g_timer_new();
1228
1229         gst_init(&argc, &argv);
1230
1231         time_msg_t("gst_init() : %12.6lfs", g_timer_elapsed(timer, NULL));
1232
1233         hstreamrecorder = (streamrecorder_handle_t *) g_malloc0(sizeof(streamrecorder_handle_t));
1234
1235         g_timer_reset(timer);
1236
1237         bret = mode_change();
1238         if (!bret)
1239                 return bret;
1240
1241         print_menu();
1242
1243         g_loop = g_main_loop_new(NULL, FALSE);
1244
1245         stdin_channel = g_io_channel_unix_new(fileno(stdin));/* read from stdin */
1246         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)cmd_input, NULL);
1247
1248         debug_msg_t("RUN main loop");
1249
1250         g_main_loop_run(g_loop);
1251
1252         debug_msg_t("STOP main loop");
1253
1254         if (timer) {
1255                 g_timer_stop(timer);
1256                 g_timer_destroy(timer);
1257                 timer = NULL;
1258         }
1259
1260         g_free(hstreamrecorder);
1261         g_main_loop_unref(g_loop);
1262         g_io_channel_unref(stdin_channel);
1263
1264         return bret;
1265 }
1266
1267 /*EOF*/