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.
31 * The input pads are from a GstPad subclass and have additional
32 * properties, which users may find useful, namely:
36 * "running-time": Running time of stream on pad (#gint64)
39 * "tags": The currently active tags on the pad (#GstTagList, boxed type)
42 * "active": If the pad is currently active (#gboolean)
45 * "always-ok" : Make an inactive pads return #GST_FLOW_OK instead of
46 * #GST_FLOW_NOT_LINKED
59 #include "gstinputselector.h"
61 GST_DEBUG_CATEGORY_STATIC (input_selector_debug);
62 #define GST_CAT_DEFAULT input_selector_debug
64 #if GLIB_CHECK_VERSION(2, 26, 0)
65 #define NOTIFY_MUTEX_LOCK()
66 #define NOTIFY_MUTEX_UNLOCK()
68 static GStaticRecMutex notify_mutex = G_STATIC_REC_MUTEX_INIT;
69 #define NOTIFY_MUTEX_LOCK() g_static_rec_mutex_lock (¬ify_mutex)
70 #define NOTIFY_MUTEX_UNLOCK() g_static_rec_mutex_unlock (¬ify_mutex)
73 #define GST_INPUT_SELECTOR_GET_LOCK(sel) (((GstInputSelector*)(sel))->lock)
74 #define GST_INPUT_SELECTOR_GET_COND(sel) (((GstInputSelector*)(sel))->cond)
75 #define GST_INPUT_SELECTOR_LOCK(sel) (g_mutex_lock (GST_INPUT_SELECTOR_GET_LOCK(sel)))
76 #define GST_INPUT_SELECTOR_UNLOCK(sel) (g_mutex_unlock (GST_INPUT_SELECTOR_GET_LOCK(sel)))
77 #define GST_INPUT_SELECTOR_WAIT(sel) (g_cond_wait (GST_INPUT_SELECTOR_GET_COND(sel), \
78 GST_INPUT_SELECTOR_GET_LOCK(sel)))
79 #define GST_INPUT_SELECTOR_BROADCAST(sel) (g_cond_broadcast (GST_INPUT_SELECTOR_GET_COND(sel)))
81 static GstStaticPadTemplate gst_input_selector_sink_factory =
82 GST_STATIC_PAD_TEMPLATE ("sink%d",
87 static GstStaticPadTemplate gst_input_selector_src_factory =
88 GST_STATIC_PAD_TEMPLATE ("src",
100 #define DEFAULT_PAD_ALWAYS_OK TRUE
105 PROP_PAD_RUNNING_TIME,
118 static guint gst_input_selector_signals[LAST_SIGNAL] = { 0 };
120 static inline gboolean gst_input_selector_is_active_sinkpad (GstInputSelector *
122 static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel,
124 static GstPad *gst_input_selector_get_linked_pad (GstPad * pad,
127 #define GST_TYPE_SELECTOR_PAD \
128 (gst_selector_pad_get_type())
129 #define GST_SELECTOR_PAD(obj) \
130 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SELECTOR_PAD, GstSelectorPad))
131 #define GST_SELECTOR_PAD_CLASS(klass) \
132 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_SELECTOR_PAD, GstSelectorPadClass))
133 #define GST_IS_SELECTOR_PAD(obj) \
134 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SELECTOR_PAD))
135 #define GST_IS_SELECTOR_PAD_CLASS(klass) \
136 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_SELECTOR_PAD))
137 #define GST_SELECTOR_PAD_CAST(obj) \
138 ((GstSelectorPad *)(obj))
140 typedef struct _GstSelectorPad GstSelectorPad;
141 typedef struct _GstSelectorPadClass GstSelectorPadClass;
143 struct _GstSelectorPad
147 gboolean active; /* when buffer have passed the pad */
148 gboolean pushed; /* when buffer was pushed downstream since activation */
149 gboolean eos; /* when EOS has been received */
150 gboolean eos_sent; /* when EOS was sent downstream */
151 gboolean discont; /* after switching we create a discont */
153 GstSegment segment; /* the current segment on the pad */
154 GstTagList *tags; /* last tags received on the pad */
156 gboolean segment_pending;
159 struct _GstSelectorPadClass
164 static void gst_selector_pad_class_init (GstSelectorPadClass * klass);
165 static void gst_selector_pad_init (GstSelectorPad * pad);
166 static void gst_selector_pad_finalize (GObject * object);
167 static void gst_selector_pad_get_property (GObject * object,
168 guint prop_id, GValue * value, GParamSpec * pspec);
169 static void gst_selector_pad_set_property (GObject * object,
170 guint prop_id, const GValue * value, GParamSpec * pspec);
172 static GstPadClass *selector_pad_parent_class = NULL;
174 static gint64 gst_selector_pad_get_running_time (GstSelectorPad * pad);
175 static void gst_selector_pad_reset (GstSelectorPad * pad);
176 static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
177 static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
178 static gboolean gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps);
179 static GstIterator *gst_selector_pad_iterate_linked_pads (GstPad * pad);
180 static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf);
181 static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad,
182 guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
185 gst_selector_pad_get_type (void)
187 static volatile gsize selector_pad_type = 0;
188 static const GTypeInfo selector_pad_info = {
189 sizeof (GstSelectorPadClass),
192 (GClassInitFunc) gst_selector_pad_class_init,
195 sizeof (GstSelectorPad),
197 (GInstanceInitFunc) gst_selector_pad_init,
200 if (g_once_init_enter (&selector_pad_type)) {
201 GType tmp = g_type_register_static (GST_TYPE_PAD, "GstSelectorPad",
202 &selector_pad_info, 0);
203 g_once_init_leave (&selector_pad_type, tmp);
206 return (GType) selector_pad_type;
210 gst_selector_pad_class_init (GstSelectorPadClass * klass)
212 GObjectClass *gobject_class;
214 gobject_class = (GObjectClass *) klass;
216 selector_pad_parent_class = g_type_class_peek_parent (klass);
218 gobject_class->finalize = gst_selector_pad_finalize;
220 gobject_class->get_property = gst_selector_pad_get_property;
221 gobject_class->set_property = gst_selector_pad_set_property;
223 g_object_class_install_property (gobject_class, PROP_PAD_RUNNING_TIME,
224 g_param_spec_int64 ("running-time", "Running time",
225 "Running time of stream on pad", 0, G_MAXINT64, 0,
226 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
227 g_object_class_install_property (gobject_class, PROP_PAD_TAGS,
228 g_param_spec_boxed ("tags", "Tags",
229 "The currently active tags on the pad", GST_TYPE_TAG_LIST,
230 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
231 g_object_class_install_property (gobject_class, PROP_PAD_ACTIVE,
232 g_param_spec_boolean ("active", "Active",
233 "If the pad is currently active", FALSE,
234 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
235 /* FIXME: better property name? */
236 g_object_class_install_property (gobject_class, PROP_PAD_ALWAYS_OK,
237 g_param_spec_boolean ("always-ok", "Always OK",
238 "Make an inactive pad return OK instead of NOT_LINKED",
239 DEFAULT_PAD_ALWAYS_OK, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243 gst_selector_pad_init (GstSelectorPad * pad)
245 pad->always_ok = DEFAULT_PAD_ALWAYS_OK;
246 gst_selector_pad_reset (pad);
250 gst_selector_pad_finalize (GObject * object)
254 pad = GST_SELECTOR_PAD_CAST (object);
257 gst_tag_list_free (pad->tags);
259 G_OBJECT_CLASS (selector_pad_parent_class)->finalize (object);
263 gst_selector_pad_set_property (GObject * object, guint prop_id,
264 const GValue * value, GParamSpec * pspec)
266 GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
269 case PROP_PAD_ALWAYS_OK:
270 GST_OBJECT_LOCK (object);
271 spad->always_ok = g_value_get_boolean (value);
272 GST_OBJECT_UNLOCK (object);
275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
281 gst_selector_pad_get_property (GObject * object, guint prop_id,
282 GValue * value, GParamSpec * pspec)
284 GstSelectorPad *spad = GST_SELECTOR_PAD_CAST (object);
287 case PROP_PAD_RUNNING_TIME:
288 g_value_set_int64 (value, gst_selector_pad_get_running_time (spad));
291 GST_OBJECT_LOCK (object);
292 g_value_set_boxed (value, spad->tags);
293 GST_OBJECT_UNLOCK (object);
295 case PROP_PAD_ACTIVE:
297 GstInputSelector *sel;
299 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (spad));
300 g_value_set_boolean (value, gst_input_selector_is_active_sinkpad (sel,
301 GST_PAD_CAST (spad)));
302 gst_object_unref (sel);
305 case PROP_PAD_ALWAYS_OK:
306 GST_OBJECT_LOCK (object);
307 g_value_set_boolean (value, spad->always_ok);
308 GST_OBJECT_UNLOCK (object);
311 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
317 gst_selector_pad_get_running_time (GstSelectorPad * pad)
321 GST_OBJECT_LOCK (pad);
323 gint64 last_stop = pad->segment.last_stop;
326 ret = gst_segment_to_running_time (&pad->segment, GST_FORMAT_TIME,
329 GST_OBJECT_UNLOCK (pad);
331 GST_DEBUG_OBJECT (pad, "running time: %" GST_TIME_FORMAT,
332 GST_TIME_ARGS (ret));
338 gst_selector_pad_reset (GstSelectorPad * pad)
340 GST_OBJECT_LOCK (pad);
344 pad->eos_sent = FALSE;
345 pad->segment_pending = FALSE;
346 pad->discont = FALSE;
347 gst_segment_init (&pad->segment, GST_FORMAT_UNDEFINED);
348 GST_OBJECT_UNLOCK (pad);
351 /* strictly get the linked pad from the sinkpad. If the pad is active we return
352 * the srcpad else we return NULL */
354 gst_selector_pad_iterate_linked_pads (GstPad * pad)
356 GstInputSelector *sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
360 otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
361 it = gst_iterator_new_single (GST_TYPE_PAD, otherpad,
362 (GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
365 gst_object_unref (otherpad);
366 gst_object_unref (sel);
372 gst_selector_pad_event (GstPad * pad, GstEvent * event)
376 GstInputSelector *sel;
377 GstSelectorPad *selpad;
378 GstPad *prev_active_sinkpad;
379 GstPad *active_sinkpad;
381 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
382 selpad = GST_SELECTOR_PAD_CAST (pad);
384 GST_INPUT_SELECTOR_LOCK (sel);
385 prev_active_sinkpad = sel->active_sinkpad;
386 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
388 /* only forward if we are dealing with the active sinkpad */
389 forward = (pad == active_sinkpad);
390 GST_INPUT_SELECTOR_UNLOCK (sel);
392 if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
393 NOTIFY_MUTEX_LOCK ();
394 g_object_notify (G_OBJECT (sel), "active-pad");
395 NOTIFY_MUTEX_UNLOCK ();
398 switch (GST_EVENT_TYPE (event)) {
399 case GST_EVENT_FLUSH_START:
400 /* FIXME, flush out the waiter */
402 case GST_EVENT_FLUSH_STOP:
403 GST_INPUT_SELECTOR_LOCK (sel);
404 gst_selector_pad_reset (selpad);
405 sel->pending_close = FALSE;
406 GST_INPUT_SELECTOR_UNLOCK (sel);
408 case GST_EVENT_NEWSEGMENT:
413 gint64 start, stop, time;
415 gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
416 &start, &stop, &time);
418 GST_DEBUG_OBJECT (pad,
419 "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
421 "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
422 G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
424 GST_INPUT_SELECTOR_LOCK (sel);
425 GST_OBJECT_LOCK (selpad);
426 gst_segment_set_newsegment_full (&selpad->segment, update,
427 rate, arate, format, start, stop, time);
428 GST_OBJECT_UNLOCK (selpad);
430 /* If we aren't forwarding the event because the pad is not the
431 * active_sinkpad, then set the flag on the pad
432 * that says a segment needs sending if/when that pad is activated.
433 * For all other cases, we send the event immediately, which makes
434 * sparse streams and other segment updates work correctly downstream.
437 selpad->segment_pending = TRUE;
439 GST_INPUT_SELECTOR_UNLOCK (sel);
444 GstTagList *tags, *oldtags, *newtags;
446 gst_event_parse_tag (event, &tags);
448 GST_OBJECT_LOCK (selpad);
449 oldtags = selpad->tags;
451 newtags = gst_tag_list_merge (oldtags, tags, GST_TAG_MERGE_REPLACE);
452 selpad->tags = newtags;
454 gst_tag_list_free (oldtags);
455 GST_DEBUG_OBJECT (pad, "received tags %" GST_PTR_FORMAT, newtags);
456 GST_OBJECT_UNLOCK (selpad);
458 g_object_notify (G_OBJECT (selpad), "tags");
465 selpad->eos_sent = TRUE;
469 /* If the active sinkpad is in EOS state but EOS
470 * was not sent downstream this means that the pad
471 * got EOS before it was set as active pad and that
472 * the previously active pad got EOS after it was
475 GST_INPUT_SELECTOR_LOCK (sel);
476 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
477 tmp = GST_SELECTOR_PAD (active_sinkpad);
478 forward = (tmp->eos && !tmp->eos_sent);
479 tmp->eos_sent = TRUE;
480 GST_INPUT_SELECTOR_UNLOCK (sel);
482 GST_DEBUG_OBJECT (pad, "received EOS");
488 GST_DEBUG_OBJECT (pad, "forwarding event");
489 res = gst_pad_push_event (sel->srcpad, event);
491 gst_event_unref (event);
493 gst_object_unref (sel);
499 gst_selector_pad_getcaps (GstPad * pad)
501 GstInputSelector *sel;
504 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
506 GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer");
507 caps = gst_pad_peer_get_caps_reffed (sel->srcpad);
509 caps = gst_caps_new_any ();
511 gst_object_unref (sel);
517 gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps)
519 GstInputSelector *sel;
522 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
524 GST_DEBUG_OBJECT (sel, "Checking acceptcaps of srcpad peer");
525 res = gst_pad_peer_accept_caps (sel->srcpad, caps);
526 gst_object_unref (sel);
532 gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset,
533 guint size, GstCaps * caps, GstBuffer ** buf)
535 GstInputSelector *sel;
536 GstFlowReturn result;
537 GstPad *active_sinkpad;
538 GstPad *prev_active_sinkpad;
539 GstSelectorPad *selpad;
541 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
542 selpad = GST_SELECTOR_PAD_CAST (pad);
544 GST_LOG_OBJECT (pad, "received alloc");
546 GST_INPUT_SELECTOR_LOCK (sel);
547 prev_active_sinkpad = sel->active_sinkpad;
548 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
550 if (pad != active_sinkpad)
553 GST_INPUT_SELECTOR_UNLOCK (sel);
555 if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
556 NOTIFY_MUTEX_LOCK ();
557 g_object_notify (G_OBJECT (sel), "active-pad");
558 NOTIFY_MUTEX_UNLOCK ();
561 result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf);
564 gst_object_unref (sel);
571 gboolean active_pad_pushed = GST_SELECTOR_PAD_CAST (active_sinkpad)->pushed;
573 GST_INPUT_SELECTOR_UNLOCK (sel);
575 /* unselected pad, perform fallback alloc or return unlinked when
577 GST_OBJECT_LOCK (selpad);
578 if (selpad->always_ok || !active_pad_pushed) {
579 GST_DEBUG_OBJECT (pad, "Not selected, performing fallback allocation");
581 result = GST_FLOW_OK;
583 GST_DEBUG_OBJECT (pad, "Not selected, return NOT_LINKED");
584 result = GST_FLOW_NOT_LINKED;
586 GST_OBJECT_UNLOCK (selpad);
592 /* must be called with the SELECTOR_LOCK, will block while the pad is blocked
593 * or return TRUE when flushing */
595 gst_input_selector_wait (GstInputSelector * self, GstPad * pad)
597 while (self->blocked && !self->flushing) {
598 /* we can be unlocked here when we are shutting down (flushing) or when we
600 GST_INPUT_SELECTOR_WAIT (self);
602 return self->flushing;
606 gst_selector_pad_chain (GstPad * pad, GstBuffer * buf)
608 GstInputSelector *sel;
610 GstPad *active_sinkpad;
611 GstPad *prev_active_sinkpad;
612 GstSelectorPad *selpad;
613 GstClockTime start_time;
615 GstEvent *close_event = NULL, *start_event = NULL;
618 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
619 selpad = GST_SELECTOR_PAD_CAST (pad);
620 seg = &selpad->segment;
622 GST_INPUT_SELECTOR_LOCK (sel);
623 /* wait or check for flushing */
624 if (gst_input_selector_wait (sel, pad))
627 GST_LOG_OBJECT (pad, "getting active pad");
629 prev_active_sinkpad = sel->active_sinkpad;
630 active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
632 /* update the segment on the srcpad */
633 start_time = GST_BUFFER_TIMESTAMP (buf);
634 if (GST_CLOCK_TIME_IS_VALID (start_time)) {
635 GST_LOG_OBJECT (pad, "received start time %" GST_TIME_FORMAT,
636 GST_TIME_ARGS (start_time));
637 if (GST_BUFFER_DURATION_IS_VALID (buf))
638 GST_LOG_OBJECT (pad, "received end time %" GST_TIME_FORMAT,
639 GST_TIME_ARGS (start_time + GST_BUFFER_DURATION (buf)));
641 GST_OBJECT_LOCK (pad);
642 gst_segment_set_last_stop (seg, seg->format, start_time);
643 GST_OBJECT_UNLOCK (pad);
646 /* Ignore buffers from pads except the selected one */
647 if (pad != active_sinkpad)
650 if (G_UNLIKELY (sel->pending_close)) {
651 GstSegment *cseg = &sel->segment;
653 GST_DEBUG_OBJECT (sel,
654 "pushing close NEWSEGMENT update %d, rate %lf, applied rate %lf, "
656 "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
657 G_GINT64_FORMAT, TRUE, cseg->rate, cseg->applied_rate, cseg->format,
658 cseg->start, cseg->stop, cseg->time);
660 /* create update segment */
661 close_event = gst_event_new_new_segment_full (TRUE, cseg->rate,
662 cseg->applied_rate, cseg->format, cseg->start, cseg->stop, cseg->time);
664 sel->pending_close = FALSE;
666 /* if we have a pending segment, push it out now */
667 if (G_UNLIKELY (selpad->segment_pending)) {
668 GST_DEBUG_OBJECT (pad,
669 "pushing pending NEWSEGMENT update %d, rate %lf, applied rate %lf, "
671 "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
672 G_GINT64_FORMAT, FALSE, seg->rate, seg->applied_rate, seg->format,
673 seg->start, seg->stop, seg->time);
675 start_event = gst_event_new_new_segment_full (FALSE, seg->rate,
676 seg->applied_rate, seg->format, seg->start, seg->stop, seg->time);
678 selpad->segment_pending = FALSE;
680 GST_INPUT_SELECTOR_UNLOCK (sel);
682 if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
683 NOTIFY_MUTEX_LOCK ();
684 g_object_notify (G_OBJECT (sel), "active-pad");
685 NOTIFY_MUTEX_UNLOCK ();
689 gst_pad_push_event (sel->srcpad, close_event);
692 gst_pad_push_event (sel->srcpad, start_event);
694 if (selpad->discont) {
695 buf = gst_buffer_make_metadata_writable (buf);
697 GST_DEBUG_OBJECT (pad, "Marking discont buffer %p", buf);
698 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
699 selpad->discont = FALSE;
703 GST_LOG_OBJECT (pad, "Forwarding buffer %p", buf);
705 if ((caps = GST_BUFFER_CAPS (buf))) {
706 if (GST_PAD_CAPS (sel->srcpad) != caps)
707 gst_pad_set_caps (sel->srcpad, caps);
710 res = gst_pad_push (sel->srcpad, buf);
711 selpad->pushed = TRUE;
714 gst_object_unref (sel);
717 /* dropped buffers */
720 gboolean active_pad_pushed = GST_SELECTOR_PAD_CAST (active_sinkpad)->pushed;
722 GST_DEBUG_OBJECT (pad, "Pad not active, discard buffer %p", buf);
723 /* when we drop a buffer, we're creating a discont on this pad */
724 selpad->discont = TRUE;
725 GST_INPUT_SELECTOR_UNLOCK (sel);
726 gst_buffer_unref (buf);
728 /* figure out what to return upstream */
729 GST_OBJECT_LOCK (selpad);
730 if (selpad->always_ok || !active_pad_pushed)
733 res = GST_FLOW_NOT_LINKED;
734 GST_OBJECT_UNLOCK (selpad);
740 GST_DEBUG_OBJECT (pad, "We are flushing, discard buffer %p", buf);
741 GST_INPUT_SELECTOR_UNLOCK (sel);
742 gst_buffer_unref (buf);
743 res = GST_FLOW_WRONG_STATE;
748 static void gst_input_selector_dispose (GObject * object);
750 static void gst_input_selector_set_property (GObject * object,
751 guint prop_id, const GValue * value, GParamSpec * pspec);
752 static void gst_input_selector_get_property (GObject * object,
753 guint prop_id, GValue * value, GParamSpec * pspec);
755 static GstPad *gst_input_selector_request_new_pad (GstElement * element,
756 GstPadTemplate * templ, const gchar * unused);
757 static void gst_input_selector_release_pad (GstElement * element, GstPad * pad);
759 static GstStateChangeReturn gst_input_selector_change_state (GstElement *
760 element, GstStateChange transition);
762 static GstCaps *gst_input_selector_getcaps (GstPad * pad);
763 static gboolean gst_input_selector_event (GstPad * pad, GstEvent * event);
764 static gboolean gst_input_selector_query (GstPad * pad, GstQuery * query);
765 static gint64 gst_input_selector_block (GstInputSelector * self);
766 static void gst_input_selector_switch (GstInputSelector * self,
767 GstPad * pad, gint64 stop_time, gint64 start_time);
769 /* FIXME: create these marshallers using glib-genmarshal */
770 #define g_marshal_value_peek_object(v) (v)->data[0].v_pointer
771 #define g_marshal_value_peek_int64(v) (v)->data[0].v_int64
774 gst_input_selector_marshal_INT64__VOID (GClosure * closure,
775 GValue * return_value G_GNUC_UNUSED,
776 guint n_param_values,
777 const GValue * param_values,
778 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
780 typedef gint64 (*GMarshalFunc_INT64__VOID) (gpointer data1, gpointer data2);
781 register GMarshalFunc_INT64__VOID callback;
782 register GCClosure *cc = (GCClosure *) closure;
783 register gpointer data1, data2;
786 g_return_if_fail (return_value != NULL);
787 g_return_if_fail (n_param_values == 1);
789 if (G_CCLOSURE_SWAP_DATA (closure)) {
790 data1 = closure->data;
791 data2 = g_value_peek_pointer (param_values + 0);
793 data1 = g_value_peek_pointer (param_values + 0);
794 data2 = closure->data;
797 (GMarshalFunc_INT64__VOID) (marshal_data ? marshal_data : cc->callback);
799 v_return = callback (data1, data2);
801 g_value_set_int64 (return_value, v_return);
805 gst_input_selector_marshal_VOID__OBJECT_INT64_INT64 (GClosure * closure,
806 GValue * return_value G_GNUC_UNUSED,
807 guint n_param_values,
808 const GValue * param_values,
809 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
811 typedef void (*GMarshalFunc_VOID__OBJECT_INT64_INT64) (gpointer data1,
812 gpointer arg_1, gint64 arg_2, gint64 arg_3, gpointer data2);
813 register GMarshalFunc_VOID__OBJECT_INT64_INT64 callback;
814 register GCClosure *cc = (GCClosure *) closure;
815 register gpointer data1, data2;
817 g_return_if_fail (n_param_values == 4);
819 if (G_CCLOSURE_SWAP_DATA (closure)) {
820 data1 = closure->data;
821 data2 = g_value_peek_pointer (param_values + 0);
823 data1 = g_value_peek_pointer (param_values + 0);
824 data2 = closure->data;
827 (GMarshalFunc_VOID__OBJECT_INT64_INT64) (marshal_data ? marshal_data :
831 g_marshal_value_peek_object (param_values + 1),
832 g_marshal_value_peek_int64 (param_values + 2),
833 g_marshal_value_peek_int64 (param_values + 3), data2);
836 #define _do_init(bla) \
837 GST_DEBUG_CATEGORY_INIT (input_selector_debug, \
838 "input-selector", 0, "An input stream selector element");
840 GST_BOILERPLATE_FULL (GstInputSelector, gst_input_selector, GstElement,
841 GST_TYPE_ELEMENT, _do_init);
844 gst_input_selector_base_init (gpointer g_class)
846 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
848 gst_element_class_set_details_simple (element_class, "Input selector",
849 "Generic", "N-to-1 input stream selector",
850 "Julien Moutte <julien@moutte.net>, "
851 "Jan Schmidt <thaytan@mad.scientist.com>, "
852 "Wim Taymans <wim.taymans@gmail.com>");
853 gst_element_class_add_pad_template (element_class,
854 gst_static_pad_template_get (&gst_input_selector_sink_factory));
855 gst_element_class_add_pad_template (element_class,
856 gst_static_pad_template_get (&gst_input_selector_src_factory));
860 gst_input_selector_class_init (GstInputSelectorClass * klass)
862 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
863 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
865 gobject_class->dispose = gst_input_selector_dispose;
867 gobject_class->set_property = gst_input_selector_set_property;
868 gobject_class->get_property = gst_input_selector_get_property;
870 g_object_class_install_property (gobject_class, PROP_N_PADS,
871 g_param_spec_uint ("n-pads", "Number of Pads",
872 "The number of sink pads", 0, G_MAXUINT, 0,
873 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
875 g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
876 g_param_spec_object ("active-pad", "Active pad",
877 "The currently active sink pad", GST_TYPE_PAD,
878 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
881 * GstInputSelector::block:
882 * @inputselector: the #GstInputSelector
884 * Block all sink pads in preparation for a switch. Returns the stop time of
885 * the current switch segment, as a running time, or 0 if there is no current
886 * active pad or the current active pad never received data.
888 gst_input_selector_signals[SIGNAL_BLOCK] =
889 g_signal_new ("block", G_TYPE_FROM_CLASS (klass),
890 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
891 G_STRUCT_OFFSET (GstInputSelectorClass, block), NULL, NULL,
892 gst_input_selector_marshal_INT64__VOID, G_TYPE_INT64, 0);
894 * GstInputSelector::switch:
895 * @inputselector: the #GstInputSelector
896 * @pad: the pad to switch to
897 * @stop_time: running time at which to close the previous segment, or -1
898 * to use the running time of the previously active sink pad
899 * @start_time: running time at which to start the new segment, or -1 to
900 * use the running time of the newly active sink pad
902 * Switch to a new feed. The segment opened by the previously active pad, if
903 * any, will be closed, and a new segment opened before data flows again.
905 * This signal must be emitted when the element has been blocked via the <link
906 * linkend="GstInputSelector-block">block</link> signal.
908 * If you have a stream with only one switch element, such as an audio-only
909 * stream, a stream switch should be performed by first emitting the block
910 * signal, and then emitting the switch signal with -1 for the stop and start
913 * The intention of the @stop_time and @start_time arguments is to allow
914 * multiple switch elements to switch and maintain stream synchronization.
915 * When switching a stream with multiple feeds, you will need as many switch
916 * elements as you have feeds. For example, a feed with audio and video will
917 * have one switch element between the audio feeds and one for video.
919 * A switch over multiple switch elements should be performed as follows:
920 * First, emit the <link linkend="GstInputSelector-block">block</link>
921 * signal, collecting the returned values. The maximum running time returned
922 * by block should then be used as the time at which to close the previous
925 * Then, query the running times of the new audio and video pads that you will
926 * switch to. Naturally, these pads are on separate switch elements. Take the
927 * minimum running time for those streams and use it for the time at which to
928 * open the new segment.
930 * If @pad is the same as the current active pad, the element will cancel any
931 * previous block without adjusting segments.
934 * the signal changed from accepting the pad name to the pad object.
939 gst_input_selector_signals[SIGNAL_SWITCH] =
940 g_signal_new ("switch", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
941 G_STRUCT_OFFSET (GstInputSelectorClass, switch_),
942 NULL, NULL, gst_input_selector_marshal_VOID__OBJECT_INT64_INT64,
943 G_TYPE_NONE, 3, GST_TYPE_PAD, G_TYPE_INT64, G_TYPE_INT64);
945 gstelement_class->request_new_pad = gst_input_selector_request_new_pad;
946 gstelement_class->release_pad = gst_input_selector_release_pad;
947 gstelement_class->change_state = gst_input_selector_change_state;
949 klass->block = GST_DEBUG_FUNCPTR (gst_input_selector_block);
950 /* note the underscore because switch is a keyword otherwise */
951 klass->switch_ = GST_DEBUG_FUNCPTR (gst_input_selector_switch);
955 gst_input_selector_init (GstInputSelector * sel,
956 GstInputSelectorClass * g_class)
958 sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
959 gst_pad_set_iterate_internal_links_function (sel->srcpad,
960 GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
961 gst_pad_set_getcaps_function (sel->srcpad,
962 GST_DEBUG_FUNCPTR (gst_input_selector_getcaps));
963 gst_pad_set_query_function (sel->srcpad,
964 GST_DEBUG_FUNCPTR (gst_input_selector_query));
965 gst_pad_set_event_function (sel->srcpad,
966 GST_DEBUG_FUNCPTR (gst_input_selector_event));
967 gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad);
968 /* sinkpad management */
969 sel->active_sinkpad = NULL;
971 gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
973 sel->lock = g_mutex_new ();
974 sel->cond = g_cond_new ();
975 sel->blocked = FALSE;
979 gst_input_selector_dispose (GObject * object)
981 GstInputSelector *sel = GST_INPUT_SELECTOR (object);
983 if (sel->active_sinkpad) {
984 gst_object_unref (sel->active_sinkpad);
985 sel->active_sinkpad = NULL;
988 g_mutex_free (sel->lock);
992 g_cond_free (sel->cond);
996 G_OBJECT_CLASS (parent_class)->dispose (object);
999 /* Solve the following equation for B.timestamp, and set that as the segment
1001 * B.running_time = (B.timestamp - NS.start) / NS.abs_rate + NS.accum
1004 gst_segment_get_timestamp (GstSegment * segment, gint64 running_time)
1006 if (running_time <= segment->accum)
1007 return segment->start;
1009 return (running_time - segment->accum) * segment->abs_rate + segment->start;
1013 gst_segment_set_stop (GstSegment * segment, gint64 running_time)
1015 segment->stop = gst_segment_get_timestamp (segment, running_time);
1016 segment->last_stop = -1;
1020 gst_segment_set_start (GstSegment * segment, gint64 running_time)
1022 gint64 new_start, duration;
1024 new_start = gst_segment_get_timestamp (segment, running_time);
1026 /* this is the duration we skipped */
1027 duration = new_start - segment->start;
1028 /* add the duration to the accumulated segment time */
1029 segment->accum += duration;
1030 /* move position in the segment */
1031 segment->time += duration;
1032 segment->start += duration;
1035 /* this function must be called with the SELECTOR_LOCK. It returns TRUE when the
1036 * active pad changed. */
1038 gst_input_selector_set_active_pad (GstInputSelector * self,
1039 GstPad * pad, gint64 stop_time, gint64 start_time)
1041 GstSelectorPad *old, *new;
1042 GstPad **active_pad_p;
1044 if (pad == self->active_sinkpad)
1047 old = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
1048 new = GST_SELECTOR_PAD_CAST (pad);
1050 GST_DEBUG_OBJECT (self, "setting active pad to %s:%s",
1051 GST_DEBUG_PAD_NAME (new));
1053 if (!GST_CLOCK_TIME_IS_VALID (stop_time) && old) {
1054 /* no stop time given, get the latest running_time on the active pad to
1055 * close and open the new segment */
1056 stop_time = start_time = gst_selector_pad_get_running_time (old);
1057 GST_DEBUG_OBJECT (self, "using start/stop of %" GST_TIME_FORMAT,
1058 GST_TIME_ARGS (start_time));
1061 if (old && old->active && !self->pending_close && stop_time >= 0) {
1062 /* schedule a last_stop update if one isn't already scheduled, and a
1063 segment has been pushed before. */
1064 memcpy (&self->segment, &old->segment, sizeof (self->segment));
1066 GST_DEBUG_OBJECT (self, "setting stop_time to %" GST_TIME_FORMAT,
1067 GST_TIME_ARGS (stop_time));
1068 gst_segment_set_stop (&self->segment, stop_time);
1069 self->pending_close = TRUE;
1072 old->pushed = FALSE;
1074 if (new && new->active && start_time >= 0) {
1075 GST_DEBUG_OBJECT (self, "setting start_time to %" GST_TIME_FORMAT,
1076 GST_TIME_ARGS (start_time));
1077 /* schedule a new segment push */
1078 gst_segment_set_start (&new->segment, start_time);
1079 new->segment_pending = TRUE;
1082 new->pushed = FALSE;
1084 active_pad_p = &self->active_sinkpad;
1085 gst_object_replace ((GstObject **) active_pad_p, GST_OBJECT_CAST (pad));
1086 GST_DEBUG_OBJECT (self, "New active pad is %" GST_PTR_FORMAT,
1087 self->active_sinkpad);
1093 gst_input_selector_set_property (GObject * object, guint prop_id,
1094 const GValue * value, GParamSpec * pspec)
1096 GstInputSelector *sel = GST_INPUT_SELECTOR (object);
1099 case PROP_ACTIVE_PAD:
1103 pad = g_value_get_object (value);
1105 GST_INPUT_SELECTOR_LOCK (sel);
1106 gst_input_selector_set_active_pad (sel, pad,
1107 GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE);
1108 GST_INPUT_SELECTOR_UNLOCK (sel);
1112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1118 gst_input_selector_get_property (GObject * object, guint prop_id,
1119 GValue * value, GParamSpec * pspec)
1121 GstInputSelector *sel = GST_INPUT_SELECTOR (object);
1125 GST_INPUT_SELECTOR_LOCK (object);
1126 g_value_set_uint (value, sel->n_pads);
1127 GST_INPUT_SELECTOR_UNLOCK (object);
1129 case PROP_ACTIVE_PAD:
1130 GST_INPUT_SELECTOR_LOCK (object);
1131 g_value_set_object (value, sel->active_sinkpad);
1132 GST_INPUT_SELECTOR_UNLOCK (object);
1135 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1141 gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict)
1143 GstInputSelector *sel;
1144 GstPad *otherpad = NULL;
1146 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
1148 GST_INPUT_SELECTOR_LOCK (sel);
1149 if (pad == sel->srcpad)
1150 otherpad = sel->active_sinkpad;
1151 else if (pad == sel->active_sinkpad || !strict)
1152 otherpad = sel->srcpad;
1154 gst_object_ref (otherpad);
1155 GST_INPUT_SELECTOR_UNLOCK (sel);
1157 gst_object_unref (sel);
1163 gst_input_selector_event (GstPad * pad, GstEvent * event)
1165 gboolean res = FALSE;
1168 otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
1171 res = gst_pad_push_event (otherpad, event);
1173 gst_object_unref (otherpad);
1175 gst_event_unref (event);
1179 /* query on the srcpad. We override this function because by default it will
1180 * only forward the query to one random sinkpad */
1182 gst_input_selector_query (GstPad * pad, GstQuery * query)
1184 gboolean res = TRUE;
1185 GstInputSelector *sel;
1188 sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
1190 otherpad = gst_input_selector_get_linked_pad (pad, TRUE);
1192 switch (GST_QUERY_TYPE (query)) {
1193 case GST_QUERY_LATENCY:
1196 GstClockTime resmin, resmax;
1203 /* assume FALSE, we become TRUE if one query succeeds */
1206 /* perform the query on all sinkpads and combine the results. We take the
1207 * max of min and the min of max for the result latency. */
1208 GST_INPUT_SELECTOR_LOCK (sel);
1209 for (walk = GST_ELEMENT_CAST (sel)->sinkpads; walk;
1210 walk = g_list_next (walk)) {
1211 GstPad *sinkpad = GST_PAD_CAST (walk->data);
1213 if (gst_pad_peer_query (sinkpad, query)) {
1214 GstClockTime min, max;
1217 /* one query succeeded, we succeed too */
1220 gst_query_parse_latency (query, &live, &min, &max);
1222 GST_DEBUG_OBJECT (sinkpad,
1223 "peer latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
1224 ", live %d", GST_TIME_ARGS (min), GST_TIME_ARGS (max), live);
1231 else if (max < resmax)
1233 if (reslive == FALSE)
1238 GST_INPUT_SELECTOR_UNLOCK (sel);
1240 gst_query_set_latency (query, reslive, resmin, resmax);
1242 GST_DEBUG_OBJECT (sel,
1243 "total latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
1244 ", live %d", GST_TIME_ARGS (resmin), GST_TIME_ARGS (resmax),
1252 res = gst_pad_peer_query (otherpad, query);
1256 gst_object_unref (otherpad);
1257 gst_object_unref (sel);
1263 gst_input_selector_getcaps (GstPad * pad)
1269 parent = gst_object_get_parent (GST_OBJECT (pad));
1271 otherpad = gst_input_selector_get_linked_pad (pad, FALSE);
1274 GST_DEBUG_OBJECT (pad, "Pad not linked, returning ANY");
1275 caps = gst_caps_new_any ();
1277 GST_DEBUG_OBJECT (pad, "Pad is linked (to %s:%s), returning peer caps",
1278 GST_DEBUG_PAD_NAME (otherpad));
1279 /* if the peer has caps, use those. If the pad is not linked, this function
1280 * returns NULL and we return ANY */
1281 if (!(caps = gst_pad_peer_get_caps_reffed (otherpad)))
1282 caps = gst_caps_new_any ();
1283 gst_object_unref (otherpad);
1286 gst_object_unref (parent);
1290 /* check if the pad is the active sinkpad */
1291 static inline gboolean
1292 gst_input_selector_is_active_sinkpad (GstInputSelector * sel, GstPad * pad)
1296 GST_INPUT_SELECTOR_LOCK (sel);
1297 res = (pad == sel->active_sinkpad);
1298 GST_INPUT_SELECTOR_UNLOCK (sel);
1303 /* Get or create the active sinkpad, must be called with SELECTOR_LOCK */
1305 gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad)
1307 GstPad *active_sinkpad;
1308 GstSelectorPad *selpad;
1310 selpad = GST_SELECTOR_PAD_CAST (pad);
1312 selpad->active = TRUE;
1313 active_sinkpad = sel->active_sinkpad;
1314 if (active_sinkpad == NULL) {
1315 /* first pad we get activity on becomes the activated pad by default */
1316 if (sel->active_sinkpad)
1317 gst_object_unref (sel->active_sinkpad);
1318 active_sinkpad = sel->active_sinkpad = gst_object_ref (pad);
1319 GST_DEBUG_OBJECT (sel, "Activating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1322 return active_sinkpad;
1326 gst_input_selector_request_new_pad (GstElement * element,
1327 GstPadTemplate * templ, const gchar * unused)
1329 GstInputSelector *sel;
1331 GstPad *sinkpad = NULL;
1333 g_return_val_if_fail (templ->direction == GST_PAD_SINK, NULL);
1335 sel = GST_INPUT_SELECTOR (element);
1337 GST_INPUT_SELECTOR_LOCK (sel);
1339 GST_LOG_OBJECT (sel, "Creating new pad %d", sel->padcount);
1340 name = g_strdup_printf ("sink%d", sel->padcount++);
1341 sinkpad = g_object_new (GST_TYPE_SELECTOR_PAD,
1342 "name", name, "direction", templ->direction, "template", templ, NULL);
1347 gst_pad_set_event_function (sinkpad,
1348 GST_DEBUG_FUNCPTR (gst_selector_pad_event));
1349 gst_pad_set_getcaps_function (sinkpad,
1350 GST_DEBUG_FUNCPTR (gst_selector_pad_getcaps));
1351 gst_pad_set_acceptcaps_function (sinkpad,
1352 GST_DEBUG_FUNCPTR (gst_selector_pad_acceptcaps));
1353 gst_pad_set_chain_function (sinkpad,
1354 GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
1355 gst_pad_set_iterate_internal_links_function (sinkpad,
1356 GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
1357 gst_pad_set_bufferalloc_function (sinkpad,
1358 GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));
1360 gst_pad_set_active (sinkpad, TRUE);
1361 gst_element_add_pad (GST_ELEMENT (sel), sinkpad);
1362 GST_INPUT_SELECTOR_UNLOCK (sel);
1368 gst_input_selector_release_pad (GstElement * element, GstPad * pad)
1370 GstInputSelector *sel;
1372 sel = GST_INPUT_SELECTOR (element);
1373 GST_LOG_OBJECT (sel, "Releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1375 GST_INPUT_SELECTOR_LOCK (sel);
1376 /* if the pad was the active pad, makes us select a new one */
1377 if (sel->active_sinkpad == pad) {
1378 GST_DEBUG_OBJECT (sel, "Deactivating pad %s:%s", GST_DEBUG_PAD_NAME (pad));
1379 gst_object_unref (sel->active_sinkpad);
1380 sel->active_sinkpad = NULL;
1384 gst_pad_set_active (pad, FALSE);
1385 gst_element_remove_pad (GST_ELEMENT (sel), pad);
1386 GST_INPUT_SELECTOR_UNLOCK (sel);
1390 gst_input_selector_reset (GstInputSelector * sel)
1394 GST_INPUT_SELECTOR_LOCK (sel);
1395 /* clear active pad */
1396 if (sel->active_sinkpad) {
1397 gst_object_unref (sel->active_sinkpad);
1398 sel->active_sinkpad = NULL;
1401 gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED);
1402 sel->pending_close = FALSE;
1403 /* reset each of our sinkpads state */
1404 for (walk = GST_ELEMENT_CAST (sel)->sinkpads; walk; walk = g_list_next (walk)) {
1405 GstSelectorPad *selpad = GST_SELECTOR_PAD_CAST (walk->data);
1407 gst_selector_pad_reset (selpad);
1410 gst_tag_list_free (selpad->tags);
1411 selpad->tags = NULL;
1414 GST_INPUT_SELECTOR_UNLOCK (sel);
1417 static GstStateChangeReturn
1418 gst_input_selector_change_state (GstElement * element,
1419 GstStateChange transition)
1421 GstInputSelector *self = GST_INPUT_SELECTOR (element);
1422 GstStateChangeReturn result;
1424 switch (transition) {
1425 case GST_STATE_CHANGE_READY_TO_PAUSED:
1426 GST_INPUT_SELECTOR_LOCK (self);
1427 self->blocked = FALSE;
1428 self->flushing = FALSE;
1429 GST_INPUT_SELECTOR_UNLOCK (self);
1431 case GST_STATE_CHANGE_PAUSED_TO_READY:
1432 /* first unlock before we call the parent state change function, which
1433 * tries to acquire the stream lock when going to ready. */
1434 GST_INPUT_SELECTOR_LOCK (self);
1435 self->blocked = FALSE;
1436 self->flushing = TRUE;
1437 GST_INPUT_SELECTOR_BROADCAST (self);
1438 GST_INPUT_SELECTOR_UNLOCK (self);
1444 result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1446 switch (transition) {
1447 case GST_STATE_CHANGE_PAUSED_TO_READY:
1448 gst_input_selector_reset (self);
1458 gst_input_selector_block (GstInputSelector * self)
1461 GstSelectorPad *spad;
1463 GST_INPUT_SELECTOR_LOCK (self);
1466 GST_WARNING_OBJECT (self, "switch already blocked");
1468 self->blocked = TRUE;
1469 spad = GST_SELECTOR_PAD_CAST (self->active_sinkpad);
1472 ret = gst_selector_pad_get_running_time (spad);
1474 GST_DEBUG_OBJECT (self, "no active pad while blocking");
1476 GST_INPUT_SELECTOR_UNLOCK (self);
1481 /* stop_time and start_time are running times */
1483 gst_input_selector_switch (GstInputSelector * self, GstPad * pad,
1484 gint64 stop_time, gint64 start_time)
1488 g_return_if_fail (self->blocked == TRUE);
1490 GST_INPUT_SELECTOR_LOCK (self);
1492 gst_input_selector_set_active_pad (self, pad, stop_time, start_time);
1494 self->blocked = FALSE;
1495 GST_INPUT_SELECTOR_BROADCAST (self);
1496 GST_INPUT_SELECTOR_UNLOCK (self);
1499 NOTIFY_MUTEX_LOCK ();
1500 g_object_notify (G_OBJECT (self), "active-pad");
1501 NOTIFY_MUTEX_UNLOCK ();