[svn r632] Added new LiveTV test case.
13 static GMainLoop *mainloop = NULL;
15 static gchar* input_file = NULL;
16 static gchar* video_encode = NULL;
17 static gchar* video_opts = NULL;
18 static gdouble video_fps = 0.0;
19 static gint video_rate = 0;
20 static gint video_width = 0;
21 static gint video_height = 0;
22 static gchar* audio_encode = NULL;
23 static gchar* audio_opts = NULL;
24 static double audio_rate = 0.0;
25 static gchar* mux_name = NULL;
26 static gchar* output_uri = NULL;
30 _mencoder_eos_cb (GMencoder *mencoder, gpointer data)
33 g_main_loop_quit ((GMainLoop *) data);
37 _mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data)
39 g_print ("Error: %s\n", msg);
40 g_main_loop_quit ((GMainLoop *) data);
44 _io_channel_cb (GIOChannel *ch,
45 GIOCondition condition,
48 GString *cmd = g_string_new ("");
49 g_io_channel_read_line_string (ch, cmd, NULL, NULL);
51 if (strcmp (cmd->str, "PLAY\n") == 0) {
52 g_mencoder_play_stream (G_MENCODER (data));
53 } else if (strcmp (cmd->str, "PAUSE\n") == 0) {
54 g_mencoder_pause_stream (G_MENCODER (data));
55 } else if (strcmp (cmd->str, "STOP\n") == 0) {
56 g_mencoder_close_stream (G_MENCODER (data));
57 } else if (strcmp (cmd->str, "QUIT\n") == 0) {
58 g_mencoder_close_stream (G_MENCODER (data));
59 g_main_loop_quit (mainloop);
61 g_string_free (cmd, TRUE);
66 main (int argc, char** argv)
68 GMencoder *coder = NULL;
75 GOptionContext *context;
76 static const GOptionEntry options [] = {
77 {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file, "Input File", NULL},
78 {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, "GstElementName for used to video encode", NULL},
79 {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, "Properties to set on video element", NULL},
80 {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, "Video FPS", NULL},
81 {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, "Video rate", NULL},
82 {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, "Video width", NULL},
83 {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, "Video height", NULL},
84 {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, "GstElementName for use to audio encode", NULL},
85 {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, "Properties to set on audio element", NULL},
86 {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, "Audio rate", NULL},
87 {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name, "GstElementName for use to mux file", NULL},
88 {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri, "Uri to output", NULL},
94 mainloop = g_main_loop_new (NULL, FALSE);
96 g_set_prgname ("gmemcoder");
97 context = g_option_context_new (NULL);
98 g_option_context_set_help_enabled (context, TRUE);
99 g_option_context_add_main_entries (context, options, NULL);
100 g_option_context_add_group (context, gst_init_get_option_group ());
101 g_option_context_parse (context, &argc, &argv, NULL);
103 gst_init (&argc, &argv);
105 if (output_uri == NULL) {
106 g_print ("You need specify output-uri.\nTry --help for more information.\n");
110 if (input_file == NULL) {
111 g_print ("You need specify input file\nTry --help for more information.\n");
114 coder = g_mencoder_new ();
115 ch = g_io_channel_unix_new (0);
117 aopts = g_strsplit (audio_opts, ",", 0);
118 vopts = g_strsplit (video_opts, ",", 0);
120 g_mencoder_setup_stream (coder,
122 video_encode, vopts, video_fps, video_rate, video_width, video_height,
123 audio_encode, aopts, audio_rate,
126 files = g_strsplit (input_file, ",", 0);
127 for (i=0; i < g_strv_length (files); i++) {
128 if (!g_mencoder_append_uri (coder, files[i])) {
129 g_debug ("Invalid uri: %s", files[i]);
138 g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder);
140 g_signal_connect (G_OBJECT (coder),
142 G_CALLBACK (_mencoder_eos_cb),
145 g_signal_connect (G_OBJECT (coder),
147 G_CALLBACK (_mencoder_error_cb),
150 g_mencoder_play_stream (coder);
152 g_debug ("RUNNING..");
153 g_main_loop_run (mainloop);
155 g_mencoder_close_stream (coder);
156 g_object_unref (coder);