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 other elements
25 * @see_also: #GstPadTemplate, #GstElement, #GstEvent
27 * A #GstElement is linked to other elements via "pads", which are extremely
28 * light-weight generic link points.
29 * After two pads are retrieved from an element with gst_element_get_pad(),
30 * the pads can be link with gst_pad_link(). (For quick links,
31 * you can also use gst_element_link(), which will make the obvious
32 * link for you if it's straightforward.)
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template().
37 * Pads have #GstCaps attached to it to describe the media type they are capable
39 * gst_pad_get_caps() and gst_pad_try_set_caps() are used to manipulate the caps
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() to push out
55 * or pull in a buffer.
56 * gst_pad_select() and gst_pad_selectv() are used by plugins to wait for the
57 * first incoming buffer or event on any of the given set of pads.
59 * To send a #GstEvent on a pad, use gst_pad_send_event().
61 * Last reviewed on December 13th, 2002 (0.5.0.1)
64 #include "gst_private.h"
67 #include "gstpadtemplate.h"
68 #include "gstenumtypes.h"
69 #include "gstmarshal.h"
75 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
76 #define GST_CAT_DEFAULT GST_CAT_PADS
78 /* Pad signals and args */
98 GType _gst_pad_type = 0;
100 static void gst_pad_class_init (GstPadClass * klass);
101 static void gst_pad_init (GstPad * pad);
102 static void gst_pad_dispose (GObject * object);
103 static void gst_pad_finalize (GObject * object);
104 static void gst_pad_set_property (GObject * object, guint prop_id,
105 const GValue * value, GParamSpec * pspec);
106 static void gst_pad_get_property (GObject * object, guint prop_id,
107 GValue * value, GParamSpec * pspec);
109 static void handle_pad_block (GstPad * pad);
110 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
111 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
112 static gboolean gst_pad_activate_default (GstPad * pad);
114 #ifndef GST_DISABLE_LOADSAVE
115 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
118 static GstObjectClass *parent_class = NULL;
119 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
121 /* quarks for probe signals */
122 static GQuark buffer_quark;
123 static GQuark event_quark;
132 static GstFlowQuarks flow_quarks[] = {
133 {GST_FLOW_RESEND, "resend", 0},
134 {GST_FLOW_OK, "ok", 0},
135 {GST_FLOW_NOT_LINKED, "not-linked", 0},
136 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
137 {GST_FLOW_UNEXPECTED, "unexpected", 0},
138 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
139 {GST_FLOW_ERROR, "error", 0},
140 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
147 * @ret: a #GstFlowReturn to get the name of.
149 * Gets a string representing the given flow return.
151 * Returns: a string with the name of the flow return.
153 G_CONST_RETURN gchar *
154 gst_flow_get_name (GstFlowReturn ret)
158 for (i = 0; flow_quarks[i].name; i++) {
159 if (ret == flow_quarks[i].ret)
160 return flow_quarks[i].name;
167 * @ret: a #GstFlowReturn to get the quark of.
169 * Get the unique quark for the given GstFlowReturn.
171 * Returns: the quark associated with the flow return or 0 if an
172 * invalid return was specified.
175 gst_flow_to_quark (GstFlowReturn ret)
179 for (i = 0; flow_quarks[i].name; i++) {
180 if (ret == flow_quarks[i].ret)
181 return flow_quarks[i].quark;
187 gst_pad_get_type (void)
189 if (!_gst_pad_type) {
190 static const GTypeInfo pad_info = {
191 sizeof (GstPadClass), NULL, NULL,
192 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
195 (GInstanceInitFunc) gst_pad_init, NULL
199 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
202 buffer_quark = g_quark_from_static_string ("buffer");
203 event_quark = g_quark_from_static_string ("event");
205 for (i = 0; flow_quarks[i].name; i++) {
206 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name);
209 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
210 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
212 return _gst_pad_type;
216 _gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
217 GValue * return_accu, const GValue * handler_return, gpointer dummy)
219 gboolean ret = g_value_get_boolean (handler_return);
221 GST_DEBUG ("accumulated %d", ret);
222 g_value_set_boolean (return_accu, ret);
228 default_have_data (GstPad * pad, GstMiniObject * o)
234 gst_pad_class_init (GstPadClass * klass)
236 GObjectClass *gobject_class;
239 GstObjectClass *gstobject_class;
241 gobject_class = (GObjectClass *) klass;
242 gstobject_class = (GstObjectClass *) klass;
244 parent_class = g_type_class_ref (GST_TYPE_OBJECT);
246 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
247 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_pad_finalize);
248 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_pad_set_property);
249 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_pad_get_property);
253 * @pad: the pad that emitted the signal
254 * @peer: the peer pad that has been connected
256 * Signals that a pad has been linked to the peer pad.
258 gst_pad_signals[PAD_LINKED] =
259 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
260 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
261 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
264 * @pad: the pad that emitted the signal
265 * @peer: the peer pad that has been disconnected
267 * Signals that a pad has been unlinked from the peer pad.
269 gst_pad_signals[PAD_UNLINKED] =
270 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
271 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
272 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
274 * GstPad::request-link:
275 * @pad: the pad that emitted the signal
276 * @peer: the peer pad for which a connection is requested
278 * Signals that a pad connection has been requested.
280 gst_pad_signals[PAD_REQUEST_LINK] =
281 g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
282 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
283 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
287 * @pad: the pad that emitted the signal
288 * @mini_obj: new data
290 * Signals that new data is available on the pad. This signal is used
291 * internally for implementing pad probes.
292 * See gst_pad_add_*_probe functions.
294 * Returns: %TRUE to keep the data, %FALSE to drop it
296 gst_pad_signals[PAD_HAVE_DATA] =
297 g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
298 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
299 G_STRUCT_OFFSET (GstPadClass, have_data),
300 _gst_do_pass_data_accumulator,
301 NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
302 GST_TYPE_MINI_OBJECT);
304 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_CAPS,
305 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
306 GST_TYPE_CAPS, G_PARAM_READABLE));
307 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_DIRECTION,
308 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
309 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
310 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
311 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_TEMPLATE,
312 g_param_spec_object ("template", "Template",
313 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
316 #ifndef GST_DISABLE_LOADSAVE
317 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
319 gstobject_class->path_string_separator = ".";
321 klass->have_data = default_have_data;
325 gst_pad_init (GstPad * pad)
327 pad->direction = GST_PAD_UNKNOWN;
330 pad->chainfunc = NULL;
334 pad->linkfunc = NULL;
335 pad->getcapsfunc = NULL;
337 pad->activatefunc = gst_pad_activate_default;
338 pad->eventfunc = gst_pad_event_default;
339 pad->querytypefunc = gst_pad_get_query_types_default;
340 pad->queryfunc = gst_pad_query_default;
341 pad->intlinkfunc = gst_pad_get_internal_links_default;
343 pad->do_buffer_signals = 0;
344 pad->do_event_signals = 0;
346 GST_PAD_UNSET_FLUSHING (pad);
348 pad->preroll_lock = g_mutex_new ();
349 pad->preroll_cond = g_cond_new ();
351 pad->stream_rec_lock = g_new (GStaticRecMutex, 1);
352 g_static_rec_mutex_init (pad->stream_rec_lock);
354 pad->block_cond = g_cond_new ();
358 gst_pad_dispose (GObject * object)
360 GstPad *pad = GST_PAD (object);
362 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
363 GST_DEBUG_PAD_NAME (pad));
365 /* we don't hold a ref to the peer so we can just set the
367 GST_PAD_PEER (pad) = NULL;
370 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
372 gst_pad_set_pad_template (pad, NULL);
374 G_OBJECT_CLASS (parent_class)->dispose (object);
378 gst_pad_finalize (GObject * object)
380 GstPad *pad = GST_PAD (object);
383 /* in case the task is still around, clean it up */
384 if ((task = GST_PAD_TASK (pad))) {
385 gst_task_join (task);
386 GST_PAD_TASK (pad) = NULL;
387 gst_object_unref (task);
390 if (pad->stream_rec_lock) {
391 g_static_rec_mutex_free (pad->stream_rec_lock);
392 g_free (pad->stream_rec_lock);
393 pad->stream_rec_lock = NULL;
395 if (pad->preroll_lock) {
396 g_mutex_free (pad->preroll_lock);
397 g_cond_free (pad->preroll_cond);
398 pad->preroll_lock = NULL;
399 pad->preroll_cond = NULL;
401 if (pad->block_cond) {
402 g_cond_free (pad->block_cond);
403 pad->block_cond = NULL;
406 G_OBJECT_CLASS (parent_class)->finalize (object);
410 gst_pad_set_property (GObject * object, guint prop_id,
411 const GValue * value, GParamSpec * pspec)
413 g_return_if_fail (GST_IS_PAD (object));
416 case PAD_PROP_DIRECTION:
417 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
419 case PAD_PROP_TEMPLATE:
420 gst_pad_set_pad_template (GST_PAD_CAST (object),
421 (GstPadTemplate *) g_value_dup_object (value));
424 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
430 gst_pad_get_property (GObject * object, guint prop_id,
431 GValue * value, GParamSpec * pspec)
433 g_return_if_fail (GST_IS_PAD (object));
437 g_value_set_boxed (value, GST_PAD_CAPS (object));
439 case PAD_PROP_DIRECTION:
440 g_value_set_enum (value, GST_PAD_DIRECTION (object));
442 case PAD_PROP_TEMPLATE:
443 g_value_set_object (value, GST_PAD_TEMPLATE (object));
446 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
453 * @name: the name of the new pad.
454 * @direction: the #GstPadDirection of the pad.
456 * Creates a new pad with the given name in the given direction.
457 * If name is NULL, a guaranteed unique name (across all pads)
459 * This function makes a copy of the name so you can safely free the name.
461 * Returns: a new #GstPad, or NULL in case of an error.
466 gst_pad_new (const gchar * name, GstPadDirection direction)
468 return g_object_new (GST_TYPE_PAD,
469 "name", name, "direction", direction, NULL);
473 * gst_pad_new_from_template:
474 * @templ: the pad template to use
475 * @name: the name of the element
477 * Creates a new pad with the given name from the given template.
478 * If name is NULL, a guaranteed unique name (across all pads)
480 * This function makes a copy of the name so you can safely free the name.
482 * Returns: a new #GstPad, or NULL in case of an error.
485 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
487 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
489 return g_object_new (GST_TYPE_PAD,
490 "name", name, "direction", templ->direction, "template", templ, NULL);
494 * gst_pad_get_direction:
495 * @pad: a #GstPad to get the direction of.
497 * Gets the direction of the pad. The direction of the pad is
498 * decided at construction time so this function does not take
501 * Returns: the #GstPadDirection of the pad.
506 gst_pad_get_direction (GstPad * pad)
508 GstPadDirection result;
510 /* PAD_UNKNOWN is a little silly but we need some sort of
511 * error return value */
512 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
515 result = GST_PAD_DIRECTION (pad);
522 gst_pad_activate_default (GstPad * pad)
524 return gst_pad_activate_push (pad, TRUE);
528 pre_activate (GstPad * pad, GstActivateMode new_mode)
531 case GST_ACTIVATE_PUSH:
532 case GST_ACTIVATE_PULL:
534 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
536 GST_PAD_UNSET_FLUSHING (pad);
537 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
540 case GST_ACTIVATE_NONE:
542 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing",
544 GST_PAD_SET_FLUSHING (pad);
545 /* unlock blocked pads so element can resume and stop */
546 GST_PAD_BLOCK_SIGNAL (pad);
553 post_activate (GstPad * pad, GstActivateMode new_mode)
556 case GST_ACTIVATE_PUSH:
557 case GST_ACTIVATE_PULL:
560 case GST_ACTIVATE_NONE:
561 /* ensures that streaming stops */
562 GST_STREAM_LOCK (pad);
563 /* while we're at it set activation mode */
565 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d", new_mode);
566 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
568 GST_STREAM_UNLOCK (pad);
574 * gst_pad_set_active:
575 * @pad: the #GstPad to activate or deactivate.
576 * @active: whether or not the pad should be active.
578 * Activates or deactivates the given pad.
579 * Must be called with the parent element's #GST_STATE_LOCK held.
580 * Normally called from within core state change functions.
582 * If @active, makes sure the pad is active. If it is already active, either in
583 * push or pull mode, just return. Otherwise dispatches to the pad's activate
584 * function to perform the actual activation.
586 * If not @active, checks the pad's current mode and calls
587 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
590 * Returns: #TRUE if the operation was successful.
592 * MT safe. Must be called with parent element's #GST_STATE_LOCK held.
595 gst_pad_set_active (GstPad * pad, gboolean active)
598 gboolean ret = FALSE;
600 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
603 old = GST_PAD_ACTIVATE_MODE (pad);
608 case GST_ACTIVATE_PUSH:
609 case GST_ACTIVATE_PULL:
612 case GST_ACTIVATE_NONE:
613 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
618 case GST_ACTIVATE_PUSH:
619 ret = gst_pad_activate_push (pad, FALSE);
621 case GST_ACTIVATE_PULL:
622 ret = gst_pad_activate_pull (pad, FALSE);
624 case GST_ACTIVATE_NONE:
630 if (!active && !ret) {
632 g_critical ("Failed to deactivate pad %s:%s, very bad",
633 GST_DEBUG_PAD_NAME (pad));
641 * gst_pad_activate_pull:
642 * @pad: the #GstPad to activate or deactivate.
643 * @active: whether or not the pad should be active.
645 * Activates or deactivates the given pad in pull mode via dispatching to the
646 * pad's activatepullfunc. For use from within pad activation functions only.
647 * When called on sink pads, will first proxy the call to the peer pad, which is
648 * expected to activate its internally linked pads from within its activate_pull
651 * If you don't know what this is, you probably don't want to call it.
653 * Returns: TRUE if the operation was successfull.
658 gst_pad_activate_pull (GstPad * pad, gboolean active)
660 GstActivateMode old, new;
663 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
666 old = GST_PAD_ACTIVATE_MODE (pad);
669 if ((active && old == GST_ACTIVATE_PULL)
670 || (!active && old == GST_ACTIVATE_NONE))
674 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
676 g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE);
679 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
680 if ((peer = gst_pad_get_peer (pad))) {
681 if (!gst_pad_activate_pull (peer, active))
683 gst_object_unref (peer);
687 new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
688 pre_activate (pad, new);
690 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
691 if (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active))
694 /* can happen for sinks of passthrough elements */
697 post_activate (pad, new);
699 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
700 active ? "activated" : "deactivated");
705 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
706 active ? "activated" : "deactivated");
712 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
713 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
715 gst_object_unref (peer);
720 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
721 active ? "activate" : "deactivate");
722 pre_activate (pad, GST_ACTIVATE_NONE);
723 post_activate (pad, GST_ACTIVATE_NONE);
729 * gst_pad_activate_push:
730 * @pad: the #GstPad to activate or deactivate.
731 * @active: whether or not the pad should be active.
733 * Activates or deactivates the given pad in push mode via dispatching to the
734 * pad's activatepushfunc. For use from within pad activation functions only.
736 * If you don't know what this is, you probably don't want to call it.
738 * Returns: TRUE if the operation was successfull.
743 gst_pad_activate_push (GstPad * pad, gboolean active)
745 GstActivateMode old, new;
747 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
748 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
749 active ? "activated" : "deactivated");
752 old = GST_PAD_ACTIVATE_MODE (pad);
755 if ((active && old == GST_ACTIVATE_PUSH)
756 || (!active && old == GST_ACTIVATE_NONE))
760 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
762 g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE);
765 new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
766 pre_activate (pad, new);
768 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
769 if (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) {
773 /* quite ok, element relies on state change func to prepare itself */
776 post_activate (pad, new);
778 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
779 active ? "activated" : "deactivated");
784 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
785 active ? "activated" : "deactivated");
790 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
791 active ? "activate" : "deactivate");
792 pre_activate (pad, GST_ACTIVATE_NONE);
793 post_activate (pad, GST_ACTIVATE_NONE);
800 * @pad: the #GstPad to query
802 * Query if a pad is active
804 * Returns: TRUE if the pad is active.
809 gst_pad_is_active (GstPad * pad)
811 gboolean result = FALSE;
813 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
816 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
823 * gst_pad_set_blocked_async:
824 * @pad: the #GstPad to block or unblock
825 * @blocked: boolean indicating whether the pad should be blocked or unblocked
826 * @callback: #GstPadBlockCallback that will be called when the
828 * @user_data: user data passed to the callback
830 * Blocks or unblocks the dataflow on a pad. The provided callback
831 * is called when the operation succeeds; this happens right before the next
832 * attempt at pushing a buffer on the pad.
834 * This can take a while as the pad can only become blocked when real dataflow
836 * When the pipeline is stalled, for example in PAUSED, this can
837 * take an indeterminate amount of time.
838 * You can pass NULL as the callback to make this call block. Be careful with
839 * this blocking call as it might not return for reasons stated above.
841 * Returns: TRUE if the pad could be blocked. This function can fail
842 * if wrong parameters were passed or the pad was already in the
848 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
849 GstPadBlockCallback callback, gpointer user_data)
851 gboolean was_blocked;
853 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
857 was_blocked = GST_PAD_IS_BLOCKED (pad);
859 if (G_UNLIKELY (was_blocked == blocked))
860 goto had_right_state;
863 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad %s:%s",
864 GST_DEBUG_PAD_NAME (pad));
866 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
867 pad->block_callback = callback;
868 pad->block_data = user_data;
870 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
871 GST_PAD_BLOCK_WAIT (pad);
872 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
875 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad %s:%s",
876 GST_DEBUG_PAD_NAME (pad));
878 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
880 pad->block_callback = callback;
881 pad->block_data = user_data;
884 GST_PAD_BLOCK_SIGNAL (pad);
886 GST_PAD_BLOCK_SIGNAL (pad);
887 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
888 GST_PAD_BLOCK_WAIT (pad);
889 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
898 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
899 "pad %s:%s was in right state", GST_DEBUG_PAD_NAME (pad));
906 * gst_pad_set_blocked:
907 * @pad: the #GstPad to block or unblock
908 * @blocked: boolean indicating we should block or unblock
910 * Blocks or unblocks the dataflow on a pad. This function is
911 * a shortcut for gst_pad_set_blocked_async() with a NULL
914 * Returns: TRUE if the pad could be blocked. This function can fail
915 * wrong parameters were passed or the pad was already in the
921 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
923 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
927 * gst_pad_is_blocked:
928 * @pad: the #GstPad to query
930 * Checks if the pad is blocked or not. This function returns the
931 * last requested state of the pad. It is not certain that the pad
932 * is actually blocked at this point.
934 * Returns: TRUE if the pad is blocked.
939 gst_pad_is_blocked (GstPad * pad)
941 gboolean result = FALSE;
943 g_return_val_if_fail (GST_IS_PAD (pad), result);
946 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
953 * gst_pad_set_activate_function:
954 * @pad: a sink #GstPad.
955 * @activate: the #GstPadActivateFunction to set.
957 * Sets the given activate function for the pad. The activate function will
958 * dispatch to activate_push or activate_pull to perform the actual activation.
959 * Only makes sense to set on sink pads.
961 * Call this function if your sink pad can start a pull-based task.
964 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
966 g_return_if_fail (GST_IS_PAD (pad));
968 GST_PAD_ACTIVATEFUNC (pad) = activate;
969 GST_CAT_DEBUG (GST_CAT_PADS, "activatefunc for %s:%s set to %s",
970 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activate));
974 * gst_pad_set_activatepull_function:
975 * @pad: a sink #GstPad.
976 * @activatepull: the #GstPadActivateModeFunction to set.
978 * Sets the given activate_pull function for the pad. An activate_pull function
979 * prepares the element and any upstream connections for pulling. See XXX
980 * part-activation.txt for details.
983 gst_pad_set_activatepull_function (GstPad * pad,
984 GstPadActivateModeFunction activatepull)
986 g_return_if_fail (GST_IS_PAD (pad));
988 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
989 GST_CAT_DEBUG (GST_CAT_PADS, "activatepullfunc for %s:%s set to %s",
990 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepull));
994 * gst_pad_set_activatepush_function:
995 * @pad: a sink #GstPad.
996 * @activatepush: the #GstPadActivateModeFunction to set.
998 * Sets the given activate_push function for the pad. An activate_push function
999 * prepares the element for pushing. See XXX part-activation.txt for details.
1002 gst_pad_set_activatepush_function (GstPad * pad,
1003 GstPadActivateModeFunction activatepush)
1005 g_return_if_fail (GST_IS_PAD (pad));
1007 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1008 GST_CAT_DEBUG (GST_CAT_PADS, "activatepushfunc for %s:%s set to %s",
1009 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepush));
1013 * gst_pad_set_chain_function:
1014 * @pad: a sink #GstPad.
1015 * @chain: the #GstPadChainFunction to set.
1017 * Sets the given chain function for the pad. The chain function is called to
1018 * process a #GstBuffer input buffer.
1021 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1023 g_return_if_fail (GST_IS_PAD (pad));
1024 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
1026 GST_PAD_CHAINFUNC (pad) = chain;
1027 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
1028 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
1032 * gst_pad_set_getrange_function:
1033 * @pad: a source #GstPad.
1034 * @get: the #GstPadGetRangeFunction to set.
1036 * Sets the given getrange function for the pad. The getrange function is called to
1037 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
1041 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1043 g_return_if_fail (GST_IS_PAD (pad));
1044 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1046 GST_PAD_GETRANGEFUNC (pad) = get;
1048 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
1049 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
1053 * gst_pad_set_checkgetrange_function:
1054 * @pad: a source #GstPad.
1055 * @check: the #GstPadCheckGetRangeFunction to set.
1057 * Sets the given checkgetrange function for the pad. Implement this function on
1058 * a pad if you dynamically support getrange based scheduling on the pad.
1061 gst_pad_set_checkgetrange_function (GstPad * pad,
1062 GstPadCheckGetRangeFunction check)
1064 g_return_if_fail (GST_IS_PAD (pad));
1065 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1067 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
1069 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
1070 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
1074 * gst_pad_set_event_function:
1075 * @pad: a source #GstPad.
1076 * @event: the #GstPadEventFunction to set.
1078 * Sets the given event handler for the pad.
1081 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1083 g_return_if_fail (GST_IS_PAD (pad));
1085 GST_PAD_EVENTFUNC (pad) = event;
1087 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
1088 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
1092 * gst_pad_set_query_function:
1093 * @pad: a #GstPad of either direction.
1094 * @query: the #GstPadQueryFunction to set.
1096 * Set the given query function for the pad.
1099 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1101 g_return_if_fail (GST_IS_PAD (pad));
1103 GST_PAD_QUERYFUNC (pad) = query;
1105 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
1106 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
1110 * gst_pad_set_query_type_function:
1111 * @pad: a #GstPad of either direction.
1112 * @type_func: the #GstPadQueryTypeFunction to set.
1114 * Set the given query type function for the pad.
1117 gst_pad_set_query_type_function (GstPad * pad,
1118 GstPadQueryTypeFunction type_func)
1120 g_return_if_fail (GST_IS_PAD (pad));
1122 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1124 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
1125 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
1129 * gst_pad_get_query_types:
1132 * Get an array of supported queries that can be performed
1135 * Returns: a zero-terminated array of #GstQueryType.
1137 const GstQueryType *
1138 gst_pad_get_query_types (GstPad * pad)
1140 GstPadQueryTypeFunction func;
1142 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1144 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1156 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1158 *data = gst_pad_get_query_types (pad);
1164 * gst_pad_get_query_types_default:
1167 * Invoke the default dispatcher for the query types on
1170 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1171 * internally-linked pads has a query types function.
1173 const GstQueryType *
1174 gst_pad_get_query_types_default (GstPad * pad)
1176 GstQueryType *result = NULL;
1178 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1180 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1181 gst_pad_get_query_types_dispatcher, &result);
1187 * gst_pad_set_internal_link_function:
1188 * @pad: a #GstPad of either direction.
1189 * @intlink: the #GstPadIntLinkFunction to set.
1191 * Sets the given internal link function for the pad.
1194 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1196 g_return_if_fail (GST_IS_PAD (pad));
1198 GST_PAD_INTLINKFUNC (pad) = intlink;
1199 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1200 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1204 * gst_pad_set_link_function:
1206 * @link: the #GstPadLinkFunction to set.
1208 * Sets the given link function for the pad. It will be called when the pad is
1209 * linked or relinked with caps. The caps passed to the link function is
1210 * the caps for the connnection. It can contain a non fixed caps.
1212 * The return value GST_PAD_LINK_OK should be used when the connection can be
1215 * The return value GST_PAD_LINK_REFUSED should be used when the connection
1216 * cannot be made for some reason.
1219 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1221 g_return_if_fail (GST_IS_PAD (pad));
1223 GST_PAD_LINKFUNC (pad) = link;
1224 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1225 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1229 * gst_pad_set_unlink_function:
1231 * @unlink: the #GstPadUnlinkFunction to set.
1233 * Sets the given unlink function for the pad. It will be called
1234 * when the pad is unlinked.
1237 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1239 g_return_if_fail (GST_IS_PAD (pad));
1241 GST_PAD_UNLINKFUNC (pad) = unlink;
1242 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1243 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1247 * gst_pad_set_getcaps_function:
1249 * @getcaps: the #GstPadGetCapsFunction to set.
1251 * Sets the given getcaps function for the pad. @getcaps should return the
1252 * allowable caps for a pad in the context of the element's state, its link to
1253 * other elements, and the devices or files it has opened. These caps must be a
1254 * subset of the pad template caps. In the NULL state with no links, @getcaps
1255 * should ideally return the same caps as the pad template. In rare
1256 * circumstances, an object property can affect the caps returned by @getcaps,
1257 * but this is discouraged.
1259 * You do not need to call this function if @pad's allowed caps are always the
1260 * same as the pad template caps. This can only be true if the padtemplate
1261 * has fixed simple caps.
1263 * For most filters, the caps returned by @getcaps is directly affected by the
1264 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1265 * the srcpad's getcaps function is directly related to the stream data. Again,
1266 * @getcaps should return the most specific caps it reasonably can, since this
1267 * helps with autoplugging.
1269 * Note that the return value from @getcaps is owned by the caller, so the caller
1270 * should unref the caps after usage.
1273 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1275 g_return_if_fail (GST_IS_PAD (pad));
1277 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1278 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1279 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1283 * gst_pad_set_acceptcaps_function:
1285 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1287 * Sets the given acceptcaps function for the pad. The acceptcaps function
1288 * will be called to check if the pad can accept the given caps.
1291 gst_pad_set_acceptcaps_function (GstPad * pad,
1292 GstPadAcceptCapsFunction acceptcaps)
1294 g_return_if_fail (GST_IS_PAD (pad));
1296 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1297 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1298 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1302 * gst_pad_set_fixatecaps_function:
1304 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1306 * Sets the given fixatecaps function for the pad. The fixatecaps function
1307 * will be called whenever the default values for a GstCaps needs to be
1311 gst_pad_set_fixatecaps_function (GstPad * pad,
1312 GstPadFixateCapsFunction fixatecaps)
1314 g_return_if_fail (GST_IS_PAD (pad));
1316 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1317 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1318 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1322 * gst_pad_set_setcaps_function:
1324 * @setcaps: the #GstPadSetCapsFunction to set.
1326 * Sets the given setcaps function for the pad. The setcaps function
1327 * will be called whenever a buffer with a new media type is pushed or
1328 * pulled from the pad. The pad/element needs to update it's internal
1329 * structures to process the new media type. If this new type is not
1330 * acceptable, the setcaps function should return FALSE.
1333 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1335 g_return_if_fail (GST_IS_PAD (pad));
1337 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1338 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1339 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1343 * gst_pad_set_bufferalloc_function:
1344 * @pad: a sink #GstPad.
1345 * @bufalloc: the #GstPadBufferAllocFunction to set.
1347 * Sets the given bufferalloc function for the pad. Note that the
1348 * bufferalloc function can only be set on sinkpads.
1351 gst_pad_set_bufferalloc_function (GstPad * pad,
1352 GstPadBufferAllocFunction bufalloc)
1354 g_return_if_fail (GST_IS_PAD (pad));
1355 g_return_if_fail (GST_PAD_IS_SINK (pad));
1357 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1358 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1359 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1364 * @srcpad: the source #GstPad to unlink.
1365 * @sinkpad: the sink #GstPad to unlink.
1367 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1370 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1371 * the pads were not linked together.
1376 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1378 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1379 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1381 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1382 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1383 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1387 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1392 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1395 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1396 goto not_linked_together;
1398 if (GST_PAD_UNLINKFUNC (srcpad)) {
1399 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1401 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1402 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1405 /* first clear peers */
1406 GST_PAD_PEER (srcpad) = NULL;
1407 GST_PAD_PEER (sinkpad) = NULL;
1409 GST_UNLOCK (sinkpad);
1410 GST_UNLOCK (srcpad);
1412 /* fire off a signal to each of the pads telling them
1413 * that they've been unlinked */
1414 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1415 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1417 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1418 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1424 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1425 GST_UNLOCK (srcpad);
1430 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1431 GST_UNLOCK (sinkpad);
1432 GST_UNLOCK (srcpad);
1435 not_linked_together:
1437 /* we do not emit a warning in this case because unlinking cannot
1438 * be made MT safe.*/
1439 GST_UNLOCK (sinkpad);
1440 GST_UNLOCK (srcpad);
1446 * gst_pad_is_linked:
1447 * @pad: pad to check
1449 * Checks if a @pad is linked to another pad or not.
1451 * Returns: TRUE if the pad is linked, FALSE otherwise.
1456 gst_pad_is_linked (GstPad * pad)
1460 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1463 result = (GST_PAD_PEER (pad) != NULL);
1469 /* get the caps from both pads and see if the intersection
1472 * This function should be called with the pad LOCK on both
1476 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1481 srccaps = gst_pad_get_caps_unlocked (src);
1482 sinkcaps = gst_pad_get_caps_unlocked (sink);
1483 GST_CAT_DEBUG (GST_CAT_CAPS, " src caps %" GST_PTR_FORMAT, srccaps);
1484 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1486 /* if we have caps on both pads we can check the intersection */
1487 if (srccaps && sinkcaps) {
1490 icaps = gst_caps_intersect (srccaps, sinkcaps);
1491 gst_caps_unref (srccaps);
1492 gst_caps_unref (sinkcaps);
1494 GST_CAT_DEBUG (GST_CAT_CAPS,
1495 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1497 if (!icaps || gst_caps_is_empty (icaps)) {
1498 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is empty");
1499 gst_caps_unref (icaps);
1502 gst_caps_unref (icaps);
1508 /* check if the grandparents of both pads are the same.
1509 * This check is required so that we don't try to link
1510 * pads from elements in different bins without ghostpads.
1512 * The LOCK should be helt on both pads
1515 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1517 GstObject *psrc, *psink;
1518 gboolean res = TRUE;
1520 psrc = GST_OBJECT_PARENT (src);
1521 psink = GST_OBJECT_PARENT (sink);
1523 /* if one of the pads has no parent, we allow the link */
1524 if (psrc && psink) {
1525 /* if the parents are the same, we have a loop */
1526 if (psrc == psink) {
1527 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1532 /* if they both have a parent, we check the grandparents */
1533 psrc = gst_object_get_parent (psrc);
1534 psink = gst_object_get_parent (psink);
1536 if (psrc != psink) {
1537 /* if they have grandparents but they are not the same */
1538 GST_CAT_DEBUG (GST_CAT_CAPS,
1539 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1540 GST_PTR_FORMAT, psrc, psink);
1544 gst_object_unref (psrc);
1546 gst_object_unref (psink);
1552 /* FIXME leftover from an attempt at refactoring... */
1553 /* call with the two pads unlocked */
1554 static GstPadLinkReturn
1555 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1557 /* generic checks */
1558 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1559 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1561 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1562 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1566 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1569 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1570 goto src_was_linked;
1574 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1577 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1578 goto sink_was_linked;
1580 /* check hierarchy, pads can only be linked if the grandparents
1582 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1583 goto wrong_hierarchy;
1585 /* check pad caps for non-empty intersection */
1586 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1589 /* FIXME check pad scheduling for non-empty intersection */
1591 return GST_PAD_LINK_OK;
1595 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1596 GST_UNLOCK (srcpad);
1597 return GST_PAD_LINK_WRONG_DIRECTION;
1601 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was linked",
1602 GST_DEBUG_PAD_NAME (srcpad));
1603 /* we do not emit a warning in this case because unlinking cannot
1604 * be made MT safe.*/
1605 GST_UNLOCK (srcpad);
1606 return GST_PAD_LINK_WAS_LINKED;
1610 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1611 GST_UNLOCK (sinkpad);
1612 GST_UNLOCK (srcpad);
1613 return GST_PAD_LINK_WRONG_DIRECTION;
1617 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was linked",
1618 GST_DEBUG_PAD_NAME (sinkpad));
1619 /* we do not emit a warning in this case because unlinking cannot
1620 * be made MT safe.*/
1621 GST_UNLOCK (sinkpad);
1622 GST_UNLOCK (srcpad);
1623 return GST_PAD_LINK_WAS_LINKED;
1627 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1628 GST_UNLOCK (sinkpad);
1629 GST_UNLOCK (srcpad);
1630 return GST_PAD_LINK_WRONG_HIERARCHY;
1634 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1635 GST_UNLOCK (sinkpad);
1636 GST_UNLOCK (srcpad);
1637 return GST_PAD_LINK_NOFORMAT;
1643 * @srcpad: the source #GstPad to link.
1644 * @sinkpad: the sink #GstPad to link.
1646 * Links the source pad and the sink pad.
1648 * Returns: A result code indicating if the connection worked or
1654 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1656 GstPadLinkReturn result;
1658 /* prepare will also lock the two pads */
1659 result = gst_pad_link_prepare (srcpad, sinkpad);
1661 if (result != GST_PAD_LINK_OK)
1662 goto prepare_failed;
1664 GST_UNLOCK (sinkpad);
1665 GST_UNLOCK (srcpad);
1667 /* FIXME released the locks here, concurrent thread might link
1668 * something else. */
1669 if (GST_PAD_LINKFUNC (srcpad)) {
1670 /* this one will call the peer link function */
1671 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1672 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1673 /* if no source link function, we need to call the sink link
1674 * function ourselves. */
1675 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1677 result = GST_PAD_LINK_OK;
1683 if (result == GST_PAD_LINK_OK) {
1684 GST_PAD_PEER (srcpad) = sinkpad;
1685 GST_PAD_PEER (sinkpad) = srcpad;
1687 GST_UNLOCK (sinkpad);
1688 GST_UNLOCK (srcpad);
1690 /* fire off a signal to each of the pads telling them
1691 * that they've been linked */
1692 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1693 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1695 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1696 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1698 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1699 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1701 GST_UNLOCK (sinkpad);
1702 GST_UNLOCK (srcpad);
1713 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1715 /* this function would need checks if it weren't static */
1718 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1722 gst_pad_template_pad_created (templ, pad);
1726 * gst_pad_get_pad_template:
1729 * Gets the template for @pad.
1731 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1732 * if this pad has no template.
1734 * FIXME: currently returns an unrefcounted padtemplate.
1737 gst_pad_get_pad_template (GstPad * pad)
1739 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1741 return GST_PAD_PAD_TEMPLATE (pad);
1745 /* should be called with the pad LOCK held */
1746 /* refs the caps, so caller is responsible for getting it unreffed */
1748 gst_pad_get_caps_unlocked (GstPad * pad)
1750 GstCaps *result = NULL;
1752 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1753 GST_DEBUG_PAD_NAME (pad), pad);
1755 if (GST_PAD_GETCAPSFUNC (pad)) {
1756 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1758 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1760 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1762 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1764 if (result == NULL) {
1765 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1766 GST_DEBUG_PAD_NAME (pad));
1768 GST_CAT_DEBUG (GST_CAT_CAPS,
1769 "pad getcaps %s:%s returned %" GST_PTR_FORMAT,
1770 GST_DEBUG_PAD_NAME (pad), result);
1771 #ifndef G_DISABLE_ASSERT
1772 /* check that the returned caps are a real subset of the template caps */
1773 if (GST_PAD_PAD_TEMPLATE (pad)) {
1774 const GstCaps *templ_caps =
1775 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1776 if (!gst_caps_is_subset (result, templ_caps)) {
1779 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1780 "pad returned caps %" GST_PTR_FORMAT
1781 " which are not a real subset of its template caps %"
1782 GST_PTR_FORMAT, result, templ_caps);
1784 ("pad %s:%s returned caps that are not a real subset of its template caps",
1785 GST_DEBUG_PAD_NAME (pad));
1786 temp = gst_caps_intersect (templ_caps, result);
1787 gst_caps_unref (result);
1795 if (GST_PAD_PAD_TEMPLATE (pad)) {
1796 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1798 result = GST_PAD_TEMPLATE_CAPS (templ);
1799 GST_CAT_DEBUG (GST_CAT_CAPS,
1800 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1803 result = gst_caps_ref (result);
1806 if (GST_PAD_CAPS (pad)) {
1807 result = GST_PAD_CAPS (pad);
1809 GST_CAT_DEBUG (GST_CAT_CAPS,
1810 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1812 result = gst_caps_ref (result);
1816 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1817 result = gst_caps_new_empty ();
1825 * @pad: a #GstPad to get the capabilities of.
1827 * Gets the capabilities this pad can produce or consume.
1828 * Note that this method doesn't necessarily returns the caps set by
1829 * #gst_pad_set_caps - use #GST_PAD_CAPS for that instead.
1830 * gst_pad_get_caps returns all possible caps a pad can operate with, using
1831 * the pad's get_caps function;
1832 * this returns the pad template caps if not explicitly set.
1834 * Returns: a newly allocated copy of the #GstCaps of this pad.
1839 gst_pad_get_caps (GstPad * pad)
1841 GstCaps *result = NULL;
1843 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1847 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1848 GST_DEBUG_PAD_NAME (pad), pad);
1850 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (pad)))
1851 goto was_dispatching;
1853 result = gst_pad_get_caps_unlocked (pad);
1860 GST_CAT_DEBUG (GST_CAT_CAPS,
1861 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1862 g_warning ("pad %s:%s recursively called getcaps!",
1863 GST_DEBUG_PAD_NAME (pad));
1870 * gst_pad_peer_get_caps:
1871 * @pad: a #GstPad to get the peer capabilities of.
1873 * Gets the capabilities of the peer connected to this pad.
1875 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1876 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1877 * peer pad or when this function is called recursively from a getcaps function.
1880 gst_pad_peer_get_caps (GstPad * pad)
1883 GstCaps *result = NULL;
1885 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1889 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1890 GST_DEBUG_PAD_NAME (pad), pad);
1892 peerpad = GST_PAD_PEER (pad);
1893 if (G_UNLIKELY (peerpad == NULL))
1896 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (peerpad)))
1897 goto was_dispatching;
1899 gst_object_ref (peerpad);
1902 result = gst_pad_get_caps (peerpad);
1904 gst_object_unref (peerpad);
1915 GST_CAT_DEBUG (GST_CAT_CAPS,
1916 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1917 g_warning ("pad %s:%s recursively called getcaps!",
1918 GST_DEBUG_PAD_NAME (pad));
1925 fixate_value (GValue * dest, const GValue * src)
1927 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
1928 g_value_init (dest, G_TYPE_INT);
1929 g_value_set_int (dest, gst_value_get_int_range_min (src));
1930 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
1931 g_value_init (dest, G_TYPE_DOUBLE);
1932 g_value_set_double (dest, gst_value_get_double_range_min (src));
1933 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1934 GValue temp = { 0 };
1936 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
1937 if (!fixate_value (dest, &temp))
1938 gst_value_init_and_copy (dest, &temp);
1939 g_value_unset (&temp);
1940 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
1941 gboolean res = FALSE;
1944 g_value_init (dest, GST_TYPE_ARRAY);
1945 for (n = 0; n < gst_value_list_get_size (src); n++) {
1947 const GValue *orig_kid = gst_value_list_get_value (src, n);
1949 if (!fixate_value (&kid, orig_kid))
1950 gst_value_init_and_copy (&kid, orig_kid);
1953 gst_value_list_append_value (dest, &kid);
1954 g_value_unset (&kid);
1958 g_value_unset (dest);
1969 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
1971 GstStructure *s = data;
1974 if (fixate_value (&v, value)) {
1975 gst_structure_id_set_value (s, field_id, &v);
1983 * gst_pad_fixate_caps:
1984 * @pad: a #GstPad to fixate
1985 * @caps: the #GstCaps to fixate
1987 * Fixate a caps on the given pad. Modifies the caps in place, so you should
1988 * make sure that the caps are actually writable (see gst_caps_make_writable()).
1991 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
1993 GstPadFixateCapsFunction fixatefunc;
1996 g_return_if_fail (GST_IS_PAD (pad));
1997 g_return_if_fail (caps != NULL);
1999 if (gst_caps_is_fixed (caps))
2002 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
2004 fixatefunc (pad, caps);
2007 /* default fixation */
2008 for (n = 0; n < gst_caps_get_size (caps); n++) {
2009 GstStructure *s = gst_caps_get_structure (caps, n);
2011 gst_structure_foreach (s, gst_pad_default_fixate, s);
2016 * gst_pad_accept_caps:
2017 * @pad: a #GstPad to check
2018 * @caps: a #GstCaps to check on the pad
2020 * Check if the given pad accepts the caps.
2022 * Returns: TRUE if the pad can accept the caps.
2025 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2028 GstPadAcceptCapsFunction acceptfunc;
2030 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2032 /* any pad can be unnegotiated */
2037 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2039 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
2040 GST_DEBUG_PAD_NAME (pad), pad);
2044 /* we can call the function */
2045 result = acceptfunc (pad, caps);
2047 /* else see get the caps and see if it intersects to something
2052 allowed = gst_pad_get_caps (pad);
2054 intersect = gst_caps_intersect (allowed, caps);
2056 result = !gst_caps_is_empty (intersect);
2058 gst_caps_unref (allowed);
2059 gst_caps_unref (intersect);
2068 * gst_pad_peer_accept_caps:
2069 * @pad: a #GstPad to check
2070 * @caps: a #GstCaps to check on the pad
2072 * Check if the given pad accepts the caps.
2074 * Returns: TRUE if the pad can accept the caps.
2077 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2082 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2086 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
2087 GST_DEBUG_PAD_NAME (pad), pad);
2089 peerpad = GST_PAD_PEER (pad);
2090 if (G_UNLIKELY (peerpad == NULL))
2093 result = gst_pad_accept_caps (peerpad, caps);
2107 * @pad: a #GstPad to set the capabilities of.
2108 * @caps: a #GstCaps to set.
2110 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2111 * caps on the pad will be unreffed. This function refs the caps so you should
2112 * unref if as soon as you don't need it anymore.
2113 * It is possible to set NULL caps, which will make the pad unnegotiated
2116 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2117 * or bad parameters were provided to this function.
2122 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2124 GstPadSetCapsFunction setcaps;
2127 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2128 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2131 setcaps = GST_PAD_SETCAPSFUNC (pad);
2133 existing = GST_PAD_CAPS (pad);
2134 if (caps == existing)
2135 goto setting_same_caps;
2136 else if (caps && existing && gst_caps_is_equal (caps, existing))
2137 goto setting_same_caps;
2139 /* call setcaps function to configure the pad */
2140 if (setcaps != NULL && caps) {
2141 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2142 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2144 if (!setcaps (pad, caps))
2147 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2149 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
2150 GST_DEBUG_PAD_NAME (pad));
2154 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2155 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
2156 GST_DEBUG_PAD_NAME (pad), caps);
2159 g_object_notify (G_OBJECT (pad), "caps");
2166 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2167 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2168 "caps %" GST_PTR_FORMAT " same as existing, updating ptr only", caps);
2175 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2176 GST_CAT_DEBUG (GST_CAT_CAPS,
2177 "pad %s:%s, caps %" GST_PTR_FORMAT " could not be set",
2178 GST_DEBUG_PAD_NAME (pad), caps);
2186 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2188 GstPadAcceptCapsFunction acceptcaps;
2189 GstPadSetCapsFunction setcaps;
2192 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2193 setcaps = GST_PAD_SETCAPSFUNC (pad);
2195 /* See if pad accepts the caps, by calling acceptcaps, only
2196 * needed if no setcaps function */
2197 if (setcaps == NULL && acceptcaps != NULL) {
2198 if (!acceptcaps (pad, caps))
2201 /* set caps on pad if call succeeds */
2202 res = gst_pad_set_caps (pad, caps);
2203 /* no need to unref the caps here, set_caps takes a ref and
2204 * our ref goes away when we leave this function. */
2210 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2215 /* returns TRUE if the src pad could be configured to accept the given caps */
2217 gst_pad_configure_src (GstPad * pad, GstCaps * caps)
2219 GstPadAcceptCapsFunction acceptcaps;
2220 GstPadSetCapsFunction setcaps;
2223 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2224 setcaps = GST_PAD_SETCAPSFUNC (pad);
2226 /* See if pad accepts the caps, by calling acceptcaps, only
2227 * needed if no setcaps function */
2228 if (setcaps == NULL && acceptcaps != NULL) {
2229 if (!acceptcaps (pad, caps))
2232 /* set caps on pad if call succeeds */
2233 res = gst_pad_set_caps (pad, caps);
2234 /* no need to unref the caps here, set_caps takes a ref and
2235 * our ref goes away when we leave this function. */
2241 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2247 * gst_pad_get_pad_template_caps:
2248 * @pad: a #GstPad to get the template capabilities from.
2250 * Gets the capabilities for @pad's template.
2252 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2253 * on the caps, make a copy (see gst_caps_copy ()).
2256 gst_pad_get_pad_template_caps (GstPad * pad)
2258 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2260 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2262 if (GST_PAD_PAD_TEMPLATE (pad))
2263 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2265 return gst_static_caps_get (&anycaps);
2271 * @pad: a #GstPad to get the peer of.
2273 * Gets the peer of @pad. This function refs the peer pad so
2274 * you need to unref it after use.
2276 * Returns: the peer #GstPad. Unref after usage.
2281 gst_pad_get_peer (GstPad * pad)
2285 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2288 result = GST_PAD_PEER (pad);
2290 gst_object_ref (result);
2297 * gst_pad_get_allowed_caps:
2298 * @srcpad: a #GstPad, it must a a source pad.
2300 * Gets the capabilities of the allowed media types that can flow through
2301 * @srcpad and its peer. The pad must be a source pad.
2302 * The caller must free the resulting caps.
2304 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2305 * you no longer need it. This function returns NULL when the @srcpad has no
2311 gst_pad_get_allowed_caps (GstPad * srcpad)
2318 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2319 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2323 peer = GST_PAD_PEER (srcpad);
2324 if (G_UNLIKELY (peer == NULL))
2327 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2328 GST_DEBUG_PAD_NAME (srcpad));
2330 gst_object_ref (peer);
2331 GST_UNLOCK (srcpad);
2332 mycaps = gst_pad_get_caps (srcpad);
2334 peercaps = gst_pad_get_caps (peer);
2335 gst_object_unref (peer);
2337 caps = gst_caps_intersect (mycaps, peercaps);
2338 gst_caps_unref (peercaps);
2339 gst_caps_unref (mycaps);
2341 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2347 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2348 GST_DEBUG_PAD_NAME (srcpad));
2349 GST_UNLOCK (srcpad);
2356 * gst_pad_get_negotiated_caps:
2359 * Gets the capabilities of the media type that currently flows through @pad
2362 * This function can be used on both src and sinkpads. Note that srcpads are
2363 * always negotiated before sinkpads so it is possible that the negotiated caps
2364 * on the srcpad do not match the negotiated caps of the peer.
2366 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2367 * you no longer need it. This function returns NULL when the @pad has no
2368 * peer or is not negotiated yet.
2373 gst_pad_get_negotiated_caps (GstPad * pad)
2378 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2382 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2385 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2386 GST_DEBUG_PAD_NAME (pad));
2388 caps = GST_PAD_CAPS (pad);
2390 gst_caps_ref (caps);
2393 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2399 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2400 GST_DEBUG_PAD_NAME (pad));
2408 * gst_pad_alloc_buffer:
2409 * @pad: a source #GstPad
2410 * @offset: the offset of the new buffer in the stream
2411 * @size: the size of the new buffer
2412 * @caps: the caps of the new buffer
2413 * @buf: a newly allocated buffer
2415 * Allocates a new, empty buffer optimized to push to pad @pad. This
2416 * function only works if @pad is a source pad and has a peer.
2418 * You need to check the caps of the buffer after performing this
2419 * function and renegotiate to the format if needed.
2421 * A new, empty #GstBuffer will be put in the @buf argument.
2423 * Returns: a result code indicating success of the operation. Any
2424 * result code other than GST_FLOW_OK is an error and @buf should
2426 * An error can occur if the pad is not connected or when the downstream
2427 * peer elements cannot provide an acceptable buffer.
2432 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2437 GstPadBufferAllocFunction bufferallocfunc;
2438 gboolean caps_changed;
2440 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2441 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2442 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2445 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2446 handle_pad_block (pad);
2448 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2451 gst_object_ref (peer);
2454 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2458 /* when the peer is flushing we cannot give a buffer */
2459 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2462 if (offset == GST_BUFFER_OFFSET_NONE) {
2463 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2464 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d offset NONE",
2465 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2466 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size);
2468 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2469 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d offset %"
2470 G_GUINT64_FORMAT, GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2471 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size, offset);
2475 ret = bufferallocfunc (peer, offset, size, caps, buf);
2477 if (G_UNLIKELY (ret != GST_FLOW_OK))
2479 if (G_UNLIKELY (*buf == NULL))
2482 /* If the buffer alloc function didn't set up the caps like it should,
2484 if (caps && (GST_BUFFER_CAPS (*buf) == NULL)) {
2485 GST_WARNING ("Buffer allocation function for pad % " GST_PTR_FORMAT
2486 " did not set up caps. Setting", peer);
2488 gst_buffer_set_caps (*buf, caps);
2492 gst_object_unref (peer);
2494 /* FIXME, move capnego this into a base class? */
2495 caps = GST_BUFFER_CAPS (*buf);
2496 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2497 /* we got a new datatype on the pad, see if it can handle it */
2498 if (G_UNLIKELY (caps_changed)) {
2499 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2500 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps)))
2501 goto not_negotiated;
2507 /* pad has no peer */
2508 GST_CAT_DEBUG (GST_CAT_PADS,
2509 "%s:%s called bufferallocfunc but had no peer",
2510 GST_DEBUG_PAD_NAME (pad));
2512 return GST_FLOW_NOT_LINKED;
2516 /* peer was flushing */
2518 gst_object_unref (peer);
2519 GST_CAT_DEBUG (GST_CAT_PADS,
2520 "%s:%s called bufferallocfunc but peer was flushing",
2521 GST_DEBUG_PAD_NAME (pad));
2522 return GST_FLOW_WRONG_STATE;
2524 /* fallback case, allocate a buffer of our own, add pad caps. */
2527 GST_CAT_DEBUG (GST_CAT_PADS,
2528 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2529 *buf = gst_buffer_new_and_alloc (size);
2530 GST_BUFFER_OFFSET (*buf) = offset;
2531 gst_buffer_set_caps (*buf, caps);
2539 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2540 "alloc function retured unacceptable buffer");
2541 return GST_FLOW_NOT_NEGOTIATED;
2545 gst_object_unref (peer);
2546 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2547 "alloc function retured error %s", gst_flow_get_name (ret));
2553 * gst_pad_get_internal_links_default:
2554 * @pad: the #GstPad to get the internal links of.
2556 * Gets a list of pads to which the given pad is linked to
2557 * inside of the parent element.
2558 * This is the default handler, and thus returns a list of all of the
2559 * pads inside the parent element with opposite direction.
2560 * The caller must free this list after use.
2562 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
2567 gst_pad_get_internal_links_default (GstPad * pad)
2572 GstPadDirection direction;
2574 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2576 direction = pad->direction;
2578 parent = GST_PAD_PARENT (pad);
2582 parent_pads = parent->pads;
2584 while (parent_pads) {
2585 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2587 if (parent_pad->direction != direction) {
2588 res = g_list_prepend (res, parent_pad);
2591 parent_pads = g_list_next (parent_pads);
2598 * gst_pad_get_internal_links:
2599 * @pad: the #GstPad to get the internal links of.
2601 * Gets a list of pads to which the given pad is linked to
2602 * inside of the parent element.
2603 * The caller must free this list after use.
2605 * Returns: a newly allocated #GList of pads.
2610 gst_pad_get_internal_links (GstPad * pad)
2614 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2616 if (GST_PAD_INTLINKFUNC (pad))
2617 res = GST_PAD_INTLINKFUNC (pad) (pad);
2624 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2629 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2632 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2634 orig = pads = gst_pad_get_internal_links (pad);
2637 GstPad *eventpad = GST_PAD_CAST (pads->data);
2639 pads = g_list_next (pads);
2641 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2642 /* for each pad we send to, we should ref the event; it's up
2643 * to downstream to unref again when handled. */
2644 GST_LOG_OBJECT (pad, "Reffing and sending event %p (%s) to %s:%s",
2645 event, gst_event_type_get_name (GST_EVENT_TYPE (event)),
2646 GST_DEBUG_PAD_NAME (eventpad));
2647 gst_event_ref (event);
2648 gst_pad_push_event (eventpad, event);
2650 /* we only send the event on one pad, multi-sinkpad elements
2651 * should implement a handler */
2652 GST_LOG_OBJECT (pad, "sending event %p (%s) to one sink pad %s:%s",
2653 event, gst_event_type_get_name (GST_EVENT_TYPE (event)),
2654 GST_DEBUG_PAD_NAME (eventpad));
2655 result = gst_pad_push_event (eventpad, event);
2659 /* we handled the incoming event so we unref once */
2660 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2661 gst_event_unref (event);
2670 * gst_pad_event_default:
2671 * @pad: a #GstPad to call the default event handler on.
2672 * @event: the #GstEvent to handle.
2674 * Invokes the default event handler for the given pad. End-of-stream and
2675 * discontinuity events are handled specially, and then the event is sent to all
2676 * pads internally linked to @pad. Note that if there are many possible sink
2677 * pads that are internally linked to @pad, only one will be sent an event.
2678 * Multi-sinkpad elements should implement custom event handlers.
2680 * Returns: TRUE if the event was sent succesfully.
2683 gst_pad_event_default (GstPad * pad, GstEvent * event)
2685 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2686 g_return_val_if_fail (event != NULL, FALSE);
2688 switch (GST_EVENT_TYPE (event)) {
2691 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2692 gst_pad_pause_task (pad);
2698 return gst_pad_event_default_dispatch (pad, event);
2702 * gst_pad_dispatcher:
2703 * @pad: a #GstPad to dispatch.
2704 * @dispatch: the #GstDispatcherFunction to call.
2705 * @data: gpointer user data passed to the dispatcher function.
2707 * Invokes the given dispatcher function on all pads that are
2708 * internally linked to the given pad.
2709 * The GstPadDispatcherFunction should return TRUE when no further pads
2710 * need to be processed.
2712 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2715 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2718 gboolean res = FALSE;
2719 GList *int_pads, *orig;
2721 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2722 g_return_val_if_fail (dispatch != NULL, FALSE);
2724 orig = int_pads = gst_pad_get_internal_links (pad);
2727 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2728 GstPad *int_peer = GST_PAD_PEER (int_pad);
2731 res = dispatch (int_peer, data);
2735 int_pads = g_list_next (int_pads);
2745 * @pad: a #GstPad to invoke the default query on.
2746 * @query: the #GstQuery to perform.
2748 * Dispatches a query to a pad. The query should have been allocated by the
2749 * caller via one of the type-specific allocation functions in gstquery.h. The
2750 * element is responsible for filling the query with an appropriate response,
2751 * which should then be parsed with a type-specific query parsing function.
2753 * Again, the caller is responsible for both the allocation and deallocation of
2754 * the query structure.
2756 * Returns: TRUE if the query could be performed.
2759 gst_pad_query (GstPad * pad, GstQuery * query)
2761 GstPadQueryFunction func;
2763 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2764 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2766 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2768 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2771 return func (pad, query);
2775 GST_DEBUG ("pad had no query function");
2781 gst_pad_query_default (GstPad * pad, GstQuery * query)
2783 switch (GST_QUERY_TYPE (query)) {
2784 case GST_QUERY_POSITION:
2785 case GST_QUERY_SEEKING:
2786 case GST_QUERY_FORMATS:
2787 case GST_QUERY_LATENCY:
2788 case GST_QUERY_JITTER:
2789 case GST_QUERY_RATE:
2790 case GST_QUERY_CONVERT:
2792 return gst_pad_dispatcher
2793 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2797 #ifndef GST_DISABLE_LOADSAVE
2798 /* FIXME: why isn't this on a GstElement ? */
2800 * gst_pad_load_and_link:
2801 * @self: an #xmlNodePtr to read the description from.
2802 * @parent: the #GstObject element that owns the pad.
2804 * Reads the pad definition from the XML node and links the given pad
2805 * in the element to a pad of an element up in the hierarchy.
2808 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2810 xmlNodePtr field = self->xmlChildrenNode;
2811 GstPad *pad = NULL, *targetpad;
2815 GstObject *grandparent;
2819 if (!strcmp ((char *) field->name, "name")) {
2820 name = (gchar *) xmlNodeGetContent (field);
2821 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2823 } else if (!strcmp ((char *) field->name, "peer")) {
2824 peer = (gchar *) xmlNodeGetContent (field);
2826 field = field->next;
2828 g_return_if_fail (pad != NULL);
2833 split = g_strsplit (peer, ".", 2);
2835 if (split[0] == NULL || split[1] == NULL) {
2836 GST_CAT_DEBUG (GST_CAT_XML,
2837 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2838 peer, GST_DEBUG_PAD_NAME (pad));
2845 g_return_if_fail (split[0] != NULL);
2846 g_return_if_fail (split[1] != NULL);
2848 grandparent = gst_object_get_parent (parent);
2850 if (grandparent && GST_IS_BIN (grandparent)) {
2851 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2858 targetpad = gst_element_get_pad (target, split[1]);
2860 if (targetpad == NULL)
2863 gst_pad_link (pad, targetpad);
2870 * gst_pad_save_thyself:
2871 * @pad: a #GstPad to save.
2872 * @parent: the parent #xmlNodePtr to save the description in.
2874 * Saves the pad into an xml representation.
2876 * Returns: the #xmlNodePtr representation of the pad.
2879 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2884 g_return_val_if_fail (GST_IS_PAD (object), NULL);
2886 pad = GST_PAD (object);
2888 xmlNewChild (parent, NULL, (xmlChar *) "name",
2889 (xmlChar *) GST_PAD_NAME (pad));
2890 if (GST_PAD_PEER (pad) != NULL) {
2893 peer = GST_PAD_PEER (pad);
2894 /* first check to see if the peer's parent's parent is the same */
2895 /* we just save it off */
2896 content = g_strdup_printf ("%s.%s",
2897 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2898 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
2901 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
2908 * gst_ghost_pad_save_thyself:
2909 * @pad: a ghost #GstPad to save.
2910 * @parent: the parent #xmlNodePtr to save the description in.
2912 * Saves the ghost pad into an xml representation.
2914 * Returns: the #xmlNodePtr representation of the pad.
2917 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2921 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2923 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
2924 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
2925 xmlNewChild (self, NULL, (xmlChar *) "parent",
2926 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2928 /* FIXME FIXME FIXME! */
2933 #endif /* GST_DISABLE_LOADSAVE */
2936 * should be called with pad lock held
2941 handle_pad_block (GstPad * pad)
2943 GstPadBlockCallback callback;
2946 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2947 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2949 /* need to grab extra ref for the callbacks */
2950 gst_object_ref (pad);
2952 callback = pad->block_callback;
2954 user_data = pad->block_data;
2956 callback (pad, TRUE, user_data);
2959 GST_PAD_BLOCK_SIGNAL (pad);
2962 while (GST_PAD_IS_BLOCKED (pad))
2963 GST_PAD_BLOCK_WAIT (pad);
2965 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
2967 callback = pad->block_callback;
2969 user_data = pad->block_data;
2971 callback (pad, FALSE, user_data);
2974 GST_PAD_BLOCK_SIGNAL (pad);
2977 gst_object_unref (pad);
2980 /**********************************************************************
2981 * Data passing functions
2985 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
2988 GValue args[2] = { {0}, {0} };
2993 g_value_init (&ret, G_TYPE_BOOLEAN);
2994 g_value_set_boolean (&ret, TRUE);
2995 g_value_init (&args[0], GST_TYPE_PAD);
2996 g_value_set_object (&args[0], pad);
2997 g_value_init (&args[1], GST_TYPE_MINI_OBJECT); // G_TYPE_POINTER);
2998 gst_value_set_mini_object (&args[1], obj);
3000 if (GST_IS_EVENT (obj))
3001 detail = event_quark;
3003 detail = buffer_quark;
3006 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
3007 res = g_value_get_boolean (&ret);
3010 g_value_unset (&ret);
3011 g_value_unset (&args[0]);
3012 g_value_unset (&args[1]);
3019 * @pad: a sink #GstPad.
3020 * @buffer: the #GstBuffer to send.
3022 * Chain a buffer to @pad.
3024 * Returns: a #GstFlowReturn from the pad.
3029 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3032 gboolean caps_changed;
3033 GstPadChainFunction chainfunc;
3035 gboolean emit_signal;
3037 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3038 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3040 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3041 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3043 GST_STREAM_LOCK (pad);
3046 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3049 caps = GST_BUFFER_CAPS (buffer);
3050 caps_changed = caps && caps != GST_PAD_CAPS (pad);
3052 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3055 /* see if the signal should be emited, we emit before caps nego as
3056 * we might drop the buffer and do capsnego for nothing. */
3057 if (G_UNLIKELY (emit_signal)) {
3058 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3062 /* we got a new datatype on the pad, see if it can handle it */
3063 if (G_UNLIKELY (caps_changed)) {
3064 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
3065 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
3066 goto not_negotiated;
3069 /* NOTE: we read the chainfunc unlocked.
3070 * we cannot hold the lock for the pad so we might send
3071 * the data to the wrong function. This is not really a
3072 * problem since functions are assigned at creation time
3073 * and don't change that often... */
3074 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3077 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3078 "calling chainfunction &%s of pad %s:%s",
3079 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
3081 ret = chainfunc (pad, buffer);
3083 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3084 "called chainfunction &%s of pad %s:%s, returned %s",
3085 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad),
3086 gst_flow_get_name (ret));
3088 GST_STREAM_UNLOCK (pad);
3095 gst_buffer_unref (buffer);
3096 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3097 "pushing, but pad was flushing");
3099 GST_STREAM_UNLOCK (pad);
3100 return GST_FLOW_WRONG_STATE;
3104 gst_buffer_unref (buffer);
3105 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
3106 GST_STREAM_UNLOCK (pad);
3111 gst_buffer_unref (buffer);
3112 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3113 "pushing buffer but pad did not accept");
3114 GST_STREAM_UNLOCK (pad);
3115 return GST_FLOW_NOT_NEGOTIATED;
3119 gst_buffer_unref (buffer);
3120 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3121 "pushing, but not chainhandler");
3122 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3123 ("push on pad %s:%s but it has no chainfunction",
3124 GST_DEBUG_PAD_NAME (pad)));
3125 GST_STREAM_UNLOCK (pad);
3126 return GST_FLOW_ERROR;
3132 * @pad: a source #GstPad.
3133 * @buffer: the #GstBuffer to push.
3135 * Pushes a buffer to the peer of @pad.
3136 * buffer probes will be triggered before the buffer gets pushed.
3138 * Returns: a #GstFlowReturn from the peer pad.
3143 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3148 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3149 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3150 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3151 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3155 /* FIXME: this check can go away; pad_set_blocked could be implemented with
3156 * probes completely */
3157 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3158 handle_pad_block (pad);
3160 /* we emit signals on the pad arg, the peer will have a chance to
3161 * emit in the _chain() function */
3162 if (G_UNLIKELY (GST_PAD_DO_BUFFER_SIGNALS (pad) > 0)) {
3163 /* unlock before emitting */
3166 /* if the signal handler returned FALSE, it means we should just drop the
3168 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3174 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3176 gst_object_ref (peer);
3179 ret = gst_pad_chain (peer, buffer);
3181 gst_object_unref (peer);
3185 /* ERROR recovery here */
3188 gst_buffer_unref (buffer);
3189 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
3194 gst_buffer_unref (buffer);
3195 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3196 "pushing, but it was not linked");
3198 return GST_FLOW_NOT_LINKED;
3203 * gst_pad_check_pull_range:
3204 * @pad: a sink #GstPad.
3206 * Checks if a #gst_pad_pull_range() can be performed on the peer
3207 * source pad. This function is used by plugins that want to check
3208 * if they can use random access on the peer source pad.
3210 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
3211 * if it needs to perform some logic to determine if pull_range is
3214 * Returns: a gboolean with the result.
3219 gst_pad_check_pull_range (GstPad * pad)
3223 GstPadCheckGetRangeFunction checkgetrangefunc;
3225 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3228 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
3229 goto wrong_direction;
3231 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3234 gst_object_ref (peer);
3237 /* see note in above function */
3238 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
3239 /* FIXME, kindoff ghetto */
3240 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
3242 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3243 "calling checkgetrangefunc %s of peer pad %s:%s",
3244 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
3246 ret = checkgetrangefunc (peer);
3249 gst_object_unref (peer);
3253 /* ERROR recovery here */
3261 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3262 "checking pull range, but it was not linked");
3269 * gst_pad_get_range:
3270 * @pad: a src #GstPad.
3271 * @offset: The start offset of the buffer
3272 * @size: The length of the buffer
3273 * @buffer: a pointer to hold the #GstBuffer.
3275 * Calls the getrange function of @pad.
3277 * Returns: a #GstFlowReturn from the pad.
3282 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3283 GstBuffer ** buffer)
3286 GstPadGetRangeFunction getrangefunc;
3287 gboolean emit_signal;
3289 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3290 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3291 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3293 GST_STREAM_LOCK (pad);
3296 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3299 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3302 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3305 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3306 "calling getrangefunc %s of peer pad %s:%s, offset %"
3307 G_GUINT64_FORMAT ", size %u",
3308 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
3311 ret = getrangefunc (pad, offset, size, buffer);
3313 /* can only fire the signal if we have a valid buffer */
3314 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3315 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3319 GST_STREAM_UNLOCK (pad);
3326 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3327 "pulling range, but pad was flushing");
3329 GST_STREAM_UNLOCK (pad);
3330 return GST_FLOW_WRONG_STATE;
3334 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3335 ("pullrange on pad %s:%s but it has no getrangefunction",
3336 GST_DEBUG_PAD_NAME (pad)));
3337 GST_STREAM_UNLOCK (pad);
3338 return GST_FLOW_ERROR;
3342 GST_DEBUG ("Dropping data after FALSE probe return");
3343 GST_STREAM_UNLOCK (pad);
3344 gst_buffer_unref (*buffer);
3346 return GST_FLOW_UNEXPECTED;
3352 * gst_pad_pull_range:
3353 * @pad: a sink #GstPad.
3354 * @offset: The start offset of the buffer
3355 * @size: The length of the buffer
3356 * @buffer: a pointer to hold the #GstBuffer.
3358 * Pulls a buffer from the peer pad. @pad must be a linked
3361 * Returns: a #GstFlowReturn from the peer pad.
3366 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3367 GstBuffer ** buffer)
3371 gboolean emit_signal;
3373 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3374 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3376 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3380 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3381 handle_pad_block (pad);
3383 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3386 /* signal emision for the pad, peer has chance to emit when
3387 * we call _get_range() */
3388 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3390 gst_object_ref (peer);
3393 ret = gst_pad_get_range (peer, offset, size, buffer);
3395 gst_object_unref (peer);
3397 /* can only fire the signal if we have a valid buffer */
3398 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3399 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3404 /* ERROR recovery here */
3407 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3408 "pulling range, but it was not linked");
3410 return GST_FLOW_NOT_LINKED;
3414 GST_DEBUG ("Dropping data after FALSE probe return");
3415 gst_buffer_unref (*buffer);
3417 return GST_FLOW_UNEXPECTED;
3422 * gst_pad_push_event:
3423 * @pad: a #GstPad to push the event to.
3424 * @event: the #GstEvent to send to the pad.
3426 * Sends the event to the peer of the given pad. This function is
3427 * mainly used by elements to send events to their peer
3430 * Returns: TRUE if the event was handled.
3435 gst_pad_push_event (GstPad * pad, GstEvent * event)
3440 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3441 g_return_val_if_fail (event != NULL, FALSE);
3442 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
3445 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
3448 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3453 peerpad = GST_PAD_PEER (pad);
3454 if (peerpad == NULL)
3457 gst_object_ref (peerpad);
3460 result = gst_pad_send_event (peerpad, event);
3462 gst_object_unref (peerpad);
3466 /* ERROR handling */
3469 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
3470 gst_event_unref (event);
3475 gst_event_unref (event);
3482 * gst_pad_send_event:
3483 * @pad: a #GstPad to send the event to.
3484 * @event: the #GstEvent to send to the pad.
3486 * Sends the event to the pad. This function can be used
3487 * by applications to send events in the pipeline.
3489 * Returns: TRUE if the event was handled.
3492 gst_pad_send_event (GstPad * pad, GstEvent * event)
3494 gboolean result = FALSE;
3495 GstPadEventFunction eventfunc;
3496 gboolean emit_signal;
3498 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3499 g_return_val_if_fail (event != NULL, FALSE);
3502 if (GST_PAD_IS_SINK (pad) && !GST_EVENT_IS_DOWNSTREAM (event))
3503 goto wrong_direction;
3504 if (GST_PAD_IS_SRC (pad) && !GST_EVENT_IS_UPSTREAM (event))
3505 goto wrong_direction;
3507 if (GST_EVENT_SRC (event) == NULL)
3508 GST_EVENT_SRC (event) = gst_object_ref (pad);
3510 switch (GST_EVENT_TYPE (event)) {
3511 case GST_EVENT_FLUSH_START:
3512 GST_CAT_DEBUG (GST_CAT_EVENT,
3513 "have event type %d (FLUSH_START) on pad %s:%s",
3514 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3516 /* can't even accept a flush begin event when flushing */
3517 if (GST_PAD_IS_FLUSHING (pad))
3519 GST_PAD_SET_FLUSHING (pad);
3520 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3522 case GST_EVENT_FLUSH_STOP:
3523 GST_PAD_UNSET_FLUSHING (pad);
3524 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3527 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %s on pad %s:%s",
3528 gst_event_type_get_name (GST_EVENT_TYPE (event)),
3529 GST_DEBUG_PAD_NAME (pad));
3531 if (GST_PAD_IS_FLUSHING (pad))
3536 if ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL)
3539 emit_signal = GST_PAD_DO_EVENT_SIGNALS (pad) > 0;
3542 if (G_UNLIKELY (emit_signal)) {
3543 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3547 result = eventfunc (GST_PAD_CAST (pad), event);
3551 /* ERROR handling */
3554 g_warning ("pad %s:%s sending event in wrong direction",
3555 GST_DEBUG_PAD_NAME (pad));
3557 gst_event_unref (event);
3562 g_warning ("pad %s:%s has no event handler, file a bug.",
3563 GST_DEBUG_PAD_NAME (pad));
3565 gst_event_unref (event);
3571 GST_CAT_DEBUG (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3572 gst_event_unref (event);
3577 GST_DEBUG ("Dropping event after FALSE probe return");
3578 gst_event_unref (event);
3584 * gst_pad_set_element_private:
3585 * @pad: the #GstPad to set the private data of.
3586 * @priv: The private data to attach to the pad.
3588 * Set the given private data gpointer on the pad.
3589 * This function can only be used by the element that owns the pad.
3592 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3594 pad->element_private = priv;
3598 * gst_pad_get_element_private:
3599 * @pad: the #GstPad to get the private data of.
3601 * Gets the private data of a pad.
3603 * Returns: a #gpointer to the private data.
3606 gst_pad_get_element_private (GstPad * pad)
3608 return pad->element_private;
3612 * gst_pad_start_task:
3613 * @pad: the #GstPad to start the task of
3614 * @func: the task function to call
3615 * @data: data passed to the task function
3617 * Starts a task that repeadedly calls @func with @data. This function
3618 * is nostly used in the pad activation function to start the
3619 * dataflow. This function will automatically acauire the STREAM_LOCK of
3620 * the pad before calling @func.
3622 * Returns: a TRUE if the task could be started.
3625 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3629 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3630 g_return_val_if_fail (func != NULL, FALSE);
3633 task = GST_PAD_TASK (pad);
3635 task = gst_task_create (func, data);
3636 gst_task_set_lock (task, GST_STREAM_GET_LOCK (pad));
3637 GST_PAD_TASK (pad) = task;
3639 gst_task_start (task);
3646 * gst_pad_pause_task:
3647 * @pad: the #GstPad to pause the task of
3649 * Pause the task of @pad. This function will also make sure that the
3650 * function executed by the task will effectively stop.
3652 * Returns: a TRUE if the task could be paused or FALSE when the pad
3656 gst_pad_pause_task (GstPad * pad)
3660 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3663 task = GST_PAD_TASK (pad);
3666 gst_task_pause (task);
3669 GST_STREAM_LOCK (pad);
3670 GST_STREAM_UNLOCK (pad);
3676 GST_WARNING_OBJECT (pad,
3677 "pad has no task -- very likely a programming error");
3684 * gst_pad_stop_task:
3685 * @pad: the #GstPad to stop the task of
3687 * Stop the task of @pad. This function will also make sure that the
3688 * function executed by the task will effectively stop if not called
3689 * from the GstTaskFunction.
3691 * This function will deadlock if called from the GstTaskFunction of
3692 * the task. Use #gst_task_pause() instead.
3694 * Regardless of whether the pad has a task, the stream lock is acquired and
3695 * released so as to ensure that streaming through this pad has finished.
3697 * Returns: a TRUE if the task could be stopped or FALSE on error.
3700 gst_pad_stop_task (GstPad * pad)
3704 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3707 task = GST_PAD_TASK (pad);
3710 GST_PAD_TASK (pad) = NULL;
3711 gst_task_stop (task);
3714 GST_STREAM_LOCK (pad);
3715 GST_STREAM_UNLOCK (pad);
3717 gst_task_join (task);
3719 gst_object_unref (task);
3727 GST_STREAM_LOCK (pad);
3728 GST_STREAM_UNLOCK (pad);