# HG changeset patch # User renatofilho # Date 1183124401 -3600 # Node ID 949291aaba656f3876756a7e60390204ad03fd5a # Parent 36b8564d10e64181dc207c9bfc25554a7df7ff95 [svn r767] use manual buffer write diff -r 36b8564d10e6 -r 949291aaba65 gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Tue Jun 26 15:00:45 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Fri Jun 29 14:40:01 2007 +0100 @@ -15,6 +15,8 @@ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate)) // #define SUPPORT_MULT_INPUT 0 +#define USE_MANUAL_SINK +#define BUFFER_SIZE 512 typedef struct _GMencoderPrivate GMencoderPrivate; typedef struct _SetupInfo SetupInfo; @@ -96,13 +98,21 @@ const gchar * audio_encode, gchar ** audio_encode_prop, guint audio_rate); +#ifdef USE_MANUAL_SINK +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 }; G_DEFINE_TYPE(GMencoder, g_mencoder, G_TYPE_OBJECT) - static void g_mencoder_class_init(GMencoderClass * klass) + +static void g_mencoder_class_init(GMencoderClass * klass) { GObjectClass *object_class; object_class = (GObjectClass *) klass; @@ -666,11 +676,19 @@ queue = gst_element_factory_make("queue", "queueu_sink"); +#ifdef USE_MANUAL_SINK + sink = gst_element_factory_make("fakesink", "sink"); + g_signal_connect (G_OBJECT (sink), + "handoff", + G_CALLBACK (_buffer_arrive_cb), + GINT_TO_POINTER (priv->fd)); +#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) @@ -1033,3 +1051,26 @@ return TRUE; } + + +#ifdef USE_MANUAL_SINK +static void +_buffer_arrive_cb (GstElement* object, + GstBuffer* buff, + GstPad* pad, + gpointer user_data) +{ + static GByteArray *queue = NULL; + static guint offset = 0; + + gint fd = GPOINTER_TO_INT (user_data); + + queue = g_byte_array_append (queue, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)); + + if (queue->len >= BUFFER_SIZE) { + write (fd, queue->data, BUFFER_SIZE); + queue = g_byte_array_remove_range (queue, 0, BUFFER_SIZE); + } +} +#endif +