# HG changeset patch # User renatofilho # Date 1187207564 -3600 # Node ID 4b2192319f5668f7b3424dfc6504bec2e1fb1c30 # Parent b1d0964060b36f2a796676cb446357396c95dc83 [svn r810] removed gnomevfs calls diff -r b1d0964060b3 -r 4b2192319f56 gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Wed Aug 15 13:33:12 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Wed Aug 15 20:52:44 2007 +0100 @@ -18,8 +18,6 @@ #define G_MENCODER_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate)) -#define USE_MANUAL_SINK - typedef struct _GMencoderPrivate GMencoderPrivate; typedef struct _SetupInfo SetupInfo; @@ -44,7 +42,7 @@ GstElement *sink; GstElement *src; - GnomeVFSHandle *handle; + gint out_fd; gboolean ready; SetupInfo *info; @@ -112,15 +110,10 @@ gchar ** audio_encode_prop, guint audio_rate, gboolean deinterlace); -#ifdef USE_MANUAL_SINK static void _flush_queue (GMencoder *self); static void _buffer_arrive_cb (GstElement* object, GstBuffer* buff, - GstPad* pad, gpointer user_data); -#endif - - static gboolean _tick_cb(gpointer data); static guint g_mencoder_signals[LAST_SIGNAL] = { 0 }; @@ -677,7 +670,6 @@ priv->pipe = NULL; priv->abin = NULL; priv->vbin = NULL; - priv->sink = NULL; } priv->ready = FALSE; } @@ -702,8 +694,10 @@ GstElement *abin = NULL; GstElement *vbin = NULL; GstElement *queue = NULL; + GstElement *identity = NULL; GstPad *aux_pad = NULL; GstPad *mux_pad = NULL; + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); pipe = gst_pipeline_new("pipe"); @@ -714,11 +708,10 @@ goto error; queue = gst_element_factory_make("queue", "queueu_sink"); - - - sink = gst_element_factory_make("fakesink", "sink"); - g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL); - g_signal_connect (G_OBJECT (sink), + identity = gst_element_factory_make ("identity", "identity"); + sink = gst_element_factory_make("fdsink", "sink"); + g_object_set (sink, "fd", priv->out_fd, NULL); + g_signal_connect (G_OBJECT (identity), "handoff", G_CALLBACK (_buffer_arrive_cb), self); @@ -734,7 +727,7 @@ goto error; // Finish Pipe - gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL); + gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, identity, sink, NULL); // Link bins with mux @@ -774,11 +767,12 @@ mux_pad = NULL; // Link mux with sink - gst_element_link_many(mux, queue, sink, NULL); + gst_element_link_many(mux, queue, identity, sink, NULL); bus = gst_pipeline_get_bus(GST_PIPELINE(pipe)); gst_bus_add_watch(bus, _pipeline_bus_cb, self); gst_object_unref(bus); + return pipe; error: @@ -934,25 +928,19 @@ _open_output(GMencoder * self, const gchar * uri) { gchar **i; - GnomeVFSResult result; GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + priv->out_fd = 0; + i = g_strsplit(uri, "://", 0); if (strcmp(i[0], "fd") == 0) { - result = gnome_vfs_open_fd (&priv->handle, atoi(i[1])); + priv->out_fd = atoi (i[1]); } else { - g_debug ("Teste file :%s", i[1]); - if (g_file_test (i[1], G_FILE_TEST_EXISTS) == FALSE) { - result = gnome_vfs_create (&priv->handle, uri, GNOME_VFS_OPEN_WRITE, TRUE, - GNOME_VFS_PERM_USER_WRITE | GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_GROUP_READ); - } else { - result = gnome_vfs_open (&priv->handle, uri, - GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE); - } + priv->out_fd = open (i[1], O_CREAT|O_WRONLY|O_TRUNC, 0666); } g_strfreev(i); - return (result == GNOME_VFS_OK); + return (priv->out_fd > 0); } static gboolean @@ -1015,9 +1003,7 @@ case GST_MESSAGE_EOS: priv->ready = FALSE; -#ifdef USE_MANUAL_SINK _flush_queue (G_MENCODER (user_data)); -#endif g_signal_emit(user_data, g_mencoder_signals[EOS], 0); break; @@ -1100,39 +1086,39 @@ } -#ifdef USE_MANUAL_SINK -static gboolean -_send_buffer (GnomeVFSHandle *handle, gpointer buff, gint size) +static void +_chunke_buffer (GstBuffer *buf) { gchar *msg; GByteArray *b_send; - GnomeVFSResult result; - GnomeVFSFileSize bytes_written; b_send = g_byte_array_new (); - msg = g_strdup_printf ("%x\r\n", size); + msg = g_strdup_printf ("%x\r\n", GST_BUFFER_SIZE(buf)); b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar)); g_free (msg); - b_send = g_byte_array_append (b_send, buff, size); + b_send = g_byte_array_append (b_send, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf)); msg = g_strdup ("\r\n"); b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar)); g_free (msg); - result = gnome_vfs_write (handle, b_send->data, b_send->len, &bytes_written); - g_byte_array_free (b_send, TRUE); + g_free (GST_BUFFER_DATA(buf)); - return (result == GNOME_VFS_OK); + GST_BUFFER_SIZE(buf)=b_send->len; + GST_BUFFER_DATA(buf)=b_send->data; + + g_byte_array_free (b_send, FALSE); } static void _flush_queue (GMencoder *self) { + /* 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"); gnome_vfs_write (priv->handle, @@ -1141,42 +1127,17 @@ &bytes_written); g_free (end_msg); } + */ } static void _buffer_arrive_cb (GstElement* object, - GstBuffer* buff, - GstPad* pad, + GstBuffer* buf, gpointer user_data) { GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data); - if (priv->send_chunked) { - if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) - goto error; - } else { - 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; + _chunke_buffer (buf); } - - return; - -error: - if (priv->tick_id != 0) { - g_source_remove(priv->tick_id); - priv->tick_id = 0; - } - 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