Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / adder / gstadder.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2001 Thomas <thomas@apestaart.org>
4  *               2005,2006 Wim Taymans <wim@fluendo.com>
5  *
6  * adder.c: Adder element, N in, one out, samples are added
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 /**
24  * SECTION:element-adder
25  *
26  * The adder allows to mix several streams into one by adding the data.
27  * Mixed data is clamped to the min/max values of the data format.
28  *
29  * The adder currently mixes all data received on the sinkpads as soon as
30  * possible without trying to synchronize the streams.
31  *
32  * <refsect2>
33  * <title>Example launch line</title>
34  * |[
35  * gst-launch audiotestsrc freq=100 ! adder name=mix ! audioconvert ! alsasink audiotestsrc freq=500 ! mix.
36  * ]| This pipeline produces two sine waves mixed together.
37  * </refsect2>
38  *
39  * Last reviewed on 2006-05-09 (0.10.7)
40  */
41 /* Element-Checklist-Version: 5 */
42
43 #ifdef HAVE_CONFIG_H
44 #include "config.h"
45 #endif
46 #include "gstadder.h"
47 #include <gst/audio/audio.h>
48 #include <string.h>             /* strcmp */
49 #include "gstadderorc.h"
50
51 /* highest positive/lowest negative x-bit value we can use for clamping */
52 #define MAX_INT_32  ((gint32) (0x7fffffff))
53 #define MAX_INT_16  ((gint16) (0x7fff))
54 #define MAX_INT_8   ((gint8)  (0x7f))
55 #define MAX_UINT_32 ((guint32)(0xffffffff))
56 #define MAX_UINT_16 ((guint16)(0xffff))
57 #define MAX_UINT_8  ((guint8) (0xff))
58
59 #define MIN_INT_32  ((gint32) (0x80000000))
60 #define MIN_INT_16  ((gint16) (0x8000))
61 #define MIN_INT_8   ((gint8)  (0x80))
62 #define MIN_UINT_32 ((guint32)(0x00000000))
63 #define MIN_UINT_16 ((guint16)(0x0000))
64 #define MIN_UINT_8  ((guint8) (0x00))
65
66 enum
67 {
68   PROP_0,
69   PROP_FILTER_CAPS
70 };
71
72 #define GST_CAT_DEFAULT gst_adder_debug
73 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
74
75 /* elementfactory information */
76
77 #define CAPS \
78   "audio/x-raw-int, " \
79   "rate = (int) [ 1, MAX ], " \
80   "channels = (int) [ 1, MAX ], " \
81   "endianness = (int) BYTE_ORDER, " \
82   "width = (int) 32, " \
83   "depth = (int) 32, " \
84   "signed = (boolean) { true, false } ;" \
85   "audio/x-raw-int, " \
86   "rate = (int) [ 1, MAX ], " \
87   "channels = (int) [ 1, MAX ], " \
88   "endianness = (int) BYTE_ORDER, " \
89   "width = (int) 16, " \
90   "depth = (int) 16, " \
91   "signed = (boolean) { true, false } ;" \
92   "audio/x-raw-int, " \
93   "rate = (int) [ 1, MAX ], " \
94   "channels = (int) [ 1, MAX ], " \
95   "endianness = (int) BYTE_ORDER, " \
96   "width = (int) 8, " \
97   "depth = (int) 8, " \
98   "signed = (boolean) { true, false } ;" \
99   "audio/x-raw-float, " \
100   "rate = (int) [ 1, MAX ], " \
101   "channels = (int) [ 1, MAX ], " \
102   "endianness = (int) BYTE_ORDER, " \
103   "width = (int) { 32, 64 }"
104
105 static GstStaticPadTemplate gst_adder_src_template =
106 GST_STATIC_PAD_TEMPLATE ("src",
107     GST_PAD_SRC,
108     GST_PAD_ALWAYS,
109     GST_STATIC_CAPS (CAPS)
110     );
111
112 static GstStaticPadTemplate gst_adder_sink_template =
113 GST_STATIC_PAD_TEMPLATE ("sink%d",
114     GST_PAD_SINK,
115     GST_PAD_REQUEST,
116     GST_STATIC_CAPS (CAPS)
117     );
118
119 #define gst_adder_parent_class parent_class
120 G_DEFINE_TYPE (GstAdder, gst_adder, GST_TYPE_ELEMENT);
121
122 static void gst_adder_dispose (GObject * object);
123 static void gst_adder_set_property (GObject * object, guint prop_id,
124     const GValue * value, GParamSpec * pspec);
125 static void gst_adder_get_property (GObject * object, guint prop_id,
126     GValue * value, GParamSpec * pspec);
127
128 static gboolean gst_adder_setcaps (GstPad * pad, GstCaps * caps);
129 static gboolean gst_adder_query (GstPad * pad, GstQuery ** query);
130 static gboolean gst_adder_src_event (GstPad * pad, GstEvent * event);
131 static gboolean gst_adder_sink_event (GstPad * pad, GstEvent * event);
132
133 static GstPad *gst_adder_request_new_pad (GstElement * element,
134     GstPadTemplate * temp, const gchar * unused, const GstCaps * caps);
135 static void gst_adder_release_pad (GstElement * element, GstPad * pad);
136
137 static GstStateChangeReturn gst_adder_change_state (GstElement * element,
138     GstStateChange transition);
139
140 static GstBuffer *gst_adder_do_clip (GstCollectPads * pads,
141     GstCollectData * data, GstBuffer * buffer, gpointer user_data);
142 static GstFlowReturn gst_adder_collected (GstCollectPads * pads,
143     gpointer user_data);
144
145 /* non-clipping versions (for float) */
146 #define MAKE_FUNC_NC(name,type)                                 \
147 static void name (type *out, type *in, gint samples) {          \
148   gint i;                                                       \
149   for (i = 0; i < samples; i++)                                 \
150     out[i] += in[i];                                            \
151 }
152
153 /* *INDENT-OFF* */
154 MAKE_FUNC_NC (add_float64, gdouble)
155 /* *INDENT-ON* */
156
157 /* we can only accept caps that we and downstream can handle.
158  * if we have filtercaps set, use those to constrain the target caps.
159  */
160 static GstCaps *
161 gst_adder_sink_getcaps (GstPad * pad, GstCaps * filter)
162 {
163   GstAdder *adder;
164   GstCaps *result, *peercaps, *sinkcaps, *filter_caps;
165
166   adder = GST_ADDER (GST_PAD_PARENT (pad));
167
168   GST_OBJECT_LOCK (adder);
169   /* take filter */
170   if ((filter_caps = adder->filter_caps)) {
171     if (filter)
172       filter_caps =
173           gst_caps_intersect_full (filter, filter_caps,
174           GST_CAPS_INTERSECT_FIRST);
175     else
176       gst_caps_ref (filter_caps);
177   } else {
178     filter_caps = gst_caps_ref (filter);
179   }
180   GST_OBJECT_UNLOCK (adder);
181
182   if (filter_caps && gst_caps_is_empty (filter_caps)) {
183     GST_WARNING_OBJECT (pad, "Empty filter caps");
184     return filter_caps;
185   }
186
187   /* get the downstream possible caps */
188   peercaps = gst_pad_peer_get_caps (adder->srcpad, filter_caps);
189
190   /* get the allowed caps on this sinkpad */
191   sinkcaps = gst_pad_get_current_caps (pad);
192   if (sinkcaps == NULL) {
193     sinkcaps = (GstCaps *) gst_pad_get_pad_template_caps (pad);
194     if (sinkcaps)
195       gst_caps_ref (sinkcaps);
196     else
197       sinkcaps = gst_caps_new_any ();
198   }
199
200   if (peercaps) {
201     /* if the peer has caps, intersect */
202     GST_DEBUG_OBJECT (adder, "intersecting peer and template caps");
203     result =
204         gst_caps_intersect_full (peercaps, sinkcaps, GST_CAPS_INTERSECT_FIRST);
205     gst_caps_unref (peercaps);
206     gst_caps_unref (sinkcaps);
207   } else {
208     /* the peer has no caps (or there is no peer), just use the allowed caps
209      * of this sinkpad. */
210     /* restrict with filter-caps if any */
211     if (filter_caps) {
212       GST_DEBUG_OBJECT (adder, "no peer caps, using filtered sinkcaps");
213       result =
214           gst_caps_intersect_full (filter_caps, sinkcaps,
215           GST_CAPS_INTERSECT_FIRST);
216       gst_caps_unref (sinkcaps);
217     } else {
218       GST_DEBUG_OBJECT (adder, "no peer caps, using sinkcaps");
219       result = sinkcaps;
220     }
221   }
222
223   if (filter_caps)
224     gst_caps_unref (filter_caps);
225
226   GST_LOG_OBJECT (adder, "getting caps on pad %p,%s to %" GST_PTR_FORMAT, pad,
227       GST_PAD_NAME (pad), result);
228
229   return result;
230 }
231
232 typedef struct
233 {
234   GstPad *pad;
235   GstCaps *caps;
236 } IterData;
237
238 static void
239 setcapsfunc (const GValue * item, IterData * data)
240 {
241   GstPad *otherpad = g_value_get_object (item);
242
243   if (otherpad != data->pad)
244     gst_pad_set_caps (data->pad, data->caps);
245 }
246
247 /* the first caps we receive on any of the sinkpads will define the caps for all
248  * the other sinkpads because we can only mix streams with the same caps.
249  */
250 static gboolean
251 gst_adder_setcaps (GstPad * pad, GstCaps * caps)
252 {
253   GstAdder *adder;
254   GstStructure *structure;
255   const char *media_type;
256   GstIterator *it;
257   GstIteratorResult ires;
258   IterData idata;
259   gboolean done;
260
261   adder = GST_ADDER (GST_PAD_PARENT (pad));
262
263   GST_LOG_OBJECT (adder, "setting caps on pad %p,%s to %" GST_PTR_FORMAT, pad,
264       GST_PAD_NAME (pad), caps);
265
266   it = gst_element_iterate_pads (GST_ELEMENT_CAST (adder));
267
268   /* FIXME, see if the other pads can accept the format. Also lock the
269    * format on the other pads to this new format. */
270   idata.caps = caps;
271   idata.pad = pad;
272
273   done = FALSE;
274   while (!done) {
275     ires = gst_iterator_foreach (it, (GstIteratorForeachFunction) setcapsfunc,
276         &idata);
277
278     switch (ires) {
279       case GST_ITERATOR_RESYNC:
280         gst_iterator_resync (it);
281         break;
282       default:
283         done = TRUE;
284         break;
285     }
286   }
287
288   /* parse caps now */
289   structure = gst_caps_get_structure (caps, 0);
290   media_type = gst_structure_get_name (structure);
291   if (strcmp (media_type, "audio/x-raw-int") == 0) {
292     adder->format = GST_ADDER_FORMAT_INT;
293     gst_structure_get_int (structure, "width", &adder->width);
294     gst_structure_get_int (structure, "depth", &adder->depth);
295     gst_structure_get_int (structure, "endianness", &adder->endianness);
296     gst_structure_get_boolean (structure, "signed", &adder->is_signed);
297
298     GST_INFO_OBJECT (pad, "parse_caps sets adder to format int, %d bit",
299         adder->width);
300
301     if (adder->endianness != G_BYTE_ORDER)
302       goto not_supported;
303
304     switch (adder->width) {
305       case 8:
306         adder->func = (adder->is_signed ?
307             (GstAdderFunction) add_int8 : (GstAdderFunction) add_uint8);
308         adder->sample_size = 1;
309         break;
310       case 16:
311         adder->func = (adder->is_signed ?
312             (GstAdderFunction) add_int16 : (GstAdderFunction) add_uint16);
313         adder->sample_size = 2;
314         break;
315       case 32:
316         adder->func = (adder->is_signed ?
317             (GstAdderFunction) add_int32 : (GstAdderFunction) add_uint32);
318         adder->sample_size = 4;
319         break;
320       default:
321         goto not_supported;
322     }
323   } else if (strcmp (media_type, "audio/x-raw-float") == 0) {
324     adder->format = GST_ADDER_FORMAT_FLOAT;
325     gst_structure_get_int (structure, "width", &adder->width);
326     gst_structure_get_int (structure, "endianness", &adder->endianness);
327
328     GST_INFO_OBJECT (pad, "parse_caps sets adder to format float, %d bit",
329         adder->width);
330
331     if (adder->endianness != G_BYTE_ORDER)
332       goto not_supported;
333
334     switch (adder->width) {
335       case 32:
336         adder->func = (GstAdderFunction) add_float32;
337         adder->sample_size = 4;
338         break;
339       case 64:
340         adder->func = (GstAdderFunction) add_float64;
341         adder->sample_size = 8;
342         break;
343       default:
344         goto not_supported;
345     }
346   } else {
347     goto not_supported;
348   }
349
350   gst_structure_get_int (structure, "channels", &adder->channels);
351   gst_structure_get_int (structure, "rate", &adder->rate);
352   /* precalc bps */
353   adder->bps = (adder->width / 8) * adder->channels;
354
355   return TRUE;
356
357   /* ERRORS */
358 not_supported:
359   {
360     GST_DEBUG_OBJECT (adder, "unsupported format set as caps");
361     return FALSE;
362   }
363 }
364
365 /* FIXME, the duration query should reflect how long you will produce
366  * data, that is the amount of stream time until you will emit EOS.
367  *
368  * For synchronized mixing this is always the max of all the durations
369  * of upstream since we emit EOS when all of them finished.
370  *
371  * We don't do synchronized mixing so this really depends on where the
372  * streams where punched in and what their relative offsets are against
373  * eachother which we can get from the first timestamps we see.
374  *
375  * When we add a new stream (or remove a stream) the duration might
376  * also become invalid again and we need to post a new DURATION
377  * message to notify this fact to the parent.
378  * For now we take the max of all the upstream elements so the simple
379  * cases work at least somewhat.
380  */
381 static gboolean
382 gst_adder_query_duration (GstAdder * adder, GstQuery ** query)
383 {
384   gint64 max;
385   gboolean res;
386   GstFormat format;
387   GstIterator *it;
388   gboolean done;
389   GValue item = { 0, };
390
391   /* parse format */
392   gst_query_parse_duration (*query, &format, NULL);
393
394   max = -1;
395   res = TRUE;
396   done = FALSE;
397
398   it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
399   while (!done) {
400     GstIteratorResult ires;
401
402     ires = gst_iterator_next (it, &item);
403     switch (ires) {
404       case GST_ITERATOR_DONE:
405         done = TRUE;
406         break;
407       case GST_ITERATOR_OK:
408       {
409         GstPad *pad = g_value_get_object (&item);
410         gint64 duration;
411
412         /* ask sink peer for duration */
413         res &= gst_pad_query_peer_duration (pad, &format, &duration);
414         /* take max from all valid return values */
415         if (res) {
416           /* valid unknown length, stop searching */
417           if (duration == -1) {
418             max = duration;
419             done = TRUE;
420           }
421           /* else see if bigger than current max */
422           else if (duration > max)
423             max = duration;
424         }
425         g_value_reset (&item);
426         break;
427       }
428       case GST_ITERATOR_RESYNC:
429         max = -1;
430         res = TRUE;
431         gst_iterator_resync (it);
432         break;
433       default:
434         res = FALSE;
435         done = TRUE;
436         break;
437     }
438   }
439   g_value_unset (&item);
440   gst_iterator_free (it);
441
442   if (res) {
443     /* and store the max */
444     GST_DEBUG_OBJECT (adder, "Total duration in format %s: %"
445         GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (max));
446     gst_query_set_duration (*query, format, max);
447   }
448
449   return res;
450 }
451
452 static gboolean
453 gst_adder_query_latency (GstAdder * adder, GstQuery ** query)
454 {
455   GstClockTime min, max;
456   gboolean live;
457   gboolean res;
458   GstIterator *it;
459   gboolean done;
460   GValue item = { 0, };
461
462   res = TRUE;
463   done = FALSE;
464
465   live = FALSE;
466   min = 0;
467   max = GST_CLOCK_TIME_NONE;
468
469   /* Take maximum of all latency values */
470   it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
471   while (!done) {
472     GstIteratorResult ires;
473
474     ires = gst_iterator_next (it, &item);
475     switch (ires) {
476       case GST_ITERATOR_DONE:
477         done = TRUE;
478         break;
479       case GST_ITERATOR_OK:
480       {
481         GstPad *pad = g_value_get_object (&item);
482         GstQuery *peerquery;
483         GstClockTime min_cur, max_cur;
484         gboolean live_cur;
485
486         peerquery = gst_query_new_latency ();
487
488         /* Ask peer for latency */
489         res &= gst_pad_peer_query (pad, &peerquery);
490
491         /* take max from all valid return values */
492         if (res) {
493           gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
494
495           if (min_cur > min)
496             min = min_cur;
497
498           if (max_cur != GST_CLOCK_TIME_NONE &&
499               ((max != GST_CLOCK_TIME_NONE && max_cur > max) ||
500                   (max == GST_CLOCK_TIME_NONE)))
501             max = max_cur;
502
503           live = live || live_cur;
504         }
505
506         gst_query_unref (peerquery);
507         g_value_reset (&item);
508         break;
509       }
510       case GST_ITERATOR_RESYNC:
511         live = FALSE;
512         min = 0;
513         max = GST_CLOCK_TIME_NONE;
514         res = TRUE;
515         gst_iterator_resync (it);
516         break;
517       default:
518         res = FALSE;
519         done = TRUE;
520         break;
521     }
522   }
523   g_value_unset (&item);
524   gst_iterator_free (it);
525
526   if (res) {
527     /* store the results */
528     GST_DEBUG_OBJECT (adder, "Calculated total latency: live %s, min %"
529         GST_TIME_FORMAT ", max %" GST_TIME_FORMAT,
530         (live ? "yes" : "no"), GST_TIME_ARGS (min), GST_TIME_ARGS (max));
531     gst_query_set_latency (*query, live, min, max);
532   }
533
534   return res;
535 }
536
537 static gboolean
538 gst_adder_query (GstPad * pad, GstQuery ** query)
539 {
540   GstAdder *adder = GST_ADDER (gst_pad_get_parent (pad));
541   gboolean res = FALSE;
542
543   switch (GST_QUERY_TYPE (*query)) {
544     case GST_QUERY_POSITION:
545     {
546       GstFormat format;
547
548       gst_query_parse_position (*query, &format, NULL);
549
550       switch (format) {
551         case GST_FORMAT_TIME:
552           /* FIXME, bring to stream time, might be tricky */
553           gst_query_set_position (*query, format, adder->segment.position);
554           res = TRUE;
555           break;
556         case GST_FORMAT_DEFAULT:
557           gst_query_set_position (*query, format, adder->offset);
558           res = TRUE;
559           break;
560         default:
561           break;
562       }
563       break;
564     }
565     case GST_QUERY_DURATION:
566       res = gst_adder_query_duration (adder, query);
567       break;
568     case GST_QUERY_LATENCY:
569       res = gst_adder_query_latency (adder, query);
570       break;
571     default:
572       /* FIXME, needs a custom query handler because we have multiple
573        * sinkpads */
574       res = gst_pad_query_default (pad, query);
575       break;
576   }
577
578   gst_object_unref (adder);
579   return res;
580 }
581
582 typedef struct
583 {
584   GstEvent *event;
585   gboolean flush;
586 } EventData;
587
588 static gboolean
589 forward_event_func (const GValue * val, GValue * ret, EventData * data)
590 {
591   GstPad *pad = g_value_get_object (val);
592   GstEvent *event = data->event;
593
594   gst_event_ref (event);
595   GST_LOG_OBJECT (pad, "About to send event %s", GST_EVENT_TYPE_NAME (event));
596   if (!gst_pad_push_event (pad, event)) {
597     GST_WARNING_OBJECT (pad, "Sending event  %p (%s) failed.",
598         event, GST_EVENT_TYPE_NAME (event));
599     /* quick hack to unflush the pads, ideally we need a way to just unflush
600      * this single collect pad */
601     if (data->flush)
602       gst_pad_send_event (pad, gst_event_new_flush_stop ());
603   } else {
604     g_value_set_boolean (ret, TRUE);
605     GST_LOG_OBJECT (pad, "Sent event  %p (%s).",
606         event, GST_EVENT_TYPE_NAME (event));
607   }
608
609   /* continue on other pads, even if one failed */
610   return TRUE;
611 }
612
613 /* forwards the event to all sinkpads, takes ownership of the
614  * event
615  *
616  * Returns: TRUE if the event could be forwarded on all
617  * sinkpads.
618  */
619 static gboolean
620 forward_event (GstAdder * adder, GstEvent * event, gboolean flush)
621 {
622   gboolean ret;
623   GstIterator *it;
624   GstIteratorResult ires;
625   GValue vret = { 0 };
626   EventData data;
627
628   GST_LOG_OBJECT (adder, "Forwarding event %p (%s)", event,
629       GST_EVENT_TYPE_NAME (event));
630
631   data.event = event;
632   data.flush = flush;
633
634   g_value_init (&vret, G_TYPE_BOOLEAN);
635   g_value_set_boolean (&vret, FALSE);
636   it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
637   while (TRUE) {
638     ires =
639         gst_iterator_fold (it, (GstIteratorFoldFunction) forward_event_func,
640         &vret, &data);
641     switch (ires) {
642       case GST_ITERATOR_RESYNC:
643         GST_WARNING ("resync");
644         gst_iterator_resync (it);
645         g_value_set_boolean (&vret, TRUE);
646         break;
647       case GST_ITERATOR_OK:
648       case GST_ITERATOR_DONE:
649         ret = g_value_get_boolean (&vret);
650         goto done;
651       default:
652         ret = FALSE;
653         goto done;
654     }
655   }
656 done:
657   gst_iterator_free (it);
658   GST_LOG_OBJECT (adder, "Forwarded event %p (%s), ret=%d", event,
659       GST_EVENT_TYPE_NAME (event), ret);
660   gst_event_unref (event);
661
662   return ret;
663 }
664
665 static gboolean
666 gst_adder_src_event (GstPad * pad, GstEvent * event)
667 {
668   GstAdder *adder;
669   gboolean result;
670
671   adder = GST_ADDER (gst_pad_get_parent (pad));
672
673   switch (GST_EVENT_TYPE (event)) {
674     case GST_EVENT_SEEK:
675     {
676       GstSeekFlags flags;
677       gdouble rate;
678       GstSeekType curtype, endtype;
679       gint64 cur, end;
680       gboolean flush;
681
682       /* parse the seek parameters */
683       gst_event_parse_seek (event, &rate, NULL, &flags, &curtype,
684           &cur, &endtype, &end);
685
686       if ((curtype != GST_SEEK_TYPE_NONE) && (curtype != GST_SEEK_TYPE_SET)) {
687         result = FALSE;
688         GST_DEBUG_OBJECT (adder,
689             "seeking failed, unhandled seek type for start: %d", curtype);
690         goto done;
691       }
692       if ((endtype != GST_SEEK_TYPE_NONE) && (endtype != GST_SEEK_TYPE_SET)) {
693         result = FALSE;
694         GST_DEBUG_OBJECT (adder,
695             "seeking failed, unhandled seek type for end: %d", endtype);
696         goto done;
697       }
698
699       flush = (flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH;
700
701       /* check if we are flushing */
702       if (flush) {
703         /* make sure we accept nothing anymore and return WRONG_STATE */
704         gst_collect_pads_set_flushing (adder->collect, TRUE);
705
706         /* flushing seek, start flush downstream, the flush will be done
707          * when all pads received a FLUSH_STOP. */
708         gst_pad_push_event (adder->srcpad, gst_event_new_flush_start ());
709
710         /* We can't send FLUSH_STOP here since upstream could start pushing data
711          * after we unlock adder->collect.
712          * We set flush_stop_pending to TRUE instead and send FLUSH_STOP after
713          * forwarding the seek upstream or from gst_adder_collected,
714          * whichever happens first.
715          */
716         adder->flush_stop_pending = TRUE;
717       }
718       GST_DEBUG_OBJECT (adder, "handling seek event: %" GST_PTR_FORMAT, event);
719
720       /* now wait for the collected to be finished and mark a new
721        * segment. After we have the lock, no collect function is running and no
722        * new collect function will be called for as long as we're flushing. */
723       GST_OBJECT_LOCK (adder->collect);
724       adder->segment.rate = rate;
725       if (curtype == GST_SEEK_TYPE_SET)
726         adder->segment.start = cur;
727       else
728         adder->segment.start = 0;
729       if (endtype == GST_SEEK_TYPE_SET)
730         adder->segment.stop = end;
731       else
732         adder->segment.stop = GST_CLOCK_TIME_NONE;
733       /* make sure we push a new segment, to inform about new basetime
734        * see FIXME in gst_adder_collected() */
735       adder->segment_pending = TRUE;
736       if (flush) {
737         /* Yes, we need to call _set_flushing again *WHEN* the streaming threads
738          * have stopped so that the cookie gets properly updated. */
739         gst_collect_pads_set_flushing (adder->collect, TRUE);
740       }
741       GST_OBJECT_UNLOCK (adder->collect);
742       GST_DEBUG_OBJECT (adder, "forwarding seek event: %" GST_PTR_FORMAT,
743           event);
744
745       result = forward_event (adder, event, flush);
746       if (!result) {
747         /* seek failed. maybe source is a live source. */
748         GST_DEBUG_OBJECT (adder, "seeking failed");
749       }
750       if (g_atomic_int_compare_and_exchange (&adder->flush_stop_pending,
751               TRUE, FALSE)) {
752         GST_DEBUG_OBJECT (adder, "pending flush stop");
753         gst_pad_push_event (adder->srcpad, gst_event_new_flush_stop ());
754       }
755       break;
756     }
757     case GST_EVENT_QOS:
758       /* QoS might be tricky */
759       result = FALSE;
760       break;
761     case GST_EVENT_NAVIGATION:
762       /* navigation is rather pointless. */
763       result = FALSE;
764       break;
765     default:
766       /* just forward the rest for now */
767       GST_DEBUG_OBJECT (adder, "forward unhandled event: %s",
768           GST_EVENT_TYPE_NAME (event));
769       result = forward_event (adder, event, FALSE);
770       break;
771   }
772
773 done:
774   gst_object_unref (adder);
775
776   return result;
777 }
778
779 static gboolean
780 gst_adder_sink_event (GstPad * pad, GstEvent * event)
781 {
782   GstAdder *adder;
783   gboolean ret = TRUE;
784
785   adder = GST_ADDER (gst_pad_get_parent (pad));
786
787   GST_DEBUG ("Got %s event on pad %s:%s", GST_EVENT_TYPE_NAME (event),
788       GST_DEBUG_PAD_NAME (pad));
789
790   switch (GST_EVENT_TYPE (event)) {
791     case GST_EVENT_FLUSH_STOP:
792       /* we received a flush-stop. The collect_event function will push the
793        * event past our element. We simply forward all flush-stop events, even
794        * when no flush-stop was pending, this is required because collectpads
795        * does not provide an API to handle-but-not-forward the flush-stop.
796        * We unset the pending flush-stop flag so that we don't send anymore
797        * flush-stop from the collect function later.
798        */
799       GST_OBJECT_LOCK (adder->collect);
800       adder->segment_pending = TRUE;
801       adder->flush_stop_pending = FALSE;
802       /* Clear pending tags */
803       if (adder->pending_events) {
804         g_list_foreach (adder->pending_events, (GFunc) gst_event_unref, NULL);
805         g_list_free (adder->pending_events);
806         adder->pending_events = NULL;
807       }
808       GST_OBJECT_UNLOCK (adder->collect);
809       break;
810     case GST_EVENT_TAG:
811       GST_OBJECT_LOCK (adder->collect);
812       /* collect tags here so we can push them out when we collect data */
813       adder->pending_events = g_list_append (adder->pending_events, event);
814       GST_OBJECT_UNLOCK (adder->collect);
815       goto beach;
816     default:
817       break;
818   }
819
820   /* now GstCollectPads can take care of the rest, e.g. EOS */
821   ret = adder->collect_event (pad, event);
822
823 beach:
824   gst_object_unref (adder);
825   return ret;
826 }
827
828 static void
829 gst_adder_class_init (GstAdderClass * klass)
830 {
831   GObjectClass *gobject_class = (GObjectClass *) klass;
832   GstElementClass *gstelement_class = (GstElementClass *) klass;
833
834   gobject_class->set_property = gst_adder_set_property;
835   gobject_class->get_property = gst_adder_get_property;
836   gobject_class->dispose = gst_adder_dispose;
837
838   /**
839    * GstAdder:caps:
840    *
841    * Since: 0.10.24
842    */
843   g_object_class_install_property (gobject_class, PROP_FILTER_CAPS,
844       g_param_spec_boxed ("caps", "Target caps",
845           "Set target format for mixing (NULL means ANY). "
846           "Setting this property takes a reference to the supplied GstCaps "
847           "object.", GST_TYPE_CAPS,
848           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
849
850   gst_element_class_add_pad_template (gstelement_class,
851       gst_static_pad_template_get (&gst_adder_src_template));
852   gst_element_class_add_pad_template (gstelement_class,
853       gst_static_pad_template_get (&gst_adder_sink_template));
854   gst_element_class_set_details_simple (gstelement_class, "Adder",
855       "Generic/Audio",
856       "Add N audio channels together",
857       "Thomas Vander Stichele <thomas at apestaart dot org>");
858
859   gstelement_class->request_new_pad =
860       GST_DEBUG_FUNCPTR (gst_adder_request_new_pad);
861   gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_adder_release_pad);
862   gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_adder_change_state);
863 }
864
865 static void
866 gst_adder_init (GstAdder * adder)
867 {
868   GstPadTemplate *template;
869
870   template = gst_static_pad_template_get (&gst_adder_src_template);
871   adder->srcpad = gst_pad_new_from_template (template, "src");
872   gst_object_unref (template);
873
874   gst_pad_set_getcaps_function (adder->srcpad,
875       GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
876   gst_pad_set_setcaps_function (adder->srcpad,
877       GST_DEBUG_FUNCPTR (gst_adder_setcaps));
878   gst_pad_set_query_function (adder->srcpad,
879       GST_DEBUG_FUNCPTR (gst_adder_query));
880   gst_pad_set_event_function (adder->srcpad,
881       GST_DEBUG_FUNCPTR (gst_adder_src_event));
882   gst_element_add_pad (GST_ELEMENT (adder), adder->srcpad);
883
884   adder->format = GST_ADDER_FORMAT_UNSET;
885   adder->padcount = 0;
886   adder->func = NULL;
887
888   adder->filter_caps = NULL;
889
890   /* keep track of the sinkpads requested */
891   adder->collect = gst_collect_pads_new ();
892   gst_collect_pads_set_function (adder->collect,
893       GST_DEBUG_FUNCPTR (gst_adder_collected), adder);
894   gst_collect_pads_set_clip_function (adder->collect,
895       GST_DEBUG_FUNCPTR (gst_adder_do_clip), adder);
896 }
897
898 static void
899 gst_adder_dispose (GObject * object)
900 {
901   GstAdder *adder = GST_ADDER (object);
902
903   if (adder->collect) {
904     gst_object_unref (adder->collect);
905     adder->collect = NULL;
906   }
907   gst_caps_replace (&adder->filter_caps, NULL);
908   if (adder->pending_events) {
909     g_list_foreach (adder->pending_events, (GFunc) gst_event_unref, NULL);
910     g_list_free (adder->pending_events);
911     adder->pending_events = NULL;
912   }
913
914   G_OBJECT_CLASS (parent_class)->dispose (object);
915 }
916
917 static void
918 gst_adder_set_property (GObject * object, guint prop_id,
919     const GValue * value, GParamSpec * pspec)
920 {
921   GstAdder *adder = GST_ADDER (object);
922
923   switch (prop_id) {
924     case PROP_FILTER_CAPS:{
925       GstCaps *new_caps = NULL;
926       GstCaps *old_caps;
927       const GstCaps *new_caps_val = gst_value_get_caps (value);
928
929       if (new_caps_val != NULL) {
930         new_caps = (GstCaps *) new_caps_val;
931         gst_caps_ref (new_caps);
932       }
933
934       GST_OBJECT_LOCK (adder);
935       old_caps = adder->filter_caps;
936       adder->filter_caps = new_caps;
937       GST_OBJECT_UNLOCK (adder);
938
939       if (old_caps)
940         gst_caps_unref (old_caps);
941
942       GST_DEBUG_OBJECT (adder, "set new caps %" GST_PTR_FORMAT, new_caps);
943       break;
944     }
945     default:
946       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
947       break;
948   }
949 }
950
951 static void
952 gst_adder_get_property (GObject * object, guint prop_id, GValue * value,
953     GParamSpec * pspec)
954 {
955   GstAdder *adder = GST_ADDER (object);
956
957   switch (prop_id) {
958     case PROP_FILTER_CAPS:
959       GST_OBJECT_LOCK (adder);
960       gst_value_set_caps (value, adder->filter_caps);
961       GST_OBJECT_UNLOCK (adder);
962       break;
963     default:
964       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
965       break;
966   }
967 }
968
969
970 static GstPad *
971 gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ,
972     const gchar * unused, const GstCaps * caps)
973 {
974   gchar *name;
975   GstAdder *adder;
976   GstPad *newpad;
977   gint padcount;
978
979   if (templ->direction != GST_PAD_SINK)
980     goto not_sink;
981
982   adder = GST_ADDER (element);
983
984   /* increment pad counter */
985   padcount = g_atomic_int_exchange_and_add (&adder->padcount, 1);
986
987   name = g_strdup_printf ("sink%d", padcount);
988   newpad = gst_pad_new_from_template (templ, name);
989   GST_DEBUG_OBJECT (adder, "request new pad %s", name);
990   g_free (name);
991
992   gst_pad_set_getcaps_function (newpad,
993       GST_DEBUG_FUNCPTR (gst_adder_sink_getcaps));
994   gst_pad_set_setcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_setcaps));
995   gst_collect_pads_add_pad (adder->collect, newpad, sizeof (GstCollectData));
996
997   /* FIXME: hacked way to override/extend the event function of
998    * GstCollectPads; because it sets its own event function giving the
999    * element no access to events */
1000   adder->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (newpad);
1001   gst_pad_set_event_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_sink_event));
1002
1003   /* takes ownership of the pad */
1004   if (!gst_element_add_pad (GST_ELEMENT (adder), newpad))
1005     goto could_not_add;
1006
1007   return newpad;
1008
1009   /* errors */
1010 not_sink:
1011   {
1012     g_warning ("gstadder: request new pad that is not a SINK pad\n");
1013     return NULL;
1014   }
1015 could_not_add:
1016   {
1017     GST_DEBUG_OBJECT (adder, "could not add pad");
1018     gst_collect_pads_remove_pad (adder->collect, newpad);
1019     gst_object_unref (newpad);
1020     return NULL;
1021   }
1022 }
1023
1024 static void
1025 gst_adder_release_pad (GstElement * element, GstPad * pad)
1026 {
1027   GstAdder *adder;
1028
1029   adder = GST_ADDER (element);
1030
1031   GST_DEBUG_OBJECT (adder, "release pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1032
1033   gst_collect_pads_remove_pad (adder->collect, pad);
1034   gst_element_remove_pad (element, pad);
1035 }
1036
1037 static GstBuffer *
1038 gst_adder_do_clip (GstCollectPads * pads, GstCollectData * data,
1039     GstBuffer * buffer, gpointer user_data)
1040 {
1041   GstAdder *adder = GST_ADDER (user_data);
1042
1043   buffer = gst_audio_buffer_clip (buffer, &data->segment, adder->rate,
1044       adder->bps);
1045
1046   return buffer;
1047 }
1048
1049 static GstFlowReturn
1050 gst_adder_collected (GstCollectPads * pads, gpointer user_data)
1051 {
1052   /*
1053    * combine streams by adding data values
1054    * basic algorithm :
1055    * - this function is called when all pads have a buffer
1056    * - get available bytes on all pads.
1057    * - repeat for each input pad :
1058    *   - read available bytes, copy or add to target buffer
1059    *   - if there's an EOS event, remove the input channel
1060    * - push out the output buffer
1061    *
1062    * todo:
1063    * - would be nice to have a mixing mode, where instead of adding we mix
1064    *   - for float we could downscale after collect loop
1065    *   - for int we need to downscale each input to avoid clipping or
1066    *     mix into a temp (float) buffer and scale afterwards as well
1067    */
1068   GstAdder *adder;
1069   GSList *collected, *next = NULL;
1070   GstFlowReturn ret;
1071   GstBuffer *outbuf = NULL, *gapbuf = NULL;
1072   gpointer outdata = NULL;
1073   guint outsize;
1074   gint64 next_offset;
1075   gint64 next_timestamp;
1076
1077   adder = GST_ADDER (user_data);
1078
1079   /* this is fatal */
1080   if (G_UNLIKELY (adder->func == NULL))
1081     goto not_negotiated;
1082
1083   if (g_atomic_int_compare_and_exchange (&adder->flush_stop_pending,
1084           TRUE, FALSE)) {
1085     GST_DEBUG_OBJECT (adder, "pending flush stop");
1086     gst_pad_push_event (adder->srcpad, gst_event_new_flush_stop ());
1087   }
1088
1089   /* get available bytes for reading, this can be 0 which could mean empty
1090    * buffers or EOS, which we will catch when we loop over the pads. */
1091   outsize = gst_collect_pads_available (pads);
1092   /* can only happen when no pads to collect or all EOS */
1093   if (outsize == 0)
1094     goto eos;
1095
1096   GST_LOG_OBJECT (adder,
1097       "starting to cycle through channels, %d bytes available (bps = %d)",
1098       outsize, adder->bps);
1099
1100   for (collected = pads->data; collected; collected = next) {
1101     GstCollectData *collect_data;
1102     GstBuffer *inbuf;
1103     gboolean is_gap;
1104
1105     /* take next to see if this is the last collectdata */
1106     next = g_slist_next (collected);
1107
1108     collect_data = (GstCollectData *) collected->data;
1109
1110     /* get a buffer of size bytes, if we get a buffer, it is at least outsize
1111      * bytes big. */
1112     inbuf = gst_collect_pads_take_buffer (pads, collect_data, outsize);
1113     /* NULL means EOS or an empty buffer so we still need to flush in
1114      * case of an empty buffer. */
1115     if (inbuf == NULL) {
1116       GST_LOG_OBJECT (adder, "channel %p: no bytes available", collect_data);
1117       continue;
1118     }
1119
1120     is_gap = GST_BUFFER_FLAG_IS_SET (inbuf, GST_BUFFER_FLAG_GAP);
1121
1122     /* Try to make an output buffer */
1123     if (outbuf == NULL) {
1124       /* if this is a gap buffer but we have some more pads to check, skip it.
1125        * If we are at the last buffer, take it, regardless if it is a GAP
1126        * buffer or not. */
1127       if (is_gap && next) {
1128         GST_DEBUG_OBJECT (adder, "skipping, non-last GAP buffer");
1129         /* we keep the GAP buffer, if we don't have anymore buffers (all pads
1130          * EOS, we can use this one as the output buffer. */
1131         if (gapbuf == NULL)
1132           gapbuf = inbuf;
1133         else
1134           gst_buffer_unref (inbuf);
1135         continue;
1136       }
1137
1138       GST_LOG_OBJECT (adder, "channel %p: preparing output buffer of %d bytes",
1139           collect_data, outsize);
1140
1141       outdata = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE);
1142     } else {
1143       if (!is_gap) {
1144         /* we had a previous output buffer, mix this non-GAP buffer */
1145         guint8 *indata;
1146         gsize insize;
1147
1148         indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
1149
1150         /* all buffers should have outsize, there are no short buffers because we
1151          * asked for the max size above */
1152         g_assert (insize == outsize);
1153
1154         GST_LOG_OBJECT (adder, "channel %p: mixing %d bytes from data %p",
1155             collect_data, insize, indata);
1156
1157         /* further buffers, need to add them */
1158         adder->func ((gpointer) outdata, (gpointer) indata,
1159             insize / adder->sample_size);
1160         gst_buffer_unmap (inbuf, indata, insize);
1161       } else {
1162         /* skip gap buffer */
1163         GST_LOG_OBJECT (adder, "channel %p: skipping GAP buffer", collect_data);
1164       }
1165       gst_buffer_unref (inbuf);
1166     }
1167   }
1168   if (outbuf)
1169     gst_buffer_unmap (outbuf, outdata, outsize);
1170
1171   if (outbuf == NULL) {
1172     /* no output buffer, reuse one of the GAP buffers then if we have one */
1173     if (gapbuf) {
1174       GST_LOG_OBJECT (adder, "reusing GAP buffer %p", gapbuf);
1175       outbuf = gapbuf;
1176     } else
1177       /* assume EOS otherwise, this should not happen, really */
1178       goto eos;
1179   } else if (gapbuf)
1180     /* we had an output buffer, unref the gapbuffer we kept */
1181     gst_buffer_unref (gapbuf);
1182
1183   if (adder->segment_pending) {
1184     GstEvent *event;
1185
1186     /* FIXME, use rate/applied_rate as set on all sinkpads.
1187      * - currently we just set rate as received from last seek-event
1188      *
1189      * When seeking we set the start and stop positions as given in the seek
1190      * event. We also adjust offset & timestamp acordingly.
1191      * This basically ignores all newsegments sent by upstream.
1192      */
1193     event = gst_event_new_segment (&adder->segment);
1194
1195     if (adder->segment.rate > 0.0) {
1196       adder->segment.position = adder->segment.start;
1197     } else {
1198       adder->segment.position = adder->segment.stop;
1199     }
1200     adder->offset = gst_util_uint64_scale (adder->segment.position,
1201         adder->rate, GST_SECOND);
1202     GST_INFO_OBJECT (adder, "seg_start %" G_GUINT64_FORMAT ", seg_end %"
1203         G_GUINT64_FORMAT, adder->segment.start, adder->segment.stop);
1204     GST_INFO_OBJECT (adder, "timestamp %" G_GINT64_FORMAT ",new offset %"
1205         G_GINT64_FORMAT, adder->segment.position, adder->offset);
1206
1207     if (event) {
1208       if (!gst_pad_push_event (adder->srcpad, event)) {
1209         GST_WARNING_OBJECT (adder->srcpad, "Sending event  %p (%s) failed.",
1210             event, GST_EVENT_TYPE_NAME (event));
1211       }
1212       adder->segment_pending = FALSE;
1213     } else {
1214       GST_WARNING_OBJECT (adder->srcpad, "Creating new segment event for "
1215           "start:%" G_GINT64_FORMAT "  end:%" G_GINT64_FORMAT " failed",
1216           adder->segment.start, adder->segment.stop);
1217     }
1218   }
1219
1220   if (G_UNLIKELY (adder->pending_events)) {
1221     GList *tmp = adder->pending_events;
1222
1223     while (tmp) {
1224       GstEvent *ev = (GstEvent *) tmp->data;
1225
1226       gst_pad_push_event (adder->srcpad, ev);
1227       tmp = g_list_next (tmp);
1228     }
1229     g_list_free (adder->pending_events);
1230     adder->pending_events = NULL;
1231   }
1232
1233   /* for the next timestamp, use the sample counter, which will
1234    * never accumulate rounding errors */
1235   if (adder->segment.rate > 0.0) {
1236     next_offset = adder->offset + outsize / adder->bps;
1237   } else {
1238     next_offset = adder->offset - outsize / adder->bps;
1239   }
1240   next_timestamp = gst_util_uint64_scale (next_offset, GST_SECOND, adder->rate);
1241
1242
1243   /* set timestamps on the output buffer */
1244   if (adder->segment.rate > 0.0) {
1245     GST_BUFFER_TIMESTAMP (outbuf) = adder->segment.position;
1246     GST_BUFFER_OFFSET (outbuf) = adder->offset;
1247     GST_BUFFER_OFFSET_END (outbuf) = next_offset;
1248     GST_BUFFER_DURATION (outbuf) = next_timestamp - adder->segment.position;
1249   } else {
1250     GST_BUFFER_TIMESTAMP (outbuf) = next_timestamp;
1251     GST_BUFFER_OFFSET (outbuf) = next_offset;
1252     GST_BUFFER_OFFSET_END (outbuf) = adder->offset;
1253     GST_BUFFER_DURATION (outbuf) = adder->segment.position - next_timestamp;
1254   }
1255
1256   adder->offset = next_offset;
1257   adder->segment.position = next_timestamp;
1258
1259   /* send it out */
1260   GST_LOG_OBJECT (adder, "pushing outbuf %p, timestamp %" GST_TIME_FORMAT
1261       " offset %" G_GINT64_FORMAT, outbuf,
1262       GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1263       GST_BUFFER_OFFSET (outbuf));
1264   ret = gst_pad_push (adder->srcpad, outbuf);
1265
1266   GST_LOG_OBJECT (adder, "pushed outbuf, result = %s", gst_flow_get_name (ret));
1267
1268   return ret;
1269
1270   /* ERRORS */
1271 not_negotiated:
1272   {
1273     GST_ELEMENT_ERROR (adder, STREAM, FORMAT, (NULL),
1274         ("Unknown data received, not negotiated"));
1275     return GST_FLOW_NOT_NEGOTIATED;
1276   }
1277 eos:
1278   {
1279     GST_DEBUG_OBJECT (adder, "no data available, must be EOS");
1280     gst_pad_push_event (adder->srcpad, gst_event_new_eos ());
1281     return GST_FLOW_UNEXPECTED;
1282   }
1283 }
1284
1285 static GstStateChangeReturn
1286 gst_adder_change_state (GstElement * element, GstStateChange transition)
1287 {
1288   GstAdder *adder;
1289   GstStateChangeReturn ret;
1290
1291   adder = GST_ADDER (element);
1292
1293   switch (transition) {
1294     case GST_STATE_CHANGE_NULL_TO_READY:
1295       break;
1296     case GST_STATE_CHANGE_READY_TO_PAUSED:
1297       adder->segment.position = 0;
1298       adder->offset = 0;
1299       adder->flush_stop_pending = FALSE;
1300       adder->segment_pending = TRUE;
1301       gst_segment_init (&adder->segment, GST_FORMAT_TIME);
1302       gst_collect_pads_start (adder->collect);
1303       break;
1304     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1305       break;
1306     case GST_STATE_CHANGE_PAUSED_TO_READY:
1307       /* need to unblock the collectpads before calling the
1308        * parent change_state so that streaming can finish */
1309       gst_collect_pads_stop (adder->collect);
1310       break;
1311     default:
1312       break;
1313   }
1314
1315   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1316
1317   switch (transition) {
1318     default:
1319       break;
1320   }
1321
1322   return ret;
1323 }
1324
1325
1326 static gboolean
1327 plugin_init (GstPlugin * plugin)
1328 {
1329   GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "adder", 0,
1330       "audio channel mixing element");
1331
1332   gst_adder_orc_init ();
1333
1334   if (!gst_element_register (plugin, "adder", GST_RANK_NONE, GST_TYPE_ADDER)) {
1335     return FALSE;
1336   }
1337
1338   return TRUE;
1339 }
1340
1341 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1342     GST_VERSION_MINOR,
1343     "adder",
1344     "Adds multiple streams",
1345     plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)