summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2005-05-05 09:46:03 +0000
committerWim Taymans <wim.taymans@gmail.com>2005-05-05 09:46:03 +0000
commit80d4778bd44c37a01f5130d34df7486b6d8dc972 (patch)
tree47f4bd3b4f26505ad0cbad5b00a25b5e2842408c /gst
parent4a77aaddbcee406d49efc82431b452476315b216 (diff)
gst/adder/: Ported adder as an example of a mixer element using collect pads. Needs more negotiation work.
Original commit message from CVS: * gst/adder/Makefile.am: * gst/adder/gstadder.c: (gst_adder_setcaps), (gst_adder_class_init), (gst_adder_init), (gst_adder_request_new_pad), (gst_adder_collected), (gst_adder_change_state): * gst/adder/gstadder.h: Ported adder as an example of a mixer element using collect pads. Needs more negotiation work.
Diffstat (limited to 'gst')
-rw-r--r--gst/adder/Makefile.am2
-rw-r--r--gst/adder/gstadder.c482
-rw-r--r--gst/adder/gstadder.h24
3 files changed, 214 insertions, 294 deletions
diff --git a/gst/adder/Makefile.am b/gst/adder/Makefile.am
index afa47ef63..cba7c4853 100644
--- a/gst/adder/Makefile.am
+++ b/gst/adder/Makefile.am
@@ -4,6 +4,6 @@ plugin_LTLIBRARIES = libgstadder.la
libgstadder_la_SOURCES = gstadder.c
libgstadder_la_CFLAGS = $(GST_CFLAGS)
libgstadder_la_LIBADD =
-libgstadder_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstadder_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS)
noinst_HEADERS = gstadder.h
diff --git a/gst/adder/gstadder.c b/gst/adder/gstadder.c
index 63478e494..298355b13 100644
--- a/gst/adder/gstadder.c
+++ b/gst/adder/gstadder.c
@@ -1,7 +1,7 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
- * 2000 Wim Taymans <wim.taymans@chello.be>
* 2001 Thomas <thomas@apestaart.org>
+ * 2005 Wim Taymans <wim@fluendo.com>
*
* adder.c: Adder element, N in, one out, samples are added
*
@@ -30,19 +30,19 @@
#include <string.h> /* strcmp */
/* highest positive/lowest negative x-bit value we can use for clamping */
-//#define MAX_INT_x ((guint) 1 << (x - 1))
-#define MAX_INT_32 2147483647L
-#define MAX_INT_16 32767
-#define MAX_INT_8 127
-
-//#define MIN_INT_x (-((guint) 1 << (x - 1)))
-/* to make non-C90 happy we need to specify the constant differently */
-#define MIN_INT_32 (-2147483647L -1L)
-#define MIN_INT_16 -32768
-#define MIN_INT_8 -128
-
-#define GST_ADDER_BUFFER_SIZE 4096
-#define GST_ADDER_NUM_BUFFERS 8
+#define MAX_INT_32 ((gint32) (0x7fffffff))
+#define MAX_INT_16 ((gint16) (0x7fff))
+#define MAX_INT_8 ((gint8) (0x7f))
+#define MAX_UINT_32 ((guint32)(0xffffffff))
+#define MAX_UINT_16 ((guint16)(0xffff))
+#define MAX_UINT_8 ((guint8) (0xff))
+
+#define MIN_INT_32 ((gint32) (0x80000000))
+#define MIN_INT_16 ((gint16) (0x8000))
+#define MIN_INT_8 ((gint8) (0x80))
+#define MIN_UINT_32 ((guint32)(0x00000000))
+#define MIN_UINT_16 ((guint16)(0x0000))
+#define MIN_UINT_8 ((guint8) (0x00))
GST_DEBUG_CATEGORY_STATIC (gst_adder_debug);
#define GST_CAT_DEFAULT gst_adder_debug
@@ -63,8 +63,7 @@ enum
enum
{
ARG_0,
- ARG_NUM_PADS
- /* FILL ME */
+ /* FILL ME */
};
static GstStaticPadTemplate gst_adder_src_template =
@@ -86,15 +85,14 @@ static GstStaticPadTemplate gst_adder_sink_template =
static void gst_adder_class_init (GstAdderClass * klass);
static void gst_adder_init (GstAdder * adder);
-static void gst_adder_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec);
-
static GstPad *gst_adder_request_new_pad (GstElement * element,
GstPadTemplate * temp, const gchar * unused);
static GstElementStateReturn gst_adder_change_state (GstElement * element);
-/* we do need a loop function */
-static void gst_adder_loop (GstElement * element);
+static gboolean gst_adder_setcaps (GstPad * pad, GstCaps * caps);
+
+static GstFlowReturn gst_adder_collected (GstCollectPads * pads,
+ gpointer user_data);
static GstElementClass *parent_class = NULL;
@@ -121,49 +119,45 @@ gst_adder_get_type (void)
return adder_type;
}
-static GstPadLinkReturn
-gst_adder_link (GstPad * pad, const GstCaps * caps)
+#define MAKE_FUNC(name,type,ttype,min,max) \
+static void name (type *out, type *in, gint bytes) { \
+ gint i; \
+ for (i = 0; i < bytes / sizeof (type); i++) \
+ out[i] = CLAMP ((ttype)out[i] + (ttype)in[i], min, max); \
+}
+
+MAKE_FUNC (add_int32, gint32, gint64, MIN_INT_32, MAX_INT_32)
+ MAKE_FUNC (add_int16, gint16, gint32, MIN_INT_16, MAX_INT_16)
+ MAKE_FUNC (add_int8, gint8, gint16, MIN_INT_8, MAX_INT_8)
+ MAKE_FUNC (add_uint32, guint32, guint64, MIN_UINT_32, MAX_UINT_32)
+ MAKE_FUNC (add_uint16, guint16, guint32, MIN_UINT_16, MAX_UINT_16)
+ MAKE_FUNC (add_uint8, guint8, guint16, MIN_UINT_8, MAX_UINT_8)
+ MAKE_FUNC (add_float64, gdouble, gdouble, -1.0, 1.0)
+ MAKE_FUNC (add_float32, gfloat, gfloat, -1.0, 1.0)
+
+ static gboolean gst_adder_setcaps (GstPad * pad, GstCaps * caps)
{
GstAdder *adder;
- const char *media_type;
- const GList *pads;
+ GList *pads;
GstStructure *structure;
- GstPadLinkReturn ret;
- GstElement *element;
-
- g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
- g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED);
-
- element = GST_PAD_PARENT (pad);
- adder = GST_ADDER (element);
-
- pads = gst_element_get_pad_list (element);
- while (pads) {
- GstPad *otherpad = GST_PAD (pads->data);
-
- if (otherpad != pad) {
- ret = gst_pad_try_set_caps (otherpad, caps);
- if (GST_PAD_LINK_FAILED (ret)) {
- return ret;
- }
- }
- pads = g_list_next (pads);
- }
+ const char *media_type;
+ adder = GST_ADDER (GST_PAD_PARENT (pad));
- pads = gst_element_get_pad_list (GST_ELEMENT (adder));
+ /* see if the other pads can accept the format */
+ GST_LOCK (adder);
+ pads = GST_ELEMENT (adder)->pads;
while (pads) {
GstPad *otherpad = GST_PAD (pads->data);
if (otherpad != pad) {
- ret = gst_pad_try_set_caps (otherpad, caps);
- if (GST_PAD_LINK_FAILED (ret)) {
- return ret;
- }
+ gst_caps_replace (&GST_PAD_CAPS (otherpad), caps);
}
pads = g_list_next (pads);
}
+ GST_UNLOCK (adder);
+ /* parse caps now */
structure = gst_caps_get_structure (caps, 0);
media_type = gst_structure_get_name (structure);
if (strcmp (media_type, "audio/x-raw-int") == 0) {
@@ -173,17 +167,54 @@ gst_adder_link (GstPad * pad, const GstCaps * caps)
gst_structure_get_int (structure, "depth", &adder->depth);
gst_structure_get_int (structure, "endianness", &adder->endianness);
gst_structure_get_boolean (structure, "signed", &adder->is_signed);
- gst_structure_get_int (structure, "channels", &adder->channels);
- gst_structure_get_int (structure, "rate", &adder->rate);
+
+ if (adder->endianness != G_BYTE_ORDER)
+ goto not_supported;
+
+ switch (adder->width) {
+ case 8:
+ adder->func = (adder->is_signed ?
+ (GstAdderFunction) add_int8 : (GstAdderFunction) add_uint8);
+ break;
+ case 16:
+ adder->func = (adder->is_signed ?
+ (GstAdderFunction) add_int16 : (GstAdderFunction) add_uint16);
+ break;
+ case 32:
+ adder->func = (adder->is_signed ?
+ (GstAdderFunction) add_int32 : (GstAdderFunction) add_uint32);
+ break;
+ default:
+ goto not_supported;
+ }
} else if (strcmp (media_type, "audio/x-raw-float") == 0) {
GST_DEBUG ("parse_caps sets adder to format float");
adder->format = GST_ADDER_FORMAT_FLOAT;
gst_structure_get_int (structure, "width", &adder->width);
- gst_structure_get_int (structure, "channels", &adder->channels);
- gst_structure_get_int (structure, "rate", &adder->rate);
+
+ switch (adder->width) {
+ case 32:
+ adder->func = (GstAdderFunction) add_float32;
+ break;
+ case 64:
+ adder->func = (GstAdderFunction) add_float64;
+ break;
+ default:
+ goto not_supported;
+ }
+ } else {
+ goto not_supported;
}
- return GST_PAD_LINK_OK;
+ gst_structure_get_int (structure, "channels", &adder->channels);
+ gst_structure_get_int (structure, "rate", &adder->rate);
+
+ return TRUE;
+
+not_supported:
+ {
+ return FALSE;
+ }
}
static void
@@ -203,12 +234,6 @@ gst_adder_class_init (GstAdderClass * klass)
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
- g_param_spec_int ("num_pads", "number of pads", "Number Of Pads",
- 0, G_MAXINT, 0, G_PARAM_READABLE));
-
- gobject_class->get_property = gst_adder_get_property;
-
gstelement_class->request_new_pad = gst_adder_request_new_pad;
gstelement_class->change_state = gst_adder_change_state;
}
@@ -219,17 +244,17 @@ gst_adder_init (GstAdder * adder)
adder->srcpad =
gst_pad_new_from_template (gst_static_pad_template_get
(&gst_adder_src_template), "src");
- gst_element_add_pad (GST_ELEMENT (adder), adder->srcpad);
- gst_element_set_loop_function (GST_ELEMENT (adder), gst_adder_loop);
gst_pad_set_getcaps_function (adder->srcpad, gst_pad_proxy_getcaps);
- gst_pad_set_link_function (adder->srcpad, gst_adder_link);
+ gst_pad_set_setcaps_function (adder->srcpad, gst_adder_setcaps);
+ gst_element_add_pad (GST_ELEMENT (adder), adder->srcpad);
adder->format = GST_ADDER_FORMAT_UNSET;
+ adder->numpads = 0;
+ adder->func = NULL;
/* keep track of the sinkpads requested */
-
- adder->numsinkpads = 0;
- adder->input_channels = NULL;
+ adder->collect = gst_collectpads_new ();
+ gst_collectpads_set_function (adder->collect, gst_adder_collected, adder);
}
static GstPad *
@@ -238,279 +263,180 @@ gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ,
{
gchar *name;
GstAdder *adder;
- GstAdderInputChannel *input;
+ GstPad *newpad;
g_return_val_if_fail (GST_IS_ADDER (element), NULL);
- if (templ->direction != GST_PAD_SINK) {
- g_warning ("gstadder: request new pad that is not a SINK pad\n");
- return NULL;
- }
-
- /* allocate space for the input_channel */
-
- input = (GstAdderInputChannel *) g_malloc (sizeof (GstAdderInputChannel));
- if (input == NULL) {
- g_warning ("gstadder: could not allocate adder input channel !\n");
- return NULL;
- }
+ if (templ->direction != GST_PAD_SINK)
+ goto not_sink;
adder = GST_ADDER (element);
- /* fill in input_channel structure */
+ name = g_strdup_printf ("sink%d", adder->numpads);
+ newpad = gst_pad_new_from_template (templ, name);
- name = g_strdup_printf ("sink%d", adder->numsinkpads);
- input->sinkpad = gst_pad_new_from_template (templ, name);
- input->bytestream = gst_bytestream_new (input->sinkpad);
+ gst_pad_set_getcaps_function (newpad, gst_pad_proxy_getcaps);
+ gst_pad_set_setcaps_function (newpad, gst_adder_setcaps);
+ gst_collectpads_add_pad (adder->collect, newpad, sizeof (GstCollectData));
+ if (!gst_element_add_pad (GST_ELEMENT (adder), newpad))
+ goto could_not_add;
- gst_element_add_pad (GST_ELEMENT (adder), input->sinkpad);
- gst_pad_set_getcaps_function (input->sinkpad, gst_pad_proxy_getcaps);
- gst_pad_set_link_function (input->sinkpad, gst_adder_link);
+ adder->numpads++;
- /* add the input_channel to the list of input channels */
+ return newpad;
- adder->input_channels = g_slist_append (adder->input_channels, input);
- adder->numsinkpads++;
-
- return input->sinkpad;
-}
-
-static void
-gst_adder_get_property (GObject * object, guint prop_id, GValue * value,
- GParamSpec * pspec)
-{
- GstAdder *adder;
-
- /* it's not null if we got it, but it might not be ours */
- g_return_if_fail (GST_IS_ADDER (object));
-
- adder = GST_ADDER (object);
-
- switch (prop_id) {
- case ARG_NUM_PADS:
- g_value_set_int (value, adder->numsinkpads);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ /* errors */
+not_sink:
+ {
+ g_warning ("gstadder: request new pad that is not a SINK pad\n");
+ return NULL;
+ }
+could_not_add:
+ {
+ gst_collectpads_remove_pad (adder->collect, newpad);
+ gst_object_unref (GST_OBJECT (newpad));
+ return NULL;
}
}
-/* use this loop */
-static void
-gst_adder_loop (GstElement * element)
+static GstFlowReturn
+gst_adder_collected (GstCollectPads * pads, gpointer user_data)
{
/*
* combine channels by adding sample values
* basic algorithm :
- * - request an output buffer from the pool
- * - repeat for each input pipe :
- * - get number of bytes from the channel's bytestream to fill output buffer
+ * - this function is called when all pads have a buffer
+ * - get available bytes on all pads.
+ * - repeat for each input pad :
+ * - read available bytes, copy or add to target buffer
* - if there's an EOS event, remove the input channel
- * - otherwise add the gotten bytes to the output buffer
* - push out the output buffer
*/
GstAdder *adder;
- GstBuffer *buf_out;
+ guint size;
+ GSList *collected;
+ GstBuffer *outbuf;
+ GstFlowReturn ret;
+ gpointer outbytes;
- GSList *inputs;
+ adder = GST_ADDER (user_data);
- register guint i;
+ /* get available bytes for reading */
+ size = gst_collectpads_available (pads);
+ if (size == 0)
+ return GST_FLOW_OK;
- g_return_if_fail (element != NULL);
- g_return_if_fail (GST_IS_ADDER (element));
+ outbuf = NULL;
+ outbytes = NULL;
- adder = GST_ADDER (element);
+ if (adder->func == NULL)
+ goto not_negotiated;
- /* get new output buffer */
- /* FIXME the 1024 is arbitrary */
- buf_out = gst_buffer_new_and_alloc (1024);
+ GST_LOG ("starting to cycle through channels, collecting %d bytes", size);
- if (buf_out == NULL) {
- GST_ELEMENT_ERROR (adder, CORE, TOO_LAZY, (NULL),
- ("could not get new output buffer"));
- return;
- }
+ for (collected = pads->data; collected; collected = g_slist_next (collected)) {
+ GstCollectData *data;
+ guint8 *bytes;
+ guint len;
- /* initialize the output data to 0 */
- memset (GST_BUFFER_DATA (buf_out), 0, GST_BUFFER_SIZE (buf_out));
+ data = (GstCollectData *) collected->data;
- /* get data from all of the sinks */
- inputs = adder->input_channels;
+ GST_LOG_OBJECT (adder, "looking into channel %p", data);
- GST_LOG ("starting to cycle through channels");
-
- while (inputs) {
- guint32 got_bytes;
- guint8 *raw_in;
- GstAdderInputChannel *input;
-
- input = (GstAdderInputChannel *) inputs->data;
+ /* get pointer to copy size bytes */
+ len = gst_collectpads_read (pads, data, &bytes, size);
+ if (len == 0)
+ continue;
- inputs = inputs->next;
+ GST_LOG (" copying %d bytes (format %d,%d)",
+ len, adder->format, adder->width);
+ GST_LOG (" from channel %p from input data %p", data, bytes);
- GST_LOG_OBJECT (adder, " looking into channel %p", input);
+ if (outbuf == NULL) {
+ /* first buffer, alloc size bytes */
+ outbuf = gst_buffer_new_and_alloc (size);
+ gst_buffer_set_caps (outbuf, GST_PAD_CAPS (adder->srcpad));
+ outbytes = GST_BUFFER_DATA (outbuf);
- if (!GST_PAD_IS_USABLE (input->sinkpad)) {
- GST_LOG_OBJECT (adder, " adder ignoring pad %s:%s",
- GST_DEBUG_PAD_NAME (input->sinkpad));
- continue;
- }
+ memset (outbytes, 0, size);
- /* Get data from the bytestream of each input channel. We need to check for
- events before passing on the data to the output buffer. */
- repeat:
- got_bytes = gst_bytestream_peek_bytes (input->bytestream, &raw_in,
- GST_BUFFER_SIZE (buf_out));
-
- /* FIXME we should do something with the data if got_bytes > 0 */
- if (got_bytes < GST_BUFFER_SIZE (buf_out)) {
- GstEvent *event = NULL;
- guint32 waiting;
-
- /* we need to check for an event. */
- gst_bytestream_get_status (input->bytestream, &waiting, &event);
-
- if (event) {
- switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_EOS:
- /* if we get an EOS event from one of our sink pads, we assume that
- pad's finished handling data. just skip this pad. */
- GST_DEBUG (" got an EOS event");
- gst_event_unref (event);
- continue;
- case GST_EVENT_INTERRUPT:
- gst_event_unref (event);
- GST_DEBUG (" got an interrupt event");
- /* we have to call interrupt here, the scheduler will switch out
- this element ASAP or returns TRUE if we need to exit the loop */
- if (gst_element_interrupt (GST_ELEMENT (adder))) {
- gst_buffer_unref (buf_out);
- return;
- }
- default:
- GST_LOG_OBJECT (adder, "pulling again after event");
- goto repeat;
- }
- }
+ /* and copy the data into it */
+ memcpy (outbytes, bytes, len);
} else {
- /* here's where the data gets copied. */
-
- GST_LOG (" copying %d bytes (format %d,%d)",
- GST_BUFFER_SIZE (buf_out), adder->format, adder->width);
- GST_LOG (" from channel %p from input data %p", input, raw_in);
- GST_LOG (" to output data %p in buffer %p",
- GST_BUFFER_DATA (buf_out), buf_out);
-
- if (adder->format == GST_ADDER_FORMAT_INT) {
- if (adder->width == 32) {
- gint32 *in = (gint32 *) raw_in;
- gint32 *out = (gint32 *) GST_BUFFER_DATA (buf_out);
-
- for (i = 0; i < GST_BUFFER_SIZE (buf_out) / 4; i++)
- out[i] = CLAMP (((gint64) out[i]) + ((gint64) in[i]),
- MIN_INT_32, MAX_INT_32);
- } else if (adder->width == 16) {
- gint16 *in = (gint16 *) raw_in;
- gint16 *out = (gint16 *) GST_BUFFER_DATA (buf_out);
-
- for (i = 0; i < GST_BUFFER_SIZE (buf_out) / 2; i++)
- out[i] = CLAMP (out[i] + in[i], MIN_INT_16, MAX_INT_16);
- } else if (adder->width == 8) {
- gint8 *in = (gint8 *) raw_in;
- gint8 *out = (gint8 *) GST_BUFFER_DATA (buf_out);
-
- for (i = 0; i < GST_BUFFER_SIZE (buf_out); i++)
- out[i] = CLAMP (out[i] + in[i], MIN_INT_8, MAX_INT_8);
- } else {
- GST_ELEMENT_ERROR (adder, STREAM, FORMAT, (NULL),
- ("invalid width (%u) for integer audio in gstadder",
- adder->width));
- return;
- }
- } else if (adder->format == GST_ADDER_FORMAT_FLOAT) {
- if (adder->width == 64) {
- gdouble *in = (gdouble *) raw_in;
- gdouble *out = (gdouble *) GST_BUFFER_DATA (buf_out);
-
- for (i = 0; i < GST_BUFFER_SIZE (buf_out) / sizeof (gdouble); i++)
- out[i] = CLAMP (out[i] + in[i], -1.0, 1.0);
- } else if (adder->width == 32) {
- gfloat *in = (gfloat *) raw_in;
- gfloat *out = (gfloat *) GST_BUFFER_DATA (buf_out);
-
- for (i = 0; i < GST_BUFFER_SIZE (buf_out) / sizeof (gfloat); i++)
- out[i] = CLAMP (out[i] + in[i], -1.0, 1.0);
- } else {
- GST_ELEMENT_ERROR (adder, STREAM, FORMAT, (NULL),
- ("invalid width (%u) for float audio in gstadder", adder->width));
- return;
- }
- } else {
- GST_ELEMENT_ERROR (adder, STREAM, FORMAT, (NULL),
- ("invalid audio format (%d) in gstadder", adder->format));
- return;
- }
-
- gst_bytestream_flush (input->bytestream, GST_BUFFER_SIZE (buf_out));
-
- GST_LOG ("done copying data");
+ /* other buffers, need to add them */
+ adder->func ((gpointer) outbytes, (gpointer) bytes, len);
}
- }
- if (adder->width == 0) {
- GST_ELEMENT_ERROR (adder, CORE, NEGOTIATION, (NULL), ("width is 0"));
- return;
- }
- if (adder->channels == 0) {
- GST_ELEMENT_ERROR (adder, CORE, NEGOTIATION, (NULL), ("channels is 0"));
- return;
- }
- if (adder->rate == 0) {
- GST_ELEMENT_ERROR (adder, CORE, NEGOTIATION, (NULL), ("rate is 0"));
- return;
+ gst_collectpads_flush (pads, data, len);
}
- GST_BUFFER_TIMESTAMP (buf_out) = adder->timestamp;
- if (adder->format == GST_ADDER_FORMAT_FLOAT)
- adder->offset += GST_BUFFER_SIZE (buf_out) / adder->width / adder->channels;
- else
- adder->offset +=
- GST_BUFFER_SIZE (buf_out) * 8 / adder->width / adder->channels;
- adder->timestamp = adder->offset * GST_SECOND / adder->rate;
+ /* set timestamps on the output buffer */
+ {
+ guint64 duration;
+
+ if (adder->format == GST_ADDER_FORMAT_FLOAT)
+ duration = size / adder->width / adder->channels;
+ else
+ duration = size * 8 / adder->width / adder->channels;
+
+ GST_BUFFER_TIMESTAMP (outbuf) = adder->timestamp;
+ GST_BUFFER_OFFSET (outbuf) = adder->offset;
+ GST_BUFFER_DURATION (outbuf) = duration;
+
+ adder->offset += duration;
+ adder->timestamp = adder->offset * GST_SECOND / adder->rate;
+ }
/* send it out */
+ GST_LOG ("pushing outbuf");
+ ret = gst_pad_push (adder->srcpad, outbuf);
- GST_LOG ("pushing buf_out");
- gst_pad_push (adder->srcpad, GST_DATA (buf_out));
-}
+ return ret;
+ /* ERRORS */
+not_negotiated:
+ {
+ return GST_FLOW_NOT_NEGOTIATED;
+ }
+}
static GstElementStateReturn
gst_adder_change_state (GstElement * element)
{
GstAdder *adder;
+ GstElementStateReturn ret;
+ gint transition;
adder = GST_ADDER (element);
+ transition = GST_STATE_TRANSITION (element);
- switch (GST_STATE_TRANSITION (element)) {
+ switch (transition) {
case GST_STATE_NULL_TO_READY:
break;
case GST_STATE_READY_TO_PAUSED:
adder->timestamp = 0;
adder->offset = 0;
+ gst_collectpads_start (adder->collect);
break;
case GST_STATE_PAUSED_TO_PLAYING:
+ break;
+ default:
+ break;
+ }
+
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
+
+ switch (transition) {
case GST_STATE_PLAYING_TO_PAUSED:
+ break;
case GST_STATE_PAUSED_TO_READY:
+ gst_collectpads_stop (adder->collect);
+ break;
case GST_STATE_READY_TO_NULL:
+ break;
default:
break;
}
-
- if (GST_ELEMENT_CLASS (parent_class)->change_state)
- return GST_ELEMENT_CLASS (parent_class)->change_state (element);
-
- return GST_STATE_SUCCESS;
+ return ret;
}
diff --git a/gst/adder/gstadder.h b/gst/adder/gstadder.h
index 00a950b5a..cc46f3e1d 100644
--- a/gst/adder/gstadder.h
+++ b/gst/adder/gstadder.h
@@ -24,11 +24,9 @@
#define __GST_ADDER_H__
#include <gst/gst.h>
-#include <gst/bytestream/bytestream.h>
+#include <gst/base/gstcollectpads.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+G_BEGIN_DECLS
extern GstElementDetails gst_adder_details;
@@ -54,19 +52,14 @@ enum _GstAdderFormat {
GST_ADDER_FORMAT_FLOAT
};
-struct _GstAdderInputChannel {
- GstPad *sinkpad;
- GstByteStream *bytestream;
-};
+typedef void (*GstAdderFunction) (gpointer out, gpointer in, guint size);
struct _GstAdder {
GstElement element;
GstPad *srcpad;
-
- /* keep track of the sinkpads */
- guint numsinkpads;
- GSList *input_channels;
+ GstCollectPads *collect;
+ gint numpads;
/* the next are valid for both int and float */
GstAdderFormat format;
@@ -79,6 +72,9 @@ struct _GstAdder {
guint depth;
gboolean is_signed;
+ /* function to add samples */
+ GstAdderFunction func;
+
/* counters to keep track of timestamps */
gint64 timestamp;
gint64 offset;
@@ -91,9 +87,7 @@ struct _GstAdderClass {
GType gst_adder_get_type (void);
gboolean gst_adder_factory_init (GstElementFactory *factory);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+G_END_DECLS
#endif /* __GST_ADDER_H__ */