1.1 --- a/gmyth-stream/gmemcoder/src/main.c Tue Jun 12 22:13:46 2007 +0100
1.2 +++ b/gmyth-stream/gmemcoder/src/main.c Thu Jun 14 18:22:32 2007 +0100
1.3 @@ -12,183 +12,187 @@
1.4
1.5 static GMainLoop *mainloop = NULL;
1.6 /* Options */
1.7 -static gchar* input_file = NULL;
1.8 -static gchar* video_encode = NULL;
1.9 -static gchar* video_opts = NULL;
1.10 -static gdouble video_fps = 0.0;
1.11 -static gint video_rate = 0;
1.12 -static gint video_width = 0;
1.13 -static gint video_height = 0;
1.14 -static gchar* audio_encode = NULL;
1.15 -static gchar* audio_opts = NULL;
1.16 -static double audio_rate = 0.0;
1.17 -static gchar* mux_name = NULL;
1.18 -static gchar* output_uri = NULL;
1.19 +static gchar *input_file = NULL;
1.20 +static gchar *video_encode = NULL;
1.21 +static gchar *video_opts = NULL;
1.22 +static gdouble video_fps = 0.0;
1.23 +static gint video_rate = 0;
1.24 +static gint video_width = 0;
1.25 +static gint video_height = 0;
1.26 +static gchar *audio_encode = NULL;
1.27 +static gchar *audio_opts = NULL;
1.28 +static double audio_rate = 0.0;
1.29 +static gchar *mux_name = NULL;
1.30 +static gchar *output_uri = NULL;
1.31
1.32
1.33
1.34 static gboolean
1.35 -_quit (gpointer data)
1.36 +_quit(gpointer data)
1.37 {
1.38 - g_object_unref (data);
1.39 - g_main_loop_quit (mainloop);
1.40 - return FALSE;
1.41 + g_object_unref(data);
1.42 + g_main_loop_quit(mainloop);
1.43 + return FALSE;
1.44 }
1.45
1.46 static void
1.47 -_mencoder_eos_cb (GMencoder *mencoder, gpointer data)
1.48 +_mencoder_eos_cb(GMencoder * mencoder, gpointer data)
1.49 {
1.50 - g_print ("EOS\n");
1.51 - g_idle_add (_quit, mencoder);
1.52 + g_print("EOS\n");
1.53 + g_idle_add(_quit, mencoder);
1.54 }
1.55
1.56
1.57 static void
1.58 -_mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data)
1.59 +_mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data)
1.60 {
1.61 - g_print ("Error: %s\n", msg);
1.62 - g_idle_add (_quit, mencoder);
1.63 + g_print("Error: %s\n", msg);
1.64 + g_idle_add(_quit, mencoder);
1.65 }
1.66
1.67 static gboolean
1.68 -_io_channel_cb (GIOChannel *ch,
1.69 - GIOCondition condition,
1.70 - gpointer data)
1.71 +_io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data)
1.72 {
1.73 - GString *cmd = g_string_new ("");
1.74 - g_io_channel_read_line_string (ch, cmd, NULL, NULL);
1.75 + GString *cmd = g_string_new("");
1.76 + g_io_channel_read_line_string(ch, cmd, NULL, NULL);
1.77
1.78 - if (strcmp (cmd->str, "PLAY\n") == 0) {
1.79 - g_mencoder_play_stream (G_MENCODER (data));
1.80 - } else if (strcmp (cmd->str, "PAUSE\n") == 0) {
1.81 - g_mencoder_pause_stream (G_MENCODER (data));
1.82 - } else if (strcmp (cmd->str, "STOP\n") == 0) {
1.83 - g_mencoder_close_stream (G_MENCODER (data));
1.84 - } else if (strcmp (cmd->str, "QUIT\n") == 0) {
1.85 - g_mencoder_close_stream (G_MENCODER (data));
1.86 - g_main_loop_quit (mainloop);
1.87 - }
1.88 - g_string_free (cmd, TRUE);
1.89 - return TRUE;
1.90 + if (strcmp(cmd->str, "PLAY\n") == 0)
1.91 + {
1.92 + g_mencoder_play_stream(G_MENCODER(data));
1.93 + }
1.94 + else if (strcmp(cmd->str, "PAUSE\n") == 0)
1.95 + {
1.96 + g_mencoder_pause_stream(G_MENCODER(data));
1.97 + }
1.98 + else if (strcmp(cmd->str, "STOP\n") == 0)
1.99 + {
1.100 + g_mencoder_close_stream(G_MENCODER(data));
1.101 + }
1.102 + else if (strcmp(cmd->str, "QUIT\n") == 0)
1.103 + {
1.104 + g_mencoder_close_stream(G_MENCODER(data));
1.105 + g_main_loop_quit(mainloop);
1.106 + }
1.107 + g_string_free(cmd, TRUE);
1.108 + return TRUE;
1.109 }
1.110
1.111 int
1.112 -main (int argc, char** argv)
1.113 +main(int argc, char **argv)
1.114 {
1.115 - GMencoder *coder = NULL;
1.116 - GIOChannel *ch;
1.117 - gchar **vopts;
1.118 - gchar **aopts;
1.119 - gchar **files;
1.120 - gint i;
1.121 + GMencoder *coder = NULL;
1.122 + GIOChannel *ch;
1.123 + gchar **vopts;
1.124 + gchar **aopts;
1.125 + gchar **files;
1.126 + gint i;
1.127
1.128 - GOptionContext *context;
1.129 - static const GOptionEntry options [] = {
1.130 - {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file,
1.131 - "Input File", NULL},
1.132 + GOptionContext *context;
1.133 + static const GOptionEntry options[] = {
1.134 + {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file,
1.135 + "Input File", NULL},
1.136
1.137 - {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode,
1.138 - "GstElementName for used to video encode", NULL},
1.139 + {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode,
1.140 + "GstElementName for used to video encode", NULL},
1.141
1.142 - {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts,
1.143 - "Properties to set on video element", NULL},
1.144 + {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts,
1.145 + "Properties to set on video element", NULL},
1.146
1.147 - {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps,
1.148 - "Video FPS", NULL},
1.149 + {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps,
1.150 + "Video FPS", NULL},
1.151
1.152 - {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate,
1.153 - "Video rate", NULL},
1.154 + {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate,
1.155 + "Video rate", NULL},
1.156
1.157 - {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width,
1.158 - "Video width", NULL},
1.159 + {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width,
1.160 + "Video width", NULL},
1.161
1.162 - {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height,
1.163 - "Video height", NULL},
1.164 + {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height,
1.165 + "Video height", NULL},
1.166
1.167 - {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode,
1.168 - "GstElementName for use to audio encode", NULL},
1.169 + {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode,
1.170 + "GstElementName for use to audio encode", NULL},
1.171
1.172 - {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts,
1.173 - "Properties to set on audio element", NULL},
1.174 + {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts,
1.175 + "Properties to set on audio element", NULL},
1.176
1.177 - {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate,
1.178 - "Audio rate", NULL},
1.179 + {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate,
1.180 + "Audio rate", NULL},
1.181
1.182 - {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name,
1.183 - "GstElementName for use to mux file", NULL},
1.184 + {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name,
1.185 + "GstElementName for use to mux file", NULL},
1.186
1.187 - {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri,
1.188 - "Uri to output", NULL},
1.189 + {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri,
1.190 + "Uri to output", NULL},
1.191
1.192 - { NULL }
1.193 - };
1.194 + {NULL}
1.195 + };
1.196
1.197 - g_type_init ();
1.198 - g_thread_init (NULL);
1.199 - mainloop = g_main_loop_new (NULL, FALSE);
1.200 + g_type_init();
1.201 + g_thread_init(NULL);
1.202 + mainloop = g_main_loop_new(NULL, FALSE);
1.203
1.204 - g_set_prgname ("gmemcoder");
1.205 - context = g_option_context_new (NULL);
1.206 - g_option_context_set_help_enabled (context, TRUE);
1.207 - g_option_context_add_main_entries (context, options, NULL);
1.208 - g_option_context_add_group (context, gst_init_get_option_group ());
1.209 - g_option_context_parse (context, &argc, &argv, NULL);
1.210 + g_set_prgname("gmemcoder");
1.211 + context = g_option_context_new(NULL);
1.212 + g_option_context_set_help_enabled(context, TRUE);
1.213 + g_option_context_add_main_entries(context, options, NULL);
1.214 + g_option_context_add_group(context, gst_init_get_option_group());
1.215 + g_option_context_parse(context, &argc, &argv, NULL);
1.216
1.217 - gst_init (&argc, &argv);
1.218 + gst_init(&argc, &argv);
1.219
1.220 - if (output_uri == NULL) {
1.221 - g_print ("You need to specify output-uri.\nTry --help "
1.222 - "for more information.\n");
1.223 - return 1;
1.224 - }
1.225 + if (output_uri == NULL)
1.226 + {
1.227 + g_print("You need to specify output-uri.\nTry --help "
1.228 + "for more information.\n");
1.229 + return 1;
1.230 + }
1.231
1.232 - if (input_file == NULL) {
1.233 - g_print ("You need to specify input file\nTry --help "
1.234 - "for more information.\n");
1.235 - }
1.236 + if (input_file == NULL)
1.237 + {
1.238 + g_print("You need to specify input file\nTry --help "
1.239 + "for more information.\n");
1.240 + }
1.241
1.242 - coder = g_mencoder_new ();
1.243 - ch = g_io_channel_unix_new (0);
1.244 + coder = g_mencoder_new();
1.245 + ch = g_io_channel_unix_new(0);
1.246
1.247 - aopts = g_strsplit (audio_opts, ",", 0);
1.248 - vopts = g_strsplit (video_opts, ",", 0);
1.249 + aopts = g_strsplit(audio_opts, ",", 0);
1.250 + vopts = g_strsplit(video_opts, ",", 0);
1.251
1.252 - g_mencoder_setup_stream (coder, mux_name,
1.253 - video_encode, vopts, video_fps,
1.254 - video_rate, video_width, video_height,
1.255 - audio_encode, aopts, audio_rate,
1.256 - output_uri);
1.257 + g_mencoder_setup_stream(coder, mux_name,
1.258 + video_encode, vopts, video_fps,
1.259 + video_rate, video_width, video_height,
1.260 + audio_encode, aopts, audio_rate, output_uri);
1.261
1.262 - files = g_strsplit (input_file, ",", 0);
1.263 - for (i=0; i < g_strv_length (files); i++) {
1.264 - if (!g_mencoder_append_uri (coder, files[i])) {
1.265 - g_debug ("Invalid uri: %s", files[i]);
1.266 - }
1.267 - }
1.268 + files = g_strsplit(input_file, ",", 0);
1.269 + for (i = 0; i < g_strv_length(files); i++)
1.270 + {
1.271 + if (!g_mencoder_append_uri(coder, files[i]))
1.272 + {
1.273 + g_debug("Invalid uri: %s", files[i]);
1.274 + }
1.275 + }
1.276
1.277 - g_strfreev (files);
1.278 - g_strfreev (aopts);
1.279 - g_strfreev (vopts);
1.280 + g_strfreev(files);
1.281 + g_strfreev(aopts);
1.282 + g_strfreev(vopts);
1.283
1.284
1.285 - g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder);
1.286 + g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
1.287
1.288 - g_signal_connect (G_OBJECT (coder),
1.289 - "eos",
1.290 - G_CALLBACK (_mencoder_eos_cb),
1.291 - mainloop);
1.292 + g_signal_connect(G_OBJECT(coder),
1.293 + "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
1.294
1.295 - g_signal_connect (G_OBJECT (coder),
1.296 - "error",
1.297 - G_CALLBACK (_mencoder_error_cb),
1.298 - mainloop);
1.299 + g_signal_connect(G_OBJECT(coder),
1.300 + "error", G_CALLBACK(_mencoder_error_cb), mainloop);
1.301
1.302 - g_mencoder_play_stream (coder);
1.303 + g_mencoder_play_stream(coder);
1.304
1.305 - g_debug ("RUNNING..");
1.306 - g_main_loop_run (mainloop);
1.307 - g_debug ("DONE");
1.308 - g_object_unref (coder);
1.309 + g_debug("RUNNING..");
1.310 + g_main_loop_run(mainloop);
1.311 + g_debug("DONE");
1.312 + g_object_unref(coder);
1.313
1.314 - return 0;
1.315 + return 0;
1.316 }