2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000,2001,2002,2003,2004,2005 Wim Taymans <wim@fluendo.com>
4 * 2007 Wim Taymans <wim.taymans@gmail.com>
6 * gsttee.c: Tee element, one in N out
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 * @see_also: #GstIdentity
28 * Split data to multiple pads.
39 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
44 GST_DEBUG_CATEGORY_STATIC (gst_tee_debug);
45 #define GST_CAT_DEFAULT gst_tee_debug
47 #define GST_TYPE_TEE_PULL_MODE (gst_tee_pull_mode_get_type())
49 gst_tee_pull_mode_get_type (void)
51 static GType type = 0;
52 static const GEnumValue data[] = {
53 {GST_TEE_PULL_MODE_NEVER, "Never activate in pull mode", "never"},
54 {GST_TEE_PULL_MODE_SINGLE, "Only one src pad can be active in pull mode",
60 type = g_enum_register_static ("GstTeePullMode", data);
65 /* lock to protect request pads from being removed while downstream */
66 #define GST_TEE_DYN_LOCK(tee) g_mutex_lock ((tee)->dyn_lock)
67 #define GST_TEE_DYN_UNLOCK(tee) g_mutex_unlock ((tee)->dyn_lock)
69 #define DEFAULT_PROP_NUM_SRC_PADS 0
70 #define DEFAULT_PROP_HAS_SINK_LOOP FALSE
71 #define DEFAULT_PROP_HAS_CHAIN TRUE
72 #define DEFAULT_PROP_SILENT TRUE
73 #define DEFAULT_PROP_LAST_MESSAGE NULL
74 #define DEFAULT_PULL_MODE GST_TEE_PULL_MODE_NEVER
88 static GstStaticPadTemplate tee_src_template = GST_STATIC_PAD_TEMPLATE ("src%d",
93 #define _do_init(bla) \
94 GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
96 GST_BOILERPLATE_FULL (GstTee, gst_tee, GstElement, GST_TYPE_ELEMENT, _do_init);
98 /* structure and quark to keep track of which pads have been pushed */
99 static GQuark push_data;
104 GstFlowReturn result;
108 static GstPad *gst_tee_request_new_pad (GstElement * element,
109 GstPadTemplate * temp, const gchar * unused);
110 static void gst_tee_release_pad (GstElement * element, GstPad * pad);
112 static void gst_tee_finalize (GObject * object);
113 static void gst_tee_set_property (GObject * object, guint prop_id,
114 const GValue * value, GParamSpec * pspec);
115 static void gst_tee_get_property (GObject * object, guint prop_id,
116 GValue * value, GParamSpec * pspec);
118 static GstFlowReturn gst_tee_chain (GstPad * pad, GstBuffer * buffer);
119 static GstFlowReturn gst_tee_chain_list (GstPad * pad, GstBufferList * list);
120 static GstFlowReturn gst_tee_buffer_alloc (GstPad * pad, guint64 offset,
121 guint size, GstCaps * caps, GstBuffer ** buf);
122 static gboolean gst_tee_sink_acceptcaps (GstPad * pad, GstCaps * caps);
123 static gboolean gst_tee_sink_activate_push (GstPad * pad, gboolean active);
124 static gboolean gst_tee_src_check_get_range (GstPad * pad);
125 static gboolean gst_tee_src_activate_pull (GstPad * pad, gboolean active);
126 static GstFlowReturn gst_tee_src_get_range (GstPad * pad, guint64 offset,
127 guint length, GstBuffer ** buf);
131 gst_tee_base_init (gpointer g_class)
133 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
135 gst_element_class_set_details_simple (gstelement_class,
138 "1-to-N pipe fitting",
139 "Erik Walthinsen <omega@cse.ogi.edu>, " "Wim Taymans <wim@fluendo.com>");
140 gst_element_class_add_pad_template (gstelement_class,
141 gst_static_pad_template_get (&sinktemplate));
142 gst_element_class_add_pad_template (gstelement_class,
143 gst_static_pad_template_get (&tee_src_template));
145 push_data = g_quark_from_static_string ("tee-push-data");
149 gst_tee_finalize (GObject * object)
153 tee = GST_TEE (object);
155 g_free (tee->last_message);
157 g_mutex_free (tee->dyn_lock);
159 G_OBJECT_CLASS (parent_class)->finalize (object);
163 gst_tee_class_init (GstTeeClass * klass)
165 GObjectClass *gobject_class;
166 GstElementClass *gstelement_class;
168 gobject_class = G_OBJECT_CLASS (klass);
169 gstelement_class = GST_ELEMENT_CLASS (klass);
171 gobject_class->finalize = gst_tee_finalize;
172 gobject_class->set_property = gst_tee_set_property;
173 gobject_class->get_property = gst_tee_get_property;
175 g_object_class_install_property (gobject_class, PROP_NUM_SRC_PADS,
176 g_param_spec_int ("num-src-pads", "Num Src Pads",
177 "The number of source pads", 0, G_MAXINT, DEFAULT_PROP_NUM_SRC_PADS,
178 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
179 g_object_class_install_property (gobject_class, PROP_HAS_SINK_LOOP,
180 g_param_spec_boolean ("has-sink-loop", "Has Sink Loop",
181 "If the element should spawn a thread (unimplemented and deprecated)",
182 DEFAULT_PROP_HAS_SINK_LOOP,
183 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (gobject_class, PROP_HAS_CHAIN,
185 g_param_spec_boolean ("has-chain", "Has Chain",
186 "If the element can operate in push mode", DEFAULT_PROP_HAS_CHAIN,
187 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188 g_object_class_install_property (gobject_class, PROP_SILENT,
189 g_param_spec_boolean ("silent", "Silent",
190 "Don't produce last_message events", DEFAULT_PROP_SILENT,
191 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192 g_object_class_install_property (gobject_class, PROP_LAST_MESSAGE,
193 g_param_spec_string ("last-message", "Last Message",
194 "The message describing current status", DEFAULT_PROP_LAST_MESSAGE,
195 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
196 g_object_class_install_property (gobject_class, PROP_PULL_MODE,
197 g_param_spec_enum ("pull-mode", "Pull mode",
198 "Behavior of tee in pull mode", GST_TYPE_TEE_PULL_MODE,
200 G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
201 g_object_class_install_property (gobject_class, PROP_ALLOC_PAD,
202 g_param_spec_object ("alloc-pad", "Allocation Src Pad",
203 "The pad used for gst_pad_alloc_buffer", GST_TYPE_PAD,
204 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
206 gstelement_class->request_new_pad =
207 GST_DEBUG_FUNCPTR (gst_tee_request_new_pad);
208 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_tee_release_pad);
212 gst_tee_init (GstTee * tee, GstTeeClass * g_class)
214 tee->dyn_lock = g_mutex_new ();
216 tee->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
217 tee->sink_mode = GST_ACTIVATE_NONE;
219 gst_pad_set_setcaps_function (tee->sinkpad,
220 GST_DEBUG_FUNCPTR (gst_pad_proxy_setcaps));
221 gst_pad_set_getcaps_function (tee->sinkpad,
222 GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
223 gst_pad_set_acceptcaps_function (tee->sinkpad,
224 GST_DEBUG_FUNCPTR (gst_tee_sink_acceptcaps));
225 gst_pad_set_bufferalloc_function (tee->sinkpad,
226 GST_DEBUG_FUNCPTR (gst_tee_buffer_alloc));
227 gst_pad_set_activatepush_function (tee->sinkpad,
228 GST_DEBUG_FUNCPTR (gst_tee_sink_activate_push));
229 gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain));
230 gst_pad_set_chain_list_function (tee->sinkpad,
231 GST_DEBUG_FUNCPTR (gst_tee_chain_list));
232 gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad);
234 tee->last_message = NULL;
238 gst_tee_request_new_pad (GstElement * element, GstPadTemplate * templ,
239 const gchar * unused)
244 GstActivateMode mode;
248 tee = GST_TEE (element);
250 GST_DEBUG_OBJECT (tee, "requesting pad");
252 GST_OBJECT_LOCK (tee);
253 name = g_strdup_printf ("src%d", tee->pad_counter++);
255 srcpad = gst_pad_new_from_template (templ, name);
258 mode = tee->sink_mode;
260 /* install the data, we automatically free it when the pad is disposed because
261 * of _release_pad or when the element goes away. */
262 data = g_new0 (PushData, 1);
263 data->pushed = FALSE;
264 data->result = GST_FLOW_NOT_LINKED;
265 data->removed = FALSE;
266 g_object_set_qdata_full (G_OBJECT (srcpad), push_data, data, g_free);
268 GST_OBJECT_UNLOCK (tee);
271 case GST_ACTIVATE_PULL:
272 /* we already have a src pad in pull mode, and our pull mode can only be
273 SINGLE, so fall through to activate this new pad in push mode */
274 case GST_ACTIVATE_PUSH:
275 res = gst_pad_activate_push (srcpad, TRUE);
283 goto activate_failed;
285 gst_pad_set_setcaps_function (srcpad,
286 GST_DEBUG_FUNCPTR (gst_pad_proxy_setcaps));
287 gst_pad_set_getcaps_function (srcpad,
288 GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
289 gst_pad_set_activatepull_function (srcpad,
290 GST_DEBUG_FUNCPTR (gst_tee_src_activate_pull));
291 gst_pad_set_checkgetrange_function (srcpad,
292 GST_DEBUG_FUNCPTR (gst_tee_src_check_get_range));
293 gst_pad_set_getrange_function (srcpad,
294 GST_DEBUG_FUNCPTR (gst_tee_src_get_range));
295 gst_element_add_pad (GST_ELEMENT_CAST (tee), srcpad);
302 gboolean changed = FALSE;
304 GST_OBJECT_LOCK (tee);
305 GST_DEBUG_OBJECT (tee, "warning failed to activate request pad");
306 if (tee->allocpad == srcpad) {
307 tee->allocpad = NULL;
310 GST_OBJECT_UNLOCK (tee);
311 gst_object_unref (srcpad);
313 g_object_notify (G_OBJECT (tee), "alloc-pad");
320 gst_tee_release_pad (GstElement * element, GstPad * pad)
324 gboolean changed = FALSE;
326 tee = GST_TEE (element);
328 GST_DEBUG_OBJECT (tee, "releasing pad");
330 GST_OBJECT_LOCK (tee);
331 if (tee->allocpad == pad) {
332 tee->allocpad = NULL;
335 GST_OBJECT_UNLOCK (tee);
337 g_object_notify (G_OBJECT (tee), "alloc-pad");
340 /* wait for pending pad_alloc to finish */
341 GST_TEE_DYN_LOCK (tee);
342 /* mark the pad as removed so that future pad_alloc fails with NOT_LINKED. */
343 data = g_object_get_qdata (G_OBJECT (pad), push_data);
344 data->removed = TRUE;
346 gst_pad_set_active (pad, FALSE);
348 gst_element_remove_pad (GST_ELEMENT_CAST (tee), pad);
349 GST_TEE_DYN_UNLOCK (tee);
353 gst_tee_set_property (GObject * object, guint prop_id, const GValue * value,
356 GstTee *tee = GST_TEE (object);
358 GST_OBJECT_LOCK (tee);
360 case PROP_HAS_SINK_LOOP:
361 tee->has_sink_loop = g_value_get_boolean (value);
362 if (tee->has_sink_loop) {
363 g_warning ("tee will never implement has-sink-loop==TRUE");
367 tee->has_chain = g_value_get_boolean (value);
370 tee->silent = g_value_get_boolean (value);
373 tee->pull_mode = g_value_get_enum (value);
377 GstPad *pad = g_value_get_object (value);
378 GST_OBJECT_LOCK (pad);
379 if (GST_OBJECT_PARENT (pad) == GST_OBJECT_CAST (object))
382 GST_WARNING_OBJECT (object, "Tried to set alloc pad %s which"
383 " is not my pad", GST_OBJECT_NAME (pad));
384 GST_OBJECT_UNLOCK (pad);
388 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
391 GST_OBJECT_UNLOCK (tee);
395 gst_tee_get_property (GObject * object, guint prop_id, GValue * value,
398 GstTee *tee = GST_TEE (object);
400 GST_OBJECT_LOCK (tee);
402 case PROP_NUM_SRC_PADS:
403 g_value_set_int (value, GST_ELEMENT (tee)->numsrcpads);
405 case PROP_HAS_SINK_LOOP:
406 g_value_set_boolean (value, tee->has_sink_loop);
409 g_value_set_boolean (value, tee->has_chain);
412 g_value_set_boolean (value, tee->silent);
414 case PROP_LAST_MESSAGE:
415 g_value_set_string (value, tee->last_message);
418 g_value_set_enum (value, tee->pull_mode);
421 g_value_set_object (value, tee->allocpad);
424 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
427 GST_OBJECT_UNLOCK (tee);
430 /* we have no previous source pad we can use to proxy the pad alloc. Loop over
431 * the source pads, try to alloc a buffer on each one of them. Keep a reference
432 * to the first pad that succeeds, we will be using it to alloc more buffers
433 * later. must be called with the OBJECT_LOCK on tee. */
435 gst_tee_find_buffer_alloc (GstTee * tee, guint64 offset, guint size,
436 GstCaps * caps, GstBuffer ** buf)
442 res = GST_FLOW_NOT_LINKED;
445 pads = GST_ELEMENT_CAST (tee)->srcpads;
446 cookie = GST_ELEMENT_CAST (tee)->pads_cookie;
452 pad = GST_PAD_CAST (pads->data);
453 gst_object_ref (pad);
454 GST_DEBUG_OBJECT (tee, "try alloc on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
455 GST_OBJECT_UNLOCK (tee);
457 GST_TEE_DYN_LOCK (tee);
458 data = g_object_get_qdata (G_OBJECT (pad), push_data);
460 res = gst_pad_alloc_buffer (pad, offset, size, caps, buf);
462 res = GST_FLOW_NOT_LINKED;
463 GST_TEE_DYN_UNLOCK (tee);
465 GST_DEBUG_OBJECT (tee, "got return value %d", res);
467 gst_object_unref (pad);
469 GST_OBJECT_LOCK (tee);
470 if (GST_ELEMENT_CAST (tee)->pads_cookie != cookie) {
471 GST_DEBUG_OBJECT (tee, "pad list changed, restart");
472 /* pad list changed, restart. If the pad alloc function returned OK we
473 * need to unref the buffer */
474 if (res == GST_FLOW_OK)
475 gst_buffer_unref (*buf);
479 if (res == GST_FLOW_OK) {
480 GST_DEBUG_OBJECT (tee, "we have a buffer on pad %s:%s",
481 GST_DEBUG_PAD_NAME (pad));
482 /* we have a buffer, keep the pad for later and exit the loop. */
484 GST_OBJECT_UNLOCK (tee);
485 g_object_notify (G_OBJECT (tee), "alloc-pad");
486 GST_OBJECT_LOCK (tee);
489 /* no valid buffer, try another pad */
490 pads = g_list_next (pads);
497 gst_tee_buffer_alloc (GstPad * pad, guint64 offset, guint size,
498 GstCaps * caps, GstBuffer ** buf)
504 tee = GST_TEE (GST_PAD_PARENT (pad));
506 res = GST_FLOW_NOT_LINKED;
508 GST_OBJECT_LOCK (tee);
509 if ((allocpad = tee->allocpad)) {
512 /* if we had a previous pad we used for allocating a buffer, continue using
514 GST_DEBUG_OBJECT (tee, "using pad %s:%s for alloc",
515 GST_DEBUG_PAD_NAME (allocpad));
516 gst_object_ref (allocpad);
517 GST_OBJECT_UNLOCK (tee);
519 GST_TEE_DYN_LOCK (tee);
520 data = g_object_get_qdata (G_OBJECT (allocpad), push_data);
522 res = gst_pad_alloc_buffer (allocpad, offset, size, caps, buf);
524 res = GST_FLOW_NOT_LINKED;
525 GST_TEE_DYN_UNLOCK (tee);
527 gst_object_unref (allocpad);
529 GST_OBJECT_LOCK (tee);
531 /* either we failed to alloc on the the previous pad or we did not have a
533 if (res == GST_FLOW_NOT_LINKED) {
534 /* find a new pad to alloc a buffer on */
535 GST_DEBUG_OBJECT (tee, "finding pad for alloc");
536 res = gst_tee_find_buffer_alloc (tee, offset, size, caps, buf);
538 GST_OBJECT_UNLOCK (tee);
543 /* on the sink we accept caps that are acceptable to all srcpads */
545 gst_tee_sink_acceptcaps (GstPad * pad, GstCaps * caps)
551 tee = GST_TEE (GST_PAD_PARENT (pad));
553 it = gst_element_iterate_src_pads (GST_ELEMENT_CAST (tee));
557 while (!done && res) {
560 switch (gst_iterator_next (it, &item)) {
561 case GST_ITERATOR_OK:
562 res &= gst_pad_peer_accept_caps (GST_PAD_CAST (item), caps);
563 gst_object_unref (item);
565 case GST_ITERATOR_RESYNC:
567 gst_iterator_resync (it);
569 case GST_ITERATOR_ERROR:
573 case GST_ITERATOR_DONE:
578 gst_iterator_free (it);
584 gst_tee_do_message (GstTee * tee, GstPad * pad, gpointer data, gboolean is_list)
586 GST_OBJECT_LOCK (tee);
587 g_free (tee->last_message);
590 g_strdup_printf ("chain-list ******* (%s:%s)t %p",
591 GST_DEBUG_PAD_NAME (pad), data);
594 g_strdup_printf ("chain ******* (%s:%s)t (%d bytes, %"
595 G_GUINT64_FORMAT ") %p", GST_DEBUG_PAD_NAME (pad),
596 GST_BUFFER_SIZE (data), GST_BUFFER_TIMESTAMP (data), data);
598 GST_OBJECT_UNLOCK (tee);
599 g_object_notify (G_OBJECT (tee), "last_message");
603 gst_tee_do_push (GstTee * tee, GstPad * pad, gpointer data, gboolean is_list)
608 if (pad == tee->pull_pad) {
609 /* don't push on the pad we're pulling from */
611 } else if (is_list) {
613 gst_pad_push_list (pad,
614 gst_buffer_list_ref (GST_BUFFER_LIST_CAST (data)));
616 res = gst_pad_push (pad, gst_buffer_ref (GST_BUFFER_CAST (data)));
622 clear_pads (GstPad * pad, GstTee * tee)
626 data = g_object_get_qdata (G_OBJECT (pad), push_data);
628 /* the data must be there or we have a screwed up internal state */
629 g_assert (data != NULL);
631 data->pushed = FALSE;
632 data->result = GST_FLOW_NOT_LINKED;
636 gst_tee_handle_data (GstTee * tee, gpointer data, gboolean is_list)
640 GstFlowReturn ret, cret;
642 if (G_UNLIKELY (!tee->silent))
643 gst_tee_do_message (tee, tee->sinkpad, data, is_list);
645 GST_OBJECT_LOCK (tee);
647 /* mark all pads as 'not pushed on yet' */
648 g_list_foreach (GST_ELEMENT_CAST (tee)->srcpads, (GFunc) clear_pads, tee);
651 cret = GST_FLOW_NOT_LINKED;
652 pads = GST_ELEMENT_CAST (tee)->srcpads;
653 cookie = GST_ELEMENT_CAST (tee)->pads_cookie;
659 pad = GST_PAD_CAST (pads->data);
661 /* get the private data, something is really wrong with the internal state
662 * when it is not there */
663 pdata = g_object_get_qdata (G_OBJECT (pad), push_data);
664 g_assert (pdata != NULL);
666 if (!pdata->pushed) {
667 /* not yet pushed, release lock and start pushing */
668 gst_object_ref (pad);
669 GST_OBJECT_UNLOCK (tee);
671 GST_LOG_OBJECT (tee, "Starting to push %s %p",
672 is_list ? "list" : "buffer", data);
674 ret = gst_tee_do_push (tee, pad, data, is_list);
676 GST_LOG_OBJECT (tee, "Pushing item %p yielded result %s", data,
677 gst_flow_get_name (ret));
679 GST_OBJECT_LOCK (tee);
680 /* keep track of which pad we pushed and the result value. We need to do
681 * this before we release the refcount on the pad, the PushData is
682 * destroyed when the last ref of the pad goes away. */
683 pdata->pushed = TRUE;
685 gst_object_unref (pad);
687 /* already pushed, use previous return value */
689 GST_LOG_OBJECT (tee, "pad already pushed with %s",
690 gst_flow_get_name (ret));
693 /* before we go combining the return value, check if the pad list is still
694 * the same. It could be possible that the pad we just pushed was removed
695 * and the return value it not valid anymore */
696 if (GST_ELEMENT_CAST (tee)->pads_cookie != cookie) {
697 GST_LOG_OBJECT (tee, "pad list changed");
698 /* the list of pads changed, restart iteration. Pads that we already
699 * pushed on and are still in the new list, will not be pushed on
704 /* stop pushing more buffers when we have a fatal error */
705 if (ret != GST_FLOW_OK && ret != GST_FLOW_NOT_LINKED)
708 /* keep all other return values, overwriting the previous one. */
709 if (ret != GST_FLOW_NOT_LINKED) {
710 GST_LOG_OBJECT (tee, "Replacing ret val %d with %d", cret, ret);
713 pads = g_list_next (pads);
715 GST_OBJECT_UNLOCK (tee);
717 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
719 /* no need to unset gvalue */
725 GST_DEBUG_OBJECT (tee, "received error %s", gst_flow_get_name (ret));
726 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
727 GST_OBJECT_UNLOCK (tee);
733 gst_tee_chain (GstPad * pad, GstBuffer * buffer)
738 tee = GST_TEE (gst_pad_get_parent (pad));
740 GST_DEBUG_OBJECT (tee, "received buffer %p", buffer);
742 res = gst_tee_handle_data (tee, buffer, FALSE);
744 GST_DEBUG_OBJECT (tee, "handled buffer %s", gst_flow_get_name (res));
746 gst_object_unref (tee);
752 gst_tee_chain_list (GstPad * pad, GstBufferList * list)
757 tee = GST_TEE (gst_pad_get_parent (pad));
759 GST_DEBUG_OBJECT (tee, "received list %p", list);
761 res = gst_tee_handle_data (tee, list, TRUE);
763 GST_DEBUG_OBJECT (tee, "handled list %s", gst_flow_get_name (res));
765 gst_object_unref (tee);
771 gst_tee_sink_activate_push (GstPad * pad, gboolean active)
775 tee = GST_TEE (GST_OBJECT_PARENT (pad));
777 GST_OBJECT_LOCK (tee);
778 tee->sink_mode = active && GST_ACTIVATE_PUSH;
780 if (active && !tee->has_chain)
782 GST_OBJECT_UNLOCK (tee);
789 GST_OBJECT_UNLOCK (tee);
790 GST_INFO_OBJECT (tee,
791 "Tee cannot operate in push mode with has-chain==FALSE");
797 gst_tee_src_activate_pull (GstPad * pad, gboolean active)
803 tee = GST_TEE (gst_pad_get_parent (pad));
805 GST_OBJECT_LOCK (tee);
807 if (tee->pull_mode == GST_TEE_PULL_MODE_NEVER)
810 if (tee->pull_mode == GST_TEE_PULL_MODE_SINGLE && active && tee->pull_pad)
811 goto cannot_pull_multiple_srcs;
813 sinkpad = gst_object_ref (tee->sinkpad);
815 GST_OBJECT_UNLOCK (tee);
817 res = gst_pad_activate_pull (sinkpad, active);
818 gst_object_unref (sinkpad);
821 goto sink_activate_failed;
823 GST_OBJECT_LOCK (tee);
825 if (tee->pull_mode == GST_TEE_PULL_MODE_SINGLE)
828 if (pad == tee->pull_pad)
829 tee->pull_pad = NULL;
831 tee->sink_mode = active && GST_ACTIVATE_PULL;
832 GST_OBJECT_UNLOCK (tee);
834 gst_object_unref (tee);
841 GST_OBJECT_UNLOCK (tee);
842 GST_INFO_OBJECT (tee, "Cannot activate in pull mode, pull-mode "
844 gst_object_unref (tee);
847 cannot_pull_multiple_srcs:
849 GST_OBJECT_UNLOCK (tee);
850 GST_INFO_OBJECT (tee, "Cannot activate multiple src pads in pull mode, "
851 "pull-mode set to SINGLE");
852 gst_object_unref (tee);
855 sink_activate_failed:
857 GST_INFO_OBJECT (tee, "Failed to %sactivate sink pad in pull mode",
859 gst_object_unref (tee);
865 gst_tee_src_check_get_range (GstPad * pad)
871 tee = GST_TEE (gst_pad_get_parent (pad));
873 GST_OBJECT_LOCK (tee);
875 if (tee->pull_mode == GST_TEE_PULL_MODE_NEVER)
878 if (tee->pull_mode == GST_TEE_PULL_MODE_SINGLE && tee->pull_pad)
879 goto cannot_pull_multiple_srcs;
881 sinkpad = gst_object_ref (tee->sinkpad);
883 GST_OBJECT_UNLOCK (tee);
885 res = gst_pad_check_pull_range (sinkpad);
886 gst_object_unref (sinkpad);
888 gst_object_unref (tee);
895 GST_OBJECT_UNLOCK (tee);
896 GST_INFO_OBJECT (tee, "Cannot activate in pull mode, pull-mode "
898 gst_object_unref (tee);
901 cannot_pull_multiple_srcs:
903 GST_OBJECT_UNLOCK (tee);
904 GST_INFO_OBJECT (tee, "Cannot activate multiple src pads in pull mode, "
905 "pull-mode set to SINGLE");
906 gst_object_unref (tee);
912 gst_tee_push_eos (GstPad * pad, GstTee * tee)
914 if (pad != tee->pull_pad)
915 gst_pad_push_event (pad, gst_event_new_eos ());
916 gst_object_unref (pad);
920 gst_tee_pull_eos (GstTee * tee)
924 iter = gst_element_iterate_src_pads (GST_ELEMENT (tee));
925 gst_iterator_foreach (iter, (GFunc) gst_tee_push_eos, tee);
926 gst_iterator_free (iter);
930 gst_tee_src_get_range (GstPad * pad, guint64 offset, guint length,
936 tee = GST_TEE (gst_pad_get_parent (pad));
938 ret = gst_pad_pull_range (tee->sinkpad, offset, length, buf);
940 if (ret == GST_FLOW_OK)
941 ret = gst_tee_handle_data (tee, gst_buffer_ref (*buf), FALSE);
942 else if (ret == GST_FLOW_UNEXPECTED)
943 gst_tee_pull_eos (tee);
945 gst_object_unref (tee);