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