gmyth-stream/gmemcoder/src/gmencoder.c
branchtrunk
changeset 787 e42706ada231
parent 781 97fd2d4783bf
child 789 f9cd59844f78
     1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c	Wed Jul 04 19:37:34 2007 +0100
     1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c	Sat Jul 14 17:20:54 2007 +0100
     1.3 @@ -10,6 +10,7 @@
     1.4  #include <string.h>
     1.5  #include <sys/types.h>
     1.6  #include <sys/socket.h>
     1.7 +#include <libgnomevfs/gnome-vfs.h>
     1.8  
     1.9  #include "gmencoder.h"
    1.10  
    1.11 @@ -42,11 +43,13 @@
    1.12      GstElement     *vbin;
    1.13      GstElement     *sink;
    1.14      GstElement     *src;
    1.15 +
    1.16 +    GnomeVFSHandle  *handle;
    1.17 +
    1.18      gboolean        ready;
    1.19      SetupInfo      *info;
    1.20      GstClockTime    videot;
    1.21      GstClockTime    audiot;
    1.22 -    gint            fd;
    1.23      gint            sources;
    1.24      gint            tick_id;
    1.25      gint64          duration;
    1.26 @@ -666,10 +669,10 @@
    1.27  
    1.28      if (priv->pipe != NULL) {
    1.29          // TODO: fixe pipeline dispose
    1.30 -        gst_element_set_state (priv->pipe, GST_STATE_NULL);
    1.31 +        //gst_element_set_state (priv->pipe, GST_STATE_NULL);
    1.32          // g_debug ("SETING STATE TO NULL: OK");
    1.33          // gst_element_set_state (priv->pipe, GST_STATE_NULL);
    1.34 -        gst_object_unref (priv->pipe);
    1.35 +        //gst_object_unref (priv->pipe);
    1.36          //gst_object_unref(priv->src);
    1.37          priv->src = NULL;
    1.38          priv->pipe = NULL;
    1.39 @@ -714,8 +717,6 @@
    1.40      vp = gst_element_factory_make("concatmux", "vp");
    1.41      gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL);
    1.42  #endif
    1.43 -    GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
    1.44 -
    1.45      mux =
    1.46          gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"),
    1.47                                   "mux");
    1.48 @@ -725,20 +726,12 @@
    1.49      queue = gst_element_factory_make("queue", "queueu_sink");
    1.50  
    1.51  
    1.52 -#ifdef USE_MANUAL_SINK
    1.53      sink = gst_element_factory_make("fakesink", "sink");
    1.54      g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
    1.55      g_signal_connect (G_OBJECT (sink),
    1.56                        "handoff",
    1.57                        G_CALLBACK (_buffer_arrive_cb),
    1.58                        self);
    1.59 -#else    
    1.60 -    sink = gst_element_factory_make("fdsink", "sink");
    1.61 -    if (sink == NULL)
    1.62 -        goto error;
    1.63 -
    1.64 -    g_object_set(G_OBJECT(sink), "fd", priv->fd, "sync", FALSE, NULL);
    1.65 -#endif
    1.66  
    1.67      abin = _create_audio_bin(audio_encode, audio_encode_prop, audio_rate);
    1.68      if (abin == NULL)
    1.69 @@ -929,36 +922,21 @@
    1.70  static gboolean
    1.71  _open_output(GMencoder * self, const gchar * uri)
    1.72  {
    1.73 -    gboolean ret = TRUE;
    1.74      gchar         **i;
    1.75 +    GnomeVFSResult result;
    1.76      GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
    1.77  
    1.78      i = g_strsplit(uri, "://", 0);
    1.79      if (strcmp(i[0], "fd") == 0) {
    1.80 -        priv->fd = atoi(i[1]);
    1.81 -    } else if (strcmp(i[0], "file") == 0) {
    1.82 -        if (g_file_test (i[1], G_FILE_TEST_EXISTS)) {
    1.83 -            if (unlink (i[1]) != 0) {
    1.84 -                g_warning ("Fail to write in : %s", uri);
    1.85 -                ret = FALSE;
    1.86 -                goto done;
    1.87 -            }
    1.88 -        }
    1.89 -        priv->fd = open(i[1], O_WRONLY | O_CREAT | O_TRUNC,
    1.90 -                        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
    1.91 +        result = gnome_vfs_open_fd (&priv->handle, atoi(i[1]));
    1.92 +    } else { 
    1.93 +        result = gnome_vfs_open (&priv->handle, uri, 
    1.94 +                                 GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE);
    1.95  
    1.96 -        if (priv->fd == -1) {
    1.97 -            g_warning ("Fail to open : %s", uri);
    1.98 -            ret = FALSE;
    1.99 -        }
   1.100 -    } else {
   1.101 -        g_warning("Output uri not supported");
   1.102 -        ret = FALSE;
   1.103      }
   1.104  
   1.105 -done:
   1.106      g_strfreev(i);
   1.107 -    return ret;
   1.108 +    return (result == GNOME_VFS_OK);
   1.109  }
   1.110  
   1.111  static          gboolean
   1.112 @@ -1108,11 +1086,12 @@
   1.113  
   1.114  #ifdef USE_MANUAL_SINK
   1.115  static gboolean
   1.116 -_send_buffer (gint fd, gpointer buff, gint size)
   1.117 +_send_buffer (GnomeVFSHandle *handle, gpointer buff, gint size)
   1.118  {
   1.119 -    gboolean ret = TRUE;
   1.120      gchar *msg;
   1.121      GByteArray *b_send;
   1.122 +    GnomeVFSResult result;
   1.123 +    GnomeVFSFileSize bytes_written;
   1.124  
   1.125      b_send = g_byte_array_new ();
   1.126      msg = g_strdup_printf ("%x\r\n", size);
   1.127 @@ -1125,11 +1104,10 @@
   1.128      b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar));
   1.129      g_free (msg);
   1.130  
   1.131 -    if (send (fd, b_send->data, b_send->len, MSG_MORE) <= 0) 
   1.132 -        ret = FALSE;
   1.133 +    result = gnome_vfs_write (handle, b_send->data, b_send->len, &bytes_written);
   1.134      g_byte_array_free (b_send, TRUE);
   1.135  
   1.136 -    return ret;
   1.137 +    return (result == GNOME_VFS_OK);
   1.138  }
   1.139  
   1.140  static void
   1.141 @@ -1138,12 +1116,17 @@
   1.142      GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
   1.143  
   1.144      if (priv->send_chunked) {
   1.145 +        GnomeVFSFileSize bytes_written;
   1.146          gchar *end_msg;
   1.147          end_msg = g_strdup ("0\r\n\r\n");
   1.148 -        write (priv->fd, (const guint8*) end_msg, strlen(end_msg) * sizeof(gchar));
   1.149 +        gnome_vfs_write (priv->handle, 
   1.150 +                         (const guint8*) end_msg, 
   1.151 +                         strlen(end_msg) * sizeof(gchar),
   1.152 +                         &bytes_written);
   1.153          g_free (end_msg);
   1.154      }
   1.155  }
   1.156 +
   1.157  static void 
   1.158  _buffer_arrive_cb (GstElement* object,
   1.159                     GstBuffer* buff,
   1.160 @@ -1152,11 +1135,20 @@
   1.161  {
   1.162      GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
   1.163  
   1.164 +
   1.165      if (priv->send_chunked) {
   1.166 -        if (_send_buffer (priv->fd, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) 
   1.167 +        if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) 
   1.168              goto error;
   1.169      } else {
   1.170 -        if (write (priv->fd, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) < 0)
   1.171 +        GnomeVFSResult result;
   1.172 +        GnomeVFSFileSize bytes_written;
   1.173 +
   1.174 +        result = gnome_vfs_write (priv->handle, 
   1.175 +                                  GST_BUFFER_DATA (buff), 
   1.176 +                                  GST_BUFFER_SIZE (buff),
   1.177 +                                  &bytes_written);
   1.178 +
   1.179 +        if (result != GNOME_VFS_OK)
   1.180              goto error;
   1.181      }
   1.182  
   1.183 @@ -1167,7 +1159,8 @@
   1.184          g_source_remove(priv->tick_id);
   1.185          priv->tick_id = 0;
   1.186      }
   1.187 -    g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Error on socket");
   1.188 +    g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Fail to write on socket");
   1.189 +    gst_element_set_state (priv->pipe, GST_STATE_PAUSED);
   1.190  }
   1.191  #endif 
   1.192