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 pad->stream_rec_lock = g_new (GStaticRecMutex, 1);
379 g_static_rec_mutex_init (pad->stream_rec_lock);
381 pad->block_cond = g_cond_new ();
385 gst_pad_dispose (GObject * object)
387 GstPad *pad = GST_PAD_CAST (object);
390 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
392 /* unlink the peer pad */
393 if ((peer = gst_pad_get_peer (pad))) {
394 /* window for MT unsafeness, someone else could unlink here
395 * and then we call unlink with wrong pads. The unlink
396 * function would catch this and safely return failed. */
397 if (GST_PAD_IS_SRC (pad))
398 gst_pad_unlink (pad, peer);
400 gst_pad_unlink (peer, pad);
402 gst_object_unref (peer);
406 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
408 gst_pad_set_pad_template (pad, NULL);
410 if (pad->block_destroy_data && pad->block_data) {
411 pad->block_destroy_data (pad->block_data);
412 pad->block_data = NULL;
415 G_OBJECT_CLASS (parent_class)->dispose (object);
419 gst_pad_finalize (GObject * object)
421 GstPad *pad = GST_PAD_CAST (object);
424 /* in case the task is still around, clean it up */
425 if ((task = GST_PAD_TASK (pad))) {
426 gst_task_join (task);
427 GST_PAD_TASK (pad) = NULL;
428 gst_object_unref (task);
431 if (pad->stream_rec_lock) {
432 g_static_rec_mutex_free (pad->stream_rec_lock);
433 g_free (pad->stream_rec_lock);
434 pad->stream_rec_lock = NULL;
436 if (pad->preroll_lock) {
437 g_mutex_free (pad->preroll_lock);
438 g_cond_free (pad->preroll_cond);
439 pad->preroll_lock = NULL;
440 pad->preroll_cond = NULL;
442 if (pad->block_cond) {
443 g_cond_free (pad->block_cond);
444 pad->block_cond = NULL;
447 G_OBJECT_CLASS (parent_class)->finalize (object);
451 gst_pad_set_property (GObject * object, guint prop_id,
452 const GValue * value, GParamSpec * pspec)
454 g_return_if_fail (GST_IS_PAD (object));
457 case PAD_PROP_DIRECTION:
458 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
460 case PAD_PROP_TEMPLATE:
461 gst_pad_set_pad_template (GST_PAD_CAST (object),
462 (GstPadTemplate *) g_value_get_object (value));
465 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
471 gst_pad_get_property (GObject * object, guint prop_id,
472 GValue * value, GParamSpec * pspec)
474 g_return_if_fail (GST_IS_PAD (object));
478 GST_OBJECT_LOCK (object);
479 g_value_set_boxed (value, GST_PAD_CAPS (object));
480 GST_OBJECT_UNLOCK (object);
482 case PAD_PROP_DIRECTION:
483 g_value_set_enum (value, GST_PAD_DIRECTION (object));
485 case PAD_PROP_TEMPLATE:
486 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
489 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
496 * @name: the name of the new pad.
497 * @direction: the #GstPadDirection of the pad.
499 * Creates a new pad with the given name in the given direction.
500 * If name is NULL, a guaranteed unique name (across all pads)
502 * This function makes a copy of the name so you can safely free the name.
504 * Returns: a new #GstPad, or NULL in case of an error.
509 gst_pad_new (const gchar * name, GstPadDirection direction)
511 return g_object_new (GST_TYPE_PAD,
512 "name", name, "direction", direction, NULL);
516 * gst_pad_new_from_template:
517 * @templ: the pad template to use
518 * @name: the name of the element
520 * Creates a new pad with the given name from the given template.
521 * If name is NULL, a guaranteed unique name (across all pads)
523 * This function makes a copy of the name so you can safely free the name.
525 * Returns: a new #GstPad, or NULL in case of an error.
528 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
530 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
532 return g_object_new (GST_TYPE_PAD,
533 "name", name, "direction", templ->direction, "template", templ, NULL);
537 * gst_pad_new_from_static_template:
538 * @templ: the #GstStaticPadTemplate to use
539 * @name: the name of the element
541 * Creates a new pad with the given name from the given static template.
542 * If name is NULL, a guaranteed unique name (across all pads)
544 * This function makes a copy of the name so you can safely free the name.
546 * Returns: a new #GstPad, or NULL in case of an error.
549 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
553 GstPadTemplate *template;
555 template = gst_static_pad_template_get (templ);
556 pad = gst_pad_new_from_template (template, name);
557 gst_object_unref (template);
562 * gst_pad_get_direction:
563 * @pad: a #GstPad to get the direction of.
565 * Gets the direction of the pad. The direction of the pad is
566 * decided at construction time so this function does not take
569 * Returns: the #GstPadDirection of the pad.
574 gst_pad_get_direction (GstPad * pad)
576 GstPadDirection result;
578 /* PAD_UNKNOWN is a little silly but we need some sort of
579 * error return value */
580 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
582 result = GST_PAD_DIRECTION (pad);
588 gst_pad_activate_default (GstPad * pad)
590 return gst_pad_activate_push (pad, TRUE);
594 pre_activate (GstPad * pad, GstActivateMode new_mode)
597 case GST_ACTIVATE_PUSH:
598 case GST_ACTIVATE_PULL:
599 GST_OBJECT_LOCK (pad);
600 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
602 GST_PAD_UNSET_FLUSHING (pad);
603 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
604 GST_OBJECT_UNLOCK (pad);
606 case GST_ACTIVATE_NONE:
607 GST_OBJECT_LOCK (pad);
608 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
609 GST_PAD_SET_FLUSHING (pad);
610 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
611 /* unlock blocked pads so element can resume and stop */
612 GST_PAD_BLOCK_BROADCAST (pad);
613 GST_OBJECT_UNLOCK (pad);
619 post_activate (GstPad * pad, GstActivateMode new_mode)
622 case GST_ACTIVATE_PUSH:
623 case GST_ACTIVATE_PULL:
626 case GST_ACTIVATE_NONE:
627 /* ensures that streaming stops */
628 GST_PAD_STREAM_LOCK (pad);
629 GST_DEBUG_OBJECT (pad, "stopped streaming");
630 GST_PAD_STREAM_UNLOCK (pad);
636 * gst_pad_set_active:
637 * @pad: the #GstPad to activate or deactivate.
638 * @active: whether or not the pad should be active.
640 * Activates or deactivates the given pad.
641 * Normally called from within core state change functions.
643 * If @active, makes sure the pad is active. If it is already active, either in
644 * push or pull mode, just return. Otherwise dispatches to the pad's activate
645 * function to perform the actual activation.
647 * If not @active, checks the pad's current mode and calls
648 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
651 * Returns: #TRUE if the operation was successful.
656 gst_pad_set_active (GstPad * pad, gboolean active)
659 gboolean ret = FALSE;
661 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
663 GST_OBJECT_LOCK (pad);
664 old = GST_PAD_ACTIVATE_MODE (pad);
665 GST_OBJECT_UNLOCK (pad);
669 case GST_ACTIVATE_PUSH:
670 GST_DEBUG_OBJECT (pad, "activating pad from push");
673 case GST_ACTIVATE_PULL:
674 GST_DEBUG_OBJECT (pad, "activating pad from pull");
677 case GST_ACTIVATE_NONE:
678 GST_DEBUG_OBJECT (pad, "activating pad from none");
679 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
684 case GST_ACTIVATE_PUSH:
685 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
686 ret = gst_pad_activate_push (pad, FALSE);
688 case GST_ACTIVATE_PULL:
689 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
690 ret = gst_pad_activate_pull (pad, FALSE);
692 case GST_ACTIVATE_NONE:
693 GST_DEBUG_OBJECT (pad, "deactivating pad from none");
700 GST_OBJECT_LOCK (pad);
702 g_critical ("Failed to deactivate pad %s:%s, very bad",
703 GST_DEBUG_PAD_NAME (pad));
705 GST_WARNING_OBJECT (pad, "Failed to activate pad");
707 GST_OBJECT_UNLOCK (pad);
714 * gst_pad_activate_pull:
715 * @pad: the #GstPad to activate or deactivate.
716 * @active: whether or not the pad should be active.
718 * Activates or deactivates the given pad in pull mode via dispatching to the
719 * pad's activatepullfunc. For use from within pad activation functions only.
720 * When called on sink pads, will first proxy the call to the peer pad, which
721 * is expected to activate its internally linked pads from within its
722 * activate_pull function.
724 * If you don't know what this is, you probably don't want to call it.
726 * Returns: TRUE if the operation was successful.
731 gst_pad_activate_pull (GstPad * pad, gboolean active)
733 GstActivateMode old, new;
736 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
738 GST_OBJECT_LOCK (pad);
739 old = GST_PAD_ACTIVATE_MODE (pad);
740 GST_OBJECT_UNLOCK (pad);
744 case GST_ACTIVATE_PULL:
745 GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
747 case GST_ACTIVATE_PUSH:
748 GST_DEBUG_OBJECT (pad,
749 "activating pad from push, deactivate push first");
750 /* pad was activate in the wrong direction, deactivate it
751 * and reactivate it in pull mode */
752 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
753 goto deactivate_failed;
754 /* fallthrough, pad is deactivated now. */
755 case GST_ACTIVATE_NONE:
756 GST_DEBUG_OBJECT (pad, "activating pad from none");
761 case GST_ACTIVATE_NONE:
762 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
764 case GST_ACTIVATE_PUSH:
765 GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
766 /* pad was activated in the other direction, deactivate it
767 * in push mode, this should not happen... */
768 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
769 goto deactivate_failed;
770 /* everything is fine now */
772 case GST_ACTIVATE_PULL:
773 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
778 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
779 if ((peer = gst_pad_get_peer (pad))) {
780 GST_DEBUG_OBJECT (pad, "calling peer");
781 if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
783 gst_object_unref (peer);
785 /* there is no peer, this is only fatal when we activate. When we
786 * deactivate, we must assume the application has unlinked the peer and
787 * will deactivate it eventually. */
791 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
794 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
795 goto failure; /* Can't activate pull on a src without a
799 new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
800 pre_activate (pad, new);
802 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
803 if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
806 /* can happen for sinks of passthrough elements */
809 post_activate (pad, new);
811 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
812 active ? "activated" : "deactivated");
818 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
819 active ? "activated" : "deactivated");
824 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
825 "failed to %s in switch to pull from mode %d",
826 (active ? "activate" : "deactivate"), old);
831 GST_OBJECT_LOCK (peer);
832 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
833 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
834 GST_OBJECT_UNLOCK (peer);
835 gst_object_unref (peer);
840 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
846 GST_OBJECT_LOCK (pad);
847 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
848 active ? "activate" : "deactivate");
849 GST_PAD_SET_FLUSHING (pad);
850 GST_PAD_ACTIVATE_MODE (pad) = old;
851 GST_OBJECT_UNLOCK (pad);
857 * gst_pad_activate_push:
858 * @pad: the #GstPad to activate or deactivate.
859 * @active: whether the pad should be active or not.
861 * Activates or deactivates the given pad in push mode via dispatching to the
862 * pad's activatepushfunc. For use from within pad activation functions only.
864 * If you don't know what this is, you probably don't want to call it.
866 * Returns: %TRUE if the operation was successful.
871 gst_pad_activate_push (GstPad * pad, gboolean active)
873 GstActivateMode old, new;
875 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
876 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
877 active ? "activated" : "deactivated");
879 GST_OBJECT_LOCK (pad);
880 old = GST_PAD_ACTIVATE_MODE (pad);
881 GST_OBJECT_UNLOCK (pad);
885 case GST_ACTIVATE_PUSH:
886 GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
888 case GST_ACTIVATE_PULL:
889 GST_DEBUG_OBJECT (pad,
890 "activating pad from push, deactivating pull first");
891 /* pad was activate in the wrong direction, deactivate it
892 * an reactivate it in push mode */
893 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
894 goto deactivate_failed;
895 /* fallthrough, pad is deactivated now. */
896 case GST_ACTIVATE_NONE:
897 GST_DEBUG_OBJECT (pad, "activating pad from none");
902 case GST_ACTIVATE_NONE:
903 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
905 case GST_ACTIVATE_PULL:
906 GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
907 /* pad was activated in the other direction, deactivate it
908 * in pull mode, this should not happen... */
909 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
910 goto deactivate_failed;
911 /* everything is fine now */
913 case GST_ACTIVATE_PUSH:
914 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
919 new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
920 pre_activate (pad, new);
922 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
923 if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
927 /* quite ok, element relies on state change func to prepare itself */
930 post_activate (pad, new);
932 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
933 active ? "activated" : "deactivated");
938 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
939 active ? "activated" : "deactivated");
944 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
945 "failed to %s in switch to push from mode %d",
946 (active ? "activate" : "deactivate"), old);
951 GST_OBJECT_LOCK (pad);
952 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
953 active ? "activate" : "deactivate");
954 GST_PAD_SET_FLUSHING (pad);
955 GST_PAD_ACTIVATE_MODE (pad) = old;
956 GST_OBJECT_UNLOCK (pad);
963 * @pad: the #GstPad to query
965 * Query if a pad is active
967 * Returns: TRUE if the pad is active.
972 gst_pad_is_active (GstPad * pad)
974 gboolean result = FALSE;
976 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
978 GST_OBJECT_LOCK (pad);
979 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
980 GST_OBJECT_UNLOCK (pad);
986 * gst_pad_set_blocked_async_full:
987 * @pad: the #GstPad to block or unblock
988 * @blocked: boolean indicating whether the pad should be blocked or unblocked
989 * @callback: #GstPadBlockCallback that will be called when the
991 * @user_data: user data passed to the callback
992 * @destroy_data: #GDestroyNotify for user_data
994 * Blocks or unblocks the dataflow on a pad. The provided callback
995 * is called when the operation succeeds; this happens right before the next
996 * attempt at pushing a buffer on the pad.
998 * This can take a while as the pad can only become blocked when real dataflow
1000 * When the pipeline is stalled, for example in PAUSED, this can
1001 * take an indeterminate amount of time.
1002 * You can pass NULL as the callback to make this call block. Be careful with
1003 * this blocking call as it might not return for reasons stated above.
1005 * Returns: TRUE if the pad could be blocked. This function can fail if the
1006 * wrong parameters were passed or the pad was already in the requested state.
1013 gst_pad_set_blocked_async_full (GstPad * pad, gboolean blocked,
1014 GstPadBlockCallback callback, gpointer user_data,
1015 GDestroyNotify destroy_data)
1017 gboolean was_blocked = FALSE;
1019 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1021 GST_OBJECT_LOCK (pad);
1023 was_blocked = GST_PAD_IS_BLOCKED (pad);
1025 if (G_UNLIKELY (was_blocked == blocked))
1026 goto had_right_state;
1029 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad");
1031 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
1033 if (pad->block_destroy_data && pad->block_data)
1034 pad->block_destroy_data (pad->block_data);
1036 pad->block_callback = callback;
1037 pad->block_data = user_data;
1038 pad->block_destroy_data = destroy_data;
1039 pad->abidata.ABI.block_callback_called = FALSE;
1041 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
1042 GST_PAD_BLOCK_WAIT (pad);
1043 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
1046 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad");
1048 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
1050 if (pad->block_destroy_data && pad->block_data)
1051 pad->block_destroy_data (pad->block_data);
1053 pad->block_callback = callback;
1054 pad->block_data = user_data;
1055 pad->block_destroy_data = destroy_data;
1056 pad->abidata.ABI.block_callback_called = FALSE;
1058 GST_PAD_BLOCK_BROADCAST (pad);
1060 /* no callback, wait for the unblock to happen */
1061 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
1062 GST_PAD_BLOCK_WAIT (pad);
1063 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
1066 GST_OBJECT_UNLOCK (pad);
1072 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1073 "pad was in right state (%d)", was_blocked);
1074 GST_OBJECT_UNLOCK (pad);
1081 * gst_pad_set_blocked_async:
1082 * @pad: the #GstPad to block or unblock
1083 * @blocked: boolean indicating whether the pad should be blocked or unblocked
1084 * @callback: #GstPadBlockCallback that will be called when the
1085 * operation succeeds
1086 * @user_data: user data passed to the callback
1088 * Blocks or unblocks the dataflow on a pad. The provided callback
1089 * is called when the operation succeeds; this happens right before the next
1090 * attempt at pushing a buffer on the pad.
1092 * This can take a while as the pad can only become blocked when real dataflow
1094 * When the pipeline is stalled, for example in PAUSED, this can
1095 * take an indeterminate amount of time.
1096 * You can pass NULL as the callback to make this call block. Be careful with
1097 * this blocking call as it might not return for reasons stated above.
1099 * Returns: TRUE if the pad could be blocked. This function can fail if the
1100 * wrong parameters were passed or the pad was already in the requested state.
1105 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
1106 GstPadBlockCallback callback, gpointer user_data)
1108 return gst_pad_set_blocked_async_full (pad, blocked,
1109 callback, user_data, NULL);
1113 * gst_pad_set_blocked:
1114 * @pad: the #GstPad to block or unblock
1115 * @blocked: boolean indicating we should block or unblock
1117 * Blocks or unblocks the dataflow on a pad. This function is
1118 * a shortcut for gst_pad_set_blocked_async() with a NULL
1121 * Returns: TRUE if the pad could be blocked. This function can fail if the
1122 * wrong parameters were passed or the pad was already in the requested state.
1127 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
1129 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
1133 * gst_pad_is_blocked:
1134 * @pad: the #GstPad to query
1136 * Checks if the pad is blocked or not. This function returns the
1137 * last requested state of the pad. It is not certain that the pad
1138 * is actually blocking at this point (see gst_pad_is_blocking()).
1140 * Returns: TRUE if the pad is blocked.
1145 gst_pad_is_blocked (GstPad * pad)
1147 gboolean result = FALSE;
1149 g_return_val_if_fail (GST_IS_PAD (pad), result);
1151 GST_OBJECT_LOCK (pad);
1152 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
1153 GST_OBJECT_UNLOCK (pad);
1159 * gst_pad_is_blocking:
1160 * @pad: the #GstPad to query
1162 * Checks if the pad is blocking or not. This is a guaranteed state
1163 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1165 * Returns: TRUE if the pad is blocking.
1172 gst_pad_is_blocking (GstPad * pad)
1174 gboolean result = FALSE;
1176 g_return_val_if_fail (GST_IS_PAD (pad), result);
1178 GST_OBJECT_LOCK (pad);
1179 /* the blocking flag is only valid if the pad is not flushing */
1180 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING) &&
1181 !GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING);
1182 GST_OBJECT_UNLOCK (pad);
1188 * gst_pad_set_activate_function:
1190 * @activate: the #GstPadActivateFunction to set.
1192 * Sets the given activate function for @pad. The activate function will
1193 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1194 * the actual activation. Only makes sense to set on sink pads.
1196 * Call this function if your sink pad can start a pull-based task.
1199 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1201 g_return_if_fail (GST_IS_PAD (pad));
1203 GST_PAD_ACTIVATEFUNC (pad) = activate;
1204 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1205 GST_DEBUG_FUNCPTR_NAME (activate));
1209 * gst_pad_set_activatepull_function:
1211 * @activatepull: the #GstPadActivateModeFunction to set.
1213 * Sets the given activate_pull function for the pad. An activate_pull function
1214 * prepares the element and any upstream connections for pulling. See XXX
1215 * part-activation.txt for details.
1218 gst_pad_set_activatepull_function (GstPad * pad,
1219 GstPadActivateModeFunction activatepull)
1221 g_return_if_fail (GST_IS_PAD (pad));
1223 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1224 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepullfunc set to %s",
1225 GST_DEBUG_FUNCPTR_NAME (activatepull));
1229 * gst_pad_set_activatepush_function:
1231 * @activatepush: the #GstPadActivateModeFunction to set.
1233 * Sets the given activate_push function for the pad. An activate_push function
1234 * prepares the element for pushing. See XXX part-activation.txt for details.
1237 gst_pad_set_activatepush_function (GstPad * pad,
1238 GstPadActivateModeFunction activatepush)
1240 g_return_if_fail (GST_IS_PAD (pad));
1242 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1243 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepushfunc set to %s",
1244 GST_DEBUG_FUNCPTR_NAME (activatepush));
1248 * gst_pad_set_chain_function:
1249 * @pad: a sink #GstPad.
1250 * @chain: the #GstPadChainFunction to set.
1252 * Sets the given chain function for the pad. The chain function is called to
1253 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1256 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1258 g_return_if_fail (GST_IS_PAD (pad));
1259 g_return_if_fail (GST_PAD_IS_SINK (pad));
1261 GST_PAD_CHAINFUNC (pad) = chain;
1262 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1263 GST_DEBUG_FUNCPTR_NAME (chain));
1267 * gst_pad_set_chain_list_function:
1268 * @pad: a sink #GstPad.
1269 * @chainlist: the #GstPadChainListFunction to set.
1271 * Sets the given chain list function for the pad. The chainlist function is
1272 * called to process a #GstBufferList input buffer list. See
1273 * #GstPadChainListFunction for more details.
1278 gst_pad_set_chain_list_function (GstPad * pad,
1279 GstPadChainListFunction chainlist)
1281 g_return_if_fail (GST_IS_PAD (pad));
1282 g_return_if_fail (GST_PAD_IS_SINK (pad));
1284 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1285 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1286 GST_DEBUG_FUNCPTR_NAME (chainlist));
1290 * gst_pad_set_getrange_function:
1291 * @pad: a source #GstPad.
1292 * @get: the #GstPadGetRangeFunction to set.
1294 * Sets the given getrange function for the pad. The getrange function is
1295 * called to produce a new #GstBuffer to start the processing pipeline. see
1296 * #GstPadGetRangeFunction for a description of the getrange function.
1299 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1301 g_return_if_fail (GST_IS_PAD (pad));
1302 g_return_if_fail (GST_PAD_IS_SRC (pad));
1304 GST_PAD_GETRANGEFUNC (pad) = get;
1306 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1307 GST_DEBUG_FUNCPTR_NAME (get));
1311 * gst_pad_set_checkgetrange_function:
1312 * @pad: a source #GstPad.
1313 * @check: the #GstPadCheckGetRangeFunction to set.
1315 * Sets the given checkgetrange function for the pad. Implement this function
1316 * on a pad if you dynamically support getrange based scheduling on the pad.
1319 gst_pad_set_checkgetrange_function (GstPad * pad,
1320 GstPadCheckGetRangeFunction check)
1322 g_return_if_fail (GST_IS_PAD (pad));
1323 g_return_if_fail (GST_PAD_IS_SRC (pad));
1325 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
1327 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "checkgetrangefunc set to %s",
1328 GST_DEBUG_FUNCPTR_NAME (check));
1332 * gst_pad_set_event_function:
1333 * @pad: a #GstPad of either direction.
1334 * @event: the #GstPadEventFunction to set.
1336 * Sets the given event handler for the pad.
1339 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1341 g_return_if_fail (GST_IS_PAD (pad));
1343 GST_PAD_EVENTFUNC (pad) = event;
1345 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1346 GST_DEBUG_FUNCPTR_NAME (event));
1350 * gst_pad_set_query_function:
1351 * @pad: a #GstPad of either direction.
1352 * @query: the #GstPadQueryFunction to set.
1354 * Set the given query function for the pad.
1357 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1359 g_return_if_fail (GST_IS_PAD (pad));
1361 GST_PAD_QUERYFUNC (pad) = query;
1363 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1364 GST_DEBUG_FUNCPTR_NAME (query));
1368 * gst_pad_set_query_type_function:
1369 * @pad: a #GstPad of either direction.
1370 * @type_func: the #GstPadQueryTypeFunction to set.
1372 * Set the given query type function for the pad.
1375 gst_pad_set_query_type_function (GstPad * pad,
1376 GstPadQueryTypeFunction type_func)
1378 g_return_if_fail (GST_IS_PAD (pad));
1380 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1382 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "querytypefunc set to %s",
1383 GST_DEBUG_FUNCPTR_NAME (type_func));
1387 * gst_pad_get_query_types:
1390 * Get an array of supported queries that can be performed
1393 * Returns: a zero-terminated array of #GstQueryType.
1395 const GstQueryType *
1396 gst_pad_get_query_types (GstPad * pad)
1398 GstPadQueryTypeFunction func;
1400 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1402 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1414 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1416 *data = gst_pad_get_query_types (pad);
1422 * gst_pad_get_query_types_default:
1425 * Invoke the default dispatcher for the query types on
1428 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1429 * internally-linked pads has a query types function.
1431 const GstQueryType *
1432 gst_pad_get_query_types_default (GstPad * pad)
1434 GstQueryType *result = NULL;
1436 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1438 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1439 gst_pad_get_query_types_dispatcher, &result);
1445 * gst_pad_set_iterate_internal_links_function:
1446 * @pad: a #GstPad of either direction.
1447 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1449 * Sets the given internal link iterator function for the pad.
1454 gst_pad_set_iterate_internal_links_function (GstPad * pad,
1455 GstPadIterIntLinkFunction iterintlink)
1457 g_return_if_fail (GST_IS_PAD (pad));
1459 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1460 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1461 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1465 * gst_pad_set_internal_link_function:
1466 * @pad: a #GstPad of either direction.
1467 * @intlink: the #GstPadIntLinkFunction to set.
1469 * Sets the given internal link function for the pad.
1471 * Deprecated: Use the thread-safe gst_pad_set_iterate_internal_links_function()
1473 #ifndef GST_REMOVE_DEPRECATED
1475 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1477 g_return_if_fail (GST_IS_PAD (pad));
1479 GST_PAD_INTLINKFUNC (pad) = intlink;
1480 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link set to %s",
1481 GST_DEBUG_FUNCPTR_NAME (intlink));
1483 #endif /* GST_REMOVE_DEPRECATED */
1486 * gst_pad_set_link_function:
1488 * @link: the #GstPadLinkFunction to set.
1490 * Sets the given link function for the pad. It will be called when
1491 * the pad is linked with another pad.
1493 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1496 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1497 * cannot be made for some reason.
1499 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1500 * of the peer sink pad, if present.
1503 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1505 g_return_if_fail (GST_IS_PAD (pad));
1507 GST_PAD_LINKFUNC (pad) = link;
1508 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1509 GST_DEBUG_FUNCPTR_NAME (link));
1513 * gst_pad_set_unlink_function:
1515 * @unlink: the #GstPadUnlinkFunction to set.
1517 * Sets the given unlink function for the pad. It will be called
1518 * when the pad is unlinked.
1521 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1523 g_return_if_fail (GST_IS_PAD (pad));
1525 GST_PAD_UNLINKFUNC (pad) = unlink;
1526 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1527 GST_DEBUG_FUNCPTR_NAME (unlink));
1531 * gst_pad_set_getcaps_function:
1533 * @getcaps: the #GstPadGetCapsFunction to set.
1535 * Sets the given getcaps function for the pad. @getcaps should return the
1536 * allowable caps for a pad in the context of the element's state, its link to
1537 * other elements, and the devices or files it has opened. These caps must be a
1538 * subset of the pad template caps. In the NULL state with no links, @getcaps
1539 * should ideally return the same caps as the pad template. In rare
1540 * circumstances, an object property can affect the caps returned by @getcaps,
1541 * but this is discouraged.
1543 * You do not need to call this function if @pad's allowed caps are always the
1544 * same as the pad template caps. This can only be true if the padtemplate
1545 * has fixed simple caps.
1547 * For most filters, the caps returned by @getcaps is directly affected by the
1548 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1549 * the srcpad's getcaps function is directly related to the stream data. Again,
1550 * @getcaps should return the most specific caps it reasonably can, since this
1551 * helps with autoplugging.
1553 * Note that the return value from @getcaps is owned by the caller, so the
1554 * caller should unref the caps after usage.
1557 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1559 g_return_if_fail (GST_IS_PAD (pad));
1561 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1562 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getcapsfunc set to %s",
1563 GST_DEBUG_FUNCPTR_NAME (getcaps));
1567 * gst_pad_set_acceptcaps_function:
1569 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1571 * Sets the given acceptcaps function for the pad. The acceptcaps function
1572 * will be called to check if the pad can accept the given caps. Setting the
1573 * acceptcaps function to NULL restores the default behaviour of allowing
1574 * any caps that matches the caps from gst_pad_get_caps.
1577 gst_pad_set_acceptcaps_function (GstPad * pad,
1578 GstPadAcceptCapsFunction acceptcaps)
1580 g_return_if_fail (GST_IS_PAD (pad));
1582 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1583 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "acceptcapsfunc set to %s",
1584 GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1588 * gst_pad_set_fixatecaps_function:
1590 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1592 * Sets the given fixatecaps function for the pad. The fixatecaps function
1593 * will be called whenever the default values for a GstCaps needs to be
1597 gst_pad_set_fixatecaps_function (GstPad * pad,
1598 GstPadFixateCapsFunction fixatecaps)
1600 g_return_if_fail (GST_IS_PAD (pad));
1602 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1603 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fixatecapsfunc set to %s",
1604 GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1608 * gst_pad_set_setcaps_function:
1610 * @setcaps: the #GstPadSetCapsFunction to set.
1612 * Sets the given setcaps function for the pad. The setcaps function
1613 * will be called whenever a buffer with a new media type is pushed or
1614 * pulled from the pad. The pad/element needs to update its internal
1615 * structures to process the new media type. If this new type is not
1616 * acceptable, the setcaps function should return FALSE.
1619 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1621 g_return_if_fail (GST_IS_PAD (pad));
1623 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1624 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "setcapsfunc set to %s",
1625 GST_DEBUG_FUNCPTR_NAME (setcaps));
1629 * gst_pad_set_bufferalloc_function:
1630 * @pad: a sink #GstPad.
1631 * @bufalloc: the #GstPadBufferAllocFunction to set.
1633 * Sets the given bufferalloc function for the pad. Note that the
1634 * bufferalloc function can only be set on sinkpads.
1637 gst_pad_set_bufferalloc_function (GstPad * pad,
1638 GstPadBufferAllocFunction bufalloc)
1640 g_return_if_fail (GST_IS_PAD (pad));
1641 g_return_if_fail (GST_PAD_IS_SINK (pad));
1643 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1644 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "bufferallocfunc set to %s",
1645 GST_DEBUG_FUNCPTR_NAME (bufalloc));
1650 * @srcpad: the source #GstPad to unlink.
1651 * @sinkpad: the sink #GstPad to unlink.
1653 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1654 * signal on both pads.
1656 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1657 * the pads were not linked together.
1662 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1664 gboolean result = FALSE;
1665 GstElement *parent = NULL;
1667 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1668 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1669 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1670 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1672 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1673 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1674 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1676 /* We need to notify the parent before taking any pad locks as the bin in
1677 * question might be waiting for a lock on the pad while holding its lock
1678 * that our message will try to take. */
1679 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1680 if (GST_IS_ELEMENT (parent)) {
1681 gst_element_post_message (parent,
1682 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1683 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1685 gst_object_unref (parent);
1690 GST_OBJECT_LOCK (srcpad);
1692 GST_OBJECT_LOCK (sinkpad);
1694 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1695 goto not_linked_together;
1697 if (GST_PAD_UNLINKFUNC (srcpad)) {
1698 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1700 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1701 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1704 /* first clear peers */
1705 GST_PAD_PEER (srcpad) = NULL;
1706 GST_PAD_PEER (sinkpad) = NULL;
1708 GST_OBJECT_UNLOCK (sinkpad);
1709 GST_OBJECT_UNLOCK (srcpad);
1711 /* fire off a signal to each of the pads telling them
1712 * that they've been unlinked */
1713 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1714 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1716 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1717 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1722 if (parent != NULL) {
1723 gst_element_post_message (parent,
1724 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1725 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1726 gst_object_unref (parent);
1731 not_linked_together:
1733 /* we do not emit a warning in this case because unlinking cannot
1734 * be made MT safe.*/
1735 GST_OBJECT_UNLOCK (sinkpad);
1736 GST_OBJECT_UNLOCK (srcpad);
1742 * gst_pad_is_linked:
1743 * @pad: pad to check
1745 * Checks if a @pad is linked to another pad or not.
1747 * Returns: TRUE if the pad is linked, FALSE otherwise.
1752 gst_pad_is_linked (GstPad * pad)
1756 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1758 GST_OBJECT_LOCK (pad);
1759 result = (GST_PAD_PEER (pad) != NULL);
1760 GST_OBJECT_UNLOCK (pad);
1765 /* get the caps from both pads and see if the intersection
1768 * This function should be called with the pad LOCK on both
1772 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1776 gboolean compatible = FALSE;
1778 srccaps = gst_pad_get_caps_unlocked (src);
1779 sinkcaps = gst_pad_get_caps_unlocked (sink);
1781 GST_CAT_DEBUG (GST_CAT_CAPS, "src caps %" GST_PTR_FORMAT, srccaps);
1782 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1784 /* if we have caps on both pads we can check the intersection. If one
1785 * of the caps is NULL, we return TRUE. */
1786 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1788 gst_caps_unref (srccaps);
1790 gst_caps_unref (sinkcaps);
1794 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1795 gst_caps_unref (srccaps);
1796 gst_caps_unref (sinkcaps);
1799 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1800 (compatible ? "" : "not"));
1805 /* check if the grandparents of both pads are the same.
1806 * This check is required so that we don't try to link
1807 * pads from elements in different bins without ghostpads.
1809 * The LOCK should be held on both pads
1812 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1814 GstObject *psrc, *psink;
1816 psrc = GST_OBJECT_PARENT (src);
1817 psink = GST_OBJECT_PARENT (sink);
1819 /* if one of the pads has no parent, we allow the link */
1820 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1823 /* only care about parents that are elements */
1824 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1825 goto no_element_parent;
1827 /* if the parents are the same, we have a loop */
1828 if (G_UNLIKELY (psrc == psink))
1831 /* if they both have a parent, we check the grandparents. We can not lock
1832 * the parent because we hold on the child (pad) and the locking order is
1833 * parent >> child. */
1834 psrc = GST_OBJECT_PARENT (psrc);
1835 psink = GST_OBJECT_PARENT (psink);
1837 /* if they have grandparents but they are not the same */
1838 if (G_UNLIKELY (psrc != psink))
1839 goto wrong_grandparents;
1846 GST_CAT_DEBUG (GST_CAT_CAPS,
1847 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1848 GST_PTR_FORMAT, psrc, psink);
1853 GST_CAT_DEBUG (GST_CAT_CAPS,
1854 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1855 GST_PTR_FORMAT, psrc, psink);
1860 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1866 GST_CAT_DEBUG (GST_CAT_CAPS,
1867 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1868 GST_PTR_FORMAT, psrc, psink);
1873 /* FIXME leftover from an attempt at refactoring... */
1874 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1875 * the two pads will be locked in the srcpad, sinkpad order. */
1876 static GstPadLinkReturn
1877 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1879 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1880 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1882 GST_OBJECT_LOCK (srcpad);
1884 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1885 goto src_was_linked;
1887 GST_OBJECT_LOCK (sinkpad);
1889 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1890 goto sink_was_linked;
1892 /* check hierarchy, pads can only be linked if the grandparents
1894 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1895 goto wrong_hierarchy;
1897 /* check pad caps for non-empty intersection */
1898 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1901 /* FIXME check pad scheduling for non-empty intersection */
1903 return GST_PAD_LINK_OK;
1907 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1908 GST_DEBUG_PAD_NAME (srcpad),
1909 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1910 /* we do not emit a warning in this case because unlinking cannot
1911 * be made MT safe.*/
1912 GST_OBJECT_UNLOCK (srcpad);
1913 return GST_PAD_LINK_WAS_LINKED;
1917 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1918 GST_DEBUG_PAD_NAME (sinkpad),
1919 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1920 /* we do not emit a warning in this case because unlinking cannot
1921 * be made MT safe.*/
1922 GST_OBJECT_UNLOCK (sinkpad);
1923 GST_OBJECT_UNLOCK (srcpad);
1924 return GST_PAD_LINK_WAS_LINKED;
1928 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1929 GST_OBJECT_UNLOCK (sinkpad);
1930 GST_OBJECT_UNLOCK (srcpad);
1931 return GST_PAD_LINK_WRONG_HIERARCHY;
1935 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1936 GST_OBJECT_UNLOCK (sinkpad);
1937 GST_OBJECT_UNLOCK (srcpad);
1938 return GST_PAD_LINK_NOFORMAT;
1944 * @srcpad: the source #GstPad.
1945 * @sinkpad: the sink #GstPad.
1947 * Checks if the source pad and the sink pad are compatible so they can be
1950 * Returns: TRUE if the pads can be linked.
1953 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1955 GstPadLinkReturn result;
1957 /* generic checks */
1958 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1959 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1961 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1962 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1964 /* gst_pad_link_prepare does everything for us, we only release the locks
1965 * on the pads that it gets us. If this function returns !OK the locks are not
1967 result = gst_pad_link_prepare (srcpad, sinkpad);
1968 if (result != GST_PAD_LINK_OK)
1971 GST_OBJECT_UNLOCK (srcpad);
1972 GST_OBJECT_UNLOCK (sinkpad);
1975 return result == GST_PAD_LINK_OK;
1980 * @srcpad: the source #GstPad to link.
1981 * @sinkpad: the sink #GstPad to link.
1983 * Links the source pad and the sink pad.
1985 * Returns: A result code indicating if the connection worked or
1991 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1993 GstPadLinkReturn result;
1996 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1997 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
1998 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1999 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2000 GST_PAD_LINK_WRONG_DIRECTION);
2002 /* Notify the parent early. See gst_pad_unlink for details. */
2003 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
2004 if (GST_IS_ELEMENT (parent)) {
2005 gst_element_post_message (parent,
2006 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2007 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2009 gst_object_unref (parent);
2014 /* prepare will also lock the two pads */
2015 result = gst_pad_link_prepare (srcpad, sinkpad);
2017 if (result != GST_PAD_LINK_OK)
2020 /* must set peers before calling the link function */
2021 GST_PAD_PEER (srcpad) = sinkpad;
2022 GST_PAD_PEER (sinkpad) = srcpad;
2024 GST_OBJECT_UNLOCK (sinkpad);
2025 GST_OBJECT_UNLOCK (srcpad);
2027 /* FIXME released the locks here, concurrent thread might link
2028 * something else. */
2029 if (GST_PAD_LINKFUNC (srcpad)) {
2030 /* this one will call the peer link function */
2031 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
2032 } else if (GST_PAD_LINKFUNC (sinkpad)) {
2033 /* if no source link function, we need to call the sink link
2034 * function ourselves. */
2035 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
2037 result = GST_PAD_LINK_OK;
2040 GST_OBJECT_LOCK (srcpad);
2041 GST_OBJECT_LOCK (sinkpad);
2043 if (result == GST_PAD_LINK_OK) {
2044 GST_OBJECT_UNLOCK (sinkpad);
2045 GST_OBJECT_UNLOCK (srcpad);
2047 /* fire off a signal to each of the pads telling them
2048 * that they've been linked */
2049 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2050 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2052 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2053 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2055 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2056 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2058 GST_PAD_PEER (srcpad) = NULL;
2059 GST_PAD_PEER (sinkpad) = NULL;
2061 GST_OBJECT_UNLOCK (sinkpad);
2062 GST_OBJECT_UNLOCK (srcpad);
2067 gst_element_post_message (parent,
2068 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2069 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2070 gst_object_unref (parent);
2077 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2079 GstPadTemplate **template_p;
2081 /* this function would need checks if it weren't static */
2083 GST_OBJECT_LOCK (pad);
2084 template_p = &pad->padtemplate;
2085 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2086 GST_OBJECT_UNLOCK (pad);
2089 gst_pad_template_pad_created (templ, pad);
2093 * gst_pad_get_pad_template:
2096 * Gets the template for @pad.
2098 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
2099 * if this pad has no template.
2101 * FIXME: currently returns an unrefcounted padtemplate.
2104 gst_pad_get_pad_template (GstPad * pad)
2106 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2108 return GST_PAD_PAD_TEMPLATE (pad);
2112 /* should be called with the pad LOCK held */
2113 /* refs the caps, so caller is responsible for getting it unreffed */
2115 gst_pad_get_caps_unlocked (GstPad * pad)
2117 GstCaps *result = NULL;
2118 GstPadTemplate *templ;
2120 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2122 if (GST_PAD_GETCAPSFUNC (pad)) {
2123 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2124 "dispatching to pad getcaps function");
2126 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
2127 GST_OBJECT_UNLOCK (pad);
2128 result = GST_PAD_GETCAPSFUNC (pad) (pad);
2129 GST_OBJECT_LOCK (pad);
2130 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
2132 if (result == NULL) {
2133 g_critical ("pad %s:%s returned NULL caps from getcaps function",
2134 GST_DEBUG_PAD_NAME (pad));
2136 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2137 "pad getcaps returned %" GST_PTR_FORMAT, result);
2138 #ifndef G_DISABLE_ASSERT
2139 /* check that the returned caps are a real subset of the template caps */
2140 if (GST_PAD_PAD_TEMPLATE (pad)) {
2141 const GstCaps *templ_caps =
2142 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2143 if (!gst_caps_is_subset (result, templ_caps)) {
2146 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2147 "pad returned caps %" GST_PTR_FORMAT
2148 " which are not a real subset of its template caps %"
2149 GST_PTR_FORMAT, result, templ_caps);
2151 ("pad %s:%s returned caps which are not a real "
2152 "subset of its template caps", GST_DEBUG_PAD_NAME (pad));
2153 temp = gst_caps_intersect (templ_caps, result);
2154 gst_caps_unref (result);
2162 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2163 result = GST_PAD_TEMPLATE_CAPS (templ);
2164 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2165 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
2168 result = gst_caps_ref (result);
2171 if ((result = GST_PAD_CAPS (pad))) {
2172 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2173 "using pad caps %p %" GST_PTR_FORMAT, result, result);
2175 result = gst_caps_ref (result);
2179 /* this almost never happens */
2180 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2181 result = gst_caps_new_empty ();
2187 /* FIXME-0.11: what about making this the default and using
2188 * gst_caps_make_writable() explicitely where needed
2191 * gst_pad_get_caps_reffed:
2192 * @pad: a #GstPad to get the capabilities of.
2194 * Gets the capabilities this pad can produce or consume. Preferred function if
2195 * one only wants to read or intersect the caps.
2197 * Returns: the caps of the pad with incremented ref-count.
2202 gst_pad_get_caps_reffed (GstPad * pad)
2204 GstCaps *result = NULL;
2206 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2208 GST_OBJECT_LOCK (pad);
2210 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2212 result = gst_pad_get_caps_unlocked (pad);
2214 GST_OBJECT_UNLOCK (pad);
2221 * @pad: a #GstPad to get the capabilities of.
2223 * Gets the capabilities this pad can produce or consume.
2224 * Note that this method doesn't necessarily return the caps set by
2225 * gst_pad_set_caps() - use GST_PAD_CAPS() for that instead.
2226 * gst_pad_get_caps returns all possible caps a pad can operate with, using
2227 * the pad's get_caps function;
2228 * this returns the pad template caps if not explicitly set.
2230 * Returns: a newly allocated copy of the #GstCaps of this pad.
2235 gst_pad_get_caps (GstPad * pad)
2237 GstCaps *result = gst_pad_get_caps_reffed (pad);
2239 /* be sure that we have a copy */
2240 if (G_LIKELY (result))
2241 result = gst_caps_make_writable (result);
2246 /* FIXME-0.11: what about making this the default and using
2247 * gst_caps_make_writable() explicitely where needed
2250 * gst_pad_peer_get_caps_reffed:
2251 * @pad: a #GstPad to get the capabilities of.
2253 * Gets the capabilities of the peer connected to this pad. Preferred function
2254 * if one only wants to read or intersect the caps.
2256 * Returns: the caps of the pad with incremented ref-count.
2261 gst_pad_peer_get_caps_reffed (GstPad * pad)
2264 GstCaps *result = NULL;
2266 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2268 GST_OBJECT_LOCK (pad);
2270 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2272 peerpad = GST_PAD_PEER (pad);
2273 if (G_UNLIKELY (peerpad == NULL))
2276 gst_object_ref (peerpad);
2277 GST_OBJECT_UNLOCK (pad);
2279 result = gst_pad_get_caps_reffed (peerpad);
2281 gst_object_unref (peerpad);
2287 GST_OBJECT_UNLOCK (pad);
2293 * gst_pad_peer_get_caps:
2294 * @pad: a #GstPad to get the peer capabilities of.
2296 * Gets the capabilities of the peer connected to this pad. Similar to
2297 * gst_pad_get_caps().
2299 * Returns: a newly allocated copy of the #GstCaps of the peer pad. Use
2300 * gst_caps_unref() to get rid of it. This function returns %NULL if there is
2304 gst_pad_peer_get_caps (GstPad * pad)
2307 GstCaps *result = NULL;
2309 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2311 GST_OBJECT_LOCK (pad);
2313 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2315 peerpad = GST_PAD_PEER (pad);
2316 if (G_UNLIKELY (peerpad == NULL))
2319 gst_object_ref (peerpad);
2320 GST_OBJECT_UNLOCK (pad);
2322 result = gst_pad_get_caps (peerpad);
2324 gst_object_unref (peerpad);
2330 GST_OBJECT_UNLOCK (pad);
2336 fixate_value (GValue * dest, const GValue * src)
2338 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
2339 g_value_init (dest, G_TYPE_INT);
2340 g_value_set_int (dest, gst_value_get_int_range_min (src));
2341 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
2342 g_value_init (dest, G_TYPE_DOUBLE);
2343 g_value_set_double (dest, gst_value_get_double_range_min (src));
2344 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
2345 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
2346 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
2347 GValue temp = { 0 };
2349 /* list could be empty */
2350 if (gst_value_list_get_size (src) <= 0)
2353 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
2355 if (!fixate_value (dest, &temp))
2356 gst_value_init_and_copy (dest, &temp);
2357 g_value_unset (&temp);
2358 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
2359 gboolean res = FALSE;
2362 len = gst_value_array_get_size (src);
2363 g_value_init (dest, GST_TYPE_ARRAY);
2364 for (n = 0; n < len; n++) {
2366 const GValue *orig_kid = gst_value_array_get_value (src, n);
2368 if (!fixate_value (&kid, orig_kid))
2369 gst_value_init_and_copy (&kid, orig_kid);
2372 gst_value_array_append_value (dest, &kid);
2373 g_value_unset (&kid);
2377 g_value_unset (dest);
2388 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
2390 GstStructure *s = data;
2393 if (fixate_value (&v, value)) {
2394 gst_structure_id_set_value (s, field_id, &v);
2402 * gst_pad_fixate_caps:
2403 * @pad: a #GstPad to fixate
2404 * @caps: the #GstCaps to fixate
2406 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2407 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2410 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2412 GstPadFixateCapsFunction fixatefunc;
2415 g_return_if_fail (GST_IS_PAD (pad));
2416 g_return_if_fail (caps != NULL);
2418 if (gst_caps_is_fixed (caps))
2421 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
2423 fixatefunc (pad, caps);
2426 /* default fixation */
2427 len = gst_caps_get_size (caps);
2429 GstStructure *s = gst_caps_get_structure (caps, 0);
2431 gst_structure_foreach (s, gst_pad_default_fixate, s);
2435 gst_caps_truncate (caps);
2439 /* Default accept caps implementation just checks against
2440 * against the allowed caps for the pad */
2442 gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
2444 /* get the caps and see if it intersects to something not empty */
2446 gboolean result = FALSE;
2448 GST_DEBUG_OBJECT (pad, "caps %" GST_PTR_FORMAT, caps);
2450 allowed = gst_pad_get_caps_reffed (pad);
2452 goto nothing_allowed;
2454 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2456 result = gst_caps_can_intersect (allowed, caps);
2458 gst_caps_unref (allowed);
2465 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2471 * gst_pad_accept_caps:
2472 * @pad: a #GstPad to check
2473 * @caps: a #GstCaps to check on the pad
2475 * Check if the given pad accepts the caps.
2477 * Returns: TRUE if the pad can accept the caps.
2480 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2483 GstPadAcceptCapsFunction acceptfunc;
2484 GstCaps *existing = NULL;
2486 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2488 /* any pad can be unnegotiated */
2492 /* lock for checking the existing caps */
2493 GST_OBJECT_LOCK (pad);
2494 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "accept caps of %p", caps);
2495 /* The current caps on a pad are trivially acceptable */
2496 if (G_LIKELY ((existing = GST_PAD_CAPS (pad)))) {
2497 if (caps == existing || gst_caps_is_equal (caps, existing))
2500 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2501 GST_OBJECT_UNLOCK (pad);
2503 if (G_LIKELY (acceptfunc)) {
2504 /* we can call the function */
2505 result = acceptfunc (pad, caps);
2506 GST_DEBUG_OBJECT (pad, "acceptfunc returned %d", result);
2508 /* Only null if the element explicitly unset it */
2509 result = gst_pad_acceptcaps_default (pad, caps);
2510 GST_DEBUG_OBJECT (pad, "default acceptcaps returned %d", result);
2516 GST_DEBUG_OBJECT (pad, "pad had same caps");
2517 GST_OBJECT_UNLOCK (pad);
2523 * gst_pad_peer_accept_caps:
2524 * @pad: a #GstPad to check the peer of
2525 * @caps: a #GstCaps to check on the pad
2527 * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
2530 * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
2533 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2538 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2540 GST_OBJECT_LOCK (pad);
2542 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "peer accept caps of (%p)", pad);
2544 peerpad = GST_PAD_PEER (pad);
2545 if (G_UNLIKELY (peerpad == NULL))
2548 gst_object_ref (peerpad);
2549 /* release lock before calling external methods but keep ref to pad */
2550 GST_OBJECT_UNLOCK (pad);
2552 result = gst_pad_accept_caps (peerpad, caps);
2554 gst_object_unref (peerpad);
2560 GST_OBJECT_UNLOCK (pad);
2567 * @pad: a #GstPad to set the capabilities of.
2568 * @caps: a #GstCaps to set.
2570 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2571 * caps on the pad will be unreffed. This function refs the caps so you should
2572 * unref if as soon as you don't need it anymore.
2573 * It is possible to set NULL caps, which will make the pad unnegotiated
2576 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2577 * or bad parameters were provided to this function.
2582 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2584 GstPadSetCapsFunction setcaps;
2587 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2588 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2590 GST_OBJECT_LOCK (pad);
2591 existing = GST_PAD_CAPS (pad);
2592 if (existing == caps)
2595 if (gst_caps_is_equal (caps, existing))
2596 goto setting_same_caps;
2598 setcaps = GST_PAD_SETCAPSFUNC (pad);
2600 /* call setcaps function to configure the pad only if the
2601 * caps is not NULL */
2602 if (setcaps != NULL && caps) {
2603 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2604 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2605 GST_OBJECT_UNLOCK (pad);
2606 if (!setcaps (pad, caps))
2608 GST_OBJECT_LOCK (pad);
2609 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2611 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad was dispatching");
2615 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2616 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "caps %p %" GST_PTR_FORMAT, caps,
2618 GST_OBJECT_UNLOCK (pad);
2620 g_object_notify (G_OBJECT (pad), "caps");
2626 GST_OBJECT_UNLOCK (pad);
2631 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2632 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2633 "caps %p %" GST_PTR_FORMAT " same as existing, updating ptr only", caps,
2635 GST_OBJECT_UNLOCK (pad);
2642 GST_OBJECT_LOCK (pad);
2643 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2644 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2645 "caps %" GST_PTR_FORMAT " could not be set", caps);
2646 GST_OBJECT_UNLOCK (pad);
2653 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2657 /* See if pad accepts the caps */
2658 if (!gst_pad_accept_caps (pad, caps))
2661 /* set caps on pad if call succeeds */
2662 res = gst_pad_set_caps (pad, caps);
2663 /* no need to unref the caps here, set_caps takes a ref and
2664 * our ref goes away when we leave this function. */
2670 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2671 "caps %" GST_PTR_FORMAT " not accepted", caps);
2676 /* returns TRUE if the src pad could be configured to accept the given caps */
2678 gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
2683 /* See if pad accepts the caps */
2684 if (!gst_pad_accept_caps (pad, caps))
2687 res = gst_pad_set_caps (pad, caps);
2695 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2696 "caps %" GST_PTR_FORMAT " not accepted", caps);
2702 * gst_pad_get_pad_template_caps:
2703 * @pad: a #GstPad to get the template capabilities from.
2705 * Gets the capabilities for @pad's template.
2707 * Returns: the #GstCaps of this pad template. If you intend to keep a
2708 * reference on the caps, make a copy (see gst_caps_copy ()).
2711 gst_pad_get_pad_template_caps (GstPad * pad)
2713 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2715 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2717 if (GST_PAD_PAD_TEMPLATE (pad))
2718 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2720 return gst_static_caps_get (&anycaps);
2725 * @pad: a #GstPad to get the peer of.
2727 * Gets the peer of @pad. This function refs the peer pad so
2728 * you need to unref it after use.
2730 * Returns: the peer #GstPad. Unref after usage.
2735 gst_pad_get_peer (GstPad * pad)
2739 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2741 GST_OBJECT_LOCK (pad);
2742 result = GST_PAD_PEER (pad);
2744 gst_object_ref (result);
2745 GST_OBJECT_UNLOCK (pad);
2751 * gst_pad_get_allowed_caps:
2754 * Gets the capabilities of the allowed media types that can flow through
2755 * @pad and its peer.
2757 * The allowed capabilities is calculated as the intersection of the results of
2758 * calling gst_pad_get_caps() on @pad and its peer. The caller owns a reference
2759 * on the resulting caps.
2761 * Returns: the allowed #GstCaps of the pad link. Unref the caps when you no
2762 * longer need it. This function returns NULL when @pad has no peer.
2767 gst_pad_get_allowed_caps (GstPad * pad)
2774 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2776 GST_OBJECT_LOCK (pad);
2778 peer = GST_PAD_PEER (pad);
2779 if (G_UNLIKELY (peer == NULL))
2782 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2784 gst_object_ref (peer);
2785 GST_OBJECT_UNLOCK (pad);
2786 mycaps = gst_pad_get_caps_reffed (pad);
2788 peercaps = gst_pad_get_caps_reffed (peer);
2789 gst_object_unref (peer);
2791 caps = gst_caps_intersect (mycaps, peercaps);
2792 gst_caps_unref (peercaps);
2793 gst_caps_unref (mycaps);
2795 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2802 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2803 GST_OBJECT_UNLOCK (pad);
2810 * gst_pad_get_negotiated_caps:
2813 * Gets the capabilities of the media type that currently flows through @pad
2816 * This function can be used on both src and sinkpads. Note that srcpads are
2817 * always negotiated before sinkpads so it is possible that the negotiated caps
2818 * on the srcpad do not match the negotiated caps of the peer.
2820 * Returns: the negotiated #GstCaps of the pad link. Unref the caps when
2821 * you no longer need it. This function returns NULL when the @pad has no
2822 * peer or is not negotiated yet.
2827 gst_pad_get_negotiated_caps (GstPad * pad)
2832 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2834 GST_OBJECT_LOCK (pad);
2836 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2839 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting negotiated caps");
2841 caps = GST_PAD_CAPS (pad);
2843 gst_caps_ref (caps);
2844 GST_OBJECT_UNLOCK (pad);
2846 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "negotiated caps %" GST_PTR_FORMAT,
2853 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2854 GST_OBJECT_UNLOCK (pad);
2860 /* calls the buffer_alloc function on the given pad */
2861 static GstFlowReturn
2862 gst_pad_buffer_alloc_unchecked (GstPad * pad, guint64 offset, gint size,
2863 GstCaps * caps, GstBuffer ** buf)
2866 GstPadBufferAllocFunction bufferallocfunc;
2868 GST_OBJECT_LOCK (pad);
2869 /* when the pad is flushing we cannot give a buffer */
2870 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2873 bufferallocfunc = pad->bufferallocfunc;
2875 if (offset == GST_BUFFER_OFFSET_NONE) {
2876 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2877 "calling bufferallocfunc &%s (@%p) for size %d offset NONE",
2878 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc), bufferallocfunc, size);
2880 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2881 "calling bufferallocfunc &%s (@%p) of for size %d offset %"
2882 G_GUINT64_FORMAT, GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2883 bufferallocfunc, size, offset);
2885 GST_OBJECT_UNLOCK (pad);
2887 /* G_LIKELY for now since most elements don't implement a buffer alloc
2888 * function and there is no default alloc proxy function as this is usually
2890 if (G_LIKELY (bufferallocfunc == NULL))
2893 ret = bufferallocfunc (pad, offset, size, caps, buf);
2895 if (G_UNLIKELY (ret != GST_FLOW_OK))
2898 /* no error, but NULL buffer means fallback to the default */
2899 if (G_UNLIKELY (*buf == NULL))
2902 /* If the buffer alloc function didn't set up the caps like it should,
2904 if (G_UNLIKELY (caps && (GST_BUFFER_CAPS (*buf) == NULL))) {
2905 GST_WARNING_OBJECT (pad,
2906 "Buffer allocation function did not set caps. Setting");
2907 gst_buffer_set_caps (*buf, caps);
2913 /* pad was flushing */
2914 GST_OBJECT_UNLOCK (pad);
2915 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "pad was flushing");
2916 return GST_FLOW_WRONG_STATE;
2920 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2921 "alloc function returned error (%d) %s", ret, gst_flow_get_name (ret));
2926 /* fallback case, allocate a buffer of our own, add pad caps. */
2927 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fallback buffer alloc");
2929 if ((*buf = gst_buffer_try_new_and_alloc (size))) {
2930 GST_BUFFER_OFFSET (*buf) = offset;
2931 gst_buffer_set_caps (*buf, caps);
2934 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2935 "out of memory allocating %d bytes", size);
2936 return GST_FLOW_ERROR;
2941 /* FIXME 0.11: size should be unsigned */
2942 static GstFlowReturn
2943 gst_pad_alloc_buffer_full (GstPad * pad, guint64 offset, gint size,
2944 GstCaps * caps, GstBuffer ** buf, gboolean setcaps)
2949 gboolean caps_changed;
2951 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2952 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2953 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2954 g_return_val_if_fail (size >= 0, GST_FLOW_ERROR);
2956 GST_DEBUG_OBJECT (pad, "offset %" G_GUINT64_FORMAT ", size %d, caps %"
2957 GST_PTR_FORMAT, offset, size, caps);
2959 GST_OBJECT_LOCK (pad);
2960 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2961 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
2964 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2967 gst_object_ref (peer);
2968 GST_OBJECT_UNLOCK (pad);
2970 ret = gst_pad_buffer_alloc_unchecked (peer, offset, size, caps, buf);
2971 gst_object_unref (peer);
2973 if (G_UNLIKELY (ret != GST_FLOW_OK))
2976 /* FIXME, move capnego this into a base class? */
2977 newcaps = GST_BUFFER_CAPS (*buf);
2979 /* Lock for checking caps, pretty pointless as the _pad_push() function might
2980 * change it concurrently, one of the problems with automatic caps setting in
2981 * pad_alloc_and_set_caps. Worst case, if does a check too much, but only
2982 * when there is heavy renegotiation going on in both directions. */
2983 GST_OBJECT_LOCK (pad);
2984 caps_changed = newcaps && newcaps != GST_PAD_CAPS (pad);
2985 GST_OBJECT_UNLOCK (pad);
2987 /* we got a new datatype on the pad, see if it can handle it */
2988 if (G_UNLIKELY (caps_changed)) {
2989 GST_DEBUG_OBJECT (pad,
2990 "caps changed from %" GST_PTR_FORMAT " to %p %" GST_PTR_FORMAT,
2991 GST_PAD_CAPS (pad), newcaps, newcaps);
2992 if (G_UNLIKELY (!gst_pad_configure_src (pad, newcaps, setcaps)))
2993 goto not_negotiated;
2996 /* sanity check (only if caps are the same) */
2997 if (G_LIKELY (newcaps == caps) && G_UNLIKELY (GST_BUFFER_SIZE (*buf) < size))
2998 goto wrong_size_fallback;
3004 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "pad block stopped by flush");
3005 GST_OBJECT_UNLOCK (pad);
3010 /* pad has no peer */
3011 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3012 "called bufferallocfunc but had no peer");
3013 GST_OBJECT_UNLOCK (pad);
3014 return GST_FLOW_NOT_LINKED;
3018 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3019 "alloc function returned error %s", gst_flow_get_name (ret));
3024 gst_buffer_unref (*buf);
3026 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3027 "alloc function returned unacceptable buffer");
3028 return GST_FLOW_NOT_NEGOTIATED;
3030 wrong_size_fallback:
3032 GST_CAT_ERROR_OBJECT (GST_CAT_PADS, pad, "buffer returned by alloc "
3033 "function is too small (%u < %d), doing fallback buffer alloc",
3034 GST_BUFFER_SIZE (*buf), size);
3036 gst_buffer_unref (*buf);
3038 if ((*buf = gst_buffer_try_new_and_alloc (size))) {
3039 GST_BUFFER_OFFSET (*buf) = offset;
3040 gst_buffer_set_caps (*buf, caps);
3043 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
3044 "out of memory allocating %d bytes", size);
3045 return GST_FLOW_ERROR;
3051 * gst_pad_alloc_buffer:
3052 * @pad: a source #GstPad
3053 * @offset: the offset of the new buffer in the stream
3054 * @size: the size of the new buffer
3055 * @caps: the caps of the new buffer
3056 * @buf: a newly allocated buffer
3058 * Allocates a new, empty buffer optimized to push to pad @pad. This
3059 * function only works if @pad is a source pad and has a peer.
3061 * A new, empty #GstBuffer will be put in the @buf argument.
3062 * You need to check the caps of the buffer after performing this
3063 * function and renegotiate to the format if needed. If the caps changed, it is
3064 * possible that the buffer returned in @buf is not of the right size for the
3065 * new format, @buf needs to be unreffed and reallocated if this is the case.
3067 * Returns: a result code indicating success of the operation. Any
3068 * result code other than #GST_FLOW_OK is an error and @buf should
3070 * An error can occur if the pad is not connected or when the downstream
3071 * peer elements cannot provide an acceptable buffer.
3076 /* FIXME 0.11: size should be unsigned */
3078 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
3081 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, FALSE);
3085 * gst_pad_alloc_buffer_and_set_caps:
3086 * @pad: a source #GstPad
3087 * @offset: the offset of the new buffer in the stream
3088 * @size: the size of the new buffer
3089 * @caps: the caps of the new buffer
3090 * @buf: a newly allocated buffer
3092 * In addition to the function gst_pad_alloc_buffer(), this function
3093 * automatically calls gst_pad_set_caps() when the caps of the
3094 * newly allocated buffer are different from the @pad caps.
3096 * After a renegotiation, the size of the new buffer returned in @buf could
3097 * be of the wrong size for the new format and must be unreffed an reallocated
3100 * Returns: a result code indicating success of the operation. Any
3101 * result code other than #GST_FLOW_OK is an error and @buf should
3103 * An error can occur if the pad is not connected or when the downstream
3104 * peer elements cannot provide an acceptable buffer.
3109 /* FIXME 0.11: size should be unsigned */
3111 gst_pad_alloc_buffer_and_set_caps (GstPad * pad, guint64 offset, gint size,
3112 GstCaps * caps, GstBuffer ** buf)
3114 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, TRUE);
3118 #ifndef GST_REMOVE_DEPRECATED
3126 int_link_iter_data_free (IntLinkIterData * data)
3128 g_list_free (data->list);
3133 static GstIteratorItem
3134 iterate_pad (GstIterator * it, GstPad * pad)
3136 gst_object_ref (pad);
3137 return GST_ITERATOR_ITEM_PASS;
3141 * gst_pad_iterate_internal_links_default:
3142 * @pad: the #GstPad to get the internal links of.
3144 * Iterate the list of pads to which the given pad is linked to inside of
3145 * the parent element.
3146 * This is the default handler, and thus returns an iterator of all of the
3147 * pads inside the parent element with opposite direction.
3149 * The caller must free this iterator after use with gst_iterator_free().
3151 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
3152 * returned pad with gst_object_unref().
3157 gst_pad_iterate_internal_links_default (GstPad * pad)
3164 GstIteratorDisposeFunction dispose;
3166 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3168 #ifndef GST_REMOVE_DEPRECATED
3169 /* when we get here, the default handler for the iterate links is called,
3170 * which means that the user has not installed a custom one. We first check if
3171 * there is maybe a custom legacy function we can call. */
3172 if (GST_PAD_INTLINKFUNC (pad) &&
3173 GST_PAD_INTLINKFUNC (pad) != gst_pad_get_internal_links_default) {
3174 IntLinkIterData *data;
3176 /* make an iterator for the list. We can't protect the list with a
3177 * cookie. If we would take the cookie of the parent element, we need to
3178 * have a parent, which is not required for GST_PAD_INTLINKFUNC(). We could
3179 * cache the per-pad list and invalidate the list when a new call to
3180 * INTLINKFUNC() returned a different list but then this would only work if
3181 * two concurrent iterators were used and the last iterator would still be
3182 * thread-unsafe. Just don't use this method anymore. */
3183 data = g_new0 (IntLinkIterData, 1);
3184 data->list = GST_PAD_INTLINKFUNC (pad) (pad);
3187 GST_WARNING_OBJECT (pad, "Making unsafe iterator");
3189 cookie = &data->cookie;
3190 padlist = &data->list;
3192 dispose = (GstIteratorDisposeFunction) int_link_iter_data_free;
3193 /* reuse the pad lock, it's all we have here */
3194 lock = GST_OBJECT_GET_LOCK (pad);
3200 GST_OBJECT_LOCK (pad);
3201 parent = GST_PAD_PARENT (pad);
3202 if (!parent || !GST_IS_ELEMENT (parent))
3205 gst_object_ref (parent);
3206 GST_OBJECT_UNLOCK (pad);
3208 if (pad->direction == GST_PAD_SRC)
3209 padlist = &parent->sinkpads;
3211 padlist = &parent->srcpads;
3213 GST_DEBUG_OBJECT (pad, "Making iterator");
3215 cookie = &parent->pads_cookie;
3217 dispose = (GstIteratorDisposeFunction) gst_object_unref;
3218 lock = GST_OBJECT_GET_LOCK (parent);
3221 res = gst_iterator_new_list (GST_TYPE_PAD,
3222 lock, cookie, padlist, owner, (GstIteratorItemFunction) iterate_pad,
3230 GST_OBJECT_UNLOCK (pad);
3231 GST_DEBUG_OBJECT (pad, "no parent element");
3237 * gst_pad_iterate_internal_links:
3238 * @pad: the GstPad to get the internal links of.
3240 * Gets an iterator for the pads to which the given pad is linked to inside
3241 * of the parent element.
3243 * Each #GstPad element yielded by the iterator will have its refcount increased,
3244 * so unref after use.
3246 * Returns: a new #GstIterator of #GstPad or %NULL when the pad does not have an
3247 * iterator function configured. Use gst_iterator_free() after usage.
3252 gst_pad_iterate_internal_links (GstPad * pad)
3254 GstIterator *res = NULL;
3256 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3258 if (GST_PAD_ITERINTLINKFUNC (pad))
3259 res = GST_PAD_ITERINTLINKFUNC (pad) (pad);
3264 #ifndef GST_REMOVE_DEPRECATED
3266 add_unref_pad_to_list (GstPad * pad, GList * list)
3268 list = g_list_prepend (list, pad);
3269 gst_object_unref (pad);
3274 * gst_pad_get_internal_links_default:
3275 * @pad: the #GstPad to get the internal links of.
3277 * Gets a list of pads to which the given pad is linked to
3278 * inside of the parent element.
3279 * This is the default handler, and thus returns a list of all of the
3280 * pads inside the parent element with opposite direction.
3282 * The caller must free this list after use with g_list_free().
3284 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
3288 * Deprecated: This function does not ref the pads in the list so that they
3289 * could become invalid by the time the application accesses them. It's also
3290 * possible that the list changes while handling the pads, which the caller of
3291 * this function is unable to know. Use the thread-safe
3292 * gst_pad_iterate_internal_links_default() instead.
3294 #ifndef GST_REMOVE_DEPRECATED
3296 gst_pad_get_internal_links_default (GstPad * pad)
3301 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3303 GST_WARNING_OBJECT (pad, "Unsafe internal links used");
3305 /* when we get here, the default handler for get_internal_links is called,
3306 * which means that the user has not installed a custom one. We first check if
3307 * there is maybe a custom iterate function we can call. */
3308 if (GST_PAD_ITERINTLINKFUNC (pad) &&
3309 GST_PAD_ITERINTLINKFUNC (pad) != gst_pad_iterate_internal_links_default) {
3311 GstIteratorResult ires;
3312 gboolean done = FALSE;
3314 it = gst_pad_iterate_internal_links (pad);
3315 /* loop over the iterator and put all elements into a list, we also
3316 * immediatly unref them, which is bad. */
3318 ires = gst_iterator_foreach (it, (GFunc) add_unref_pad_to_list, res);
3320 case GST_ITERATOR_OK:
3321 case GST_ITERATOR_DONE:
3322 case GST_ITERATOR_ERROR:
3325 case GST_ITERATOR_RESYNC:
3326 /* restart, discard previous list */
3327 gst_iterator_resync (it);
3334 gst_iterator_free (it);
3336 /* lock pad, check and ref parent */
3337 GST_OBJECT_LOCK (pad);
3338 parent = GST_PAD_PARENT (pad);
3339 if (!parent || !GST_IS_ELEMENT (parent))
3342 parent = gst_object_ref (parent);
3343 GST_OBJECT_UNLOCK (pad);
3345 /* now lock the parent while we copy the pads */
3346 GST_OBJECT_LOCK (parent);
3347 if (pad->direction == GST_PAD_SRC)
3348 res = g_list_copy (parent->sinkpads);
3350 res = g_list_copy (parent->srcpads);
3351 GST_OBJECT_UNLOCK (parent);
3353 gst_object_unref (parent);
3356 /* At this point pads can be changed and unreffed. Nothing we can do about it
3357 * because for compatibility reasons this function cannot ref the pads or
3358 * notify the app that the list changed. */
3364 GST_DEBUG_OBJECT (pad, "no parent");
3365 GST_OBJECT_UNLOCK (pad);
3369 #endif /* GST_REMOVE_DEPRECATED */
3372 * gst_pad_get_internal_links:
3373 * @pad: the #GstPad to get the internal links of.
3375 * Gets a list of pads to which the given pad is linked to
3376 * inside of the parent element.
3377 * The caller must free this list after use.
3381 * Returns: a newly allocated #GList of pads, free with g_list_free().
3383 * Deprecated: This function does not ref the pads in the list so that they
3384 * could become invalid by the time the application accesses them. It's also
3385 * possible that the list changes while handling the pads, which the caller of
3386 * this function is unable to know. Use the thread-safe
3387 * gst_pad_iterate_internal_links() instead.
3389 #ifndef GST_REMOVE_DEPRECATED
3391 gst_pad_get_internal_links (GstPad * pad)
3395 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3397 GST_WARNING_OBJECT (pad, "Calling unsafe internal links");
3399 if (GST_PAD_INTLINKFUNC (pad))
3400 res = GST_PAD_INTLINKFUNC (pad) (pad);
3404 #endif /* GST_REMOVE_DEPRECATED */
3407 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
3409 gboolean result = FALSE;
3411 gboolean done = FALSE;
3414 GList *pushed_pads = NULL;
3416 GST_INFO_OBJECT (pad, "Sending event %p (%s) to all internally linked pads",
3417 event, GST_EVENT_TYPE_NAME (event));
3419 iter = gst_pad_iterate_internal_links (pad);
3425 switch (gst_iterator_next (iter, &item)) {
3426 case GST_ITERATOR_OK:
3427 eventpad = GST_PAD_CAST (item);
3429 /* if already pushed, skip */
3430 if (g_list_find (pushed_pads, eventpad)) {
3431 gst_object_unref (item);
3435 if (GST_PAD_IS_SRC (eventpad)) {
3436 /* for each pad we send to, we should ref the event; it's up
3437 * to downstream to unref again when handled. */
3438 GST_LOG_OBJECT (pad, "Reffing and sending event %p (%s) to %s:%s",
3439 event, GST_EVENT_TYPE_NAME (event),
3440 GST_DEBUG_PAD_NAME (eventpad));
3441 gst_event_ref (event);
3442 result |= gst_pad_push_event (eventpad, event);
3444 /* we only send the event on one pad, multi-sinkpad elements
3445 * should implement a handler */
3446 GST_LOG_OBJECT (pad, "sending event %p (%s) to one sink pad %s:%s",
3447 event, GST_EVENT_TYPE_NAME (event),
3448 GST_DEBUG_PAD_NAME (eventpad));
3449 result = gst_pad_push_event (eventpad, event);
3454 pushed_pads = g_list_prepend (pushed_pads, eventpad);
3456 gst_object_unref (item);
3458 case GST_ITERATOR_RESYNC:
3459 /* FIXME, if we want to reset the result value we need to remember which
3460 * pads pushed with which result */
3461 gst_iterator_resync (iter);
3463 case GST_ITERATOR_ERROR:
3464 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3467 case GST_ITERATOR_DONE:
3472 gst_iterator_free (iter);
3476 /* If this is a sinkpad and we don't have pads to send the event to, we
3477 * return TRUE. This is so that when using the default handler on a sink
3478 * element, we don't fail to push it. */
3480 result = GST_PAD_IS_SINK (pad);
3482 g_list_free (pushed_pads);
3484 /* we handled the incoming event so we unref once */
3486 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
3487 gst_event_unref (event);
3494 * gst_pad_event_default:
3495 * @pad: a #GstPad to call the default event handler on.
3496 * @event: the #GstEvent to handle.
3498 * Invokes the default event handler for the given pad. End-of-stream and
3499 * discontinuity events are handled specially, and then the event is sent to all
3500 * pads internally linked to @pad. Note that if there are many possible sink
3501 * pads that are internally linked to @pad, only one will be sent an event.
3502 * Multi-sinkpad elements should implement custom event handlers.
3504 * Returns: TRUE if the event was sent succesfully.
3507 gst_pad_event_default (GstPad * pad, GstEvent * event)
3509 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3510 g_return_val_if_fail (event != NULL, FALSE);
3512 GST_LOG_OBJECT (pad, "default event handler");
3514 switch (GST_EVENT_TYPE (event)) {
3517 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
3518 gst_pad_pause_task (pad);
3525 return gst_pad_event_default_dispatch (pad, event);
3529 * gst_pad_dispatcher:
3530 * @pad: a #GstPad to dispatch.
3531 * @dispatch: the #GstPadDispatcherFunction to call.
3532 * @data: gpointer user data passed to the dispatcher function.
3534 * Invokes the given dispatcher function on each respective peer of
3535 * all pads that are internally linked to the given pad.
3536 * The GstPadDispatcherFunction should return TRUE when no further pads
3537 * need to be processed.
3539 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3542 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
3545 gboolean res = FALSE;
3546 GstIterator *iter = NULL;
3547 gboolean done = FALSE;
3550 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3551 g_return_val_if_fail (dispatch != NULL, FALSE);
3553 iter = gst_pad_iterate_internal_links (pad);
3559 switch (gst_iterator_next (iter, &item)) {
3560 case GST_ITERATOR_OK:
3562 GstPad *int_pad = GST_PAD_CAST (item);
3563 GstPad *int_peer = gst_pad_get_peer (int_pad);
3566 GST_DEBUG_OBJECT (int_pad, "dispatching to peer %s:%s",
3567 GST_DEBUG_PAD_NAME (int_peer));
3568 done = res = dispatch (int_peer, data);
3569 gst_object_unref (int_peer);
3571 GST_DEBUG_OBJECT (int_pad, "no peer");
3574 gst_object_unref (item);
3576 case GST_ITERATOR_RESYNC:
3577 gst_iterator_resync (iter);
3579 case GST_ITERATOR_ERROR:
3581 GST_ERROR_OBJECT (pad, "Could not iterate internally linked pads");
3583 case GST_ITERATOR_DONE:
3588 gst_iterator_free (iter);
3590 GST_DEBUG_OBJECT (pad, "done, result %d", res);
3599 * @pad: a #GstPad to invoke the default query on.
3600 * @query: the #GstQuery to perform.
3602 * Dispatches a query to a pad. The query should have been allocated by the
3603 * caller via one of the type-specific allocation functions in gstquery.h. The
3604 * element is responsible for filling the query with an appropriate response,
3605 * which should then be parsed with a type-specific query parsing function.
3607 * Again, the caller is responsible for both the allocation and deallocation of
3608 * the query structure.
3610 * Returns: TRUE if the query could be performed.
3613 gst_pad_query (GstPad * pad, GstQuery * query)
3615 GstPadQueryFunction func;
3617 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3618 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3620 GST_DEBUG_OBJECT (pad, "sending query %p", query);
3622 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3625 return func (pad, query);
3629 GST_DEBUG_OBJECT (pad, "had no query function");
3635 * gst_pad_peer_query:
3636 * @pad: a #GstPad to invoke the peer query on.
3637 * @query: the #GstQuery to perform.
3639 * Performs gst_pad_query() on the peer of @pad.
3641 * The caller is responsible for both the allocation and deallocation of
3642 * the query structure.
3644 * Returns: TRUE if the query could be performed. This function returns %FALSE
3645 * if @pad has no peer.
3650 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3655 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3656 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3658 GST_OBJECT_LOCK (pad);
3660 GST_DEBUG_OBJECT (pad, "peer query");
3662 peerpad = GST_PAD_PEER (pad);
3663 if (G_UNLIKELY (peerpad == NULL))
3666 gst_object_ref (peerpad);
3667 GST_OBJECT_UNLOCK (pad);
3669 result = gst_pad_query (peerpad, query);
3671 gst_object_unref (peerpad);
3678 GST_WARNING_OBJECT (pad, "pad has no peer");
3679 GST_OBJECT_UNLOCK (pad);
3685 * gst_pad_query_default:
3686 * @pad: a #GstPad to call the default query handler on.
3687 * @query: the #GstQuery to handle.
3689 * Invokes the default query handler for the given pad.
3690 * The query is sent to all pads internally linked to @pad. Note that
3691 * if there are many possible sink pads that are internally linked to
3692 * @pad, only one will be sent the query.
3693 * Multi-sinkpad elements should implement custom query handlers.
3695 * Returns: TRUE if the query was performed succesfully.
3698 gst_pad_query_default (GstPad * pad, GstQuery * query)
3700 switch (GST_QUERY_TYPE (query)) {
3701 case GST_QUERY_POSITION:
3702 case GST_QUERY_SEEKING:
3703 case GST_QUERY_FORMATS:
3704 case GST_QUERY_LATENCY:
3705 case GST_QUERY_JITTER:
3706 case GST_QUERY_RATE:
3707 case GST_QUERY_CONVERT:
3709 return gst_pad_dispatcher
3710 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
3714 #ifndef GST_DISABLE_LOADSAVE
3715 /* FIXME: why isn't this on a GstElement ? */
3717 * gst_pad_load_and_link:
3718 * @self: an #xmlNodePtr to read the description from.
3719 * @parent: the #GstObject element that owns the pad.
3721 * Reads the pad definition from the XML node and links the given pad
3722 * in the element to a pad of an element up in the hierarchy.
3725 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
3727 xmlNodePtr field = self->xmlChildrenNode;
3728 GstPad *pad = NULL, *targetpad;
3729 GstPadTemplate *tmpl;
3733 GstObject *grandparent;
3737 if (!strcmp ((char *) field->name, "name")) {
3738 name = (gchar *) xmlNodeGetContent (field);
3739 pad = gst_element_get_static_pad (GST_ELEMENT (parent), name);
3740 if ((!pad) || ((tmpl = gst_pad_get_pad_template (pad))
3741 && (GST_PAD_REQUEST == GST_PAD_TEMPLATE_PRESENCE (tmpl))))
3742 pad = gst_element_get_request_pad (GST_ELEMENT (parent), name);
3744 } else if (!strcmp ((char *) field->name, "peer")) {
3745 peer = (gchar *) xmlNodeGetContent (field);
3747 field = field->next;
3749 g_return_if_fail (pad != NULL);
3754 split = g_strsplit (peer, ".", 2);
3756 if (split[0] == NULL || split[1] == NULL) {
3757 GST_CAT_DEBUG_OBJECT (GST_CAT_XML, pad,
3758 "Could not parse peer '%s', leaving unlinked", peer);
3765 g_return_if_fail (split[0] != NULL);
3766 g_return_if_fail (split[1] != NULL);
3768 grandparent = gst_object_get_parent (parent);
3770 if (grandparent && GST_IS_BIN (grandparent)) {
3771 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
3778 targetpad = gst_element_get_static_pad (target, split[1]);
3780 targetpad = gst_element_get_request_pad (target, split[1]);
3782 if (targetpad == NULL)
3785 if (gst_pad_get_direction (pad) == GST_PAD_SRC)
3786 gst_pad_link (pad, targetpad);
3788 gst_pad_link (targetpad, pad);
3795 * gst_pad_save_thyself:
3796 * @pad: a #GstPad to save.
3797 * @parent: the parent #xmlNodePtr to save the description in.
3799 * Saves the pad into an xml representation.
3801 * Returns: the #xmlNodePtr representation of the pad.
3804 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3809 g_return_val_if_fail (GST_IS_PAD (object), NULL);
3811 pad = GST_PAD_CAST (object);
3813 xmlNewChild (parent, NULL, (xmlChar *) "name",
3814 (xmlChar *) GST_PAD_NAME (pad));
3816 if (GST_PAD_IS_SRC (pad)) {
3817 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "source");
3818 } else if (GST_PAD_IS_SINK (pad)) {
3819 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "sink");
3821 xmlNewChild (parent, NULL, (xmlChar *) "direction", (xmlChar *) "unknown");
3824 if (GST_PAD_PEER (pad) != NULL) {
3827 peer = GST_PAD_PEER (pad);
3828 /* first check to see if the peer's parent's parent is the same */
3829 /* we just save it off */
3830 content = g_strdup_printf ("%s.%s",
3831 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3832 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
3835 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
3842 * gst_ghost_pad_save_thyself:
3843 * @pad: a ghost #GstPad to save.
3844 * @parent: the parent #xmlNodePtr to save the description in.
3846 * Saves the ghost pad into an xml representation.
3848 * Returns: the #xmlNodePtr representation of the pad.
3851 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3855 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3857 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
3858 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
3859 xmlNewChild (self, NULL, (xmlChar *) "parent",
3860 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3862 /* FIXME FIXME FIXME! */
3867 #endif /* GST_DISABLE_LOADSAVE */
3870 * should be called with pad OBJECT_LOCK and STREAM_LOCK held.
3871 * GST_PAD_IS_BLOCKED (pad) == TRUE when this function is
3874 * This function performs the pad blocking when an event, buffer push
3875 * or buffer_alloc is performed on a _SRC_ pad. It blocks the
3876 * streaming thread after informing the pad has been blocked.
3878 * An application can with this method wait and block any streaming
3879 * thread and perform operations such as seeking or linking.
3881 * Two methods are available for notifying the application of the
3883 * - the callback method, which happens in the STREAMING thread with
3884 * the STREAM_LOCK held. With this method, the most useful way of
3885 * dealing with the callback is to post a message to the main thread
3886 * where the pad block can then be handled outside of the streaming
3887 * thread. With the last method one can perform all operations such
3888 * as doing a state change, linking, unblocking, seeking etc on the
3890 * - the GCond signal method, which makes any thread unblock when
3891 * the pad block happens.
3893 * During the actual blocking state, the GST_PAD_BLOCKING flag is set.
3894 * The GST_PAD_BLOCKING flag is unset when the pad was unblocked.
3898 static GstFlowReturn
3899 handle_pad_block (GstPad * pad)
3901 GstPadBlockCallback callback;
3903 GstFlowReturn ret = GST_FLOW_OK;
3905 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "signal block taken");
3907 /* flushing, don't bother trying to block and return WRONG_STATE
3909 if (GST_PAD_IS_FLUSHING (pad))
3910 goto flushingnonref;
3912 /* we grab an extra ref for the callbacks, this is probably not
3913 * needed (callback code does not have a ref and cannot unref). I
3914 * think this was done to make it possible to unref the element in
3915 * the callback, which is in the end totally impossible as it
3916 * requires grabbing the STREAM_LOCK and OBJECT_LOCK which are
3917 * all taken when calling this function. */
3918 gst_object_ref (pad);
3920 while (GST_PAD_IS_BLOCKED (pad)) {
3922 /* we either have a callback installed to notify the block or
3923 * some other thread is doing a GCond wait. */
3924 callback = pad->block_callback;
3925 pad->abidata.ABI.block_callback_called = TRUE;
3927 /* there is a callback installed, call it. We release the
3928 * lock so that the callback can do something usefull with the
3930 user_data = pad->block_data;
3931 GST_OBJECT_UNLOCK (pad);
3932 callback (pad, TRUE, user_data);
3933 GST_OBJECT_LOCK (pad);
3935 /* we released the lock, recheck flushing */
3936 if (GST_PAD_IS_FLUSHING (pad))
3939 /* no callback, signal the thread that is doing a GCond wait
3941 GST_PAD_BLOCK_BROADCAST (pad);
3943 } while (pad->abidata.ABI.block_callback_called == FALSE
3944 && GST_PAD_IS_BLOCKED (pad));
3946 /* OBJECT_LOCK could have been released when we did the callback, which
3947 * then could have made the pad unblock so we need to check the blocking
3948 * condition again. */
3949 if (!GST_PAD_IS_BLOCKED (pad))
3952 /* now we block the streaming thread. It can be unlocked when we
3953 * deactivate the pad (which will also set the FLUSHING flag) or
3954 * when the pad is unblocked. A flushing event will also unblock
3955 * the pad after setting the FLUSHING flag. */
3956 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3957 "Waiting to be unblocked or set flushing");
3958 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKING);
3959 GST_PAD_BLOCK_WAIT (pad);
3960 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKING);
3962 /* see if we got unblocked by a flush or not */
3963 if (GST_PAD_IS_FLUSHING (pad))
3967 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
3969 /* when we get here, the pad is unblocked again and we perform
3970 * the needed unblock code. */
3971 callback = pad->block_callback;
3973 /* we need to call the callback */
3974 user_data = pad->block_data;
3975 GST_OBJECT_UNLOCK (pad);
3976 callback (pad, FALSE, user_data);
3977 GST_OBJECT_LOCK (pad);
3979 /* we need to signal the thread waiting on the GCond */
3980 GST_PAD_BLOCK_BROADCAST (pad);
3983 gst_object_unref (pad);
3989 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pad was flushing");
3990 return GST_FLOW_WRONG_STATE;
3994 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pad became flushing");
3995 gst_object_unref (pad);
3996 return GST_FLOW_WRONG_STATE;
4000 /**********************************************************************
4001 * Data passing functions
4005 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
4008 GValue args[2] = { {0}, {0} };
4013 g_value_init (&ret, G_TYPE_BOOLEAN);
4014 g_value_set_boolean (&ret, TRUE);
4015 g_value_init (&args[0], GST_TYPE_PAD);
4016 g_value_set_object (&args[0], pad);
4017 g_value_init (&args[1], GST_TYPE_MINI_OBJECT);
4018 gst_value_set_mini_object (&args[1], obj);
4020 if (GST_IS_EVENT (obj))
4021 detail = event_quark;
4023 detail = buffer_quark;
4026 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
4027 res = g_value_get_boolean (&ret);
4030 g_value_unset (&ret);
4031 g_value_unset (&args[0]);
4032 g_value_unset (&args[1]);
4038 gst_pad_data_unref (gboolean is_buffer, void *data)
4040 if (G_LIKELY (is_buffer)) {
4041 gst_buffer_unref (data);
4043 gst_buffer_list_unref (data);
4048 gst_pad_data_get_caps (gboolean is_buffer, void *data)
4052 if (G_LIKELY (is_buffer)) {
4053 caps = GST_BUFFER_CAPS (data);
4057 if ((buf = gst_buffer_list_get (GST_BUFFER_LIST_CAST (data), 0, 0)))
4058 caps = GST_BUFFER_CAPS (buf);
4065 /* this is the chain function that does not perform the additional argument
4066 * checking for that little extra speed.
4068 static inline GstFlowReturn
4069 gst_pad_chain_data_unchecked (GstPad * pad, gboolean is_buffer, void *data)
4072 gboolean caps_changed;
4074 gboolean emit_signal;
4076 GST_PAD_STREAM_LOCK (pad);
4078 GST_OBJECT_LOCK (pad);
4079 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4082 caps = gst_pad_data_get_caps (is_buffer, data);
4083 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4085 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4086 GST_OBJECT_UNLOCK (pad);
4088 /* see if the signal should be emited, we emit before caps nego as
4089 * we might drop the buffer and do capsnego for nothing. */
4090 if (G_UNLIKELY (emit_signal)) {
4091 if (G_LIKELY (is_buffer)) {
4092 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (data)))
4095 /* chain all groups in the buffer list one by one to avoid problems with
4096 * buffer probes that push buffers or events */
4101 /* we got a new datatype on the pad, see if it can handle it */
4102 if (G_UNLIKELY (caps_changed)) {
4103 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4104 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
4105 goto not_negotiated;
4108 /* NOTE: we read the chainfunc unlocked.
4109 * we cannot hold the lock for the pad so we might send
4110 * the data to the wrong function. This is not really a
4111 * problem since functions are assigned at creation time
4112 * and don't change that often... */
4113 if (G_LIKELY (is_buffer)) {
4114 GstPadChainFunction chainfunc;
4116 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4119 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4120 "calling chainfunction &%s", GST_DEBUG_FUNCPTR_NAME (chainfunc));
4122 ret = chainfunc (pad, GST_BUFFER_CAST (data));
4124 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4125 "called chainfunction &%s, returned %s",
4126 GST_DEBUG_FUNCPTR_NAME (chainfunc), gst_flow_get_name (ret));
4128 GstPadChainListFunction chainlistfunc;
4130 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4133 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4134 "calling chainlistfunction &%s",
4135 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4137 ret = chainlistfunc (pad, GST_BUFFER_LIST_CAST (data));
4139 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4140 "called chainlistfunction &%s, returned %s",
4141 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4144 GST_PAD_STREAM_UNLOCK (pad);
4150 GstBufferList *list;
4151 GstBufferListIterator *it;
4154 GST_PAD_STREAM_UNLOCK (pad);
4156 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
4158 list = GST_BUFFER_LIST_CAST (data);
4159 it = gst_buffer_list_iterate (list);
4161 if (gst_buffer_list_iterator_next_group (it)) {
4163 group = gst_buffer_list_iterator_merge_group (it);
4164 if (group == NULL) {
4165 group = gst_buffer_new ();
4166 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining empty group");
4168 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining group");
4170 ret = gst_pad_chain_data_unchecked (pad, TRUE, group);
4171 } while (ret == GST_FLOW_OK && gst_buffer_list_iterator_next_group (it));
4173 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "chaining empty group");
4174 ret = gst_pad_chain_data_unchecked (pad, TRUE, gst_buffer_new ());
4177 gst_buffer_list_iterator_free (it);
4178 gst_buffer_list_unref (list);
4186 gst_pad_data_unref (is_buffer, data);
4187 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4188 "pushing, but pad was flushing");
4189 GST_OBJECT_UNLOCK (pad);
4190 GST_PAD_STREAM_UNLOCK (pad);
4191 return GST_FLOW_WRONG_STATE;
4195 gst_pad_data_unref (is_buffer, data);
4196 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
4197 GST_PAD_STREAM_UNLOCK (pad);
4202 gst_pad_data_unref (is_buffer, data);
4203 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4204 "pushing data but pad did not accept");
4205 GST_PAD_STREAM_UNLOCK (pad);
4206 return GST_FLOW_NOT_NEGOTIATED;
4210 gst_pad_data_unref (is_buffer, data);
4211 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4212 "pushing, but not chainhandler");
4213 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4214 ("push on pad %s:%s but it has no chainfunction",
4215 GST_DEBUG_PAD_NAME (pad)));
4216 GST_PAD_STREAM_UNLOCK (pad);
4217 return GST_FLOW_NOT_SUPPORTED;
4223 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4224 * @buffer: the #GstBuffer to send, return GST_FLOW_ERROR if not.
4226 * Chain a buffer to @pad.
4228 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
4230 * If the caps on @buffer are different from the current caps on @pad, this
4231 * function will call any setcaps function (see gst_pad_set_setcaps_function())
4232 * installed on @pad. If the new caps are not acceptable for @pad, this
4233 * function returns #GST_FLOW_NOT_NEGOTIATED.
4235 * The function proceeds calling the chain function installed on @pad (see
4236 * gst_pad_set_chain_function()) and the return value of that function is
4237 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4240 * In all cases, success or failure, the caller loses its reference to @buffer
4241 * after calling this function.
4243 * Returns: a #GstFlowReturn from the pad.
4248 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4250 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4251 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4252 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4254 return gst_pad_chain_data_unchecked (pad, TRUE, buffer);
4258 * gst_pad_chain_list:
4259 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4260 * @list: the #GstBufferList to send, return GST_FLOW_ERROR if not.
4262 * Chain a bufferlist to @pad.
4264 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
4266 * If the caps on the first buffer of @list are different from the current
4267 * caps on @pad, this function will call any setcaps function
4268 * (see gst_pad_set_setcaps_function()) installed on @pad. If the new caps
4269 * are not acceptable for @pad, this function returns #GST_FLOW_NOT_NEGOTIATED.
4271 * The function proceeds calling the chainlist function installed on @pad (see
4272 * gst_pad_set_chain_list_function()) and the return value of that function is
4273 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4274 * chainlist function.
4276 * In all cases, success or failure, the caller loses its reference to @list
4277 * after calling this function.
4281 * Returns: a #GstFlowReturn from the pad.
4286 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4288 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4289 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4290 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4292 return gst_pad_chain_data_unchecked (pad, FALSE, list);
4295 static GstFlowReturn
4296 gst_pad_push_data (GstPad * pad, gboolean is_buffer, void *data)
4301 gboolean caps_changed;
4303 GST_OBJECT_LOCK (pad);
4305 /* FIXME: this check can go away; pad_set_blocked could be implemented with
4306 * probes completely or probes with an extended pad block. */
4307 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
4308 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
4311 /* we emit signals on the pad arg, the peer will have a chance to
4312 * emit in the _chain() function */
4313 if (G_UNLIKELY (GST_PAD_DO_BUFFER_SIGNALS (pad) > 0)) {
4314 /* unlock before emitting */
4315 GST_OBJECT_UNLOCK (pad);
4317 if (G_LIKELY (is_buffer)) {
4318 /* if the signal handler returned FALSE, it means we should just drop the
4320 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (data)))
4323 /* push all buffers in the list */
4326 GST_OBJECT_LOCK (pad);
4329 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4332 /* Before pushing the buffer to the peer pad, ensure that caps
4333 * are set on this pad */
4334 caps = gst_pad_data_get_caps (is_buffer, data);
4335 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4337 /* take ref to peer pad before releasing the lock */
4338 gst_object_ref (peer);
4340 GST_OBJECT_UNLOCK (pad);
4342 /* we got a new datatype from the pad, it had better handle it */
4343 if (G_UNLIKELY (caps_changed)) {
4344 GST_DEBUG_OBJECT (pad,
4345 "caps changed from %" GST_PTR_FORMAT " to %p %" GST_PTR_FORMAT,
4346 GST_PAD_CAPS (pad), caps, caps);
4347 if (G_UNLIKELY (!gst_pad_set_caps (pad, caps)))
4348 goto not_negotiated;
4351 ret = gst_pad_chain_data_unchecked (peer, is_buffer, data);
4353 gst_object_unref (peer);
4359 GstBufferList *list;
4360 GstBufferListIterator *it;
4363 GST_INFO_OBJECT (pad, "pushing each group in list as a merged buffer");
4365 list = GST_BUFFER_LIST_CAST (data);
4366 it = gst_buffer_list_iterate (list);
4368 if (gst_buffer_list_iterator_next_group (it)) {
4370 group = gst_buffer_list_iterator_merge_group (it);
4371 if (group == NULL) {
4372 group = gst_buffer_new ();
4373 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing empty group");
4375 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing group");
4377 ret = gst_pad_push_data (pad, TRUE, group);
4378 } while (ret == GST_FLOW_OK && gst_buffer_list_iterator_next_group (it));
4380 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pushing empty group");
4381 ret = gst_pad_push_data (pad, TRUE, gst_buffer_new ());
4384 gst_buffer_list_iterator_free (it);
4385 gst_buffer_list_unref (list);
4390 /* ERROR recovery here */
4393 gst_pad_data_unref (is_buffer, data);
4394 GST_DEBUG_OBJECT (pad, "pad block stopped by flush");
4395 GST_OBJECT_UNLOCK (pad);
4400 gst_pad_data_unref (is_buffer, data);
4401 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
4406 gst_pad_data_unref (is_buffer, data);
4407 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4408 "pushing, but it was not linked");
4409 GST_OBJECT_UNLOCK (pad);
4410 return GST_FLOW_NOT_LINKED;
4414 gst_pad_data_unref (is_buffer, data);
4415 gst_object_unref (peer);
4416 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4417 "element pushed data then refused to accept the caps");
4418 return GST_FLOW_NOT_NEGOTIATED;
4424 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4425 * @buffer: the #GstBuffer to push returns GST_FLOW_ERROR if not.
4427 * Pushes a buffer to the peer of @pad.
4429 * This function will call an installed pad block before triggering any
4430 * installed pad probes.
4432 * If the caps on @buffer are different from the currently configured caps on
4433 * @pad, this function will call any installed setcaps function on @pad (see
4434 * gst_pad_set_setcaps_function()). In case of failure to renegotiate the new
4435 * format, this function returns #GST_FLOW_NOT_NEGOTIATED.
4437 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4438 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4441 * In all cases, success or failure, the caller loses its reference to @buffer
4442 * after calling this function.
4444 * Returns: a #GstFlowReturn from the peer pad.
4449 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4451 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4452 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4453 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4455 return gst_pad_push_data (pad, TRUE, buffer);
4459 * gst_pad_push_list:
4460 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4461 * @list: the #GstBufferList to push returns GST_FLOW_ERROR if not.
4463 * Pushes a buffer list to the peer of @pad.
4465 * This function will call an installed pad block before triggering any
4466 * installed pad probes.
4468 * If the caps on the first buffer in the first group of @list are different
4469 * from the currently configured caps on @pad, this function will call any
4470 * installed setcaps function on @pad (see gst_pad_set_setcaps_function()). In
4471 * case of failure to renegotiate the new format, this function returns
4472 * #GST_FLOW_NOT_NEGOTIATED.
4474 * If there are any probes installed on @pad every group of the buffer list
4475 * will be merged into a normal #GstBuffer and pushed via gst_pad_push and the
4476 * buffer list will be unreffed.
4478 * The function proceeds calling the chain function on the peer pad and returns
4479 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4480 * be returned. If the peer pad does not have any installed chainlist function
4481 * every group buffer of the list will be merged into a normal #GstBuffer and
4482 * chained via gst_pad_chain().
4484 * In all cases, success or failure, the caller loses its reference to @list
4485 * after calling this function.
4487 * Returns: a #GstFlowReturn from the peer pad.
4494 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4496 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4497 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4498 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4500 return gst_pad_push_data (pad, FALSE, list);
4504 * gst_pad_check_pull_range:
4505 * @pad: a sink #GstPad.
4507 * Checks if a gst_pad_pull_range() can be performed on the peer
4508 * source pad. This function is used by plugins that want to check
4509 * if they can use random access on the peer source pad.
4511 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
4512 * if it needs to perform some logic to determine if pull_range is
4515 * Returns: a gboolean with the result.
4520 gst_pad_check_pull_range (GstPad * pad)
4524 GstPadCheckGetRangeFunction checkgetrangefunc;
4526 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4528 GST_OBJECT_LOCK (pad);
4529 if (!GST_PAD_IS_SINK (pad))
4530 goto wrong_direction;
4532 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4535 gst_object_ref (peer);
4536 GST_OBJECT_UNLOCK (pad);
4538 /* see note in above function */
4539 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
4540 /* FIXME, kindoff ghetto */
4541 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
4542 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4543 "no checkgetrangefunc, assuming %d", ret);
4545 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4546 "calling checkgetrangefunc %s of peer pad %s:%s",
4547 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
4549 ret = checkgetrangefunc (peer);
4552 gst_object_unref (peer);
4556 /* ERROR recovery here */
4559 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4560 "checking pull range, but pad must be a sinkpad");
4561 GST_OBJECT_UNLOCK (pad);
4566 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4567 "checking pull range, but it was not linked");
4568 GST_OBJECT_UNLOCK (pad);
4574 * gst_pad_get_range:
4575 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4576 * @offset: The start offset of the buffer
4577 * @size: The length of the buffer
4578 * @buffer: a pointer to hold the #GstBuffer, returns #GST_FLOW_ERROR if %NULL.
4580 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
4583 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4584 * description of a getrange function. If @pad has no getrange function
4585 * installed (see gst_pad_set_getrange_function()) this function returns
4586 * #GST_FLOW_NOT_SUPPORTED.
4588 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4590 * Returns: a #GstFlowReturn from the pad.
4595 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4596 GstBuffer ** buffer)
4599 GstPadGetRangeFunction getrangefunc;
4600 gboolean emit_signal;
4602 gboolean caps_changed;
4604 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4605 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4606 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4608 GST_PAD_STREAM_LOCK (pad);
4610 GST_OBJECT_LOCK (pad);
4611 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4614 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4615 GST_OBJECT_UNLOCK (pad);
4617 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4620 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4621 "calling getrangefunc %s, offset %"
4622 G_GUINT64_FORMAT ", size %u",
4623 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4625 ret = getrangefunc (pad, offset, size, buffer);
4627 /* can only fire the signal if we have a valid buffer */
4628 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
4629 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
4633 GST_PAD_STREAM_UNLOCK (pad);
4635 if (G_UNLIKELY (ret != GST_FLOW_OK))
4636 goto get_range_failed;
4638 GST_OBJECT_LOCK (pad);
4639 /* Before pushing the buffer to the peer pad, ensure that caps
4640 * are set on this pad */
4641 caps = GST_BUFFER_CAPS (*buffer);
4642 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4643 GST_OBJECT_UNLOCK (pad);
4645 if (G_UNLIKELY (caps_changed)) {
4646 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4647 /* this should usually work because the element produced the buffer */
4648 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, TRUE)))
4649 goto not_negotiated;
4656 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4657 "pulling range, but pad was flushing");
4658 GST_OBJECT_UNLOCK (pad);
4659 GST_PAD_STREAM_UNLOCK (pad);
4660 return GST_FLOW_WRONG_STATE;
4664 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4665 ("pullrange on pad %s:%s but it has no getrangefunction",
4666 GST_DEBUG_PAD_NAME (pad)));
4667 GST_PAD_STREAM_UNLOCK (pad);
4668 return GST_FLOW_NOT_SUPPORTED;
4672 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4673 "Dropping data after FALSE probe return");
4674 GST_PAD_STREAM_UNLOCK (pad);
4675 gst_buffer_unref (*buffer);
4677 return GST_FLOW_UNEXPECTED;
4682 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4683 "getrange failed %s", gst_flow_get_name (ret));
4688 gst_buffer_unref (*buffer);
4690 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4691 "getrange returned buffer of unaccaptable caps");
4692 return GST_FLOW_NOT_NEGOTIATED;
4698 * gst_pad_pull_range:
4699 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4700 * @offset: The start offset of the buffer
4701 * @size: The length of the buffer
4702 * @buffer: a pointer to hold the #GstBuffer, returns GST_FLOW_ERROR if %NULL.
4704 * Pulls a @buffer from the peer pad.
4706 * This function will first trigger the pad block signal if it was
4709 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4710 * function returns the result of gst_pad_get_range() on the peer pad.
4711 * See gst_pad_get_range() for a list of return values and for the
4712 * semantics of the arguments of this function.
4714 * @buffer's caps must either be unset or the same as what is already
4715 * configured on @pad. Renegotiation within a running pull-mode pipeline is not
4718 * Returns: a #GstFlowReturn from the peer pad.
4719 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
4720 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
4721 * @buffer may not be used or freed when any other return value than
4722 * #GST_FLOW_OK is returned.
4727 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4728 GstBuffer ** buffer)
4732 gboolean emit_signal;
4734 gboolean caps_changed;
4736 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4737 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4738 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4740 GST_OBJECT_LOCK (pad);
4742 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
4743 handle_pad_block (pad);
4745 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4748 /* signal emision for the pad, peer has chance to emit when
4749 * we call _get_range() */
4750 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
4752 gst_object_ref (peer);
4753 GST_OBJECT_UNLOCK (pad);
4755 ret = gst_pad_get_range (peer, offset, size, buffer);
4757 gst_object_unref (peer);
4759 if (G_UNLIKELY (ret != GST_FLOW_OK))
4760 goto pull_range_failed;
4762 /* can only fire the signal if we have a valid buffer */
4763 if (G_UNLIKELY (emit_signal)) {
4764 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
4768 GST_OBJECT_LOCK (pad);
4769 /* Before pushing the buffer to the peer pad, ensure that caps
4770 * are set on this pad */
4771 caps = GST_BUFFER_CAPS (*buffer);
4772 caps_changed = caps && caps != GST_PAD_CAPS (pad);
4773 GST_OBJECT_UNLOCK (pad);
4775 /* we got a new datatype on the pad, see if it can handle it */
4776 if (G_UNLIKELY (caps_changed)) {
4777 GST_DEBUG_OBJECT (pad, "caps changed to %p %" GST_PTR_FORMAT, caps, caps);
4778 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
4779 goto not_negotiated;
4783 /* ERROR recovery here */
4786 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4787 "pulling range, but it was not linked");
4788 GST_OBJECT_UNLOCK (pad);
4789 return GST_FLOW_NOT_LINKED;
4794 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4795 (ret >= GST_FLOW_UNEXPECTED) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4796 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4801 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4802 "Dropping data after FALSE probe return");
4803 gst_buffer_unref (*buffer);
4805 return GST_FLOW_UNEXPECTED;
4809 gst_buffer_unref (*buffer);
4811 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4812 "pullrange returned buffer of different caps");
4813 return GST_FLOW_NOT_NEGOTIATED;
4818 * gst_pad_push_event:
4819 * @pad: a #GstPad to push the event to.
4820 * @event: the #GstEvent to send to the pad.
4822 * Sends the event to the peer of the given pad. This function is
4823 * mainly used by elements to send events to their peer
4826 * This function takes owership of the provided event so you should
4827 * gst_event_ref() it if you want to reuse the event after this call.
4829 * Returns: TRUE if the event was handled.
4834 gst_pad_push_event (GstPad * pad, GstEvent * event)
4839 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4840 g_return_val_if_fail (event != NULL, FALSE);
4841 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4843 GST_LOG_OBJECT (pad, "event: %s", GST_EVENT_TYPE_NAME (event));
4845 GST_OBJECT_LOCK (pad);
4847 /* Two checks to be made:
4848 * . (un)set the FLUSHING flag for flushing events,
4849 * . handle pad blocking */
4850 switch (GST_EVENT_TYPE (event)) {
4851 case GST_EVENT_FLUSH_START:
4852 GST_PAD_SET_FLUSHING (pad);
4854 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4855 /* flush start will have set the FLUSHING flag and will then
4856 * unlock all threads doing a GCond wait on the blocking pad. This
4857 * will typically unblock the STREAMING thread blocked on a pad. */
4858 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
4859 "doing block signal.");
4860 GST_PAD_BLOCK_BROADCAST (pad);
4864 case GST_EVENT_FLUSH_STOP:
4865 GST_PAD_UNSET_FLUSHING (pad);
4867 /* if we are blocked, flush away the FLUSH_STOP event */
4868 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4869 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4874 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4875 /* block the event as long as the pad is blocked */
4876 if (handle_pad_block (pad) != GST_FLOW_OK)
4882 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
4883 GST_OBJECT_UNLOCK (pad);
4885 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
4888 GST_OBJECT_LOCK (pad);
4890 peerpad = GST_PAD_PEER (pad);
4891 if (peerpad == NULL)
4894 GST_LOG_OBJECT (pad, "sending event %s to peerpad %" GST_PTR_FORMAT,
4895 GST_EVENT_TYPE_NAME (event), peerpad);
4896 gst_object_ref (peerpad);
4897 GST_OBJECT_UNLOCK (pad);
4899 result = gst_pad_send_event (peerpad, event);
4901 /* Note: we gave away ownership of the event at this point */
4902 GST_LOG_OBJECT (pad, "sent event to peerpad %" GST_PTR_FORMAT ", result %d",
4904 gst_object_unref (peerpad);
4908 /* ERROR handling */
4911 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
4912 gst_event_unref (event);
4917 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4918 gst_event_unref (event);
4919 GST_OBJECT_UNLOCK (pad);
4924 GST_DEBUG_OBJECT (pad,
4925 "Not forwarding event since we're flushing and blocking");
4926 gst_event_unref (event);
4927 GST_OBJECT_UNLOCK (pad);
4933 * gst_pad_send_event:
4934 * @pad: a #GstPad to send the event to.
4935 * @event: the #GstEvent to send to the pad.
4937 * Sends the event to the pad. This function can be used
4938 * by applications to send events in the pipeline.
4940 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4941 * sink pad, @event should be a downstream event. For example, you would not
4942 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4943 * Furthermore, some downstream events have to be serialized with data flow,
4944 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4945 * the event needs to be serialized with data flow, this function will take the
4946 * pad's stream lock while calling its event function.
4948 * To find out whether an event type is upstream, downstream, or downstream and
4949 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4950 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4951 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4952 * plugin doesn't need to bother itself with this information; the core handles
4953 * all necessary locks and checks.
4955 * This function takes owership of the provided event so you should
4956 * gst_event_ref() it if you want to reuse the event after this call.
4958 * Returns: TRUE if the event was handled.
4961 gst_pad_send_event (GstPad * pad, GstEvent * event)
4963 gboolean result = FALSE;
4964 GstPadEventFunction eventfunc;
4965 gboolean serialized, need_unlock = FALSE;
4967 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4968 g_return_val_if_fail (event != NULL, FALSE);
4970 GST_OBJECT_LOCK (pad);
4971 if (GST_PAD_IS_SINK (pad)) {
4972 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4973 goto wrong_direction;
4974 serialized = GST_EVENT_IS_SERIALIZED (event);
4975 } else if (GST_PAD_IS_SRC (pad)) {
4976 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4977 goto wrong_direction;
4978 /* events on srcpad never are serialized */
4981 goto unknown_direction;
4983 if (G_UNLIKELY (GST_EVENT_SRC (event) == NULL)) {
4984 GST_LOG_OBJECT (pad, "event had no source, setting pad as event source");
4985 GST_EVENT_SRC (event) = gst_object_ref (pad);
4989 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
4990 GST_OBJECT_UNLOCK (pad);
4992 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT_CAST (event)))
4995 GST_OBJECT_LOCK (pad);
4998 switch (GST_EVENT_TYPE (event)) {
4999 case GST_EVENT_FLUSH_START:
5000 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5001 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5003 /* can't even accept a flush begin event when flushing */
5004 if (GST_PAD_IS_FLUSHING (pad))
5006 GST_PAD_SET_FLUSHING (pad);
5007 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5009 case GST_EVENT_FLUSH_STOP:
5010 GST_PAD_UNSET_FLUSHING (pad);
5011 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5012 GST_OBJECT_UNLOCK (pad);
5013 /* grab stream lock */
5014 GST_PAD_STREAM_LOCK (pad);
5016 GST_OBJECT_LOCK (pad);
5019 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
5020 GST_EVENT_TYPE_NAME (event));
5022 /* make this a little faster, no point in grabbing the lock
5023 * if the pad is allready flushing. */
5024 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5028 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5029 GST_OBJECT_UNLOCK (pad);
5030 GST_PAD_STREAM_LOCK (pad);
5032 GST_OBJECT_LOCK (pad);
5033 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5038 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5041 GST_OBJECT_UNLOCK (pad);
5043 result = eventfunc (pad, event);
5046 GST_PAD_STREAM_UNLOCK (pad);
5048 GST_DEBUG_OBJECT (pad, "sent event, result %d", result);
5052 /* ERROR handling */
5055 g_warning ("pad %s:%s sending %s event in wrong direction",
5056 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5057 GST_OBJECT_UNLOCK (pad);
5058 gst_event_unref (event);
5063 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5064 GST_OBJECT_UNLOCK (pad);
5065 gst_event_unref (event);
5070 g_warning ("pad %s:%s has no event handler, file a bug.",
5071 GST_DEBUG_PAD_NAME (pad));
5072 GST_OBJECT_UNLOCK (pad);
5074 GST_PAD_STREAM_UNLOCK (pad);
5075 gst_event_unref (event);
5080 GST_OBJECT_UNLOCK (pad);
5082 GST_PAD_STREAM_UNLOCK (pad);
5083 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5084 "Received event on flushing pad. Discarding");
5085 gst_event_unref (event);
5090 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
5091 gst_event_unref (event);
5097 * gst_pad_set_element_private:
5098 * @pad: the #GstPad to set the private data of.
5099 * @priv: The private data to attach to the pad.
5101 * Set the given private data gpointer on the pad.
5102 * This function can only be used by the element that owns the pad.
5103 * No locking is performed in this function.
5106 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5108 pad->element_private = priv;
5112 * gst_pad_get_element_private:
5113 * @pad: the #GstPad to get the private data of.
5115 * Gets the private data of a pad.
5116 * No locking is performed in this function.
5118 * Returns: a #gpointer to the private data.
5121 gst_pad_get_element_private (GstPad * pad)
5123 return pad->element_private;
5127 do_stream_status (GstPad * pad, GstStreamStatusType type,
5128 GThread * thread, GstTask * task)
5132 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5134 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5135 if (GST_IS_ELEMENT (parent)) {
5136 GstMessage *message;
5137 GValue value = { 0 };
5139 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5142 g_value_init (&value, GST_TYPE_TASK);
5143 g_value_set_object (&value, task);
5144 gst_message_set_stream_status_object (message, &value);
5145 g_value_unset (&value);
5147 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5148 gst_element_post_message (parent, message);
5150 gst_object_unref (parent);
5155 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5157 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5162 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5164 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5168 static GstTaskThreadCallbacks thr_callbacks = {
5174 * gst_pad_start_task:
5175 * @pad: the #GstPad to start the task of
5176 * @func: the task function to call
5177 * @data: data passed to the task function
5179 * Starts a task that repeatedly calls @func with @data. This function
5180 * is mostly used in pad activation functions to start the dataflow.
5181 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5182 * before @func is called.
5184 * Returns: a %TRUE if the task could be started.
5187 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
5192 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5193 g_return_val_if_fail (func != NULL, FALSE);
5195 GST_DEBUG_OBJECT (pad, "start task");
5197 GST_OBJECT_LOCK (pad);
5198 task = GST_PAD_TASK (pad);
5200 task = gst_task_create (func, data);
5201 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5202 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
5203 GST_DEBUG_OBJECT (pad, "created task");
5204 GST_PAD_TASK (pad) = task;
5205 gst_object_ref (task);
5206 /* release lock to post the message */
5207 GST_OBJECT_UNLOCK (pad);
5209 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5211 gst_object_unref (task);
5213 GST_OBJECT_LOCK (pad);
5214 /* nobody else is supposed to have changed the pad now */
5215 if (GST_PAD_TASK (pad) != task)
5216 goto concurrent_stop;
5218 res = gst_task_set_state (task, GST_TASK_STARTED);
5219 GST_OBJECT_UNLOCK (pad);
5226 GST_OBJECT_UNLOCK (pad);
5232 * gst_pad_pause_task:
5233 * @pad: the #GstPad to pause the task of
5235 * Pause the task of @pad. This function will also wait until the
5236 * function executed by the task is finished if this function is not
5237 * called from the task function.
5239 * Returns: a TRUE if the task could be paused or FALSE when the pad
5243 gst_pad_pause_task (GstPad * pad)
5248 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5250 GST_DEBUG_OBJECT (pad, "pause task");
5252 GST_OBJECT_LOCK (pad);
5253 task = GST_PAD_TASK (pad);
5256 res = gst_task_set_state (task, GST_TASK_PAUSED);
5257 GST_OBJECT_UNLOCK (pad);
5259 /* wait for task function to finish, this lock is recursive so it does nothing
5260 * when the pause is called from the task itself */
5261 GST_PAD_STREAM_LOCK (pad);
5262 GST_PAD_STREAM_UNLOCK (pad);
5268 GST_DEBUG_OBJECT (pad, "pad has no task");
5269 GST_OBJECT_UNLOCK (pad);
5275 * gst_pad_stop_task:
5276 * @pad: the #GstPad to stop the task of
5278 * Stop the task of @pad. This function will also make sure that the
5279 * function executed by the task will effectively stop if not called
5280 * from the GstTaskFunction.
5282 * This function will deadlock if called from the GstTaskFunction of
5283 * the task. Use gst_task_pause() instead.
5285 * Regardless of whether the pad has a task, the stream lock is acquired and
5286 * released so as to ensure that streaming through this pad has finished.
5288 * Returns: a TRUE if the task could be stopped or FALSE on error.
5291 gst_pad_stop_task (GstPad * pad)
5296 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5298 GST_DEBUG_OBJECT (pad, "stop task");
5300 GST_OBJECT_LOCK (pad);
5301 task = GST_PAD_TASK (pad);
5304 GST_PAD_TASK (pad) = NULL;
5305 res = gst_task_set_state (task, GST_TASK_STOPPED);
5306 GST_OBJECT_UNLOCK (pad);
5308 GST_PAD_STREAM_LOCK (pad);
5309 GST_PAD_STREAM_UNLOCK (pad);
5311 if (!gst_task_join (task))
5314 gst_object_unref (task);
5320 GST_DEBUG_OBJECT (pad, "no task");
5321 GST_OBJECT_UNLOCK (pad);
5323 GST_PAD_STREAM_LOCK (pad);
5324 GST_PAD_STREAM_UNLOCK (pad);
5326 /* this is not an error */
5331 /* this is bad, possibly the application tried to join the task from
5332 * the task's thread. We install the task again so that it will be stopped
5333 * again from the right thread next time hopefully. */
5334 GST_OBJECT_LOCK (pad);
5335 GST_DEBUG_OBJECT (pad, "join failed");
5336 /* we can only install this task if there was no other task */
5337 if (GST_PAD_TASK (pad) == NULL)
5338 GST_PAD_TASK (pad) = task;
5339 GST_OBJECT_UNLOCK (pad);