1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c Wed Aug 15 13:33:12 2007 +0100
1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Wed Aug 15 20:52:44 2007 +0100
1.3 @@ -18,8 +18,6 @@
1.4 #define G_MENCODER_GET_PRIVATE(obj) \
1.5 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
1.6
1.7 -#define USE_MANUAL_SINK
1.8 -
1.9 typedef struct _GMencoderPrivate GMencoderPrivate;
1.10 typedef struct _SetupInfo SetupInfo;
1.11
1.12 @@ -44,7 +42,7 @@
1.13 GstElement *sink;
1.14 GstElement *src;
1.15
1.16 - GnomeVFSHandle *handle;
1.17 + gint out_fd;
1.18
1.19 gboolean ready;
1.20 SetupInfo *info;
1.21 @@ -112,15 +110,10 @@
1.22 gchar ** audio_encode_prop,
1.23 guint audio_rate,
1.24 gboolean deinterlace);
1.25 -#ifdef USE_MANUAL_SINK
1.26 static void _flush_queue (GMencoder *self);
1.27 static void _buffer_arrive_cb (GstElement* object,
1.28 GstBuffer* buff,
1.29 - GstPad* pad,
1.30 gpointer user_data);
1.31 -#endif
1.32 -
1.33 -
1.34 static gboolean _tick_cb(gpointer data);
1.35
1.36 static guint g_mencoder_signals[LAST_SIGNAL] = { 0 };
1.37 @@ -677,7 +670,6 @@
1.38 priv->pipe = NULL;
1.39 priv->abin = NULL;
1.40 priv->vbin = NULL;
1.41 - priv->sink = NULL;
1.42 }
1.43 priv->ready = FALSE;
1.44 }
1.45 @@ -702,8 +694,10 @@
1.46 GstElement *abin = NULL;
1.47 GstElement *vbin = NULL;
1.48 GstElement *queue = NULL;
1.49 + GstElement *identity = NULL;
1.50 GstPad *aux_pad = NULL;
1.51 GstPad *mux_pad = NULL;
1.52 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
1.53
1.54 pipe = gst_pipeline_new("pipe");
1.55
1.56 @@ -714,11 +708,10 @@
1.57 goto error;
1.58
1.59 queue = gst_element_factory_make("queue", "queueu_sink");
1.60 -
1.61 -
1.62 - sink = gst_element_factory_make("fakesink", "sink");
1.63 - g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
1.64 - g_signal_connect (G_OBJECT (sink),
1.65 + identity = gst_element_factory_make ("identity", "identity");
1.66 + sink = gst_element_factory_make("fdsink", "sink");
1.67 + g_object_set (sink, "fd", priv->out_fd, NULL);
1.68 + g_signal_connect (G_OBJECT (identity),
1.69 "handoff",
1.70 G_CALLBACK (_buffer_arrive_cb),
1.71 self);
1.72 @@ -734,7 +727,7 @@
1.73 goto error;
1.74
1.75 // Finish Pipe
1.76 - gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL);
1.77 + gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, identity, sink, NULL);
1.78
1.79
1.80 // Link bins with mux
1.81 @@ -774,11 +767,12 @@
1.82 mux_pad = NULL;
1.83
1.84 // Link mux with sink
1.85 - gst_element_link_many(mux, queue, sink, NULL);
1.86 + gst_element_link_many(mux, queue, identity, sink, NULL);
1.87
1.88 bus = gst_pipeline_get_bus(GST_PIPELINE(pipe));
1.89 gst_bus_add_watch(bus, _pipeline_bus_cb, self);
1.90 gst_object_unref(bus);
1.91 +
1.92 return pipe;
1.93
1.94 error:
1.95 @@ -934,25 +928,19 @@
1.96 _open_output(GMencoder * self, const gchar * uri)
1.97 {
1.98 gchar **i;
1.99 - GnomeVFSResult result;
1.100 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.101
1.102 + priv->out_fd = 0;
1.103 +
1.104 i = g_strsplit(uri, "://", 0);
1.105 if (strcmp(i[0], "fd") == 0) {
1.106 - result = gnome_vfs_open_fd (&priv->handle, atoi(i[1]));
1.107 + priv->out_fd = atoi (i[1]);
1.108 } else {
1.109 - g_debug ("Teste file :%s", i[1]);
1.110 - if (g_file_test (i[1], G_FILE_TEST_EXISTS) == FALSE) {
1.111 - result = gnome_vfs_create (&priv->handle, uri, GNOME_VFS_OPEN_WRITE, TRUE,
1.112 - GNOME_VFS_PERM_USER_WRITE | GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_GROUP_READ);
1.113 - } else {
1.114 - result = gnome_vfs_open (&priv->handle, uri,
1.115 - GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE);
1.116 - }
1.117 + priv->out_fd = open (i[1], O_CREAT|O_WRONLY|O_TRUNC, 0666);
1.118 }
1.119
1.120 g_strfreev(i);
1.121 - return (result == GNOME_VFS_OK);
1.122 + return (priv->out_fd > 0);
1.123 }
1.124
1.125 static gboolean
1.126 @@ -1015,9 +1003,7 @@
1.127
1.128 case GST_MESSAGE_EOS:
1.129 priv->ready = FALSE;
1.130 -#ifdef USE_MANUAL_SINK
1.131 _flush_queue (G_MENCODER (user_data));
1.132 -#endif
1.133 g_signal_emit(user_data, g_mencoder_signals[EOS], 0);
1.134 break;
1.135
1.136 @@ -1100,39 +1086,39 @@
1.137 }
1.138
1.139
1.140 -#ifdef USE_MANUAL_SINK
1.141 -static gboolean
1.142 -_send_buffer (GnomeVFSHandle *handle, gpointer buff, gint size)
1.143 +static void
1.144 +_chunke_buffer (GstBuffer *buf)
1.145 {
1.146 gchar *msg;
1.147 GByteArray *b_send;
1.148 - GnomeVFSResult result;
1.149 - GnomeVFSFileSize bytes_written;
1.150
1.151 b_send = g_byte_array_new ();
1.152 - msg = g_strdup_printf ("%x\r\n", size);
1.153 + msg = g_strdup_printf ("%x\r\n", GST_BUFFER_SIZE(buf));
1.154 b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar));
1.155 g_free (msg);
1.156
1.157 - b_send = g_byte_array_append (b_send, buff, size);
1.158 + b_send = g_byte_array_append (b_send, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf));
1.159
1.160 msg = g_strdup ("\r\n");
1.161 b_send = g_byte_array_append (b_send, (const guint8*) msg, strlen (msg) * sizeof (gchar));
1.162 g_free (msg);
1.163
1.164 - result = gnome_vfs_write (handle, b_send->data, b_send->len, &bytes_written);
1.165 - g_byte_array_free (b_send, TRUE);
1.166 + g_free (GST_BUFFER_DATA(buf));
1.167
1.168 - return (result == GNOME_VFS_OK);
1.169 + GST_BUFFER_SIZE(buf)=b_send->len;
1.170 + GST_BUFFER_DATA(buf)=b_send->data;
1.171 +
1.172 + g_byte_array_free (b_send, FALSE);
1.173 }
1.174
1.175 static void
1.176 _flush_queue (GMencoder *self)
1.177 {
1.178 + /*
1.179 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.180
1.181 +
1.182 if (priv->send_chunked) {
1.183 - GnomeVFSFileSize bytes_written;
1.184 gchar *end_msg;
1.185 end_msg = g_strdup ("0\r\n\r\n");
1.186 gnome_vfs_write (priv->handle,
1.187 @@ -1141,42 +1127,17 @@
1.188 &bytes_written);
1.189 g_free (end_msg);
1.190 }
1.191 + */
1.192 }
1.193
1.194 static void
1.195 _buffer_arrive_cb (GstElement* object,
1.196 - GstBuffer* buff,
1.197 - GstPad* pad,
1.198 + GstBuffer* buf,
1.199 gpointer user_data)
1.200 {
1.201 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data);
1.202
1.203 -
1.204 if (priv->send_chunked) {
1.205 - if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE)
1.206 - goto error;
1.207 - } else {
1.208 - GnomeVFSResult result;
1.209 - GnomeVFSFileSize bytes_written;
1.210 -
1.211 - result = gnome_vfs_write (priv->handle,
1.212 - GST_BUFFER_DATA (buff),
1.213 - GST_BUFFER_SIZE (buff),
1.214 - &bytes_written);
1.215 -
1.216 - if (result != GNOME_VFS_OK)
1.217 - goto error;
1.218 + _chunke_buffer (buf);
1.219 }
1.220 -
1.221 - return;
1.222 -
1.223 -error:
1.224 - if (priv->tick_id != 0) {
1.225 - g_source_remove(priv->tick_id);
1.226 - priv->tick_id = 0;
1.227 - }
1.228 - g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Fail to write on socket");
1.229 - gst_element_set_state (priv->pipe, GST_STATE_PAUSED);
1.230 }
1.231 -
1.232 -#endif