diff -r bf9dac4bdc5d -r 8ee634511c1e gmyth-stream/gmemcoder/src/main.c --- a/gmyth-stream/gmemcoder/src/main.c Tue Jun 12 22:13:46 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/main.c Thu Jun 14 18:22:32 2007 +0100 @@ -12,183 +12,187 @@ static GMainLoop *mainloop = NULL; /* Options */ -static gchar* input_file = NULL; -static gchar* video_encode = NULL; -static gchar* video_opts = NULL; -static gdouble video_fps = 0.0; -static gint video_rate = 0; -static gint video_width = 0; -static gint video_height = 0; -static gchar* audio_encode = NULL; -static gchar* audio_opts = NULL; -static double audio_rate = 0.0; -static gchar* mux_name = NULL; -static gchar* output_uri = NULL; +static gchar *input_file = NULL; +static gchar *video_encode = NULL; +static gchar *video_opts = NULL; +static gdouble video_fps = 0.0; +static gint video_rate = 0; +static gint video_width = 0; +static gint video_height = 0; +static gchar *audio_encode = NULL; +static gchar *audio_opts = NULL; +static double audio_rate = 0.0; +static gchar *mux_name = NULL; +static gchar *output_uri = NULL; static gboolean -_quit (gpointer data) +_quit(gpointer data) { - g_object_unref (data); - g_main_loop_quit (mainloop); - return FALSE; + g_object_unref(data); + g_main_loop_quit(mainloop); + return FALSE; } static void -_mencoder_eos_cb (GMencoder *mencoder, gpointer data) +_mencoder_eos_cb(GMencoder * mencoder, gpointer data) { - g_print ("EOS\n"); - g_idle_add (_quit, mencoder); + g_print("EOS\n"); + g_idle_add(_quit, mencoder); } static void -_mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data) +_mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data) { - g_print ("Error: %s\n", msg); - g_idle_add (_quit, mencoder); + g_print("Error: %s\n", msg); + g_idle_add(_quit, mencoder); } static gboolean -_io_channel_cb (GIOChannel *ch, - GIOCondition condition, - gpointer data) +_io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data) { - GString *cmd = g_string_new (""); - g_io_channel_read_line_string (ch, cmd, NULL, NULL); + GString *cmd = g_string_new(""); + g_io_channel_read_line_string(ch, cmd, NULL, NULL); - if (strcmp (cmd->str, "PLAY\n") == 0) { - g_mencoder_play_stream (G_MENCODER (data)); - } else if (strcmp (cmd->str, "PAUSE\n") == 0) { - g_mencoder_pause_stream (G_MENCODER (data)); - } else if (strcmp (cmd->str, "STOP\n") == 0) { - g_mencoder_close_stream (G_MENCODER (data)); - } else if (strcmp (cmd->str, "QUIT\n") == 0) { - g_mencoder_close_stream (G_MENCODER (data)); - g_main_loop_quit (mainloop); - } - g_string_free (cmd, TRUE); - return TRUE; + if (strcmp(cmd->str, "PLAY\n") == 0) + { + g_mencoder_play_stream(G_MENCODER(data)); + } + else if (strcmp(cmd->str, "PAUSE\n") == 0) + { + g_mencoder_pause_stream(G_MENCODER(data)); + } + else if (strcmp(cmd->str, "STOP\n") == 0) + { + g_mencoder_close_stream(G_MENCODER(data)); + } + else if (strcmp(cmd->str, "QUIT\n") == 0) + { + g_mencoder_close_stream(G_MENCODER(data)); + g_main_loop_quit(mainloop); + } + g_string_free(cmd, TRUE); + return TRUE; } int -main (int argc, char** argv) +main(int argc, char **argv) { - GMencoder *coder = NULL; - GIOChannel *ch; - gchar **vopts; - gchar **aopts; - gchar **files; - gint i; + GMencoder *coder = NULL; + GIOChannel *ch; + gchar **vopts; + gchar **aopts; + gchar **files; + gint i; - GOptionContext *context; - static const GOptionEntry options [] = { - {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file, - "Input File", NULL}, + GOptionContext *context; + static const GOptionEntry options[] = { + {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file, + "Input File", NULL}, - {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, - "GstElementName for used to video encode", NULL}, + {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, + "GstElementName for used to video encode", NULL}, - {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, - "Properties to set on video element", NULL}, + {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, + "Properties to set on video element", NULL}, - {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, - "Video FPS", NULL}, + {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, + "Video FPS", NULL}, - {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, - "Video rate", NULL}, + {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, + "Video rate", NULL}, - {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, - "Video width", NULL}, + {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, + "Video width", NULL}, - {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, - "Video height", NULL}, + {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, + "Video height", NULL}, - {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, - "GstElementName for use to audio encode", NULL}, + {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, + "GstElementName for use to audio encode", NULL}, - {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, - "Properties to set on audio element", NULL}, + {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, + "Properties to set on audio element", NULL}, - {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, - "Audio rate", NULL}, + {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, + "Audio rate", NULL}, - {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name, - "GstElementName for use to mux file", NULL}, + {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name, + "GstElementName for use to mux file", NULL}, - {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri, - "Uri to output", NULL}, + {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri, + "Uri to output", NULL}, - { NULL } - }; + {NULL} + }; - g_type_init (); - g_thread_init (NULL); - mainloop = g_main_loop_new (NULL, FALSE); + g_type_init(); + g_thread_init(NULL); + mainloop = g_main_loop_new(NULL, FALSE); - g_set_prgname ("gmemcoder"); - context = g_option_context_new (NULL); - g_option_context_set_help_enabled (context, TRUE); - g_option_context_add_main_entries (context, options, NULL); - g_option_context_add_group (context, gst_init_get_option_group ()); - g_option_context_parse (context, &argc, &argv, NULL); + g_set_prgname("gmemcoder"); + context = g_option_context_new(NULL); + g_option_context_set_help_enabled(context, TRUE); + g_option_context_add_main_entries(context, options, NULL); + g_option_context_add_group(context, gst_init_get_option_group()); + g_option_context_parse(context, &argc, &argv, NULL); - gst_init (&argc, &argv); + gst_init(&argc, &argv); - if (output_uri == NULL) { - g_print ("You need to specify output-uri.\nTry --help " - "for more information.\n"); - return 1; - } + if (output_uri == NULL) + { + g_print("You need to specify output-uri.\nTry --help " + "for more information.\n"); + return 1; + } - if (input_file == NULL) { - g_print ("You need to specify input file\nTry --help " - "for more information.\n"); - } + if (input_file == NULL) + { + g_print("You need to specify input file\nTry --help " + "for more information.\n"); + } - coder = g_mencoder_new (); - ch = g_io_channel_unix_new (0); + coder = g_mencoder_new(); + ch = g_io_channel_unix_new(0); - aopts = g_strsplit (audio_opts, ",", 0); - vopts = g_strsplit (video_opts, ",", 0); + aopts = g_strsplit(audio_opts, ",", 0); + vopts = g_strsplit(video_opts, ",", 0); - g_mencoder_setup_stream (coder, mux_name, - video_encode, vopts, video_fps, - video_rate, video_width, video_height, - audio_encode, aopts, audio_rate, - output_uri); + g_mencoder_setup_stream(coder, mux_name, + video_encode, vopts, video_fps, + video_rate, video_width, video_height, + audio_encode, aopts, audio_rate, output_uri); - files = g_strsplit (input_file, ",", 0); - for (i=0; i < g_strv_length (files); i++) { - if (!g_mencoder_append_uri (coder, files[i])) { - g_debug ("Invalid uri: %s", files[i]); - } - } + files = g_strsplit(input_file, ",", 0); + for (i = 0; i < g_strv_length(files); i++) + { + if (!g_mencoder_append_uri(coder, files[i])) + { + g_debug("Invalid uri: %s", files[i]); + } + } - g_strfreev (files); - g_strfreev (aopts); - g_strfreev (vopts); + g_strfreev(files); + g_strfreev(aopts); + g_strfreev(vopts); - g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder); + g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder); - g_signal_connect (G_OBJECT (coder), - "eos", - G_CALLBACK (_mencoder_eos_cb), - mainloop); + g_signal_connect(G_OBJECT(coder), + "eos", G_CALLBACK(_mencoder_eos_cb), mainloop); - g_signal_connect (G_OBJECT (coder), - "error", - G_CALLBACK (_mencoder_error_cb), - mainloop); + g_signal_connect(G_OBJECT(coder), + "error", G_CALLBACK(_mencoder_error_cb), mainloop); - g_mencoder_play_stream (coder); + g_mencoder_play_stream(coder); - g_debug ("RUNNING.."); - g_main_loop_run (mainloop); - g_debug ("DONE"); - g_object_unref (coder); + g_debug("RUNNING.."); + g_main_loop_run(mainloop); + g_debug("DONE"); + g_object_unref(coder); - return 0; + return 0; }