[svn r763] fixed bug on manage outputfile trunk
authorrenatofilho
Fri Jun 22 19:24:16 2007 +0100 (2007-06-22)
branchtrunk
changeset 757d03fc6221891
parent 756 59623bb25c17
child 758 b57cdd5fb898
[svn r763] fixed bug on manage outputfile
gmyth-stream/gmemcoder/src/gmencoder.c
gmyth-stream/gmemcoder/src/gmencoder.h
gmyth-stream/gmemcoder/src/main.c
     1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c	Fri Jun 22 16:14:21 2007 +0100
     1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c	Fri Jun 22 19:24:16 2007 +0100
     1.3 @@ -82,7 +82,7 @@
     1.4                                             gpointer user_data);
     1.5  
     1.6  static void     _close_output(GMencoder * self);
     1.7 -static void     _open_output(GMencoder * self, const gchar * uri);
     1.8 +static gboolean _open_output(GMencoder * self, const gchar * uri);
     1.9  
    1.10  static GstElement *_create_source(const gchar * uri);
    1.11  static GstElement *_create_pipeline(GMencoder * self,
    1.12 @@ -437,7 +437,7 @@
    1.13  
    1.14  
    1.15  
    1.16 -void
    1.17 +gboolean 
    1.18  g_mencoder_setup_stream(GMencoder * self,
    1.19                          const gchar * mux_name,
    1.20                          const gchar * video_encode,
    1.21 @@ -454,11 +454,12 @@
    1.22      if (priv->ready == TRUE) {
    1.23          g_warning
    1.24              ("Stream already configured. You need close stream first.");
    1.25 -        return;
    1.26 +        return FALSE;
    1.27      }
    1.28  
    1.29      _close_output(self);
    1.30 -    _open_output(self, out_uri);
    1.31 +    if (_open_output(self, out_uri) == FALSE)
    1.32 +        return FALSE;
    1.33  
    1.34      priv->sources = 0;
    1.35      priv->pipe = _create_pipeline(self,
    1.36 @@ -472,6 +473,7 @@
    1.37                                    audio_encode, audio_encode_prop,
    1.38                                    audio_rate);
    1.39  
    1.40 +    return (priv->pipe != NULL);
    1.41  }
    1.42  
    1.43  
    1.44 @@ -856,9 +858,10 @@
    1.45      return NULL;
    1.46  }
    1.47  
    1.48 -static void
    1.49 +static gboolean
    1.50  _open_output(GMencoder * self, const gchar * uri)
    1.51  {
    1.52 +    gboolean ret = TRUE;
    1.53      gchar         **i;
    1.54      GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
    1.55  
    1.56 @@ -867,15 +870,27 @@
    1.57          priv->fd = atoi(i[1]);
    1.58      } else if (strcmp(i[0], "file") == 0) {
    1.59          if (g_file_test (i[1], G_FILE_TEST_EXISTS)) {
    1.60 -            g_assert (unlink (i[1]) == 0);
    1.61 +            if (unlink (i[1]) != 0) {
    1.62 +                g_warning ("Fail to write in : %s", uri);
    1.63 +                ret = FALSE;
    1.64 +                goto done;
    1.65 +            }
    1.66          }
    1.67          priv->fd = open(i[1], O_WRONLY | O_CREAT | O_TRUNC,
    1.68                          S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    1.69 +
    1.70 +        if (priv->fd == -1) {
    1.71 +            g_warning ("Fail to open : %s", uri);
    1.72 +            ret = FALSE;
    1.73 +        }
    1.74      } else {
    1.75          g_warning("Output uri not supported");
    1.76 +        ret = FALSE;
    1.77      }
    1.78  
    1.79 +done:
    1.80      g_strfreev(i);
    1.81 +    return ret;
    1.82  }
    1.83  
    1.84  static          gboolean
     2.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.h	Fri Jun 22 16:14:21 2007 +0100
     2.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.h	Fri Jun 22 19:24:16 2007 +0100
     2.3 @@ -34,7 +34,7 @@
     2.4  GType           g_mencoder_get_type(void);
     2.5  GMencoder      *g_mencoder_new(void);
     2.6  
     2.7 -void            g_mencoder_setup_stream(GMencoder * self,
     2.8 +gboolean        g_mencoder_setup_stream(GMencoder * self,
     2.9                                          const gchar * mux_name,
    2.10                                          const gchar * video_encode,
    2.11                                          gchar ** video_encode_prop,
     3.1 --- a/gmyth-stream/gmemcoder/src/main.c	Fri Jun 22 16:14:21 2007 +0100
     3.2 +++ b/gmyth-stream/gmemcoder/src/main.c	Fri Jun 22 19:24:16 2007 +0100
     3.3 @@ -81,6 +81,7 @@
     3.4      gchar         **aopts;
     3.5      gchar         **files;
     3.6      gint            i;
     3.7 +    gboolean      ret;
     3.8  
     3.9      GOptionContext *context;
    3.10      static const GOptionEntry options[] = {
    3.11 @@ -150,40 +151,48 @@
    3.12      coder = g_mencoder_new();
    3.13      ch = g_io_channel_unix_new(0);
    3.14  
    3.15 -    aopts = g_strsplit(audio_opts, ",", 0);
    3.16 -    vopts = g_strsplit(video_opts, ",", 0);
    3.17 +    if (audio_opts != NULL)
    3.18 +        aopts = g_strsplit(audio_opts, ",", 0);
    3.19 +    else
    3.20 +        aopts = NULL;
    3.21  
    3.22 -    g_mencoder_setup_stream(coder, mux_name,
    3.23 -                            video_encode, vopts, video_fps,
    3.24 -                            video_rate, video_width, video_height,
    3.25 -                            audio_encode, aopts, audio_rate, output_uri);
    3.26 +    if (video_opts != NULL)
    3.27 +        vopts = g_strsplit(video_opts, ",", 0);
    3.28 +    else
    3.29 +        vopts = NULL;
    3.30  
    3.31 -    files = g_strsplit(input_file, ",", 0);
    3.32 -    for (i = 0; i < g_strv_length(files); i++) {
    3.33 -        if (!g_mencoder_append_uri(coder, files[i])) {
    3.34 -            g_debug("Invalid uri: %s", files[i]);
    3.35 +    
    3.36 +    ret = g_mencoder_setup_stream(coder, mux_name,
    3.37 +                                  video_encode, vopts, video_fps,
    3.38 +                                  video_rate, video_width, video_height,
    3.39 +                                  audio_encode, aopts, audio_rate, output_uri);
    3.40 +
    3.41 +    if (ret == TRUE) {
    3.42 +        files = g_strsplit(input_file, ",", 0);
    3.43 +        for (i = 0; i < g_strv_length(files); i++) {
    3.44 +            if (!g_mencoder_append_uri(coder, files[i])) {
    3.45 +                g_debug("Invalid uri: %s", files[i]);
    3.46 +            }
    3.47          }
    3.48 +        g_strfreev(files);
    3.49      }
    3.50  
    3.51 -    g_strfreev(files);
    3.52      g_strfreev(aopts);
    3.53      g_strfreev(vopts);
    3.54  
    3.55  
    3.56 -    g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
    3.57 +    if (ret == TRUE) {
    3.58 +        g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
    3.59 +        g_signal_connect(G_OBJECT(coder),
    3.60 +                         "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
    3.61  
    3.62 -    g_signal_connect(G_OBJECT(coder),
    3.63 -                     "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
    3.64 +        g_signal_connect(G_OBJECT(coder),
    3.65 +                         "error", G_CALLBACK(_mencoder_error_cb), mainloop);
    3.66  
    3.67 -    g_signal_connect(G_OBJECT(coder),
    3.68 -                     "error", G_CALLBACK(_mencoder_error_cb), mainloop);
    3.69 +        g_mencoder_play_stream(coder);
    3.70 +        g_main_loop_run(mainloop);
    3.71 +    }
    3.72  
    3.73 -    g_mencoder_play_stream(coder);
    3.74 -
    3.75 -    g_debug("RUNNING..");
    3.76 -    g_main_loop_run(mainloop);
    3.77 -    g_debug("DONE");
    3.78      g_object_unref(coder);
    3.79 -
    3.80      return 0;
    3.81  }