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_DEBUG_FUNCPTR (gst_tee_finalize);
172 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_tee_set_property);
173 gobject_class->get_property = GST_DEBUG_FUNCPTR (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 GST_OBJECT_LOCK (tee);
303 GST_DEBUG_OBJECT (tee, "warning failed to activate request pad");
304 if (tee->allocpad == srcpad)
305 tee->allocpad = NULL;
306 gst_object_unref (srcpad);
307 GST_OBJECT_UNLOCK (tee);
308 g_object_notify (G_OBJECT (tee), "alloc-pad");
314 gst_tee_release_pad (GstElement * element, GstPad * pad)
319 tee = GST_TEE (element);
321 GST_DEBUG_OBJECT (tee, "releasing pad");
323 GST_OBJECT_LOCK (tee);
324 if (tee->allocpad == pad)
325 tee->allocpad = NULL;
326 GST_OBJECT_UNLOCK (tee);
327 g_object_notify (G_OBJECT (tee), "alloc-pad");
329 /* wait for pending pad_alloc to finish */
330 GST_TEE_DYN_LOCK (tee);
331 /* mark the pad as removed so that future pad_alloc fails with NOT_LINKED. */
332 data = g_object_get_qdata (G_OBJECT (pad), push_data);
333 data->removed = TRUE;
335 gst_pad_set_active (pad, FALSE);
337 gst_element_remove_pad (GST_ELEMENT_CAST (tee), pad);
338 GST_TEE_DYN_UNLOCK (tee);
342 gst_tee_set_property (GObject * object, guint prop_id, const GValue * value,
345 GstTee *tee = GST_TEE (object);
347 GST_OBJECT_LOCK (tee);
349 case PROP_HAS_SINK_LOOP:
350 tee->has_sink_loop = g_value_get_boolean (value);
351 if (tee->has_sink_loop) {
352 g_warning ("tee will never implement has-sink-loop==TRUE");
356 tee->has_chain = g_value_get_boolean (value);
359 tee->silent = g_value_get_boolean (value);
362 tee->pull_mode = g_value_get_enum (value);
366 GstPad *pad = g_value_get_object (value);
367 GST_OBJECT_LOCK (pad);
368 if (GST_OBJECT_PARENT (pad) == GST_OBJECT_CAST (object))
371 GST_WARNING_OBJECT (object, "Tried to set alloc pad %s which"
372 " is not my pad", GST_OBJECT_NAME (pad));
373 GST_OBJECT_UNLOCK (pad);
377 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
380 GST_OBJECT_UNLOCK (tee);
384 gst_tee_get_property (GObject * object, guint prop_id, GValue * value,
387 GstTee *tee = GST_TEE (object);
389 GST_OBJECT_LOCK (tee);
391 case PROP_NUM_SRC_PADS:
392 g_value_set_int (value, GST_ELEMENT (tee)->numsrcpads);
394 case PROP_HAS_SINK_LOOP:
395 g_value_set_boolean (value, tee->has_sink_loop);
398 g_value_set_boolean (value, tee->has_chain);
401 g_value_set_boolean (value, tee->silent);
403 case PROP_LAST_MESSAGE:
404 g_value_set_string (value, tee->last_message);
407 g_value_set_enum (value, tee->pull_mode);
410 g_value_set_object (value, tee->allocpad);
413 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
416 GST_OBJECT_UNLOCK (tee);
419 /* we have no previous source pad we can use to proxy the pad alloc. Loop over
420 * the source pads, try to alloc a buffer on each one of them. Keep a reference
421 * to the first pad that succeeds, we will be using it to alloc more buffers
422 * later. must be called with the OBJECT_LOCK on tee. */
424 gst_tee_find_buffer_alloc (GstTee * tee, guint64 offset, guint size,
425 GstCaps * caps, GstBuffer ** buf)
431 res = GST_FLOW_NOT_LINKED;
434 pads = GST_ELEMENT_CAST (tee)->srcpads;
435 cookie = GST_ELEMENT_CAST (tee)->pads_cookie;
441 pad = GST_PAD_CAST (pads->data);
442 gst_object_ref (pad);
443 GST_DEBUG_OBJECT (tee, "try alloc on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
444 GST_OBJECT_UNLOCK (tee);
446 GST_TEE_DYN_LOCK (tee);
447 data = g_object_get_qdata (G_OBJECT (pad), push_data);
449 res = gst_pad_alloc_buffer (pad, offset, size, caps, buf);
451 res = GST_FLOW_NOT_LINKED;
452 GST_TEE_DYN_UNLOCK (tee);
454 GST_DEBUG_OBJECT (tee, "got return value %d", res);
456 gst_object_unref (pad);
458 GST_OBJECT_LOCK (tee);
459 if (GST_ELEMENT_CAST (tee)->pads_cookie != cookie) {
460 GST_DEBUG_OBJECT (tee, "pad list changed, restart");
461 /* pad list changed, restart. If the pad alloc function returned OK we
462 * need to unref the buffer */
463 if (res == GST_FLOW_OK)
464 gst_buffer_unref (*buf);
468 if (res == GST_FLOW_OK) {
469 GST_DEBUG_OBJECT (tee, "we have a buffer on pad %s:%s",
470 GST_DEBUG_PAD_NAME (pad));
471 /* we have a buffer, keep the pad for later and exit the loop. */
473 GST_OBJECT_UNLOCK (tee);
474 g_object_notify (G_OBJECT (tee), "alloc-pad");
475 GST_OBJECT_LOCK (tee);
478 /* no valid buffer, try another pad */
479 pads = g_list_next (pads);
486 gst_tee_buffer_alloc (GstPad * pad, guint64 offset, guint size,
487 GstCaps * caps, GstBuffer ** buf)
493 tee = GST_TEE (GST_PAD_PARENT (pad));
495 res = GST_FLOW_NOT_LINKED;
497 GST_OBJECT_LOCK (tee);
498 if ((allocpad = tee->allocpad)) {
501 /* if we had a previous pad we used for allocating a buffer, continue using
503 GST_DEBUG_OBJECT (tee, "using pad %s:%s for alloc",
504 GST_DEBUG_PAD_NAME (allocpad));
505 gst_object_ref (allocpad);
506 GST_OBJECT_UNLOCK (tee);
508 GST_TEE_DYN_LOCK (tee);
509 data = g_object_get_qdata (G_OBJECT (allocpad), push_data);
511 res = gst_pad_alloc_buffer (allocpad, offset, size, caps, buf);
513 res = GST_FLOW_NOT_LINKED;
514 GST_TEE_DYN_UNLOCK (tee);
516 gst_object_unref (allocpad);
518 GST_OBJECT_LOCK (tee);
520 /* either we failed to alloc on the the previous pad or we did not have a
522 if (res == GST_FLOW_NOT_LINKED) {
523 /* find a new pad to alloc a buffer on */
524 GST_DEBUG_OBJECT (tee, "finding pad for alloc");
525 res = gst_tee_find_buffer_alloc (tee, offset, size, caps, buf);
527 GST_OBJECT_UNLOCK (tee);
532 /* on the sink we accept caps that are acceptable to all srcpads */
534 gst_tee_sink_acceptcaps (GstPad * pad, GstCaps * caps)
540 tee = GST_TEE (GST_PAD_PARENT (pad));
542 it = gst_element_iterate_src_pads (GST_ELEMENT_CAST (tee));
546 while (!done && res) {
549 switch (gst_iterator_next (it, &item)) {
550 case GST_ITERATOR_OK:
551 res &= gst_pad_peer_accept_caps (GST_PAD_CAST (item), caps);
552 gst_object_unref (item);
554 case GST_ITERATOR_RESYNC:
556 gst_iterator_resync (it);
558 case GST_ITERATOR_ERROR:
562 case GST_ITERATOR_DONE:
567 gst_iterator_free (it);
573 gst_tee_do_push (GstTee * tee, GstPad * pad, gpointer data, gboolean is_list)
577 if (G_UNLIKELY (!tee->silent)) {
578 GST_OBJECT_LOCK (tee);
579 g_free (tee->last_message);
582 g_strdup_printf ("chain-list ******* (%s:%s)t %p",
583 GST_DEBUG_PAD_NAME (pad), data);
586 g_strdup_printf ("chain ******* (%s:%s)t (%d bytes, %"
587 G_GUINT64_FORMAT ") %p", GST_DEBUG_PAD_NAME (pad),
588 GST_BUFFER_SIZE (data), GST_BUFFER_TIMESTAMP (data), data);
590 GST_OBJECT_UNLOCK (tee);
591 g_object_notify (G_OBJECT (tee), "last_message");
595 if (pad == tee->pull_pad) {
596 /* don't push on the pad we're pulling from */
598 } else if (is_list) {
600 gst_pad_push_list (pad,
601 gst_buffer_list_ref (GST_BUFFER_LIST_CAST (data)));
603 res = gst_pad_push (pad, gst_buffer_ref (GST_BUFFER_CAST (data)));
609 clear_pads (GstPad * pad, GstTee * tee)
613 data = g_object_get_qdata (G_OBJECT (pad), push_data);
615 /* the data must be there or we have a screwed up internal state */
616 g_assert (data != NULL);
618 data->pushed = FALSE;
619 data->result = GST_FLOW_NOT_LINKED;
623 gst_tee_handle_data (GstTee * tee, gpointer data, gboolean is_list)
627 GstFlowReturn ret, cret;
630 tee->offset += GST_BUFFER_SIZE (data);
633 GST_OBJECT_LOCK (tee);
634 /* mark all pads as 'not pushed on yet' */
635 g_list_foreach (GST_ELEMENT_CAST (tee)->srcpads, (GFunc) clear_pads, tee);
638 cret = GST_FLOW_NOT_LINKED;
639 pads = GST_ELEMENT_CAST (tee)->srcpads;
640 cookie = GST_ELEMENT_CAST (tee)->pads_cookie;
646 pad = GST_PAD_CAST (pads->data);
648 /* get the private data, something is really wrong with the internal state
649 * when it is not there */
650 pdata = g_object_get_qdata (G_OBJECT (pad), push_data);
651 g_assert (pdata != NULL);
653 if (!pdata->pushed) {
654 /* not yet pushed, release lock and start pushing */
655 gst_object_ref (pad);
656 GST_OBJECT_UNLOCK (tee);
658 GST_LOG_OBJECT (tee, "Starting to push %s %p",
659 is_list ? "list" : "buffer", data);
661 ret = gst_tee_do_push (tee, pad, data, is_list);
663 GST_LOG_OBJECT (tee, "Pushing item %p yielded result %s", data,
664 gst_flow_get_name (ret));
666 GST_OBJECT_LOCK (tee);
667 /* keep track of which pad we pushed and the result value. We need to do
668 * this before we release the refcount on the pad, the PushData is
669 * destroyed when the last ref of the pad goes away. */
670 pdata->pushed = TRUE;
672 gst_object_unref (pad);
674 /* already pushed, use previous return value */
676 GST_LOG_OBJECT (tee, "pad already pushed with %s",
677 gst_flow_get_name (ret));
680 /* before we go combining the return value, check if the pad list is still
681 * the same. It could be possible that the pad we just pushed was removed
682 * and the return value it not valid anymore */
683 if (GST_ELEMENT_CAST (tee)->pads_cookie != cookie) {
684 GST_LOG_OBJECT (tee, "pad list changed");
685 /* the list of pads changed, restart iteration. Pads that we already
686 * pushed on and are still in the new list, will not be pushed on
691 /* stop pushing more buffers when we have a fatal error */
692 if (ret != GST_FLOW_OK && ret != GST_FLOW_NOT_LINKED)
695 /* keep all other return values, overwriting the previous one. */
696 if (ret != GST_FLOW_NOT_LINKED) {
697 GST_LOG_OBJECT (tee, "Replacing ret val %d with %d", cret, ret);
700 pads = g_list_next (pads);
702 GST_OBJECT_UNLOCK (tee);
704 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
706 /* no need to unset gvalue */
712 GST_DEBUG_OBJECT (tee, "received error %s", gst_flow_get_name (ret));
713 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
714 GST_OBJECT_UNLOCK (tee);
720 gst_tee_chain (GstPad * pad, GstBuffer * buffer)
725 tee = GST_TEE (gst_pad_get_parent (pad));
727 GST_DEBUG_OBJECT (tee, "received buffer %p", buffer);
729 res = gst_tee_handle_data (tee, buffer, FALSE);
731 GST_DEBUG_OBJECT (tee, "handled buffer %s", gst_flow_get_name (res));
733 gst_object_unref (tee);
739 gst_tee_chain_list (GstPad * pad, GstBufferList * list)
744 tee = GST_TEE (gst_pad_get_parent (pad));
746 GST_DEBUG_OBJECT (tee, "received list %p", list);
748 res = gst_tee_handle_data (tee, list, TRUE);
750 GST_DEBUG_OBJECT (tee, "handled list %s", gst_flow_get_name (res));
752 gst_object_unref (tee);
758 gst_tee_sink_activate_push (GstPad * pad, gboolean active)
762 tee = GST_TEE (GST_OBJECT_PARENT (pad));
764 GST_OBJECT_LOCK (tee);
765 tee->sink_mode = active && GST_ACTIVATE_PUSH;
767 if (active && !tee->has_chain)
769 GST_OBJECT_UNLOCK (tee);
776 GST_OBJECT_UNLOCK (tee);
777 GST_INFO_OBJECT (tee,
778 "Tee cannot operate in push mode with has-chain==FALSE");
784 gst_tee_src_activate_pull (GstPad * pad, gboolean active)
790 tee = GST_TEE (gst_pad_get_parent (pad));
792 GST_OBJECT_LOCK (tee);
794 if (tee->pull_mode == GST_TEE_PULL_MODE_NEVER)
797 if (tee->pull_mode == GST_TEE_PULL_MODE_SINGLE && active && tee->pull_pad)
798 goto cannot_pull_multiple_srcs;
800 sinkpad = gst_object_ref (tee->sinkpad);
802 GST_OBJECT_UNLOCK (tee);
804 res = gst_pad_activate_pull (sinkpad, active);
805 gst_object_unref (sinkpad);
808 goto sink_activate_failed;
810 GST_OBJECT_LOCK (tee);
812 if (tee->pull_mode == GST_TEE_PULL_MODE_SINGLE)
815 if (pad == tee->pull_pad)
816 tee->pull_pad = NULL;
818 tee->sink_mode = active && GST_ACTIVATE_PULL;
819 GST_OBJECT_UNLOCK (tee);
821 gst_object_unref (tee);
828 GST_OBJECT_UNLOCK (tee);
829 GST_INFO_OBJECT (tee, "Cannot activate in pull mode, pull-mode "
831 gst_object_unref (tee);
834 cannot_pull_multiple_srcs:
836 GST_OBJECT_UNLOCK (tee);
837 GST_INFO_OBJECT (tee, "Cannot activate multiple src pads in pull mode, "
838 "pull-mode set to SINGLE");
839 gst_object_unref (tee);
842 sink_activate_failed:
844 GST_INFO_OBJECT (tee, "Failed to %sactivate sink pad in pull mode",
846 gst_object_unref (tee);
852 gst_tee_src_check_get_range (GstPad * pad)
858 tee = GST_TEE (gst_pad_get_parent (pad));
860 GST_OBJECT_LOCK (tee);
862 if (tee->pull_mode == GST_TEE_PULL_MODE_NEVER)
865 if (tee->pull_mode == GST_TEE_PULL_MODE_SINGLE && tee->pull_pad)
866 goto cannot_pull_multiple_srcs;
868 sinkpad = gst_object_ref (tee->sinkpad);
870 GST_OBJECT_UNLOCK (tee);
872 res = gst_pad_check_pull_range (sinkpad);
873 gst_object_unref (sinkpad);
875 gst_object_unref (tee);
882 GST_OBJECT_UNLOCK (tee);
883 GST_INFO_OBJECT (tee, "Cannot activate in pull mode, pull-mode "
885 gst_object_unref (tee);
888 cannot_pull_multiple_srcs:
890 GST_OBJECT_UNLOCK (tee);
891 GST_INFO_OBJECT (tee, "Cannot activate multiple src pads in pull mode, "
892 "pull-mode set to SINGLE");
893 gst_object_unref (tee);
899 gst_tee_push_eos (GstPad * pad, GstTee * tee)
901 if (pad != tee->pull_pad)
902 gst_pad_push_event (pad, gst_event_new_eos ());
903 gst_object_unref (pad);
907 gst_tee_pull_eos (GstTee * tee)
911 iter = gst_element_iterate_src_pads (GST_ELEMENT (tee));
912 gst_iterator_foreach (iter, (GFunc) gst_tee_push_eos, tee);
913 gst_iterator_free (iter);
917 gst_tee_src_get_range (GstPad * pad, guint64 offset, guint length,
923 tee = GST_TEE (gst_pad_get_parent (pad));
925 ret = gst_pad_pull_range (tee->sinkpad, offset, length, buf);
927 if (ret == GST_FLOW_OK)
928 ret = gst_tee_handle_data (tee, gst_buffer_ref (*buf), FALSE);
929 else if (ret == GST_FLOW_UNEXPECTED)
930 gst_tee_pull_eos (tee);
932 gst_object_unref (tee);