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