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