Do not use short_description in section docs for elements. We extract them from eleme...
[platform/upstream/gstreamer.git] / plugins / elements / gstinputselector.c
1 /* GStreamer
2  * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
3  * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
4  * Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com>
5  * Copyright (C) 2007 Wim Taymans <wim.taymans@gmail.com>
6  * Copyright (C) 2007 Andy Wingo <wingo@pobox.com>
7  * Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>)
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 /**
26  * SECTION:element-input-selector
27  * @see_also: #GstOutputSelector
28  *
29  * Direct one out of N input streams to the output pad.
30  */
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <string.h>
37
38 #include "gstinputselector.h"
39 #include "gstselector-marshal.h"
40
41 GST_DEBUG_CATEGORY_STATIC (input_selector_debug);
42 #define GST_CAT_DEFAULT input_selector_debug
43
44 static const GstElementDetails gst_input_selector_details =
45 GST_ELEMENT_DETAILS ("Input selector",
46     "Generic",
47     "N-to-1 input stream selectoring",
48     "Julien Moutte <julien@moutte.net>\n"
49     "Ronald S. Bultje <rbultje@ronald.bitfreak.net>\n"
50     "Jan Schmidt <thaytan@mad.scientist.com>\n"
51     "Wim Taymans <wim.taymans@gmail.com>");
52
53 static GstStaticPadTemplate gst_input_selector_sink_factory =
54 GST_STATIC_PAD_TEMPLATE ("sink%d",
55     GST_PAD_SINK,
56     GST_PAD_REQUEST,
57     GST_STATIC_CAPS_ANY);
58
59 static GstStaticPadTemplate gst_input_selector_src_factory =
60 GST_STATIC_PAD_TEMPLATE ("src",
61     GST_PAD_SRC,
62     GST_PAD_ALWAYS,
63     GST_STATIC_CAPS_ANY);
64
65 enum
66 {
67   PROP_0,
68   PROP_N_PADS,
69   PROP_ACTIVE_PAD,
70   PROP_SELECT_ALL,
71   PROP_LAST
72 };
73
74 #define DEFAULT_PAD_ALWAYS_OK   TRUE
75
76 enum
77 {
78   PROP_PAD_0,
79   PROP_PAD_RUNNING_TIME,
80   PROP_PAD_TAGS,
81   PROP_PAD_ACTIVE,
82   PROP_PAD_ALWAYS_OK,
83   PROP_PAD_LAST
84 };
85
86 enum
87 {
88   /* methods */
89   SIGNAL_BLOCK,
90   SIGNAL_SWITCH,
91   LAST_SIGNAL
92 };
93 static guint gst_input_selector_signals[LAST_SIGNAL] = { 0 };
94
95 static gboolean gst_input_selector_is_active_sinkpad (GstInputSelector * sel,
96     GstPad * pad);
97 static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel,
98     GstPad * pad);
99 static GstPad *gst_input_selector_get_linked_pad (GstPad * pad,
100     gboolean strict);
101 static gboolean gst_input_selector_check_eos (GstElement * selector);
102
103 #define GST_TYPE_SELECTOR_PAD \
104   (gst_selector_pad_get_type())
105 #define GST_SELECTOR_PAD(obj) \
106   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SELECTOR_PAD, GstSelectorPad))
107 #define GST_SELECTOR_PAD_CLASS(klass) \
108   (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_SELECTOR_PAD, GstSelectorPadClass))
109 #define GST_IS_SELECTOR_PAD(obj) \
110   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SELECTOR_PAD))
111 #define GST_IS_SELECTOR_PAD_CLASS(klass) \
112   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_SELECTOR_PAD))
113 #define GST_SELECTOR_PAD_CAST(obj) \
114   ((GstSelectorPad *)(obj))
115
116 typedef struct _GstSelectorPad GstSelectorPad;
117 typedef struct _GstSelectorPadClass GstSelectorPadClass;
118
119 struct _GstSelectorPad
120 {
121   GstPad parent;
122
123   gboolean active;              /* when buffer have passed the pad */
124   gboolean eos;                 /* when EOS has been received */
125   gboolean discont;             /* after switching we create a discont */
126   gboolean always_ok;
127   GstSegment segment;           /* the current segment on the pad */
128   GstTagList *tags;             /* last tags received on the pad */
129
130   gboolean segment_pending;
131 };
132
133 struct _GstSelectorPadClass
134 {
135   GstPadClass parent;
136 };
137
138 static void gst_selector_pad_class_init (GstSelectorPadClass * klass);
139 static void gst_selector_pad_init (GstSelectorPad * pad);
140 static void gst_selector_pad_finalize (GObject * object);
141 static void gst_selector_pad_get_property (GObject * object,
142     guint prop_id, GValue * value, GParamSpec * pspec);
143 static void gst_selector_pad_set_property (GObject * object,
144     guint prop_id, const GValue * value, GParamSpec * pspec);
145
146 static GstPadClass *selector_pad_parent_class = NULL;
147
148 static gint64 gst_selector_pad_get_running_time (GstSelectorPad * pad);
149 static void gst_selector_pad_reset (GstSelectorPad * pad);
150 static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
151 static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
152 static GList *gst_selector_pad_get_linked_pads (GstPad * pad);
153 static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf);
154 static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad,
155     guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
156
157 static GType
158 gst_selector_pad_get_type (void)
159 {
160   static GType selector_pad_type = 0;
161
162   if (!selector_pad_type) {
163     static const GTypeInfo selector_pad_info = {
164       sizeof (GstSelectorPadClass),
165       NULL,
166       NULL,
167       (GClassInitFunc) gst_selector_pad_class_init,
168       NULL,
169       NULL,
170       sizeof (GstSelectorPad),
171       0,
172       (GInstanceInitFunc) gst_selector_pad_init,
173     };
174
175     selector_pad_type =
176         g_type_register_static (GST_TYPE_PAD, "GstSelectorPad",
177         &selector_pad_info, 0);
178   }
179   return selector_pad_type;
180 }
181
182 static void
183 gst_selector_pad_class_init (GstSelectorPadClass * klass)
184 {
185   GObjectClass *gobject_class;
186
187   gobject_class = (GObjectClass *) klass;
188
189   selector_pad_parent_class = g_type_class_peek_parent (klass);
190
191   gobject_class->finalize = gst_selector_pad_finalize;
192
193   gobject_class->get_property =
194       GST_DEBUG_FUNCPTR (gst_selector_pad_get_property);
195   gobject_class->set_property =
196       GST_DEBUG_FUNCPTR (gst_selector_pad_set_property);
197
198   g_object_class_install_property (gobject_class, PROP_PAD_RUNNING_TIME,
199       g_param_spec_int64 ("running-time", "Running time",
200           "Running time of stream on pad", 0, G_MAXINT64, 0, G_PARAM_READABLE));
201   g_object_class_install_property (gobject_class, PROP_PAD_TAGS,
202       g_param_spec_boxed ("tags", "Tags",
203           "The currently active tags on the pad", GST_TYPE_TAG_LIST,
204           G_PARAM_READABLE));
205   g_object_class_install_property (gobject_class, PROP_PAD_ACTIVE,
206       g_param_spec_boolean ("active", "Active",
207           "If the pad is currently active", FALSE, G_PARAM_READABLE));
208   g_object_class_install_property (gobject_class, PROP_PAD_ALWAYS_OK,
209       g_param_spec_boolean ("always-ok", "Always OK",
210           "Make an inactive pad return OK instead of NOT_LINKED",
211           DEFAULT_PAD_ALWAYS_OK, G_PARAM_READWRITE));
212 }
213
214 static void
215 gst_selector_pad_init (GstSelectorPad * pad)
216 {
217   pad->always_ok = DEFAULT_PAD_ALWAYS_OK;
218   gst_selector_pad_reset (pad);
219 }
220
221 static void
222 gst_selector_pad_finalize (GObject * object)
223 {
224   GstSelectorPad *pad;
225
226   pad = GST_SELECTOR_PAD_CAST (object);
227
228   if (pad->tags)
229     gst_tag_list_free (pad->tags);
230
231   G_OBJECT_CLASS (selector_pad_parent_class)->finalize (object);
232 }
233
234 static void
235 gst_selector_pad_set_property (GObject * object, guint prop_id,
236     const GValue * value, GParamSpec * pspec)
237 {
238   GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
239
240   switch (prop_id) {
241     case PROP_PAD_ALWAYS_OK:
242       GST_OBJECT_LOCK (object);
243       spad->always_ok = g_value_get_boolean (value);
244       GST_OBJECT_UNLOCK (object);
245       break;
246     default:
247       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
248       break;
249   }
250 }
251
252 static void
253 gst_selector_pad_get_property (GObject * object, guint prop_id,
254     GValue * value, GParamSpec * pspec)
255 {
256   GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
257
258   switch (prop_id) {
259     case PROP_PAD_RUNNING_TIME:
260       g_value_set_int64 (value, gst_selector_pad_get_running_time (spad));
261       break;
262     case PROP_PAD_TAGS:
263       GST_OBJECT_LOCK (object);
264       g_value_set_boxed (value, spad->tags);
265       GST_OBJECT_UNLOCK (object);
266       break;
267     case PROP_PAD_ACTIVE:
268     {
269       GstInputSelector *sel;
270
271       sel = GST_INPUT_SELECTOR (gst_pad_get_parent (spad));
272       g_value_set_boolean (value, gst_input_selector_is_active_sinkpad (sel,
273               GST_PAD_CAST (spad)));
274       gst_object_unref (sel);
275       break;
276     }
277     case PROP_PAD_ALWAYS_OK:
278       GST_OBJECT_LOCK (object);
279       g_value_set_boolean (value, spad->always_ok);
280       GST_OBJECT_UNLOCK (object);
281       break;
282     default:
283       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
284       break;
285   }
286 }
287
288 static gint64
289 gst_selector_pad_get_running_time (GstSelectorPad * pad)
290 {
291   gint64 ret = 0;
292
293   GST_OBJECT_LOCK (pad);
294   if (pad->active) {
295     gint64 last_stop = pad->segment.last_stop;
296
297     if (last_stop >= 0)
298       ret = gst_segment_to_running_time (&pad->segment, GST_FORMAT_TIME,
299           last_stop);
300   }
301   GST_OBJECT_UNLOCK (pad);
302
303   GST_DEBUG_OBJECT (pad, "running time: %" GST_TIME_FORMAT,
304       GST_TIME_ARGS (ret));
305
306   return ret;
307 }
308
309 static void
310 gst_selector_pad_reset (GstSelectorPad * pad)
311 {
312   GST_OBJECT_LOCK (pad);
313   pad->active = FALSE;
314   pad->eos = FALSE;
315   pad->segment_pending = FALSE;
316   gst_segment_init (&pad->segment, GST_FORMAT_UNDEFINED);
317   GST_OBJECT_UNLOCK (pad);
318 }
319
320 /* strictly get the linked pad from the sinkpad. If the pad is active we return
321  * the srcpad else we return NULL */
322 static GList *
323 gst_selector_pad_get_linked_pads (GstPad * pad)
324 {
325   GstPad *otherpad;
326
327   otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
328   if (!otherpad)
329     return NULL;
330
331   /* need to drop the ref, internal linked pads is not MT safe */
332   gst_object_unref (otherpad);
333
334   return g_list_append (NULL, otherpad);
335 }
336
337 static gboolean
338 gst_selector_pad_event (GstPad * pad, GstEvent * event)
339 {
340   gboolean res = TRUE;
341   gboolean forward = TRUE;
342   GstInputSelector *sel;
343   GstSelectorPad *selpad;
344
345   sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
346   selpad = GST_SELECTOR_PAD_CAST (pad);
347
348   /* only forward if we are dealing with the active sinkpad */
349   forward = gst_input_selector_is_active_sinkpad (sel, pad);
350
351   /* forward all events in select_all mode by default */
352   if (sel->select_all) {
353     forward = TRUE;
354   }
355
356   switch (GST_EVENT_TYPE (event)) {
357     case GST_EVENT_FLUSH_START:
358       /* FIXME, flush out the waiter */
359       break;
360     case GST_EVENT_FLUSH_STOP:
361       GST_INPUT_SELECTOR_LOCK (sel);
362       gst_selector_pad_reset (selpad);
363       sel->pending_close = FALSE;
364       GST_INPUT_SELECTOR_UNLOCK (sel);
365       break;
366     case GST_EVENT_NEWSEGMENT:
367     {
368       gboolean update;
369       GstFormat format;
370       gdouble rate, arate;
371       gint64 start, stop, time;
372
373       gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
374           &start, &stop, &time);
375
376       GST_DEBUG_OBJECT (pad,
377           "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
378           "format %d, "
379           "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
380           G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
381
382       GST_INPUT_SELECTOR_LOCK (sel);
383       GST_OBJECT_LOCK (selpad);
384       gst_segment_set_newsegment_full (&selpad->segment, update,
385           rate, arate, format, start, stop, time);
386       GST_OBJECT_UNLOCK (selpad);
387       /* we are not going to forward the segment, mark the segment as
388        * pending */
389       forward = FALSE;
390       selpad->segment_pending = TRUE;
391       GST_INPUT_SELECTOR_UNLOCK (sel);
392
393       break;
394     }
395     case GST_EVENT_TAG:
396     {
397       GstTagList *tags;
398
399       GST_OBJECT_LOCK (selpad);
400       if (selpad->tags)
401         gst_tag_list_free (selpad->tags);
402       gst_event_parse_tag (event, &tags);
403       if (tags)
404         tags = gst_tag_list_copy (tags);
405       selpad->tags = tags;
406       GST_DEBUG_OBJECT (pad, "received tags %" GST_PTR_FORMAT, selpad->tags);
407       GST_OBJECT_UNLOCK (selpad);
408       break;
409     }
410     case GST_EVENT_EOS:
411       selpad->eos = TRUE;
412       GST_DEBUG_OBJECT (pad, "received EOS");
413       /* don't forward eos in select_all mode until all sink pads have eos */
414       if (sel->select_all && !gst_input_selector_check_eos (GST_ELEMENT (sel))) {
415         forward = FALSE;
416       }
417       break;
418     default:
419       break;
420   }
421   if (forward) {
422     GST_DEBUG_OBJECT (pad, "forwarding event");
423     res = gst_pad_push_event (sel->srcpad, event);
424   } else
425     gst_event_unref (event);
426
427   gst_object_unref (sel);
428
429   return res;
430 }
431
432 static GstCaps *
433 gst_selector_pad_getcaps (GstPad * pad)
434 {
435   GstInputSelector *sel;
436   GstCaps *caps;
437
438   sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
439
440   GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer");
441   caps = gst_pad_peer_get_caps (sel->srcpad);
442   if (caps == NULL)
443     caps = gst_caps_new_any ();
444
445   gst_object_unref (sel);
446
447   return caps;
448 }
449
450 static GstFlowReturn
451 gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset,
452     guint size, GstCaps * caps, GstBuffer ** buf)
453 {
454   GstInputSelector *sel;
455   GstFlowReturn result;
456   GstPad *active_sinkpad;
457   GstSelectorPad *selpad;
458
459   sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
460   selpad = GST_SELECTOR_PAD_CAST (pad);
461
462   GST_DEBUG_OBJECT (pad, "received alloc");
463
464   GST_INPUT_SELECTOR_LOCK (sel);
465   active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
466
467   if (pad != active_sinkpad && !sel->select_all)
468     goto not_active;
469
470   GST_INPUT_SELECTOR_UNLOCK (sel);
471
472   result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf);
473
474 done:
475   gst_object_unref (sel);
476
477   return result;
478
479   /* ERRORS */
480 not_active:
481   {
482     GST_INPUT_SELECTOR_UNLOCK (sel);
483
484     /* unselected pad, perform fallback alloc or return unlinked when
485      * asked */
486     GST_OBJECT_LOCK (selpad);
487     if (selpad->always_ok) {
488       GST_DEBUG_OBJECT (pad, "Not selected, performing fallback allocation");
489       *buf = NULL;
490       result = GST_FLOW_OK;
491     } else {
492       GST_DEBUG_OBJECT (pad, "Not selected, return NOT_LINKED");
493       result = GST_FLOW_NOT_LINKED;
494     }
495     GST_OBJECT_UNLOCK (selpad);
496
497     goto done;
498   }
499 }
500
501 /* must be called with the SELECTOR_LOCK, will block while the pad is blocked 
502  * or return TRUE when flushing */
503 static gboolean
504 gst_input_selector_wait (GstInputSelector * self, GstPad * pad)
505 {
506   while (self->blocked && !self->flushing) {
507     /* we can be unlocked here when we are shutting down (flushing) or when we
508      * get unblocked */
509     GST_INPUT_SELECTOR_WAIT (self);
510   }
511   return self->flushing;
512 }
513
514 static GstFlowReturn
515 gst_selector_pad_chain (GstPad * pad, GstBuffer * buf)
516 {
517   GstInputSelector *sel;
518   GstFlowReturn res;
519   GstPad *active_sinkpad;
520   GstSelectorPad *selpad;
521   GstClockTime end_time, duration;
522   GstSegment *seg;
523   GstEvent *close_event = NULL, *start_event = NULL;
524
525   sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
526   selpad = GST_SELECTOR_PAD_CAST (pad);
527   seg = &selpad->segment;
528
529   GST_INPUT_SELECTOR_LOCK (sel);
530   /* wait or check for flushing */
531   if (gst_input_selector_wait (sel, pad))
532     goto flushing;
533
534   GST_DEBUG_OBJECT (pad, "getting active pad");
535
536   active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
537
538   /* update the segment on the srcpad */
539   end_time = GST_BUFFER_TIMESTAMP (buf);
540   if (GST_CLOCK_TIME_IS_VALID (end_time)) {
541     duration = GST_BUFFER_DURATION (buf);
542     if (GST_CLOCK_TIME_IS_VALID (duration))
543       end_time += duration;
544     GST_DEBUG_OBJECT (pad, "received end time %" GST_TIME_FORMAT,
545         GST_TIME_ARGS (end_time));
546
547     GST_OBJECT_LOCK (pad);
548     gst_segment_set_last_stop (seg, seg->format, end_time);
549     GST_OBJECT_UNLOCK (pad);
550   }
551
552   /* Ignore buffers from pads except the selected one */
553   if (pad != active_sinkpad && !sel->select_all)
554     goto ignore;
555
556   if (G_UNLIKELY (sel->pending_close)) {
557     GstSegment *cseg = &sel->segment;
558
559     GST_DEBUG_OBJECT (sel,
560         "pushing NEWSEGMENT update %d, rate %lf, applied rate %lf, "
561         "format %d, "
562         "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
563         G_GINT64_FORMAT, TRUE, cseg->rate, cseg->applied_rate, cseg->format,
564         cseg->start, cseg->stop, cseg->time);
565
566     /* create update segment */
567     close_event = gst_event_new_new_segment_full (TRUE, cseg->rate,
568         cseg->applied_rate, cseg->format, cseg->start, cseg->stop, cseg->time);
569
570     sel->pending_close = FALSE;
571   }
572   /* if we have a pending segment, push it out now */
573   if (G_UNLIKELY (selpad->segment_pending)) {
574     GST_DEBUG_OBJECT (pad,
575         "pushing NEWSEGMENT update %d, rate %lf, applied rate %lf, "
576         "format %d, "
577         "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
578         G_GINT64_FORMAT, FALSE, seg->rate, seg->applied_rate, seg->format,
579         seg->start, seg->stop, seg->time);
580
581     start_event = gst_event_new_new_segment_full (FALSE, seg->rate,
582         seg->applied_rate, seg->format, seg->start, seg->stop, seg->time);
583
584     selpad->segment_pending = FALSE;
585   }
586   GST_INPUT_SELECTOR_UNLOCK (sel);
587
588   if (close_event)
589     gst_pad_push_event (sel->srcpad, close_event);
590
591   if (start_event)
592     gst_pad_push_event (sel->srcpad, start_event);
593
594   if (selpad->discont) {
595     buf = gst_buffer_make_metadata_writable (buf);
596
597     GST_DEBUG_OBJECT (pad, "Marking discont buffer %p", buf);
598     GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
599     selpad->discont = FALSE;
600   }
601
602   /* forward */
603   GST_DEBUG_OBJECT (pad, "Forwarding buffer %p from pad %s:%s", buf,
604       GST_DEBUG_PAD_NAME (pad));
605
606   res = gst_pad_push (sel->srcpad, buf);
607
608 done:
609   gst_object_unref (sel);
610   return res;
611
612   /* dropped buffers */
613 ignore:
614   {
615     GST_DEBUG_OBJECT (pad, "Pad not active, discard buffer %p", buf);
616     /* when we drop a buffer, we're creating a discont on this pad */
617     selpad->discont = TRUE;
618     GST_INPUT_SELECTOR_UNLOCK (sel);
619     gst_buffer_unref (buf);
620
621     /* figure out what to return upstream */
622     GST_OBJECT_LOCK (selpad);
623     if (selpad->always_ok)
624       res = GST_FLOW_OK;
625     else
626       res = GST_FLOW_NOT_LINKED;
627     GST_OBJECT_UNLOCK (selpad);
628
629     goto done;
630   }
631 flushing:
632   {
633     GST_DEBUG_OBJECT (pad, "We are flushing, discard buffer %p", buf);
634     GST_INPUT_SELECTOR_UNLOCK (sel);
635     gst_buffer_unref (buf);
636     res = GST_FLOW_WRONG_STATE;
637     goto done;
638   }
639 }
640
641 static void gst_input_selector_init (GstInputSelector * sel);
642 static void gst_input_selector_base_init (GstInputSelectorClass * klass);
643 static void gst_input_selector_class_init (GstInputSelectorClass * klass);
644
645 static void gst_input_selector_dispose (GObject * object);
646
647 static void gst_input_selector_set_property (GObject * object,
648     guint prop_id, const GValue * value, GParamSpec * pspec);
649 static void gst_input_selector_get_property (GObject * object,
650     guint prop_id, GValue * value, GParamSpec * pspec);
651
652 static GstPad *gst_input_selector_request_new_pad (GstElement * element,
653     GstPadTemplate * templ, const gchar * unused);
654 static void gst_input_selector_release_pad (GstElement * element, GstPad * pad);
655
656 static GstStateChangeReturn gst_input_selector_change_state (GstElement *
657     element, GstStateChange transition);
658
659 static GList *gst_input_selector_get_linked_pads (GstPad * pad);
660 static GstCaps *gst_input_selector_getcaps (GstPad * pad);
661 static gint64 gst_input_selector_block (GstInputSelector * self);
662 static void gst_input_selector_switch (GstInputSelector * self,
663     GstPad * pad, gint64 stop_time, gint64 start_time);
664
665 static GstElementClass *parent_class = NULL;
666
667 GType
668 gst_input_selector_get_type (void)
669 {
670   static GType input_selector_type = 0;
671
672   if (!input_selector_type) {
673     static const GTypeInfo input_selector_info = {
674       sizeof (GstInputSelectorClass),
675       (GBaseInitFunc) gst_input_selector_base_init,
676       NULL,
677       (GClassInitFunc) gst_input_selector_class_init,
678       NULL,
679       NULL,
680       sizeof (GstInputSelector),
681       0,
682       (GInstanceInitFunc) gst_input_selector_init,
683     };
684     input_selector_type =
685         g_type_register_static (GST_TYPE_ELEMENT,
686         "GstInputSelector", &input_selector_info, 0);
687     GST_DEBUG_CATEGORY_INIT (input_selector_debug,
688         "input-selector", 0, "An input stream selector element");
689   }
690
691   return input_selector_type;
692 }
693
694 static void
695 gst_input_selector_base_init (GstInputSelectorClass * klass)
696 {
697   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
698
699   gst_element_class_set_details (element_class, &gst_input_selector_details);
700   gst_element_class_add_pad_template (element_class,
701       gst_static_pad_template_get (&gst_input_selector_sink_factory));
702   gst_element_class_add_pad_template (element_class,
703       gst_static_pad_template_get (&gst_input_selector_src_factory));
704 }
705
706 static void
707 gst_input_selector_class_init (GstInputSelectorClass * klass)
708 {
709   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
710   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
711
712   parent_class = g_type_class_peek_parent (klass);
713
714   gobject_class->dispose = gst_input_selector_dispose;
715
716   gobject_class->set_property =
717       GST_DEBUG_FUNCPTR (gst_input_selector_set_property);
718   gobject_class->get_property =
719       GST_DEBUG_FUNCPTR (gst_input_selector_get_property);
720
721   g_object_class_install_property (gobject_class, PROP_N_PADS,
722       g_param_spec_uint ("n-pads", "Number of Pads",
723           "The number of sink pads", 0, G_MAXUINT, 0, G_PARAM_READABLE));
724
725   g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
726       g_param_spec_object ("active-pad", "Active pad",
727           "The currently active sink pad", GST_TYPE_PAD, G_PARAM_READWRITE));
728
729   g_object_class_install_property (gobject_class, PROP_SELECT_ALL,
730       g_param_spec_boolean ("select-all", "Select all mode",
731           "Forwards data from all input pads", FALSE, G_PARAM_READWRITE));
732
733   /**
734    * GstInputSelector::block:
735    * @inputselector: the #GstInputSelector
736    *
737    * Block all sink pads in preparation for a switch. Returns the stop time of
738    * the current switch segment, as a running time, or 0 if there is no current
739    * active pad or the current active pad never received data.
740    */
741   gst_input_selector_signals[SIGNAL_BLOCK] =
742       g_signal_new ("block", G_TYPE_FROM_CLASS (klass),
743       G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
744       G_STRUCT_OFFSET (GstInputSelectorClass, block), NULL, NULL,
745       gst_selector_marshal_INT64__VOID, G_TYPE_INT64, 0);
746   /**
747    * GstInputSelector::switch:
748    * @inputselector: the #GstInputSelector
749    * @pad:            the pad to switch to
750    * @stop_time:      running time at which to close the previous segment, or -1
751    *                  to use the running time of the previously active sink pad
752    * @start_time:     running time at which to start the new segment, or -1 to
753    *                  use the running time of the newly active sink pad
754    *
755    * Switch to a new feed. The segment opened by the previously active pad, if
756    * any, will be closed, and a new segment opened before data flows again.
757    *
758    * This signal must be emitted when the element has been blocked via the <link
759    * linkend="GstInputSelector-block">block</link> signal.
760    *
761    * If you have a stream with only one switch element, such as an audio-only
762    * stream, a stream switch should be performed by first emitting the block
763    * signal, and then emitting the switch signal with -1 for the stop and start
764    * time values.
765    *
766    * The intention of the @stop_time and @start_time arguments is to allow
767    * multiple switch elements to switch and maintain stream synchronization.
768    * When switching a stream with multiple feeds, you will need as many switch
769    * elements as you have feeds. For example, a feed with audio and video will
770    * have one switch element between the audio feeds and one for video.
771    *
772    * A switch over multiple switch elements should be performed as follows:
773    * First, emit the <link linkend="GstInputSelector-block">block</link>
774    * signal, collecting the returned values. The maximum running time returned
775    * by block should then be used as the time at which to close the previous
776    * segment.
777    *
778    * Then, query the running times of the new audio and video pads that you will
779    * switch to. Naturally, these pads are on separate switch elements. Take the
780    * minimum running time for those streams and use it for the time at which to
781    * open the new segment.
782    *
783    * If @pad is the same as the current active pad, the element will cancel any
784    * previous block without adjusting segments.
785    *
786    * Since: 0.10.7 the signal changed from accepting the pad name to the pad
787    * object.
788    */
789   gst_input_selector_signals[SIGNAL_SWITCH] =
790       g_signal_new ("switch", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
791       G_STRUCT_OFFSET (GstInputSelectorClass, switch_),
792       NULL, NULL, gst_selector_marshal_VOID__OBJECT_INT64_INT64,
793       G_TYPE_NONE, 3, GST_TYPE_PAD, G_TYPE_INT64, G_TYPE_INT64);
794
795   gstelement_class->request_new_pad = gst_input_selector_request_new_pad;
796   gstelement_class->release_pad = gst_input_selector_release_pad;
797   gstelement_class->change_state = gst_input_selector_change_state;
798
799   klass->block = GST_DEBUG_FUNCPTR (gst_input_selector_block);
800   /* note the underscore because switch is a keyword otherwise */
801   klass->switch_ = GST_DEBUG_FUNCPTR (gst_input_selector_switch);
802 }
803
804 static void
805 gst_input_selector_init (GstInputSelector * sel)
806 {
807   sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
808   gst_pad_set_internal_link_function (sel->srcpad,
809       GST_DEBUG_FUNCPTR (gst_input_selector_get_linked_pads));
810   gst_pad_set_getcaps_function (sel->srcpad,
811       GST_DEBUG_FUNCPTR (gst_input_selector_getcaps));
812   gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
813   /* sinkpad management */
814   sel->active_sinkpad = NULL;
815   sel->padcount = 0;
816   gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
817
818   sel->lock = g_mutex_new ();
819   sel->cond = g_cond_new ();
820   sel->blocked = FALSE;
821
822   sel->select_all = FALSE;
823 }
824
825 static void
826 gst_input_selector_dispose (GObject * object)
827 {
828   GstInputSelector *sel = GST_INPUT_SELECTOR (object);
829
830   if (sel->active_sinkpad) {
831     gst_object_unref (sel->active_sinkpad);
832     sel->active_sinkpad = NULL;
833   }
834   if (sel->lock) {
835     g_mutex_free (sel->lock);
836     sel->lock = NULL;
837   }
838   if (sel->cond) {
839     g_cond_free (sel->cond);
840     sel->cond = NULL;
841   }
842
843   G_OBJECT_CLASS (parent_class)->dispose (object);
844 }
845
846 /* Solve the following equation for B.timestamp, and set that as the segment
847  * stop:
848  * B.running_time = (B.timestamp - NS.start) / NS.abs_rate + NS.accum
849  */
850 static gint64
851 gst_segment_get_timestamp (GstSegment * segment, gint64 running_time)
852 {
853   return (running_time - segment->accum) * segment->abs_rate + segment->start;
854 }
855
856 static void
857 gst_segment_set_stop (GstSegment * segment, gint64 running_time)
858 {
859   segment->stop = gst_segment_get_timestamp (segment, running_time);
860   segment->last_stop = -1;
861 }
862
863 static void
864 gst_segment_set_start (GstSegment * segment, gint64 running_time)
865 {
866   gint64 new_start, duration;
867
868   new_start = gst_segment_get_timestamp (segment, running_time);
869
870   /* this is the duration we skipped */
871   duration = new_start - segment->start;
872   /* add the duration to the accumulated segment time */
873   segment->accum += duration;
874   /* move position in the segment */
875   segment->time += duration;
876   segment->start += duration;
877 }
878
879 /* this function must be called with the SELECTOR_LOCK. It returns TRUE when the
880  * active pad changed. */
881 static gboolean
882 gst_input_selector_set_active_pad (GstInputSelector * self,
883     GstPad * pad, gint64 stop_time, gint64 start_time)
884 {
885   GstSelectorPad *old, *new;
886   GstPad **active_pad_p;
887
888   if (pad == self->active_sinkpad)
889     return FALSE;
890
891   old = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
892   new = GST_SELECTOR_PAD_CAST (pad);
893
894   GST_DEBUG_OBJECT (self, "setting active pad to %s:%s",
895       GST_DEBUG_PAD_NAME (new));
896
897   if (stop_time == -1 && old) {
898     /* no stop time given, get the latest running_time on the active pad to 
899      * close and open the new segment */
900     stop_time = start_time = gst_selector_pad_get_running_time (old);
901     GST_DEBUG_OBJECT (self, "using start/stop of %" G_GINT64_FORMAT,
902         start_time);
903   }
904
905   if (old && old->active && !self->pending_close && stop_time >= 0) {
906     /* schedule a last_stop update if one isn't already scheduled, and a
907        segment has been pushed before. */
908     memcpy (&self->segment, &old->segment, sizeof (self->segment));
909     GST_DEBUG_OBJECT (self, "setting stop_time to %" G_GINT64_FORMAT,
910         stop_time);
911     gst_segment_set_stop (&self->segment, stop_time);
912     self->pending_close = TRUE;
913   }
914
915   if (new && new->active && start_time >= 0) {
916     GST_DEBUG_OBJECT (self, "setting start_time to %" G_GINT64_FORMAT,
917         start_time);
918     /* schedule a new segment push */
919     gst_segment_set_start (&new->segment, start_time);
920     new->segment_pending = TRUE;
921   }
922
923   active_pad_p = &self->active_sinkpad;
924   gst_object_replace ((GstObject **) active_pad_p, GST_OBJECT_CAST (pad));
925   GST_DEBUG_OBJECT (self, "New active pad is %" GST_PTR_FORMAT,
926       self->active_sinkpad);
927
928   return TRUE;
929 }
930
931 static void
932 gst_input_selector_set_property (GObject * object, guint prop_id,
933     const GValue * value, GParamSpec * pspec)
934 {
935   GstInputSelector *sel = GST_INPUT_SELECTOR (object);
936
937   switch (prop_id) {
938     case PROP_ACTIVE_PAD:
939     {
940       GstPad *pad;
941
942       pad = g_value_get_object (value);
943
944       GST_INPUT_SELECTOR_LOCK (sel);
945       gst_input_selector_set_active_pad (sel, pad,
946           GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
947       GST_INPUT_SELECTOR_UNLOCK (sel);
948       break;
949     }
950     case PROP_SELECT_ALL:
951       GST_INPUT_SELECTOR_LOCK (object);
952       sel->select_all = g_value_get_boolean (value);
953       GST_INPUT_SELECTOR_UNLOCK (object);
954       break;
955     default:
956       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
957       break;
958   }
959 }
960
961 static void
962 gst_input_selector_get_property (GObject * object, guint prop_id,
963     GValue * value, GParamSpec * pspec)
964 {
965   GstInputSelector *sel = GST_INPUT_SELECTOR (object);
966
967   switch (prop_id) {
968     case PROP_N_PADS:
969       GST_INPUT_SELECTOR_LOCK (object);
970       g_value_set_uint (value, sel->n_pads);
971       GST_INPUT_SELECTOR_UNLOCK (object);
972       break;
973     case PROP_ACTIVE_PAD:
974       GST_INPUT_SELECTOR_LOCK (object);
975       g_value_set_object (value, sel->active_sinkpad);
976       GST_INPUT_SELECTOR_UNLOCK (object);
977       break;
978     case PROP_SELECT_ALL:
979       GST_INPUT_SELECTOR_LOCK (object);
980       g_value_set_boolean (value, sel->select_all);
981       GST_INPUT_SELECTOR_UNLOCK (object);
982       break;
983     default:
984       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
985       break;
986   }
987 }
988
989 static GstPad *
990 gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict)
991 {
992   GstInputSelector *sel;
993   GstPad *otherpad = NULL;
994
995   sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
996
997   GST_INPUT_SELECTOR_LOCK (sel);
998   if (pad == sel->srcpad)
999     otherpad = sel->active_sinkpad;
1000   else if (pad == sel->active_sinkpad || !strict)
1001     otherpad = sel->srcpad;
1002   if (otherpad)
1003     gst_object_ref (otherpad);
1004   GST_INPUT_SELECTOR_UNLOCK (sel);
1005
1006   gst_object_unref (sel);
1007
1008   return otherpad;
1009 }
1010
1011 static GstCaps *
1012 gst_input_selector_getcaps (GstPad * pad)
1013 {
1014   GstPad *otherpad;
1015   GstObject *parent;
1016   GstCaps *caps;
1017
1018   parent = gst_object_get_parent (GST_OBJECT (pad));
1019   if (GST_INPUT_SELECTOR (parent)->select_all) {
1020     caps = gst_pad_proxy_getcaps (pad);
1021     goto done;
1022   }
1023
1024   otherpad = gst_input_selector_get_linked_pad (pad, FALSE);
1025   if (!otherpad) {
1026     GST_DEBUG_OBJECT (parent,
1027         "Pad %s:%s not linked, returning ANY", GST_DEBUG_PAD_NAME (pad));
1028     caps = gst_caps_new_any ();
1029   } else {
1030     GST_DEBUG_OBJECT (parent,
1031         "Pad %s:%s is linked (to %s:%s), returning peer caps",
1032         GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (otherpad));
1033     /* if the peer has caps, use those. If the pad is not linked, this function
1034      * returns NULL and we return ANY */
1035     if (!(caps = gst_pad_peer_get_caps (otherpad)))
1036       caps = gst_caps_new_any ();
1037     gst_object_unref (otherpad);
1038   }
1039
1040 done:
1041   gst_object_unref (parent);
1042   return caps;
1043 }
1044
1045 /* check if the pad is the active sinkpad */
1046 static gboolean
1047 gst_input_selector_is_active_sinkpad (GstInputSelector * sel, GstPad * pad)
1048 {
1049   GstSelectorPad *selpad;
1050   gboolean res;
1051
1052   selpad = GST_SELECTOR_PAD_CAST (pad);
1053
1054   GST_INPUT_SELECTOR_LOCK (sel);
1055   res = (pad == sel->active_sinkpad);
1056   GST_INPUT_SELECTOR_UNLOCK (sel);
1057
1058   return res;
1059 }
1060
1061 /* Get or create the active sinkpad, must be called with SELECTOR_LOCK */
1062 static GstPad *
1063 gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad)
1064 {
1065   GstPad *active_sinkpad;
1066   GstSelectorPad *selpad;
1067
1068   selpad = GST_SELECTOR_PAD_CAST (pad);
1069
1070   selpad->active = TRUE;
1071   active_sinkpad = sel->active_sinkpad;
1072   if (active_sinkpad == NULL) {
1073     /* first pad we get activity on becomes the activated pad by default */
1074     active_sinkpad = sel->active_sinkpad = gst_object_ref (pad);
1075     GST_DEBUG_OBJECT (sel, "Activating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1076   }
1077
1078   return active_sinkpad;
1079 }
1080
1081 static GList *
1082 gst_input_selector_get_linked_pads (GstPad * pad)
1083 {
1084   GstPad *otherpad;
1085
1086   otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
1087   if (!otherpad)
1088     return NULL;
1089   /* need to drop the ref, internal linked pads is not MT safe */
1090   gst_object_unref (otherpad);
1091   return g_list_append (NULL, otherpad);
1092 }
1093
1094 static GstPad *
1095 gst_input_selector_request_new_pad (GstElement * element,
1096     GstPadTemplate * templ, const gchar * unused)
1097 {
1098   GstInputSelector *sel;
1099   gchar *name = NULL;
1100   GstPad *sinkpad = NULL;
1101
1102   g_return_val_if_fail (templ->direction == GST_PAD_SINK, NULL);
1103
1104   sel = GST_INPUT_SELECTOR (element);
1105
1106   GST_INPUT_SELECTOR_LOCK (sel);
1107
1108   GST_LOG_OBJECT (sel, "Creating new pad %d", sel->padcount);
1109   name = g_strdup_printf ("sink%d", sel->padcount++);
1110   sinkpad = g_object_new (GST_TYPE_SELECTOR_PAD,
1111       "name", name, "direction", templ->direction, "template", templ, NULL);
1112   g_free (name);
1113
1114   sel->n_pads++;
1115
1116   gst_pad_set_event_function (sinkpad,
1117       GST_DEBUG_FUNCPTR (gst_selector_pad_event));
1118   gst_pad_set_getcaps_function (sinkpad,
1119       GST_DEBUG_FUNCPTR (gst_selector_pad_getcaps));
1120   gst_pad_set_chain_function (sinkpad,
1121       GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
1122   gst_pad_set_internal_link_function (sinkpad,
1123       GST_DEBUG_FUNCPTR (gst_selector_pad_get_linked_pads));
1124   gst_pad_set_bufferalloc_function (sinkpad,
1125       GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));
1126
1127   gst_pad_set_active (sinkpad, TRUE);
1128   gst_element_add_pad (GST_ELEMENT (sel), sinkpad);
1129   GST_INPUT_SELECTOR_UNLOCK (sel);
1130
1131   return sinkpad;
1132 }
1133
1134 static void
1135 gst_input_selector_release_pad (GstElement * element, GstPad * pad)
1136 {
1137   GstInputSelector *sel;
1138
1139   sel = GST_INPUT_SELECTOR (element);
1140   GST_LOG_OBJECT (sel, "Releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1141
1142   GST_INPUT_SELECTOR_LOCK (sel);
1143   /* if the pad was the active pad, makes us select a new one */
1144   if (sel->active_sinkpad == pad) {
1145     GST_DEBUG_OBJECT (sel, "Deactivating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1146     sel->active_sinkpad = NULL;
1147   }
1148   sel->n_pads--;
1149
1150   gst_pad_set_active (pad, FALSE);
1151   gst_element_remove_pad (GST_ELEMENT (sel), pad);
1152   GST_INPUT_SELECTOR_UNLOCK (sel);
1153 }
1154
1155 static GstStateChangeReturn
1156 gst_input_selector_change_state (GstElement * element,
1157     GstStateChange transition)
1158 {
1159   GstInputSelector *self = GST_INPUT_SELECTOR (element);
1160   GstStateChangeReturn result;
1161
1162   switch (transition) {
1163     case GST_STATE_CHANGE_READY_TO_PAUSED:
1164       GST_INPUT_SELECTOR_LOCK (self);
1165       self->blocked = FALSE;
1166       self->flushing = FALSE;
1167       GST_INPUT_SELECTOR_UNLOCK (self);
1168       break;
1169     case GST_STATE_CHANGE_PAUSED_TO_READY:
1170       /* first unlock before we call the parent state change function, which
1171        * tries to acquire the stream lock when going to ready. */
1172       GST_INPUT_SELECTOR_LOCK (self);
1173       self->blocked = FALSE;
1174       self->flushing = TRUE;
1175       GST_INPUT_SELECTOR_BROADCAST (self);
1176       GST_INPUT_SELECTOR_UNLOCK (self);
1177       break;
1178     default:
1179       break;
1180   }
1181
1182   result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1183
1184   return result;
1185 }
1186
1187 static gint64
1188 gst_input_selector_block (GstInputSelector * self)
1189 {
1190   gint64 ret = 0;
1191   GstSelectorPad *spad;
1192
1193   GST_INPUT_SELECTOR_LOCK (self);
1194
1195   if (self->blocked)
1196     GST_WARNING_OBJECT (self, "switch already blocked");
1197
1198   self->blocked = TRUE;
1199   spad = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
1200
1201   if (spad)
1202     ret = gst_selector_pad_get_running_time (spad);
1203   else
1204     GST_DEBUG_OBJECT (self, "no active pad while blocking");
1205
1206   GST_INPUT_SELECTOR_UNLOCK (self);
1207
1208   return ret;
1209 }
1210
1211 /* stop_time and start_time are running times */
1212 static void
1213 gst_input_selector_switch (GstInputSelector * self, GstPad * pad,
1214     gint64 stop_time, gint64 start_time)
1215 {
1216   gboolean changed;
1217
1218   g_return_if_fail (self->blocked == TRUE);
1219
1220   GST_INPUT_SELECTOR_LOCK (self);
1221   changed =
1222       gst_input_selector_set_active_pad (self, pad, stop_time, start_time);
1223
1224   self->blocked = FALSE;
1225   GST_INPUT_SELECTOR_BROADCAST (self);
1226   GST_INPUT_SELECTOR_UNLOCK (self);
1227
1228   if (changed)
1229     g_object_notify (G_OBJECT (self), "active-pad");
1230 }
1231
1232 static gboolean
1233 gst_input_selector_check_eos (GstElement * selector)
1234 {
1235   GstIterator *it = gst_element_iterate_sink_pads (selector);
1236   GstIteratorResult ires;
1237   gpointer item;
1238   gboolean done = FALSE, is_eos = FALSE;
1239   GstSelectorPad *pad;
1240
1241   while (!done) {
1242     ires = gst_iterator_next (it, &item);
1243     switch (ires) {
1244       case GST_ITERATOR_DONE:
1245         GST_INFO_OBJECT (selector, "all sink pads have eos");
1246         done = TRUE;
1247         is_eos = TRUE;
1248         break;
1249       case GST_ITERATOR_OK:
1250         pad = GST_SELECTOR_PAD_CAST (item);
1251         if (!pad->eos) {
1252           done = TRUE;
1253         }
1254         break;
1255       case GST_ITERATOR_RESYNC:
1256         gst_iterator_resync (it);
1257         break;
1258       default:
1259         done = TRUE;
1260         break;
1261     }
1262   }
1263   gst_iterator_free (it);
1264
1265   return is_eos;
1266 }