1 /* GStreamer input selector
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>)
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.
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.
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.
26 * SECTION:element-input-selector
27 * @see_also: #GstOutputSelector
29 * Direct one out of N input streams to the output pad.
40 #include "gstinputselector.h"
42 GST_DEBUG_CATEGORY_STATIC (input_selector_debug);
43 #define GST_CAT_DEFAULT input_selector_debug
45 #if GLIB_CHECK_VERSION(2, 26, 0)
46 #define NOTIFY_MUTEX_LOCK()
47 #define NOTIFY_MUTEX_UNLOCK()
49 static GStaticRecMutex notify_mutex = G_STATIC_REC_MUTEX_INIT;
50 #define NOTIFY_MUTEX_LOCK() g_static_rec_mutex_lock (¬ify_mutex)
51 #define NOTIFY_MUTEX_UNLOCK() g_static_rec_mutex_unlock (¬ify_mutex)
54 static GstStaticPadTemplate gst_input_selector_sink_factory =
55 GST_STATIC_PAD_TEMPLATE ("sink%d",
60 static GstStaticPadTemplate gst_input_selector_src_factory =
61 GST_STATIC_PAD_TEMPLATE ("src",
74 #define DEFAULT_PAD_ALWAYS_OK TRUE
79 PROP_PAD_RUNNING_TIME,
92 static guint gst_input_selector_signals[LAST_SIGNAL] = { 0 };
94 static inline gboolean gst_input_selector_is_active_sinkpad (GstInputSelector *
96 static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel,
98 static GstPad *gst_input_selector_get_linked_pad (GstPad * pad,
100 static gboolean gst_input_selector_check_eos (GstElement * selector);
102 #define GST_TYPE_SELECTOR_PAD \
103 (gst_selector_pad_get_type())
104 #define GST_SELECTOR_PAD(obj) \
105 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SELECTOR_PAD, GstSelectorPad))
106 #define GST_SELECTOR_PAD_CLASS(klass) \
107 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_SELECTOR_PAD, GstSelectorPadClass))
108 #define GST_IS_SELECTOR_PAD(obj) \
109 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SELECTOR_PAD))
110 #define GST_IS_SELECTOR_PAD_CLASS(klass) \
111 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_SELECTOR_PAD))
112 #define GST_SELECTOR_PAD_CAST(obj) \
113 ((GstSelectorPad *)(obj))
115 typedef struct _GstSelectorPad GstSelectorPad;
116 typedef struct _GstSelectorPadClass GstSelectorPadClass;
118 struct _GstSelectorPad
122 gboolean active; /* when buffer have passed the pad */
123 gboolean eos; /* when EOS has been received */
124 gboolean discont; /* after switching we create a discont */
126 GstSegment segment; /* the current segment on the pad */
127 GstTagList *tags; /* last tags received on the pad */
129 gboolean segment_pending;
132 struct _GstSelectorPadClass
137 static void gst_selector_pad_class_init (GstSelectorPadClass * klass);
138 static void gst_selector_pad_init (GstSelectorPad * pad);
139 static void gst_selector_pad_finalize (GObject * object);
140 static void gst_selector_pad_get_property (GObject * object,
141 guint prop_id, GValue * value, GParamSpec * pspec);
142 static void gst_selector_pad_set_property (GObject * object,
143 guint prop_id, const GValue * value, GParamSpec * pspec);
145 static GstPadClass *selector_pad_parent_class = NULL;
147 static gint64 gst_selector_pad_get_running_time (GstSelectorPad * pad);
148 static void gst_selector_pad_reset (GstSelectorPad * pad);
149 static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
150 static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
151 static gboolean gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps);
152 static GstIterator *gst_selector_pad_iterate_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);
158 gst_selector_pad_get_type (void)
160 static GType selector_pad_type = 0;
162 if (!selector_pad_type) {
163 static const GTypeInfo selector_pad_info = {
164 sizeof (GstSelectorPadClass),
167 (GClassInitFunc) gst_selector_pad_class_init,
170 sizeof (GstSelectorPad),
172 (GInstanceInitFunc) gst_selector_pad_init,
176 g_type_register_static (GST_TYPE_PAD, "GstSelectorPad",
177 &selector_pad_info, 0);
179 return selector_pad_type;
183 gst_selector_pad_class_init (GstSelectorPadClass * klass)
185 GObjectClass *gobject_class;
187 gobject_class = (GObjectClass *) klass;
189 selector_pad_parent_class = g_type_class_peek_parent (klass);
191 gobject_class->finalize = gst_selector_pad_finalize;
193 gobject_class->get_property = gst_selector_pad_get_property;
194 gobject_class->set_property = gst_selector_pad_set_property;
196 g_object_class_install_property (gobject_class, PROP_PAD_RUNNING_TIME,
197 g_param_spec_int64 ("running-time", "Running time",
198 "Running time of stream on pad", 0, G_MAXINT64, 0,
199 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
200 g_object_class_install_property (gobject_class, PROP_PAD_TAGS,
201 g_param_spec_boxed ("tags", "Tags",
202 "The currently active tags on the pad", GST_TYPE_TAG_LIST,
203 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
204 g_object_class_install_property (gobject_class, PROP_PAD_ACTIVE,
205 g_param_spec_boolean ("active", "Active",
206 "If the pad is currently active", FALSE,
207 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
208 /* FIXME: better property name? */
209 g_object_class_install_property (gobject_class, PROP_PAD_ALWAYS_OK,
210 g_param_spec_boolean ("always-ok", "Always OK",
211 "Make an inactive pad return OK instead of NOT_LINKED",
212 DEFAULT_PAD_ALWAYS_OK, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
216 gst_selector_pad_init (GstSelectorPad * pad)
218 pad->always_ok = DEFAULT_PAD_ALWAYS_OK;
219 gst_selector_pad_reset (pad);
223 gst_selector_pad_finalize (GObject * object)
227 pad = GST_SELECTOR_PAD_CAST (object);
230 gst_tag_list_free (pad->tags);
232 G_OBJECT_CLASS (selector_pad_parent_class)->finalize (object);
236 gst_selector_pad_set_property (GObject * object, guint prop_id,
237 const GValue * value, GParamSpec * pspec)
239 GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
242 case PROP_PAD_ALWAYS_OK:
243 GST_OBJECT_LOCK (object);
244 spad->always_ok = g_value_get_boolean (value);
245 GST_OBJECT_UNLOCK (object);
248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
254 gst_selector_pad_get_property (GObject * object, guint prop_id,
255 GValue * value, GParamSpec * pspec)
257 GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
260 case PROP_PAD_RUNNING_TIME:
261 g_value_set_int64 (value, gst_selector_pad_get_running_time (spad));
264 GST_OBJECT_LOCK (object);
265 g_value_set_boxed (value, spad->tags);
266 GST_OBJECT_UNLOCK (object);
268 case PROP_PAD_ACTIVE:
270 GstInputSelector *sel;
272 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (spad));
273 g_value_set_boolean (value, gst_input_selector_is_active_sinkpad (sel,
274 GST_PAD_CAST (spad)));
275 gst_object_unref (sel);
278 case PROP_PAD_ALWAYS_OK:
279 GST_OBJECT_LOCK (object);
280 g_value_set_boolean (value, spad->always_ok);
281 GST_OBJECT_UNLOCK (object);
284 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290 gst_selector_pad_get_running_time (GstSelectorPad * pad)
294 GST_OBJECT_LOCK (pad);
296 gint64 last_stop = pad->segment.last_stop;
299 ret = gst_segment_to_running_time (&pad->segment, GST_FORMAT_TIME,
302 GST_OBJECT_UNLOCK (pad);
304 GST_DEBUG_OBJECT (pad, "running time: %" GST_TIME_FORMAT,
305 GST_TIME_ARGS (ret));
311 gst_selector_pad_reset (GstSelectorPad * pad)
313 GST_OBJECT_LOCK (pad);
316 pad->segment_pending = FALSE;
317 pad->discont = FALSE;
318 gst_segment_init (&pad->segment, GST_FORMAT_UNDEFINED);
319 GST_OBJECT_UNLOCK (pad);
322 /* strictly get the linked pad from the sinkpad. If the pad is active we return
323 * the srcpad else we return NULL */
325 gst_selector_pad_iterate_linked_pads (GstPad * pad)
327 GstInputSelector *sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
331 otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
332 it = gst_iterator_new_single (GST_TYPE_PAD, otherpad,
333 (GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
336 gst_object_unref (otherpad);
337 gst_object_unref (sel);
343 gst_selector_pad_event (GstPad * pad, GstEvent * event)
346 gboolean forward = TRUE;
347 GstInputSelector *sel;
348 GstSelectorPad *selpad;
349 GstPad *prev_active_sinkpad;
350 GstPad *active_sinkpad;
352 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
353 selpad = GST_SELECTOR_PAD_CAST (pad);
355 GST_INPUT_SELECTOR_LOCK (sel);
356 prev_active_sinkpad = sel->active_sinkpad;
357 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
359 /* only forward if we are dealing with the active sinkpad or if select_all
361 if (pad != active_sinkpad && !sel->select_all)
363 GST_INPUT_SELECTOR_UNLOCK (sel);
365 if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
366 NOTIFY_MUTEX_LOCK ();
367 g_object_notify (G_OBJECT (sel), "active-pad");
368 NOTIFY_MUTEX_UNLOCK ();
371 switch (GST_EVENT_TYPE (event)) {
372 case GST_EVENT_FLUSH_START:
373 /* FIXME, flush out the waiter */
375 case GST_EVENT_FLUSH_STOP:
376 GST_INPUT_SELECTOR_LOCK (sel);
377 gst_selector_pad_reset (selpad);
378 sel->pending_close = FALSE;
379 GST_INPUT_SELECTOR_UNLOCK (sel);
381 case GST_EVENT_NEWSEGMENT:
386 gint64 start, stop, time;
388 gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
389 &start, &stop, &time);
391 GST_DEBUG_OBJECT (pad,
392 "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
394 "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
395 G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
397 GST_INPUT_SELECTOR_LOCK (sel);
398 GST_OBJECT_LOCK (selpad);
399 gst_segment_set_newsegment_full (&selpad->segment, update,
400 rate, arate, format, start, stop, time);
401 GST_OBJECT_UNLOCK (selpad);
403 /* If we aren't forwarding the event (because the pad is not the
404 * active_sinkpad, and select_all is not set, then set the flag on the
405 * that says a segment needs sending if/when that pad is activated.
406 * For all other cases, we send the event immediately, which makes
407 * sparse streams and other segment updates work correctly downstream.
410 selpad->segment_pending = TRUE;
412 GST_INPUT_SELECTOR_UNLOCK (sel);
417 GstTagList *tags, *oldtags, *newtags;
419 gst_event_parse_tag (event, &tags);
421 GST_OBJECT_LOCK (selpad);
422 oldtags = selpad->tags;
424 newtags = gst_tag_list_merge (oldtags, tags, GST_TAG_MERGE_REPLACE);
425 selpad->tags = newtags;
427 gst_tag_list_free (oldtags);
428 GST_DEBUG_OBJECT (pad, "received tags %" GST_PTR_FORMAT, newtags);
429 GST_OBJECT_UNLOCK (selpad);
431 g_object_notify (G_OBJECT (selpad), "tags");
436 GST_DEBUG_OBJECT (pad, "received EOS");
437 /* don't forward eos in select_all mode until all sink pads have eos */
438 if (sel->select_all && !gst_input_selector_check_eos (GST_ELEMENT (sel))) {
446 GST_DEBUG_OBJECT (pad, "forwarding event");
447 res = gst_pad_push_event (sel->srcpad, event);
449 gst_event_unref (event);
451 gst_object_unref (sel);
457 gst_selector_pad_getcaps (GstPad * pad)
459 GstInputSelector *sel;
462 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
464 GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer");
465 caps = gst_pad_peer_get_caps_reffed (sel->srcpad);
467 caps = gst_caps_new_any ();
469 gst_object_unref (sel);
475 gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps)
477 GstInputSelector *sel;
480 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
482 GST_DEBUG_OBJECT (sel, "Checking acceptcaps of srcpad peer");
483 res = gst_pad_peer_accept_caps (sel->srcpad, caps);
484 gst_object_unref (sel);
490 gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset,
491 guint size, GstCaps * caps, GstBuffer ** buf)
493 GstInputSelector *sel;
494 GstFlowReturn result;
495 GstPad *active_sinkpad;
496 GstPad *prev_active_sinkpad;
497 GstSelectorPad *selpad;
499 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
500 selpad = GST_SELECTOR_PAD_CAST (pad);
502 GST_LOG_OBJECT (pad, "received alloc");
504 GST_INPUT_SELECTOR_LOCK (sel);
505 prev_active_sinkpad = sel->active_sinkpad;
506 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
508 if (pad != active_sinkpad)
511 GST_INPUT_SELECTOR_UNLOCK (sel);
513 if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
514 NOTIFY_MUTEX_LOCK ();
515 g_object_notify (G_OBJECT (sel), "active-pad");
516 NOTIFY_MUTEX_UNLOCK ();
519 result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf);
522 gst_object_unref (sel);
529 GST_INPUT_SELECTOR_UNLOCK (sel);
531 /* unselected pad, perform fallback alloc or return unlinked when
533 GST_OBJECT_LOCK (selpad);
534 if (selpad->always_ok) {
535 GST_DEBUG_OBJECT (pad, "Not selected, performing fallback allocation");
537 result = GST_FLOW_OK;
539 GST_DEBUG_OBJECT (pad, "Not selected, return NOT_LINKED");
540 result = GST_FLOW_NOT_LINKED;
542 GST_OBJECT_UNLOCK (selpad);
548 /* must be called with the SELECTOR_LOCK, will block while the pad is blocked
549 * or return TRUE when flushing */
551 gst_input_selector_wait (GstInputSelector * self, GstPad * pad)
553 while (self->blocked && !self->flushing) {
554 /* we can be unlocked here when we are shutting down (flushing) or when we
556 GST_INPUT_SELECTOR_WAIT (self);
558 return self->flushing;
562 gst_selector_pad_chain (GstPad * pad, GstBuffer * buf)
564 GstInputSelector *sel;
566 GstPad *active_sinkpad;
567 GstPad *prev_active_sinkpad;
568 GstSelectorPad *selpad;
569 GstClockTime start_time;
571 GstEvent *close_event = NULL, *start_event = NULL;
574 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
575 selpad = GST_SELECTOR_PAD_CAST (pad);
576 seg = &selpad->segment;
578 GST_INPUT_SELECTOR_LOCK (sel);
579 /* wait or check for flushing */
580 if (gst_input_selector_wait (sel, pad))
583 GST_LOG_OBJECT (pad, "getting active pad");
585 prev_active_sinkpad = sel->active_sinkpad;
586 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
588 /* update the segment on the srcpad */
589 start_time = GST_BUFFER_TIMESTAMP (buf);
590 if (GST_CLOCK_TIME_IS_VALID (start_time)) {
591 GST_LOG_OBJECT (pad, "received start time %" GST_TIME_FORMAT,
592 GST_TIME_ARGS (start_time));
593 if (GST_BUFFER_DURATION_IS_VALID (buf))
594 GST_LOG_OBJECT (pad, "received end time %" GST_TIME_FORMAT,
595 GST_TIME_ARGS (start_time + GST_BUFFER_DURATION (buf)));
597 GST_OBJECT_LOCK (pad);
598 gst_segment_set_last_stop (seg, seg->format, start_time);
599 GST_OBJECT_UNLOCK (pad);
602 /* Ignore buffers from pads except the selected one */
603 if (pad != active_sinkpad)
606 if (G_UNLIKELY (sel->pending_close)) {
607 GstSegment *cseg = &sel->segment;
609 GST_DEBUG_OBJECT (sel,
610 "pushing close NEWSEGMENT update %d, rate %lf, applied rate %lf, "
612 "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
613 G_GINT64_FORMAT, TRUE, cseg->rate, cseg->applied_rate, cseg->format,
614 cseg->start, cseg->stop, cseg->time);
616 /* create update segment */
617 close_event = gst_event_new_new_segment_full (TRUE, cseg->rate,
618 cseg->applied_rate, cseg->format, cseg->start, cseg->stop, cseg->time);
620 sel->pending_close = FALSE;
622 /* if we have a pending segment, push it out now */
623 if (G_UNLIKELY (selpad->segment_pending)) {
624 GST_DEBUG_OBJECT (pad,
625 "pushing pending NEWSEGMENT update %d, rate %lf, applied rate %lf, "
627 "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
628 G_GINT64_FORMAT, FALSE, seg->rate, seg->applied_rate, seg->format,
629 seg->start, seg->stop, seg->time);
631 start_event = gst_event_new_new_segment_full (FALSE, seg->rate,
632 seg->applied_rate, seg->format, seg->start, seg->stop, seg->time);
634 selpad->segment_pending = FALSE;
636 GST_INPUT_SELECTOR_UNLOCK (sel);
638 if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
639 NOTIFY_MUTEX_LOCK ();
640 g_object_notify (G_OBJECT (sel), "active-pad");
641 NOTIFY_MUTEX_UNLOCK ();
645 gst_pad_push_event (sel->srcpad, close_event);
648 gst_pad_push_event (sel->srcpad, start_event);
650 if (selpad->discont) {
651 buf = gst_buffer_make_metadata_writable (buf);
653 GST_DEBUG_OBJECT (pad, "Marking discont buffer %p", buf);
654 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
655 selpad->discont = FALSE;
659 GST_LOG_OBJECT (pad, "Forwarding buffer %p", buf);
661 if ((caps = GST_BUFFER_CAPS (buf))) {
662 if (GST_PAD_CAPS (sel->srcpad) != caps)
663 gst_pad_set_caps (sel->srcpad, caps);
666 res = gst_pad_push (sel->srcpad, buf);
669 gst_object_unref (sel);
672 /* dropped buffers */
675 GST_DEBUG_OBJECT (pad, "Pad not active, discard buffer %p", buf);
676 /* when we drop a buffer, we're creating a discont on this pad */
677 selpad->discont = TRUE;
678 GST_INPUT_SELECTOR_UNLOCK (sel);
679 gst_buffer_unref (buf);
681 /* figure out what to return upstream */
682 GST_OBJECT_LOCK (selpad);
683 if (selpad->always_ok)
686 res = GST_FLOW_NOT_LINKED;
687 GST_OBJECT_UNLOCK (selpad);
693 GST_DEBUG_OBJECT (pad, "We are flushing, discard buffer %p", buf);
694 GST_INPUT_SELECTOR_UNLOCK (sel);
695 gst_buffer_unref (buf);
696 res = GST_FLOW_WRONG_STATE;
701 static void gst_input_selector_dispose (GObject * object);
703 static void gst_input_selector_set_property (GObject * object,
704 guint prop_id, const GValue * value, GParamSpec * pspec);
705 static void gst_input_selector_get_property (GObject * object,
706 guint prop_id, GValue * value, GParamSpec * pspec);
708 static GstPad *gst_input_selector_request_new_pad (GstElement * element,
709 GstPadTemplate * templ, const gchar * unused);
710 static void gst_input_selector_release_pad (GstElement * element, GstPad * pad);
712 static GstStateChangeReturn gst_input_selector_change_state (GstElement *
713 element, GstStateChange transition);
715 static GstCaps *gst_input_selector_getcaps (GstPad * pad);
716 static gboolean gst_input_selector_event (GstPad * pad, GstEvent * event);
717 static gboolean gst_input_selector_query (GstPad * pad, GstQuery * query);
718 static gint64 gst_input_selector_block (GstInputSelector * self);
719 static void gst_input_selector_switch (GstInputSelector * self,
720 GstPad * pad, gint64 stop_time, gint64 start_time);
722 /* FIXME: create these marshallers using glib-genmarshal */
723 #define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
724 #define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
727 gst_input_selector_marshal_INT64__VOID (GClosure * closure,
728 GValue * return_value G_GNUC_UNUSED,
729 guint n_param_values,
730 const GValue * param_values,
731 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
733 typedef gint64 (*GMarshalFunc_INT64__VOID) (gpointer data1, gpointer data2);
734 register GMarshalFunc_INT64__VOID callback;
735 register GCClosure *cc = (GCClosure *) closure;
736 register gpointer data1, data2;
739 g_return_if_fail (return_value != NULL);
740 g_return_if_fail (n_param_values == 1);
742 if (G_CCLOSURE_SWAP_DATA (closure)) {
743 data1 = closure->data;
744 data2 = g_value_peek_pointer (param_values + 0);
746 data1 = g_value_peek_pointer (param_values + 0);
747 data2 = closure->data;
750 (GMarshalFunc_INT64__VOID) (marshal_data ? marshal_data : cc->callback);
752 v_return = callback (data1, data2);
754 g_value_set_int64 (return_value, v_return);
758 gst_input_selector_marshal_VOID__OBJECT_INT64_INT64 (GClosure * closure,
759 GValue * return_value G_GNUC_UNUSED,
760 guint n_param_values,
761 const GValue * param_values,
762 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
764 typedef void (*GMarshalFunc_VOID__OBJECT_INT64_INT64) (gpointer data1,
765 gpointer arg_1, gint64 arg_2, gint64 arg_3, gpointer data2);
766 register GMarshalFunc_VOID__OBJECT_INT64_INT64 callback;
767 register GCClosure *cc = (GCClosure *) closure;
768 register gpointer data1, data2;
770 g_return_if_fail (n_param_values == 4);
772 if (G_CCLOSURE_SWAP_DATA (closure)) {
773 data1 = closure->data;
774 data2 = g_value_peek_pointer (param_values + 0);
776 data1 = g_value_peek_pointer (param_values + 0);
777 data2 = closure->data;
780 (GMarshalFunc_VOID__OBJECT_INT64_INT64) (marshal_data ? marshal_data :
784 g_marshal_value_peek_object (param_values + 1),
785 g_marshal_value_peek_int64 (param_values + 2),
786 g_marshal_value_peek_int64 (param_values + 3), data2);
789 #define _do_init(bla) \
790 GST_DEBUG_CATEGORY_INIT (input_selector_debug, \
791 "input-selector", 0, "An input stream selector element");
793 GST_BOILERPLATE_FULL (GstInputSelector, gst_input_selector, GstElement,
794 GST_TYPE_ELEMENT, _do_init);
797 gst_input_selector_base_init (gpointer g_class)
799 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
801 gst_element_class_set_details_simple (element_class, "Input selector",
802 "Generic", "N-to-1 input stream selector",
803 "Julien Moutte <julien@moutte.net>, "
804 "Jan Schmidt <thaytan@mad.scientist.com>, "
805 "Wim Taymans <wim.taymans@gmail.com>");
806 gst_element_class_add_pad_template (element_class,
807 gst_static_pad_template_get (&gst_input_selector_sink_factory));
808 gst_element_class_add_pad_template (element_class,
809 gst_static_pad_template_get (&gst_input_selector_src_factory));
813 gst_input_selector_class_init (GstInputSelectorClass * klass)
815 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
816 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
818 gobject_class->dispose = gst_input_selector_dispose;
820 gobject_class->set_property = gst_input_selector_set_property;
821 gobject_class->get_property = gst_input_selector_get_property;
823 g_object_class_install_property (gobject_class, PROP_N_PADS,
824 g_param_spec_uint ("n-pads", "Number of Pads",
825 "The number of sink pads", 0, G_MAXUINT, 0,
826 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
828 g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
829 g_param_spec_object ("active-pad", "Active pad",
830 "The currently active sink pad", GST_TYPE_PAD,
831 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
833 g_object_class_install_property (gobject_class, PROP_SELECT_ALL,
834 g_param_spec_boolean ("select-all", "Select all mode",
835 "Forwards data from all input pads", FALSE,
836 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
839 * GstInputSelector::block:
840 * @inputselector: the #GstInputSelector
842 * Block all sink pads in preparation for a switch. Returns the stop time of
843 * the current switch segment, as a running time, or 0 if there is no current
844 * active pad or the current active pad never received data.
846 gst_input_selector_signals[SIGNAL_BLOCK] =
847 g_signal_new ("block", G_TYPE_FROM_CLASS (klass),
848 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
849 G_STRUCT_OFFSET (GstInputSelectorClass, block), NULL, NULL,
850 gst_input_selector_marshal_INT64__VOID, G_TYPE_INT64, 0);
852 * GstInputSelector::switch:
853 * @inputselector: the #GstInputSelector
854 * @pad: the pad to switch to
855 * @stop_time: running time at which to close the previous segment, or -1
856 * to use the running time of the previously active sink pad
857 * @start_time: running time at which to start the new segment, or -1 to
858 * use the running time of the newly active sink pad
860 * Switch to a new feed. The segment opened by the previously active pad, if
861 * any, will be closed, and a new segment opened before data flows again.
863 * This signal must be emitted when the element has been blocked via the <link
864 * linkend="GstInputSelector-block">block</link> signal.
866 * If you have a stream with only one switch element, such as an audio-only
867 * stream, a stream switch should be performed by first emitting the block
868 * signal, and then emitting the switch signal with -1 for the stop and start
871 * The intention of the @stop_time and @start_time arguments is to allow
872 * multiple switch elements to switch and maintain stream synchronization.
873 * When switching a stream with multiple feeds, you will need as many switch
874 * elements as you have feeds. For example, a feed with audio and video will
875 * have one switch element between the audio feeds and one for video.
877 * A switch over multiple switch elements should be performed as follows:
878 * First, emit the <link linkend="GstInputSelector-block">block</link>
879 * signal, collecting the returned values. The maximum running time returned
880 * by block should then be used as the time at which to close the previous
883 * Then, query the running times of the new audio and video pads that you will
884 * switch to. Naturally, these pads are on separate switch elements. Take the
885 * minimum running time for those streams and use it for the time at which to
886 * open the new segment.
888 * If @pad is the same as the current active pad, the element will cancel any
889 * previous block without adjusting segments.
892 * the signal changed from accepting the pad name to the pad object.
897 gst_input_selector_signals[SIGNAL_SWITCH] =
898 g_signal_new ("switch", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
899 G_STRUCT_OFFSET (GstInputSelectorClass, switch_),
900 NULL, NULL, gst_input_selector_marshal_VOID__OBJECT_INT64_INT64,
901 G_TYPE_NONE, 3, GST_TYPE_PAD, G_TYPE_INT64, G_TYPE_INT64);
903 gstelement_class->request_new_pad = gst_input_selector_request_new_pad;
904 gstelement_class->release_pad = gst_input_selector_release_pad;
905 gstelement_class->change_state = gst_input_selector_change_state;
907 klass->block = GST_DEBUG_FUNCPTR (gst_input_selector_block);
908 /* note the underscore because switch is a keyword otherwise */
909 klass->switch_ = GST_DEBUG_FUNCPTR (gst_input_selector_switch);
913 gst_input_selector_init (GstInputSelector * sel,
914 GstInputSelectorClass * g_class)
916 sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
917 gst_pad_set_iterate_internal_links_function (sel->srcpad,
918 GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
919 gst_pad_set_getcaps_function (sel->srcpad,
920 GST_DEBUG_FUNCPTR (gst_input_selector_getcaps));
921 gst_pad_set_query_function (sel->srcpad,
922 GST_DEBUG_FUNCPTR (gst_input_selector_query));
923 gst_pad_set_event_function (sel->srcpad,
924 GST_DEBUG_FUNCPTR (gst_input_selector_event));
925 gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
926 /* sinkpad management */
927 sel->active_sinkpad = NULL;
929 gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
931 sel->lock = g_mutex_new ();
932 sel->cond = g_cond_new ();
933 sel->blocked = FALSE;
935 sel->select_all = FALSE;
939 gst_input_selector_dispose (GObject * object)
941 GstInputSelector *sel = GST_INPUT_SELECTOR (object);
943 if (sel->active_sinkpad) {
944 gst_object_unref (sel->active_sinkpad);
945 sel->active_sinkpad = NULL;
948 g_mutex_free (sel->lock);
952 g_cond_free (sel->cond);
956 G_OBJECT_CLASS (parent_class)->dispose (object);
959 /* Solve the following equation for B.timestamp, and set that as the segment
961 * B.running_time = (B.timestamp - NS.start) / NS.abs_rate + NS.accum
964 gst_segment_get_timestamp (GstSegment * segment, gint64 running_time)
966 if (running_time <= segment->accum)
967 return segment->start;
969 return (running_time - segment->accum) * segment->abs_rate + segment->start;
973 gst_segment_set_stop (GstSegment * segment, gint64 running_time)
975 segment->stop = gst_segment_get_timestamp (segment, running_time);
976 segment->last_stop = -1;
980 gst_segment_set_start (GstSegment * segment, gint64 running_time)
982 gint64 new_start, duration;
984 new_start = gst_segment_get_timestamp (segment, running_time);
986 /* this is the duration we skipped */
987 duration = new_start - segment->start;
988 /* add the duration to the accumulated segment time */
989 segment->accum += duration;
990 /* move position in the segment */
991 segment->time += duration;
992 segment->start += duration;
995 /* this function must be called with the SELECTOR_LOCK. It returns TRUE when the
996 * active pad changed. */
998 gst_input_selector_set_active_pad (GstInputSelector * self,
999 GstPad * pad, gint64 stop_time, gint64 start_time)
1001 GstSelectorPad *old, *new;
1002 GstPad **active_pad_p;
1004 if (pad == self->active_sinkpad)
1007 old = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
1008 new = GST_SELECTOR_PAD_CAST (pad);
1010 GST_DEBUG_OBJECT (self, "setting active pad to %s:%s",
1011 GST_DEBUG_PAD_NAME (new));
1013 if (!GST_CLOCK_TIME_IS_VALID (stop_time) && old) {
1014 /* no stop time given, get the latest running_time on the active pad to
1015 * close and open the new segment */
1016 stop_time = start_time = gst_selector_pad_get_running_time (old);
1017 GST_DEBUG_OBJECT (self, "using start/stop of %" GST_TIME_FORMAT,
1018 GST_TIME_ARGS (start_time));
1021 if (old && old->active && !self->pending_close && stop_time >= 0) {
1022 /* schedule a last_stop update if one isn't already scheduled, and a
1023 segment has been pushed before. */
1024 memcpy (&self->segment, &old->segment, sizeof (self->segment));
1026 GST_DEBUG_OBJECT (self, "setting stop_time to %" GST_TIME_FORMAT,
1027 GST_TIME_ARGS (stop_time));
1028 gst_segment_set_stop (&self->segment, stop_time);
1029 self->pending_close = TRUE;
1032 if (new && new->active && start_time >= 0) {
1033 GST_DEBUG_OBJECT (self, "setting start_time to %" GST_TIME_FORMAT,
1034 GST_TIME_ARGS (start_time));
1035 /* schedule a new segment push */
1036 gst_segment_set_start (&new->segment, start_time);
1037 new->segment_pending = TRUE;
1040 active_pad_p = &self->active_sinkpad;
1041 gst_object_replace ((GstObject **) active_pad_p, GST_OBJECT_CAST (pad));
1042 GST_DEBUG_OBJECT (self, "New active pad is %" GST_PTR_FORMAT,
1043 self->active_sinkpad);
1049 gst_input_selector_set_property (GObject * object, guint prop_id,
1050 const GValue * value, GParamSpec * pspec)
1052 GstInputSelector *sel = GST_INPUT_SELECTOR (object);
1055 case PROP_ACTIVE_PAD:
1059 pad = g_value_get_object (value);
1061 GST_INPUT_SELECTOR_LOCK (sel);
1062 gst_input_selector_set_active_pad (sel, pad,
1063 GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
1064 GST_INPUT_SELECTOR_UNLOCK (sel);
1067 case PROP_SELECT_ALL:
1068 GST_INPUT_SELECTOR_LOCK (object);
1069 sel->select_all = g_value_get_boolean (value);
1070 GST_INPUT_SELECTOR_UNLOCK (object);
1073 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1079 gst_input_selector_get_property (GObject * object, guint prop_id,
1080 GValue * value, GParamSpec * pspec)
1082 GstInputSelector *sel = GST_INPUT_SELECTOR (object);
1086 GST_INPUT_SELECTOR_LOCK (object);
1087 g_value_set_uint (value, sel->n_pads);
1088 GST_INPUT_SELECTOR_UNLOCK (object);
1090 case PROP_ACTIVE_PAD:
1091 GST_INPUT_SELECTOR_LOCK (object);
1092 g_value_set_object (value, sel->active_sinkpad);
1093 GST_INPUT_SELECTOR_UNLOCK (object);
1095 case PROP_SELECT_ALL:
1096 GST_INPUT_SELECTOR_LOCK (object);
1097 g_value_set_boolean (value, sel->select_all);
1098 GST_INPUT_SELECTOR_UNLOCK (object);
1101 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1107 gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict)
1109 GstInputSelector *sel;
1110 GstPad *otherpad = NULL;
1112 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
1114 GST_INPUT_SELECTOR_LOCK (sel);
1115 if (pad == sel->srcpad)
1116 otherpad = sel->active_sinkpad;
1117 else if (pad == sel->active_sinkpad || !strict)
1118 otherpad = sel->srcpad;
1120 gst_object_ref (otherpad);
1121 GST_INPUT_SELECTOR_UNLOCK (sel);
1123 gst_object_unref (sel);
1129 gst_input_selector_event (GstPad * pad, GstEvent * event)
1131 gboolean res = FALSE;
1134 otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
1137 res = gst_pad_push_event (otherpad, event);
1139 gst_object_unref (otherpad);
1141 gst_event_unref (event);
1145 /* query on the srcpad. We override this function because by default it will
1146 * only forward the query to one random sinkpad */
1148 gst_input_selector_query (GstPad * pad, GstQuery * query)
1150 gboolean res = TRUE;
1151 GstInputSelector *sel;
1154 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
1156 otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
1158 switch (GST_QUERY_TYPE (query)) {
1159 case GST_QUERY_LATENCY:
1162 GstClockTime resmin, resmax;
1169 /* assume FALSE, we become TRUE if one query succeeds */
1172 /* perform the query on all sinkpads and combine the results. We take the
1173 * max of min and the min of max for the result latency. */
1174 GST_INPUT_SELECTOR_LOCK (sel);
1175 for (walk = GST_ELEMENT_CAST (sel)->sinkpads; walk;
1176 walk = g_list_next (walk)) {
1177 GstPad *sinkpad = GST_PAD_CAST (walk->data);
1179 if (gst_pad_peer_query (sinkpad, query)) {
1180 GstClockTime min, max;
1183 /* one query succeeded, we succeed too */
1186 gst_query_parse_latency (query, &live, &min, &max);
1188 GST_DEBUG_OBJECT (sinkpad,
1189 "peer latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
1190 ", live %d", GST_TIME_ARGS (min), GST_TIME_ARGS (max), live);
1197 else if (max < resmax)
1199 if (reslive == FALSE)
1204 GST_INPUT_SELECTOR_UNLOCK (sel);
1206 gst_query_set_latency (query, reslive, resmin, resmax);
1208 GST_DEBUG_OBJECT (sel,
1209 "total latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
1210 ", live %d", GST_TIME_ARGS (resmin), GST_TIME_ARGS (resmax),
1218 res = gst_pad_peer_query (otherpad, query);
1222 gst_object_unref (otherpad);
1223 gst_object_unref (sel);
1229 gst_input_selector_getcaps (GstPad * pad)
1235 parent = gst_object_get_parent (GST_OBJECT (pad));
1237 otherpad = gst_input_selector_get_linked_pad (pad, FALSE);
1240 if (GST_INPUT_SELECTOR (parent)->select_all) {
1241 GST_DEBUG_OBJECT (parent,
1242 "Pad %s:%s not linked, returning merge of caps",
1243 GST_DEBUG_PAD_NAME (pad));
1244 caps = gst_pad_proxy_getcaps (pad);
1246 GST_DEBUG_OBJECT (parent,
1247 "Pad %s:%s not linked, returning ANY", GST_DEBUG_PAD_NAME (pad));
1248 caps = gst_caps_new_any ();
1251 GST_DEBUG_OBJECT (parent,
1252 "Pad %s:%s is linked (to %s:%s), returning peer caps",
1253 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (otherpad));
1254 /* if the peer has caps, use those. If the pad is not linked, this function
1255 * returns NULL and we return ANY */
1256 if (!(caps = gst_pad_peer_get_caps_reffed (otherpad)))
1257 caps = gst_caps_new_any ();
1258 gst_object_unref (otherpad);
1261 gst_object_unref (parent);
1265 /* check if the pad is the active sinkpad */
1266 static inline gboolean
1267 gst_input_selector_is_active_sinkpad (GstInputSelector * sel, GstPad * pad)
1271 GST_INPUT_SELECTOR_LOCK (sel);
1272 res = (pad == sel->active_sinkpad);
1273 GST_INPUT_SELECTOR_UNLOCK (sel);
1278 /* Get or create the active sinkpad, must be called with SELECTOR_LOCK */
1280 gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad)
1282 GstPad *active_sinkpad;
1283 GstSelectorPad *selpad;
1285 selpad = GST_SELECTOR_PAD_CAST (pad);
1287 selpad->active = TRUE;
1288 active_sinkpad = sel->active_sinkpad;
1289 if (active_sinkpad == NULL || sel->select_all) {
1290 /* first pad we get activity on becomes the activated pad by default, if we
1291 * select all, we also remember the last used pad. */
1292 if (sel->active_sinkpad)
1293 gst_object_unref (sel->active_sinkpad);
1294 active_sinkpad = sel->active_sinkpad = gst_object_ref (pad);
1295 GST_DEBUG_OBJECT (sel, "Activating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1298 return active_sinkpad;
1302 gst_input_selector_request_new_pad (GstElement * element,
1303 GstPadTemplate * templ, const gchar * unused)
1305 GstInputSelector *sel;
1307 GstPad *sinkpad = NULL;
1309 g_return_val_if_fail (templ->direction == GST_PAD_SINK, NULL);
1311 sel = GST_INPUT_SELECTOR (element);
1313 GST_INPUT_SELECTOR_LOCK (sel);
1315 GST_LOG_OBJECT (sel, "Creating new pad %d", sel->padcount);
1316 name = g_strdup_printf ("sink%d", sel->padcount++);
1317 sinkpad = g_object_new (GST_TYPE_SELECTOR_PAD,
1318 "name", name, "direction", templ->direction, "template", templ, NULL);
1323 gst_pad_set_event_function (sinkpad,
1324 GST_DEBUG_FUNCPTR (gst_selector_pad_event));
1325 gst_pad_set_getcaps_function (sinkpad,
1326 GST_DEBUG_FUNCPTR (gst_selector_pad_getcaps));
1327 gst_pad_set_acceptcaps_function (sinkpad,
1328 GST_DEBUG_FUNCPTR (gst_selector_pad_acceptcaps));
1329 gst_pad_set_chain_function (sinkpad,
1330 GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
1331 gst_pad_set_iterate_internal_links_function (sinkpad,
1332 GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
1333 gst_pad_set_bufferalloc_function (sinkpad,
1334 GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));
1336 gst_pad_set_active (sinkpad, TRUE);
1337 gst_element_add_pad (GST_ELEMENT (sel), sinkpad);
1338 GST_INPUT_SELECTOR_UNLOCK (sel);
1344 gst_input_selector_release_pad (GstElement * element, GstPad * pad)
1346 GstInputSelector *sel;
1348 sel = GST_INPUT_SELECTOR (element);
1349 GST_LOG_OBJECT (sel, "Releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1351 GST_INPUT_SELECTOR_LOCK (sel);
1352 /* if the pad was the active pad, makes us select a new one */
1353 if (sel->active_sinkpad == pad) {
1354 GST_DEBUG_OBJECT (sel, "Deactivating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1355 gst_object_unref (sel->active_sinkpad);
1356 sel->active_sinkpad = NULL;
1360 gst_pad_set_active (pad, FALSE);
1361 gst_element_remove_pad (GST_ELEMENT (sel), pad);
1362 GST_INPUT_SELECTOR_UNLOCK (sel);
1366 gst_input_selector_reset (GstInputSelector * sel)
1370 GST_INPUT_SELECTOR_LOCK (sel);
1371 /* clear active pad */
1372 if (sel->active_sinkpad) {
1373 gst_object_unref (sel->active_sinkpad);
1374 sel->active_sinkpad = NULL;
1377 gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
1378 sel->pending_close = FALSE;
1379 /* reset each of our sinkpads state */
1380 for (walk = GST_ELEMENT_CAST (sel)->sinkpads; walk; walk = g_list_next (walk)) {
1381 GstSelectorPad *selpad = GST_SELECTOR_PAD_CAST (walk->data);
1383 gst_selector_pad_reset (selpad);
1386 gst_tag_list_free (selpad->tags);
1387 selpad->tags = NULL;
1390 GST_INPUT_SELECTOR_UNLOCK (sel);
1393 static GstStateChangeReturn
1394 gst_input_selector_change_state (GstElement * element,
1395 GstStateChange transition)
1397 GstInputSelector *self = GST_INPUT_SELECTOR (element);
1398 GstStateChangeReturn result;
1400 switch (transition) {
1401 case GST_STATE_CHANGE_READY_TO_PAUSED:
1402 GST_INPUT_SELECTOR_LOCK (self);
1403 self->blocked = FALSE;
1404 self->flushing = FALSE;
1405 GST_INPUT_SELECTOR_UNLOCK (self);
1407 case GST_STATE_CHANGE_PAUSED_TO_READY:
1408 /* first unlock before we call the parent state change function, which
1409 * tries to acquire the stream lock when going to ready. */
1410 GST_INPUT_SELECTOR_LOCK (self);
1411 self->blocked = FALSE;
1412 self->flushing = TRUE;
1413 GST_INPUT_SELECTOR_BROADCAST (self);
1414 GST_INPUT_SELECTOR_UNLOCK (self);
1420 result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1422 switch (transition) {
1423 case GST_STATE_CHANGE_PAUSED_TO_READY:
1424 gst_input_selector_reset (self);
1434 gst_input_selector_block (GstInputSelector * self)
1437 GstSelectorPad *spad;
1439 GST_INPUT_SELECTOR_LOCK (self);
1442 GST_WARNING_OBJECT (self, "switch already blocked");
1444 self->blocked = TRUE;
1445 spad = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
1448 ret = gst_selector_pad_get_running_time (spad);
1450 GST_DEBUG_OBJECT (self, "no active pad while blocking");
1452 GST_INPUT_SELECTOR_UNLOCK (self);
1457 /* stop_time and start_time are running times */
1459 gst_input_selector_switch (GstInputSelector * self, GstPad * pad,
1460 gint64 stop_time, gint64 start_time)
1464 g_return_if_fail (self->blocked == TRUE);
1466 GST_INPUT_SELECTOR_LOCK (self);
1468 gst_input_selector_set_active_pad (self, pad, stop_time, start_time);
1470 self->blocked = FALSE;
1471 GST_INPUT_SELECTOR_BROADCAST (self);
1472 GST_INPUT_SELECTOR_UNLOCK (self);
1475 NOTIFY_MUTEX_LOCK ();
1476 g_object_notify (G_OBJECT (self), "active-pad");
1477 NOTIFY_MUTEX_UNLOCK ();
1482 gst_input_selector_check_eos (GstElement * selector)
1484 GstIterator *it = gst_element_iterate_sink_pads (selector);
1485 GstIteratorResult ires;
1487 gboolean done = FALSE, is_eos = FALSE;
1488 GstSelectorPad *pad;
1491 ires = gst_iterator_next (it, &item);
1493 case GST_ITERATOR_DONE:
1494 GST_INFO_OBJECT (selector, "all sink pads have eos");
1498 case GST_ITERATOR_OK:
1499 pad = GST_SELECTOR_PAD_CAST (item);
1503 gst_object_unref (pad);
1505 case GST_ITERATOR_RESYNC:
1506 gst_iterator_resync (it);
1513 gst_iterator_free (it);