# HG changeset patch # User renatofilho # Date 1182536656 -3600 # Node ID d03fc6221891ec90763c52d18d647a67a8562552 # Parent 59623bb25c17e434fe6d5b4e92275475ee4ebf30 [svn r763] fixed bug on manage outputfile diff -r 59623bb25c17 -r d03fc6221891 gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Fri Jun 22 16:14:21 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Fri Jun 22 19:24:16 2007 +0100 @@ -82,7 +82,7 @@ gpointer user_data); static void _close_output(GMencoder * self); -static void _open_output(GMencoder * self, const gchar * uri); +static gboolean _open_output(GMencoder * self, const gchar * uri); static GstElement *_create_source(const gchar * uri); static GstElement *_create_pipeline(GMencoder * self, @@ -437,7 +437,7 @@ -void +gboolean g_mencoder_setup_stream(GMencoder * self, const gchar * mux_name, const gchar * video_encode, @@ -454,11 +454,12 @@ if (priv->ready == TRUE) { g_warning ("Stream already configured. You need close stream first."); - return; + return FALSE; } _close_output(self); - _open_output(self, out_uri); + if (_open_output(self, out_uri) == FALSE) + return FALSE; priv->sources = 0; priv->pipe = _create_pipeline(self, @@ -472,6 +473,7 @@ audio_encode, audio_encode_prop, audio_rate); + return (priv->pipe != NULL); } @@ -856,9 +858,10 @@ return NULL; } -static void +static gboolean _open_output(GMencoder * self, const gchar * uri) { + gboolean ret = TRUE; gchar **i; GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); @@ -867,15 +870,27 @@ priv->fd = atoi(i[1]); } else if (strcmp(i[0], "file") == 0) { if (g_file_test (i[1], G_FILE_TEST_EXISTS)) { - g_assert (unlink (i[1]) == 0); + if (unlink (i[1]) != 0) { + g_warning ("Fail to write in : %s", uri); + ret = FALSE; + goto done; + } } priv->fd = open(i[1], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + if (priv->fd == -1) { + g_warning ("Fail to open : %s", uri); + ret = FALSE; + } } else { g_warning("Output uri not supported"); + ret = FALSE; } +done: g_strfreev(i); + return ret; } static gboolean diff -r 59623bb25c17 -r d03fc6221891 gmyth-stream/gmemcoder/src/gmencoder.h --- a/gmyth-stream/gmemcoder/src/gmencoder.h Fri Jun 22 16:14:21 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.h Fri Jun 22 19:24:16 2007 +0100 @@ -34,7 +34,7 @@ GType g_mencoder_get_type(void); GMencoder *g_mencoder_new(void); -void g_mencoder_setup_stream(GMencoder * self, +gboolean g_mencoder_setup_stream(GMencoder * self, const gchar * mux_name, const gchar * video_encode, gchar ** video_encode_prop, diff -r 59623bb25c17 -r d03fc6221891 gmyth-stream/gmemcoder/src/main.c --- a/gmyth-stream/gmemcoder/src/main.c Fri Jun 22 16:14:21 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/main.c Fri Jun 22 19:24:16 2007 +0100 @@ -81,6 +81,7 @@ gchar **aopts; gchar **files; gint i; + gboolean ret; GOptionContext *context; static const GOptionEntry options[] = { @@ -150,40 +151,48 @@ coder = g_mencoder_new(); ch = g_io_channel_unix_new(0); - aopts = g_strsplit(audio_opts, ",", 0); - vopts = g_strsplit(video_opts, ",", 0); + if (audio_opts != NULL) + aopts = g_strsplit(audio_opts, ",", 0); + else + aopts = NULL; - 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); + if (video_opts != NULL) + vopts = g_strsplit(video_opts, ",", 0); + else + vopts = NULL; - 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]); + + ret = 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); + + if (ret == TRUE) { + 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(files); g_strfreev(aopts); g_strfreev(vopts); - g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder); + if (ret == TRUE) { + 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_main_loop_run(mainloop); + } - g_mencoder_play_stream(coder); - - g_debug("RUNNING.."); - g_main_loop_run(mainloop); - g_debug("DONE"); g_object_unref(coder); - return 0; }