diff -r 97fd2d4783bf -r a4529d0f8ede gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Wed Jul 04 19:37:34 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jul 05 13:43:24 2007 +0100 @@ -10,6 +10,7 @@ #include #include #include +#include #include "gmencoder.h" @@ -42,11 +43,13 @@ GstElement *vbin; GstElement *sink; GstElement *src; + + GnomeVFSHandle *handle; + gboolean ready; SetupInfo *info; GstClockTime videot; GstClockTime audiot; - gint fd; gint sources; gint tick_id; gint64 duration; @@ -666,10 +669,10 @@ if (priv->pipe != NULL) { // TODO: fixe pipeline dispose - gst_element_set_state (priv->pipe, GST_STATE_NULL); + //gst_element_set_state (priv->pipe, GST_STATE_NULL); // g_debug ("SETING STATE TO NULL: OK"); // gst_element_set_state (priv->pipe, GST_STATE_NULL); - gst_object_unref (priv->pipe); + //gst_object_unref (priv->pipe); //gst_object_unref(priv->src); priv->src = NULL; priv->pipe = NULL; @@ -714,8 +717,6 @@ vp = gst_element_factory_make("concatmux", "vp"); gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL); #endif - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); - mux = gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"), "mux"); @@ -725,20 +726,12 @@ queue = gst_element_factory_make("queue", "queueu_sink"); -#ifdef USE_MANUAL_SINK sink = gst_element_factory_make("fakesink", "sink"); g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL); g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (_buffer_arrive_cb), self); -#else - sink = gst_element_factory_make("fdsink", "sink"); - if (sink == NULL) - goto error; - - g_object_set(G_OBJECT(sink), "fd", priv->fd, "sync", FALSE, NULL); -#endif abin = _create_audio_bin(audio_encode, audio_encode_prop, audio_rate); if (abin == NULL) @@ -929,36 +922,21 @@ static gboolean _open_output(GMencoder * self, const gchar * uri) { - gboolean ret = TRUE; gchar **i; + GnomeVFSResult result; GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); i = g_strsplit(uri, "://", 0); if (strcmp(i[0], "fd") == 0) { - priv->fd = atoi(i[1]); - } else if (strcmp(i[0], "file") == 0) { - if (g_file_test (i[1], G_FILE_TEST_EXISTS)) { - 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); + result = gnome_vfs_open_fd (&priv->handle, atoi(i[1])); + } else { + result = gnome_vfs_open (&priv->handle, uri, + GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE); - 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; + return (result == GNOME_VFS_OK); } static gboolean @@ -1108,11 +1086,12 @@ #ifdef USE_MANUAL_SINK static gboolean -_send_buffer (gint fd, gpointer buff, gint size) +_send_buffer (GnomeVFSHandle *handle, gpointer buff, gint size) { - gboolean ret = TRUE; gchar *msg; GByteArray *b_send; + GnomeVFSResult result; + GnomeVFSFileSize bytes_written; b_send = g_byte_array_new (); msg = g_strdup_printf ("%x\r\n", size); @@ -1125,11 +1104,10 @@ b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar)); g_free (msg); - if (send (fd, b_send->data, b_send->len, MSG_MORE) <= 0) - ret = FALSE; + result = gnome_vfs_write (handle, b_send->data, b_send->len, &bytes_written); g_byte_array_free (b_send, TRUE); - return ret; + return (result == GNOME_VFS_OK); } static void @@ -1138,12 +1116,17 @@ GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); if (priv->send_chunked) { + GnomeVFSFileSize bytes_written; gchar *end_msg; end_msg = g_strdup ("0\r\n\r\n"); - write (priv->fd, (const guint8*) end_msg, strlen(end_msg) * sizeof(gchar)); + gnome_vfs_write (priv->handle, + (const guint8*) end_msg, + strlen(end_msg) * sizeof(gchar), + &bytes_written); g_free (end_msg); } } + static void _buffer_arrive_cb (GstElement* object, GstBuffer* buff, @@ -1152,11 +1135,20 @@ { GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data); + if (priv->send_chunked) { - if (_send_buffer (priv->fd, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) + if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) goto error; } else { - if (write (priv->fd, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) < 0) + GnomeVFSResult result; + GnomeVFSFileSize bytes_written; + + result = gnome_vfs_write (priv->handle, + GST_BUFFER_DATA (buff), + GST_BUFFER_SIZE (buff), + &bytes_written); + + if (result != GNOME_VFS_OK) goto error; } @@ -1167,7 +1159,8 @@ g_source_remove(priv->tick_id); priv->tick_id = 0; } - g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Error on socket"); + g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Fail to write on socket"); + gst_element_set_state (priv->pipe, GST_STATE_PAUSED); } #endif