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() and
58 * gst_pad_push_event().
60 * Last reviewed on 2006-07-06 (0.10.9)
63 #include "gst_private.h"
66 #include "gstpadtemplate.h"
67 #include "gstenumtypes.h"
68 #include "gstmarshal.h"
73 #include "glib-compat-private.h"
75 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
76 #define GST_CAT_DEFAULT GST_CAT_PADS
78 /* Pad signals and args */
98 #define GST_PAD_GET_PRIVATE(obj) \
99 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
101 #define GST_PAD_CHAINLISTFUNC(pad) ((pad)->abidata.ABI.priv->chainlistfunc)
103 struct _GstPadPrivate
105 GstPadChainListFunction chainlistfunc;
108 static void gst_pad_dispose (GObject * object);
109 static void gst_pad_finalize (GObject * object);
110 static void gst_pad_set_property (GObject * object, guint prop_id,
111 const GValue * value, GParamSpec * pspec);
112 static void gst_pad_get_property (GObject * object, guint prop_id,
113 GValue * value, GParamSpec * pspec);
115 static GstFlowReturn handle_pad_block (GstPad * pad);
116 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
117 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
118 static gboolean gst_pad_activate_default (GstPad * pad);
119 static gboolean gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps);
121 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
122 #ifdef GST_DISABLE_DEPRECATED
123 #include <libxml/parser.h>
125 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
126 void gst_pad_load_and_link (xmlNodePtr self, GstObject * parent);
129 /* Some deprecated stuff that we need inside here for
130 * backwards compatibility */
131 #ifdef GST_DISABLE_DEPRECATED
132 #ifndef GST_REMOVE_DEPRECATED
133 #define GST_PAD_INTLINKFUNC(pad) (GST_PAD_CAST(pad)->intlinkfunc)
134 GList *gst_pad_get_internal_links_default (GstPad * pad);
138 static GstObjectClass *parent_class = NULL;
139 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
141 /* quarks for probe signals */
142 static GQuark buffer_quark;
143 static GQuark event_quark;
152 static GstFlowQuarks flow_quarks[] = {
153 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
154 {GST_FLOW_RESEND, "resend", 0},
155 {GST_FLOW_OK, "ok", 0},
156 {GST_FLOW_NOT_LINKED, "not-linked", 0},
157 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
158 {GST_FLOW_UNEXPECTED, "unexpected", 0},
159 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
160 {GST_FLOW_ERROR, "error", 0},
161 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
162 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
167 * @ret: a #GstFlowReturn to get the name of.
169 * Gets a string representing the given flow return.
171 * Returns: a static string with the name of the flow return.
173 G_CONST_RETURN gchar *
174 gst_flow_get_name (GstFlowReturn ret)
178 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
180 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
181 if (ret == flow_quarks[i].ret)
182 return flow_quarks[i].name;
189 * @ret: a #GstFlowReturn to get the quark of.
191 * Get the unique quark for the given GstFlowReturn.
193 * Returns: the quark associated with the flow return or 0 if an
194 * invalid return was specified.
197 gst_flow_to_quark (GstFlowReturn ret)
201 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
203 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
204 if (ret == flow_quarks[i].ret)
205 return flow_quarks[i].quark;
214 buffer_quark = g_quark_from_static_string ("buffer"); \
215 event_quark = g_quark_from_static_string ("event"); \
217 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
218 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
221 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
222 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
225 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
228 _gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
229 GValue * return_accu, const GValue * handler_return, gpointer dummy)
231 gboolean ret = g_value_get_boolean (handler_return);
233 GST_DEBUG ("accumulated %d", ret);
234 g_value_set_boolean (return_accu, ret);
240 default_have_data (GstPad * pad, GstMiniObject * o)
246 gst_pad_class_init (GstPadClass * klass)
248 GObjectClass *gobject_class;
249 GstObjectClass *gstobject_class;
251 gobject_class = G_OBJECT_CLASS (klass);
252 gstobject_class = GST_OBJECT_CLASS (klass);
254 g_type_class_add_private (klass, sizeof (GstPadPrivate));
256 parent_class = g_type_class_peek_parent (klass);
258 gobject_class->dispose = gst_pad_dispose;
259 gobject_class->finalize = gst_pad_finalize;
260 gobject_class->set_property = gst_pad_set_property;
261 gobject_class->get_property = gst_pad_get_property;
265 * @pad: the pad that emitted the signal
266 * @peer: the peer pad that has been connected
268 * Signals that a pad has been linked to the peer pad.
270 gst_pad_signals[PAD_LINKED] =
271 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
272 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
273 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
276 * @pad: the pad that emitted the signal
277 * @peer: the peer pad that has been disconnected
279 * Signals that a pad has been unlinked from the peer pad.
281 gst_pad_signals[PAD_UNLINKED] =
282 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
283 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
284 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
286 * GstPad::request-link:
287 * @pad: the pad that emitted the signal
288 * @peer: the peer pad for which a connection is requested
290 * Signals that a pad connection has been requested.
292 gst_pad_signals[PAD_REQUEST_LINK] =
293 g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
294 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
295 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
299 * @pad: the pad that emitted the signal
300 * @mini_obj: new data
302 * Signals that new data is available on the pad. This signal is used
303 * internally for implementing pad probes.
304 * See gst_pad_add_*_probe functions.
306 * Returns: %TRUE to keep the data, %FALSE to drop it
308 gst_pad_signals[PAD_HAVE_DATA] =
309 g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
310 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
311 G_STRUCT_OFFSET (GstPadClass, have_data),
312 _gst_do_pass_data_accumulator,
313 NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
314 GST_TYPE_MINI_OBJECT);
316 g_object_class_install_property (gobject_class, PAD_PROP_CAPS,
317 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
318 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
319 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
320 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
321 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
322 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
323 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
324 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
325 g_param_spec_object ("template", "Template",
326 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
327 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
329 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
330 gstobject_class->save_thyself =
331 ((gpointer (*)(GstObject * object,
332 gpointer self)) * GST_DEBUG_FUNCPTR (gst_pad_save_thyself));
334 gstobject_class->path_string_separator = ".";
336 /* Register common function pointer descriptions */
337 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
338 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
339 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_query_types_default);
340 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
341 #ifndef GST_REMOVE_DEPRECATED
342 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_internal_links_default);
344 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
345 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_acceptcaps_default);
347 klass->have_data = default_have_data;
351 gst_pad_init (GstPad * pad)
353 pad->abidata.ABI.priv = GST_PAD_GET_PRIVATE (pad);
355 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
356 GST_PAD_PEER (pad) = NULL;
358 GST_PAD_CHAINFUNC (pad) = NULL;
360 GST_PAD_LINKFUNC (pad) = NULL;
362 GST_PAD_CAPS (pad) = NULL;
363 GST_PAD_GETCAPSFUNC (pad) = NULL;
365 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
366 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
367 GST_PAD_QUERYTYPEFUNC (pad) = gst_pad_get_query_types_default;
368 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
369 #ifndef GST_REMOVE_DEPRECATED
370 GST_PAD_INTLINKFUNC (pad) = gst_pad_get_internal_links_default;
372 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
374 GST_PAD_ACCEPTCAPSFUNC (pad) = gst_pad_acceptcaps_default;
376 pad->do_buffer_signals = 0;
377 pad->do_event_signals = 0;
379 GST_PAD_SET_FLUSHING (pad);
381 pad->preroll_lock = g_mutex_new ();
382 pad->preroll_cond = g_cond_new ();
384 /* FIXME 0.11: Store this directly in the instance struct */
385 pad->stream_rec_lock = g_slice_new (GStaticRecMutex);
386 g_static_rec_mutex_init (pad->stream_rec_lock);
388 pad->block_cond = g_cond_new ();
392 gst_pad_dispose (GObject * object)
394 GstPad *pad = GST_PAD_CAST (object);
397 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
399 /* unlink the peer pad */
400 if ((peer = gst_pad_get_peer (pad))) {
401 /* window for MT unsafeness, someone else could unlink here
402 * and then we call unlink with wrong pads. The unlink
403 * function would catch this and safely return failed. */
404 if (GST_PAD_IS_SRC (pad))
405 gst_pad_unlink (pad, peer);
407 gst_pad_unlink (peer, pad);
409 gst_object_unref (peer);
413 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
415 gst_pad_set_pad_template (pad, NULL);
417 if (pad->block_destroy_data && pad->block_data) {
418 pad->block_destroy_data (pad->block_data);
419 pad->block_data = NULL;
422 G_OBJECT_CLASS (parent_class)->dispose (object);
426 gst_pad_finalize (GObject * object)
428 GstPad *pad = GST_PAD_CAST (object);
431 /* in case the task is still around, clean it up */
432 if ((task = GST_PAD_TASK (pad))) {
433 gst_task_join (task);
434 GST_PAD_TASK (pad) = NULL;
435 gst_object_unref (task);
438 if (pad->stream_rec_lock) {
439 g_static_rec_mutex_free (pad->stream_rec_lock);
440 g_slice_free (GStaticRecMutex, pad->stream_rec_lock);
441 pad->stream_rec_lock = NULL;
443 if (pad->preroll_lock) {
444 g_mutex_free (pad->preroll_lock);
445 g_cond_free (pad->preroll_cond);
446 pad->preroll_lock = NULL;
447 pad->preroll_cond = NULL;
449 if (pad->block_cond) {
450 g_cond_free (pad->block_cond);
451 pad->block_cond = NULL;
454 G_OBJECT_CLASS (parent_class)->finalize (object);
458 gst_pad_set_property (GObject * object, guint prop_id,
459 const GValue * value, GParamSpec * pspec)
461 g_return_if_fail (GST_IS_PAD (object));
464 case PAD_PROP_DIRECTION:
465 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
467 case PAD_PROP_TEMPLATE:
468 gst_pad_set_pad_template (GST_PAD_CAST (object),
469 (GstPadTemplate *) g_value_get_object (value));
472 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
478 gst_pad_get_property (GObject * object, guint prop_id,
479 GValue * value, GParamSpec * pspec)
481 g_return_if_fail (GST_IS_PAD (object));
485 GST_OBJECT_LOCK (object);
486 g_value_set_boxed (value, GST_PAD_CAPS (object));
487 GST_OBJECT_UNLOCK (object);
489 case PAD_PROP_DIRECTION:
490 g_value_set_enum (value, GST_PAD_DIRECTION (object));
492 case PAD_PROP_TEMPLATE:
493 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
496 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
503 * @name: the name of the new pad.
504 * @direction: the #GstPadDirection of the pad.
506 * Creates a new pad with the given name in the given direction.
507 * If name is NULL, a guaranteed unique name (across all pads)
509 * This function makes a copy of the name so you can safely free the name.
511 * Returns: a new #GstPad, or NULL in case of an error.
516 gst_pad_new (const gchar * name, GstPadDirection direction)
518 return g_object_new (GST_TYPE_PAD,
519 "name", name, "direction", direction, NULL);
523 * gst_pad_new_from_template:
524 * @templ: the pad template to use
525 * @name: the name of the element
527 * Creates a new pad with the given name from the given template.
528 * If name is NULL, a guaranteed unique name (across all pads)
530 * This function makes a copy of the name so you can safely free the name.
532 * Returns: a new #GstPad, or NULL in case of an error.
535 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
537 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
539 return g_object_new (GST_TYPE_PAD,
540 "name", name, "direction", templ->direction, "template", templ, NULL);
544 * gst_pad_new_from_static_template:
545 * @templ: the #GstStaticPadTemplate to use
546 * @name: the name of the element
548 * Creates a new pad with the given name from the given static template.
549 * If name is NULL, a guaranteed unique name (across all pads)
551 * This function makes a copy of the name so you can safely free the name.
553 * Returns: a new #GstPad, or NULL in case of an error.
556 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
560 GstPadTemplate *template;
562 template = gst_static_pad_template_get (templ);
563 pad = gst_pad_new_from_template (template, name);
564 gst_object_unref (template);
569 * gst_pad_get_direction:
570 * @pad: a #GstPad to get the direction of.
572 * Gets the direction of the pad. The direction of the pad is
573 * decided at construction time so this function does not take
576 * Returns: the #GstPadDirection of the pad.
581 gst_pad_get_direction (GstPad * pad)
583 GstPadDirection result;
585 /* PAD_UNKNOWN is a little silly but we need some sort of
586 * error return value */
587 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
589 result = GST_PAD_DIRECTION (pad);
595 gst_pad_activate_default (GstPad * pad)
597 return gst_pad_activate_push (pad, TRUE);
601 pre_activate (GstPad * pad, GstActivateMode new_mode)
604 case GST_ACTIVATE_PUSH:
605 case GST_ACTIVATE_PULL:
606 GST_OBJECT_LOCK (pad);
607 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
609 GST_PAD_UNSET_FLUSHING (pad);
610 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
611 GST_OBJECT_UNLOCK (pad);
613 case GST_ACTIVATE_NONE:
614 GST_OBJECT_LOCK (pad);
615 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
616 GST_PAD_SET_FLUSHING (pad);
617 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
618 /* unlock blocked pads so element can resume and stop */
619 GST_PAD_BLOCK_BROADCAST (pad);
620 GST_OBJECT_UNLOCK (pad);
626 post_activate (GstPad * pad, GstActivateMode new_mode)
629 case GST_ACTIVATE_PUSH:
630 case GST_ACTIVATE_PULL:
633 case GST_ACTIVATE_NONE:
634 /* ensures that streaming stops */
635 GST_PAD_STREAM_LOCK (pad);
636 GST_DEBUG_OBJECT (pad, "stopped streaming");
637 GST_PAD_STREAM_UNLOCK (pad);
643 * gst_pad_set_active:
644 * @pad: the #GstPad to activate or deactivate.
645 * @active: whether or not the pad should be active.
647 * Activates or deactivates the given pad.
648 * Normally called from within core state change functions.
650 * If @active, makes sure the pad is active. If it is already active, either in
651 * push or pull mode, just return. Otherwise dispatches to the pad's activate
652 * function to perform the actual activation.
654 * If not @active, checks the pad's current mode and calls
655 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
658 * Returns: #TRUE if the operation was successful.
663 gst_pad_set_active (GstPad * pad, gboolean active)
666 gboolean ret = FALSE;
668 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
670 GST_OBJECT_LOCK (pad);
671 old = GST_PAD_ACTIVATE_MODE (pad);
672 GST_OBJECT_UNLOCK (pad);
676 case GST_ACTIVATE_PUSH:
677 GST_DEBUG_OBJECT (pad, "activating pad from push");
680 case GST_ACTIVATE_PULL:
681 GST_DEBUG_OBJECT (pad, "activating pad from pull");
684 case GST_ACTIVATE_NONE:
685 GST_DEBUG_OBJECT (pad, "activating pad from none");
686 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
691 case GST_ACTIVATE_PUSH:
692 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
693 ret = gst_pad_activate_push (pad, FALSE);
695 case GST_ACTIVATE_PULL:
696 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
697 ret = gst_pad_activate_pull (pad, FALSE);
699 case GST_ACTIVATE_NONE:
700 GST_DEBUG_OBJECT (pad, "deactivating pad from none");
707 GST_OBJECT_LOCK (pad);
709 g_critical ("Failed to deactivate pad %s:%s, very bad",
710 GST_DEBUG_PAD_NAME (pad));
712 GST_WARNING_OBJECT (pad, "Failed to activate pad");
714 GST_OBJECT_UNLOCK (pad);
721 * gst_pad_activate_pull:
722 * @pad: the #GstPad to activate or deactivate.
723 * @active: whether or not the pad should be active.
725 * Activates or deactivates the given pad in pull mode via dispatching to the
726 * pad's activatepullfunc. For use from within pad activation functions only.
727 * When called on sink pads, will first proxy the call to the peer pad, which
728 * is expected to activate its internally linked pads from within its
729 * activate_pull function.
731 * If you don't know what this is, you probably don't want to call it.
733 * Returns: TRUE if the operation was successful.
738 gst_pad_activate_pull (GstPad * pad, gboolean active)
740 GstActivateMode old, new;
743 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
745 GST_OBJECT_LOCK (pad);
746 old = GST_PAD_ACTIVATE_MODE (pad);
747 GST_OBJECT_UNLOCK (pad);
751 case GST_ACTIVATE_PULL:
752 GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
754 case GST_ACTIVATE_PUSH:
755 GST_DEBUG_OBJECT (pad,
756 "activating pad from push, deactivate push first");
757 /* pad was activate in the wrong direction, deactivate it
758 * and reactivate it in pull mode */
759 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
760 goto deactivate_failed;
761 /* fallthrough, pad is deactivated now. */
762 case GST_ACTIVATE_NONE:
763 GST_DEBUG_OBJECT (pad, "activating pad from none");
768 case GST_ACTIVATE_NONE:
769 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
771 case GST_ACTIVATE_PUSH:
772 GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
773 /* pad was activated in the other direction, deactivate it
774 * in push mode, this should not happen... */
775 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
776 goto deactivate_failed;
777 /* everything is fine now */
779 case GST_ACTIVATE_PULL:
780 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
785 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
786 if ((peer = gst_pad_get_peer (pad))) {
787 GST_DEBUG_OBJECT (pad, "calling peer");
788 if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
790 gst_object_unref (peer);
792 /* there is no peer, this is only fatal when we activate. When we
793 * deactivate, we must assume the application has unlinked the peer and
794 * will deactivate it eventually. */
798 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
801 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
802 goto failure; /* Can't activate pull on a src without a
806 new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
807 pre_activate (pad, new);
809 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
810 if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
813 /* can happen for sinks of passthrough elements */
816 post_activate (pad, new);
818 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
819 active ? "activated" : "deactivated");
825 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
826 active ? "activated" : "deactivated");
831 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
832 "failed to %s in switch to pull from mode %d",
833 (active ? "activate" : "deactivate"), old);
838 GST_OBJECT_LOCK (peer);
839 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
840 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
841 GST_OBJECT_UNLOCK (peer);
842 gst_object_unref (peer);
847 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
853 GST_OBJECT_LOCK (pad);
854 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
855 active ? "activate" : "deactivate");
856 GST_PAD_SET_FLUSHING (pad);
857 GST_PAD_ACTIVATE_MODE (pad) = old;
858 GST_OBJECT_UNLOCK (pad);
864 * gst_pad_activate_push:
865 * @pad: the #GstPad to activate or deactivate.
866 * @active: whether the pad should be active or not.
868 * Activates or deactivates the given pad in push mode via dispatching to the
869 * pad's activatepushfunc. For use from within pad activation functions only.
871 * If you don't know what this is, you probably don't want to call it.
873 * Returns: %TRUE if the operation was successful.
878 gst_pad_activate_push (GstPad * pad, gboolean active)
880 GstActivateMode old, new;
882 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
883 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
884 active ? "activated" : "deactivated");
886 GST_OBJECT_LOCK (pad);
887 old = GST_PAD_ACTIVATE_MODE (pad);
888 GST_OBJECT_UNLOCK (pad);
892 case GST_ACTIVATE_PUSH:
893 GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
895 case GST_ACTIVATE_PULL:
896 GST_DEBUG_OBJECT (pad,
897 "activating pad from push, deactivating pull first");
898 /* pad was activate in the wrong direction, deactivate it
899 * an reactivate it in push mode */
900 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
901 goto deactivate_failed;
902 /* fallthrough, pad is deactivated now. */
903 case GST_ACTIVATE_NONE:
904 GST_DEBUG_OBJECT (pad, "activating pad from none");
909 case GST_ACTIVATE_NONE:
910 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
912 case GST_ACTIVATE_PULL:
913 GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
914 /* pad was activated in the other direction, deactivate it
915 * in pull mode, this should not happen... */
916 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
917 goto deactivate_failed;
918 /* everything is fine now */
920 case GST_ACTIVATE_PUSH:
921 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
926 new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
927 pre_activate (pad, new);
929 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
930 if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
934 /* quite ok, element relies on state change func to prepare itself */
937 post_activate (pad, new);
939 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
940 active ? "activated" : "deactivated");
945 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
946 active ? "activated" : "deactivated");
951 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
952 "failed to %s in switch to push from mode %d",
953 (active ? "activate" : "deactivate"), old);
958 GST_OBJECT_LOCK (pad);
959 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
960 active ? "activate" : "deactivate");
961 GST_PAD_SET_FLUSHING (pad);
962 GST_PAD_ACTIVATE_MODE (pad) = old;
963 GST_OBJECT_UNLOCK (pad);
970 * @pad: the #GstPad to query
972 * Query if a pad is active
974 * Returns: TRUE if the pad is active.
979 gst_pad_is_active (GstPad * pad)
981 gboolean result = FALSE;
983 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
985 GST_OBJECT_LOCK (pad);
986 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
987 GST_OBJECT_UNLOCK (pad);
993 * gst_pad_set_blocked_async_full:
994 * @pad: the #GstPad to block or unblock
995 * @blocked: boolean indicating whether the pad should be blocked or unblocked
996 * @callback: #GstPadBlockCallback that will be called when the
998 * @user_data: user data passed to the callback
999 * @destroy_data: #GDestroyNotify for user_data
1001 * Blocks or unblocks the dataflow on a pad. The provided callback
1002 * is called when the operation succeeds; this happens right before the next
1003 * attempt at pushing a buffer on the pad.
1005 * This can take a while as the pad can only become blocked when real dataflow
1007 * When the pipeline is stalled, for example in PAUSED, this can
1008 * take an indeterminate amount of time.
1009 * You can pass NULL as the callback to make this call block. Be careful with
1010 * this blocking call as it might not return for reasons stated above.
1012 * Returns: TRUE if the pad could be blocked. This function can fail if the
1013 * wrong parameters were passed or the pad was already in the requested state.
1020 gst_pad_set_blocked_async_full (GstPad * pad, gboolean blocked,
1021 GstPadBlockCallback callback, gpointer user_data,
1022 GDestroyNotify destroy_data)
1024 gboolean was_blocked = FALSE;
1026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1028 GST_OBJECT_LOCK (pad);
1030 was_blocked = GST_PAD_IS_BLOCKED (pad);
1032 if (G_UNLIKELY (was_blocked == blocked))
1033 goto had_right_state;
1036 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad");
1038 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
1040 if (pad->block_destroy_data && pad->block_data)
1041 pad->block_destroy_data (pad->block_data);
1043 pad->block_callback = callback;
1044 pad->block_data = user_data;
1045 pad->block_destroy_data = destroy_data;
1046 pad->abidata.ABI.block_callback_called = FALSE;
1048 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
1049 GST_PAD_BLOCK_WAIT (pad);
1050 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
1053 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad");
1055 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
1057 if (pad->block_destroy_data && pad->block_data)
1058 pad->block_destroy_data (pad->block_data);
1060 pad->block_callback = callback;
1061 pad->block_data = user_data;
1062 pad->block_destroy_data = destroy_data;
1063 pad->abidata.ABI.block_callback_called = FALSE;
1065 GST_PAD_BLOCK_BROADCAST (pad);
1067 /* no callback, wait for the unblock to happen */
1068 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
1069 GST_PAD_BLOCK_WAIT (pad);
1070 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
1073 GST_OBJECT_UNLOCK (pad);
1079 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1080 "pad was in right state (%d)", was_blocked);
1081 GST_OBJECT_UNLOCK (pad);
1088 * gst_pad_set_blocked_async:
1089 * @pad: the #GstPad to block or unblock
1090 * @blocked: boolean indicating whether the pad should be blocked or unblocked
1091 * @callback: #GstPadBlockCallback that will be called when the
1092 * operation succeeds
1093 * @user_data: user data passed to the callback
1095 * Blocks or unblocks the dataflow on a pad. The provided callback
1096 * is called when the operation succeeds; this happens right before the next
1097 * attempt at pushing a buffer on the pad.
1099 * This can take a while as the pad can only become blocked when real dataflow
1101 * When the pipeline is stalled, for example in PAUSED, this can
1102 * take an indeterminate amount of time.
1103 * You can pass NULL as the callback to make this call block. Be careful with
1104 * this blocking call as it might not return for reasons stated above.
1106 * Returns: TRUE if the pad could be blocked. This function can fail if the
1107 * wrong parameters were passed or the pad was already in the requested state.
1112 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
1113 GstPadBlockCallback callback, gpointer user_data)
1115 return gst_pad_set_blocked_async_full (pad, blocked,
1116 callback, user_data, NULL);
1120 * gst_pad_set_blocked:
1121 * @pad: the #GstPad to block or unblock
1122 * @blocked: boolean indicating we should block or unblock
1124 * Blocks or unblocks the dataflow on a pad. This function is
1125 * a shortcut for gst_pad_set_blocked_async() with a NULL
1128 * Returns: TRUE if the pad could be blocked. This function can fail if the
1129 * wrong parameters were passed or the pad was already in the requested state.
1134 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
1136 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
1140 * gst_pad_is_blocked:
1141 * @pad: the #GstPad to query
1143 * Checks if the pad is blocked or not. This function returns the
1144 * last requested state of the pad. It is not certain that the pad
1145 * is actually blocking at this point (see gst_pad_is_blocking()).
1147 * Returns: TRUE if the pad is blocked.
1152 gst_pad_is_blocked (GstPad * pad)
1154 gboolean result = FALSE;
1156 g_return_val_if_fail (GST_IS_PAD (pad), result);
1158 GST_OBJECT_LOCK (pad);
1159 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
1160 GST_OBJECT_UNLOCK (pad);
1166 * gst_pad_is_blocking:
1167 * @pad: the #GstPad to query
1169 * Checks if the pad is blocking or not. This is a guaranteed state
1170 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1172 * Returns: TRUE if the pad is blocking.
1179 gst_pad_is_blocking (GstPad * pad)
1181 gboolean result = FALSE;
1183 g_return_val_if_fail (GST_IS_PAD (pad), result);
1185 GST_OBJECT_LOCK (pad);
1186 /* the blocking flag is only valid if the pad is not flushing */
1187 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING) &&
1188 !GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING);
1189 GST_OBJECT_UNLOCK (pad);
1195 * gst_pad_set_activate_function:
1197 * @activate: the #GstPadActivateFunction to set.
1199 * Sets the given activate function for @pad. The activate function will
1200 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1201 * the actual activation. Only makes sense to set on sink pads.
1203 * Call this function if your sink pad can start a pull-based task.
1206 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1208 g_return_if_fail (GST_IS_PAD (pad));
1210 GST_PAD_ACTIVATEFUNC (pad) = activate;
1211 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1212 GST_DEBUG_FUNCPTR_NAME (activate));
1216 * gst_pad_set_activatepull_function:
1218 * @activatepull: the #GstPadActivateModeFunction to set.
1220 * Sets the given activate_pull function for the pad. An activate_pull function
1221 * prepares the element and any upstream connections for pulling. See XXX
1222 * part-activation.txt for details.
1225 gst_pad_set_activatepull_function (GstPad * pad,
1226 GstPadActivateModeFunction activatepull)
1228 g_return_if_fail (GST_IS_PAD (pad));
1230 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1231 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepullfunc set to %s",
1232 GST_DEBUG_FUNCPTR_NAME (activatepull));
1236 * gst_pad_set_activatepush_function:
1238 * @activatepush: the #GstPadActivateModeFunction to set.
1240 * Sets the given activate_push function for the pad. An activate_push function
1241 * prepares the element for pushing. See XXX part-activation.txt for details.
1244 gst_pad_set_activatepush_function (GstPad * pad,
1245 GstPadActivateModeFunction activatepush)
1247 g_return_if_fail (GST_IS_PAD (pad));
1249 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1250 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepushfunc set to %s",
1251 GST_DEBUG_FUNCPTR_NAME (activatepush));
1255 * gst_pad_set_chain_function:
1256 * @pad: a sink #GstPad.
1257 * @chain: the #GstPadChainFunction to set.
1259 * Sets the given chain function for the pad. The chain function is called to
1260 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1263 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1265 g_return_if_fail (GST_IS_PAD (pad));
1266 g_return_if_fail (GST_PAD_IS_SINK (pad));
1268 GST_PAD_CHAINFUNC (pad) = chain;
1269 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1270 GST_DEBUG_FUNCPTR_NAME (chain));
1274 * gst_pad_set_chain_list_function:
1275 * @pad: a sink #GstPad.
1276 * @chainlist: the #GstPadChainListFunction to set.
1278 * Sets the given chain list function for the pad. The chainlist function is
1279 * called to process a #GstBufferList input buffer list. See
1280 * #GstPadChainListFunction for more details.
1285 gst_pad_set_chain_list_function (GstPad * pad,
1286 GstPadChainListFunction chainlist)
1288 g_return_if_fail (GST_IS_PAD (pad));
1289 g_return_if_fail (GST_PAD_IS_SINK (pad));
1291 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1292 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1293 GST_DEBUG_FUNCPTR_NAME (chainlist));
1297 * gst_pad_set_getrange_function:
1298 * @pad: a source #GstPad.
1299 * @get: the #GstPadGetRangeFunction to set.
1301 * Sets the given getrange function for the pad. The getrange function is
1302 * called to produce a new #GstBuffer to start the processing pipeline. see
1303 * #GstPadGetRangeFunction for a description of the getrange function.
1306 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1308 g_return_if_fail (GST_IS_PAD (pad));
1309 g_return_if_fail (GST_PAD_IS_SRC (pad));
1311 GST_PAD_GETRANGEFUNC (pad) = get;
1313 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1314 GST_DEBUG_FUNCPTR_NAME (get));
1318 * gst_pad_set_checkgetrange_function:
1319 * @pad: a source #GstPad.
1320 * @check: the #GstPadCheckGetRangeFunction to set.
1322 * Sets the given checkgetrange function for the pad. Implement this function
1323 * on a pad if you dynamically support getrange based scheduling on the pad.
1326 gst_pad_set_checkgetrange_function (GstPad * pad,
1327 GstPadCheckGetRangeFunction check)
1329 g_return_if_fail (GST_IS_PAD (pad));
1330 g_return_if_fail (GST_PAD_IS_SRC (pad));
1332 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
1334 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "checkgetrangefunc set to %s",
1335 GST_DEBUG_FUNCPTR_NAME (check));
1339 * gst_pad_set_event_function:
1340 * @pad: a #GstPad of either direction.
1341 * @event: the #GstPadEventFunction to set.
1343 * Sets the given event handler for the pad.
1346 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1348 g_return_if_fail (GST_IS_PAD (pad));
1350 GST_PAD_EVENTFUNC (pad) = event;
1352 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1353 GST_DEBUG_FUNCPTR_NAME (event));
1357 * gst_pad_set_query_function:
1358 * @pad: a #GstPad of either direction.
1359 * @query: the #GstPadQueryFunction to set.
1361 * Set the given query function for the pad.
1364 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1366 g_return_if_fail (GST_IS_PAD (pad));
1368 GST_PAD_QUERYFUNC (pad) = query;
1370 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1371 GST_DEBUG_FUNCPTR_NAME (query));
1375 * gst_pad_set_query_type_function:
1376 * @pad: a #GstPad of either direction.
1377 * @type_func: the #GstPadQueryTypeFunction to set.
1379 * Set the given query type function for the pad.
1382 gst_pad_set_query_type_function (GstPad * pad,
1383 GstPadQueryTypeFunction type_func)
1385 g_return_if_fail (GST_IS_PAD (pad));
1387 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1389 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "querytypefunc set to %s",
1390 GST_DEBUG_FUNCPTR_NAME (type_func));
1394 * gst_pad_get_query_types:
1397 * Get an array of supported queries that can be performed
1400 * Returns: a zero-terminated array of #GstQueryType.
1402 const GstQueryType *
1403 gst_pad_get_query_types (GstPad * pad)
1405 GstPadQueryTypeFunction func;
1407 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1409 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1421 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1423 *data = gst_pad_get_query_types (pad);
1429 * gst_pad_get_query_types_default:
1432 * Invoke the default dispatcher for the query types on
1435 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1436 * internally-linked pads has a query types function.
1438 const GstQueryType *
1439 gst_pad_get_query_types_default (GstPad * pad)
1441 GstQueryType *result = NULL;
1443 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1445 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1446 gst_pad_get_query_types_dispatcher, &result);
1452 * gst_pad_set_iterate_internal_links_function:
1453 * @pad: a #GstPad of either direction.
1454 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1456 * Sets the given internal link iterator function for the pad.
1461 gst_pad_set_iterate_internal_links_function (GstPad * pad,
1462 GstPadIterIntLinkFunction iterintlink)
1464 g_return_if_fail (GST_IS_PAD (pad));
1466 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1467 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1468 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1472 * gst_pad_set_internal_link_function:
1473 * @pad: a #GstPad of either direction.
1474 * @intlink: the #GstPadIntLinkFunction to set.
1476 * Sets the given internal link function for the pad.
1478 * Deprecated: Use the thread-safe gst_pad_set_iterate_internal_links_function()
1480 #ifndef GST_REMOVE_DEPRECATED
1481 #ifdef GST_DISABLE_DEPRECATED
1483 gst_pad_set_internal_link_function (GstPad * pad,
1484 GstPadIntLinkFunction intlink);
1487 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1489 g_return_if_fail (GST_IS_PAD (pad));
1491 GST_PAD_INTLINKFUNC (pad) = intlink;
1492 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link set to %s",
1493 GST_DEBUG_FUNCPTR_NAME (intlink));
1495 #endif /* GST_REMOVE_DEPRECATED */
1498 * gst_pad_set_link_function:
1500 * @link: the #GstPadLinkFunction to set.
1502 * Sets the given link function for the pad. It will be called when
1503 * the pad is linked with another pad.
1505 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1508 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1509 * cannot be made for some reason.
1511 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1512 * of the peer sink pad, if present.
1515 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1517 g_return_if_fail (GST_IS_PAD (pad));
1519 GST_PAD_LINKFUNC (pad) = link;
1520 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1521 GST_DEBUG_FUNCPTR_NAME (link));
1525 * gst_pad_set_unlink_function:
1527 * @unlink: the #GstPadUnlinkFunction to set.
1529 * Sets the given unlink function for the pad. It will be called
1530 * when the pad is unlinked.
1533 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1535 g_return_if_fail (GST_IS_PAD (pad));
1537 GST_PAD_UNLINKFUNC (pad) = unlink;
1538 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1539 GST_DEBUG_FUNCPTR_NAME (unlink));
1543 * gst_pad_set_getcaps_function:
1545 * @getcaps: the #GstPadGetCapsFunction to set.
1547 * Sets the given getcaps function for the pad. @getcaps should return the
1548 * allowable caps for a pad in the context of the element's state, its link to
1549 * other elements, and the devices or files it has opened. These caps must be a
1550 * subset of the pad template caps. In the NULL state with no links, @getcaps
1551 * should ideally return the same caps as the pad template. In rare
1552 * circumstances, an object property can affect the caps returned by @getcaps,
1553 * but this is discouraged.
1555 * You do not need to call this function if @pad's allowed caps are always the
1556 * same as the pad template caps. This can only be true if the padtemplate
1557 * has fixed simple caps.
1559 * For most filters, the caps returned by @getcaps is directly affected by the
1560 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1561 * the srcpad's getcaps function is directly related to the stream data. Again,
1562 * @getcaps should return the most specific caps it reasonably can, since this
1563 * helps with autoplugging.
1565 * Note that the return value from @getcaps is owned by the caller, so the
1566 * caller should unref the caps after usage.
1569 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1571 g_return_if_fail (GST_IS_PAD (pad));
1573 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1574 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getcapsfunc set to %s",
1575 GST_DEBUG_FUNCPTR_NAME (getcaps));
1579 * gst_pad_set_acceptcaps_function:
1581 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1583 * Sets the given acceptcaps function for the pad. The acceptcaps function
1584 * will be called to check if the pad can accept the given caps. Setting the
1585 * acceptcaps function to NULL restores the default behaviour of allowing
1586 * any caps that matches the caps from gst_pad_get_caps().
1589 gst_pad_set_acceptcaps_function (GstPad * pad,
1590 GstPadAcceptCapsFunction acceptcaps)
1592 g_return_if_fail (GST_IS_PAD (pad));
1594 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1595 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "acceptcapsfunc set to %s",
1596 GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1600 * gst_pad_set_fixatecaps_function:
1602 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1604 * Sets the given fixatecaps function for the pad. The fixatecaps function
1605 * will be called whenever the default values for a GstCaps needs to be
1609 gst_pad_set_fixatecaps_function (GstPad * pad,
1610 GstPadFixateCapsFunction fixatecaps)
1612 g_return_if_fail (GST_IS_PAD (pad));
1614 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1615 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fixatecapsfunc set to %s",
1616 GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1620 * gst_pad_set_setcaps_function:
1622 * @setcaps: the #GstPadSetCapsFunction to set.
1624 * Sets the given setcaps function for the pad. The setcaps function
1625 * will be called whenever a buffer with a new media type is pushed or
1626 * pulled from the pad. The pad/element needs to update its internal
1627 * structures to process the new media type. If this new type is not
1628 * acceptable, the setcaps function should return FALSE.
1631 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1633 g_return_if_fail (GST_IS_PAD (pad));
1635 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1636 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "setcapsfunc set to %s",
1637 GST_DEBUG_FUNCPTR_NAME (setcaps));
1641 * gst_pad_set_bufferalloc_function:
1642 * @pad: a sink #GstPad.
1643 * @bufalloc: the #GstPadBufferAllocFunction to set.
1645 * Sets the given bufferalloc function for the pad. Note that the
1646 * bufferalloc function can only be set on sinkpads.
1649 gst_pad_set_bufferalloc_function (GstPad * pad,
1650 GstPadBufferAllocFunction bufalloc)
1652 g_return_if_fail (GST_IS_PAD (pad));
1653 g_return_if_fail (GST_PAD_IS_SINK (pad));
1655 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1656 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "bufferallocfunc set to %s",
1657 GST_DEBUG_FUNCPTR_NAME (bufalloc));
1662 * @srcpad: the source #GstPad to unlink.
1663 * @sinkpad: the sink #GstPad to unlink.
1665 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1666 * signal on both pads.
1668 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1669 * the pads were not linked together.
1674 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1676 gboolean result = FALSE;
1677 GstElement *parent = NULL;
1679 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1680 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1681 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1682 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1684 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1685 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1686 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1688 /* We need to notify the parent before taking any pad locks as the bin in
1689 * question might be waiting for a lock on the pad while holding its lock
1690 * that our message will try to take. */
1691 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1692 if (GST_IS_ELEMENT (parent)) {
1693 gst_element_post_message (parent,
1694 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1695 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1697 gst_object_unref (parent);
1702 GST_OBJECT_LOCK (srcpad);
1704 GST_OBJECT_LOCK (sinkpad);
1706 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1707 goto not_linked_together;
1709 if (GST_PAD_UNLINKFUNC (srcpad)) {
1710 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1712 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1713 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1716 /* first clear peers */
1717 GST_PAD_PEER (srcpad) = NULL;
1718 GST_PAD_PEER (sinkpad) = NULL;
1720 GST_OBJECT_UNLOCK (sinkpad);
1721 GST_OBJECT_UNLOCK (srcpad);
1723 /* fire off a signal to each of the pads telling them
1724 * that they've been unlinked */
1725 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1726 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1728 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1729 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1734 if (parent != NULL) {
1735 gst_element_post_message (parent,
1736 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1737 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1738 gst_object_unref (parent);
1743 not_linked_together:
1745 /* we do not emit a warning in this case because unlinking cannot
1746 * be made MT safe.*/
1747 GST_OBJECT_UNLOCK (sinkpad);
1748 GST_OBJECT_UNLOCK (srcpad);
1754 * gst_pad_is_linked:
1755 * @pad: pad to check
1757 * Checks if a @pad is linked to another pad or not.
1759 * Returns: TRUE if the pad is linked, FALSE otherwise.
1764 gst_pad_is_linked (GstPad * pad)
1768 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1770 GST_OBJECT_LOCK (pad);
1771 result = (GST_PAD_PEER (pad) != NULL);
1772 GST_OBJECT_UNLOCK (pad);
1777 /* get the caps from both pads and see if the intersection
1780 * This function should be called with the pad LOCK on both
1784 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1785 GstPadLinkCheck flags)
1787 GstCaps *srccaps = NULL;
1788 GstCaps *sinkcaps = NULL;
1789 gboolean compatible = FALSE;
1791 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1794 /* Doing the expensive caps checking takes priority over only checking the template caps */
1795 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1796 srccaps = gst_pad_get_caps_unlocked (src);
1797 sinkcaps = gst_pad_get_caps_unlocked (sink);
1799 /* If one of the two pads doesn't have a template, consider the intersection
1801 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1802 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1806 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1808 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1811 GST_CAT_DEBUG (GST_CAT_CAPS, "src caps %" GST_PTR_FORMAT, srccaps);
1812 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1814 /* if we have caps on both pads we can check the intersection. If one
1815 * of the caps is NULL, we return TRUE. */
1816 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1818 gst_caps_unref (srccaps);
1820 gst_caps_unref (sinkcaps);
1824 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1825 gst_caps_unref (srccaps);
1826 gst_caps_unref (sinkcaps);
1829 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1830 (compatible ? "" : "not"));
1835 /* check if the grandparents of both pads are the same.
1836 * This check is required so that we don't try to link
1837 * pads from elements in different bins without ghostpads.
1839 * The LOCK should be held on both pads
1842 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1844 GstObject *psrc, *psink;
1846 psrc = GST_OBJECT_PARENT (src);
1847 psink = GST_OBJECT_PARENT (sink);
1849 /* if one of the pads has no parent, we allow the link */
1850 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1853 /* only care about parents that are elements */
1854 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1855 goto no_element_parent;
1857 /* if the parents are the same, we have a loop */
1858 if (G_UNLIKELY (psrc == psink))
1861 /* if they both have a parent, we check the grandparents. We can not lock
1862 * the parent because we hold on the child (pad) and the locking order is
1863 * parent >> child. */
1864 psrc = GST_OBJECT_PARENT (psrc);
1865 psink = GST_OBJECT_PARENT (psink);
1867 /* if they have grandparents but they are not the same */
1868 if (G_UNLIKELY (psrc != psink))
1869 goto wrong_grandparents;
1876 GST_CAT_DEBUG (GST_CAT_CAPS,
1877 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1878 GST_PTR_FORMAT, psrc, psink);
1883 GST_CAT_DEBUG (GST_CAT_CAPS,
1884 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1885 GST_PTR_FORMAT, psrc, psink);
1890 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1896 GST_CAT_DEBUG (GST_CAT_CAPS,
1897 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1898 GST_PTR_FORMAT, psrc, psink);
1903 /* FIXME leftover from an attempt at refactoring... */
1904 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1905 * the two pads will be locked in the srcpad, sinkpad order. */
1906 static GstPadLinkReturn
1907 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1909 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1910 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1912 GST_OBJECT_LOCK (srcpad);
1914 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1915 goto src_was_linked;
1917 GST_OBJECT_LOCK (sinkpad);
1919 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1920 goto sink_was_linked;
1922 /* check hierarchy, pads can only be linked if the grandparents
1924 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1925 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1926 goto wrong_hierarchy;
1928 /* check pad caps for non-empty intersection */
1929 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1932 /* FIXME check pad scheduling for non-empty intersection */
1934 return GST_PAD_LINK_OK;
1938 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1939 GST_DEBUG_PAD_NAME (srcpad),
1940 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1941 /* we do not emit a warning in this case because unlinking cannot
1942 * be made MT safe.*/
1943 GST_OBJECT_UNLOCK (srcpad);
1944 return GST_PAD_LINK_WAS_LINKED;
1948 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1949 GST_DEBUG_PAD_NAME (sinkpad),
1950 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1951 /* we do not emit a warning in this case because unlinking cannot
1952 * be made MT safe.*/
1953 GST_OBJECT_UNLOCK (sinkpad);
1954 GST_OBJECT_UNLOCK (srcpad);
1955 return GST_PAD_LINK_WAS_LINKED;
1959 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1960 GST_OBJECT_UNLOCK (sinkpad);
1961 GST_OBJECT_UNLOCK (srcpad);
1962 return GST_PAD_LINK_WRONG_HIERARCHY;
1966 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1967 GST_OBJECT_UNLOCK (sinkpad);
1968 GST_OBJECT_UNLOCK (srcpad);
1969 return GST_PAD_LINK_NOFORMAT;
1975 * @srcpad: the source #GstPad.
1976 * @sinkpad: the sink #GstPad.
1978 * Checks if the source pad and the sink pad are compatible so they can be
1981 * Returns: TRUE if the pads can be linked.
1984 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1986 GstPadLinkReturn result;
1988 /* generic checks */
1989 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1990 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1992 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1993 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1995 /* gst_pad_link_prepare does everything for us, we only release the locks
1996 * on the pads that it gets us. If this function returns !OK the locks are not
1998 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
1999 if (result != GST_PAD_LINK_OK)
2002 GST_OBJECT_UNLOCK (srcpad);
2003 GST_OBJECT_UNLOCK (sinkpad);
2006 return result == GST_PAD_LINK_OK;
2010 * gst_pad_link_full:
2011 * @srcpad: the source #GstPad to link.
2012 * @sinkpad: the sink #GstPad to link.
2013 * @flags: the checks to validate when linking
2015 * Links the source pad and the sink pad.
2017 * This variant of #gst_pad_link provides a more granular control on the
2018 * checks being done when linking. While providing some considerable speedups
2019 * the caller of this method must be aware that wrong usage of those flags
2020 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2021 * for more information.
2023 * Returns: A result code indicating if the connection worked or
2031 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2033 GstPadLinkReturn result;
2036 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2037 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2038 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2039 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2040 GST_PAD_LINK_WRONG_DIRECTION);
2042 /* Notify the parent early. See gst_pad_unlink for details. */
2043 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2044 if (GST_IS_ELEMENT (parent)) {
2045 gst_element_post_message (parent,
2046 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2047 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2049 gst_object_unref (parent);
2054 /* prepare will also lock the two pads */
2055 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2057 if (result != GST_PAD_LINK_OK)
2060 /* must set peers before calling the link function */
2061 GST_PAD_PEER (srcpad) = sinkpad;
2062 GST_PAD_PEER (sinkpad) = srcpad;
2064 GST_OBJECT_UNLOCK (sinkpad);
2065 GST_OBJECT_UNLOCK (srcpad);
2067 /* FIXME released the locks here, concurrent thread might link
2068 * something else. */
2069 if (GST_PAD_LINKFUNC (srcpad)) {
2070 /* this one will call the peer link function */
2071 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
2072 } else if (GST_PAD_LINKFUNC (sinkpad)) {
2073 /* if no source link function, we need to call the sink link
2074 * function ourselves. */
2075 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
2077 result = GST_PAD_LINK_OK;
2080 GST_OBJECT_LOCK (srcpad);
2081 GST_OBJECT_LOCK (sinkpad);
2083 if (result == GST_PAD_LINK_OK) {
2084 GST_OBJECT_UNLOCK (sinkpad);
2085 GST_OBJECT_UNLOCK (srcpad);
2087 /* fire off a signal to each of the pads telling them
2088 * that they've been linked */
2089 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2090 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2092 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2093 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2095 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2096 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2098 GST_PAD_PEER (srcpad) = NULL;
2099 GST_PAD_PEER (sinkpad) = NULL;
2101 GST_OBJECT_UNLOCK (sinkpad);
2102 GST_OBJECT_UNLOCK (srcpad);
2107 gst_element_post_message (parent,
2108 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2109 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2110 gst_object_unref (parent);
2118 * @srcpad: the source #GstPad to link.
2119 * @sinkpad: the sink #GstPad to link.
2121 * Links the source pad and the sink pad.
2123 * Returns: A result code indicating if the connection worked or
2129 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2131 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2135 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2137 GstPadTemplate **template_p;
2139 /* this function would need checks if it weren't static */
2141 GST_OBJECT_LOCK (pad);
2142 template_p = &pad->padtemplate;
2143 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2144 GST_OBJECT_UNLOCK (pad);
2147 gst_pad_template_pad_created (templ, pad);
2151 * gst_pad_get_pad_template:
2154 * Gets the template for @pad.
2156 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
2157 * if this pad has no template.
2159 * FIXME: currently returns an unrefcounted padtemplate.
2162 gst_pad_get_pad_template (GstPad * pad)
2164 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2166 return GST_PAD_PAD_TEMPLATE (pad);
2170 /* should be called with the pad LOCK held */
2171 /* refs the caps, so caller is responsible for getting it unreffed */
2173 gst_pad_get_caps_unlocked (GstPad * pad)
2175 GstCaps *result = NULL;
2176 GstPadTemplate *templ;
2178 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2180 if (GST_PAD_GETCAPSFUNC (pad)) {
2181 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2182 "dispatching to pad getcaps function");
2184 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
2185 GST_OBJECT_UNLOCK (pad);
2186 result = GST_PAD_GETCAPSFUNC (pad) (pad);
2187 GST_OBJECT_LOCK (pad);
2188 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
2190 if (result == NULL) {
2191 g_critical ("pad %s:%s returned NULL caps from getcaps function",
2192 GST_DEBUG_PAD_NAME (pad));
2194 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2195 "pad getcaps returned %" GST_PTR_FORMAT, result);
2196 #ifndef G_DISABLE_ASSERT
2197 /* check that the returned caps are a real subset of the template caps */
2198 if (GST_PAD_PAD_TEMPLATE (pad)) {
2199 const GstCaps *templ_caps =
2200 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2201 if (!gst_caps_is_subset (result, templ_caps)) {
2204 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2205 "pad returned caps %" GST_PTR_FORMAT
2206 " which are not a real subset of its template caps %"
2207 GST_PTR_FORMAT, result, templ_caps);
2209 ("pad %s:%s returned caps which are not a real "
2210 "subset of its template caps", GST_DEBUG_PAD_NAME (pad));
2211 temp = gst_caps_intersect (templ_caps, result);
2212 gst_caps_unref (result);
2220 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2221 result = GST_PAD_TEMPLATE_CAPS (templ);
2222 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2223 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
2226 result = gst_caps_ref (result);
2229 if ((result = GST_PAD_CAPS (pad))) {
2230 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2231 "using pad caps %p %" GST_PTR_FORMAT, result, result);
2233 result = gst_caps_ref (result);
2237 /* this almost never happens */
2238 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2239 result = gst_caps_new_empty ();
2245 /* FIXME-0.11: what about making this the default and using
2246 * gst_caps_make_writable() explicitely where needed
2249 * gst_pad_get_caps_reffed:
2250 * @pad: a #GstPad to get the capabilities of.
2252 * Gets the capabilities this pad can produce or consume. Preferred function if
2253 * one only wants to read or intersect the caps.
2255 * Returns: the caps of the pad with incremented ref-count.
2260 gst_pad_get_caps_reffed (GstPad * pad)
2262 GstCaps *result = NULL;
2264 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2266 GST_OBJECT_LOCK (pad);
2268 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2270 result = gst_pad_get_caps_unlocked (pad);
2272 GST_OBJECT_UNLOCK (pad);
2279 * @pad: a #GstPad to get the capabilities of.
2281 * Gets the capabilities this pad can produce or consume.
2282 * Note that this method doesn't necessarily return the caps set by
2283 * gst_pad_set_caps() - use GST_PAD_CAPS() for that instead.
2284 * gst_pad_get_caps returns all possible caps a pad can operate with, using
2285 * the pad's get_caps function;
2286 * this returns the pad template caps if not explicitly set.
2288 * Returns: a newly allocated copy of the #GstCaps of this pad.
2293 gst_pad_get_caps (GstPad * pad)
2295 GstCaps *result = gst_pad_get_caps_reffed (pad);
2297 /* be sure that we have a copy */
2298 if (G_LIKELY (result))
2299 result = gst_caps_make_writable (result);
2304 /* FIXME-0.11: what about making this the default and using
2305 * gst_caps_make_writable() explicitely where needed
2308 * gst_pad_peer_get_caps_reffed:
2309 * @pad: a #GstPad to get the capabilities of.
2311 * Gets the capabilities of the peer connected to this pad. Preferred function
2312 * if one only wants to read or intersect the caps.
2314 * Returns: the caps of the pad with incremented ref-count.
2319 gst_pad_peer_get_caps_reffed (GstPad * pad)
2322 GstCaps *result = NULL;
2324 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2326 GST_OBJECT_LOCK (pad);
2328 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2330 peerpad = GST_PAD_PEER (pad);
2331 if (G_UNLIKELY (peerpad == NULL))
2334 gst_object_ref (peerpad);
2335 GST_OBJECT_UNLOCK (pad);
2337 result = gst_pad_get_caps_reffed (peerpad);
2339 gst_object_unref (peerpad);
2345 GST_OBJECT_UNLOCK (pad);
2351 * gst_pad_peer_get_caps:
2352 * @pad: a #GstPad to get the peer capabilities of.
2354 * Gets the capabilities of the peer connected to this pad. Similar to
2355 * gst_pad_get_caps().
2357 * Returns: a newly allocated copy of the #GstCaps of the peer pad. Use
2358 * gst_caps_unref() to get rid of it. This function returns %NULL if there is
2362 gst_pad_peer_get_caps (GstPad * pad)
2365 GstCaps *result = NULL;
2367 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2369 GST_OBJECT_LOCK (pad);
2371 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2373 peerpad = GST_PAD_PEER (pad);
2374 if (G_UNLIKELY (peerpad == NULL))
2377 gst_object_ref (peerpad);
2378 GST_OBJECT_UNLOCK (pad);
2380 result = gst_pad_get_caps (peerpad);
2382 gst_object_unref (peerpad);
2388 GST_OBJECT_UNLOCK (pad);
2394 fixate_value (GValue * dest, const GValue * src)
2396 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
2397 g_value_init (dest, G_TYPE_INT);
2398 g_value_set_int (dest, gst_value_get_int_range_min (src));
2399 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
2400 g_value_init (dest, G_TYPE_DOUBLE);
2401 g_value_set_double (dest, gst_value_get_double_range_min (src));
2402 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
2403 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
2404 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
2405 GValue temp = { 0 };
2407 /* list could be empty */
2408 if (gst_value_list_get_size (src) <= 0)
2411 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
2413 if (!fixate_value (dest, &temp))
2414 gst_value_init_and_copy (dest, &temp);
2415 g_value_unset (&temp);
2416 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
2417 gboolean res = FALSE;
2420 len = gst_value_array_get_size (src);
2421 g_value_init (dest, GST_TYPE_ARRAY);
2422 for (n = 0; n < len; n++) {
2424 const GValue *orig_kid = gst_value_array_get_value (src, n);
2426 if (!fixate_value (&kid, orig_kid))
2427 gst_value_init_and_copy (&kid, orig_kid);
2430 gst_value_array_append_value (dest, &kid);
2431 g_value_unset (&kid);
2435 g_value_unset (dest);
2446 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
2448 GstStructure *s = data;
2451 if (fixate_value (&v, value)) {
2452 gst_structure_id_set_value (s, field_id, &v);
2460 * gst_pad_fixate_caps:
2461 * @pad: a #GstPad to fixate
2462 * @caps: the #GstCaps to fixate
2464 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2465 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2468 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2470 GstPadFixateCapsFunction fixatefunc;
2473 g_return_if_fail (GST_IS_PAD (pad));
2474 g_return_if_fail (caps != NULL);
2475 g_return_if_fail (!gst_caps_is_empty (caps));
2476 /* FIXME-0.11: do not allow fixating any-caps
2477 * g_return_if_fail (!gst_caps_is_any (caps));
2480 if (gst_caps_is_fixed (caps) || gst_caps_is_any (caps))
2483 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
2485 fixatefunc (pad, caps);
2488 /* default fixation */
2489 gst_caps_truncate (caps);
2490 s = gst_caps_get_structure (caps, 0);
2491 gst_structure_foreach (s, gst_pad_default_fixate, s);
2494 /* Default accept caps implementation just checks against
2495 * against the allowed caps for the pad */
2497 gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
2499 /* get the caps and see if it intersects to something not empty */
2501 gboolean result = FALSE;
2503 GST_DEBUG_OBJECT (pad, "caps %" GST_PTR_FORMAT, caps);
2505 allowed = gst_pad_get_caps_reffed (pad);
2507 goto nothing_allowed;
2509 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2511 result = gst_caps_can_intersect (allowed, caps);
2513 gst_caps_unref (allowed);
2520 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2526 * gst_pad_accept_caps:
2527 * @pad: a #GstPad to check
2528 * @caps: a #GstCaps to check on the pad
2530 * Check if the given pad accepts the caps.
2532 * Returns: TRUE if the pad can accept the caps.
2535 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2538 GstPadAcceptCapsFunction acceptfunc;
2539 GstCaps *existing = NULL;
2541 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2543 /* any pad can be unnegotiated */
2547 /* lock for checking the existing caps */
2548 GST_OBJECT_LOCK (pad);
2549 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "accept caps of %p", caps);
2550 /* The current caps on a pad are trivially acceptable */
2551 if (G_LIKELY ((existing = GST_PAD_CAPS (pad)))) {
2552 if (caps == existing || gst_caps_is_equal (caps, existing))
2555 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2556 GST_OBJECT_UNLOCK (pad);
2558 if (G_LIKELY (acceptfunc)) {
2559 /* we can call the function */
2560 result = acceptfunc (pad, caps);
2561 GST_DEBUG_OBJECT (pad, "acceptfunc returned %d", result);
2563 /* Only null if the element explicitly unset it */
2564 result = gst_pad_acceptcaps_default (pad, caps);
2565 GST_DEBUG_OBJECT (pad, "default acceptcaps returned %d", result);
2571 GST_DEBUG_OBJECT (pad, "pad had same caps");
2572 GST_OBJECT_UNLOCK (pad);
2578 * gst_pad_peer_accept_caps:
2579 * @pad: a #GstPad to check the peer of
2580 * @caps: a #GstCaps to check on the pad
2582 * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
2585 * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
2588 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2593 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2595 GST_OBJECT_LOCK (pad);
2597 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "peer accept caps of (%p)", pad);
2599 peerpad = GST_PAD_PEER (pad);
2600 if (G_UNLIKELY (peerpad == NULL))
2603 gst_object_ref (peerpad);
2604 /* release lock before calling external methods but keep ref to pad */
2605 GST_OBJECT_UNLOCK (pad);
2607 result = gst_pad_accept_caps (peerpad, caps);
2609 gst_object_unref (peerpad);
2615 GST_OBJECT_UNLOCK (pad);
2622 * @pad: a #GstPad to set the capabilities of.
2623 * @caps: a #GstCaps to set.
2625 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2626 * caps on the pad will be unreffed. This function refs the caps so you should
2627 * unref if as soon as you don't need it anymore.
2628 * It is possible to set NULL caps, which will make the pad unnegotiated
2631 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2632 * or bad parameters were provided to this function.
2637 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2639 GstPadSetCapsFunction setcaps;
2642 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2643 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2645 GST_OBJECT_LOCK (pad);
2646 existing = GST_PAD_CAPS (pad);
2647 if (existing == caps)
2650 if (gst_caps_is_equal (caps, existing))
2651 goto setting_same_caps;
2653 setcaps = GST_PAD_SETCAPSFUNC (pad);
2655 /* call setcaps function to configure the pad only if the
2656 * caps is not NULL */
2657 if (setcaps != NULL && caps) {
2658 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2659 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2660 GST_OBJECT_UNLOCK (pad);
2661 if (!setcaps (pad, caps))
2663 GST_OBJECT_LOCK (pad);
2664 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2666 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad was dispatching");
2670 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2671 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "caps %p %" GST_PTR_FORMAT, caps,
2673 GST_OBJECT_UNLOCK (pad);
2675 g_object_notify (G_OBJECT (pad), "caps");
2681 GST_OBJECT_UNLOCK (pad);
2686 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2687 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2688 "caps %p %" GST_PTR_FORMAT " same as existing, updating ptr only", caps,
2690 GST_OBJECT_UNLOCK (pad);
2697 GST_OBJECT_LOCK (pad);
2698 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2699 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2700 "caps %" GST_PTR_FORMAT " could not be set", caps);
2701 GST_OBJECT_UNLOCK (pad);
2708 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2712 /* See if pad accepts the caps */
2713 if (!gst_caps_can_intersect (caps, gst_pad_get_pad_template_caps (pad)))
2716 /* set caps on pad if call succeeds */
2717 res = gst_pad_set_caps (pad, caps);
2718 /* no need to unref the caps here, set_caps takes a ref and
2719 * our ref goes away when we leave this function. */
2725 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2726 "caps %" GST_PTR_FORMAT " not accepted", caps);
2731 /* returns TRUE if the src pad could be configured to accept the given caps */
2733 gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
2738 /* See if pad accepts the caps */
2739 if (!gst_pad_accept_caps (pad, caps))
2742 res = gst_pad_set_caps (pad, caps);
2750 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2751 "caps %" GST_PTR_FORMAT " not accepted", caps);
2757 * gst_pad_get_pad_template_caps:
2758 * @pad: a #GstPad to get the template capabilities from.
2760 * Gets the capabilities for @pad's template.
2762 * Returns: the #GstCaps of this pad template. If you intend to keep a
2763 * reference on the caps, make a copy (see gst_caps_copy ()).
2766 gst_pad_get_pad_template_caps (GstPad * pad)
2768 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2770 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2772 if (GST_PAD_PAD_TEMPLATE (pad))
2773 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2775 return gst_static_caps_get (&anycaps);
2780 * @pad: a #GstPad to get the peer of.
2782 * Gets the peer of @pad. This function refs the peer pad so
2783 * you need to unref it after use.
2785 * Returns: the peer #GstPad. Unref after usage.
2790 gst_pad_get_peer (GstPad * pad)
2794 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2796 GST_OBJECT_LOCK (pad);
2797 result = GST_PAD_PEER (pad);
2799 gst_object_ref (result);
2800 GST_OBJECT_UNLOCK (pad);
2806 * gst_pad_get_allowed_caps:
2809 * Gets the capabilities of the allowed media types that can flow through
2810 * @pad and its peer.
2812 * The allowed capabilities is calculated as the intersection of the results of
2813 * calling gst_pad_get_caps() on @pad and its peer. The caller owns a reference
2814 * on the resulting caps.
2816 * Returns: the allowed #GstCaps of the pad link. Unref the caps when you no
2817 * longer need it. This function returns NULL when @pad has no peer.
2822 gst_pad_get_allowed_caps (GstPad * pad)
2829 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2831 GST_OBJECT_LOCK (pad);
2833 peer = GST_PAD_PEER (pad);
2834 if (G_UNLIKELY (peer == NULL))
2837 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2839 gst_object_ref (peer);
2840 GST_OBJECT_UNLOCK (pad);
2841 mycaps = gst_pad_get_caps_reffed (pad);
2843 peercaps = gst_pad_get_caps_reffed (peer);
2844 gst_object_unref (peer);
2846 caps = gst_caps_intersect (mycaps, peercaps);
2847 gst_caps_unref (peercaps);
2848 gst_caps_unref (mycaps);
2850 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2857 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2858 GST_OBJECT_UNLOCK (pad);
2865 * gst_pad_get_negotiated_caps:
2868 * Gets the capabilities of the media type that currently flows through @pad
2871 * This function can be used on both src and sinkpads. Note that srcpads are
2872 * always negotiated before sinkpads so it is possible that the negotiated caps
2873 * on the srcpad do not match the negotiated caps of the peer.
2875 * Returns: the negotiated #GstCaps of the pad link. Unref the caps when
2876 * you no longer need it. This function returns NULL when the @pad has no
2877 * peer or is not negotiated yet.
2882 gst_pad_get_negotiated_caps (GstPad * pad)
2887 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2889 GST_OBJECT_LOCK (pad);
2891 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2894 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting negotiated caps");
2896 caps = GST_PAD_CAPS (pad);
2898 gst_caps_ref (caps);
2899 GST_OBJECT_UNLOCK (pad);
2901 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "negotiated caps %" GST_PTR_FORMAT,
2908 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2909 GST_OBJECT_UNLOCK (pad);
2915 /* calls the buffer_alloc function on the given pad */
2916 static GstFlowReturn
2917 gst_pad_buffer_alloc_unchecked (GstPad * pad, guint64 offset, gint size,
2918 GstCaps * caps, GstBuffer ** buf)
2921 GstPadBufferAllocFunction bufferallocfunc;
2923 GST_OBJECT_LOCK (pad);
2924 /* when the pad is flushing we cannot give a buffer */
2925 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2928 bufferallocfunc = pad->bufferallocfunc;
2930 if (offset == GST_BUFFER_OFFSET_NONE) {
2931 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2932 "calling bufferallocfunc &%s (@%p) for size %d offset NONE",
2933 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc), bufferallocfunc, size);
2935 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2936 "calling bufferallocfunc &%s (@%p) of for size %d offset %"
2937 G_GUINT64_FORMAT, GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2938 bufferallocfunc, size, offset);
2940 GST_OBJECT_UNLOCK (pad);
2942 /* G_LIKELY for now since most elements don't implement a buffer alloc
2943 * function and there is no default alloc proxy function as this is usually
2945 if (G_LIKELY (bufferallocfunc == NULL))
2948 ret = bufferallocfunc (pad, offset, size, caps, buf);
2950 if (G_UNLIKELY (ret != GST_FLOW_OK))
2953 /* no error, but NULL buffer means fallback to the default */
2954 if (G_UNLIKELY (*buf == NULL))
2957 /* If the buffer alloc function didn't set up the caps like it should,
2959 if (G_UNLIKELY (caps && (GST_BUFFER_CAPS (*buf) == NULL))) {
2960 GST_WARNING_OBJECT (pad,
2961 "Buffer allocation function did not set caps. Setting");
2962 gst_buffer_set_caps (*buf, caps);
2968 /* pad was flushing */
2969 GST_OBJECT_UNLOCK (pad);
2970 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "pad was flushing");
2971 return GST_FLOW_WRONG_STATE;
2975 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2976 "alloc function returned error (%d) %s", ret, gst_flow_get_name (ret));
2981 /* fallback case, allocate a buffer of our own, add pad caps. */
2982 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fallback buffer alloc");
2984 if ((*buf = gst_buffer_try_new_and_alloc (size))) {
2985 GST_BUFFER_OFFSET (*buf) = offset;
2986 gst_buffer_set_caps (*buf, caps);
2989 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2990 "out of memory allocating %d bytes", size);
2991 return GST_FLOW_ERROR;
2996 /* FIXME 0.11: size should be unsigned */
2997 static GstFlowReturn
2998 gst_pad_alloc_buffer_full (GstPad * pad, guint64 offset, gint size,
2999 GstCaps * caps, GstBuffer ** buf, gboolean setcaps)
3004 gboolean caps_changed;
3006 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3007 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3008 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
3009 g_return_val_if_fail (size >= 0, GST_FLOW_ERROR);
3011 GST_DEBUG_OBJECT (pad, "offset %" G_GUINT64_FORMAT ", size %d, caps %"
3012 GST_PTR_FORMAT, offset, size, caps);
3014 GST_OBJECT_LOCK (pad);
3015 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3016 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
3019 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3022 gst_object_ref (peer);
3023 GST_OBJECT_UNLOCK (pad);
3025 ret = gst_pad_buffer_alloc_unchecked (peer, offset, size, caps, buf);
3026 gst_object_unref (peer);
3028 if (G_UNLIKELY (ret != GST_FLOW_OK))
3031 /* FIXME, move capnego this into a base class? */
3032 newcaps = GST_BUFFER_CAPS (*buf);
3034 /* Lock for checking caps, pretty pointless as the _pad_push() function might
3035 * change it concurrently, one of the problems with automatic caps setting in
3036 * pad_alloc_and_set_caps. Worst case, if does a check too much, but only
3037 * when there is heavy renegotiation going on in both directions. */
3038 GST_OBJECT_LOCK (pad);
3039 caps_changed = newcaps && newcaps != GST_PAD_CAPS (pad);
3040 GST_OBJECT_UNLOCK (pad);
3042 /* we got a new datatype on the pad, see if it can handle it */
3043 if (G_UNLIKELY (caps_changed)) {
3044 GST_DEBUG_OBJECT (pad,
3045 "caps changed from %" GST_PTR_FORMAT " to %p %" GST_PTR_FORMAT,
3046 GST_PAD_CAPS (pad), newcaps, newcaps);
3047 if (G_UNLIKELY (!gst_pad_configure_src (pad, newcaps, setcaps)))
3048 goto not_negotiated;
3051 /* sanity check (only if caps are the same) */
3052 if (G_LIKELY (newcaps == caps) && G_UNLIKELY (GST_BUFFER_SIZE (*buf) < size))
3053 goto wrong_size_fallback;
3059 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "pad block stopped by flush");
3060 GST_OBJECT_UNLOCK (pad);
3065 /* pad has no peer */
3066 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3067 "called bufferallocfunc but had no peer");
3068 GST_OBJECT_UNLOCK (pad);
3069 return GST_FLOW_NOT_LINKED;
3073 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3074 "alloc function returned error %s", gst_flow_get_name (ret));
3079 gst_buffer_unref (*buf);
3081 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3082 "alloc function returned unacceptable buffer");
3083 return GST_FLOW_NOT_NEGOTIATED;
3085 wrong_size_fallback:
3087 GST_CAT_ERROR_OBJECT (GST_CAT_PADS, pad, "buffer returned by alloc "
3088 "function is too small (%u < %d), doing fallback buffer alloc",
3089 GST_BUFFER_SIZE (*buf), size);
3091 gst_buffer_unref (*buf);
3093 if ((*buf = gst_buffer_try_new_and_alloc (size))) {
3094 GST_BUFFER_OFFSET (*buf) = offset;
3095 gst_buffer_set_caps (*buf, caps);
3098 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3099 "out of memory allocating %d bytes", size);
3100 return GST_FLOW_ERROR;
3106 * gst_pad_alloc_buffer:
3107 * @pad: a source #GstPad
3108 * @offset: the offset of the new buffer in the stream
3109 * @size: the size of the new buffer
3110 * @caps: the caps of the new buffer
3111 * @buf: a newly allocated buffer
3113 * Allocates a new, empty buffer optimized to push to pad @pad. This
3114 * function only works if @pad is a source pad and has a peer.
3116 * A new, empty #GstBuffer will be put in the @buf argument.
3117 * You need to check the caps of the buffer after performing this
3118 * function and renegotiate to the format if needed. If the caps changed, it is
3119 * possible that the buffer returned in @buf is not of the right size for the
3120 * new format, @buf needs to be unreffed and reallocated if this is the case.
3122 * Returns: a result code indicating success of the operation. Any
3123 * result code other than #GST_FLOW_OK is an error and @buf should
3125 * An error can occur if the pad is not connected or when the downstream
3126 * peer elements cannot provide an acceptable buffer.
3131 /* FIXME 0.11: size should be unsigned */
3133 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
3136 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, FALSE);
3140 * gst_pad_alloc_buffer_and_set_caps:
3141 * @pad: a source #GstPad
3142 * @offset: the offset of the new buffer in the stream
3143 * @size: the size of the new buffer
3144 * @caps: the caps of the new buffer
3145 * @buf: a newly allocated buffer
3147 * In addition to the function gst_pad_alloc_buffer(), this function
3148 * automatically calls gst_pad_set_caps() when the caps of the
3149 * newly allocated buffer are different from the @pad caps.
3151 * After a renegotiation, the size of the new buffer returned in @buf could
3152 * be of the wrong size for the new format and must be unreffed an reallocated
3155 * Returns: a result code indicating success of the operation. Any
3156 * result code other than #GST_FLOW_OK is an error and @buf should
3158 * An error can occur if the pad is not connected or when the downstream
3159 * peer elements cannot provide an acceptable buffer.
3164 /* FIXME 0.11: size should be unsigned */
3166 gst_pad_alloc_buffer_and_set_caps (GstPad * pad, guint64 offset, gint size,
3167 GstCaps * caps, GstBuffer ** buf)
3169 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, TRUE);
3173 #ifndef GST_REMOVE_DEPRECATED
3181 int_link_iter_data_free (IntLinkIterData * data)
3183 g_list_free (data->list);
3184 g_slice_free (IntLinkIterData, data);
3188 static GstIteratorItem
3189 iterate_pad (GstIterator * it, GstPad * pad)
3191 gst_object_ref (pad);
3192 return GST_ITERATOR_ITEM_PASS;
3196 * gst_pad_iterate_internal_links_default:
3197 * @pad: the #GstPad to get the internal links of.
3199 * Iterate the list of pads to which the given pad is linked to inside of
3200 * the parent element.
3201 * This is the default handler, and thus returns an iterator of all of the
3202 * pads inside the parent element with opposite direction.
3204 * The caller must free this iterator after use with gst_iterator_free().
3206 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
3207 * returned pad with gst_object_unref().
3212 gst_pad_iterate_internal_links_default (GstPad * pad)
3219 GstIteratorDisposeFunction dispose;
3221 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3223 #ifndef GST_REMOVE_DEPRECATED
3224 /* when we get here, the default handler for the iterate links is called,
3225 * which means that the user has not installed a custom one. We first check if
3226 * there is maybe a custom legacy function we can call. */
3227 if (GST_PAD_INTLINKFUNC (pad) &&
3228 GST_PAD_INTLINKFUNC (pad) != gst_pad_get_internal_links_default) {
3229 IntLinkIterData *data;
3231 /* make an iterator for the list. We can't protect the list with a
3232 * cookie. If we would take the cookie of the parent element, we need to
3233 * have a parent, which is not required for GST_PAD_INTLINKFUNC(). We could
3234 * cache the per-pad list and invalidate the list when a new call to
3235 * INTLINKFUNC() returned a different list but then this would only work if
3236 * two concurrent iterators were used and the last iterator would still be
3237 * thread-unsafe. Just don't use this method anymore. */
3238 data = g_slice_new (IntLinkIterData);
3239 data->list = GST_PAD_INTLINKFUNC (pad) (pad);
3242 GST_WARNING_OBJECT (pad, "Making unsafe iterator");
3244 cookie = &data->cookie;
3245 padlist = &data->list;
3247 dispose = (GstIteratorDisposeFunction) int_link_iter_data_free;
3248 /* reuse the pad lock, it's all we have here */
3249 lock = GST_OBJECT_GET_LOCK (pad);
3255 GST_OBJECT_LOCK (pad);
3256 parent = GST_PAD_PARENT (pad);
3257 if (!parent || !GST_IS_ELEMENT (parent))
3260 gst_object_ref (parent);
3261 GST_OBJECT_UNLOCK (pad);
3263 if (pad->direction == GST_PAD_SRC)
3264 padlist = &parent->sinkpads;
3266 padlist = &parent->srcpads;
3268 GST_DEBUG_OBJECT (pad, "Making iterator");
3270 cookie = &parent->pads_cookie;
3272 dispose = (GstIteratorDisposeFunction) gst_object_unref;
3273 lock = GST_OBJECT_GET_LOCK (parent);
3276 res = gst_iterator_new_list (GST_TYPE_PAD,
3277 lock, cookie, padlist, owner, (GstIteratorItemFunction) iterate_pad,
3285 GST_OBJECT_UNLOCK (pad);
3286 GST_DEBUG_OBJECT (pad, "no parent element");
3292 * gst_pad_iterate_internal_links:
3293 * @pad: the GstPad to get the internal links of.
3295 * Gets an iterator for the pads to which the given pad is linked to inside
3296 * of the parent element.
3298 * Each #GstPad element yielded by the iterator will have its refcount increased,
3299 * so unref after use.
3301 * Returns: a new #GstIterator of #GstPad or %NULL when the pad does not have an
3302 * iterator function configured. Use gst_iterator_free() after usage.
3307 gst_pad_iterate_internal_links (GstPad * pad)
3309 GstIterator *res = NULL;
3311 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3313 if (GST_PAD_ITERINTLINKFUNC (pad))
3314 res = GST_PAD_ITERINTLINKFUNC (pad) (pad);
3319 #ifndef GST_REMOVE_DEPRECATED
3321 add_unref_pad_to_list (GstPad * pad, GList ** list)
3323 *list = g_list_prepend (*list, pad);
3324 gst_object_unref (pad);
3329 * gst_pad_get_internal_links_default:
3330 * @pad: the #GstPad to get the internal links of.
3332 * Gets a list of pads to which the given pad is linked to
3333 * inside of the parent element.
3334 * This is the default handler, and thus returns a list of all of the
3335 * pads inside the parent element with opposite direction.
3337 * The caller must free this list after use with g_list_free().
3339 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
3343 * Deprecated: This function does not ref the pads in the list so that they
3344 * could become invalid by the time the application accesses them. It's also
3345 * possible that the list changes while handling the pads, which the caller of
3346 * this function is unable to know. Use the thread-safe
3347 * gst_pad_iterate_internal_links_default() instead.
3349 #ifndef GST_REMOVE_DEPRECATED
3351 gst_pad_get_internal_links_default (GstPad * pad)
3356 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3358 GST_WARNING_OBJECT (pad, "Unsafe internal links used");
3360 /* when we get here, the default handler for get_internal_links is called,
3361 * which means that the user has not installed a custom one. We first check if
3362 * there is maybe a custom iterate function we can call. */
3363 if (GST_PAD_ITERINTLINKFUNC (pad) &&
3364 GST_PAD_ITERINTLINKFUNC (pad) != gst_pad_iterate_internal_links_default) {
3366 GstIteratorResult ires;
3367 gboolean done = FALSE;
3369 it = gst_pad_iterate_internal_links (pad);
3370 /* loop over the iterator and put all elements into a list, we also
3371 * immediatly unref them, which is bad. */
3373 ires = gst_iterator_foreach (it, (GFunc) add_unref_pad_to_list, &res);
3375 case GST_ITERATOR_OK:
3376 case GST_ITERATOR_DONE:
3377 case GST_ITERATOR_ERROR:
3380 case GST_ITERATOR_RESYNC:
3381 /* restart, discard previous list */
3382 gst_iterator_resync (it);
3389 gst_iterator_free (it);
3391 /* lock pad, check and ref parent */
3392 GST_OBJECT_LOCK (pad);
3393 parent = GST_PAD_PARENT (pad);
3394 if (!parent || !GST_IS_ELEMENT (parent))
3397 parent = gst_object_ref (parent);
3398 GST_OBJECT_UNLOCK (pad);
3400 /* now lock the parent while we copy the pads */
3401 GST_OBJECT_LOCK (parent);
3402 if (pad->direction == GST_PAD_SRC)
3403 res = g_list_copy (parent->sinkpads);
3405 res = g_list_copy (parent->srcpads);
3406 GST_OBJECT_UNLOCK (parent);
3408 gst_object_unref (parent);
3411 /* At this point pads can be changed and unreffed. Nothing we can do about it
3412 * because for compatibility reasons this function cannot ref the pads or
3413 * notify the app that the list changed. */
3419 GST_DEBUG_OBJECT (pad, "no parent");
3420 GST_OBJECT_UNLOCK (pad);
3424 #endif /* GST_REMOVE_DEPRECATED */
3427 * gst_pad_get_internal_links:
3428 * @pad: the #GstPad to get the internal links of.
3430 * Gets a list of pads to which the given pad is linked to
3431 * inside of the parent element.
3432 * The caller must free this list after use.
3436 * Returns: a newly allocated #GList of pads, free with g_list_free().
3438 * Deprecated: This function does not ref the pads in the list so that they
3439 * could become invalid by the time the application accesses them. It's also
3440 * possible that the list changes while handling the pads, which the caller of
3441 * this function is unable to know. Use the thread-safe
3442 * gst_pad_iterate_internal_links() instead.
3444 #ifndef GST_REMOVE_DEPRECATED
3445 #ifdef GST_DISABLE_DEPRECATED
3446 GList *gst_pad_get_internal_links (GstPad * pad);
3449 gst_pad_get_internal_links (GstPad * pad)
3453 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3455 GST_WARNING_OBJECT (pad, "Calling unsafe internal links");
3457 if (GST_PAD_INTLINKFUNC (pad))
3458 res = GST_PAD_INTLINKFUNC (pad) (pad);
3462 #endif /* GST_REMOVE_DEPRECATED */
3465 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
3467 gboolean result = FALSE;
3469 gboolean done = FALSE;
3472 GList *pushed_pads = NULL;
3474 GST_INFO_OBJECT (pad, "Sending event %p (%s) to all internally linked pads",
3475 event, GST_EVENT_TYPE_NAME (event));
3477 iter = gst_pad_iterate_internal_links (pad);
3483 switch (gst_iterator_next (iter, &item)) {
3484 case GST_ITERATOR_OK:
3485 eventpad = GST_PAD_CAST (item);
3487 /* if already pushed, skip */
3488 if (g_list_find (pushed_pads, eventpad)) {
3489 gst_object_unref (item);
3493 if (GST_PAD_IS_SRC (eventpad)) {
3494 /* for each pad we send to, we should ref the event; it's up
3495 * to downstream to unref again when handled. */
3496 GST_LOG_OBJECT (pad, "Reffing and sending event %p (%s) to %s:%s",
3497 event, GST_EVENT_TYPE_NAME (event),
3498 GST_DEBUG_PAD_NAME (eventpad));
3499 gst_event_ref (event);
3500 result |= gst_pad_push_event (eventpad, event);
3502 /* we only send the event on one pad, multi-sinkpad elements
3503 * should implement a handler */
3504 GST_LOG_OBJECT (pad, "sending event %p (%s) to one sink pad %s:%s",
3505 event, GST_EVENT_TYPE_NAME (event),
3506 GST_DEBUG_PAD_NAME (eventpad));
3507 result = gst_pad_push_event (eventpad, event);
3512 pushed_pads = g_list_prepend (pushed_pads, eventpad);
3514 gst_object_unref (item);
3516 case GST_ITERATOR_RESYNC:
3517 /* FIXME, if we want to reset the result value we need to remember which
3518 * pads pushed with which result */
3519 gst_iterator_resync (iter);
3521 case GST_ITERATOR_ERROR:
3522 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3525 case GST_ITERATOR_DONE:
3530 gst_iterator_free (iter);
3534 /* If this is a sinkpad and we don't have pads to send the event to, we
3535 * return TRUE. This is so that when using the default handler on a sink
3536 * element, we don't fail to push it. */
3538 result = GST_PAD_IS_SINK (pad);
3540 g_list_free (pushed_pads);
3542 /* we handled the incoming event so we unref once */
3544 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
3545 gst_event_unref (event);
3552 * gst_pad_event_default:
3553 * @pad: a #GstPad to call the default event handler on.
3554 * @event: the #GstEvent to handle.
3556 * Invokes the default event handler for the given pad. End-of-stream and
3557 * discontinuity events are handled specially, and then the event is sent to all
3558 * pads internally linked to @pad. Note that if there are many possible sink
3559 * pads that are internally linked to @pad, only one will be sent an event.
3560 * Multi-sinkpad elements should implement custom event handlers.
3562 * Returns: TRUE if the event was sent succesfully.
3565 gst_pad_event_default (GstPad * pad, GstEvent * event)
3567 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3568 g_return_val_if_fail (event != NULL, FALSE);
3570 GST_LOG_OBJECT (pad, "default event handler");
3572 switch (GST_EVENT_TYPE (event)) {
3575 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
3576 gst_pad_pause_task (pad);
3583 return gst_pad_event_default_dispatch (pad, event);
3587 * gst_pad_dispatcher:
3588 * @pad: a #GstPad to dispatch.
3589 * @dispatch: the #GstPadDispatcherFunction to call.
3590 * @data: gpointer user data passed to the dispatcher function.
3592 * Invokes the given dispatcher function on each respective peer of
3593 * all pads that are internally linked to the given pad.
3594 * The GstPadDispatcherFunction should return TRUE when no further pads
3595 * need to be processed.
3597 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3600 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
3603 gboolean res = FALSE;
3604 GstIterator *iter = NULL;
3605 gboolean done = FALSE;
3608 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3609 g_return_val_if_fail (dispatch != NULL, FALSE);
3611 iter = gst_pad_iterate_internal_links (pad);
3617 switch (gst_iterator_next (iter, &item)) {
3618 case GST_ITERATOR_OK:
3620 GstPad *int_pad = GST_PAD_CAST (item);
3621 GstPad *int_peer = gst_pad_get_peer (int_pad);
3624 GST_DEBUG_OBJECT (int_pad, "dispatching to peer %s:%s",
3625 GST_DEBUG_PAD_NAME (int_peer));
3626 done = res = dispatch (int_peer, data);
3627 gst_object_unref (int_peer);
3629 GST_DEBUG_OBJECT (int_pad, "no peer");
3632 gst_object_unref (item);
3634 case GST_ITERATOR_RESYNC:
3635 gst_iterator_resync (iter);
3637 case GST_ITERATOR_ERROR:
3639 GST_ERROR_OBJECT (pad, "Could not iterate internally linked pads");
3641 case GST_ITERATOR_DONE:
3646 gst_iterator_free (iter);
3648 GST_DEBUG_OBJECT (pad, "done, result %d", res);
3657 * @pad: a #GstPad to invoke the default query on.
3658 * @query: the #GstQuery to perform.
3660 * Dispatches a query to a pad. The query should have been allocated by the
3661 * caller via one of the type-specific allocation functions in gstquery.h. The
3662 * element is responsible for filling the query with an appropriate response,
3663 * which should then be parsed with a type-specific query parsing function.
3665 * Again, the caller is responsible for both the allocation and deallocation of
3666 * the query structure.
3668 * Returns: TRUE if the query could be performed.
3671 gst_pad_query (GstPad * pad, GstQuery * query)
3673 GstPadQueryFunction func;
3675 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3676 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3678 GST_DEBUG_OBJECT (pad, "sending query %p", query);
3680 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3683 return func (pad, query);
3687 GST_DEBUG_OBJECT (pad, "had no query function");
3693 * gst_pad_peer_query:
3694 * @pad: a #GstPad to invoke the peer query on.
3695 * @query: the #GstQuery to perform.
3697 * Performs gst_pad_query() on the peer of @pad.
3699 * The caller is responsible for both the allocation and deallocation of
3700 * the query structure.
3702 * Returns: TRUE if the query could be performed. This function returns %FALSE
3703 * if @pad has no peer.
3708 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3713 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3714 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3716 GST_OBJECT_LOCK (pad);
3718 GST_DEBUG_OBJECT (pad, "peer query");
3720 peerpad = GST_PAD_PEER (pad);
3721 if (G_UNLIKELY (peerpad == NULL))
3724 gst_object_ref (peerpad);
3725 GST_OBJECT_UNLOCK (pad);
3727 result = gst_pad_query (peerpad, query);
3729 gst_object_unref (peerpad);
3736 GST_WARNING_OBJECT (pad, "pad has no peer");
3737 GST_OBJECT_UNLOCK (pad);
3743 * gst_pad_query_default:
3744 * @pad: a #GstPad to call the default query handler on.
3745 * @query: the #GstQuery to handle.
3747 * Invokes the default query handler for the given pad.
3748 * The query is sent to all pads internally linked to @pad. Note that
3749 * if there are many possible sink pads that are internally linked to
3750 * @pad, only one will be sent the query.
3751 * Multi-sinkpad elements should implement custom query handlers.
3753 * Returns: TRUE if the query was performed succesfully.
3756 gst_pad_query_default (GstPad * pad, GstQuery * query)
3758 switch (GST_QUERY_TYPE (query)) {
3759 case GST_QUERY_POSITION:
3760 case GST_QUERY_SEEKING:
3761 case GST_QUERY_FORMATS:
3762 case GST_QUERY_LATENCY:
3763 case GST_QUERY_JITTER:
3764 case GST_QUERY_RATE:
3765 case GST_QUERY_CONVERT:
3767 return gst_pad_dispatcher
3768 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
3772 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
3773 /* FIXME: why isn't this on a GstElement ? */
3775 * gst_pad_load_and_link:
3776 * @self: an #xmlNodePtr to read the description from.
3777 * @parent: the #GstObject element that owns the pad.
3779 * Reads the pad definition from the XML node and links the given pad
3780 * in the element to a pad of an element up in the hierarchy.
3783 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
3785 xmlNodePtr field = self->xmlChildrenNode;
3786 GstPad *pad = NULL, *targetpad;
3787 GstPadTemplate *tmpl;
3791 GstObject *grandparent;
3795 if (!strcmp ((char *) field->name, "name")) {
3796 name = (gchar *) xmlNodeGetContent (field);
3797 pad = gst_element_get_static_pad (GST_ELEMENT (parent), name);
3798 if ((!pad) || ((tmpl = gst_pad_get_pad_template (pad))
3799 && (GST_PAD_REQUEST == GST_PAD_TEMPLATE_PRESENCE (tmpl))))
3800 pad = gst_element_get_request_pad (GST_ELEMENT (parent), name);
3802 } else if (!strcmp ((char *) field->name, "peer")) {
3803 peer = (gchar *) xmlNodeGetContent (field);
3805 field = field->next;
3807 g_return_if_fail (pad != NULL);
3812 split = g_strsplit (peer, ".", 2);
3814 if (split[0] == NULL || split[1] == NULL) {
3815 GST_CAT_DEBUG_OBJECT (GST_CAT_XML, pad,
3816 "Could not parse peer '%s', leaving unlinked", peer);
3823 g_return_if_fail (split[0] != NULL);
3824 g_return_if_fail (split[1] != NULL);
3826 grandparent = gst_object_get_parent (parent);
3828 if (grandparent && GST_IS_BIN (grandparent)) {
3829 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
3836 targetpad = gst_element_get_static_pad (target, split[1]);
3838 targetpad = gst_element_get_request_pad (target, split[1]);
3840 if (targetpad == NULL)
3843 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
3844 gst_pad_link (pad, targetpad);
3846 gst_pad_link (targetpad, pad);
3853 * gst_pad_save_thyself:
3854 * @pad: a #GstPad to save.
3855 * @parent: the parent #xmlNodePtr to save the description in.
3857 * Saves the pad into an xml representation.
3859 * Returns: the #xmlNodePtr representation of the pad.
3862 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3867 g_return_val_if_fail (GST_IS_PAD (object), NULL);
3869 pad = GST_PAD_CAST (object);
3871 xmlNewChild (parent, NULL, (xmlChar *) "name",
3872 (xmlChar *) GST_PAD_NAME (pad));
3874 if (GST_PAD_IS_SRC (pad)) {
3875 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "source");
3876 } else if (GST_PAD_IS_SINK (pad)) {
3877 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "sink");
3879 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "unknown");
3882 if (GST_PAD_PEER (pad) != NULL) {
3885 peer = GST_PAD_PEER (pad);
3886 /* first check to see if the peer's parent's parent is the same */
3887 /* we just save it off */
3888 content = g_strdup_printf ("%s.%s",
3889 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3890 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
3893 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
3900 * gst_ghost_pad_save_thyself:
3901 * @pad: a ghost #GstPad to save.
3902 * @parent: the parent #xmlNodePtr to save the description in.
3904 * Saves the ghost pad into an xml representation.
3906 * Returns: the #xmlNodePtr representation of the pad.
3909 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3913 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3915 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
3916 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
3917 xmlNewChild (self, NULL, (xmlChar *) "parent",
3918 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3920 /* FIXME FIXME FIXME! */
3925 #endif /* GST_DISABLE_LOADSAVE */
3928 * should be called with pad OBJECT_LOCK and STREAM_LOCK held.
3929 * GST_PAD_IS_BLOCKED (pad) == TRUE when this function is
3932 * This function performs the pad blocking when an event, buffer push
3933 * or buffer_alloc is performed on a _SRC_ pad. It blocks the
3934 * streaming thread after informing the pad has been blocked.
3936 * An application can with this method wait and block any streaming
3937 * thread and perform operations such as seeking or linking.
3939 * Two methods are available for notifying the application of the
3941 * - the callback method, which happens in the STREAMING thread with
3942 * the STREAM_LOCK held. With this method, the most useful way of
3943 * dealing with the callback is to post a message to the main thread
3944 * where the pad block can then be handled outside of the streaming
3945 * thread. With the last method one can perform all operations such
3946 * as doing a state change, linking, unblocking, seeking etc on the
3948 * - the GCond signal method, which makes any thread unblock when
3949 * the pad block happens.
3951 * During the actual blocking state, the GST_PAD_BLOCKING flag is set.
3952 * The GST_PAD_BLOCKING flag is unset when the pad was unblocked.
3956 static GstFlowReturn
3957 handle_pad_block (GstPad * pad)
3959 GstPadBlockCallback callback;
3961 GstFlowReturn ret = GST_FLOW_OK;
3963 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "signal block taken");
3965 /* flushing, don't bother trying to block and return WRONG_STATE
3967 if (GST_PAD_IS_FLUSHING (pad))
3968 goto flushingnonref;
3970 /* we grab an extra ref for the callbacks, this is probably not
3971 * needed (callback code does not have a ref and cannot unref). I
3972 * think this was done to make it possible to unref the element in
3973 * the callback, which is in the end totally impossible as it
3974 * requires grabbing the STREAM_LOCK and OBJECT_LOCK which are
3975 * all taken when calling this function. */
3976 gst_object_ref (pad);
3978 while (GST_PAD_IS_BLOCKED (pad)) {
3980 /* we either have a callback installed to notify the block or
3981 * some other thread is doing a GCond wait. */
3982 callback = pad->block_callback;
3983 pad->abidata.ABI.block_callback_called = TRUE;
3985 /* there is a callback installed, call it. We release the
3986 * lock so that the callback can do something usefull with the
3988 user_data = pad->block_data;
3989 GST_OBJECT_UNLOCK (pad);
3990 callback (pad, TRUE, user_data);
3991 GST_OBJECT_LOCK (pad);
3993 /* we released the lock, recheck flushing */
3994 if (GST_PAD_IS_FLUSHING (pad))
3997 /* no callback, signal the thread that is doing a GCond wait
3999 GST_PAD_BLOCK_BROADCAST (pad);
4001 } while (pad->abidata.ABI.block_callback_called == FALSE
4002 && GST_PAD_IS_BLOCKED (pad));
4004 /* OBJECT_LOCK could have been released when we did the callback, which
4005 * then could have made the pad unblock so we need to check the blocking
4006 * condition again. */
4007 if (!GST_PAD_IS_BLOCKED (pad))
4010 /* now we block the streaming thread. It can be unlocked when we
4011 * deactivate the pad (which will also set the FLUSHING flag) or
4012 * when the pad is unblocked. A flushing event will also unblock
4013 * the pad after setting the FLUSHING flag. */
4014 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4015 "Waiting to be unblocked or set flushing");
4016 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKING);
4017 GST_PAD_BLOCK_WAIT (pad);
4018 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKING);
4020 /* see if we got unblocked by a flush or not */
4021 if (GST_PAD_IS_FLUSHING (pad))
4025 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
4027 /* when we get here, the pad is unblocked again and we perform
4028 * the needed unblock code. */
4029 callback = pad->block_callback;
4031 /* we need to call the callback */
4032 user_data = pad->block_data;
4033 GST_OBJECT_UNLOCK (pad);
4034 callback (pad, FALSE, user_data);
4035 GST_OBJECT_LOCK (pad);
4037 /* we need to signal the thread waiting on the GCond */
4038 GST_PAD_BLOCK_BROADCAST (pad);
4041 gst_object_unref (pad);
4047 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pad was flushing");
4048 return GST_FLOW_WRONG_STATE;
4052 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pad became flushing");
4053 gst_object_unref (pad);
4054 return GST_FLOW_WRONG_STATE;
4058 /**********************************************************************
4059 * Data passing functions
4063 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
4066 GValue args[2] = { {0}, {0} };
4071 g_value_init (&ret, G_TYPE_BOOLEAN);
4072 g_value_set_boolean (&ret, TRUE);
4073 g_value_init (&args[0], GST_TYPE_PAD);
4074 g_value_set_object (&args[0], pad);
4075 g_value_init (&args[1], GST_TYPE_MINI_OBJECT);
4076 gst_value_set_mini_object (&args[1], obj);
4078 if (GST_IS_EVENT (obj))
4079 detail = event_quark;
4081 detail = buffer_quark;
4084 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
4085 res = g_value_get_boolean (&ret);
4088 g_value_unset (&ret);
4089 g_value_unset (&args[0]);
4090 g_value_unset (&args[1]);
4096 gst_pad_data_unref (gboolean is_buffer, void *data)
4098 if (G_LIKELY (is_buffer)) {
4099 gst_buffer_unref (data);
4101 gst_buffer_list_unref (data);
4106 gst_pad_data_get_caps (gboolean is_buffer, void *data)
4110 if (G_LIKELY (is_buffer)) {
4111 caps = GST_BUFFER_CAPS (data);
4115 if ((buf = gst_buffer_list_get (GST_BUFFER_LIST_CAST (data), 0, 0)))
4116 caps = GST_BUFFER_CAPS (buf);
4123 /* this is the chain function that does not perform the additional argument
4124 * checking for that little extra speed.
4126 static inline GstFlowReturn
4127 gst_pad_chain_data_unchecked (GstPad * pad, gboolean is_buffer, void *data)
4130 gboolean caps_changed;
4132 gboolean emit_signal;
4134 GST_PAD_STREAM_LOCK (pad);
4136 GST_OBJECT_LOCK (pad);
4137 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4140 caps = gst_pad_data_get_caps (is_buffer, data);
4141 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4143 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4144 GST_OBJECT_UNLOCK (pad);
4146 /* see if the signal should be emited, we emit before caps nego as
4147 * we might drop the buffer and do capsnego for nothing. */
4148 if (G_UNLIKELY (emit_signal)) {
4149 if (G_LIKELY (is_buffer)) {
4150 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (data)))
4153 /* chain all groups in the buffer list one by one to avoid problems with
4154 * buffer probes that push buffers or events */
4159 /* we got a new datatype on the pad, see if it can handle it */
4160 if (G_UNLIKELY (caps_changed)) {
4161 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4162 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
4163 goto not_negotiated;
4166 /* NOTE: we read the chainfunc unlocked.
4167 * we cannot hold the lock for the pad so we might send
4168 * the data to the wrong function. This is not really a
4169 * problem since functions are assigned at creation time
4170 * and don't change that often... */
4171 if (G_LIKELY (is_buffer)) {
4172 GstPadChainFunction chainfunc;
4174 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4177 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4178 "calling chainfunction &%s", GST_DEBUG_FUNCPTR_NAME (chainfunc));
4180 ret = chainfunc (pad, GST_BUFFER_CAST (data));
4182 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4183 "called chainfunction &%s, returned %s",
4184 GST_DEBUG_FUNCPTR_NAME (chainfunc), gst_flow_get_name (ret));
4186 GstPadChainListFunction chainlistfunc;
4188 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4191 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4192 "calling chainlistfunction &%s",
4193 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4195 ret = chainlistfunc (pad, GST_BUFFER_LIST_CAST (data));
4197 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4198 "called chainlistfunction &%s, returned %s",
4199 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4202 GST_PAD_STREAM_UNLOCK (pad);
4208 GstBufferList *list;
4209 GstBufferListIterator *it;
4212 GST_PAD_STREAM_UNLOCK (pad);
4214 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
4216 list = GST_BUFFER_LIST_CAST (data);
4217 it = gst_buffer_list_iterate (list);
4219 if (gst_buffer_list_iterator_next_group (it)) {
4221 group = gst_buffer_list_iterator_merge_group (it);
4222 if (group == NULL) {
4223 group = gst_buffer_new ();
4224 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining empty group");
4226 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining group");
4228 ret = gst_pad_chain_data_unchecked (pad, TRUE, group);
4229 } while (ret == GST_FLOW_OK && gst_buffer_list_iterator_next_group (it));
4231 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining empty group");
4232 ret = gst_pad_chain_data_unchecked (pad, TRUE, gst_buffer_new ());
4235 gst_buffer_list_iterator_free (it);
4236 gst_buffer_list_unref (list);
4244 gst_pad_data_unref (is_buffer, data);
4245 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4246 "pushing, but pad was flushing");
4247 GST_OBJECT_UNLOCK (pad);
4248 GST_PAD_STREAM_UNLOCK (pad);
4249 return GST_FLOW_WRONG_STATE;
4253 gst_pad_data_unref (is_buffer, data);
4254 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
4255 GST_PAD_STREAM_UNLOCK (pad);
4260 gst_pad_data_unref (is_buffer, data);
4261 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4262 "pushing data but pad did not accept");
4263 GST_PAD_STREAM_UNLOCK (pad);
4264 return GST_FLOW_NOT_NEGOTIATED;
4268 gst_pad_data_unref (is_buffer, data);
4269 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4270 "pushing, but not chainhandler");
4271 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4272 ("push on pad %s:%s but it has no chainfunction",
4273 GST_DEBUG_PAD_NAME (pad)));
4274 GST_PAD_STREAM_UNLOCK (pad);
4275 return GST_FLOW_NOT_SUPPORTED;
4281 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4282 * @buffer: the #GstBuffer to send, return GST_FLOW_ERROR if not.
4284 * Chain a buffer to @pad.
4286 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
4288 * If the caps on @buffer are different from the current caps on @pad, this
4289 * function will call any setcaps function (see gst_pad_set_setcaps_function())
4290 * installed on @pad. If the new caps are not acceptable for @pad, this
4291 * function returns #GST_FLOW_NOT_NEGOTIATED.
4293 * The function proceeds calling the chain function installed on @pad (see
4294 * gst_pad_set_chain_function()) and the return value of that function is
4295 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4298 * In all cases, success or failure, the caller loses its reference to @buffer
4299 * after calling this function.
4301 * Returns: a #GstFlowReturn from the pad.
4306 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4308 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4309 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4310 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4312 return gst_pad_chain_data_unchecked (pad, TRUE, buffer);
4316 * gst_pad_chain_list:
4317 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4318 * @list: the #GstBufferList to send, return GST_FLOW_ERROR if not.
4320 * Chain a bufferlist to @pad.
4322 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
4324 * If the caps on the first buffer of @list are different from the current
4325 * caps on @pad, this function will call any setcaps function
4326 * (see gst_pad_set_setcaps_function()) installed on @pad. If the new caps
4327 * are not acceptable for @pad, this function returns #GST_FLOW_NOT_NEGOTIATED.
4329 * The function proceeds calling the chainlist function installed on @pad (see
4330 * gst_pad_set_chain_list_function()) and the return value of that function is
4331 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4332 * chainlist function.
4334 * In all cases, success or failure, the caller loses its reference to @list
4335 * after calling this function.
4339 * Returns: a #GstFlowReturn from the pad.
4344 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4346 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4347 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4348 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4350 return gst_pad_chain_data_unchecked (pad, FALSE, list);
4353 static GstFlowReturn
4354 gst_pad_push_data (GstPad * pad, gboolean is_buffer, void *data)
4359 gboolean caps_changed;
4361 GST_OBJECT_LOCK (pad);
4363 /* FIXME: this check can go away; pad_set_blocked could be implemented with
4364 * probes completely or probes with an extended pad block. */
4365 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
4366 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
4369 /* we emit signals on the pad arg, the peer will have a chance to
4370 * emit in the _chain() function */
4371 if (G_UNLIKELY (GST_PAD_DO_BUFFER_SIGNALS (pad) > 0)) {
4372 /* unlock before emitting */
4373 GST_OBJECT_UNLOCK (pad);
4375 if (G_LIKELY (is_buffer)) {
4376 /* if the signal handler returned FALSE, it means we should just drop the
4378 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (data)))
4381 /* push all buffers in the list */
4384 GST_OBJECT_LOCK (pad);
4387 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4390 /* Before pushing the buffer to the peer pad, ensure that caps
4391 * are set on this pad */
4392 caps = gst_pad_data_get_caps (is_buffer, data);
4393 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4395 /* take ref to peer pad before releasing the lock */
4396 gst_object_ref (peer);
4398 GST_OBJECT_UNLOCK (pad);
4400 /* we got a new datatype from the pad, it had better handle it */
4401 if (G_UNLIKELY (caps_changed)) {
4402 GST_DEBUG_OBJECT (pad,
4403 "caps changed from %" GST_PTR_FORMAT " to %p %" GST_PTR_FORMAT,
4404 GST_PAD_CAPS (pad), caps, caps);
4405 if (G_UNLIKELY (!gst_pad_set_caps (pad, caps)))
4406 goto not_negotiated;
4409 ret = gst_pad_chain_data_unchecked (peer, is_buffer, data);
4411 gst_object_unref (peer);
4417 GstBufferList *list;
4418 GstBufferListIterator *it;
4421 GST_INFO_OBJECT (pad, "pushing each group in list as a merged buffer");
4423 list = GST_BUFFER_LIST_CAST (data);
4424 it = gst_buffer_list_iterate (list);
4426 if (gst_buffer_list_iterator_next_group (it)) {
4428 group = gst_buffer_list_iterator_merge_group (it);
4429 if (group == NULL) {
4430 group = gst_buffer_new ();
4431 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing empty group");
4433 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing group");
4435 ret = gst_pad_push_data (pad, TRUE, group);
4436 } while (ret == GST_FLOW_OK && gst_buffer_list_iterator_next_group (it));
4438 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing empty group");
4439 ret = gst_pad_push_data (pad, TRUE, gst_buffer_new ());
4442 gst_buffer_list_iterator_free (it);
4443 gst_buffer_list_unref (list);
4448 /* ERROR recovery here */
4451 gst_pad_data_unref (is_buffer, data);
4452 GST_DEBUG_OBJECT (pad, "pad block stopped by flush");
4453 GST_OBJECT_UNLOCK (pad);
4458 gst_pad_data_unref (is_buffer, data);
4459 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
4464 gst_pad_data_unref (is_buffer, data);
4465 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4466 "pushing, but it was not linked");
4467 GST_OBJECT_UNLOCK (pad);
4468 return GST_FLOW_NOT_LINKED;
4472 gst_pad_data_unref (is_buffer, data);
4473 gst_object_unref (peer);
4474 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4475 "element pushed data then refused to accept the caps");
4476 return GST_FLOW_NOT_NEGOTIATED;
4482 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4483 * @buffer: the #GstBuffer to push returns GST_FLOW_ERROR if not.
4485 * Pushes a buffer to the peer of @pad.
4487 * This function will call an installed pad block before triggering any
4488 * installed pad probes.
4490 * If the caps on @buffer are different from the currently configured caps on
4491 * @pad, this function will call any installed setcaps function on @pad (see
4492 * gst_pad_set_setcaps_function()). In case of failure to renegotiate the new
4493 * format, this function returns #GST_FLOW_NOT_NEGOTIATED.
4495 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4496 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4499 * In all cases, success or failure, the caller loses its reference to @buffer
4500 * after calling this function.
4502 * Returns: a #GstFlowReturn from the peer pad.
4507 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4509 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4510 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4511 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4513 return gst_pad_push_data (pad, TRUE, buffer);
4517 * gst_pad_push_list:
4518 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4519 * @list: the #GstBufferList to push returns GST_FLOW_ERROR if not.
4521 * Pushes a buffer list to the peer of @pad.
4523 * This function will call an installed pad block before triggering any
4524 * installed pad probes.
4526 * If the caps on the first buffer in the first group of @list are different
4527 * from the currently configured caps on @pad, this function will call any
4528 * installed setcaps function on @pad (see gst_pad_set_setcaps_function()). In
4529 * case of failure to renegotiate the new format, this function returns
4530 * #GST_FLOW_NOT_NEGOTIATED.
4532 * If there are any probes installed on @pad every group of the buffer list
4533 * will be merged into a normal #GstBuffer and pushed via gst_pad_push and the
4534 * buffer list will be unreffed.
4536 * The function proceeds calling the chain function on the peer pad and returns
4537 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4538 * be returned. If the peer pad does not have any installed chainlist function
4539 * every group buffer of the list will be merged into a normal #GstBuffer and
4540 * chained via gst_pad_chain().
4542 * In all cases, success or failure, the caller loses its reference to @list
4543 * after calling this function.
4545 * Returns: a #GstFlowReturn from the peer pad.
4552 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4554 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4555 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4556 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4558 return gst_pad_push_data (pad, FALSE, list);
4562 * gst_pad_check_pull_range:
4563 * @pad: a sink #GstPad.
4565 * Checks if a gst_pad_pull_range() can be performed on the peer
4566 * source pad. This function is used by plugins that want to check
4567 * if they can use random access on the peer source pad.
4569 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
4570 * if it needs to perform some logic to determine if pull_range is
4573 * Returns: a gboolean with the result.
4578 gst_pad_check_pull_range (GstPad * pad)
4582 GstPadCheckGetRangeFunction checkgetrangefunc;
4584 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4586 GST_OBJECT_LOCK (pad);
4587 if (!GST_PAD_IS_SINK (pad))
4588 goto wrong_direction;
4590 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4593 gst_object_ref (peer);
4594 GST_OBJECT_UNLOCK (pad);
4596 /* see note in above function */
4597 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
4598 /* FIXME, kindoff ghetto */
4599 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
4600 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4601 "no checkgetrangefunc, assuming %d", ret);
4603 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4604 "calling checkgetrangefunc %s of peer pad %s:%s",
4605 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
4607 ret = checkgetrangefunc (peer);
4610 gst_object_unref (peer);
4614 /* ERROR recovery here */
4617 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4618 "checking pull range, but pad must be a sinkpad");
4619 GST_OBJECT_UNLOCK (pad);
4624 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4625 "checking pull range, but it was not linked");
4626 GST_OBJECT_UNLOCK (pad);
4632 * gst_pad_get_range:
4633 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4634 * @offset: The start offset of the buffer
4635 * @size: The length of the buffer
4636 * @buffer: a pointer to hold the #GstBuffer, returns #GST_FLOW_ERROR if %NULL.
4638 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
4639 * immediatly and @buffer is %NULL.
4641 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4642 * description of a getrange function. If @pad has no getrange function
4643 * installed (see gst_pad_set_getrange_function()) this function returns
4644 * #GST_FLOW_NOT_SUPPORTED.
4646 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4648 * Returns: a #GstFlowReturn from the pad.
4653 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4654 GstBuffer ** buffer)
4657 GstPadGetRangeFunction getrangefunc;
4658 gboolean emit_signal;
4660 gboolean caps_changed;
4662 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4663 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4664 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4666 GST_PAD_STREAM_LOCK (pad);
4668 GST_OBJECT_LOCK (pad);
4669 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4672 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4673 GST_OBJECT_UNLOCK (pad);
4675 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4678 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4679 "calling getrangefunc %s, offset %"
4680 G_GUINT64_FORMAT ", size %u",
4681 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4683 ret = getrangefunc (pad, offset, size, buffer);
4685 /* can only fire the signal if we have a valid buffer */
4686 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
4687 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
4691 GST_PAD_STREAM_UNLOCK (pad);
4693 if (G_UNLIKELY (ret != GST_FLOW_OK))
4694 goto get_range_failed;
4696 GST_OBJECT_LOCK (pad);
4697 /* Before pushing the buffer to the peer pad, ensure that caps
4698 * are set on this pad */
4699 caps = GST_BUFFER_CAPS (*buffer);
4700 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4701 GST_OBJECT_UNLOCK (pad);
4703 if (G_UNLIKELY (caps_changed)) {
4704 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4705 /* this should usually work because the element produced the buffer */
4706 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, TRUE)))
4707 goto not_negotiated;
4714 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4715 "pulling range, but pad was flushing");
4716 GST_OBJECT_UNLOCK (pad);
4717 GST_PAD_STREAM_UNLOCK (pad);
4718 return GST_FLOW_WRONG_STATE;
4722 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4723 ("pullrange on pad %s:%s but it has no getrangefunction",
4724 GST_DEBUG_PAD_NAME (pad)));
4725 GST_PAD_STREAM_UNLOCK (pad);
4726 return GST_FLOW_NOT_SUPPORTED;
4730 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4731 "Dropping data after FALSE probe return");
4732 GST_PAD_STREAM_UNLOCK (pad);
4733 gst_buffer_unref (*buffer);
4735 return GST_FLOW_UNEXPECTED;
4740 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4741 (ret >= GST_FLOW_UNEXPECTED) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4742 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4747 gst_buffer_unref (*buffer);
4749 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4750 "getrange returned buffer of unaccaptable caps");
4751 return GST_FLOW_NOT_NEGOTIATED;
4757 * gst_pad_pull_range:
4758 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4759 * @offset: The start offset of the buffer
4760 * @size: The length of the buffer
4761 * @buffer: a pointer to hold the #GstBuffer, returns GST_FLOW_ERROR if %NULL.
4763 * Pulls a @buffer from the peer pad.
4765 * This function will first trigger the pad block signal if it was
4768 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4769 * function returns the result of gst_pad_get_range() on the peer pad.
4770 * See gst_pad_get_range() for a list of return values and for the
4771 * semantics of the arguments of this function.
4773 * @buffer's caps must either be unset or the same as what is already
4774 * configured on @pad. Renegotiation within a running pull-mode pipeline is not
4777 * Returns: a #GstFlowReturn from the peer pad.
4778 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
4779 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
4780 * @buffer may not be used or freed when any other return value than
4781 * #GST_FLOW_OK is returned.
4786 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4787 GstBuffer ** buffer)
4791 gboolean emit_signal;
4793 gboolean caps_changed;
4795 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4796 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4797 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4799 GST_OBJECT_LOCK (pad);
4801 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
4802 handle_pad_block (pad);
4804 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4807 /* signal emision for the pad, peer has chance to emit when
4808 * we call _get_range() */
4809 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4811 gst_object_ref (peer);
4812 GST_OBJECT_UNLOCK (pad);
4814 ret = gst_pad_get_range (peer, offset, size, buffer);
4816 gst_object_unref (peer);
4818 if (G_UNLIKELY (ret != GST_FLOW_OK))
4819 goto pull_range_failed;
4821 /* can only fire the signal if we have a valid buffer */
4822 if (G_UNLIKELY (emit_signal)) {
4823 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
4827 GST_OBJECT_LOCK (pad);
4828 /* Before pushing the buffer to the peer pad, ensure that caps
4829 * are set on this pad */
4830 caps = GST_BUFFER_CAPS (*buffer);
4831 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4832 GST_OBJECT_UNLOCK (pad);
4834 /* we got a new datatype on the pad, see if it can handle it */
4835 if (G_UNLIKELY (caps_changed)) {
4836 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4837 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
4838 goto not_negotiated;
4842 /* ERROR recovery here */
4845 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4846 "pulling range, but it was not linked");
4847 GST_OBJECT_UNLOCK (pad);
4848 return GST_FLOW_NOT_LINKED;
4853 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4854 (ret >= GST_FLOW_UNEXPECTED) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4855 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4860 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4861 "Dropping data after FALSE probe return");
4862 gst_buffer_unref (*buffer);
4864 return GST_FLOW_UNEXPECTED;
4868 gst_buffer_unref (*buffer);
4870 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4871 "pullrange returned buffer of different caps");
4872 return GST_FLOW_NOT_NEGOTIATED;
4877 * gst_pad_push_event:
4878 * @pad: a #GstPad to push the event to.
4879 * @event: the #GstEvent to send to the pad.
4881 * Sends the event to the peer of the given pad. This function is
4882 * mainly used by elements to send events to their peer
4885 * This function takes owership of the provided event so you should
4886 * gst_event_ref() it if you want to reuse the event after this call.
4888 * Returns: TRUE if the event was handled.
4893 gst_pad_push_event (GstPad * pad, GstEvent * event)
4898 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4899 g_return_val_if_fail (event != NULL, FALSE);
4900 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4902 GST_LOG_OBJECT (pad, "event: %s", GST_EVENT_TYPE_NAME (event));
4904 GST_OBJECT_LOCK (pad);
4906 /* Two checks to be made:
4907 * . (un)set the FLUSHING flag for flushing events,
4908 * . handle pad blocking */
4909 switch (GST_EVENT_TYPE (event)) {
4910 case GST_EVENT_FLUSH_START:
4911 GST_PAD_SET_FLUSHING (pad);
4913 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4914 /* flush start will have set the FLUSHING flag and will then
4915 * unlock all threads doing a GCond wait on the blocking pad. This
4916 * will typically unblock the STREAMING thread blocked on a pad. */
4917 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
4918 "doing block signal.");
4919 GST_PAD_BLOCK_BROADCAST (pad);
4923 case GST_EVENT_FLUSH_STOP:
4924 GST_PAD_UNSET_FLUSHING (pad);
4926 /* if we are blocked, flush away the FLUSH_STOP event */
4927 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4928 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4933 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4934 /* block the event as long as the pad is blocked */
4935 if (handle_pad_block (pad) != GST_FLOW_OK)
4941 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
4942 GST_OBJECT_UNLOCK (pad);
4944 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
4947 GST_OBJECT_LOCK (pad);
4949 peerpad = GST_PAD_PEER (pad);
4950 if (peerpad == NULL)
4953 GST_LOG_OBJECT (pad, "sending event %s to peerpad %" GST_PTR_FORMAT,
4954 GST_EVENT_TYPE_NAME (event), peerpad);
4955 gst_object_ref (peerpad);
4956 GST_OBJECT_UNLOCK (pad);
4958 result = gst_pad_send_event (peerpad, event);
4960 /* Note: we gave away ownership of the event at this point */
4961 GST_LOG_OBJECT (pad, "sent event to peerpad %" GST_PTR_FORMAT ", result %d",
4963 gst_object_unref (peerpad);
4967 /* ERROR handling */
4970 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
4971 gst_event_unref (event);
4976 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4977 gst_event_unref (event);
4978 GST_OBJECT_UNLOCK (pad);
4983 GST_DEBUG_OBJECT (pad,
4984 "Not forwarding event since we're flushing and blocking");
4985 gst_event_unref (event);
4986 GST_OBJECT_UNLOCK (pad);
4992 * gst_pad_send_event:
4993 * @pad: a #GstPad to send the event to.
4994 * @event: the #GstEvent to send to the pad.
4996 * Sends the event to the pad. This function can be used
4997 * by applications to send events in the pipeline.
4999 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5000 * sink pad, @event should be a downstream event. For example, you would not
5001 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5002 * Furthermore, some downstream events have to be serialized with data flow,
5003 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5004 * the event needs to be serialized with data flow, this function will take the
5005 * pad's stream lock while calling its event function.
5007 * To find out whether an event type is upstream, downstream, or downstream and
5008 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5009 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5010 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5011 * plugin doesn't need to bother itself with this information; the core handles
5012 * all necessary locks and checks.
5014 * This function takes owership of the provided event so you should
5015 * gst_event_ref() it if you want to reuse the event after this call.
5017 * Returns: TRUE if the event was handled.
5020 gst_pad_send_event (GstPad * pad, GstEvent * event)
5022 gboolean result = FALSE;
5023 GstPadEventFunction eventfunc;
5024 gboolean serialized, need_unlock = FALSE;
5026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5027 g_return_val_if_fail (event != NULL, FALSE);
5029 GST_OBJECT_LOCK (pad);
5030 if (GST_PAD_IS_SINK (pad)) {
5031 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5032 goto wrong_direction;
5033 serialized = GST_EVENT_IS_SERIALIZED (event);
5034 } else if (GST_PAD_IS_SRC (pad)) {
5035 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5036 goto wrong_direction;
5037 /* events on srcpad never are serialized */
5040 goto unknown_direction;
5042 if (G_UNLIKELY (GST_EVENT_SRC (event) == NULL)) {
5043 GST_LOG_OBJECT (pad, "event had no source, setting pad as event source");
5044 GST_EVENT_SRC (event) = gst_object_ref (pad);
5048 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
5049 GST_OBJECT_UNLOCK (pad);
5051 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT_CAST (event)))
5054 GST_OBJECT_LOCK (pad);
5057 switch (GST_EVENT_TYPE (event)) {
5058 case GST_EVENT_FLUSH_START:
5059 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5060 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5062 /* can't even accept a flush begin event when flushing */
5063 if (GST_PAD_IS_FLUSHING (pad))
5065 GST_PAD_SET_FLUSHING (pad);
5066 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5068 case GST_EVENT_FLUSH_STOP:
5069 GST_PAD_UNSET_FLUSHING (pad);
5070 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5071 GST_OBJECT_UNLOCK (pad);
5072 /* grab stream lock */
5073 GST_PAD_STREAM_LOCK (pad);
5075 GST_OBJECT_LOCK (pad);
5078 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
5079 GST_EVENT_TYPE_NAME (event));
5081 /* make this a little faster, no point in grabbing the lock
5082 * if the pad is allready flushing. */
5083 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5087 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5088 GST_OBJECT_UNLOCK (pad);
5089 GST_PAD_STREAM_LOCK (pad);
5091 GST_OBJECT_LOCK (pad);
5092 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5097 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5100 GST_OBJECT_UNLOCK (pad);
5102 result = eventfunc (pad, event);
5105 GST_PAD_STREAM_UNLOCK (pad);
5107 GST_DEBUG_OBJECT (pad, "sent event, result %d", result);
5111 /* ERROR handling */
5114 g_warning ("pad %s:%s sending %s event in wrong direction",
5115 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5116 GST_OBJECT_UNLOCK (pad);
5117 gst_event_unref (event);
5122 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5123 GST_OBJECT_UNLOCK (pad);
5124 gst_event_unref (event);
5129 g_warning ("pad %s:%s has no event handler, file a bug.",
5130 GST_DEBUG_PAD_NAME (pad));
5131 GST_OBJECT_UNLOCK (pad);
5133 GST_PAD_STREAM_UNLOCK (pad);
5134 gst_event_unref (event);
5139 GST_OBJECT_UNLOCK (pad);
5141 GST_PAD_STREAM_UNLOCK (pad);
5142 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5143 "Received event on flushing pad. Discarding");
5144 gst_event_unref (event);
5149 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
5150 gst_event_unref (event);
5156 * gst_pad_set_element_private:
5157 * @pad: the #GstPad to set the private data of.
5158 * @priv: The private data to attach to the pad.
5160 * Set the given private data gpointer on the pad.
5161 * This function can only be used by the element that owns the pad.
5162 * No locking is performed in this function.
5165 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5167 pad->element_private = priv;
5171 * gst_pad_get_element_private:
5172 * @pad: the #GstPad to get the private data of.
5174 * Gets the private data of a pad.
5175 * No locking is performed in this function.
5177 * Returns: a #gpointer to the private data.
5180 gst_pad_get_element_private (GstPad * pad)
5182 return pad->element_private;
5186 do_stream_status (GstPad * pad, GstStreamStatusType type,
5187 GThread * thread, GstTask * task)
5191 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5193 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5194 if (GST_IS_ELEMENT (parent)) {
5195 GstMessage *message;
5196 GValue value = { 0 };
5198 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5199 gchar *tname, *ename, *pname;
5201 /* create a good task name */
5202 ename = gst_element_get_name (parent);
5203 pname = gst_pad_get_name (pad);
5204 tname = g_strdup_printf ("%s:%s", ename, pname);
5208 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5212 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5215 g_value_init (&value, GST_TYPE_TASK);
5216 g_value_set_object (&value, task);
5217 gst_message_set_stream_status_object (message, &value);
5218 g_value_unset (&value);
5220 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5221 gst_element_post_message (parent, message);
5223 gst_object_unref (parent);
5228 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5230 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5235 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5237 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5241 static GstTaskThreadCallbacks thr_callbacks = {
5247 * gst_pad_start_task:
5248 * @pad: the #GstPad to start the task of
5249 * @func: the task function to call
5250 * @data: data passed to the task function
5252 * Starts a task that repeatedly calls @func with @data. This function
5253 * is mostly used in pad activation functions to start the dataflow.
5254 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5255 * before @func is called.
5257 * Returns: a %TRUE if the task could be started.
5260 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
5265 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5266 g_return_val_if_fail (func != NULL, FALSE);
5268 GST_DEBUG_OBJECT (pad, "start task");
5270 GST_OBJECT_LOCK (pad);
5271 task = GST_PAD_TASK (pad);
5273 task = gst_task_create (func, data);
5274 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5275 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
5276 GST_DEBUG_OBJECT (pad, "created task");
5277 GST_PAD_TASK (pad) = task;
5278 gst_object_ref (task);
5279 /* release lock to post the message */
5280 GST_OBJECT_UNLOCK (pad);
5282 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5284 gst_object_unref (task);
5286 GST_OBJECT_LOCK (pad);
5287 /* nobody else is supposed to have changed the pad now */
5288 if (GST_PAD_TASK (pad) != task)
5289 goto concurrent_stop;
5291 res = gst_task_set_state (task, GST_TASK_STARTED);
5292 GST_OBJECT_UNLOCK (pad);
5299 GST_OBJECT_UNLOCK (pad);
5305 * gst_pad_pause_task:
5306 * @pad: the #GstPad to pause the task of
5308 * Pause the task of @pad. This function will also wait until the
5309 * function executed by the task is finished if this function is not
5310 * called from the task function.
5312 * Returns: a TRUE if the task could be paused or FALSE when the pad
5316 gst_pad_pause_task (GstPad * pad)
5321 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5323 GST_DEBUG_OBJECT (pad, "pause task");
5325 GST_OBJECT_LOCK (pad);
5326 task = GST_PAD_TASK (pad);
5329 res = gst_task_set_state (task, GST_TASK_PAUSED);
5330 GST_OBJECT_UNLOCK (pad);
5332 /* wait for task function to finish, this lock is recursive so it does nothing
5333 * when the pause is called from the task itself */
5334 GST_PAD_STREAM_LOCK (pad);
5335 GST_PAD_STREAM_UNLOCK (pad);
5341 GST_DEBUG_OBJECT (pad, "pad has no task");
5342 GST_OBJECT_UNLOCK (pad);
5348 * gst_pad_stop_task:
5349 * @pad: the #GstPad to stop the task of
5351 * Stop the task of @pad. This function will also make sure that the
5352 * function executed by the task will effectively stop if not called
5353 * from the GstTaskFunction.
5355 * This function will deadlock if called from the GstTaskFunction of
5356 * the task. Use gst_task_pause() instead.
5358 * Regardless of whether the pad has a task, the stream lock is acquired and
5359 * released so as to ensure that streaming through this pad has finished.
5361 * Returns: a TRUE if the task could be stopped or FALSE on error.
5364 gst_pad_stop_task (GstPad * pad)
5369 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5371 GST_DEBUG_OBJECT (pad, "stop task");
5373 GST_OBJECT_LOCK (pad);
5374 task = GST_PAD_TASK (pad);
5377 GST_PAD_TASK (pad) = NULL;
5378 res = gst_task_set_state (task, GST_TASK_STOPPED);
5379 GST_OBJECT_UNLOCK (pad);
5381 GST_PAD_STREAM_LOCK (pad);
5382 GST_PAD_STREAM_UNLOCK (pad);
5384 if (!gst_task_join (task))
5387 gst_object_unref (task);
5393 GST_DEBUG_OBJECT (pad, "no task");
5394 GST_OBJECT_UNLOCK (pad);
5396 GST_PAD_STREAM_LOCK (pad);
5397 GST_PAD_STREAM_UNLOCK (pad);
5399 /* this is not an error */
5404 /* this is bad, possibly the application tried to join the task from
5405 * the task's thread. We install the task again so that it will be stopped
5406 * again from the right thread next time hopefully. */
5407 GST_OBJECT_LOCK (pad);
5408 GST_DEBUG_OBJECT (pad, "join failed");
5409 /* we can only install this task if there was no other task */
5410 if (GST_PAD_TASK (pad) == NULL)
5411 GST_PAD_TASK (pad) = task;
5412 GST_OBJECT_UNLOCK (pad);