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 #ifndef GST_DISABLE_LOADSAVE
122 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
125 /* Some deprecated stuff that we need inside here for
126 * backwards compatibility */
127 #ifdef GST_DISABLE_DEPRECATED
128 #ifndef GST_REMOVE_DEPRECATED
129 #define GST_PAD_INTLINKFUNC(pad) (GST_PAD_CAST(pad)->intlinkfunc)
130 GList *gst_pad_get_internal_links_default (GstPad * pad);
134 static GstObjectClass *parent_class = NULL;
135 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
137 /* quarks for probe signals */
138 static GQuark buffer_quark;
139 static GQuark event_quark;
148 static GstFlowQuarks flow_quarks[] = {
149 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
150 {GST_FLOW_RESEND, "resend", 0},
151 {GST_FLOW_OK, "ok", 0},
152 {GST_FLOW_NOT_LINKED, "not-linked", 0},
153 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
154 {GST_FLOW_UNEXPECTED, "unexpected", 0},
155 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
156 {GST_FLOW_ERROR, "error", 0},
157 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
158 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
163 * @ret: a #GstFlowReturn to get the name of.
165 * Gets a string representing the given flow return.
167 * Returns: a static string with the name of the flow return.
169 G_CONST_RETURN gchar *
170 gst_flow_get_name (GstFlowReturn ret)
174 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
176 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
177 if (ret == flow_quarks[i].ret)
178 return flow_quarks[i].name;
185 * @ret: a #GstFlowReturn to get the quark of.
187 * Get the unique quark for the given GstFlowReturn.
189 * Returns: the quark associated with the flow return or 0 if an
190 * invalid return was specified.
193 gst_flow_to_quark (GstFlowReturn ret)
197 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
199 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
200 if (ret == flow_quarks[i].ret)
201 return flow_quarks[i].quark;
210 buffer_quark = g_quark_from_static_string ("buffer"); \
211 event_quark = g_quark_from_static_string ("event"); \
213 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
214 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
217 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
218 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
221 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
224 _gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
225 GValue * return_accu, const GValue * handler_return, gpointer dummy)
227 gboolean ret = g_value_get_boolean (handler_return);
229 GST_DEBUG ("accumulated %d", ret);
230 g_value_set_boolean (return_accu, ret);
236 default_have_data (GstPad * pad, GstMiniObject * o)
242 gst_pad_class_init (GstPadClass * klass)
244 GObjectClass *gobject_class;
245 GstObjectClass *gstobject_class;
247 gobject_class = G_OBJECT_CLASS (klass);
248 gstobject_class = GST_OBJECT_CLASS (klass);
250 g_type_class_add_private (klass, sizeof (GstPadPrivate));
252 parent_class = g_type_class_peek_parent (klass);
254 gobject_class->dispose = gst_pad_dispose;
255 gobject_class->finalize = gst_pad_finalize;
256 gobject_class->set_property = gst_pad_set_property;
257 gobject_class->get_property = gst_pad_get_property;
261 * @pad: the pad that emitted the signal
262 * @peer: the peer pad that has been connected
264 * Signals that a pad has been linked to the peer pad.
266 gst_pad_signals[PAD_LINKED] =
267 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
268 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
269 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
272 * @pad: the pad that emitted the signal
273 * @peer: the peer pad that has been disconnected
275 * Signals that a pad has been unlinked from the peer pad.
277 gst_pad_signals[PAD_UNLINKED] =
278 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
279 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
280 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
282 * GstPad::request-link:
283 * @pad: the pad that emitted the signal
284 * @peer: the peer pad for which a connection is requested
286 * Signals that a pad connection has been requested.
288 gst_pad_signals[PAD_REQUEST_LINK] =
289 g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
290 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
291 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
295 * @pad: the pad that emitted the signal
296 * @mini_obj: new data
298 * Signals that new data is available on the pad. This signal is used
299 * internally for implementing pad probes.
300 * See gst_pad_add_*_probe functions.
302 * Returns: %TRUE to keep the data, %FALSE to drop it
304 gst_pad_signals[PAD_HAVE_DATA] =
305 g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
306 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
307 G_STRUCT_OFFSET (GstPadClass, have_data),
308 _gst_do_pass_data_accumulator,
309 NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
310 GST_TYPE_MINI_OBJECT);
312 g_object_class_install_property (gobject_class, PAD_PROP_CAPS,
313 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
314 GST_TYPE_CAPS, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
315 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
316 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
317 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
318 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
319 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
320 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
321 g_param_spec_object ("template", "Template",
322 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
323 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
325 #ifndef GST_DISABLE_LOADSAVE
326 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
328 gstobject_class->path_string_separator = ".";
330 /* Register common function pointer descriptions */
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_query_types_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
335 #ifndef GST_REMOVE_DEPRECATED
336 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_internal_links_default);
338 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
339 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_acceptcaps_default);
341 klass->have_data = default_have_data;
345 gst_pad_init (GstPad * pad)
347 pad->abidata.ABI.priv = GST_PAD_GET_PRIVATE (pad);
349 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
350 GST_PAD_PEER (pad) = NULL;
352 GST_PAD_CHAINFUNC (pad) = NULL;
354 GST_PAD_LINKFUNC (pad) = NULL;
356 GST_PAD_CAPS (pad) = NULL;
357 GST_PAD_GETCAPSFUNC (pad) = NULL;
359 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
360 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
361 GST_PAD_QUERYTYPEFUNC (pad) = gst_pad_get_query_types_default;
362 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
363 #ifndef GST_REMOVE_DEPRECATED
364 GST_PAD_INTLINKFUNC (pad) = gst_pad_get_internal_links_default;
366 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
368 GST_PAD_ACCEPTCAPSFUNC (pad) = gst_pad_acceptcaps_default;
370 pad->do_buffer_signals = 0;
371 pad->do_event_signals = 0;
373 GST_PAD_SET_FLUSHING (pad);
375 pad->preroll_lock = g_mutex_new ();
376 pad->preroll_cond = g_cond_new ();
378 /* FIXME 0.11: Store this directly in the instance struct */
379 pad->stream_rec_lock = g_slice_new (GStaticRecMutex);
380 g_static_rec_mutex_init (pad->stream_rec_lock);
382 pad->block_cond = g_cond_new ();
386 gst_pad_dispose (GObject * object)
388 GstPad *pad = GST_PAD_CAST (object);
391 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
393 /* unlink the peer pad */
394 if ((peer = gst_pad_get_peer (pad))) {
395 /* window for MT unsafeness, someone else could unlink here
396 * and then we call unlink with wrong pads. The unlink
397 * function would catch this and safely return failed. */
398 if (GST_PAD_IS_SRC (pad))
399 gst_pad_unlink (pad, peer);
401 gst_pad_unlink (peer, pad);
403 gst_object_unref (peer);
407 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
409 gst_pad_set_pad_template (pad, NULL);
411 if (pad->block_destroy_data && pad->block_data) {
412 pad->block_destroy_data (pad->block_data);
413 pad->block_data = NULL;
416 G_OBJECT_CLASS (parent_class)->dispose (object);
420 gst_pad_finalize (GObject * object)
422 GstPad *pad = GST_PAD_CAST (object);
425 /* in case the task is still around, clean it up */
426 if ((task = GST_PAD_TASK (pad))) {
427 gst_task_join (task);
428 GST_PAD_TASK (pad) = NULL;
429 gst_object_unref (task);
432 if (pad->stream_rec_lock) {
433 g_static_rec_mutex_free (pad->stream_rec_lock);
434 g_slice_free (GStaticRecMutex, pad->stream_rec_lock);
435 pad->stream_rec_lock = NULL;
437 if (pad->preroll_lock) {
438 g_mutex_free (pad->preroll_lock);
439 g_cond_free (pad->preroll_cond);
440 pad->preroll_lock = NULL;
441 pad->preroll_cond = NULL;
443 if (pad->block_cond) {
444 g_cond_free (pad->block_cond);
445 pad->block_cond = NULL;
448 G_OBJECT_CLASS (parent_class)->finalize (object);
452 gst_pad_set_property (GObject * object, guint prop_id,
453 const GValue * value, GParamSpec * pspec)
455 g_return_if_fail (GST_IS_PAD (object));
458 case PAD_PROP_DIRECTION:
459 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
461 case PAD_PROP_TEMPLATE:
462 gst_pad_set_pad_template (GST_PAD_CAST (object),
463 (GstPadTemplate *) g_value_get_object (value));
466 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
472 gst_pad_get_property (GObject * object, guint prop_id,
473 GValue * value, GParamSpec * pspec)
475 g_return_if_fail (GST_IS_PAD (object));
479 GST_OBJECT_LOCK (object);
480 g_value_set_boxed (value, GST_PAD_CAPS (object));
481 GST_OBJECT_UNLOCK (object);
483 case PAD_PROP_DIRECTION:
484 g_value_set_enum (value, GST_PAD_DIRECTION (object));
486 case PAD_PROP_TEMPLATE:
487 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
490 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
497 * @name: the name of the new pad.
498 * @direction: the #GstPadDirection of the pad.
500 * Creates a new pad with the given name in the given direction.
501 * If name is NULL, a guaranteed unique name (across all pads)
503 * This function makes a copy of the name so you can safely free the name.
505 * Returns: a new #GstPad, or NULL in case of an error.
510 gst_pad_new (const gchar * name, GstPadDirection direction)
512 return g_object_new (GST_TYPE_PAD,
513 "name", name, "direction", direction, NULL);
517 * gst_pad_new_from_template:
518 * @templ: the pad template to use
519 * @name: the name of the element
521 * Creates a new pad with the given name from the given template.
522 * If name is NULL, a guaranteed unique name (across all pads)
524 * This function makes a copy of the name so you can safely free the name.
526 * Returns: a new #GstPad, or NULL in case of an error.
529 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
531 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
533 return g_object_new (GST_TYPE_PAD,
534 "name", name, "direction", templ->direction, "template", templ, NULL);
538 * gst_pad_new_from_static_template:
539 * @templ: the #GstStaticPadTemplate to use
540 * @name: the name of the element
542 * Creates a new pad with the given name from the given static template.
543 * If name is NULL, a guaranteed unique name (across all pads)
545 * This function makes a copy of the name so you can safely free the name.
547 * Returns: a new #GstPad, or NULL in case of an error.
550 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
554 GstPadTemplate *template;
556 template = gst_static_pad_template_get (templ);
557 pad = gst_pad_new_from_template (template, name);
558 gst_object_unref (template);
563 * gst_pad_get_direction:
564 * @pad: a #GstPad to get the direction of.
566 * Gets the direction of the pad. The direction of the pad is
567 * decided at construction time so this function does not take
570 * Returns: the #GstPadDirection of the pad.
575 gst_pad_get_direction (GstPad * pad)
577 GstPadDirection result;
579 /* PAD_UNKNOWN is a little silly but we need some sort of
580 * error return value */
581 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
583 result = GST_PAD_DIRECTION (pad);
589 gst_pad_activate_default (GstPad * pad)
591 return gst_pad_activate_push (pad, TRUE);
595 pre_activate (GstPad * pad, GstActivateMode new_mode)
598 case GST_ACTIVATE_PUSH:
599 case GST_ACTIVATE_PULL:
600 GST_OBJECT_LOCK (pad);
601 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
603 GST_PAD_UNSET_FLUSHING (pad);
604 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
605 GST_OBJECT_UNLOCK (pad);
607 case GST_ACTIVATE_NONE:
608 GST_OBJECT_LOCK (pad);
609 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
610 GST_PAD_SET_FLUSHING (pad);
611 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
612 /* unlock blocked pads so element can resume and stop */
613 GST_PAD_BLOCK_BROADCAST (pad);
614 GST_OBJECT_UNLOCK (pad);
620 post_activate (GstPad * pad, GstActivateMode new_mode)
623 case GST_ACTIVATE_PUSH:
624 case GST_ACTIVATE_PULL:
627 case GST_ACTIVATE_NONE:
628 /* ensures that streaming stops */
629 GST_PAD_STREAM_LOCK (pad);
630 GST_DEBUG_OBJECT (pad, "stopped streaming");
631 GST_PAD_STREAM_UNLOCK (pad);
637 * gst_pad_set_active:
638 * @pad: the #GstPad to activate or deactivate.
639 * @active: whether or not the pad should be active.
641 * Activates or deactivates the given pad.
642 * Normally called from within core state change functions.
644 * If @active, makes sure the pad is active. If it is already active, either in
645 * push or pull mode, just return. Otherwise dispatches to the pad's activate
646 * function to perform the actual activation.
648 * If not @active, checks the pad's current mode and calls
649 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
652 * Returns: #TRUE if the operation was successful.
657 gst_pad_set_active (GstPad * pad, gboolean active)
660 gboolean ret = FALSE;
662 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
664 GST_OBJECT_LOCK (pad);
665 old = GST_PAD_ACTIVATE_MODE (pad);
666 GST_OBJECT_UNLOCK (pad);
670 case GST_ACTIVATE_PUSH:
671 GST_DEBUG_OBJECT (pad, "activating pad from push");
674 case GST_ACTIVATE_PULL:
675 GST_DEBUG_OBJECT (pad, "activating pad from pull");
678 case GST_ACTIVATE_NONE:
679 GST_DEBUG_OBJECT (pad, "activating pad from none");
680 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
685 case GST_ACTIVATE_PUSH:
686 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
687 ret = gst_pad_activate_push (pad, FALSE);
689 case GST_ACTIVATE_PULL:
690 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
691 ret = gst_pad_activate_pull (pad, FALSE);
693 case GST_ACTIVATE_NONE:
694 GST_DEBUG_OBJECT (pad, "deactivating pad from none");
701 GST_OBJECT_LOCK (pad);
703 g_critical ("Failed to deactivate pad %s:%s, very bad",
704 GST_DEBUG_PAD_NAME (pad));
706 GST_WARNING_OBJECT (pad, "Failed to activate pad");
708 GST_OBJECT_UNLOCK (pad);
715 * gst_pad_activate_pull:
716 * @pad: the #GstPad to activate or deactivate.
717 * @active: whether or not the pad should be active.
719 * Activates or deactivates the given pad in pull mode via dispatching to the
720 * pad's activatepullfunc. For use from within pad activation functions only.
721 * When called on sink pads, will first proxy the call to the peer pad, which
722 * is expected to activate its internally linked pads from within its
723 * activate_pull function.
725 * If you don't know what this is, you probably don't want to call it.
727 * Returns: TRUE if the operation was successful.
732 gst_pad_activate_pull (GstPad * pad, gboolean active)
734 GstActivateMode old, new;
737 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
739 GST_OBJECT_LOCK (pad);
740 old = GST_PAD_ACTIVATE_MODE (pad);
741 GST_OBJECT_UNLOCK (pad);
745 case GST_ACTIVATE_PULL:
746 GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
748 case GST_ACTIVATE_PUSH:
749 GST_DEBUG_OBJECT (pad,
750 "activating pad from push, deactivate push first");
751 /* pad was activate in the wrong direction, deactivate it
752 * and reactivate it in pull mode */
753 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
754 goto deactivate_failed;
755 /* fallthrough, pad is deactivated now. */
756 case GST_ACTIVATE_NONE:
757 GST_DEBUG_OBJECT (pad, "activating pad from none");
762 case GST_ACTIVATE_NONE:
763 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
765 case GST_ACTIVATE_PUSH:
766 GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
767 /* pad was activated in the other direction, deactivate it
768 * in push mode, this should not happen... */
769 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
770 goto deactivate_failed;
771 /* everything is fine now */
773 case GST_ACTIVATE_PULL:
774 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
779 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
780 if ((peer = gst_pad_get_peer (pad))) {
781 GST_DEBUG_OBJECT (pad, "calling peer");
782 if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
784 gst_object_unref (peer);
786 /* there is no peer, this is only fatal when we activate. When we
787 * deactivate, we must assume the application has unlinked the peer and
788 * will deactivate it eventually. */
792 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
795 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
796 goto failure; /* Can't activate pull on a src without a
800 new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
801 pre_activate (pad, new);
803 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
804 if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
807 /* can happen for sinks of passthrough elements */
810 post_activate (pad, new);
812 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
813 active ? "activated" : "deactivated");
819 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
820 active ? "activated" : "deactivated");
825 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
826 "failed to %s in switch to pull from mode %d",
827 (active ? "activate" : "deactivate"), old);
832 GST_OBJECT_LOCK (peer);
833 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
834 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
835 GST_OBJECT_UNLOCK (peer);
836 gst_object_unref (peer);
841 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
847 GST_OBJECT_LOCK (pad);
848 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
849 active ? "activate" : "deactivate");
850 GST_PAD_SET_FLUSHING (pad);
851 GST_PAD_ACTIVATE_MODE (pad) = old;
852 GST_OBJECT_UNLOCK (pad);
858 * gst_pad_activate_push:
859 * @pad: the #GstPad to activate or deactivate.
860 * @active: whether the pad should be active or not.
862 * Activates or deactivates the given pad in push mode via dispatching to the
863 * pad's activatepushfunc. For use from within pad activation functions only.
865 * If you don't know what this is, you probably don't want to call it.
867 * Returns: %TRUE if the operation was successful.
872 gst_pad_activate_push (GstPad * pad, gboolean active)
874 GstActivateMode old, new;
876 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
877 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
878 active ? "activated" : "deactivated");
880 GST_OBJECT_LOCK (pad);
881 old = GST_PAD_ACTIVATE_MODE (pad);
882 GST_OBJECT_UNLOCK (pad);
886 case GST_ACTIVATE_PUSH:
887 GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
889 case GST_ACTIVATE_PULL:
890 GST_DEBUG_OBJECT (pad,
891 "activating pad from push, deactivating pull first");
892 /* pad was activate in the wrong direction, deactivate it
893 * an reactivate it in push mode */
894 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
895 goto deactivate_failed;
896 /* fallthrough, pad is deactivated now. */
897 case GST_ACTIVATE_NONE:
898 GST_DEBUG_OBJECT (pad, "activating pad from none");
903 case GST_ACTIVATE_NONE:
904 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
906 case GST_ACTIVATE_PULL:
907 GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
908 /* pad was activated in the other direction, deactivate it
909 * in pull mode, this should not happen... */
910 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
911 goto deactivate_failed;
912 /* everything is fine now */
914 case GST_ACTIVATE_PUSH:
915 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
920 new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
921 pre_activate (pad, new);
923 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
924 if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
928 /* quite ok, element relies on state change func to prepare itself */
931 post_activate (pad, new);
933 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
934 active ? "activated" : "deactivated");
939 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
940 active ? "activated" : "deactivated");
945 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
946 "failed to %s in switch to push from mode %d",
947 (active ? "activate" : "deactivate"), old);
952 GST_OBJECT_LOCK (pad);
953 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
954 active ? "activate" : "deactivate");
955 GST_PAD_SET_FLUSHING (pad);
956 GST_PAD_ACTIVATE_MODE (pad) = old;
957 GST_OBJECT_UNLOCK (pad);
964 * @pad: the #GstPad to query
966 * Query if a pad is active
968 * Returns: TRUE if the pad is active.
973 gst_pad_is_active (GstPad * pad)
975 gboolean result = FALSE;
977 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
979 GST_OBJECT_LOCK (pad);
980 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
981 GST_OBJECT_UNLOCK (pad);
987 * gst_pad_set_blocked_async_full:
988 * @pad: the #GstPad to block or unblock
989 * @blocked: boolean indicating whether the pad should be blocked or unblocked
990 * @callback: #GstPadBlockCallback that will be called when the
992 * @user_data: user data passed to the callback
993 * @destroy_data: #GDestroyNotify for user_data
995 * Blocks or unblocks the dataflow on a pad. The provided callback
996 * is called when the operation succeeds; this happens right before the next
997 * attempt at pushing a buffer on the pad.
999 * This can take a while as the pad can only become blocked when real dataflow
1001 * When the pipeline is stalled, for example in PAUSED, this can
1002 * take an indeterminate amount of time.
1003 * You can pass NULL as the callback to make this call block. Be careful with
1004 * this blocking call as it might not return for reasons stated above.
1006 * Returns: TRUE if the pad could be blocked. This function can fail if the
1007 * wrong parameters were passed or the pad was already in the requested state.
1014 gst_pad_set_blocked_async_full (GstPad * pad, gboolean blocked,
1015 GstPadBlockCallback callback, gpointer user_data,
1016 GDestroyNotify destroy_data)
1018 gboolean was_blocked = FALSE;
1020 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1022 GST_OBJECT_LOCK (pad);
1024 was_blocked = GST_PAD_IS_BLOCKED (pad);
1026 if (G_UNLIKELY (was_blocked == blocked))
1027 goto had_right_state;
1030 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad");
1032 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
1034 if (pad->block_destroy_data && pad->block_data)
1035 pad->block_destroy_data (pad->block_data);
1037 pad->block_callback = callback;
1038 pad->block_data = user_data;
1039 pad->block_destroy_data = destroy_data;
1040 pad->abidata.ABI.block_callback_called = FALSE;
1042 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
1043 GST_PAD_BLOCK_WAIT (pad);
1044 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
1047 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad");
1049 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
1051 if (pad->block_destroy_data && pad->block_data)
1052 pad->block_destroy_data (pad->block_data);
1054 pad->block_callback = callback;
1055 pad->block_data = user_data;
1056 pad->block_destroy_data = destroy_data;
1057 pad->abidata.ABI.block_callback_called = FALSE;
1059 GST_PAD_BLOCK_BROADCAST (pad);
1061 /* no callback, wait for the unblock to happen */
1062 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
1063 GST_PAD_BLOCK_WAIT (pad);
1064 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
1067 GST_OBJECT_UNLOCK (pad);
1073 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1074 "pad was in right state (%d)", was_blocked);
1075 GST_OBJECT_UNLOCK (pad);
1082 * gst_pad_set_blocked_async:
1083 * @pad: the #GstPad to block or unblock
1084 * @blocked: boolean indicating whether the pad should be blocked or unblocked
1085 * @callback: #GstPadBlockCallback that will be called when the
1086 * operation succeeds
1087 * @user_data: user data passed to the callback
1089 * Blocks or unblocks the dataflow on a pad. The provided callback
1090 * is called when the operation succeeds; this happens right before the next
1091 * attempt at pushing a buffer on the pad.
1093 * This can take a while as the pad can only become blocked when real dataflow
1095 * When the pipeline is stalled, for example in PAUSED, this can
1096 * take an indeterminate amount of time.
1097 * You can pass NULL as the callback to make this call block. Be careful with
1098 * this blocking call as it might not return for reasons stated above.
1100 * Returns: TRUE if the pad could be blocked. This function can fail if the
1101 * wrong parameters were passed or the pad was already in the requested state.
1106 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
1107 GstPadBlockCallback callback, gpointer user_data)
1109 return gst_pad_set_blocked_async_full (pad, blocked,
1110 callback, user_data, NULL);
1114 * gst_pad_set_blocked:
1115 * @pad: the #GstPad to block or unblock
1116 * @blocked: boolean indicating we should block or unblock
1118 * Blocks or unblocks the dataflow on a pad. This function is
1119 * a shortcut for gst_pad_set_blocked_async() with a NULL
1122 * Returns: TRUE if the pad could be blocked. This function can fail if the
1123 * wrong parameters were passed or the pad was already in the requested state.
1128 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
1130 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
1134 * gst_pad_is_blocked:
1135 * @pad: the #GstPad to query
1137 * Checks if the pad is blocked or not. This function returns the
1138 * last requested state of the pad. It is not certain that the pad
1139 * is actually blocking at this point (see gst_pad_is_blocking()).
1141 * Returns: TRUE if the pad is blocked.
1146 gst_pad_is_blocked (GstPad * pad)
1148 gboolean result = FALSE;
1150 g_return_val_if_fail (GST_IS_PAD (pad), result);
1152 GST_OBJECT_LOCK (pad);
1153 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
1154 GST_OBJECT_UNLOCK (pad);
1160 * gst_pad_is_blocking:
1161 * @pad: the #GstPad to query
1163 * Checks if the pad is blocking or not. This is a guaranteed state
1164 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1166 * Returns: TRUE if the pad is blocking.
1173 gst_pad_is_blocking (GstPad * pad)
1175 gboolean result = FALSE;
1177 g_return_val_if_fail (GST_IS_PAD (pad), result);
1179 GST_OBJECT_LOCK (pad);
1180 /* the blocking flag is only valid if the pad is not flushing */
1181 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING) &&
1182 !GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING);
1183 GST_OBJECT_UNLOCK (pad);
1189 * gst_pad_set_activate_function:
1191 * @activate: the #GstPadActivateFunction to set.
1193 * Sets the given activate function for @pad. The activate function will
1194 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1195 * the actual activation. Only makes sense to set on sink pads.
1197 * Call this function if your sink pad can start a pull-based task.
1200 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1202 g_return_if_fail (GST_IS_PAD (pad));
1204 GST_PAD_ACTIVATEFUNC (pad) = activate;
1205 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1206 GST_DEBUG_FUNCPTR_NAME (activate));
1210 * gst_pad_set_activatepull_function:
1212 * @activatepull: the #GstPadActivateModeFunction to set.
1214 * Sets the given activate_pull function for the pad. An activate_pull function
1215 * prepares the element and any upstream connections for pulling. See XXX
1216 * part-activation.txt for details.
1219 gst_pad_set_activatepull_function (GstPad * pad,
1220 GstPadActivateModeFunction activatepull)
1222 g_return_if_fail (GST_IS_PAD (pad));
1224 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1225 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepullfunc set to %s",
1226 GST_DEBUG_FUNCPTR_NAME (activatepull));
1230 * gst_pad_set_activatepush_function:
1232 * @activatepush: the #GstPadActivateModeFunction to set.
1234 * Sets the given activate_push function for the pad. An activate_push function
1235 * prepares the element for pushing. See XXX part-activation.txt for details.
1238 gst_pad_set_activatepush_function (GstPad * pad,
1239 GstPadActivateModeFunction activatepush)
1241 g_return_if_fail (GST_IS_PAD (pad));
1243 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1244 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepushfunc set to %s",
1245 GST_DEBUG_FUNCPTR_NAME (activatepush));
1249 * gst_pad_set_chain_function:
1250 * @pad: a sink #GstPad.
1251 * @chain: the #GstPadChainFunction to set.
1253 * Sets the given chain function for the pad. The chain function is called to
1254 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1257 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1259 g_return_if_fail (GST_IS_PAD (pad));
1260 g_return_if_fail (GST_PAD_IS_SINK (pad));
1262 GST_PAD_CHAINFUNC (pad) = chain;
1263 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1264 GST_DEBUG_FUNCPTR_NAME (chain));
1268 * gst_pad_set_chain_list_function:
1269 * @pad: a sink #GstPad.
1270 * @chainlist: the #GstPadChainListFunction to set.
1272 * Sets the given chain list function for the pad. The chainlist function is
1273 * called to process a #GstBufferList input buffer list. See
1274 * #GstPadChainListFunction for more details.
1279 gst_pad_set_chain_list_function (GstPad * pad,
1280 GstPadChainListFunction chainlist)
1282 g_return_if_fail (GST_IS_PAD (pad));
1283 g_return_if_fail (GST_PAD_IS_SINK (pad));
1285 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1286 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1287 GST_DEBUG_FUNCPTR_NAME (chainlist));
1291 * gst_pad_set_getrange_function:
1292 * @pad: a source #GstPad.
1293 * @get: the #GstPadGetRangeFunction to set.
1295 * Sets the given getrange function for the pad. The getrange function is
1296 * called to produce a new #GstBuffer to start the processing pipeline. see
1297 * #GstPadGetRangeFunction for a description of the getrange function.
1300 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1302 g_return_if_fail (GST_IS_PAD (pad));
1303 g_return_if_fail (GST_PAD_IS_SRC (pad));
1305 GST_PAD_GETRANGEFUNC (pad) = get;
1307 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1308 GST_DEBUG_FUNCPTR_NAME (get));
1312 * gst_pad_set_checkgetrange_function:
1313 * @pad: a source #GstPad.
1314 * @check: the #GstPadCheckGetRangeFunction to set.
1316 * Sets the given checkgetrange function for the pad. Implement this function
1317 * on a pad if you dynamically support getrange based scheduling on the pad.
1320 gst_pad_set_checkgetrange_function (GstPad * pad,
1321 GstPadCheckGetRangeFunction check)
1323 g_return_if_fail (GST_IS_PAD (pad));
1324 g_return_if_fail (GST_PAD_IS_SRC (pad));
1326 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
1328 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "checkgetrangefunc set to %s",
1329 GST_DEBUG_FUNCPTR_NAME (check));
1333 * gst_pad_set_event_function:
1334 * @pad: a #GstPad of either direction.
1335 * @event: the #GstPadEventFunction to set.
1337 * Sets the given event handler for the pad.
1340 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1342 g_return_if_fail (GST_IS_PAD (pad));
1344 GST_PAD_EVENTFUNC (pad) = event;
1346 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1347 GST_DEBUG_FUNCPTR_NAME (event));
1351 * gst_pad_set_query_function:
1352 * @pad: a #GstPad of either direction.
1353 * @query: the #GstPadQueryFunction to set.
1355 * Set the given query function for the pad.
1358 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1360 g_return_if_fail (GST_IS_PAD (pad));
1362 GST_PAD_QUERYFUNC (pad) = query;
1364 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1365 GST_DEBUG_FUNCPTR_NAME (query));
1369 * gst_pad_set_query_type_function:
1370 * @pad: a #GstPad of either direction.
1371 * @type_func: the #GstPadQueryTypeFunction to set.
1373 * Set the given query type function for the pad.
1376 gst_pad_set_query_type_function (GstPad * pad,
1377 GstPadQueryTypeFunction type_func)
1379 g_return_if_fail (GST_IS_PAD (pad));
1381 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1383 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "querytypefunc set to %s",
1384 GST_DEBUG_FUNCPTR_NAME (type_func));
1388 * gst_pad_get_query_types:
1391 * Get an array of supported queries that can be performed
1394 * Returns: a zero-terminated array of #GstQueryType.
1396 const GstQueryType *
1397 gst_pad_get_query_types (GstPad * pad)
1399 GstPadQueryTypeFunction func;
1401 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1403 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1415 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1417 *data = gst_pad_get_query_types (pad);
1423 * gst_pad_get_query_types_default:
1426 * Invoke the default dispatcher for the query types on
1429 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1430 * internally-linked pads has a query types function.
1432 const GstQueryType *
1433 gst_pad_get_query_types_default (GstPad * pad)
1435 GstQueryType *result = NULL;
1437 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1439 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1440 gst_pad_get_query_types_dispatcher, &result);
1446 * gst_pad_set_iterate_internal_links_function:
1447 * @pad: a #GstPad of either direction.
1448 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1450 * Sets the given internal link iterator function for the pad.
1455 gst_pad_set_iterate_internal_links_function (GstPad * pad,
1456 GstPadIterIntLinkFunction iterintlink)
1458 g_return_if_fail (GST_IS_PAD (pad));
1460 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1461 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1462 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1466 * gst_pad_set_internal_link_function:
1467 * @pad: a #GstPad of either direction.
1468 * @intlink: the #GstPadIntLinkFunction to set.
1470 * Sets the given internal link function for the pad.
1472 * Deprecated: Use the thread-safe gst_pad_set_iterate_internal_links_function()
1474 #ifndef GST_REMOVE_DEPRECATED
1475 #ifdef GST_DISABLE_DEPRECATED
1477 gst_pad_set_internal_link_function (GstPad * pad,
1478 GstPadIntLinkFunction intlink);
1481 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1483 g_return_if_fail (GST_IS_PAD (pad));
1485 GST_PAD_INTLINKFUNC (pad) = intlink;
1486 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link set to %s",
1487 GST_DEBUG_FUNCPTR_NAME (intlink));
1489 #endif /* GST_REMOVE_DEPRECATED */
1492 * gst_pad_set_link_function:
1494 * @link: the #GstPadLinkFunction to set.
1496 * Sets the given link function for the pad. It will be called when
1497 * the pad is linked with another pad.
1499 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1502 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1503 * cannot be made for some reason.
1505 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1506 * of the peer sink pad, if present.
1509 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1511 g_return_if_fail (GST_IS_PAD (pad));
1513 GST_PAD_LINKFUNC (pad) = link;
1514 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1515 GST_DEBUG_FUNCPTR_NAME (link));
1519 * gst_pad_set_unlink_function:
1521 * @unlink: the #GstPadUnlinkFunction to set.
1523 * Sets the given unlink function for the pad. It will be called
1524 * when the pad is unlinked.
1527 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1529 g_return_if_fail (GST_IS_PAD (pad));
1531 GST_PAD_UNLINKFUNC (pad) = unlink;
1532 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1533 GST_DEBUG_FUNCPTR_NAME (unlink));
1537 * gst_pad_set_getcaps_function:
1539 * @getcaps: the #GstPadGetCapsFunction to set.
1541 * Sets the given getcaps function for the pad. @getcaps should return the
1542 * allowable caps for a pad in the context of the element's state, its link to
1543 * other elements, and the devices or files it has opened. These caps must be a
1544 * subset of the pad template caps. In the NULL state with no links, @getcaps
1545 * should ideally return the same caps as the pad template. In rare
1546 * circumstances, an object property can affect the caps returned by @getcaps,
1547 * but this is discouraged.
1549 * You do not need to call this function if @pad's allowed caps are always the
1550 * same as the pad template caps. This can only be true if the padtemplate
1551 * has fixed simple caps.
1553 * For most filters, the caps returned by @getcaps is directly affected by the
1554 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1555 * the srcpad's getcaps function is directly related to the stream data. Again,
1556 * @getcaps should return the most specific caps it reasonably can, since this
1557 * helps with autoplugging.
1559 * Note that the return value from @getcaps is owned by the caller, so the
1560 * caller should unref the caps after usage.
1563 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1565 g_return_if_fail (GST_IS_PAD (pad));
1567 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1568 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getcapsfunc set to %s",
1569 GST_DEBUG_FUNCPTR_NAME (getcaps));
1573 * gst_pad_set_acceptcaps_function:
1575 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1577 * Sets the given acceptcaps function for the pad. The acceptcaps function
1578 * will be called to check if the pad can accept the given caps. Setting the
1579 * acceptcaps function to NULL restores the default behaviour of allowing
1580 * any caps that matches the caps from gst_pad_get_caps.
1583 gst_pad_set_acceptcaps_function (GstPad * pad,
1584 GstPadAcceptCapsFunction acceptcaps)
1586 g_return_if_fail (GST_IS_PAD (pad));
1588 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1589 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "acceptcapsfunc set to %s",
1590 GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1594 * gst_pad_set_fixatecaps_function:
1596 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1598 * Sets the given fixatecaps function for the pad. The fixatecaps function
1599 * will be called whenever the default values for a GstCaps needs to be
1603 gst_pad_set_fixatecaps_function (GstPad * pad,
1604 GstPadFixateCapsFunction fixatecaps)
1606 g_return_if_fail (GST_IS_PAD (pad));
1608 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1609 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fixatecapsfunc set to %s",
1610 GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1614 * gst_pad_set_setcaps_function:
1616 * @setcaps: the #GstPadSetCapsFunction to set.
1618 * Sets the given setcaps function for the pad. The setcaps function
1619 * will be called whenever a buffer with a new media type is pushed or
1620 * pulled from the pad. The pad/element needs to update its internal
1621 * structures to process the new media type. If this new type is not
1622 * acceptable, the setcaps function should return FALSE.
1625 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1627 g_return_if_fail (GST_IS_PAD (pad));
1629 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1630 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "setcapsfunc set to %s",
1631 GST_DEBUG_FUNCPTR_NAME (setcaps));
1635 * gst_pad_set_bufferalloc_function:
1636 * @pad: a sink #GstPad.
1637 * @bufalloc: the #GstPadBufferAllocFunction to set.
1639 * Sets the given bufferalloc function for the pad. Note that the
1640 * bufferalloc function can only be set on sinkpads.
1643 gst_pad_set_bufferalloc_function (GstPad * pad,
1644 GstPadBufferAllocFunction bufalloc)
1646 g_return_if_fail (GST_IS_PAD (pad));
1647 g_return_if_fail (GST_PAD_IS_SINK (pad));
1649 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1650 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "bufferallocfunc set to %s",
1651 GST_DEBUG_FUNCPTR_NAME (bufalloc));
1656 * @srcpad: the source #GstPad to unlink.
1657 * @sinkpad: the sink #GstPad to unlink.
1659 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1660 * signal on both pads.
1662 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1663 * the pads were not linked together.
1668 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1670 gboolean result = FALSE;
1671 GstElement *parent = NULL;
1673 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1674 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1675 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1676 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1678 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1679 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1680 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1682 /* We need to notify the parent before taking any pad locks as the bin in
1683 * question might be waiting for a lock on the pad while holding its lock
1684 * that our message will try to take. */
1685 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1686 if (GST_IS_ELEMENT (parent)) {
1687 gst_element_post_message (parent,
1688 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1689 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1691 gst_object_unref (parent);
1696 GST_OBJECT_LOCK (srcpad);
1698 GST_OBJECT_LOCK (sinkpad);
1700 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1701 goto not_linked_together;
1703 if (GST_PAD_UNLINKFUNC (srcpad)) {
1704 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1706 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1707 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1710 /* first clear peers */
1711 GST_PAD_PEER (srcpad) = NULL;
1712 GST_PAD_PEER (sinkpad) = NULL;
1714 GST_OBJECT_UNLOCK (sinkpad);
1715 GST_OBJECT_UNLOCK (srcpad);
1717 /* fire off a signal to each of the pads telling them
1718 * that they've been unlinked */
1719 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1720 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1722 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1723 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1728 if (parent != NULL) {
1729 gst_element_post_message (parent,
1730 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1731 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1732 gst_object_unref (parent);
1737 not_linked_together:
1739 /* we do not emit a warning in this case because unlinking cannot
1740 * be made MT safe.*/
1741 GST_OBJECT_UNLOCK (sinkpad);
1742 GST_OBJECT_UNLOCK (srcpad);
1748 * gst_pad_is_linked:
1749 * @pad: pad to check
1751 * Checks if a @pad is linked to another pad or not.
1753 * Returns: TRUE if the pad is linked, FALSE otherwise.
1758 gst_pad_is_linked (GstPad * pad)
1762 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1764 GST_OBJECT_LOCK (pad);
1765 result = (GST_PAD_PEER (pad) != NULL);
1766 GST_OBJECT_UNLOCK (pad);
1771 /* get the caps from both pads and see if the intersection
1774 * This function should be called with the pad LOCK on both
1778 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1782 gboolean compatible = FALSE;
1784 srccaps = gst_pad_get_caps_unlocked (src);
1785 sinkcaps = gst_pad_get_caps_unlocked (sink);
1787 GST_CAT_DEBUG (GST_CAT_CAPS, "src caps %" GST_PTR_FORMAT, srccaps);
1788 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1790 /* if we have caps on both pads we can check the intersection. If one
1791 * of the caps is NULL, we return TRUE. */
1792 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1794 gst_caps_unref (srccaps);
1796 gst_caps_unref (sinkcaps);
1800 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1801 gst_caps_unref (srccaps);
1802 gst_caps_unref (sinkcaps);
1805 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1806 (compatible ? "" : "not"));
1811 /* check if the grandparents of both pads are the same.
1812 * This check is required so that we don't try to link
1813 * pads from elements in different bins without ghostpads.
1815 * The LOCK should be held on both pads
1818 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1820 GstObject *psrc, *psink;
1822 psrc = GST_OBJECT_PARENT (src);
1823 psink = GST_OBJECT_PARENT (sink);
1825 /* if one of the pads has no parent, we allow the link */
1826 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1829 /* only care about parents that are elements */
1830 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1831 goto no_element_parent;
1833 /* if the parents are the same, we have a loop */
1834 if (G_UNLIKELY (psrc == psink))
1837 /* if they both have a parent, we check the grandparents. We can not lock
1838 * the parent because we hold on the child (pad) and the locking order is
1839 * parent >> child. */
1840 psrc = GST_OBJECT_PARENT (psrc);
1841 psink = GST_OBJECT_PARENT (psink);
1843 /* if they have grandparents but they are not the same */
1844 if (G_UNLIKELY (psrc != psink))
1845 goto wrong_grandparents;
1852 GST_CAT_DEBUG (GST_CAT_CAPS,
1853 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1854 GST_PTR_FORMAT, psrc, psink);
1859 GST_CAT_DEBUG (GST_CAT_CAPS,
1860 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1861 GST_PTR_FORMAT, psrc, psink);
1866 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1872 GST_CAT_DEBUG (GST_CAT_CAPS,
1873 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1874 GST_PTR_FORMAT, psrc, psink);
1879 /* FIXME leftover from an attempt at refactoring... */
1880 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1881 * the two pads will be locked in the srcpad, sinkpad order. */
1882 static GstPadLinkReturn
1883 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1885 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1886 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1888 GST_OBJECT_LOCK (srcpad);
1890 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1891 goto src_was_linked;
1893 GST_OBJECT_LOCK (sinkpad);
1895 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1896 goto sink_was_linked;
1898 /* check hierarchy, pads can only be linked if the grandparents
1900 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1901 goto wrong_hierarchy;
1903 /* check pad caps for non-empty intersection */
1904 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1907 /* FIXME check pad scheduling for non-empty intersection */
1909 return GST_PAD_LINK_OK;
1913 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1914 GST_DEBUG_PAD_NAME (srcpad),
1915 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1916 /* we do not emit a warning in this case because unlinking cannot
1917 * be made MT safe.*/
1918 GST_OBJECT_UNLOCK (srcpad);
1919 return GST_PAD_LINK_WAS_LINKED;
1923 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1924 GST_DEBUG_PAD_NAME (sinkpad),
1925 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1926 /* we do not emit a warning in this case because unlinking cannot
1927 * be made MT safe.*/
1928 GST_OBJECT_UNLOCK (sinkpad);
1929 GST_OBJECT_UNLOCK (srcpad);
1930 return GST_PAD_LINK_WAS_LINKED;
1934 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1935 GST_OBJECT_UNLOCK (sinkpad);
1936 GST_OBJECT_UNLOCK (srcpad);
1937 return GST_PAD_LINK_WRONG_HIERARCHY;
1941 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1942 GST_OBJECT_UNLOCK (sinkpad);
1943 GST_OBJECT_UNLOCK (srcpad);
1944 return GST_PAD_LINK_NOFORMAT;
1950 * @srcpad: the source #GstPad.
1951 * @sinkpad: the sink #GstPad.
1953 * Checks if the source pad and the sink pad are compatible so they can be
1956 * Returns: TRUE if the pads can be linked.
1959 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1961 GstPadLinkReturn result;
1963 /* generic checks */
1964 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1965 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1967 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1968 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1970 /* gst_pad_link_prepare does everything for us, we only release the locks
1971 * on the pads that it gets us. If this function returns !OK the locks are not
1973 result = gst_pad_link_prepare (srcpad, sinkpad);
1974 if (result != GST_PAD_LINK_OK)
1977 GST_OBJECT_UNLOCK (srcpad);
1978 GST_OBJECT_UNLOCK (sinkpad);
1981 return result == GST_PAD_LINK_OK;
1986 * @srcpad: the source #GstPad to link.
1987 * @sinkpad: the sink #GstPad to link.
1989 * Links the source pad and the sink pad.
1991 * Returns: A result code indicating if the connection worked or
1997 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1999 GstPadLinkReturn result;
2002 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2003 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2004 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2005 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2006 GST_PAD_LINK_WRONG_DIRECTION);
2008 /* Notify the parent early. See gst_pad_unlink for details. */
2009 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2010 if (GST_IS_ELEMENT (parent)) {
2011 gst_element_post_message (parent,
2012 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2013 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2015 gst_object_unref (parent);
2020 /* prepare will also lock the two pads */
2021 result = gst_pad_link_prepare (srcpad, sinkpad);
2023 if (result != GST_PAD_LINK_OK)
2026 /* must set peers before calling the link function */
2027 GST_PAD_PEER (srcpad) = sinkpad;
2028 GST_PAD_PEER (sinkpad) = srcpad;
2030 GST_OBJECT_UNLOCK (sinkpad);
2031 GST_OBJECT_UNLOCK (srcpad);
2033 /* FIXME released the locks here, concurrent thread might link
2034 * something else. */
2035 if (GST_PAD_LINKFUNC (srcpad)) {
2036 /* this one will call the peer link function */
2037 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
2038 } else if (GST_PAD_LINKFUNC (sinkpad)) {
2039 /* if no source link function, we need to call the sink link
2040 * function ourselves. */
2041 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
2043 result = GST_PAD_LINK_OK;
2046 GST_OBJECT_LOCK (srcpad);
2047 GST_OBJECT_LOCK (sinkpad);
2049 if (result == GST_PAD_LINK_OK) {
2050 GST_OBJECT_UNLOCK (sinkpad);
2051 GST_OBJECT_UNLOCK (srcpad);
2053 /* fire off a signal to each of the pads telling them
2054 * that they've been linked */
2055 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2056 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2058 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2059 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2061 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2062 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2064 GST_PAD_PEER (srcpad) = NULL;
2065 GST_PAD_PEER (sinkpad) = NULL;
2067 GST_OBJECT_UNLOCK (sinkpad);
2068 GST_OBJECT_UNLOCK (srcpad);
2073 gst_element_post_message (parent,
2074 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2075 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2076 gst_object_unref (parent);
2083 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2085 GstPadTemplate **template_p;
2087 /* this function would need checks if it weren't static */
2089 GST_OBJECT_LOCK (pad);
2090 template_p = &pad->padtemplate;
2091 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2092 GST_OBJECT_UNLOCK (pad);
2095 gst_pad_template_pad_created (templ, pad);
2099 * gst_pad_get_pad_template:
2102 * Gets the template for @pad.
2104 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
2105 * if this pad has no template.
2107 * FIXME: currently returns an unrefcounted padtemplate.
2110 gst_pad_get_pad_template (GstPad * pad)
2112 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2114 return GST_PAD_PAD_TEMPLATE (pad);
2118 /* should be called with the pad LOCK held */
2119 /* refs the caps, so caller is responsible for getting it unreffed */
2121 gst_pad_get_caps_unlocked (GstPad * pad)
2123 GstCaps *result = NULL;
2124 GstPadTemplate *templ;
2126 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2128 if (GST_PAD_GETCAPSFUNC (pad)) {
2129 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2130 "dispatching to pad getcaps function");
2132 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
2133 GST_OBJECT_UNLOCK (pad);
2134 result = GST_PAD_GETCAPSFUNC (pad) (pad);
2135 GST_OBJECT_LOCK (pad);
2136 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
2138 if (result == NULL) {
2139 g_critical ("pad %s:%s returned NULL caps from getcaps function",
2140 GST_DEBUG_PAD_NAME (pad));
2142 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2143 "pad getcaps returned %" GST_PTR_FORMAT, result);
2144 #ifndef G_DISABLE_ASSERT
2145 /* check that the returned caps are a real subset of the template caps */
2146 if (GST_PAD_PAD_TEMPLATE (pad)) {
2147 const GstCaps *templ_caps =
2148 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2149 if (!gst_caps_is_subset (result, templ_caps)) {
2152 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2153 "pad returned caps %" GST_PTR_FORMAT
2154 " which are not a real subset of its template caps %"
2155 GST_PTR_FORMAT, result, templ_caps);
2157 ("pad %s:%s returned caps which are not a real "
2158 "subset of its template caps", GST_DEBUG_PAD_NAME (pad));
2159 temp = gst_caps_intersect (templ_caps, result);
2160 gst_caps_unref (result);
2168 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2169 result = GST_PAD_TEMPLATE_CAPS (templ);
2170 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2171 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
2174 result = gst_caps_ref (result);
2177 if ((result = GST_PAD_CAPS (pad))) {
2178 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2179 "using pad caps %p %" GST_PTR_FORMAT, result, result);
2181 result = gst_caps_ref (result);
2185 /* this almost never happens */
2186 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2187 result = gst_caps_new_empty ();
2193 /* FIXME-0.11: what about making this the default and using
2194 * gst_caps_make_writable() explicitely where needed
2197 * gst_pad_get_caps_reffed:
2198 * @pad: a #GstPad to get the capabilities of.
2200 * Gets the capabilities this pad can produce or consume. Preferred function if
2201 * one only wants to read or intersect the caps.
2203 * Returns: the caps of the pad with incremented ref-count.
2208 gst_pad_get_caps_reffed (GstPad * pad)
2210 GstCaps *result = NULL;
2212 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2214 GST_OBJECT_LOCK (pad);
2216 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2218 result = gst_pad_get_caps_unlocked (pad);
2220 GST_OBJECT_UNLOCK (pad);
2227 * @pad: a #GstPad to get the capabilities of.
2229 * Gets the capabilities this pad can produce or consume.
2230 * Note that this method doesn't necessarily return the caps set by
2231 * gst_pad_set_caps() - use GST_PAD_CAPS() for that instead.
2232 * gst_pad_get_caps returns all possible caps a pad can operate with, using
2233 * the pad's get_caps function;
2234 * this returns the pad template caps if not explicitly set.
2236 * Returns: a newly allocated copy of the #GstCaps of this pad.
2241 gst_pad_get_caps (GstPad * pad)
2243 GstCaps *result = gst_pad_get_caps_reffed (pad);
2245 /* be sure that we have a copy */
2246 if (G_LIKELY (result))
2247 result = gst_caps_make_writable (result);
2252 /* FIXME-0.11: what about making this the default and using
2253 * gst_caps_make_writable() explicitely where needed
2256 * gst_pad_peer_get_caps_reffed:
2257 * @pad: a #GstPad to get the capabilities of.
2259 * Gets the capabilities of the peer connected to this pad. Preferred function
2260 * if one only wants to read or intersect the caps.
2262 * Returns: the caps of the pad with incremented ref-count.
2267 gst_pad_peer_get_caps_reffed (GstPad * pad)
2270 GstCaps *result = NULL;
2272 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2274 GST_OBJECT_LOCK (pad);
2276 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2278 peerpad = GST_PAD_PEER (pad);
2279 if (G_UNLIKELY (peerpad == NULL))
2282 gst_object_ref (peerpad);
2283 GST_OBJECT_UNLOCK (pad);
2285 result = gst_pad_get_caps_reffed (peerpad);
2287 gst_object_unref (peerpad);
2293 GST_OBJECT_UNLOCK (pad);
2299 * gst_pad_peer_get_caps:
2300 * @pad: a #GstPad to get the peer capabilities of.
2302 * Gets the capabilities of the peer connected to this pad. Similar to
2303 * gst_pad_get_caps().
2305 * Returns: a newly allocated copy of the #GstCaps of the peer pad. Use
2306 * gst_caps_unref() to get rid of it. This function returns %NULL if there is
2310 gst_pad_peer_get_caps (GstPad * pad)
2313 GstCaps *result = NULL;
2315 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2317 GST_OBJECT_LOCK (pad);
2319 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2321 peerpad = GST_PAD_PEER (pad);
2322 if (G_UNLIKELY (peerpad == NULL))
2325 gst_object_ref (peerpad);
2326 GST_OBJECT_UNLOCK (pad);
2328 result = gst_pad_get_caps (peerpad);
2330 gst_object_unref (peerpad);
2336 GST_OBJECT_UNLOCK (pad);
2342 fixate_value (GValue * dest, const GValue * src)
2344 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
2345 g_value_init (dest, G_TYPE_INT);
2346 g_value_set_int (dest, gst_value_get_int_range_min (src));
2347 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
2348 g_value_init (dest, G_TYPE_DOUBLE);
2349 g_value_set_double (dest, gst_value_get_double_range_min (src));
2350 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
2351 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
2352 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
2353 GValue temp = { 0 };
2355 /* list could be empty */
2356 if (gst_value_list_get_size (src) <= 0)
2359 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
2361 if (!fixate_value (dest, &temp))
2362 gst_value_init_and_copy (dest, &temp);
2363 g_value_unset (&temp);
2364 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
2365 gboolean res = FALSE;
2368 len = gst_value_array_get_size (src);
2369 g_value_init (dest, GST_TYPE_ARRAY);
2370 for (n = 0; n < len; n++) {
2372 const GValue *orig_kid = gst_value_array_get_value (src, n);
2374 if (!fixate_value (&kid, orig_kid))
2375 gst_value_init_and_copy (&kid, orig_kid);
2378 gst_value_array_append_value (dest, &kid);
2379 g_value_unset (&kid);
2383 g_value_unset (dest);
2394 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
2396 GstStructure *s = data;
2399 if (fixate_value (&v, value)) {
2400 gst_structure_id_set_value (s, field_id, &v);
2408 * gst_pad_fixate_caps:
2409 * @pad: a #GstPad to fixate
2410 * @caps: the #GstCaps to fixate
2412 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2413 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2416 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2418 GstPadFixateCapsFunction fixatefunc;
2421 g_return_if_fail (GST_IS_PAD (pad));
2422 g_return_if_fail (caps != NULL);
2423 g_return_if_fail (!gst_caps_is_empty (caps));
2425 if (gst_caps_is_fixed (caps))
2428 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
2430 fixatefunc (pad, caps);
2433 /* default fixation */
2434 len = gst_caps_get_size (caps);
2436 GstStructure *s = gst_caps_get_structure (caps, 0);
2438 gst_structure_foreach (s, gst_pad_default_fixate, s);
2442 gst_caps_truncate (caps);
2446 /* Default accept caps implementation just checks against
2447 * against the allowed caps for the pad */
2449 gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
2451 /* get the caps and see if it intersects to something not empty */
2453 gboolean result = FALSE;
2455 GST_DEBUG_OBJECT (pad, "caps %" GST_PTR_FORMAT, caps);
2457 allowed = gst_pad_get_caps_reffed (pad);
2459 goto nothing_allowed;
2461 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2463 result = gst_caps_can_intersect (allowed, caps);
2465 gst_caps_unref (allowed);
2472 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2478 * gst_pad_accept_caps:
2479 * @pad: a #GstPad to check
2480 * @caps: a #GstCaps to check on the pad
2482 * Check if the given pad accepts the caps.
2484 * Returns: TRUE if the pad can accept the caps.
2487 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2490 GstPadAcceptCapsFunction acceptfunc;
2491 GstCaps *existing = NULL;
2493 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2495 /* any pad can be unnegotiated */
2499 /* lock for checking the existing caps */
2500 GST_OBJECT_LOCK (pad);
2501 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "accept caps of %p", caps);
2502 /* The current caps on a pad are trivially acceptable */
2503 if (G_LIKELY ((existing = GST_PAD_CAPS (pad)))) {
2504 if (caps == existing || gst_caps_is_equal (caps, existing))
2507 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2508 GST_OBJECT_UNLOCK (pad);
2510 if (G_LIKELY (acceptfunc)) {
2511 /* we can call the function */
2512 result = acceptfunc (pad, caps);
2513 GST_DEBUG_OBJECT (pad, "acceptfunc returned %d", result);
2515 /* Only null if the element explicitly unset it */
2516 result = gst_pad_acceptcaps_default (pad, caps);
2517 GST_DEBUG_OBJECT (pad, "default acceptcaps returned %d", result);
2523 GST_DEBUG_OBJECT (pad, "pad had same caps");
2524 GST_OBJECT_UNLOCK (pad);
2530 * gst_pad_peer_accept_caps:
2531 * @pad: a #GstPad to check the peer of
2532 * @caps: a #GstCaps to check on the pad
2534 * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
2537 * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
2540 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2545 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2547 GST_OBJECT_LOCK (pad);
2549 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "peer accept caps of (%p)", pad);
2551 peerpad = GST_PAD_PEER (pad);
2552 if (G_UNLIKELY (peerpad == NULL))
2555 gst_object_ref (peerpad);
2556 /* release lock before calling external methods but keep ref to pad */
2557 GST_OBJECT_UNLOCK (pad);
2559 result = gst_pad_accept_caps (peerpad, caps);
2561 gst_object_unref (peerpad);
2567 GST_OBJECT_UNLOCK (pad);
2574 * @pad: a #GstPad to set the capabilities of.
2575 * @caps: a #GstCaps to set.
2577 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2578 * caps on the pad will be unreffed. This function refs the caps so you should
2579 * unref if as soon as you don't need it anymore.
2580 * It is possible to set NULL caps, which will make the pad unnegotiated
2583 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2584 * or bad parameters were provided to this function.
2589 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2591 GstPadSetCapsFunction setcaps;
2594 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2595 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2597 GST_OBJECT_LOCK (pad);
2598 existing = GST_PAD_CAPS (pad);
2599 if (existing == caps)
2602 if (gst_caps_is_equal (caps, existing))
2603 goto setting_same_caps;
2605 setcaps = GST_PAD_SETCAPSFUNC (pad);
2607 /* call setcaps function to configure the pad only if the
2608 * caps is not NULL */
2609 if (setcaps != NULL && caps) {
2610 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2611 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2612 GST_OBJECT_UNLOCK (pad);
2613 if (!setcaps (pad, caps))
2615 GST_OBJECT_LOCK (pad);
2616 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2618 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad was dispatching");
2622 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2623 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "caps %p %" GST_PTR_FORMAT, caps,
2625 GST_OBJECT_UNLOCK (pad);
2627 g_object_notify (G_OBJECT (pad), "caps");
2633 GST_OBJECT_UNLOCK (pad);
2638 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2639 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2640 "caps %p %" GST_PTR_FORMAT " same as existing, updating ptr only", caps,
2642 GST_OBJECT_UNLOCK (pad);
2649 GST_OBJECT_LOCK (pad);
2650 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2651 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2652 "caps %" GST_PTR_FORMAT " could not be set", caps);
2653 GST_OBJECT_UNLOCK (pad);
2660 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2664 /* See if pad accepts the caps */
2665 if (!gst_pad_accept_caps (pad, caps))
2668 /* set caps on pad if call succeeds */
2669 res = gst_pad_set_caps (pad, caps);
2670 /* no need to unref the caps here, set_caps takes a ref and
2671 * our ref goes away when we leave this function. */
2677 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2678 "caps %" GST_PTR_FORMAT " not accepted", caps);
2683 /* returns TRUE if the src pad could be configured to accept the given caps */
2685 gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
2690 /* See if pad accepts the caps */
2691 if (!gst_pad_accept_caps (pad, caps))
2694 res = gst_pad_set_caps (pad, caps);
2702 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2703 "caps %" GST_PTR_FORMAT " not accepted", caps);
2709 * gst_pad_get_pad_template_caps:
2710 * @pad: a #GstPad to get the template capabilities from.
2712 * Gets the capabilities for @pad's template.
2714 * Returns: the #GstCaps of this pad template. If you intend to keep a
2715 * reference on the caps, make a copy (see gst_caps_copy ()).
2718 gst_pad_get_pad_template_caps (GstPad * pad)
2720 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2722 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2724 if (GST_PAD_PAD_TEMPLATE (pad))
2725 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2727 return gst_static_caps_get (&anycaps);
2732 * @pad: a #GstPad to get the peer of.
2734 * Gets the peer of @pad. This function refs the peer pad so
2735 * you need to unref it after use.
2737 * Returns: the peer #GstPad. Unref after usage.
2742 gst_pad_get_peer (GstPad * pad)
2746 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2748 GST_OBJECT_LOCK (pad);
2749 result = GST_PAD_PEER (pad);
2751 gst_object_ref (result);
2752 GST_OBJECT_UNLOCK (pad);
2758 * gst_pad_get_allowed_caps:
2761 * Gets the capabilities of the allowed media types that can flow through
2762 * @pad and its peer.
2764 * The allowed capabilities is calculated as the intersection of the results of
2765 * calling gst_pad_get_caps() on @pad and its peer. The caller owns a reference
2766 * on the resulting caps.
2768 * Returns: the allowed #GstCaps of the pad link. Unref the caps when you no
2769 * longer need it. This function returns NULL when @pad has no peer.
2774 gst_pad_get_allowed_caps (GstPad * pad)
2781 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2783 GST_OBJECT_LOCK (pad);
2785 peer = GST_PAD_PEER (pad);
2786 if (G_UNLIKELY (peer == NULL))
2789 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2791 gst_object_ref (peer);
2792 GST_OBJECT_UNLOCK (pad);
2793 mycaps = gst_pad_get_caps_reffed (pad);
2795 peercaps = gst_pad_get_caps_reffed (peer);
2796 gst_object_unref (peer);
2798 caps = gst_caps_intersect (mycaps, peercaps);
2799 gst_caps_unref (peercaps);
2800 gst_caps_unref (mycaps);
2802 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2809 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2810 GST_OBJECT_UNLOCK (pad);
2817 * gst_pad_get_negotiated_caps:
2820 * Gets the capabilities of the media type that currently flows through @pad
2823 * This function can be used on both src and sinkpads. Note that srcpads are
2824 * always negotiated before sinkpads so it is possible that the negotiated caps
2825 * on the srcpad do not match the negotiated caps of the peer.
2827 * Returns: the negotiated #GstCaps of the pad link. Unref the caps when
2828 * you no longer need it. This function returns NULL when the @pad has no
2829 * peer or is not negotiated yet.
2834 gst_pad_get_negotiated_caps (GstPad * pad)
2839 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2841 GST_OBJECT_LOCK (pad);
2843 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2846 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting negotiated caps");
2848 caps = GST_PAD_CAPS (pad);
2850 gst_caps_ref (caps);
2851 GST_OBJECT_UNLOCK (pad);
2853 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "negotiated caps %" GST_PTR_FORMAT,
2860 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2861 GST_OBJECT_UNLOCK (pad);
2867 /* calls the buffer_alloc function on the given pad */
2868 static GstFlowReturn
2869 gst_pad_buffer_alloc_unchecked (GstPad * pad, guint64 offset, gint size,
2870 GstCaps * caps, GstBuffer ** buf)
2873 GstPadBufferAllocFunction bufferallocfunc;
2875 GST_OBJECT_LOCK (pad);
2876 /* when the pad is flushing we cannot give a buffer */
2877 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2880 bufferallocfunc = pad->bufferallocfunc;
2882 if (offset == GST_BUFFER_OFFSET_NONE) {
2883 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2884 "calling bufferallocfunc &%s (@%p) for size %d offset NONE",
2885 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc), bufferallocfunc, size);
2887 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2888 "calling bufferallocfunc &%s (@%p) of for size %d offset %"
2889 G_GUINT64_FORMAT, GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2890 bufferallocfunc, size, offset);
2892 GST_OBJECT_UNLOCK (pad);
2894 /* G_LIKELY for now since most elements don't implement a buffer alloc
2895 * function and there is no default alloc proxy function as this is usually
2897 if (G_LIKELY (bufferallocfunc == NULL))
2900 ret = bufferallocfunc (pad, offset, size, caps, buf);
2902 if (G_UNLIKELY (ret != GST_FLOW_OK))
2905 /* no error, but NULL buffer means fallback to the default */
2906 if (G_UNLIKELY (*buf == NULL))
2909 /* If the buffer alloc function didn't set up the caps like it should,
2911 if (G_UNLIKELY (caps && (GST_BUFFER_CAPS (*buf) == NULL))) {
2912 GST_WARNING_OBJECT (pad,
2913 "Buffer allocation function did not set caps. Setting");
2914 gst_buffer_set_caps (*buf, caps);
2920 /* pad was flushing */
2921 GST_OBJECT_UNLOCK (pad);
2922 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "pad was flushing");
2923 return GST_FLOW_WRONG_STATE;
2927 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2928 "alloc function returned error (%d) %s", ret, gst_flow_get_name (ret));
2933 /* fallback case, allocate a buffer of our own, add pad caps. */
2934 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fallback buffer alloc");
2936 if ((*buf = gst_buffer_try_new_and_alloc (size))) {
2937 GST_BUFFER_OFFSET (*buf) = offset;
2938 gst_buffer_set_caps (*buf, caps);
2941 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2942 "out of memory allocating %d bytes", size);
2943 return GST_FLOW_ERROR;
2948 /* FIXME 0.11: size should be unsigned */
2949 static GstFlowReturn
2950 gst_pad_alloc_buffer_full (GstPad * pad, guint64 offset, gint size,
2951 GstCaps * caps, GstBuffer ** buf, gboolean setcaps)
2956 gboolean caps_changed;
2958 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2959 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2960 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2961 g_return_val_if_fail (size >= 0, GST_FLOW_ERROR);
2963 GST_DEBUG_OBJECT (pad, "offset %" G_GUINT64_FORMAT ", size %d, caps %"
2964 GST_PTR_FORMAT, offset, size, caps);
2966 GST_OBJECT_LOCK (pad);
2967 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2968 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
2971 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2974 gst_object_ref (peer);
2975 GST_OBJECT_UNLOCK (pad);
2977 ret = gst_pad_buffer_alloc_unchecked (peer, offset, size, caps, buf);
2978 gst_object_unref (peer);
2980 if (G_UNLIKELY (ret != GST_FLOW_OK))
2983 /* FIXME, move capnego this into a base class? */
2984 newcaps = GST_BUFFER_CAPS (*buf);
2986 /* Lock for checking caps, pretty pointless as the _pad_push() function might
2987 * change it concurrently, one of the problems with automatic caps setting in
2988 * pad_alloc_and_set_caps. Worst case, if does a check too much, but only
2989 * when there is heavy renegotiation going on in both directions. */
2990 GST_OBJECT_LOCK (pad);
2991 caps_changed = newcaps && newcaps != GST_PAD_CAPS (pad);
2992 GST_OBJECT_UNLOCK (pad);
2994 /* we got a new datatype on the pad, see if it can handle it */
2995 if (G_UNLIKELY (caps_changed)) {
2996 GST_DEBUG_OBJECT (pad,
2997 "caps changed from %" GST_PTR_FORMAT " to %p %" GST_PTR_FORMAT,
2998 GST_PAD_CAPS (pad), newcaps, newcaps);
2999 if (G_UNLIKELY (!gst_pad_configure_src (pad, newcaps, setcaps)))
3000 goto not_negotiated;
3003 /* sanity check (only if caps are the same) */
3004 if (G_LIKELY (newcaps == caps) && G_UNLIKELY (GST_BUFFER_SIZE (*buf) < size))
3005 goto wrong_size_fallback;
3011 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "pad block stopped by flush");
3012 GST_OBJECT_UNLOCK (pad);
3017 /* pad has no peer */
3018 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3019 "called bufferallocfunc but had no peer");
3020 GST_OBJECT_UNLOCK (pad);
3021 return GST_FLOW_NOT_LINKED;
3025 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3026 "alloc function returned error %s", gst_flow_get_name (ret));
3031 gst_buffer_unref (*buf);
3033 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3034 "alloc function returned unacceptable buffer");
3035 return GST_FLOW_NOT_NEGOTIATED;
3037 wrong_size_fallback:
3039 GST_CAT_ERROR_OBJECT (GST_CAT_PADS, pad, "buffer returned by alloc "
3040 "function is too small (%u < %d), doing fallback buffer alloc",
3041 GST_BUFFER_SIZE (*buf), size);
3043 gst_buffer_unref (*buf);
3045 if ((*buf = gst_buffer_try_new_and_alloc (size))) {
3046 GST_BUFFER_OFFSET (*buf) = offset;
3047 gst_buffer_set_caps (*buf, caps);
3050 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3051 "out of memory allocating %d bytes", size);
3052 return GST_FLOW_ERROR;
3058 * gst_pad_alloc_buffer:
3059 * @pad: a source #GstPad
3060 * @offset: the offset of the new buffer in the stream
3061 * @size: the size of the new buffer
3062 * @caps: the caps of the new buffer
3063 * @buf: a newly allocated buffer
3065 * Allocates a new, empty buffer optimized to push to pad @pad. This
3066 * function only works if @pad is a source pad and has a peer.
3068 * A new, empty #GstBuffer will be put in the @buf argument.
3069 * You need to check the caps of the buffer after performing this
3070 * function and renegotiate to the format if needed. If the caps changed, it is
3071 * possible that the buffer returned in @buf is not of the right size for the
3072 * new format, @buf needs to be unreffed and reallocated if this is the case.
3074 * Returns: a result code indicating success of the operation. Any
3075 * result code other than #GST_FLOW_OK is an error and @buf should
3077 * An error can occur if the pad is not connected or when the downstream
3078 * peer elements cannot provide an acceptable buffer.
3083 /* FIXME 0.11: size should be unsigned */
3085 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
3088 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, FALSE);
3092 * gst_pad_alloc_buffer_and_set_caps:
3093 * @pad: a source #GstPad
3094 * @offset: the offset of the new buffer in the stream
3095 * @size: the size of the new buffer
3096 * @caps: the caps of the new buffer
3097 * @buf: a newly allocated buffer
3099 * In addition to the function gst_pad_alloc_buffer(), this function
3100 * automatically calls gst_pad_set_caps() when the caps of the
3101 * newly allocated buffer are different from the @pad caps.
3103 * After a renegotiation, the size of the new buffer returned in @buf could
3104 * be of the wrong size for the new format and must be unreffed an reallocated
3107 * Returns: a result code indicating success of the operation. Any
3108 * result code other than #GST_FLOW_OK is an error and @buf should
3110 * An error can occur if the pad is not connected or when the downstream
3111 * peer elements cannot provide an acceptable buffer.
3116 /* FIXME 0.11: size should be unsigned */
3118 gst_pad_alloc_buffer_and_set_caps (GstPad * pad, guint64 offset, gint size,
3119 GstCaps * caps, GstBuffer ** buf)
3121 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, TRUE);
3125 #ifndef GST_REMOVE_DEPRECATED
3133 int_link_iter_data_free (IntLinkIterData * data)
3135 g_list_free (data->list);
3136 g_slice_free (IntLinkIterData, data);
3140 static GstIteratorItem
3141 iterate_pad (GstIterator * it, GstPad * pad)
3143 gst_object_ref (pad);
3144 return GST_ITERATOR_ITEM_PASS;
3148 * gst_pad_iterate_internal_links_default:
3149 * @pad: the #GstPad to get the internal links of.
3151 * Iterate the list of pads to which the given pad is linked to inside of
3152 * the parent element.
3153 * This is the default handler, and thus returns an iterator of all of the
3154 * pads inside the parent element with opposite direction.
3156 * The caller must free this iterator after use with gst_iterator_free().
3158 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
3159 * returned pad with gst_object_unref().
3164 gst_pad_iterate_internal_links_default (GstPad * pad)
3171 GstIteratorDisposeFunction dispose;
3173 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3175 #ifndef GST_REMOVE_DEPRECATED
3176 /* when we get here, the default handler for the iterate links is called,
3177 * which means that the user has not installed a custom one. We first check if
3178 * there is maybe a custom legacy function we can call. */
3179 if (GST_PAD_INTLINKFUNC (pad) &&
3180 GST_PAD_INTLINKFUNC (pad) != gst_pad_get_internal_links_default) {
3181 IntLinkIterData *data;
3183 /* make an iterator for the list. We can't protect the list with a
3184 * cookie. If we would take the cookie of the parent element, we need to
3185 * have a parent, which is not required for GST_PAD_INTLINKFUNC(). We could
3186 * cache the per-pad list and invalidate the list when a new call to
3187 * INTLINKFUNC() returned a different list but then this would only work if
3188 * two concurrent iterators were used and the last iterator would still be
3189 * thread-unsafe. Just don't use this method anymore. */
3190 data = g_slice_new (IntLinkIterData);
3191 data->list = GST_PAD_INTLINKFUNC (pad) (pad);
3194 GST_WARNING_OBJECT (pad, "Making unsafe iterator");
3196 cookie = &data->cookie;
3197 padlist = &data->list;
3199 dispose = (GstIteratorDisposeFunction) int_link_iter_data_free;
3200 /* reuse the pad lock, it's all we have here */
3201 lock = GST_OBJECT_GET_LOCK (pad);
3207 GST_OBJECT_LOCK (pad);
3208 parent = GST_PAD_PARENT (pad);
3209 if (!parent || !GST_IS_ELEMENT (parent))
3212 gst_object_ref (parent);
3213 GST_OBJECT_UNLOCK (pad);
3215 if (pad->direction == GST_PAD_SRC)
3216 padlist = &parent->sinkpads;
3218 padlist = &parent->srcpads;
3220 GST_DEBUG_OBJECT (pad, "Making iterator");
3222 cookie = &parent->pads_cookie;
3224 dispose = (GstIteratorDisposeFunction) gst_object_unref;
3225 lock = GST_OBJECT_GET_LOCK (parent);
3228 res = gst_iterator_new_list (GST_TYPE_PAD,
3229 lock, cookie, padlist, owner, (GstIteratorItemFunction) iterate_pad,
3237 GST_OBJECT_UNLOCK (pad);
3238 GST_DEBUG_OBJECT (pad, "no parent element");
3244 * gst_pad_iterate_internal_links:
3245 * @pad: the GstPad to get the internal links of.
3247 * Gets an iterator for the pads to which the given pad is linked to inside
3248 * of the parent element.
3250 * Each #GstPad element yielded by the iterator will have its refcount increased,
3251 * so unref after use.
3253 * Returns: a new #GstIterator of #GstPad or %NULL when the pad does not have an
3254 * iterator function configured. Use gst_iterator_free() after usage.
3259 gst_pad_iterate_internal_links (GstPad * pad)
3261 GstIterator *res = NULL;
3263 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3265 if (GST_PAD_ITERINTLINKFUNC (pad))
3266 res = GST_PAD_ITERINTLINKFUNC (pad) (pad);
3271 #ifndef GST_REMOVE_DEPRECATED
3273 add_unref_pad_to_list (GstPad * pad, GList * list)
3275 list = g_list_prepend (list, pad);
3276 gst_object_unref (pad);
3281 * gst_pad_get_internal_links_default:
3282 * @pad: the #GstPad to get the internal links of.
3284 * Gets a list of pads to which the given pad is linked to
3285 * inside of the parent element.
3286 * This is the default handler, and thus returns a list of all of the
3287 * pads inside the parent element with opposite direction.
3289 * The caller must free this list after use with g_list_free().
3291 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
3295 * Deprecated: This function does not ref the pads in the list so that they
3296 * could become invalid by the time the application accesses them. It's also
3297 * possible that the list changes while handling the pads, which the caller of
3298 * this function is unable to know. Use the thread-safe
3299 * gst_pad_iterate_internal_links_default() instead.
3301 #ifndef GST_REMOVE_DEPRECATED
3303 gst_pad_get_internal_links_default (GstPad * pad)
3308 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3310 GST_WARNING_OBJECT (pad, "Unsafe internal links used");
3312 /* when we get here, the default handler for get_internal_links is called,
3313 * which means that the user has not installed a custom one. We first check if
3314 * there is maybe a custom iterate function we can call. */
3315 if (GST_PAD_ITERINTLINKFUNC (pad) &&
3316 GST_PAD_ITERINTLINKFUNC (pad) != gst_pad_iterate_internal_links_default) {
3318 GstIteratorResult ires;
3319 gboolean done = FALSE;
3321 it = gst_pad_iterate_internal_links (pad);
3322 /* loop over the iterator and put all elements into a list, we also
3323 * immediatly unref them, which is bad. */
3325 ires = gst_iterator_foreach (it, (GFunc) add_unref_pad_to_list, res);
3327 case GST_ITERATOR_OK:
3328 case GST_ITERATOR_DONE:
3329 case GST_ITERATOR_ERROR:
3332 case GST_ITERATOR_RESYNC:
3333 /* restart, discard previous list */
3334 gst_iterator_resync (it);
3341 gst_iterator_free (it);
3343 /* lock pad, check and ref parent */
3344 GST_OBJECT_LOCK (pad);
3345 parent = GST_PAD_PARENT (pad);
3346 if (!parent || !GST_IS_ELEMENT (parent))
3349 parent = gst_object_ref (parent);
3350 GST_OBJECT_UNLOCK (pad);
3352 /* now lock the parent while we copy the pads */
3353 GST_OBJECT_LOCK (parent);
3354 if (pad->direction == GST_PAD_SRC)
3355 res = g_list_copy (parent->sinkpads);
3357 res = g_list_copy (parent->srcpads);
3358 GST_OBJECT_UNLOCK (parent);
3360 gst_object_unref (parent);
3363 /* At this point pads can be changed and unreffed. Nothing we can do about it
3364 * because for compatibility reasons this function cannot ref the pads or
3365 * notify the app that the list changed. */
3371 GST_DEBUG_OBJECT (pad, "no parent");
3372 GST_OBJECT_UNLOCK (pad);
3376 #endif /* GST_REMOVE_DEPRECATED */
3379 * gst_pad_get_internal_links:
3380 * @pad: the #GstPad to get the internal links of.
3382 * Gets a list of pads to which the given pad is linked to
3383 * inside of the parent element.
3384 * The caller must free this list after use.
3388 * Returns: a newly allocated #GList of pads, free with g_list_free().
3390 * Deprecated: This function does not ref the pads in the list so that they
3391 * could become invalid by the time the application accesses them. It's also
3392 * possible that the list changes while handling the pads, which the caller of
3393 * this function is unable to know. Use the thread-safe
3394 * gst_pad_iterate_internal_links() instead.
3396 #ifndef GST_REMOVE_DEPRECATED
3397 #ifdef GST_DISABLE_DEPRECATED
3398 GList *gst_pad_get_internal_links (GstPad * pad);
3401 gst_pad_get_internal_links (GstPad * pad)
3405 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3407 GST_WARNING_OBJECT (pad, "Calling unsafe internal links");
3409 if (GST_PAD_INTLINKFUNC (pad))
3410 res = GST_PAD_INTLINKFUNC (pad) (pad);
3414 #endif /* GST_REMOVE_DEPRECATED */
3417 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
3419 gboolean result = FALSE;
3421 gboolean done = FALSE;
3424 GList *pushed_pads = NULL;
3426 GST_INFO_OBJECT (pad, "Sending event %p (%s) to all internally linked pads",
3427 event, GST_EVENT_TYPE_NAME (event));
3429 iter = gst_pad_iterate_internal_links (pad);
3435 switch (gst_iterator_next (iter, &item)) {
3436 case GST_ITERATOR_OK:
3437 eventpad = GST_PAD_CAST (item);
3439 /* if already pushed, skip */
3440 if (g_list_find (pushed_pads, eventpad)) {
3441 gst_object_unref (item);
3445 if (GST_PAD_IS_SRC (eventpad)) {
3446 /* for each pad we send to, we should ref the event; it's up
3447 * to downstream to unref again when handled. */
3448 GST_LOG_OBJECT (pad, "Reffing and sending event %p (%s) to %s:%s",
3449 event, GST_EVENT_TYPE_NAME (event),
3450 GST_DEBUG_PAD_NAME (eventpad));
3451 gst_event_ref (event);
3452 result |= gst_pad_push_event (eventpad, event);
3454 /* we only send the event on one pad, multi-sinkpad elements
3455 * should implement a handler */
3456 GST_LOG_OBJECT (pad, "sending event %p (%s) to one sink pad %s:%s",
3457 event, GST_EVENT_TYPE_NAME (event),
3458 GST_DEBUG_PAD_NAME (eventpad));
3459 result = gst_pad_push_event (eventpad, event);
3464 pushed_pads = g_list_prepend (pushed_pads, eventpad);
3466 gst_object_unref (item);
3468 case GST_ITERATOR_RESYNC:
3469 /* FIXME, if we want to reset the result value we need to remember which
3470 * pads pushed with which result */
3471 gst_iterator_resync (iter);
3473 case GST_ITERATOR_ERROR:
3474 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3477 case GST_ITERATOR_DONE:
3482 gst_iterator_free (iter);
3486 /* If this is a sinkpad and we don't have pads to send the event to, we
3487 * return TRUE. This is so that when using the default handler on a sink
3488 * element, we don't fail to push it. */
3490 result = GST_PAD_IS_SINK (pad);
3492 g_list_free (pushed_pads);
3494 /* we handled the incoming event so we unref once */
3496 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
3497 gst_event_unref (event);
3504 * gst_pad_event_default:
3505 * @pad: a #GstPad to call the default event handler on.
3506 * @event: the #GstEvent to handle.
3508 * Invokes the default event handler for the given pad. End-of-stream and
3509 * discontinuity events are handled specially, and then the event is sent to all
3510 * pads internally linked to @pad. Note that if there are many possible sink
3511 * pads that are internally linked to @pad, only one will be sent an event.
3512 * Multi-sinkpad elements should implement custom event handlers.
3514 * Returns: TRUE if the event was sent succesfully.
3517 gst_pad_event_default (GstPad * pad, GstEvent * event)
3519 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3520 g_return_val_if_fail (event != NULL, FALSE);
3522 GST_LOG_OBJECT (pad, "default event handler");
3524 switch (GST_EVENT_TYPE (event)) {
3527 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
3528 gst_pad_pause_task (pad);
3535 return gst_pad_event_default_dispatch (pad, event);
3539 * gst_pad_dispatcher:
3540 * @pad: a #GstPad to dispatch.
3541 * @dispatch: the #GstPadDispatcherFunction to call.
3542 * @data: gpointer user data passed to the dispatcher function.
3544 * Invokes the given dispatcher function on each respective peer of
3545 * all pads that are internally linked to the given pad.
3546 * The GstPadDispatcherFunction should return TRUE when no further pads
3547 * need to be processed.
3549 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3552 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
3555 gboolean res = FALSE;
3556 GstIterator *iter = NULL;
3557 gboolean done = FALSE;
3560 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3561 g_return_val_if_fail (dispatch != NULL, FALSE);
3563 iter = gst_pad_iterate_internal_links (pad);
3569 switch (gst_iterator_next (iter, &item)) {
3570 case GST_ITERATOR_OK:
3572 GstPad *int_pad = GST_PAD_CAST (item);
3573 GstPad *int_peer = gst_pad_get_peer (int_pad);
3576 GST_DEBUG_OBJECT (int_pad, "dispatching to peer %s:%s",
3577 GST_DEBUG_PAD_NAME (int_peer));
3578 done = res = dispatch (int_peer, data);
3579 gst_object_unref (int_peer);
3581 GST_DEBUG_OBJECT (int_pad, "no peer");
3584 gst_object_unref (item);
3586 case GST_ITERATOR_RESYNC:
3587 gst_iterator_resync (iter);
3589 case GST_ITERATOR_ERROR:
3591 GST_ERROR_OBJECT (pad, "Could not iterate internally linked pads");
3593 case GST_ITERATOR_DONE:
3598 gst_iterator_free (iter);
3600 GST_DEBUG_OBJECT (pad, "done, result %d", res);
3609 * @pad: a #GstPad to invoke the default query on.
3610 * @query: the #GstQuery to perform.
3612 * Dispatches a query to a pad. The query should have been allocated by the
3613 * caller via one of the type-specific allocation functions in gstquery.h. The
3614 * element is responsible for filling the query with an appropriate response,
3615 * which should then be parsed with a type-specific query parsing function.
3617 * Again, the caller is responsible for both the allocation and deallocation of
3618 * the query structure.
3620 * Returns: TRUE if the query could be performed.
3623 gst_pad_query (GstPad * pad, GstQuery * query)
3625 GstPadQueryFunction func;
3627 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3628 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3630 GST_DEBUG_OBJECT (pad, "sending query %p", query);
3632 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3635 return func (pad, query);
3639 GST_DEBUG_OBJECT (pad, "had no query function");
3645 * gst_pad_peer_query:
3646 * @pad: a #GstPad to invoke the peer query on.
3647 * @query: the #GstQuery to perform.
3649 * Performs gst_pad_query() on the peer of @pad.
3651 * The caller is responsible for both the allocation and deallocation of
3652 * the query structure.
3654 * Returns: TRUE if the query could be performed. This function returns %FALSE
3655 * if @pad has no peer.
3660 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3665 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3666 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3668 GST_OBJECT_LOCK (pad);
3670 GST_DEBUG_OBJECT (pad, "peer query");
3672 peerpad = GST_PAD_PEER (pad);
3673 if (G_UNLIKELY (peerpad == NULL))
3676 gst_object_ref (peerpad);
3677 GST_OBJECT_UNLOCK (pad);
3679 result = gst_pad_query (peerpad, query);
3681 gst_object_unref (peerpad);
3688 GST_WARNING_OBJECT (pad, "pad has no peer");
3689 GST_OBJECT_UNLOCK (pad);
3695 * gst_pad_query_default:
3696 * @pad: a #GstPad to call the default query handler on.
3697 * @query: the #GstQuery to handle.
3699 * Invokes the default query handler for the given pad.
3700 * The query is sent to all pads internally linked to @pad. Note that
3701 * if there are many possible sink pads that are internally linked to
3702 * @pad, only one will be sent the query.
3703 * Multi-sinkpad elements should implement custom query handlers.
3705 * Returns: TRUE if the query was performed succesfully.
3708 gst_pad_query_default (GstPad * pad, GstQuery * query)
3710 switch (GST_QUERY_TYPE (query)) {
3711 case GST_QUERY_POSITION:
3712 case GST_QUERY_SEEKING:
3713 case GST_QUERY_FORMATS:
3714 case GST_QUERY_LATENCY:
3715 case GST_QUERY_JITTER:
3716 case GST_QUERY_RATE:
3717 case GST_QUERY_CONVERT:
3719 return gst_pad_dispatcher
3720 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
3724 #ifndef GST_DISABLE_LOADSAVE
3725 /* FIXME: why isn't this on a GstElement ? */
3727 * gst_pad_load_and_link:
3728 * @self: an #xmlNodePtr to read the description from.
3729 * @parent: the #GstObject element that owns the pad.
3731 * Reads the pad definition from the XML node and links the given pad
3732 * in the element to a pad of an element up in the hierarchy.
3735 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
3737 xmlNodePtr field = self->xmlChildrenNode;
3738 GstPad *pad = NULL, *targetpad;
3739 GstPadTemplate *tmpl;
3743 GstObject *grandparent;
3747 if (!strcmp ((char *) field->name, "name")) {
3748 name = (gchar *) xmlNodeGetContent (field);
3749 pad = gst_element_get_static_pad (GST_ELEMENT (parent), name);
3750 if ((!pad) || ((tmpl = gst_pad_get_pad_template (pad))
3751 && (GST_PAD_REQUEST == GST_PAD_TEMPLATE_PRESENCE (tmpl))))
3752 pad = gst_element_get_request_pad (GST_ELEMENT (parent), name);
3754 } else if (!strcmp ((char *) field->name, "peer")) {
3755 peer = (gchar *) xmlNodeGetContent (field);
3757 field = field->next;
3759 g_return_if_fail (pad != NULL);
3764 split = g_strsplit (peer, ".", 2);
3766 if (split[0] == NULL || split[1] == NULL) {
3767 GST_CAT_DEBUG_OBJECT (GST_CAT_XML, pad,
3768 "Could not parse peer '%s', leaving unlinked", peer);
3775 g_return_if_fail (split[0] != NULL);
3776 g_return_if_fail (split[1] != NULL);
3778 grandparent = gst_object_get_parent (parent);
3780 if (grandparent && GST_IS_BIN (grandparent)) {
3781 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
3788 targetpad = gst_element_get_static_pad (target, split[1]);
3790 targetpad = gst_element_get_request_pad (target, split[1]);
3792 if (targetpad == NULL)
3795 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
3796 gst_pad_link (pad, targetpad);
3798 gst_pad_link (targetpad, pad);
3805 * gst_pad_save_thyself:
3806 * @pad: a #GstPad to save.
3807 * @parent: the parent #xmlNodePtr to save the description in.
3809 * Saves the pad into an xml representation.
3811 * Returns: the #xmlNodePtr representation of the pad.
3814 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3819 g_return_val_if_fail (GST_IS_PAD (object), NULL);
3821 pad = GST_PAD_CAST (object);
3823 xmlNewChild (parent, NULL, (xmlChar *) "name",
3824 (xmlChar *) GST_PAD_NAME (pad));
3826 if (GST_PAD_IS_SRC (pad)) {
3827 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "source");
3828 } else if (GST_PAD_IS_SINK (pad)) {
3829 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "sink");
3831 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "unknown");
3834 if (GST_PAD_PEER (pad) != NULL) {
3837 peer = GST_PAD_PEER (pad);
3838 /* first check to see if the peer's parent's parent is the same */
3839 /* we just save it off */
3840 content = g_strdup_printf ("%s.%s",
3841 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3842 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
3845 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
3852 * gst_ghost_pad_save_thyself:
3853 * @pad: a ghost #GstPad to save.
3854 * @parent: the parent #xmlNodePtr to save the description in.
3856 * Saves the ghost pad into an xml representation.
3858 * Returns: the #xmlNodePtr representation of the pad.
3861 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3865 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3867 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
3868 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
3869 xmlNewChild (self, NULL, (xmlChar *) "parent",
3870 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3872 /* FIXME FIXME FIXME! */
3877 #endif /* GST_DISABLE_LOADSAVE */
3880 * should be called with pad OBJECT_LOCK and STREAM_LOCK held.
3881 * GST_PAD_IS_BLOCKED (pad) == TRUE when this function is
3884 * This function performs the pad blocking when an event, buffer push
3885 * or buffer_alloc is performed on a _SRC_ pad. It blocks the
3886 * streaming thread after informing the pad has been blocked.
3888 * An application can with this method wait and block any streaming
3889 * thread and perform operations such as seeking or linking.
3891 * Two methods are available for notifying the application of the
3893 * - the callback method, which happens in the STREAMING thread with
3894 * the STREAM_LOCK held. With this method, the most useful way of
3895 * dealing with the callback is to post a message to the main thread
3896 * where the pad block can then be handled outside of the streaming
3897 * thread. With the last method one can perform all operations such
3898 * as doing a state change, linking, unblocking, seeking etc on the
3900 * - the GCond signal method, which makes any thread unblock when
3901 * the pad block happens.
3903 * During the actual blocking state, the GST_PAD_BLOCKING flag is set.
3904 * The GST_PAD_BLOCKING flag is unset when the pad was unblocked.
3908 static GstFlowReturn
3909 handle_pad_block (GstPad * pad)
3911 GstPadBlockCallback callback;
3913 GstFlowReturn ret = GST_FLOW_OK;
3915 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "signal block taken");
3917 /* flushing, don't bother trying to block and return WRONG_STATE
3919 if (GST_PAD_IS_FLUSHING (pad))
3920 goto flushingnonref;
3922 /* we grab an extra ref for the callbacks, this is probably not
3923 * needed (callback code does not have a ref and cannot unref). I
3924 * think this was done to make it possible to unref the element in
3925 * the callback, which is in the end totally impossible as it
3926 * requires grabbing the STREAM_LOCK and OBJECT_LOCK which are
3927 * all taken when calling this function. */
3928 gst_object_ref (pad);
3930 while (GST_PAD_IS_BLOCKED (pad)) {
3932 /* we either have a callback installed to notify the block or
3933 * some other thread is doing a GCond wait. */
3934 callback = pad->block_callback;
3935 pad->abidata.ABI.block_callback_called = TRUE;
3937 /* there is a callback installed, call it. We release the
3938 * lock so that the callback can do something usefull with the
3940 user_data = pad->block_data;
3941 GST_OBJECT_UNLOCK (pad);
3942 callback (pad, TRUE, user_data);
3943 GST_OBJECT_LOCK (pad);
3945 /* we released the lock, recheck flushing */
3946 if (GST_PAD_IS_FLUSHING (pad))
3949 /* no callback, signal the thread that is doing a GCond wait
3951 GST_PAD_BLOCK_BROADCAST (pad);
3953 } while (pad->abidata.ABI.block_callback_called == FALSE
3954 && GST_PAD_IS_BLOCKED (pad));
3956 /* OBJECT_LOCK could have been released when we did the callback, which
3957 * then could have made the pad unblock so we need to check the blocking
3958 * condition again. */
3959 if (!GST_PAD_IS_BLOCKED (pad))
3962 /* now we block the streaming thread. It can be unlocked when we
3963 * deactivate the pad (which will also set the FLUSHING flag) or
3964 * when the pad is unblocked. A flushing event will also unblock
3965 * the pad after setting the FLUSHING flag. */
3966 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3967 "Waiting to be unblocked or set flushing");
3968 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKING);
3969 GST_PAD_BLOCK_WAIT (pad);
3970 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKING);
3972 /* see if we got unblocked by a flush or not */
3973 if (GST_PAD_IS_FLUSHING (pad))
3977 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
3979 /* when we get here, the pad is unblocked again and we perform
3980 * the needed unblock code. */
3981 callback = pad->block_callback;
3983 /* we need to call the callback */
3984 user_data = pad->block_data;
3985 GST_OBJECT_UNLOCK (pad);
3986 callback (pad, FALSE, user_data);
3987 GST_OBJECT_LOCK (pad);
3989 /* we need to signal the thread waiting on the GCond */
3990 GST_PAD_BLOCK_BROADCAST (pad);
3993 gst_object_unref (pad);
3999 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pad was flushing");
4000 return GST_FLOW_WRONG_STATE;
4004 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pad became flushing");
4005 gst_object_unref (pad);
4006 return GST_FLOW_WRONG_STATE;
4010 /**********************************************************************
4011 * Data passing functions
4015 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
4018 GValue args[2] = { {0}, {0} };
4023 g_value_init (&ret, G_TYPE_BOOLEAN);
4024 g_value_set_boolean (&ret, TRUE);
4025 g_value_init (&args[0], GST_TYPE_PAD);
4026 g_value_set_object (&args[0], pad);
4027 g_value_init (&args[1], GST_TYPE_MINI_OBJECT);
4028 gst_value_set_mini_object (&args[1], obj);
4030 if (GST_IS_EVENT (obj))
4031 detail = event_quark;
4033 detail = buffer_quark;
4036 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
4037 res = g_value_get_boolean (&ret);
4040 g_value_unset (&ret);
4041 g_value_unset (&args[0]);
4042 g_value_unset (&args[1]);
4048 gst_pad_data_unref (gboolean is_buffer, void *data)
4050 if (G_LIKELY (is_buffer)) {
4051 gst_buffer_unref (data);
4053 gst_buffer_list_unref (data);
4058 gst_pad_data_get_caps (gboolean is_buffer, void *data)
4062 if (G_LIKELY (is_buffer)) {
4063 caps = GST_BUFFER_CAPS (data);
4067 if ((buf = gst_buffer_list_get (GST_BUFFER_LIST_CAST (data), 0, 0)))
4068 caps = GST_BUFFER_CAPS (buf);
4075 /* this is the chain function that does not perform the additional argument
4076 * checking for that little extra speed.
4078 static inline GstFlowReturn
4079 gst_pad_chain_data_unchecked (GstPad * pad, gboolean is_buffer, void *data)
4082 gboolean caps_changed;
4084 gboolean emit_signal;
4086 GST_PAD_STREAM_LOCK (pad);
4088 GST_OBJECT_LOCK (pad);
4089 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4092 caps = gst_pad_data_get_caps (is_buffer, data);
4093 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4095 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4096 GST_OBJECT_UNLOCK (pad);
4098 /* see if the signal should be emited, we emit before caps nego as
4099 * we might drop the buffer and do capsnego for nothing. */
4100 if (G_UNLIKELY (emit_signal)) {
4101 if (G_LIKELY (is_buffer)) {
4102 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (data)))
4105 /* chain all groups in the buffer list one by one to avoid problems with
4106 * buffer probes that push buffers or events */
4111 /* we got a new datatype on the pad, see if it can handle it */
4112 if (G_UNLIKELY (caps_changed)) {
4113 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4114 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
4115 goto not_negotiated;
4118 /* NOTE: we read the chainfunc unlocked.
4119 * we cannot hold the lock for the pad so we might send
4120 * the data to the wrong function. This is not really a
4121 * problem since functions are assigned at creation time
4122 * and don't change that often... */
4123 if (G_LIKELY (is_buffer)) {
4124 GstPadChainFunction chainfunc;
4126 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4129 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4130 "calling chainfunction &%s", GST_DEBUG_FUNCPTR_NAME (chainfunc));
4132 ret = chainfunc (pad, GST_BUFFER_CAST (data));
4134 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4135 "called chainfunction &%s, returned %s",
4136 GST_DEBUG_FUNCPTR_NAME (chainfunc), gst_flow_get_name (ret));
4138 GstPadChainListFunction chainlistfunc;
4140 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4143 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4144 "calling chainlistfunction &%s",
4145 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4147 ret = chainlistfunc (pad, GST_BUFFER_LIST_CAST (data));
4149 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4150 "called chainlistfunction &%s, returned %s",
4151 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4154 GST_PAD_STREAM_UNLOCK (pad);
4160 GstBufferList *list;
4161 GstBufferListIterator *it;
4164 GST_PAD_STREAM_UNLOCK (pad);
4166 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
4168 list = GST_BUFFER_LIST_CAST (data);
4169 it = gst_buffer_list_iterate (list);
4171 if (gst_buffer_list_iterator_next_group (it)) {
4173 group = gst_buffer_list_iterator_merge_group (it);
4174 if (group == NULL) {
4175 group = gst_buffer_new ();
4176 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining empty group");
4178 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining group");
4180 ret = gst_pad_chain_data_unchecked (pad, TRUE, group);
4181 } while (ret == GST_FLOW_OK && gst_buffer_list_iterator_next_group (it));
4183 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining empty group");
4184 ret = gst_pad_chain_data_unchecked (pad, TRUE, gst_buffer_new ());
4187 gst_buffer_list_iterator_free (it);
4188 gst_buffer_list_unref (list);
4196 gst_pad_data_unref (is_buffer, data);
4197 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4198 "pushing, but pad was flushing");
4199 GST_OBJECT_UNLOCK (pad);
4200 GST_PAD_STREAM_UNLOCK (pad);
4201 return GST_FLOW_WRONG_STATE;
4205 gst_pad_data_unref (is_buffer, data);
4206 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
4207 GST_PAD_STREAM_UNLOCK (pad);
4212 gst_pad_data_unref (is_buffer, data);
4213 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4214 "pushing data but pad did not accept");
4215 GST_PAD_STREAM_UNLOCK (pad);
4216 return GST_FLOW_NOT_NEGOTIATED;
4220 gst_pad_data_unref (is_buffer, data);
4221 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4222 "pushing, but not chainhandler");
4223 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4224 ("push on pad %s:%s but it has no chainfunction",
4225 GST_DEBUG_PAD_NAME (pad)));
4226 GST_PAD_STREAM_UNLOCK (pad);
4227 return GST_FLOW_NOT_SUPPORTED;
4233 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4234 * @buffer: the #GstBuffer to send, return GST_FLOW_ERROR if not.
4236 * Chain a buffer to @pad.
4238 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
4240 * If the caps on @buffer are different from the current caps on @pad, this
4241 * function will call any setcaps function (see gst_pad_set_setcaps_function())
4242 * installed on @pad. If the new caps are not acceptable for @pad, this
4243 * function returns #GST_FLOW_NOT_NEGOTIATED.
4245 * The function proceeds calling the chain function installed on @pad (see
4246 * gst_pad_set_chain_function()) and the return value of that function is
4247 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4250 * In all cases, success or failure, the caller loses its reference to @buffer
4251 * after calling this function.
4253 * Returns: a #GstFlowReturn from the pad.
4258 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4260 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4261 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4262 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4264 return gst_pad_chain_data_unchecked (pad, TRUE, buffer);
4268 * gst_pad_chain_list:
4269 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4270 * @list: the #GstBufferList to send, return GST_FLOW_ERROR if not.
4272 * Chain a bufferlist to @pad.
4274 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
4276 * If the caps on the first buffer of @list are different from the current
4277 * caps on @pad, this function will call any setcaps function
4278 * (see gst_pad_set_setcaps_function()) installed on @pad. If the new caps
4279 * are not acceptable for @pad, this function returns #GST_FLOW_NOT_NEGOTIATED.
4281 * The function proceeds calling the chainlist function installed on @pad (see
4282 * gst_pad_set_chain_list_function()) and the return value of that function is
4283 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4284 * chainlist function.
4286 * In all cases, success or failure, the caller loses its reference to @list
4287 * after calling this function.
4291 * Returns: a #GstFlowReturn from the pad.
4296 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4298 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4299 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4300 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4302 return gst_pad_chain_data_unchecked (pad, FALSE, list);
4305 static GstFlowReturn
4306 gst_pad_push_data (GstPad * pad, gboolean is_buffer, void *data)
4311 gboolean caps_changed;
4313 GST_OBJECT_LOCK (pad);
4315 /* FIXME: this check can go away; pad_set_blocked could be implemented with
4316 * probes completely or probes with an extended pad block. */
4317 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
4318 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
4321 /* we emit signals on the pad arg, the peer will have a chance to
4322 * emit in the _chain() function */
4323 if (G_UNLIKELY (GST_PAD_DO_BUFFER_SIGNALS (pad) > 0)) {
4324 /* unlock before emitting */
4325 GST_OBJECT_UNLOCK (pad);
4327 if (G_LIKELY (is_buffer)) {
4328 /* if the signal handler returned FALSE, it means we should just drop the
4330 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (data)))
4333 /* push all buffers in the list */
4336 GST_OBJECT_LOCK (pad);
4339 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4342 /* Before pushing the buffer to the peer pad, ensure that caps
4343 * are set on this pad */
4344 caps = gst_pad_data_get_caps (is_buffer, data);
4345 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4347 /* take ref to peer pad before releasing the lock */
4348 gst_object_ref (peer);
4350 GST_OBJECT_UNLOCK (pad);
4352 /* we got a new datatype from the pad, it had better handle it */
4353 if (G_UNLIKELY (caps_changed)) {
4354 GST_DEBUG_OBJECT (pad,
4355 "caps changed from %" GST_PTR_FORMAT " to %p %" GST_PTR_FORMAT,
4356 GST_PAD_CAPS (pad), caps, caps);
4357 if (G_UNLIKELY (!gst_pad_set_caps (pad, caps)))
4358 goto not_negotiated;
4361 ret = gst_pad_chain_data_unchecked (peer, is_buffer, data);
4363 gst_object_unref (peer);
4369 GstBufferList *list;
4370 GstBufferListIterator *it;
4373 GST_INFO_OBJECT (pad, "pushing each group in list as a merged buffer");
4375 list = GST_BUFFER_LIST_CAST (data);
4376 it = gst_buffer_list_iterate (list);
4378 if (gst_buffer_list_iterator_next_group (it)) {
4380 group = gst_buffer_list_iterator_merge_group (it);
4381 if (group == NULL) {
4382 group = gst_buffer_new ();
4383 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing empty group");
4385 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing group");
4387 ret = gst_pad_push_data (pad, TRUE, group);
4388 } while (ret == GST_FLOW_OK && gst_buffer_list_iterator_next_group (it));
4390 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing empty group");
4391 ret = gst_pad_push_data (pad, TRUE, gst_buffer_new ());
4394 gst_buffer_list_iterator_free (it);
4395 gst_buffer_list_unref (list);
4400 /* ERROR recovery here */
4403 gst_pad_data_unref (is_buffer, data);
4404 GST_DEBUG_OBJECT (pad, "pad block stopped by flush");
4405 GST_OBJECT_UNLOCK (pad);
4410 gst_pad_data_unref (is_buffer, data);
4411 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
4416 gst_pad_data_unref (is_buffer, data);
4417 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4418 "pushing, but it was not linked");
4419 GST_OBJECT_UNLOCK (pad);
4420 return GST_FLOW_NOT_LINKED;
4424 gst_pad_data_unref (is_buffer, data);
4425 gst_object_unref (peer);
4426 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4427 "element pushed data then refused to accept the caps");
4428 return GST_FLOW_NOT_NEGOTIATED;
4434 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4435 * @buffer: the #GstBuffer to push returns GST_FLOW_ERROR if not.
4437 * Pushes a buffer to the peer of @pad.
4439 * This function will call an installed pad block before triggering any
4440 * installed pad probes.
4442 * If the caps on @buffer are different from the currently configured caps on
4443 * @pad, this function will call any installed setcaps function on @pad (see
4444 * gst_pad_set_setcaps_function()). In case of failure to renegotiate the new
4445 * format, this function returns #GST_FLOW_NOT_NEGOTIATED.
4447 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4448 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4451 * In all cases, success or failure, the caller loses its reference to @buffer
4452 * after calling this function.
4454 * Returns: a #GstFlowReturn from the peer pad.
4459 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4461 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4462 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4463 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4465 return gst_pad_push_data (pad, TRUE, buffer);
4469 * gst_pad_push_list:
4470 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4471 * @list: the #GstBufferList to push returns GST_FLOW_ERROR if not.
4473 * Pushes a buffer list to the peer of @pad.
4475 * This function will call an installed pad block before triggering any
4476 * installed pad probes.
4478 * If the caps on the first buffer in the first group of @list are different
4479 * from the currently configured caps on @pad, this function will call any
4480 * installed setcaps function on @pad (see gst_pad_set_setcaps_function()). In
4481 * case of failure to renegotiate the new format, this function returns
4482 * #GST_FLOW_NOT_NEGOTIATED.
4484 * If there are any probes installed on @pad every group of the buffer list
4485 * will be merged into a normal #GstBuffer and pushed via gst_pad_push and the
4486 * buffer list will be unreffed.
4488 * The function proceeds calling the chain function on the peer pad and returns
4489 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4490 * be returned. If the peer pad does not have any installed chainlist function
4491 * every group buffer of the list will be merged into a normal #GstBuffer and
4492 * chained via gst_pad_chain().
4494 * In all cases, success or failure, the caller loses its reference to @list
4495 * after calling this function.
4497 * Returns: a #GstFlowReturn from the peer pad.
4504 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4506 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4507 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4508 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4510 return gst_pad_push_data (pad, FALSE, list);
4514 * gst_pad_check_pull_range:
4515 * @pad: a sink #GstPad.
4517 * Checks if a gst_pad_pull_range() can be performed on the peer
4518 * source pad. This function is used by plugins that want to check
4519 * if they can use random access on the peer source pad.
4521 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
4522 * if it needs to perform some logic to determine if pull_range is
4525 * Returns: a gboolean with the result.
4530 gst_pad_check_pull_range (GstPad * pad)
4534 GstPadCheckGetRangeFunction checkgetrangefunc;
4536 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4538 GST_OBJECT_LOCK (pad);
4539 if (!GST_PAD_IS_SINK (pad))
4540 goto wrong_direction;
4542 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4545 gst_object_ref (peer);
4546 GST_OBJECT_UNLOCK (pad);
4548 /* see note in above function */
4549 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
4550 /* FIXME, kindoff ghetto */
4551 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
4552 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4553 "no checkgetrangefunc, assuming %d", ret);
4555 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4556 "calling checkgetrangefunc %s of peer pad %s:%s",
4557 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
4559 ret = checkgetrangefunc (peer);
4562 gst_object_unref (peer);
4566 /* ERROR recovery here */
4569 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4570 "checking pull range, but pad must be a sinkpad");
4571 GST_OBJECT_UNLOCK (pad);
4576 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4577 "checking pull range, but it was not linked");
4578 GST_OBJECT_UNLOCK (pad);
4584 * gst_pad_get_range:
4585 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4586 * @offset: The start offset of the buffer
4587 * @size: The length of the buffer
4588 * @buffer: a pointer to hold the #GstBuffer, returns #GST_FLOW_ERROR if %NULL.
4590 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
4593 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4594 * description of a getrange function. If @pad has no getrange function
4595 * installed (see gst_pad_set_getrange_function()) this function returns
4596 * #GST_FLOW_NOT_SUPPORTED.
4598 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4600 * Returns: a #GstFlowReturn from the pad.
4605 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4606 GstBuffer ** buffer)
4609 GstPadGetRangeFunction getrangefunc;
4610 gboolean emit_signal;
4612 gboolean caps_changed;
4614 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4615 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4616 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4618 GST_PAD_STREAM_LOCK (pad);
4620 GST_OBJECT_LOCK (pad);
4621 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4624 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4625 GST_OBJECT_UNLOCK (pad);
4627 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4630 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4631 "calling getrangefunc %s, offset %"
4632 G_GUINT64_FORMAT ", size %u",
4633 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4635 ret = getrangefunc (pad, offset, size, buffer);
4637 /* can only fire the signal if we have a valid buffer */
4638 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
4639 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
4643 GST_PAD_STREAM_UNLOCK (pad);
4645 if (G_UNLIKELY (ret != GST_FLOW_OK))
4646 goto get_range_failed;
4648 GST_OBJECT_LOCK (pad);
4649 /* Before pushing the buffer to the peer pad, ensure that caps
4650 * are set on this pad */
4651 caps = GST_BUFFER_CAPS (*buffer);
4652 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4653 GST_OBJECT_UNLOCK (pad);
4655 if (G_UNLIKELY (caps_changed)) {
4656 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4657 /* this should usually work because the element produced the buffer */
4658 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, TRUE)))
4659 goto not_negotiated;
4666 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4667 "pulling range, but pad was flushing");
4668 GST_OBJECT_UNLOCK (pad);
4669 GST_PAD_STREAM_UNLOCK (pad);
4670 return GST_FLOW_WRONG_STATE;
4674 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4675 ("pullrange on pad %s:%s but it has no getrangefunction",
4676 GST_DEBUG_PAD_NAME (pad)));
4677 GST_PAD_STREAM_UNLOCK (pad);
4678 return GST_FLOW_NOT_SUPPORTED;
4682 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4683 "Dropping data after FALSE probe return");
4684 GST_PAD_STREAM_UNLOCK (pad);
4685 gst_buffer_unref (*buffer);
4687 return GST_FLOW_UNEXPECTED;
4692 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4693 "getrange failed %s", gst_flow_get_name (ret));
4698 gst_buffer_unref (*buffer);
4700 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4701 "getrange returned buffer of unaccaptable caps");
4702 return GST_FLOW_NOT_NEGOTIATED;
4708 * gst_pad_pull_range:
4709 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4710 * @offset: The start offset of the buffer
4711 * @size: The length of the buffer
4712 * @buffer: a pointer to hold the #GstBuffer, returns GST_FLOW_ERROR if %NULL.
4714 * Pulls a @buffer from the peer pad.
4716 * This function will first trigger the pad block signal if it was
4719 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4720 * function returns the result of gst_pad_get_range() on the peer pad.
4721 * See gst_pad_get_range() for a list of return values and for the
4722 * semantics of the arguments of this function.
4724 * @buffer's caps must either be unset or the same as what is already
4725 * configured on @pad. Renegotiation within a running pull-mode pipeline is not
4728 * Returns: a #GstFlowReturn from the peer pad.
4729 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
4730 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
4731 * @buffer may not be used or freed when any other return value than
4732 * #GST_FLOW_OK is returned.
4737 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4738 GstBuffer ** buffer)
4742 gboolean emit_signal;
4744 gboolean caps_changed;
4746 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4747 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4748 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4750 GST_OBJECT_LOCK (pad);
4752 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
4753 handle_pad_block (pad);
4755 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4758 /* signal emision for the pad, peer has chance to emit when
4759 * we call _get_range() */
4760 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4762 gst_object_ref (peer);
4763 GST_OBJECT_UNLOCK (pad);
4765 ret = gst_pad_get_range (peer, offset, size, buffer);
4767 gst_object_unref (peer);
4769 if (G_UNLIKELY (ret != GST_FLOW_OK))
4770 goto pull_range_failed;
4772 /* can only fire the signal if we have a valid buffer */
4773 if (G_UNLIKELY (emit_signal)) {
4774 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
4778 GST_OBJECT_LOCK (pad);
4779 /* Before pushing the buffer to the peer pad, ensure that caps
4780 * are set on this pad */
4781 caps = GST_BUFFER_CAPS (*buffer);
4782 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4783 GST_OBJECT_UNLOCK (pad);
4785 /* we got a new datatype on the pad, see if it can handle it */
4786 if (G_UNLIKELY (caps_changed)) {
4787 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4788 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
4789 goto not_negotiated;
4793 /* ERROR recovery here */
4796 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4797 "pulling range, but it was not linked");
4798 GST_OBJECT_UNLOCK (pad);
4799 return GST_FLOW_NOT_LINKED;
4804 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4805 (ret >= GST_FLOW_UNEXPECTED) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4806 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4811 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4812 "Dropping data after FALSE probe return");
4813 gst_buffer_unref (*buffer);
4815 return GST_FLOW_UNEXPECTED;
4819 gst_buffer_unref (*buffer);
4821 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4822 "pullrange returned buffer of different caps");
4823 return GST_FLOW_NOT_NEGOTIATED;
4828 * gst_pad_push_event:
4829 * @pad: a #GstPad to push the event to.
4830 * @event: the #GstEvent to send to the pad.
4832 * Sends the event to the peer of the given pad. This function is
4833 * mainly used by elements to send events to their peer
4836 * This function takes owership of the provided event so you should
4837 * gst_event_ref() it if you want to reuse the event after this call.
4839 * Returns: TRUE if the event was handled.
4844 gst_pad_push_event (GstPad * pad, GstEvent * event)
4849 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4850 g_return_val_if_fail (event != NULL, FALSE);
4851 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4853 GST_LOG_OBJECT (pad, "event: %s", GST_EVENT_TYPE_NAME (event));
4855 GST_OBJECT_LOCK (pad);
4857 /* Two checks to be made:
4858 * . (un)set the FLUSHING flag for flushing events,
4859 * . handle pad blocking */
4860 switch (GST_EVENT_TYPE (event)) {
4861 case GST_EVENT_FLUSH_START:
4862 GST_PAD_SET_FLUSHING (pad);
4864 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4865 /* flush start will have set the FLUSHING flag and will then
4866 * unlock all threads doing a GCond wait on the blocking pad. This
4867 * will typically unblock the STREAMING thread blocked on a pad. */
4868 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
4869 "doing block signal.");
4870 GST_PAD_BLOCK_BROADCAST (pad);
4874 case GST_EVENT_FLUSH_STOP:
4875 GST_PAD_UNSET_FLUSHING (pad);
4877 /* if we are blocked, flush away the FLUSH_STOP event */
4878 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4879 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4884 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4885 /* block the event as long as the pad is blocked */
4886 if (handle_pad_block (pad) != GST_FLOW_OK)
4892 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
4893 GST_OBJECT_UNLOCK (pad);
4895 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
4898 GST_OBJECT_LOCK (pad);
4900 peerpad = GST_PAD_PEER (pad);
4901 if (peerpad == NULL)
4904 GST_LOG_OBJECT (pad, "sending event %s to peerpad %" GST_PTR_FORMAT,
4905 GST_EVENT_TYPE_NAME (event), peerpad);
4906 gst_object_ref (peerpad);
4907 GST_OBJECT_UNLOCK (pad);
4909 result = gst_pad_send_event (peerpad, event);
4911 /* Note: we gave away ownership of the event at this point */
4912 GST_LOG_OBJECT (pad, "sent event to peerpad %" GST_PTR_FORMAT ", result %d",
4914 gst_object_unref (peerpad);
4918 /* ERROR handling */
4921 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
4922 gst_event_unref (event);
4927 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4928 gst_event_unref (event);
4929 GST_OBJECT_UNLOCK (pad);
4934 GST_DEBUG_OBJECT (pad,
4935 "Not forwarding event since we're flushing and blocking");
4936 gst_event_unref (event);
4937 GST_OBJECT_UNLOCK (pad);
4943 * gst_pad_send_event:
4944 * @pad: a #GstPad to send the event to.
4945 * @event: the #GstEvent to send to the pad.
4947 * Sends the event to the pad. This function can be used
4948 * by applications to send events in the pipeline.
4950 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4951 * sink pad, @event should be a downstream event. For example, you would not
4952 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4953 * Furthermore, some downstream events have to be serialized with data flow,
4954 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4955 * the event needs to be serialized with data flow, this function will take the
4956 * pad's stream lock while calling its event function.
4958 * To find out whether an event type is upstream, downstream, or downstream and
4959 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4960 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4961 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4962 * plugin doesn't need to bother itself with this information; the core handles
4963 * all necessary locks and checks.
4965 * This function takes owership of the provided event so you should
4966 * gst_event_ref() it if you want to reuse the event after this call.
4968 * Returns: TRUE if the event was handled.
4971 gst_pad_send_event (GstPad * pad, GstEvent * event)
4973 gboolean result = FALSE;
4974 GstPadEventFunction eventfunc;
4975 gboolean serialized, need_unlock = FALSE;
4977 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4978 g_return_val_if_fail (event != NULL, FALSE);
4980 GST_OBJECT_LOCK (pad);
4981 if (GST_PAD_IS_SINK (pad)) {
4982 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4983 goto wrong_direction;
4984 serialized = GST_EVENT_IS_SERIALIZED (event);
4985 } else if (GST_PAD_IS_SRC (pad)) {
4986 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4987 goto wrong_direction;
4988 /* events on srcpad never are serialized */
4991 goto unknown_direction;
4993 if (G_UNLIKELY (GST_EVENT_SRC (event) == NULL)) {
4994 GST_LOG_OBJECT (pad, "event had no source, setting pad as event source");
4995 GST_EVENT_SRC (event) = gst_object_ref (pad);
4999 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
5000 GST_OBJECT_UNLOCK (pad);
5002 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT_CAST (event)))
5005 GST_OBJECT_LOCK (pad);
5008 switch (GST_EVENT_TYPE (event)) {
5009 case GST_EVENT_FLUSH_START:
5010 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5011 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5013 /* can't even accept a flush begin event when flushing */
5014 if (GST_PAD_IS_FLUSHING (pad))
5016 GST_PAD_SET_FLUSHING (pad);
5017 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5019 case GST_EVENT_FLUSH_STOP:
5020 GST_PAD_UNSET_FLUSHING (pad);
5021 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5022 GST_OBJECT_UNLOCK (pad);
5023 /* grab stream lock */
5024 GST_PAD_STREAM_LOCK (pad);
5026 GST_OBJECT_LOCK (pad);
5029 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
5030 GST_EVENT_TYPE_NAME (event));
5032 /* make this a little faster, no point in grabbing the lock
5033 * if the pad is allready flushing. */
5034 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5038 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5039 GST_OBJECT_UNLOCK (pad);
5040 GST_PAD_STREAM_LOCK (pad);
5042 GST_OBJECT_LOCK (pad);
5043 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5048 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5051 GST_OBJECT_UNLOCK (pad);
5053 result = eventfunc (pad, event);
5056 GST_PAD_STREAM_UNLOCK (pad);
5058 GST_DEBUG_OBJECT (pad, "sent event, result %d", result);
5062 /* ERROR handling */
5065 g_warning ("pad %s:%s sending %s event in wrong direction",
5066 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5067 GST_OBJECT_UNLOCK (pad);
5068 gst_event_unref (event);
5073 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5074 GST_OBJECT_UNLOCK (pad);
5075 gst_event_unref (event);
5080 g_warning ("pad %s:%s has no event handler, file a bug.",
5081 GST_DEBUG_PAD_NAME (pad));
5082 GST_OBJECT_UNLOCK (pad);
5084 GST_PAD_STREAM_UNLOCK (pad);
5085 gst_event_unref (event);
5090 GST_OBJECT_UNLOCK (pad);
5092 GST_PAD_STREAM_UNLOCK (pad);
5093 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5094 "Received event on flushing pad. Discarding");
5095 gst_event_unref (event);
5100 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
5101 gst_event_unref (event);
5107 * gst_pad_set_element_private:
5108 * @pad: the #GstPad to set the private data of.
5109 * @priv: The private data to attach to the pad.
5111 * Set the given private data gpointer on the pad.
5112 * This function can only be used by the element that owns the pad.
5113 * No locking is performed in this function.
5116 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5118 pad->element_private = priv;
5122 * gst_pad_get_element_private:
5123 * @pad: the #GstPad to get the private data of.
5125 * Gets the private data of a pad.
5126 * No locking is performed in this function.
5128 * Returns: a #gpointer to the private data.
5131 gst_pad_get_element_private (GstPad * pad)
5133 return pad->element_private;
5137 do_stream_status (GstPad * pad, GstStreamStatusType type,
5138 GThread * thread, GstTask * task)
5142 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5144 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5145 if (GST_IS_ELEMENT (parent)) {
5146 GstMessage *message;
5147 GValue value = { 0 };
5149 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5150 gchar *tname, *ename, *pname;
5152 /* create a good task name */
5153 ename = gst_element_get_name (parent);
5154 pname = gst_pad_get_name (pad);
5155 tname = g_strdup_printf ("%s:%s", ename, pname);
5159 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5163 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5166 g_value_init (&value, GST_TYPE_TASK);
5167 g_value_set_object (&value, task);
5168 gst_message_set_stream_status_object (message, &value);
5169 g_value_unset (&value);
5171 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5172 gst_element_post_message (parent, message);
5174 gst_object_unref (parent);
5179 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5181 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5186 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5188 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5192 static GstTaskThreadCallbacks thr_callbacks = {
5198 * gst_pad_start_task:
5199 * @pad: the #GstPad to start the task of
5200 * @func: the task function to call
5201 * @data: data passed to the task function
5203 * Starts a task that repeatedly calls @func with @data. This function
5204 * is mostly used in pad activation functions to start the dataflow.
5205 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5206 * before @func is called.
5208 * Returns: a %TRUE if the task could be started.
5211 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
5216 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5217 g_return_val_if_fail (func != NULL, FALSE);
5219 GST_DEBUG_OBJECT (pad, "start task");
5221 GST_OBJECT_LOCK (pad);
5222 task = GST_PAD_TASK (pad);
5224 task = gst_task_create (func, data);
5225 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5226 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
5227 GST_DEBUG_OBJECT (pad, "created task");
5228 GST_PAD_TASK (pad) = task;
5229 gst_object_ref (task);
5230 /* release lock to post the message */
5231 GST_OBJECT_UNLOCK (pad);
5233 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5235 gst_object_unref (task);
5237 GST_OBJECT_LOCK (pad);
5238 /* nobody else is supposed to have changed the pad now */
5239 if (GST_PAD_TASK (pad) != task)
5240 goto concurrent_stop;
5242 res = gst_task_set_state (task, GST_TASK_STARTED);
5243 GST_OBJECT_UNLOCK (pad);
5250 GST_OBJECT_UNLOCK (pad);
5256 * gst_pad_pause_task:
5257 * @pad: the #GstPad to pause the task of
5259 * Pause the task of @pad. This function will also wait until the
5260 * function executed by the task is finished if this function is not
5261 * called from the task function.
5263 * Returns: a TRUE if the task could be paused or FALSE when the pad
5267 gst_pad_pause_task (GstPad * pad)
5272 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5274 GST_DEBUG_OBJECT (pad, "pause task");
5276 GST_OBJECT_LOCK (pad);
5277 task = GST_PAD_TASK (pad);
5280 res = gst_task_set_state (task, GST_TASK_PAUSED);
5281 GST_OBJECT_UNLOCK (pad);
5283 /* wait for task function to finish, this lock is recursive so it does nothing
5284 * when the pause is called from the task itself */
5285 GST_PAD_STREAM_LOCK (pad);
5286 GST_PAD_STREAM_UNLOCK (pad);
5292 GST_DEBUG_OBJECT (pad, "pad has no task");
5293 GST_OBJECT_UNLOCK (pad);
5299 * gst_pad_stop_task:
5300 * @pad: the #GstPad to stop the task of
5302 * Stop the task of @pad. This function will also make sure that the
5303 * function executed by the task will effectively stop if not called
5304 * from the GstTaskFunction.
5306 * This function will deadlock if called from the GstTaskFunction of
5307 * the task. Use gst_task_pause() instead.
5309 * Regardless of whether the pad has a task, the stream lock is acquired and
5310 * released so as to ensure that streaming through this pad has finished.
5312 * Returns: a TRUE if the task could be stopped or FALSE on error.
5315 gst_pad_stop_task (GstPad * pad)
5320 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5322 GST_DEBUG_OBJECT (pad, "stop task");
5324 GST_OBJECT_LOCK (pad);
5325 task = GST_PAD_TASK (pad);
5328 GST_PAD_TASK (pad) = NULL;
5329 res = gst_task_set_state (task, GST_TASK_STOPPED);
5330 GST_OBJECT_UNLOCK (pad);
5332 GST_PAD_STREAM_LOCK (pad);
5333 GST_PAD_STREAM_UNLOCK (pad);
5335 if (!gst_task_join (task))
5338 gst_object_unref (task);
5344 GST_DEBUG_OBJECT (pad, "no task");
5345 GST_OBJECT_UNLOCK (pad);
5347 GST_PAD_STREAM_LOCK (pad);
5348 GST_PAD_STREAM_UNLOCK (pad);
5350 /* this is not an error */
5355 /* this is bad, possibly the application tried to join the task from
5356 * the task's thread. We install the task again so that it will be stopped
5357 * again from the right thread next time hopefully. */
5358 GST_OBJECT_LOCK (pad);
5359 GST_DEBUG_OBJECT (pad, "join failed");
5360 /* we can only install this task if there was no other task */
5361 if (GST_PAD_TASK (pad) == NULL)
5362 GST_PAD_TASK (pad) = task;
5363 GST_OBJECT_UNLOCK (pad);