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