2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
30 * After two pads are retrieved from an element with gst_element_get_pad(),
31 * the pads can be link with gst_pad_link(). (For quick links,
32 * you can also use gst_element_link(), which will make the obvious
33 * link for you if it's straightforward.)
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template().
38 * Pads have #GstCaps attached to it to describe the media type they are
39 * capable of dealing with. gst_pad_get_caps() and gst_pad_set_caps() are
40 * used to manipulate the caps of the pads.
41 * Pads created from a pad template cannot set capabilities that are
42 * incompatible with the pad template capabilities.
44 * Pads without pad templates can be created with gst_pad_new(),
45 * which takes a direction and a name as an argument. If the name is NULL,
46 * then a guaranteed unique name will be assigned to it.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * A #GstElement creating a pad will typically use the various
51 * gst_pad_set_*_function() calls to register callbacks for various events
54 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
55 * or pull in a buffer.
57 * To send a #GstEvent on a pad, use gst_pad_send_event().
59 * Last reviewed on 2005-11-23 (0.9.5)
63 #include "gst_private.h"
66 #include "gstghostpad.h"
67 #include "gstpadtemplate.h"
68 #include "gstenumtypes.h"
69 #include "gstmarshal.h"
74 #include "glib-compat-private.h"
76 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
77 #define GST_CAT_DEFAULT GST_CAT_PADS
79 /* Pad signals and args */
99 static void gst_pad_class_init (GstPadClass * klass);
100 static void gst_pad_init (GstPad * pad);
101 static void gst_pad_dispose (GObject * object);
102 static void gst_pad_finalize (GObject * object);
103 static void gst_pad_set_property (GObject * object, guint prop_id,
104 const GValue * value, GParamSpec * pspec);
105 static void gst_pad_get_property (GObject * object, guint prop_id,
106 GValue * value, GParamSpec * pspec);
108 static GstFlowReturn handle_pad_block (GstPad * pad);
109 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
110 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
111 static gboolean gst_pad_activate_default (GstPad * pad);
112 static gboolean gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps);
114 #ifndef GST_DISABLE_LOADSAVE
115 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
118 static GstObjectClass *parent_class = NULL;
119 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
121 /* quarks for probe signals */
122 static GQuark buffer_quark;
123 static GQuark event_quark;
132 static GstFlowQuarks flow_quarks[] = {
133 {GST_FLOW_RESEND, "resend", 0},
134 {GST_FLOW_OK, "ok", 0},
135 {GST_FLOW_NOT_LINKED, "not-linked", 0},
136 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
137 {GST_FLOW_UNEXPECTED, "unexpected", 0},
138 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
139 {GST_FLOW_ERROR, "error", 0},
140 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
147 * @ret: a #GstFlowReturn to get the name of.
149 * Gets a string representing the given flow return.
151 * Returns: a string with the name of the flow return.
153 G_CONST_RETURN gchar *
154 gst_flow_get_name (GstFlowReturn ret)
158 for (i = 0; flow_quarks[i].name; i++) {
159 if (ret == flow_quarks[i].ret)
160 return flow_quarks[i].name;
167 * @ret: a #GstFlowReturn to get the quark of.
169 * Get the unique quark for the given GstFlowReturn.
171 * Returns: the quark associated with the flow return or 0 if an
172 * invalid return was specified.
175 gst_flow_to_quark (GstFlowReturn ret)
179 for (i = 0; flow_quarks[i].name; i++) {
180 if (ret == flow_quarks[i].ret)
181 return flow_quarks[i].quark;
187 gst_pad_get_type (void)
189 static GType gst_pad_type = 0;
191 if (G_UNLIKELY (gst_pad_type == 0)) {
192 static const GTypeInfo pad_info = {
193 sizeof (GstPadClass), NULL, NULL,
194 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
197 (GInstanceInitFunc) gst_pad_init, NULL
201 gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
204 buffer_quark = g_quark_from_static_string ("buffer");
205 event_quark = g_quark_from_static_string ("event");
207 for (i = 0; flow_quarks[i].name; i++) {
208 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name);
211 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
212 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
218 _gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
219 GValue * return_accu, const GValue * handler_return, gpointer dummy)
221 gboolean ret = g_value_get_boolean (handler_return);
223 GST_DEBUG ("accumulated %d", ret);
224 g_value_set_boolean (return_accu, ret);
230 default_have_data (GstPad * pad, GstMiniObject * o)
236 gst_pad_class_init (GstPadClass * klass)
238 GObjectClass *gobject_class;
241 GstObjectClass *gstobject_class;
243 gobject_class = (GObjectClass *) klass;
244 gstobject_class = (GstObjectClass *) klass;
246 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
248 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
249 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_pad_finalize);
250 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_pad_set_property);
251 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_pad_get_property);
255 * @pad: the pad that emitted the signal
256 * @peer: the peer pad that has been connected
258 * Signals that a pad has been linked to the peer pad.
260 gst_pad_signals[PAD_LINKED] =
261 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
262 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
263 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
266 * @pad: the pad that emitted the signal
267 * @peer: the peer pad that has been disconnected
269 * Signals that a pad has been unlinked from the peer pad.
271 gst_pad_signals[PAD_UNLINKED] =
272 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
273 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
274 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
276 * GstPad::request-link:
277 * @pad: the pad that emitted the signal
278 * @peer: the peer pad for which a connection is requested
280 * Signals that a pad connection has been requested.
282 gst_pad_signals[PAD_REQUEST_LINK] =
283 g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
284 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
285 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
289 * @pad: the pad that emitted the signal
290 * @mini_obj: new data
292 * Signals that new data is available on the pad. This signal is used
293 * internally for implementing pad probes.
294 * See gst_pad_add_*_probe functions.
296 * Returns: %TRUE to keep the data, %FALSE to drop it
298 gst_pad_signals[PAD_HAVE_DATA] =
299 g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
300 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
301 G_STRUCT_OFFSET (GstPadClass, have_data),
302 _gst_do_pass_data_accumulator,
303 NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
304 GST_TYPE_MINI_OBJECT);
306 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_CAPS,
307 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
308 GST_TYPE_CAPS, G_PARAM_READABLE));
309 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_DIRECTION,
310 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
311 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
312 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
313 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_TEMPLATE,
314 g_param_spec_object ("template", "Template",
315 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
318 #ifndef GST_DISABLE_LOADSAVE
319 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
321 gstobject_class->path_string_separator = ".";
323 klass->have_data = default_have_data;
327 gst_pad_init (GstPad * pad)
329 pad->direction = GST_PAD_UNKNOWN;
332 pad->chainfunc = NULL;
336 pad->linkfunc = NULL;
337 pad->getcapsfunc = NULL;
339 pad->activatefunc = GST_DEBUG_FUNCPTR (gst_pad_activate_default);
340 pad->eventfunc = GST_DEBUG_FUNCPTR (gst_pad_event_default);
341 pad->querytypefunc = GST_DEBUG_FUNCPTR (gst_pad_get_query_types_default);
342 pad->queryfunc = GST_DEBUG_FUNCPTR (gst_pad_query_default);
343 pad->intlinkfunc = GST_DEBUG_FUNCPTR (gst_pad_get_internal_links_default);
344 GST_PAD_ACCEPTCAPSFUNC (pad) = GST_DEBUG_FUNCPTR (gst_pad_acceptcaps_default);
346 pad->do_buffer_signals = 0;
347 pad->do_event_signals = 0;
349 GST_PAD_UNSET_FLUSHING (pad);
351 pad->preroll_lock = g_mutex_new ();
352 pad->preroll_cond = g_cond_new ();
354 pad->stream_rec_lock = g_new (GStaticRecMutex, 1);
355 g_static_rec_mutex_init (pad->stream_rec_lock);
357 pad->block_cond = g_cond_new ();
361 gst_pad_dispose (GObject * object)
363 GstPad *pad = GST_PAD (object);
365 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
366 GST_DEBUG_PAD_NAME (pad));
368 /* we don't hold a ref to the peer so we can just set the
370 GST_PAD_PEER (pad) = NULL;
373 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
375 gst_pad_set_pad_template (pad, NULL);
377 G_OBJECT_CLASS (parent_class)->dispose (object);
381 gst_pad_finalize (GObject * object)
383 GstPad *pad = GST_PAD (object);
386 /* in case the task is still around, clean it up */
387 if ((task = GST_PAD_TASK (pad))) {
388 gst_task_join (task);
389 GST_PAD_TASK (pad) = NULL;
390 gst_object_unref (task);
393 if (pad->stream_rec_lock) {
394 g_static_rec_mutex_free (pad->stream_rec_lock);
395 g_free (pad->stream_rec_lock);
396 pad->stream_rec_lock = NULL;
398 if (pad->preroll_lock) {
399 g_mutex_free (pad->preroll_lock);
400 g_cond_free (pad->preroll_cond);
401 pad->preroll_lock = NULL;
402 pad->preroll_cond = NULL;
404 if (pad->block_cond) {
405 g_cond_free (pad->block_cond);
406 pad->block_cond = NULL;
409 G_OBJECT_CLASS (parent_class)->finalize (object);
413 gst_pad_set_property (GObject * object, guint prop_id,
414 const GValue * value, GParamSpec * pspec)
416 g_return_if_fail (GST_IS_PAD (object));
419 case PAD_PROP_DIRECTION:
420 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
422 case PAD_PROP_TEMPLATE:
423 gst_pad_set_pad_template (GST_PAD_CAST (object),
424 (GstPadTemplate *) g_value_get_object (value));
427 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
433 gst_pad_get_property (GObject * object, guint prop_id,
434 GValue * value, GParamSpec * pspec)
436 g_return_if_fail (GST_IS_PAD (object));
440 g_value_set_boxed (value, GST_PAD_CAPS (object));
442 case PAD_PROP_DIRECTION:
443 g_value_set_enum (value, GST_PAD_DIRECTION (object));
445 case PAD_PROP_TEMPLATE:
446 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
449 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
456 * @name: the name of the new pad.
457 * @direction: the #GstPadDirection of the pad.
459 * Creates a new pad with the given name in the given direction.
460 * If name is NULL, a guaranteed unique name (across all pads)
462 * This function makes a copy of the name so you can safely free the name.
464 * Returns: a new #GstPad, or NULL in case of an error.
469 gst_pad_new (const gchar * name, GstPadDirection direction)
471 return g_object_new (GST_TYPE_PAD,
472 "name", name, "direction", direction, NULL);
476 * gst_pad_new_from_template:
477 * @templ: the pad template to use
478 * @name: the name of the element
480 * Creates a new pad with the given name from the given template.
481 * If name is NULL, a guaranteed unique name (across all pads)
483 * This function makes a copy of the name so you can safely free the name.
485 * Returns: a new #GstPad, or NULL in case of an error.
488 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
490 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
492 return g_object_new (GST_TYPE_PAD,
493 "name", name, "direction", templ->direction, "template", templ, NULL);
497 * gst_pad_new_from_static_template:
498 * @templ: the #GstStaticPadTemplate to use
499 * @name: the name of the element
501 * Creates a new pad with the given name from the given static template.
502 * If name is NULL, a guaranteed unique name (across all pads)
504 * This function makes a copy of the name so you can safely free the name.
506 * Returns: a new #GstPad, or NULL in case of an error.
509 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
513 GstPadTemplate *template;
515 template = gst_static_pad_template_get (templ);
516 pad = gst_pad_new_from_template (template, name);
517 gst_object_unref (template);
522 * gst_pad_get_direction:
523 * @pad: a #GstPad to get the direction of.
525 * Gets the direction of the pad. The direction of the pad is
526 * decided at construction time so this function does not take
529 * Returns: the #GstPadDirection of the pad.
534 gst_pad_get_direction (GstPad * pad)
536 GstPadDirection result;
538 /* PAD_UNKNOWN is a little silly but we need some sort of
539 * error return value */
540 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
542 GST_OBJECT_LOCK (pad);
543 result = GST_PAD_DIRECTION (pad);
544 GST_OBJECT_UNLOCK (pad);
550 gst_pad_activate_default (GstPad * pad)
552 return gst_pad_activate_push (pad, TRUE);
556 pre_activate (GstPad * pad, GstActivateMode new_mode)
559 case GST_ACTIVATE_PUSH:
560 case GST_ACTIVATE_PULL:
561 GST_OBJECT_LOCK (pad);
562 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
564 GST_PAD_UNSET_FLUSHING (pad);
565 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
566 GST_OBJECT_UNLOCK (pad);
568 case GST_ACTIVATE_NONE:
569 GST_OBJECT_LOCK (pad);
570 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing",
572 GST_PAD_SET_FLUSHING (pad);
573 /* unlock blocked pads so element can resume and stop */
574 GST_PAD_BLOCK_SIGNAL (pad);
575 GST_OBJECT_UNLOCK (pad);
581 post_activate (GstPad * pad, GstActivateMode new_mode)
584 case GST_ACTIVATE_PUSH:
585 case GST_ACTIVATE_PULL:
588 case GST_ACTIVATE_NONE:
589 /* ensures that streaming stops */
590 GST_PAD_STREAM_LOCK (pad);
591 /* while we're at it set activation mode */
592 GST_OBJECT_LOCK (pad);
593 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d", new_mode);
594 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
595 GST_OBJECT_UNLOCK (pad);
596 GST_PAD_STREAM_UNLOCK (pad);
602 * gst_pad_set_active:
603 * @pad: the #GstPad to activate or deactivate.
604 * @active: whether or not the pad should be active.
606 * Activates or deactivates the given pad.
607 * Normally called from within core state change functions.
609 * If @active, makes sure the pad is active. If it is already active, either in
610 * push or pull mode, just return. Otherwise dispatches to the pad's activate
611 * function to perform the actual activation.
613 * If not @active, checks the pad's current mode and calls
614 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
617 * Returns: #TRUE if the operation was successful.
622 gst_pad_set_active (GstPad * pad, gboolean active)
625 gboolean ret = FALSE;
627 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
629 GST_OBJECT_LOCK (pad);
630 old = GST_PAD_ACTIVATE_MODE (pad);
631 GST_OBJECT_UNLOCK (pad);
635 case GST_ACTIVATE_PUSH:
636 case GST_ACTIVATE_PULL:
639 case GST_ACTIVATE_NONE:
640 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
645 case GST_ACTIVATE_PUSH:
646 ret = gst_pad_activate_push (pad, FALSE);
648 case GST_ACTIVATE_PULL:
649 ret = gst_pad_activate_pull (pad, FALSE);
651 case GST_ACTIVATE_NONE:
657 if (!active && !ret) {
658 GST_OBJECT_LOCK (pad);
659 g_critical ("Failed to deactivate pad %s:%s, very bad",
660 GST_DEBUG_PAD_NAME (pad));
661 GST_OBJECT_UNLOCK (pad);
668 * gst_pad_activate_pull:
669 * @pad: the #GstPad to activate or deactivate.
670 * @active: whether or not the pad should be active.
672 * Activates or deactivates the given pad in pull mode via dispatching to the
673 * pad's activatepullfunc. For use from within pad activation functions only.
674 * When called on sink pads, will first proxy the call to the peer pad, which is
675 * expected to activate its internally linked pads from within its activate_pull
678 * If you don't know what this is, you probably don't want to call it.
680 * Returns: TRUE if the operation was successful.
685 gst_pad_activate_pull (GstPad * pad, gboolean active)
687 GstActivateMode old, new;
690 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
692 GST_OBJECT_LOCK (pad);
693 old = GST_PAD_ACTIVATE_MODE (pad);
694 GST_OBJECT_UNLOCK (pad);
696 if ((active && old == GST_ACTIVATE_PULL)
697 || (!active && old == GST_ACTIVATE_NONE))
701 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
703 g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE);
706 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
707 if ((peer = gst_pad_get_peer (pad))) {
708 if (!gst_pad_activate_pull (peer, active))
710 gst_object_unref (peer);
713 if (GST_PAD_GETRANGEFUNC (pad) == NULL)
714 goto failure; /* Can't activate pull on a src without a
718 new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
719 pre_activate (pad, new);
721 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
722 if (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active))
725 /* can happen for sinks of passthrough elements */
728 post_activate (pad, new);
730 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
731 active ? "activated" : "deactivated");
736 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
737 active ? "activated" : "deactivated");
742 GST_OBJECT_LOCK (peer);
743 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
744 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
745 GST_OBJECT_UNLOCK (peer);
746 gst_object_unref (peer);
751 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
752 active ? "activate" : "deactivate");
753 pre_activate (pad, GST_ACTIVATE_NONE);
754 post_activate (pad, GST_ACTIVATE_NONE);
760 * gst_pad_activate_push:
761 * @pad: the #GstPad to activate or deactivate.
762 * @active: whether or not the pad should be active.
764 * Activates or deactivates the given pad in push mode via dispatching to the
765 * pad's activatepushfunc. For use from within pad activation functions only.
767 * If you don't know what this is, you probably don't want to call it.
769 * Returns: TRUE if the operation was successfull.
774 gst_pad_activate_push (GstPad * pad, gboolean active)
776 GstActivateMode old, new;
778 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
779 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
780 active ? "activated" : "deactivated");
782 GST_OBJECT_LOCK (pad);
783 old = GST_PAD_ACTIVATE_MODE (pad);
784 GST_OBJECT_UNLOCK (pad);
786 if ((active && old == GST_ACTIVATE_PUSH)
787 || (!active && old == GST_ACTIVATE_NONE))
791 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
793 g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE);
796 new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
797 pre_activate (pad, new);
799 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
800 if (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) {
804 /* quite ok, element relies on state change func to prepare itself */
807 post_activate (pad, new);
809 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
810 active ? "activated" : "deactivated");
815 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
816 active ? "activated" : "deactivated");
821 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
822 active ? "activate" : "deactivate");
823 pre_activate (pad, GST_ACTIVATE_NONE);
824 post_activate (pad, GST_ACTIVATE_NONE);
831 * @pad: the #GstPad to query
833 * Query if a pad is active
835 * Returns: TRUE if the pad is active.
840 gst_pad_is_active (GstPad * pad)
842 gboolean result = FALSE;
844 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
846 GST_OBJECT_LOCK (pad);
847 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
848 GST_OBJECT_UNLOCK (pad);
854 * gst_pad_set_blocked_async:
855 * @pad: the #GstPad to block or unblock
856 * @blocked: boolean indicating whether the pad should be blocked or unblocked
857 * @callback: #GstPadBlockCallback that will be called when the
859 * @user_data: user data passed to the callback
861 * Blocks or unblocks the dataflow on a pad. The provided callback
862 * is called when the operation succeeds; this happens right before the next
863 * attempt at pushing a buffer on the pad.
865 * This can take a while as the pad can only become blocked when real dataflow
867 * When the pipeline is stalled, for example in PAUSED, this can
868 * take an indeterminate amount of time.
869 * You can pass NULL as the callback to make this call block. Be careful with
870 * this blocking call as it might not return for reasons stated above.
872 * Returns: TRUE if the pad could be blocked. This function can fail
873 * if wrong parameters were passed or the pad was already in the
879 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
880 GstPadBlockCallback callback, gpointer user_data)
882 gboolean was_blocked, was_ghost = FALSE;
884 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
886 if (GST_IS_GHOST_PAD (pad)) {
887 pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
894 GST_OBJECT_LOCK (pad);
896 was_blocked = GST_PAD_IS_BLOCKED (pad);
898 if (G_UNLIKELY (was_blocked == blocked))
899 goto had_right_state;
902 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad %s:%s",
903 GST_DEBUG_PAD_NAME (pad));
905 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
906 pad->block_callback = callback;
907 pad->block_data = user_data;
909 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
910 GST_PAD_BLOCK_WAIT (pad);
911 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
914 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad %s:%s",
915 GST_DEBUG_PAD_NAME (pad));
917 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
919 pad->block_callback = callback;
920 pad->block_data = user_data;
923 GST_PAD_BLOCK_SIGNAL (pad);
925 GST_PAD_BLOCK_SIGNAL (pad);
926 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
927 GST_PAD_BLOCK_WAIT (pad);
928 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
931 GST_OBJECT_UNLOCK (pad);
934 gst_object_unref (pad);
941 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
942 "pad %s:%s was in right state (%d)", GST_DEBUG_PAD_NAME (pad),
944 GST_OBJECT_UNLOCK (pad);
947 gst_object_unref (pad);
954 * gst_pad_set_blocked:
955 * @pad: the #GstPad to block or unblock
956 * @blocked: boolean indicating we should block or unblock
958 * Blocks or unblocks the dataflow on a pad. This function is
959 * a shortcut for gst_pad_set_blocked_async() with a NULL
962 * Returns: TRUE if the pad could be blocked. This function can fail
963 * wrong parameters were passed or the pad was already in the
969 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
971 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
975 * gst_pad_is_blocked:
976 * @pad: the #GstPad to query
978 * Checks if the pad is blocked or not. This function returns the
979 * last requested state of the pad. It is not certain that the pad
980 * is actually blocked at this point.
982 * Returns: TRUE if the pad is blocked.
987 gst_pad_is_blocked (GstPad * pad)
989 gboolean result = FALSE;
991 g_return_val_if_fail (GST_IS_PAD (pad), result);
993 GST_OBJECT_LOCK (pad);
994 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
995 GST_OBJECT_UNLOCK (pad);
1001 * gst_pad_set_activate_function:
1002 * @pad: a sink #GstPad.
1003 * @activate: the #GstPadActivateFunction to set.
1005 * Sets the given activate function for the pad. The activate function will
1006 * dispatch to activate_push or activate_pull to perform the actual activation.
1007 * Only makes sense to set on sink pads.
1009 * Call this function if your sink pad can start a pull-based task.
1012 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1014 g_return_if_fail (GST_IS_PAD (pad));
1016 GST_PAD_ACTIVATEFUNC (pad) = activate;
1017 GST_CAT_DEBUG (GST_CAT_PADS, "activatefunc for %s:%s set to %s",
1018 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activate));
1022 * gst_pad_set_activatepull_function:
1023 * @pad: a sink #GstPad.
1024 * @activatepull: the #GstPadActivateModeFunction to set.
1026 * Sets the given activate_pull function for the pad. An activate_pull function
1027 * prepares the element and any upstream connections for pulling. See XXX
1028 * part-activation.txt for details.
1031 gst_pad_set_activatepull_function (GstPad * pad,
1032 GstPadActivateModeFunction activatepull)
1034 g_return_if_fail (GST_IS_PAD (pad));
1036 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1037 GST_CAT_DEBUG (GST_CAT_PADS, "activatepullfunc for %s:%s set to %s",
1038 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepull));
1042 * gst_pad_set_activatepush_function:
1043 * @pad: a sink #GstPad.
1044 * @activatepush: the #GstPadActivateModeFunction to set.
1046 * Sets the given activate_push function for the pad. An activate_push function
1047 * prepares the element for pushing. See XXX part-activation.txt for details.
1050 gst_pad_set_activatepush_function (GstPad * pad,
1051 GstPadActivateModeFunction activatepush)
1053 g_return_if_fail (GST_IS_PAD (pad));
1055 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1056 GST_CAT_DEBUG (GST_CAT_PADS, "activatepushfunc for %s:%s set to %s",
1057 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepush));
1061 * gst_pad_set_chain_function:
1062 * @pad: a sink #GstPad.
1063 * @chain: the #GstPadChainFunction to set.
1065 * Sets the given chain function for the pad. The chain function is called to
1066 * process a #GstBuffer input buffer.
1069 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1071 g_return_if_fail (GST_IS_PAD (pad));
1072 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
1074 GST_PAD_CHAINFUNC (pad) = chain;
1075 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
1076 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
1080 * gst_pad_set_getrange_function:
1081 * @pad: a source #GstPad.
1082 * @get: the #GstPadGetRangeFunction to set.
1084 * Sets the given getrange function for the pad. The getrange function is called to
1085 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
1089 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1091 g_return_if_fail (GST_IS_PAD (pad));
1092 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1094 GST_PAD_GETRANGEFUNC (pad) = get;
1096 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
1097 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
1101 * gst_pad_set_checkgetrange_function:
1102 * @pad: a source #GstPad.
1103 * @check: the #GstPadCheckGetRangeFunction to set.
1105 * Sets the given checkgetrange function for the pad. Implement this function on
1106 * a pad if you dynamically support getrange based scheduling on the pad.
1109 gst_pad_set_checkgetrange_function (GstPad * pad,
1110 GstPadCheckGetRangeFunction check)
1112 g_return_if_fail (GST_IS_PAD (pad));
1113 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1115 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
1117 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
1118 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
1122 * gst_pad_set_event_function:
1123 * @pad: a source #GstPad.
1124 * @event: the #GstPadEventFunction to set.
1126 * Sets the given event handler for the pad.
1129 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1131 g_return_if_fail (GST_IS_PAD (pad));
1133 GST_PAD_EVENTFUNC (pad) = event;
1135 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
1136 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
1140 * gst_pad_set_query_function:
1141 * @pad: a #GstPad of either direction.
1142 * @query: the #GstPadQueryFunction to set.
1144 * Set the given query function for the pad.
1147 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1149 g_return_if_fail (GST_IS_PAD (pad));
1151 GST_PAD_QUERYFUNC (pad) = query;
1153 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
1154 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
1158 * gst_pad_set_query_type_function:
1159 * @pad: a #GstPad of either direction.
1160 * @type_func: the #GstPadQueryTypeFunction to set.
1162 * Set the given query type function for the pad.
1165 gst_pad_set_query_type_function (GstPad * pad,
1166 GstPadQueryTypeFunction type_func)
1168 g_return_if_fail (GST_IS_PAD (pad));
1170 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1172 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
1173 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
1177 * gst_pad_get_query_types:
1180 * Get an array of supported queries that can be performed
1183 * Returns: a zero-terminated array of #GstQueryType.
1185 const GstQueryType *
1186 gst_pad_get_query_types (GstPad * pad)
1188 GstPadQueryTypeFunction func;
1190 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1192 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1204 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1206 *data = gst_pad_get_query_types (pad);
1212 * gst_pad_get_query_types_default:
1215 * Invoke the default dispatcher for the query types on
1218 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1219 * internally-linked pads has a query types function.
1221 const GstQueryType *
1222 gst_pad_get_query_types_default (GstPad * pad)
1224 GstQueryType *result = NULL;
1226 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1228 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1229 gst_pad_get_query_types_dispatcher, &result);
1235 * gst_pad_set_internal_link_function:
1236 * @pad: a #GstPad of either direction.
1237 * @intlink: the #GstPadIntLinkFunction to set.
1239 * Sets the given internal link function for the pad.
1242 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1244 g_return_if_fail (GST_IS_PAD (pad));
1246 GST_PAD_INTLINKFUNC (pad) = intlink;
1247 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1248 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1252 * gst_pad_set_link_function:
1254 * @link: the #GstPadLinkFunction to set.
1256 * Sets the given link function for the pad. It will be called when
1257 * the pad is linked with another pad.
1259 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1262 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1263 * cannot be made for some reason.
1265 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1266 * of the peer sink pad, if present.
1269 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1271 g_return_if_fail (GST_IS_PAD (pad));
1273 GST_PAD_LINKFUNC (pad) = link;
1274 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1275 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1279 * gst_pad_set_unlink_function:
1281 * @unlink: the #GstPadUnlinkFunction to set.
1283 * Sets the given unlink function for the pad. It will be called
1284 * when the pad is unlinked.
1287 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1289 g_return_if_fail (GST_IS_PAD (pad));
1291 GST_PAD_UNLINKFUNC (pad) = unlink;
1292 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1293 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1297 * gst_pad_set_getcaps_function:
1299 * @getcaps: the #GstPadGetCapsFunction to set.
1301 * Sets the given getcaps function for the pad. @getcaps should return the
1302 * allowable caps for a pad in the context of the element's state, its link to
1303 * other elements, and the devices or files it has opened. These caps must be a
1304 * subset of the pad template caps. In the NULL state with no links, @getcaps
1305 * should ideally return the same caps as the pad template. In rare
1306 * circumstances, an object property can affect the caps returned by @getcaps,
1307 * but this is discouraged.
1309 * You do not need to call this function if @pad's allowed caps are always the
1310 * same as the pad template caps. This can only be true if the padtemplate
1311 * has fixed simple caps.
1313 * For most filters, the caps returned by @getcaps is directly affected by the
1314 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1315 * the srcpad's getcaps function is directly related to the stream data. Again,
1316 * @getcaps should return the most specific caps it reasonably can, since this
1317 * helps with autoplugging.
1319 * Note that the return value from @getcaps is owned by the caller, so the caller
1320 * should unref the caps after usage.
1323 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1325 g_return_if_fail (GST_IS_PAD (pad));
1327 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1328 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1329 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1333 * gst_pad_set_acceptcaps_function:
1335 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1337 * Sets the given acceptcaps function for the pad. The acceptcaps function
1338 * will be called to check if the pad can accept the given caps. Setting the
1339 * acceptcaps function to NULL restores the default behaviour of allowing
1340 * any caps that matches the caps from gst_pad_get_caps.
1343 gst_pad_set_acceptcaps_function (GstPad * pad,
1344 GstPadAcceptCapsFunction acceptcaps)
1346 g_return_if_fail (GST_IS_PAD (pad));
1348 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1349 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1350 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1354 * gst_pad_set_fixatecaps_function:
1356 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1358 * Sets the given fixatecaps function for the pad. The fixatecaps function
1359 * will be called whenever the default values for a GstCaps needs to be
1363 gst_pad_set_fixatecaps_function (GstPad * pad,
1364 GstPadFixateCapsFunction fixatecaps)
1366 g_return_if_fail (GST_IS_PAD (pad));
1368 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1369 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1370 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1374 * gst_pad_set_setcaps_function:
1376 * @setcaps: the #GstPadSetCapsFunction to set.
1378 * Sets the given setcaps function for the pad. The setcaps function
1379 * will be called whenever a buffer with a new media type is pushed or
1380 * pulled from the pad. The pad/element needs to update it's internal
1381 * structures to process the new media type. If this new type is not
1382 * acceptable, the setcaps function should return FALSE.
1385 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1387 g_return_if_fail (GST_IS_PAD (pad));
1389 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1390 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1391 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1395 * gst_pad_set_bufferalloc_function:
1396 * @pad: a sink #GstPad.
1397 * @bufalloc: the #GstPadBufferAllocFunction to set.
1399 * Sets the given bufferalloc function for the pad. Note that the
1400 * bufferalloc function can only be set on sinkpads.
1403 gst_pad_set_bufferalloc_function (GstPad * pad,
1404 GstPadBufferAllocFunction bufalloc)
1406 g_return_if_fail (GST_IS_PAD (pad));
1407 g_return_if_fail (GST_PAD_IS_SINK (pad));
1409 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1410 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1411 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1416 * @srcpad: the source #GstPad to unlink.
1417 * @sinkpad: the sink #GstPad to unlink.
1419 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1422 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1423 * the pads were not linked together.
1428 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1430 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1431 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1433 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1434 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1435 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1437 GST_OBJECT_LOCK (srcpad);
1439 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1442 GST_OBJECT_LOCK (sinkpad);
1444 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1447 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1448 goto not_linked_together;
1450 if (GST_PAD_UNLINKFUNC (srcpad)) {
1451 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1453 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1454 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1457 /* first clear peers */
1458 GST_PAD_PEER (srcpad) = NULL;
1459 GST_PAD_PEER (sinkpad) = NULL;
1461 GST_OBJECT_UNLOCK (sinkpad);
1462 GST_OBJECT_UNLOCK (srcpad);
1464 /* fire off a signal to each of the pads telling them
1465 * that they've been unlinked */
1466 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1467 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1469 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1470 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1476 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1477 GST_OBJECT_UNLOCK (srcpad);
1482 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1483 GST_OBJECT_UNLOCK (sinkpad);
1484 GST_OBJECT_UNLOCK (srcpad);
1487 not_linked_together:
1489 /* we do not emit a warning in this case because unlinking cannot
1490 * be made MT safe.*/
1491 GST_OBJECT_UNLOCK (sinkpad);
1492 GST_OBJECT_UNLOCK (srcpad);
1498 * gst_pad_is_linked:
1499 * @pad: pad to check
1501 * Checks if a @pad is linked to another pad or not.
1503 * Returns: TRUE if the pad is linked, FALSE otherwise.
1508 gst_pad_is_linked (GstPad * pad)
1512 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1514 GST_OBJECT_LOCK (pad);
1515 result = (GST_PAD_PEER (pad) != NULL);
1516 GST_OBJECT_UNLOCK (pad);
1521 /* get the caps from both pads and see if the intersection
1524 * This function should be called with the pad LOCK on both
1528 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1534 srccaps = gst_pad_get_caps_unlocked (src);
1535 sinkcaps = gst_pad_get_caps_unlocked (sink);
1537 GST_CAT_DEBUG (GST_CAT_CAPS, "src caps %" GST_PTR_FORMAT, srccaps);
1538 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1540 /* if we have caps on both pads we can check the intersection. If one
1541 * of the caps is NULL, we return TRUE. */
1542 if (srccaps == NULL || sinkcaps == NULL)
1545 icaps = gst_caps_intersect (srccaps, sinkcaps);
1546 gst_caps_unref (srccaps);
1547 gst_caps_unref (sinkcaps);
1552 GST_CAT_DEBUG (GST_CAT_CAPS,
1553 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1555 if (gst_caps_is_empty (icaps))
1558 gst_caps_unref (icaps);
1563 /* incompatible cases */
1566 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection gave NULL");
1571 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is EMPTY");
1572 gst_caps_unref (icaps);
1577 /* check if the grandparents of both pads are the same.
1578 * This check is required so that we don't try to link
1579 * pads from elements in different bins without ghostpads.
1581 * The LOCK should be helt on both pads
1584 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1586 GstObject *psrc, *psink;
1587 gboolean res = TRUE;
1589 psrc = GST_OBJECT_PARENT (src);
1590 psink = GST_OBJECT_PARENT (sink);
1592 /* if one of the pads has no parent, we allow the link */
1593 if (psrc && psink) {
1594 /* if the parents are the same, we have a loop */
1595 if (psrc == psink) {
1596 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1601 /* if they both have a parent, we check the grandparents */
1602 psrc = gst_object_get_parent (psrc);
1603 psink = gst_object_get_parent (psink);
1605 if (psrc != psink) {
1606 /* if they have grandparents but they are not the same */
1607 GST_CAT_DEBUG (GST_CAT_CAPS,
1608 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1609 GST_PTR_FORMAT, psrc, psink);
1613 gst_object_unref (psrc);
1615 gst_object_unref (psink);
1621 /* FIXME leftover from an attempt at refactoring... */
1622 /* call with the two pads unlocked */
1623 static GstPadLinkReturn
1624 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1626 /* generic checks */
1627 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1628 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1630 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1631 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1633 GST_OBJECT_LOCK (srcpad);
1635 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1638 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1639 goto src_was_linked;
1641 GST_OBJECT_LOCK (sinkpad);
1643 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1646 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1647 goto sink_was_linked;
1649 /* check hierarchy, pads can only be linked if the grandparents
1651 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1652 goto wrong_hierarchy;
1654 /* check pad caps for non-empty intersection */
1655 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1658 /* FIXME check pad scheduling for non-empty intersection */
1660 return GST_PAD_LINK_OK;
1664 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1665 GST_OBJECT_UNLOCK (srcpad);
1666 return GST_PAD_LINK_WRONG_DIRECTION;
1670 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked",
1671 GST_DEBUG_PAD_NAME (srcpad));
1672 /* we do not emit a warning in this case because unlinking cannot
1673 * be made MT safe.*/
1674 GST_OBJECT_UNLOCK (srcpad);
1675 return GST_PAD_LINK_WAS_LINKED;
1679 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1680 GST_OBJECT_UNLOCK (sinkpad);
1681 GST_OBJECT_UNLOCK (srcpad);
1682 return GST_PAD_LINK_WRONG_DIRECTION;
1686 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked",
1687 GST_DEBUG_PAD_NAME (sinkpad));
1688 /* we do not emit a warning in this case because unlinking cannot
1689 * be made MT safe.*/
1690 GST_OBJECT_UNLOCK (sinkpad);
1691 GST_OBJECT_UNLOCK (srcpad);
1692 return GST_PAD_LINK_WAS_LINKED;
1696 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1697 GST_OBJECT_UNLOCK (sinkpad);
1698 GST_OBJECT_UNLOCK (srcpad);
1699 return GST_PAD_LINK_WRONG_HIERARCHY;
1703 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1704 GST_OBJECT_UNLOCK (sinkpad);
1705 GST_OBJECT_UNLOCK (srcpad);
1706 return GST_PAD_LINK_NOFORMAT;
1712 * @srcpad: the source #GstPad to link.
1713 * @sinkpad: the sink #GstPad to link.
1715 * Links the source pad and the sink pad.
1717 * Returns: A result code indicating if the connection worked or
1723 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1725 GstPadLinkReturn result;
1727 /* prepare will also lock the two pads */
1728 result = gst_pad_link_prepare (srcpad, sinkpad);
1730 if (result != GST_PAD_LINK_OK)
1731 goto prepare_failed;
1733 GST_OBJECT_UNLOCK (sinkpad);
1734 GST_OBJECT_UNLOCK (srcpad);
1736 /* FIXME released the locks here, concurrent thread might link
1737 * something else. */
1738 if (GST_PAD_LINKFUNC (srcpad)) {
1739 /* this one will call the peer link function */
1740 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1741 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1742 /* if no source link function, we need to call the sink link
1743 * function ourselves. */
1744 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1746 result = GST_PAD_LINK_OK;
1749 GST_OBJECT_LOCK (srcpad);
1750 GST_OBJECT_LOCK (sinkpad);
1752 if (result == GST_PAD_LINK_OK) {
1753 GST_PAD_PEER (srcpad) = sinkpad;
1754 GST_PAD_PEER (sinkpad) = srcpad;
1756 GST_OBJECT_UNLOCK (sinkpad);
1757 GST_OBJECT_UNLOCK (srcpad);
1759 /* fire off a signal to each of the pads telling them
1760 * that they've been linked */
1761 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1762 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1764 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1765 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1767 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1768 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1770 GST_OBJECT_UNLOCK (sinkpad);
1771 GST_OBJECT_UNLOCK (srcpad);
1782 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1784 GstPadTemplate **template_p;
1786 /* this function would need checks if it weren't static */
1788 GST_OBJECT_LOCK (pad);
1789 template_p = &pad->padtemplate;
1790 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
1791 GST_OBJECT_UNLOCK (pad);
1794 gst_pad_template_pad_created (templ, pad);
1798 * gst_pad_get_pad_template:
1801 * Gets the template for @pad.
1803 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1804 * if this pad has no template.
1806 * FIXME: currently returns an unrefcounted padtemplate.
1809 gst_pad_get_pad_template (GstPad * pad)
1811 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1813 return GST_PAD_PAD_TEMPLATE (pad);
1817 /* should be called with the pad LOCK held */
1818 /* refs the caps, so caller is responsible for getting it unreffed */
1820 gst_pad_get_caps_unlocked (GstPad * pad)
1822 GstCaps *result = NULL;
1824 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1825 GST_DEBUG_PAD_NAME (pad), pad);
1827 if (GST_PAD_GETCAPSFUNC (pad)) {
1828 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1830 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1831 GST_OBJECT_UNLOCK (pad);
1832 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1833 GST_OBJECT_LOCK (pad);
1834 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1836 if (result == NULL) {
1837 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1838 GST_DEBUG_PAD_NAME (pad));
1840 GST_CAT_DEBUG (GST_CAT_CAPS,
1841 "pad getcaps %s:%s returned %" GST_PTR_FORMAT,
1842 GST_DEBUG_PAD_NAME (pad), result);
1843 #ifndef G_DISABLE_ASSERT
1844 /* check that the returned caps are a real subset of the template caps */
1845 if (GST_PAD_PAD_TEMPLATE (pad)) {
1846 const GstCaps *templ_caps =
1847 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1848 if (!gst_caps_is_subset (result, templ_caps)) {
1851 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1852 "pad returned caps %" GST_PTR_FORMAT
1853 " which are not a real subset of its template caps %"
1854 GST_PTR_FORMAT, result, templ_caps);
1856 ("pad %s:%s returned caps that are not a real subset of its template caps",
1857 GST_DEBUG_PAD_NAME (pad));
1858 temp = gst_caps_intersect (templ_caps, result);
1859 gst_caps_unref (result);
1867 if (GST_PAD_PAD_TEMPLATE (pad)) {
1868 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1870 result = GST_PAD_TEMPLATE_CAPS (templ);
1871 GST_CAT_DEBUG (GST_CAT_CAPS,
1872 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1875 result = gst_caps_ref (result);
1878 if (GST_PAD_CAPS (pad)) {
1879 result = GST_PAD_CAPS (pad);
1881 GST_CAT_DEBUG (GST_CAT_CAPS,
1882 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1884 result = gst_caps_ref (result);
1888 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1889 result = gst_caps_new_empty ();
1897 * @pad: a #GstPad to get the capabilities of.
1899 * Gets the capabilities this pad can produce or consume.
1900 * Note that this method doesn't necessarily returns the caps set by
1901 * gst_pad_set_caps() - use #GST_PAD_CAPS for that instead.
1902 * gst_pad_get_caps returns all possible caps a pad can operate with, using
1903 * the pad's get_caps function;
1904 * this returns the pad template caps if not explicitly set.
1906 * Returns: a newly allocated copy of the #GstCaps of this pad.
1911 gst_pad_get_caps (GstPad * pad)
1913 GstCaps *result = NULL;
1915 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1917 GST_OBJECT_LOCK (pad);
1919 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1920 GST_DEBUG_PAD_NAME (pad), pad);
1922 result = gst_pad_get_caps_unlocked (pad);
1923 GST_OBJECT_UNLOCK (pad);
1929 * gst_pad_peer_get_caps:
1930 * @pad: a #GstPad to get the peer capabilities of.
1932 * Gets the capabilities of the peer connected to this pad.
1934 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1935 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1939 gst_pad_peer_get_caps (GstPad * pad)
1942 GstCaps *result = NULL;
1944 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1946 GST_OBJECT_LOCK (pad);
1948 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1949 GST_DEBUG_PAD_NAME (pad), pad);
1951 peerpad = GST_PAD_PEER (pad);
1952 if (G_UNLIKELY (peerpad == NULL))
1955 gst_object_ref (peerpad);
1956 GST_OBJECT_UNLOCK (pad);
1958 result = gst_pad_get_caps (peerpad);
1960 gst_object_unref (peerpad);
1966 GST_OBJECT_UNLOCK (pad);
1972 fixate_value (GValue * dest, const GValue * src)
1974 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
1975 g_value_init (dest, G_TYPE_INT);
1976 g_value_set_int (dest, gst_value_get_int_range_min (src));
1977 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
1978 g_value_init (dest, G_TYPE_DOUBLE);
1979 g_value_set_double (dest, gst_value_get_double_range_min (src));
1980 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
1981 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
1982 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1983 GValue temp = { 0 };
1985 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
1986 if (!fixate_value (dest, &temp))
1987 gst_value_init_and_copy (dest, &temp);
1988 g_value_unset (&temp);
1989 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
1990 gboolean res = FALSE;
1993 g_value_init (dest, GST_TYPE_ARRAY);
1994 for (n = 0; n < gst_value_array_get_size (src); n++) {
1996 const GValue *orig_kid = gst_value_array_get_value (src, n);
1998 if (!fixate_value (&kid, orig_kid))
1999 gst_value_init_and_copy (&kid, orig_kid);
2002 gst_value_array_append_value (dest, &kid);
2003 g_value_unset (&kid);
2007 g_value_unset (dest);
2018 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
2020 GstStructure *s = data;
2023 if (fixate_value (&v, value)) {
2024 gst_structure_id_set_value (s, field_id, &v);
2032 * gst_pad_fixate_caps:
2033 * @pad: a #GstPad to fixate
2034 * @caps: the #GstCaps to fixate
2036 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2037 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2040 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2042 GstPadFixateCapsFunction fixatefunc;
2045 g_return_if_fail (GST_IS_PAD (pad));
2046 g_return_if_fail (caps != NULL);
2048 if (gst_caps_is_fixed (caps))
2051 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
2053 fixatefunc (pad, caps);
2056 /* default fixation */
2057 for (n = 0; n < gst_caps_get_size (caps); n++) {
2058 GstStructure *s = gst_caps_get_structure (caps, n);
2060 gst_structure_foreach (s, gst_pad_default_fixate, s);
2064 /* Default accept caps implementation just checks against
2065 * against the allowed caps for the pad */
2067 gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
2069 /* get the caps and see if it intersects to something
2073 gboolean result = FALSE;
2075 allowed = gst_pad_get_caps (pad);
2077 intersect = gst_caps_intersect (allowed, caps);
2079 result = !gst_caps_is_empty (intersect);
2081 gst_caps_unref (allowed);
2082 gst_caps_unref (intersect);
2089 * gst_pad_accept_caps:
2090 * @pad: a #GstPad to check
2091 * @caps: a #GstCaps to check on the pad
2093 * Check if the given pad accepts the caps.
2095 * Returns: TRUE if the pad can accept the caps.
2098 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2101 GstPadAcceptCapsFunction acceptfunc;
2102 GstCaps *existing = NULL;
2104 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2106 /* any pad can be unnegotiated */
2110 GST_OBJECT_LOCK (pad);
2111 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2112 if (GST_PAD_CAPS (pad) != NULL)
2113 existing = gst_caps_ref (GST_PAD_CAPS (pad));
2115 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
2116 GST_DEBUG_PAD_NAME (pad), pad);
2117 GST_OBJECT_UNLOCK (pad);
2119 /* The current caps on a pad are trivially acceptable */
2121 if (caps == existing || gst_caps_is_equal (caps, existing))
2123 gst_caps_unref (existing);
2126 if (G_LIKELY (acceptfunc)) {
2127 /* we can call the function */
2128 result = acceptfunc (pad, caps);
2130 /* Only null if the element explicitly unset it */
2131 result = gst_pad_acceptcaps_default (pad, caps);
2136 gst_caps_unref (existing);
2141 * gst_pad_peer_accept_caps:
2142 * @pad: a #GstPad to check
2143 * @caps: a #GstCaps to check on the pad
2145 * Check if the given pad accepts the caps.
2147 * Returns: TRUE if the pad can accept the caps.
2150 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2155 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2157 GST_OBJECT_LOCK (pad);
2159 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
2160 GST_DEBUG_PAD_NAME (pad), pad);
2162 peerpad = GST_PAD_PEER (pad);
2163 if (G_UNLIKELY (peerpad == NULL))
2166 result = gst_pad_accept_caps (peerpad, caps);
2167 GST_OBJECT_UNLOCK (pad);
2173 GST_OBJECT_UNLOCK (pad);
2180 * @pad: a #GstPad to set the capabilities of.
2181 * @caps: a #GstCaps to set.
2183 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2184 * caps on the pad will be unreffed. This function refs the caps so you should
2185 * unref if as soon as you don't need it anymore.
2186 * It is possible to set NULL caps, which will make the pad unnegotiated
2189 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2190 * or bad parameters were provided to this function.
2195 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2197 GstPadSetCapsFunction setcaps;
2200 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2201 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2203 GST_OBJECT_LOCK (pad);
2204 setcaps = GST_PAD_SETCAPSFUNC (pad);
2206 existing = GST_PAD_CAPS (pad);
2207 if (gst_caps_is_equal (caps, existing))
2208 goto setting_same_caps;
2210 /* call setcaps function to configure the pad only if the
2211 * caps is not NULL */
2212 if (setcaps != NULL && caps) {
2213 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2214 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2215 GST_OBJECT_UNLOCK (pad);
2216 if (!setcaps (pad, caps))
2218 GST_OBJECT_LOCK (pad);
2219 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2221 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
2222 GST_DEBUG_PAD_NAME (pad));
2226 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2227 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
2228 GST_DEBUG_PAD_NAME (pad), caps);
2229 GST_OBJECT_UNLOCK (pad);
2231 g_object_notify (G_OBJECT (pad), "caps");
2237 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2238 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2239 "caps %" GST_PTR_FORMAT " same as existing, updating ptr only", caps);
2240 GST_OBJECT_UNLOCK (pad);
2247 GST_OBJECT_LOCK (pad);
2248 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2249 GST_CAT_DEBUG (GST_CAT_CAPS,
2250 "pad %s:%s, caps %" GST_PTR_FORMAT " could not be set",
2251 GST_DEBUG_PAD_NAME (pad), caps);
2252 GST_OBJECT_UNLOCK (pad);
2259 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2261 GstPadSetCapsFunction setcaps;
2264 setcaps = GST_PAD_SETCAPSFUNC (pad);
2266 /* See if pad accepts the caps - only needed if
2267 * no setcaps function */
2268 if (setcaps == NULL)
2269 if (!gst_pad_accept_caps (pad, caps))
2272 /* set caps on pad if call succeeds */
2273 res = gst_pad_set_caps (pad, caps);
2274 /* no need to unref the caps here, set_caps takes a ref and
2275 * our ref goes away when we leave this function. */
2281 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2286 /* returns TRUE if the src pad could be configured to accept the given caps */
2288 gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
2290 GstPadSetCapsFunction setcaps;
2293 setcaps = GST_PAD_SETCAPSFUNC (pad);
2295 /* See if pad accepts the caps - only needed if
2296 * no setcaps function */
2297 if (setcaps == NULL)
2298 if (!gst_pad_accept_caps (pad, caps))
2302 res = gst_pad_set_caps (pad, caps);
2310 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2316 * gst_pad_get_pad_template_caps:
2317 * @pad: a #GstPad to get the template capabilities from.
2319 * Gets the capabilities for @pad's template.
2321 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2322 * on the caps, make a copy (see gst_caps_copy ()).
2325 gst_pad_get_pad_template_caps (GstPad * pad)
2327 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2329 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2331 if (GST_PAD_PAD_TEMPLATE (pad))
2332 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2334 return gst_static_caps_get (&anycaps);
2340 * @pad: a #GstPad to get the peer of.
2342 * Gets the peer of @pad. This function refs the peer pad so
2343 * you need to unref it after use.
2345 * Returns: the peer #GstPad. Unref after usage.
2350 gst_pad_get_peer (GstPad * pad)
2354 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2356 GST_OBJECT_LOCK (pad);
2357 result = GST_PAD_PEER (pad);
2359 gst_object_ref (result);
2360 GST_OBJECT_UNLOCK (pad);
2366 * gst_pad_get_allowed_caps:
2367 * @srcpad: a #GstPad, it must a a source pad.
2369 * Gets the capabilities of the allowed media types that can flow through
2370 * @srcpad and its peer. The pad must be a source pad.
2371 * The caller must free the resulting caps.
2373 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2374 * you no longer need it. This function returns NULL when the @srcpad has no
2380 gst_pad_get_allowed_caps (GstPad * srcpad)
2387 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2388 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2390 GST_OBJECT_LOCK (srcpad);
2392 peer = GST_PAD_PEER (srcpad);
2393 if (G_UNLIKELY (peer == NULL))
2396 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2397 GST_DEBUG_PAD_NAME (srcpad));
2399 gst_object_ref (peer);
2400 GST_OBJECT_UNLOCK (srcpad);
2401 mycaps = gst_pad_get_caps (srcpad);
2403 peercaps = gst_pad_get_caps (peer);
2404 gst_object_unref (peer);
2406 caps = gst_caps_intersect (mycaps, peercaps);
2407 gst_caps_unref (peercaps);
2408 gst_caps_unref (mycaps);
2410 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2416 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2417 GST_DEBUG_PAD_NAME (srcpad));
2418 GST_OBJECT_UNLOCK (srcpad);
2425 * gst_pad_get_negotiated_caps:
2428 * Gets the capabilities of the media type that currently flows through @pad
2431 * This function can be used on both src and sinkpads. Note that srcpads are
2432 * always negotiated before sinkpads so it is possible that the negotiated caps
2433 * on the srcpad do not match the negotiated caps of the peer.
2435 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2436 * you no longer need it. This function returns NULL when the @pad has no
2437 * peer or is not negotiated yet.
2442 gst_pad_get_negotiated_caps (GstPad * pad)
2447 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2449 GST_OBJECT_LOCK (pad);
2451 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2454 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2455 GST_DEBUG_PAD_NAME (pad));
2457 caps = GST_PAD_CAPS (pad);
2459 gst_caps_ref (caps);
2460 GST_OBJECT_UNLOCK (pad);
2462 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2468 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2469 GST_DEBUG_PAD_NAME (pad));
2470 GST_OBJECT_UNLOCK (pad);
2476 static GstFlowReturn
2477 gst_pad_alloc_buffer_full (GstPad * pad, guint64 offset, gint size,
2478 GstCaps * caps, GstBuffer ** buf, gboolean setcaps)
2482 GstPadBufferAllocFunction bufferallocfunc;
2483 gboolean caps_changed;
2485 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2486 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2487 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2489 GST_OBJECT_LOCK (pad);
2490 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2491 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
2494 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2497 gst_object_ref (peer);
2498 GST_OBJECT_UNLOCK (pad);
2500 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2503 GST_OBJECT_LOCK (peer);
2504 /* when the peer is flushing we cannot give a buffer */
2505 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2508 if (offset == GST_BUFFER_OFFSET_NONE) {
2509 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2510 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d offset NONE",
2511 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2512 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size);
2514 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2515 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d offset %"
2516 G_GUINT64_FORMAT, GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2517 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size, offset);
2519 GST_OBJECT_UNLOCK (peer);
2521 ret = bufferallocfunc (peer, offset, size, caps, buf);
2523 if (G_UNLIKELY (ret != GST_FLOW_OK))
2525 if (G_UNLIKELY (*buf == NULL))
2528 /* If the buffer alloc function didn't set up the caps like it should,
2530 if (caps && (GST_BUFFER_CAPS (*buf) == NULL)) {
2531 GST_WARNING ("Buffer allocation function for pad % " GST_PTR_FORMAT
2532 " did not set up caps. Setting", peer);
2534 gst_buffer_set_caps (*buf, caps);
2538 gst_object_unref (peer);
2540 /* FIXME, move capnego this into a base class? */
2541 caps = GST_BUFFER_CAPS (*buf);
2542 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2543 /* we got a new datatype on the pad, see if it can handle it */
2544 if (G_UNLIKELY (caps_changed)) {
2545 GST_DEBUG_OBJECT (pad, "caps changed to %" GST_PTR_FORMAT, caps);
2546 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, setcaps)))
2547 goto not_negotiated;
2553 GST_CAT_DEBUG (GST_CAT_PADS, "%s:%s pad block stopped by flush",
2554 GST_DEBUG_PAD_NAME (pad));
2555 GST_OBJECT_UNLOCK (pad);
2560 /* pad has no peer */
2561 GST_CAT_DEBUG (GST_CAT_PADS,
2562 "%s:%s called bufferallocfunc but had no peer",
2563 GST_DEBUG_PAD_NAME (pad));
2564 GST_OBJECT_UNLOCK (pad);
2565 return GST_FLOW_NOT_LINKED;
2569 /* peer was flushing */
2570 GST_OBJECT_UNLOCK (peer);
2571 gst_object_unref (peer);
2572 GST_CAT_DEBUG (GST_CAT_PADS,
2573 "%s:%s called bufferallocfunc but peer was flushing",
2574 GST_DEBUG_PAD_NAME (pad));
2575 return GST_FLOW_WRONG_STATE;
2577 /* fallback case, allocate a buffer of our own, add pad caps. */
2580 GST_CAT_DEBUG (GST_CAT_PADS,
2581 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2582 *buf = gst_buffer_new_and_alloc (size);
2583 GST_BUFFER_OFFSET (*buf) = offset;
2584 gst_buffer_set_caps (*buf, caps);
2592 gst_buffer_unref (*buf);
2594 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2595 "alloc function returned unacceptable buffer");
2596 return GST_FLOW_NOT_NEGOTIATED;
2600 gst_object_unref (peer);
2601 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2602 "alloc function returned error %s", gst_flow_get_name (ret));
2608 * gst_pad_alloc_buffer:
2609 * @pad: a source #GstPad
2610 * @offset: the offset of the new buffer in the stream
2611 * @size: the size of the new buffer
2612 * @caps: the caps of the new buffer
2613 * @buf: a newly allocated buffer
2615 * Allocates a new, empty buffer optimized to push to pad @pad. This
2616 * function only works if @pad is a source pad and has a peer.
2618 * You need to check the caps of the buffer after performing this
2619 * function and renegotiate to the format if needed.
2621 * A new, empty #GstBuffer will be put in the @buf argument.
2623 * Returns: a result code indicating success of the operation. Any
2624 * result code other than GST_FLOW_OK is an error and @buf should
2626 * An error can occur if the pad is not connected or when the downstream
2627 * peer elements cannot provide an acceptable buffer.
2632 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2635 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, FALSE);
2639 * gst_pad_alloc_buffer_and_set_caps:
2640 * @pad: a source #GstPad
2641 * @offset: the offset of the new buffer in the stream
2642 * @size: the size of the new buffer
2643 * @caps: the caps of the new buffer
2644 * @buf: a newly allocated buffer
2646 * In addition to the function gst_pad_alloc_buffer(), this function
2647 * automatically calls gst_pad_set_caps() when the caps of the
2648 * newly allocated buffer are different from the @pad caps.
2650 * Returns: a result code indicating success of the operation. Any
2651 * result code other than GST_FLOW_OK is an error and @buf should
2653 * An error can occur if the pad is not connected or when the downstream
2654 * peer elements cannot provide an acceptable buffer.
2659 gst_pad_alloc_buffer_and_set_caps (GstPad * pad, guint64 offset, gint size,
2660 GstCaps * caps, GstBuffer ** buf)
2662 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, TRUE);
2666 * gst_pad_get_internal_links_default:
2667 * @pad: the #GstPad to get the internal links of.
2669 * Gets a list of pads to which the given pad is linked to
2670 * inside of the parent element.
2671 * This is the default handler, and thus returns a list of all of the
2672 * pads inside the parent element with opposite direction.
2673 * The caller must free this list after use.
2675 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
2680 gst_pad_get_internal_links_default (GstPad * pad)
2685 GstPadDirection direction;
2687 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2689 direction = pad->direction;
2691 parent = GST_PAD_PARENT (pad);
2695 parent_pads = parent->pads;
2697 while (parent_pads) {
2698 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2700 if (parent_pad->direction != direction) {
2701 res = g_list_prepend (res, parent_pad);
2704 parent_pads = g_list_next (parent_pads);
2711 * gst_pad_get_internal_links:
2712 * @pad: the #GstPad to get the internal links of.
2714 * Gets a list of pads to which the given pad is linked to
2715 * inside of the parent element.
2716 * The caller must free this list after use.
2718 * Returns: a newly allocated #GList of pads.
2723 gst_pad_get_internal_links (GstPad * pad)
2727 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2729 if (GST_PAD_INTLINKFUNC (pad))
2730 res = GST_PAD_INTLINKFUNC (pad) (pad);
2737 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2742 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2745 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2747 orig = pads = gst_pad_get_internal_links (pad);
2750 GstPad *eventpad = GST_PAD_CAST (pads->data);
2752 pads = g_list_next (pads);
2754 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2755 /* for each pad we send to, we should ref the event; it's up
2756 * to downstream to unref again when handled. */
2757 GST_LOG_OBJECT (pad, "Reffing and sending event %p (%s) to %s:%s",
2758 event, GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (eventpad));
2759 gst_event_ref (event);
2760 gst_pad_push_event (eventpad, event);
2762 /* we only send the event on one pad, multi-sinkpad elements
2763 * should implement a handler */
2764 GST_LOG_OBJECT (pad, "sending event %p (%s) to one sink pad %s:%s",
2765 event, GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (eventpad));
2766 result = gst_pad_push_event (eventpad, event);
2770 /* we handled the incoming event so we unref once */
2771 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2772 gst_event_unref (event);
2781 * gst_pad_event_default:
2782 * @pad: a #GstPad to call the default event handler on.
2783 * @event: the #GstEvent to handle.
2785 * Invokes the default event handler for the given pad. End-of-stream and
2786 * discontinuity events are handled specially, and then the event is sent to all
2787 * pads internally linked to @pad. Note that if there are many possible sink
2788 * pads that are internally linked to @pad, only one will be sent an event.
2789 * Multi-sinkpad elements should implement custom event handlers.
2791 * Returns: TRUE if the event was sent succesfully.
2794 gst_pad_event_default (GstPad * pad, GstEvent * event)
2796 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2797 g_return_val_if_fail (event != NULL, FALSE);
2799 switch (GST_EVENT_TYPE (event)) {
2802 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2803 gst_pad_pause_task (pad);
2809 return gst_pad_event_default_dispatch (pad, event);
2813 * gst_pad_dispatcher:
2814 * @pad: a #GstPad to dispatch.
2815 * @dispatch: the #GstDispatcherFunction to call.
2816 * @data: gpointer user data passed to the dispatcher function.
2818 * Invokes the given dispatcher function on all pads that are
2819 * internally linked to the given pad.
2820 * The GstPadDispatcherFunction should return TRUE when no further pads
2821 * need to be processed.
2823 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2826 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2829 gboolean res = FALSE;
2830 GList *int_pads, *orig;
2832 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2833 g_return_val_if_fail (dispatch != NULL, FALSE);
2835 orig = int_pads = gst_pad_get_internal_links (pad);
2838 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2839 GstPad *int_peer = GST_PAD_PEER (int_pad);
2842 res = dispatch (int_peer, data);
2846 int_pads = g_list_next (int_pads);
2856 * @pad: a #GstPad to invoke the default query on.
2857 * @query: the #GstQuery to perform.
2859 * Dispatches a query to a pad. The query should have been allocated by the
2860 * caller via one of the type-specific allocation functions in gstquery.h. The
2861 * element is responsible for filling the query with an appropriate response,
2862 * which should then be parsed with a type-specific query parsing function.
2864 * Again, the caller is responsible for both the allocation and deallocation of
2865 * the query structure.
2867 * Returns: TRUE if the query could be performed.
2870 gst_pad_query (GstPad * pad, GstQuery * query)
2872 GstPadQueryFunction func;
2874 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2875 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2877 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2879 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2882 return func (pad, query);
2886 GST_DEBUG ("pad had no query function");
2892 * gst_pad_query_default:
2893 * @pad: a #GstPad to call the default query handler on.
2894 * @query: the #GstQuery to handle.
2896 * Invokes the default query handler for the given pad.
2897 * The query is sent to all pads internally linked to @pad. Note that
2898 * if there are many possible sink pads that are internally linked to
2899 * @pad, only one will be sent the query.
2900 * Multi-sinkpad elements should implement custom query handlers.
2902 * Returns: TRUE if the query was performed succesfully.
2905 gst_pad_query_default (GstPad * pad, GstQuery * query)
2907 switch (GST_QUERY_TYPE (query)) {
2908 case GST_QUERY_POSITION:
2909 case GST_QUERY_SEEKING:
2910 case GST_QUERY_FORMATS:
2911 case GST_QUERY_LATENCY:
2912 case GST_QUERY_JITTER:
2913 case GST_QUERY_RATE:
2914 case GST_QUERY_CONVERT:
2916 return gst_pad_dispatcher
2917 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2921 #ifndef GST_DISABLE_LOADSAVE
2922 /* FIXME: why isn't this on a GstElement ? */
2924 * gst_pad_load_and_link:
2925 * @self: an #xmlNodePtr to read the description from.
2926 * @parent: the #GstObject element that owns the pad.
2928 * Reads the pad definition from the XML node and links the given pad
2929 * in the element to a pad of an element up in the hierarchy.
2932 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2934 xmlNodePtr field = self->xmlChildrenNode;
2935 GstPad *pad = NULL, *targetpad;
2939 GstObject *grandparent;
2943 if (!strcmp ((char *) field->name, "name")) {
2944 name = (gchar *) xmlNodeGetContent (field);
2945 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2947 } else if (!strcmp ((char *) field->name, "peer")) {
2948 peer = (gchar *) xmlNodeGetContent (field);
2950 field = field->next;
2952 g_return_if_fail (pad != NULL);
2957 split = g_strsplit (peer, ".", 2);
2959 if (split[0] == NULL || split[1] == NULL) {
2960 GST_CAT_DEBUG (GST_CAT_XML,
2961 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2962 peer, GST_DEBUG_PAD_NAME (pad));
2969 g_return_if_fail (split[0] != NULL);
2970 g_return_if_fail (split[1] != NULL);
2972 grandparent = gst_object_get_parent (parent);
2974 if (grandparent && GST_IS_BIN (grandparent)) {
2975 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2982 targetpad = gst_element_get_pad (target, split[1]);
2984 if (targetpad == NULL)
2987 gst_pad_link (pad, targetpad);
2994 * gst_pad_save_thyself:
2995 * @pad: a #GstPad to save.
2996 * @parent: the parent #xmlNodePtr to save the description in.
2998 * Saves the pad into an xml representation.
3000 * Returns: the #xmlNodePtr representation of the pad.
3003 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3008 g_return_val_if_fail (GST_IS_PAD (object), NULL);
3010 pad = GST_PAD (object);
3012 xmlNewChild (parent, NULL, (xmlChar *) "name",
3013 (xmlChar *) GST_PAD_NAME (pad));
3014 if (GST_PAD_PEER (pad) != NULL) {
3017 peer = GST_PAD_PEER (pad);
3018 /* first check to see if the peer's parent's parent is the same */
3019 /* we just save it off */
3020 content = g_strdup_printf ("%s.%s",
3021 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3022 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
3025 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
3032 * gst_ghost_pad_save_thyself:
3033 * @pad: a ghost #GstPad to save.
3034 * @parent: the parent #xmlNodePtr to save the description in.
3036 * Saves the ghost pad into an xml representation.
3038 * Returns: the #xmlNodePtr representation of the pad.
3041 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3045 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3047 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
3048 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
3049 xmlNewChild (self, NULL, (xmlChar *) "parent",
3050 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3052 /* FIXME FIXME FIXME! */
3057 #endif /* GST_DISABLE_LOADSAVE */
3060 * should be called with pad lock held
3064 static GstFlowReturn
3065 handle_pad_block (GstPad * pad)
3067 GstPadBlockCallback callback;
3069 GstFlowReturn ret = GST_FLOW_OK;
3071 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3072 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
3074 /* need to grab extra ref for the callbacks */
3075 gst_object_ref (pad);
3077 callback = pad->block_callback;
3079 user_data = pad->block_data;
3080 GST_OBJECT_UNLOCK (pad);
3081 callback (pad, TRUE, user_data);
3082 GST_OBJECT_LOCK (pad);
3084 GST_PAD_BLOCK_SIGNAL (pad);
3087 while (GST_PAD_IS_BLOCKED (pad)) {
3088 if (GST_PAD_IS_FLUSHING (pad))
3090 GST_PAD_BLOCK_WAIT (pad);
3091 if (GST_PAD_IS_FLUSHING (pad))
3095 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
3097 callback = pad->block_callback;
3099 user_data = pad->block_data;
3100 GST_OBJECT_UNLOCK (pad);
3101 callback (pad, FALSE, user_data);
3102 GST_OBJECT_LOCK (pad);
3104 GST_PAD_BLOCK_SIGNAL (pad);
3107 gst_object_unref (pad);
3113 gst_object_unref (pad);
3114 return GST_FLOW_WRONG_STATE;
3118 /**********************************************************************
3119 * Data passing functions
3123 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
3126 GValue args[2] = { {0}, {0} };
3131 g_value_init (&ret, G_TYPE_BOOLEAN);
3132 g_value_set_boolean (&ret, TRUE);
3133 g_value_init (&args[0], GST_TYPE_PAD);
3134 g_value_set_object (&args[0], pad);
3135 g_value_init (&args[1], GST_TYPE_MINI_OBJECT); // G_TYPE_POINTER);
3136 gst_value_set_mini_object (&args[1], obj);
3138 if (GST_IS_EVENT (obj))
3139 detail = event_quark;
3141 detail = buffer_quark;
3144 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
3145 res = g_value_get_boolean (&ret);
3148 g_value_unset (&ret);
3149 g_value_unset (&args[0]);
3150 g_value_unset (&args[1]);
3157 * @pad: a sink #GstPad.
3158 * @buffer: the #GstBuffer to send.
3160 * Chain a buffer to @pad.
3162 * Returns: a #GstFlowReturn from the pad.
3167 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3170 gboolean caps_changed;
3171 GstPadChainFunction chainfunc;
3173 gboolean emit_signal;
3175 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3176 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3178 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3179 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3181 GST_PAD_STREAM_LOCK (pad);
3183 GST_OBJECT_LOCK (pad);
3184 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3187 caps = GST_BUFFER_CAPS (buffer);
3188 caps_changed = caps && caps != GST_PAD_CAPS (pad);
3190 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3191 GST_OBJECT_UNLOCK (pad);
3193 /* see if the signal should be emited, we emit before caps nego as
3194 * we might drop the buffer and do capsnego for nothing. */
3195 if (G_UNLIKELY (emit_signal)) {
3196 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3200 /* we got a new datatype on the pad, see if it can handle it */
3201 if (G_UNLIKELY (caps_changed)) {
3202 GST_DEBUG_OBJECT (pad, "caps changed to %" GST_PTR_FORMAT, caps);
3203 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
3204 goto not_negotiated;
3207 /* NOTE: we read the chainfunc unlocked.
3208 * we cannot hold the lock for the pad so we might send
3209 * the data to the wrong function. This is not really a
3210 * problem since functions are assigned at creation time
3211 * and don't change that often... */
3212 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3215 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3216 "calling chainfunction &%s of pad %s:%s",
3217 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
3219 ret = chainfunc (pad, buffer);
3221 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3222 "called chainfunction &%s of pad %s:%s, returned %s",
3223 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad),
3224 gst_flow_get_name (ret));
3226 GST_PAD_STREAM_UNLOCK (pad);
3233 gst_buffer_unref (buffer);
3234 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3235 "pushing, but pad was flushing");
3236 GST_OBJECT_UNLOCK (pad);
3237 GST_PAD_STREAM_UNLOCK (pad);
3238 return GST_FLOW_WRONG_STATE;
3242 gst_buffer_unref (buffer);
3243 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
3244 GST_PAD_STREAM_UNLOCK (pad);
3249 gst_buffer_unref (buffer);
3250 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3251 "pushing buffer but pad did not accept");
3252 GST_PAD_STREAM_UNLOCK (pad);
3253 return GST_FLOW_NOT_NEGOTIATED;
3257 gst_buffer_unref (buffer);
3258 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3259 "pushing, but not chainhandler");
3260 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3261 ("push on pad %s:%s but it has no chainfunction",
3262 GST_DEBUG_PAD_NAME (pad)));
3263 GST_PAD_STREAM_UNLOCK (pad);
3264 return GST_FLOW_ERROR;
3270 * @pad: a source #GstPad.
3271 * @buffer: the #GstBuffer to push.
3273 * Pushes a buffer to the peer of @pad.
3274 * buffer probes will be triggered before the buffer gets pushed.
3276 * Returns: a #GstFlowReturn from the peer pad.
3281 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3286 gboolean caps_changed;
3288 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3289 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3290 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3291 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3293 GST_OBJECT_LOCK (pad);
3295 /* FIXME: this check can go away; pad_set_blocked could be implemented with
3296 * probes completely */
3297 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3298 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
3301 /* we emit signals on the pad arg, the peer will have a chance to
3302 * emit in the _chain() function */
3303 if (G_UNLIKELY (GST_PAD_DO_BUFFER_SIGNALS (pad) > 0)) {
3304 /* unlock before emitting */
3305 GST_OBJECT_UNLOCK (pad);
3307 /* if the signal handler returned FALSE, it means we should just drop the
3309 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3312 GST_OBJECT_LOCK (pad);
3315 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3317 gst_object_ref (peer);
3319 /* Before pushing the buffer to the peer pad, ensure that caps
3320 * are set on this pad */
3321 caps = GST_BUFFER_CAPS (buffer);
3322 caps_changed = caps && caps != GST_PAD_CAPS (pad);
3324 GST_OBJECT_UNLOCK (pad);
3326 /* we got a new datatype from the pad, it had better handle it */
3327 if (G_UNLIKELY (caps_changed)) {
3328 GST_DEBUG_OBJECT (pad, "caps changed to %" GST_PTR_FORMAT, caps);
3329 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, TRUE)))
3330 goto not_negotiated;
3333 ret = gst_pad_chain (peer, buffer);
3335 gst_object_unref (peer);
3339 /* ERROR recovery here */
3342 gst_buffer_unref (buffer);
3343 GST_DEBUG_OBJECT (pad, "pad block stopped by flush");
3344 GST_OBJECT_UNLOCK (pad);
3349 gst_buffer_unref (buffer);
3350 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
3355 gst_buffer_unref (buffer);
3356 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3357 "pushing, but it was not linked");
3358 GST_OBJECT_UNLOCK (pad);
3359 return GST_FLOW_NOT_LINKED;
3363 gst_buffer_unref (buffer);
3364 gst_object_unref (peer);
3365 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
3366 "element pushed buffer then refused to accept the caps");
3367 return GST_FLOW_NOT_NEGOTIATED;
3372 * gst_pad_check_pull_range:
3373 * @pad: a sink #GstPad.
3375 * Checks if a gst_pad_pull_range() can be performed on the peer
3376 * source pad. This function is used by plugins that want to check
3377 * if they can use random access on the peer source pad.
3379 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
3380 * if it needs to perform some logic to determine if pull_range is
3383 * Returns: a gboolean with the result.
3388 gst_pad_check_pull_range (GstPad * pad)
3392 GstPadCheckGetRangeFunction checkgetrangefunc;
3394 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3396 GST_OBJECT_LOCK (pad);
3397 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
3398 goto wrong_direction;
3400 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3403 gst_object_ref (peer);
3404 GST_OBJECT_UNLOCK (pad);
3406 /* see note in above function */
3407 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
3408 /* FIXME, kindoff ghetto */
3409 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
3411 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3412 "calling checkgetrangefunc %s of peer pad %s:%s",
3413 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
3415 ret = checkgetrangefunc (peer);
3418 gst_object_unref (peer);
3422 /* ERROR recovery here */
3425 GST_OBJECT_UNLOCK (pad);
3430 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3431 "checking pull range, but it was not linked");
3432 GST_OBJECT_UNLOCK (pad);
3438 * gst_pad_get_range:
3439 * @pad: a src #GstPad.
3440 * @offset: The start offset of the buffer
3441 * @size: The length of the buffer
3442 * @buffer: a pointer to hold the #GstBuffer.
3444 * Calls the getrange function of @pad.
3446 * Returns: a #GstFlowReturn from the pad.
3451 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3452 GstBuffer ** buffer)
3455 GstPadGetRangeFunction getrangefunc;
3456 gboolean emit_signal;
3458 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3459 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3460 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3462 GST_PAD_STREAM_LOCK (pad);
3464 GST_OBJECT_LOCK (pad);
3465 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3468 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3469 GST_OBJECT_UNLOCK (pad);
3471 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3474 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3475 "calling getrangefunc %s of peer pad %s:%s, offset %"
3476 G_GUINT64_FORMAT ", size %u",
3477 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
3480 ret = getrangefunc (pad, offset, size, buffer);
3482 /* can only fire the signal if we have a valid buffer */
3483 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3484 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3488 GST_PAD_STREAM_UNLOCK (pad);
3495 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3496 "pulling range, but pad was flushing");
3497 GST_OBJECT_UNLOCK (pad);
3498 GST_PAD_STREAM_UNLOCK (pad);
3499 return GST_FLOW_WRONG_STATE;
3503 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3504 ("pullrange on pad %s:%s but it has no getrangefunction",
3505 GST_DEBUG_PAD_NAME (pad)));
3506 GST_PAD_STREAM_UNLOCK (pad);
3507 return GST_FLOW_ERROR;
3511 GST_DEBUG ("Dropping data after FALSE probe return");
3512 GST_PAD_STREAM_UNLOCK (pad);
3513 gst_buffer_unref (*buffer);
3515 return GST_FLOW_UNEXPECTED;
3521 * gst_pad_pull_range:
3522 * @pad: a sink #GstPad.
3523 * @offset: The start offset of the buffer
3524 * @size: The length of the buffer
3525 * @buffer: a pointer to hold the #GstBuffer.
3527 * Pulls a buffer from the peer pad. @pad must be a linked
3530 * Returns: a #GstFlowReturn from the peer pad.
3535 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3536 GstBuffer ** buffer)
3540 gboolean emit_signal;
3542 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3543 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3545 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3547 GST_OBJECT_LOCK (pad);
3549 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3550 handle_pad_block (pad);
3552 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3555 /* signal emision for the pad, peer has chance to emit when
3556 * we call _get_range() */
3557 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3559 gst_object_ref (peer);
3560 GST_OBJECT_UNLOCK (pad);
3562 ret = gst_pad_get_range (peer, offset, size, buffer);
3564 gst_object_unref (peer);
3566 /* can only fire the signal if we have a valid buffer */
3567 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3568 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3573 /* ERROR recovery here */
3576 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3577 "pulling range, but it was not linked");
3578 GST_OBJECT_UNLOCK (pad);
3579 return GST_FLOW_NOT_LINKED;
3583 GST_DEBUG ("Dropping data after FALSE probe return");
3584 gst_buffer_unref (*buffer);
3586 return GST_FLOW_UNEXPECTED;
3591 * gst_pad_push_event:
3592 * @pad: a #GstPad to push the event to.
3593 * @event: the #GstEvent to send to the pad.
3595 * Sends the event to the peer of the given pad. This function is
3596 * mainly used by elements to send events to their peer
3599 * This function takes owership of the provided event so you should
3600 * gst_event_ref() it if you want to reuse the event after this call.
3602 * Returns: TRUE if the event was handled.
3607 gst_pad_push_event (GstPad * pad, GstEvent * event)
3612 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3613 g_return_val_if_fail (event != NULL, FALSE);
3614 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
3616 GST_OBJECT_LOCK (pad);
3617 switch (GST_EVENT_TYPE (event)) {
3618 case GST_EVENT_FLUSH_START:
3619 GST_PAD_SET_FLUSHING (pad);
3621 case GST_EVENT_FLUSH_STOP:
3622 GST_PAD_UNSET_FLUSHING (pad);
3628 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
3629 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
3630 GST_PAD_BLOCK_SIGNAL (pad);
3634 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
3635 GST_OBJECT_UNLOCK (pad);
3637 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3640 GST_OBJECT_LOCK (pad);
3642 peerpad = GST_PAD_PEER (pad);
3643 if (peerpad == NULL)
3646 GST_LOG_OBJECT (peerpad, "sending event on peerpad");
3647 gst_object_ref (peerpad);
3648 GST_OBJECT_UNLOCK (pad);
3650 result = gst_pad_send_event (peerpad, event);
3652 gst_object_unref (peerpad);
3653 GST_LOG_OBJECT (peerpad, "sent event on peerpad");
3657 /* ERROR handling */
3660 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
3661 gst_event_unref (event);
3666 gst_event_unref (event);
3667 GST_OBJECT_UNLOCK (pad);
3673 * gst_pad_send_event:
3674 * @pad: a #GstPad to send the event to.
3675 * @event: the #GstEvent to send to the pad.
3677 * Sends the event to the pad. This function can be used
3678 * by applications to send events in the pipeline.
3680 * If @pad is a source pad, @event should be an upstream event. If @pad is a
3681 * sink pad, @event should be a downstream event. For example, you would not
3682 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
3683 * Furthermore, some downstream events have to be serialized with data flow,
3684 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
3685 * the event needs to be serialized with data flow, this function will take the
3686 * pad's stream lock while calling its event function.
3688 * To find out whether an event type is upstream, downstream, or downstream and
3689 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
3690 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
3691 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or plugin
3692 * doesn't need to bother itself with this information; the core handles all
3693 * necessary locks and checks.
3695 * This function takes owership of the provided event so you should
3696 * gst_event_ref() it if you want to reuse the event after this call.
3698 * Returns: TRUE if the event was handled.
3701 gst_pad_send_event (GstPad * pad, GstEvent * event)
3703 gboolean result = FALSE;
3704 GstPadEventFunction eventfunc;
3705 gboolean serialized, need_unlock = FALSE;
3707 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3708 g_return_val_if_fail (event != NULL, FALSE);
3710 GST_OBJECT_LOCK (pad);
3711 if (GST_PAD_IS_SINK (pad)) {
3712 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
3713 goto wrong_direction;
3714 serialized = GST_EVENT_IS_SERIALIZED (event);
3715 } else if (GST_PAD_IS_SRC (pad)) {
3716 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
3717 goto wrong_direction;
3718 /* events on srcpad never are serialized */
3721 goto unknown_direction;
3723 if (G_UNLIKELY (GST_EVENT_SRC (event) == NULL)) {
3724 GST_LOG_OBJECT (pad, "event had no source, setting pad as event source");
3725 GST_EVENT_SRC (event) = gst_object_ref (pad);
3729 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
3730 GST_OBJECT_UNLOCK (pad);
3732 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT_CAST (event)))
3735 GST_OBJECT_LOCK (pad);
3738 switch (GST_EVENT_TYPE (event)) {
3739 case GST_EVENT_FLUSH_START:
3740 GST_CAT_DEBUG (GST_CAT_EVENT,
3741 "have event type %d (FLUSH_START) on pad %s:%s",
3742 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3744 /* can't even accept a flush begin event when flushing */
3745 if (GST_PAD_IS_FLUSHING (pad))
3747 GST_PAD_SET_FLUSHING (pad);
3748 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3750 case GST_EVENT_FLUSH_STOP:
3751 GST_PAD_UNSET_FLUSHING (pad);
3752 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3753 GST_OBJECT_UNLOCK (pad);
3754 /* grab stream lock */
3755 GST_PAD_STREAM_LOCK (pad);
3757 GST_OBJECT_LOCK (pad);
3760 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %s on pad %s:%s",
3761 GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (pad));
3763 /* make this a little faster, no point in grabbing the lock
3764 * if the pad is allready flushing. */
3765 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3769 /* lock order: STREAM_LOCK, LOCK */
3770 GST_OBJECT_UNLOCK (pad);
3771 GST_PAD_STREAM_LOCK (pad);
3773 GST_OBJECT_LOCK (pad);
3774 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3779 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
3782 GST_OBJECT_UNLOCK (pad);
3784 result = eventfunc (pad, event);
3787 GST_PAD_STREAM_UNLOCK (pad);
3791 /* ERROR handling */
3794 g_warning ("pad %s:%s sending %s event in wrong direction",
3795 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
3796 GST_OBJECT_UNLOCK (pad);
3797 gst_event_unref (event);
3802 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3803 GST_OBJECT_UNLOCK (pad);
3804 gst_event_unref (event);
3809 g_warning ("pad %s:%s has no event handler, file a bug.",
3810 GST_DEBUG_PAD_NAME (pad));
3811 GST_OBJECT_UNLOCK (pad);
3812 gst_event_unref (event);
3817 GST_OBJECT_UNLOCK (pad);
3819 GST_PAD_STREAM_UNLOCK (pad);
3820 GST_CAT_INFO (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3821 gst_event_unref (event);
3826 GST_DEBUG ("Dropping event after FALSE probe return");
3827 gst_event_unref (event);
3833 * gst_pad_set_element_private:
3834 * @pad: the #GstPad to set the private data of.
3835 * @priv: The private data to attach to the pad.
3837 * Set the given private data gpointer on the pad.
3838 * This function can only be used by the element that owns the pad.
3839 * No locking is performed in this function.
3842 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3844 pad->element_private = priv;
3848 * gst_pad_get_element_private:
3849 * @pad: the #GstPad to get the private data of.
3851 * Gets the private data of a pad.
3852 * No locking is performed in this function.
3854 * Returns: a #gpointer to the private data.
3857 gst_pad_get_element_private (GstPad * pad)
3859 return pad->element_private;
3863 * gst_pad_start_task:
3864 * @pad: the #GstPad to start the task of
3865 * @func: the task function to call
3866 * @data: data passed to the task function
3868 * Starts a task that repeadedly calls @func with @data. This function
3869 * is nostly used in the pad activation function to start the
3870 * dataflow. This function will automatically acquire the STREAM_LOCK of
3871 * the pad before calling @func.
3873 * Returns: a TRUE if the task could be started.
3876 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3880 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3881 g_return_val_if_fail (func != NULL, FALSE);
3883 GST_OBJECT_LOCK (pad);
3884 task = GST_PAD_TASK (pad);
3886 task = gst_task_create (func, data);
3887 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
3888 GST_PAD_TASK (pad) = task;
3890 gst_task_start (task);
3891 GST_OBJECT_UNLOCK (pad);
3897 * gst_pad_pause_task:
3898 * @pad: the #GstPad to pause the task of
3900 * Pause the task of @pad. This function will also make sure that the
3901 * function executed by the task will effectively stop.
3903 * Returns: a TRUE if the task could be paused or FALSE when the pad
3907 gst_pad_pause_task (GstPad * pad)
3911 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3913 GST_OBJECT_LOCK (pad);
3914 task = GST_PAD_TASK (pad);
3917 gst_task_pause (task);
3918 GST_OBJECT_UNLOCK (pad);
3920 GST_PAD_STREAM_LOCK (pad);
3921 GST_PAD_STREAM_UNLOCK (pad);
3927 GST_DEBUG_OBJECT (pad, "pad has no task");
3928 GST_OBJECT_UNLOCK (pad);
3934 * gst_pad_stop_task:
3935 * @pad: the #GstPad to stop the task of
3937 * Stop the task of @pad. This function will also make sure that the
3938 * function executed by the task will effectively stop if not called
3939 * from the GstTaskFunction.
3941 * This function will deadlock if called from the GstTaskFunction of
3942 * the task. Use gst_task_pause() instead.
3944 * Regardless of whether the pad has a task, the stream lock is acquired and
3945 * released so as to ensure that streaming through this pad has finished.
3947 * Returns: a TRUE if the task could be stopped or FALSE on error.
3950 gst_pad_stop_task (GstPad * pad)
3954 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3956 GST_OBJECT_LOCK (pad);
3957 task = GST_PAD_TASK (pad);
3960 GST_PAD_TASK (pad) = NULL;
3961 gst_task_stop (task);
3962 GST_OBJECT_UNLOCK (pad);
3964 GST_PAD_STREAM_LOCK (pad);
3965 GST_PAD_STREAM_UNLOCK (pad);
3967 gst_task_join (task);
3969 gst_object_unref (task);
3975 GST_OBJECT_UNLOCK (pad);
3977 GST_PAD_STREAM_LOCK (pad);
3978 GST_PAD_STREAM_UNLOCK (pad);