2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
30 * After two pads are retrieved from an element with gst_element_get_pad(),
31 * the pads can be link with gst_pad_link(). (For quick links,
32 * you can also use gst_element_link(), which will make the obvious
33 * link for you if it's straightforward.)
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template().
38 * Pads have #GstCaps attached to it to describe the media type they are
39 * capable of dealing with. gst_pad_get_caps() and gst_pad_set_caps() are
40 * used to manipulate the caps of the pads.
41 * Pads created from a pad template cannot set capabilities that are
42 * incompatible with the pad template capabilities.
44 * Pads without pad templates can be created with gst_pad_new(),
45 * which takes a direction and a name as an argument. If the name is NULL,
46 * then a guaranteed unique name will be assigned to it.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * A #GstElement creating a pad will typically use the various
51 * gst_pad_set_*_function() calls to register callbacks for various events
54 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
55 * or pull in a buffer.
57 * To send a #GstEvent on a pad, use gst_pad_send_event().
59 * Last reviewed on 2005-11-23 (0.9.5)
63 #include "gst_private.h"
66 #include "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 static void gst_pad_class_init (GstPadClass * klass);
99 static void gst_pad_init (GstPad * pad);
100 static void gst_pad_dispose (GObject * object);
101 static void gst_pad_finalize (GObject * object);
102 static void gst_pad_set_property (GObject * object, guint prop_id,
103 const GValue * value, GParamSpec * pspec);
104 static void gst_pad_get_property (GObject * object, guint prop_id,
105 GValue * value, GParamSpec * pspec);
107 static GstFlowReturn handle_pad_block (GstPad * pad);
108 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
109 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
110 static gboolean gst_pad_activate_default (GstPad * pad);
112 #ifndef GST_DISABLE_LOADSAVE
113 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
116 static GstObjectClass *parent_class = NULL;
117 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
119 /* quarks for probe signals */
120 static GQuark buffer_quark;
121 static GQuark event_quark;
130 static GstFlowQuarks flow_quarks[] = {
131 {GST_FLOW_RESEND, "resend", 0},
132 {GST_FLOW_OK, "ok", 0},
133 {GST_FLOW_NOT_LINKED, "not-linked", 0},
134 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
135 {GST_FLOW_UNEXPECTED, "unexpected", 0},
136 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
137 {GST_FLOW_ERROR, "error", 0},
138 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
145 * @ret: a #GstFlowReturn to get the name of.
147 * Gets a string representing the given flow return.
149 * Returns: a string with the name of the flow return.
151 G_CONST_RETURN gchar *
152 gst_flow_get_name (GstFlowReturn ret)
156 for (i = 0; flow_quarks[i].name; i++) {
157 if (ret == flow_quarks[i].ret)
158 return flow_quarks[i].name;
165 * @ret: a #GstFlowReturn to get the quark of.
167 * Get the unique quark for the given GstFlowReturn.
169 * Returns: the quark associated with the flow return or 0 if an
170 * invalid return was specified.
173 gst_flow_to_quark (GstFlowReturn ret)
177 for (i = 0; flow_quarks[i].name; i++) {
178 if (ret == flow_quarks[i].ret)
179 return flow_quarks[i].quark;
185 gst_pad_get_type (void)
187 static GType gst_pad_type = 0;
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");
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_DEBUG_FUNCPTR (gst_pad_activate_default);
338 pad->eventfunc = GST_DEBUG_FUNCPTR (gst_pad_event_default);
339 pad->querytypefunc = GST_DEBUG_FUNCPTR (gst_pad_get_query_types_default);
340 pad->queryfunc = GST_DEBUG_FUNCPTR (gst_pad_query_default);
341 pad->intlinkfunc = GST_DEBUG_FUNCPTR (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_gst_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_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_new_from_static_template:
495 * @templ: the #GstStaticPadTemplate to use
496 * @name: the name of the element
498 * Creates a new pad with the given name from the given static template.
499 * If name is NULL, a guaranteed unique name (across all pads)
501 * This function makes a copy of the name so you can safely free the name.
503 * Returns: a new #GstPad, or NULL in case of an error.
506 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
510 GstPadTemplate *template;
512 template = gst_static_pad_template_get (templ);
513 pad = gst_pad_new_from_template (template, name);
514 gst_object_unref (template);
519 * gst_pad_get_direction:
520 * @pad: a #GstPad to get the direction of.
522 * Gets the direction of the pad. The direction of the pad is
523 * decided at construction time so this function does not take
526 * Returns: the #GstPadDirection of the pad.
531 gst_pad_get_direction (GstPad * pad)
533 GstPadDirection result;
535 /* PAD_UNKNOWN is a little silly but we need some sort of
536 * error return value */
537 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
539 GST_OBJECT_LOCK (pad);
540 result = GST_PAD_DIRECTION (pad);
541 GST_OBJECT_UNLOCK (pad);
547 gst_pad_activate_default (GstPad * pad)
549 return gst_pad_activate_push (pad, TRUE);
553 pre_activate (GstPad * pad, GstActivateMode new_mode)
556 case GST_ACTIVATE_PUSH:
557 case GST_ACTIVATE_PULL:
558 GST_OBJECT_LOCK (pad);
559 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
561 GST_PAD_UNSET_FLUSHING (pad);
562 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
563 GST_OBJECT_UNLOCK (pad);
565 case GST_ACTIVATE_NONE:
566 GST_OBJECT_LOCK (pad);
567 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing",
569 GST_PAD_SET_FLUSHING (pad);
570 /* unlock blocked pads so element can resume and stop */
571 GST_PAD_BLOCK_SIGNAL (pad);
572 GST_OBJECT_UNLOCK (pad);
578 post_activate (GstPad * pad, GstActivateMode new_mode)
581 case GST_ACTIVATE_PUSH:
582 case GST_ACTIVATE_PULL:
585 case GST_ACTIVATE_NONE:
586 /* ensures that streaming stops */
587 GST_PAD_STREAM_LOCK (pad);
588 /* while we're at it set activation mode */
589 GST_OBJECT_LOCK (pad);
590 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d", new_mode);
591 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
592 GST_OBJECT_UNLOCK (pad);
593 GST_PAD_STREAM_UNLOCK (pad);
599 * gst_pad_set_active:
600 * @pad: the #GstPad to activate or deactivate.
601 * @active: whether or not the pad should be active.
603 * Activates or deactivates the given pad.
604 * Normally called from within core state change functions.
606 * If @active, makes sure the pad is active. If it is already active, either in
607 * push or pull mode, just return. Otherwise dispatches to the pad's activate
608 * function to perform the actual activation.
610 * If not @active, checks the pad's current mode and calls
611 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
614 * Returns: #TRUE if the operation was successful.
619 gst_pad_set_active (GstPad * pad, gboolean active)
622 gboolean ret = FALSE;
624 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
626 GST_OBJECT_LOCK (pad);
627 old = GST_PAD_ACTIVATE_MODE (pad);
628 GST_OBJECT_UNLOCK (pad);
632 case GST_ACTIVATE_PUSH:
633 case GST_ACTIVATE_PULL:
636 case GST_ACTIVATE_NONE:
637 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
642 case GST_ACTIVATE_PUSH:
643 ret = gst_pad_activate_push (pad, FALSE);
645 case GST_ACTIVATE_PULL:
646 ret = gst_pad_activate_pull (pad, FALSE);
648 case GST_ACTIVATE_NONE:
654 if (!active && !ret) {
655 GST_OBJECT_LOCK (pad);
656 g_critical ("Failed to deactivate pad %s:%s, very bad",
657 GST_DEBUG_PAD_NAME (pad));
658 GST_OBJECT_UNLOCK (pad);
665 * gst_pad_activate_pull:
666 * @pad: the #GstPad to activate or deactivate.
667 * @active: whether or not the pad should be active.
669 * Activates or deactivates the given pad in pull mode via dispatching to the
670 * pad's activatepullfunc. For use from within pad activation functions only.
671 * When called on sink pads, will first proxy the call to the peer pad, which is
672 * expected to activate its internally linked pads from within its activate_pull
675 * If you don't know what this is, you probably don't want to call it.
677 * Returns: TRUE if the operation was successful.
682 gst_pad_activate_pull (GstPad * pad, gboolean active)
684 GstActivateMode old, new;
687 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
689 GST_OBJECT_LOCK (pad);
690 old = GST_PAD_ACTIVATE_MODE (pad);
691 GST_OBJECT_UNLOCK (pad);
693 if ((active && old == GST_ACTIVATE_PULL)
694 || (!active && old == GST_ACTIVATE_NONE))
698 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
700 g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE);
703 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
704 if ((peer = gst_pad_get_peer (pad))) {
705 if (!gst_pad_activate_pull (peer, active))
707 gst_object_unref (peer);
710 if (GST_PAD_GETRANGEFUNC (pad) == NULL)
711 goto failure; /* Can't activate pull on a src without a
715 new = active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
716 pre_activate (pad, new);
718 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
719 if (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active))
722 /* can happen for sinks of passthrough elements */
725 post_activate (pad, new);
727 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
728 active ? "activated" : "deactivated");
733 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
734 active ? "activated" : "deactivated");
739 GST_OBJECT_LOCK (peer);
740 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
741 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
742 GST_OBJECT_UNLOCK (peer);
743 gst_object_unref (peer);
748 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
749 active ? "activate" : "deactivate");
750 pre_activate (pad, GST_ACTIVATE_NONE);
751 post_activate (pad, GST_ACTIVATE_NONE);
757 * gst_pad_activate_push:
758 * @pad: the #GstPad to activate or deactivate.
759 * @active: whether or not the pad should be active.
761 * Activates or deactivates the given pad in push mode via dispatching to the
762 * pad's activatepushfunc. For use from within pad activation functions only.
764 * If you don't know what this is, you probably don't want to call it.
766 * Returns: TRUE if the operation was successfull.
771 gst_pad_activate_push (GstPad * pad, gboolean active)
773 GstActivateMode old, new;
775 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
776 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
777 active ? "activated" : "deactivated");
779 GST_OBJECT_LOCK (pad);
780 old = GST_PAD_ACTIVATE_MODE (pad);
781 GST_OBJECT_UNLOCK (pad);
783 if ((active && old == GST_ACTIVATE_PUSH)
784 || (!active && old == GST_ACTIVATE_NONE))
788 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
790 g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE);
793 new = active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
794 pre_activate (pad, new);
796 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
797 if (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) {
801 /* quite ok, element relies on state change func to prepare itself */
804 post_activate (pad, new);
806 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
807 active ? "activated" : "deactivated");
812 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
813 active ? "activated" : "deactivated");
818 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
819 active ? "activate" : "deactivate");
820 pre_activate (pad, GST_ACTIVATE_NONE);
821 post_activate (pad, GST_ACTIVATE_NONE);
828 * @pad: the #GstPad to query
830 * Query if a pad is active
832 * Returns: TRUE if the pad is active.
837 gst_pad_is_active (GstPad * pad)
839 gboolean result = FALSE;
841 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
843 GST_OBJECT_LOCK (pad);
844 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
845 GST_OBJECT_UNLOCK (pad);
851 * gst_pad_set_blocked_async:
852 * @pad: the #GstPad to block or unblock
853 * @blocked: boolean indicating whether the pad should be blocked or unblocked
854 * @callback: #GstPadBlockCallback that will be called when the
856 * @user_data: user data passed to the callback
858 * Blocks or unblocks the dataflow on a pad. The provided callback
859 * is called when the operation succeeds; this happens right before the next
860 * attempt at pushing a buffer on the pad.
862 * This can take a while as the pad can only become blocked when real dataflow
864 * When the pipeline is stalled, for example in PAUSED, this can
865 * take an indeterminate amount of time.
866 * You can pass NULL as the callback to make this call block. Be careful with
867 * this blocking call as it might not return for reasons stated above.
869 * Returns: TRUE if the pad could be blocked. This function can fail
870 * if wrong parameters were passed or the pad was already in the
876 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
877 GstPadBlockCallback callback, gpointer user_data)
879 gboolean was_blocked;
881 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
883 GST_OBJECT_LOCK (pad);
885 was_blocked = GST_PAD_IS_BLOCKED (pad);
887 if (G_UNLIKELY (was_blocked == blocked))
888 goto had_right_state;
891 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad %s:%s",
892 GST_DEBUG_PAD_NAME (pad));
894 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
895 pad->block_callback = callback;
896 pad->block_data = user_data;
898 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
899 GST_PAD_BLOCK_WAIT (pad);
900 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
903 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad %s:%s",
904 GST_DEBUG_PAD_NAME (pad));
906 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
908 pad->block_callback = callback;
909 pad->block_data = user_data;
912 GST_PAD_BLOCK_SIGNAL (pad);
914 GST_PAD_BLOCK_SIGNAL (pad);
915 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
916 GST_PAD_BLOCK_WAIT (pad);
917 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
920 GST_OBJECT_UNLOCK (pad);
926 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
927 "pad %s:%s was in right state", GST_DEBUG_PAD_NAME (pad));
928 GST_OBJECT_UNLOCK (pad);
934 * gst_pad_set_blocked:
935 * @pad: the #GstPad to block or unblock
936 * @blocked: boolean indicating we should block or unblock
938 * Blocks or unblocks the dataflow on a pad. This function is
939 * a shortcut for gst_pad_set_blocked_async() with a NULL
942 * Returns: TRUE if the pad could be blocked. This function can fail
943 * wrong parameters were passed or the pad was already in the
949 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
951 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
955 * gst_pad_is_blocked:
956 * @pad: the #GstPad to query
958 * Checks if the pad is blocked or not. This function returns the
959 * last requested state of the pad. It is not certain that the pad
960 * is actually blocked at this point.
962 * Returns: TRUE if the pad is blocked.
967 gst_pad_is_blocked (GstPad * pad)
969 gboolean result = FALSE;
971 g_return_val_if_fail (GST_IS_PAD (pad), result);
973 GST_OBJECT_LOCK (pad);
974 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
975 GST_OBJECT_UNLOCK (pad);
981 * gst_pad_set_activate_function:
982 * @pad: a sink #GstPad.
983 * @activate: the #GstPadActivateFunction to set.
985 * Sets the given activate function for the pad. The activate function will
986 * dispatch to activate_push or activate_pull to perform the actual activation.
987 * Only makes sense to set on sink pads.
989 * Call this function if your sink pad can start a pull-based task.
992 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
994 g_return_if_fail (GST_IS_PAD (pad));
996 GST_PAD_ACTIVATEFUNC (pad) = activate;
997 GST_CAT_DEBUG (GST_CAT_PADS, "activatefunc for %s:%s set to %s",
998 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activate));
1002 * gst_pad_set_activatepull_function:
1003 * @pad: a sink #GstPad.
1004 * @activatepull: the #GstPadActivateModeFunction to set.
1006 * Sets the given activate_pull function for the pad. An activate_pull function
1007 * prepares the element and any upstream connections for pulling. See XXX
1008 * part-activation.txt for details.
1011 gst_pad_set_activatepull_function (GstPad * pad,
1012 GstPadActivateModeFunction activatepull)
1014 g_return_if_fail (GST_IS_PAD (pad));
1016 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1017 GST_CAT_DEBUG (GST_CAT_PADS, "activatepullfunc for %s:%s set to %s",
1018 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepull));
1022 * gst_pad_set_activatepush_function:
1023 * @pad: a sink #GstPad.
1024 * @activatepush: the #GstPadActivateModeFunction to set.
1026 * Sets the given activate_push function for the pad. An activate_push function
1027 * prepares the element for pushing. See XXX part-activation.txt for details.
1030 gst_pad_set_activatepush_function (GstPad * pad,
1031 GstPadActivateModeFunction activatepush)
1033 g_return_if_fail (GST_IS_PAD (pad));
1035 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1036 GST_CAT_DEBUG (GST_CAT_PADS, "activatepushfunc for %s:%s set to %s",
1037 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepush));
1041 * gst_pad_set_chain_function:
1042 * @pad: a sink #GstPad.
1043 * @chain: the #GstPadChainFunction to set.
1045 * Sets the given chain function for the pad. The chain function is called to
1046 * process a #GstBuffer input buffer.
1049 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1051 g_return_if_fail (GST_IS_PAD (pad));
1052 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
1054 GST_PAD_CHAINFUNC (pad) = chain;
1055 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
1056 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
1060 * gst_pad_set_getrange_function:
1061 * @pad: a source #GstPad.
1062 * @get: the #GstPadGetRangeFunction to set.
1064 * Sets the given getrange function for the pad. The getrange function is called to
1065 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
1069 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1071 g_return_if_fail (GST_IS_PAD (pad));
1072 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1074 GST_PAD_GETRANGEFUNC (pad) = get;
1076 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
1077 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
1081 * gst_pad_set_checkgetrange_function:
1082 * @pad: a source #GstPad.
1083 * @check: the #GstPadCheckGetRangeFunction to set.
1085 * Sets the given checkgetrange function for the pad. Implement this function on
1086 * a pad if you dynamically support getrange based scheduling on the pad.
1089 gst_pad_set_checkgetrange_function (GstPad * pad,
1090 GstPadCheckGetRangeFunction check)
1092 g_return_if_fail (GST_IS_PAD (pad));
1093 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1095 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
1097 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
1098 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
1102 * gst_pad_set_event_function:
1103 * @pad: a source #GstPad.
1104 * @event: the #GstPadEventFunction to set.
1106 * Sets the given event handler for the pad.
1109 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1111 g_return_if_fail (GST_IS_PAD (pad));
1113 GST_PAD_EVENTFUNC (pad) = event;
1115 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
1116 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
1120 * gst_pad_set_query_function:
1121 * @pad: a #GstPad of either direction.
1122 * @query: the #GstPadQueryFunction to set.
1124 * Set the given query function for the pad.
1127 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1129 g_return_if_fail (GST_IS_PAD (pad));
1131 GST_PAD_QUERYFUNC (pad) = query;
1133 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
1134 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
1138 * gst_pad_set_query_type_function:
1139 * @pad: a #GstPad of either direction.
1140 * @type_func: the #GstPadQueryTypeFunction to set.
1142 * Set the given query type function for the pad.
1145 gst_pad_set_query_type_function (GstPad * pad,
1146 GstPadQueryTypeFunction type_func)
1148 g_return_if_fail (GST_IS_PAD (pad));
1150 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1152 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
1153 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
1157 * gst_pad_get_query_types:
1160 * Get an array of supported queries that can be performed
1163 * Returns: a zero-terminated array of #GstQueryType.
1165 const GstQueryType *
1166 gst_pad_get_query_types (GstPad * pad)
1168 GstPadQueryTypeFunction func;
1170 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1172 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1184 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1186 *data = gst_pad_get_query_types (pad);
1192 * gst_pad_get_query_types_default:
1195 * Invoke the default dispatcher for the query types on
1198 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1199 * internally-linked pads has a query types function.
1201 const GstQueryType *
1202 gst_pad_get_query_types_default (GstPad * pad)
1204 GstQueryType *result = NULL;
1206 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1208 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1209 gst_pad_get_query_types_dispatcher, &result);
1215 * gst_pad_set_internal_link_function:
1216 * @pad: a #GstPad of either direction.
1217 * @intlink: the #GstPadIntLinkFunction to set.
1219 * Sets the given internal link function for the pad.
1222 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1224 g_return_if_fail (GST_IS_PAD (pad));
1226 GST_PAD_INTLINKFUNC (pad) = intlink;
1227 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1228 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1232 * gst_pad_set_link_function:
1234 * @link: the #GstPadLinkFunction to set.
1236 * Sets the given link function for the pad. It will be called when
1237 * the pad is linked with another pad.
1239 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1242 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1243 * cannot be made for some reason.
1245 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1246 * of the peer sink pad, if present.
1249 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1251 g_return_if_fail (GST_IS_PAD (pad));
1253 GST_PAD_LINKFUNC (pad) = link;
1254 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1255 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1259 * gst_pad_set_unlink_function:
1261 * @unlink: the #GstPadUnlinkFunction to set.
1263 * Sets the given unlink function for the pad. It will be called
1264 * when the pad is unlinked.
1267 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1269 g_return_if_fail (GST_IS_PAD (pad));
1271 GST_PAD_UNLINKFUNC (pad) = unlink;
1272 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1273 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1277 * gst_pad_set_getcaps_function:
1279 * @getcaps: the #GstPadGetCapsFunction to set.
1281 * Sets the given getcaps function for the pad. @getcaps should return the
1282 * allowable caps for a pad in the context of the element's state, its link to
1283 * other elements, and the devices or files it has opened. These caps must be a
1284 * subset of the pad template caps. In the NULL state with no links, @getcaps
1285 * should ideally return the same caps as the pad template. In rare
1286 * circumstances, an object property can affect the caps returned by @getcaps,
1287 * but this is discouraged.
1289 * You do not need to call this function if @pad's allowed caps are always the
1290 * same as the pad template caps. This can only be true if the padtemplate
1291 * has fixed simple caps.
1293 * For most filters, the caps returned by @getcaps is directly affected by the
1294 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1295 * the srcpad's getcaps function is directly related to the stream data. Again,
1296 * @getcaps should return the most specific caps it reasonably can, since this
1297 * helps with autoplugging.
1299 * Note that the return value from @getcaps is owned by the caller, so the caller
1300 * should unref the caps after usage.
1303 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1305 g_return_if_fail (GST_IS_PAD (pad));
1307 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1308 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1309 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1313 * gst_pad_set_acceptcaps_function:
1315 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1317 * Sets the given acceptcaps function for the pad. The acceptcaps function
1318 * will be called to check if the pad can accept the given caps.
1321 gst_pad_set_acceptcaps_function (GstPad * pad,
1322 GstPadAcceptCapsFunction acceptcaps)
1324 g_return_if_fail (GST_IS_PAD (pad));
1326 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1327 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1328 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1332 * gst_pad_set_fixatecaps_function:
1334 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1336 * Sets the given fixatecaps function for the pad. The fixatecaps function
1337 * will be called whenever the default values for a GstCaps needs to be
1341 gst_pad_set_fixatecaps_function (GstPad * pad,
1342 GstPadFixateCapsFunction fixatecaps)
1344 g_return_if_fail (GST_IS_PAD (pad));
1346 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1347 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1348 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1352 * gst_pad_set_setcaps_function:
1354 * @setcaps: the #GstPadSetCapsFunction to set.
1356 * Sets the given setcaps function for the pad. The setcaps function
1357 * will be called whenever a buffer with a new media type is pushed or
1358 * pulled from the pad. The pad/element needs to update it's internal
1359 * structures to process the new media type. If this new type is not
1360 * acceptable, the setcaps function should return FALSE.
1363 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1365 g_return_if_fail (GST_IS_PAD (pad));
1367 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1368 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1369 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1373 * gst_pad_set_bufferalloc_function:
1374 * @pad: a sink #GstPad.
1375 * @bufalloc: the #GstPadBufferAllocFunction to set.
1377 * Sets the given bufferalloc function for the pad. Note that the
1378 * bufferalloc function can only be set on sinkpads.
1381 gst_pad_set_bufferalloc_function (GstPad * pad,
1382 GstPadBufferAllocFunction bufalloc)
1384 g_return_if_fail (GST_IS_PAD (pad));
1385 g_return_if_fail (GST_PAD_IS_SINK (pad));
1387 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1388 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1389 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1394 * @srcpad: the source #GstPad to unlink.
1395 * @sinkpad: the sink #GstPad to unlink.
1397 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1400 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1401 * the pads were not linked together.
1406 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1408 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1409 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1411 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1412 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1413 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1415 GST_OBJECT_LOCK (srcpad);
1417 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1420 GST_OBJECT_LOCK (sinkpad);
1422 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1425 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1426 goto not_linked_together;
1428 if (GST_PAD_UNLINKFUNC (srcpad)) {
1429 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1431 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1432 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1435 /* first clear peers */
1436 GST_PAD_PEER (srcpad) = NULL;
1437 GST_PAD_PEER (sinkpad) = NULL;
1439 GST_OBJECT_UNLOCK (sinkpad);
1440 GST_OBJECT_UNLOCK (srcpad);
1442 /* fire off a signal to each of the pads telling them
1443 * that they've been unlinked */
1444 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1445 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1447 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1448 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1454 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1455 GST_OBJECT_UNLOCK (srcpad);
1460 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1461 GST_OBJECT_UNLOCK (sinkpad);
1462 GST_OBJECT_UNLOCK (srcpad);
1465 not_linked_together:
1467 /* we do not emit a warning in this case because unlinking cannot
1468 * be made MT safe.*/
1469 GST_OBJECT_UNLOCK (sinkpad);
1470 GST_OBJECT_UNLOCK (srcpad);
1476 * gst_pad_is_linked:
1477 * @pad: pad to check
1479 * Checks if a @pad is linked to another pad or not.
1481 * Returns: TRUE if the pad is linked, FALSE otherwise.
1486 gst_pad_is_linked (GstPad * pad)
1490 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1492 GST_OBJECT_LOCK (pad);
1493 result = (GST_PAD_PEER (pad) != NULL);
1494 GST_OBJECT_UNLOCK (pad);
1499 /* get the caps from both pads and see if the intersection
1502 * This function should be called with the pad LOCK on both
1506 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1511 srccaps = gst_pad_get_caps_unlocked (src);
1512 sinkcaps = gst_pad_get_caps_unlocked (sink);
1514 GST_CAT_DEBUG (GST_CAT_CAPS, "src caps %" GST_PTR_FORMAT, srccaps);
1515 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1517 /* if we have caps on both pads we can check the intersection. If one
1518 * of the caps is NULL, we return TRUE. */
1519 if (srccaps && sinkcaps) {
1522 icaps = gst_caps_intersect (srccaps, sinkcaps);
1523 gst_caps_unref (srccaps);
1524 gst_caps_unref (sinkcaps);
1529 GST_CAT_DEBUG (GST_CAT_CAPS,
1530 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1532 if (gst_caps_is_empty (icaps))
1535 gst_caps_unref (icaps);
1539 /* incompatible cases */
1542 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection gave NULL");
1547 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is EMPTY");
1548 gst_caps_unref (icaps);
1553 /* check if the grandparents of both pads are the same.
1554 * This check is required so that we don't try to link
1555 * pads from elements in different bins without ghostpads.
1557 * The LOCK should be helt on both pads
1560 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1562 GstObject *psrc, *psink;
1563 gboolean res = TRUE;
1565 psrc = GST_OBJECT_PARENT (src);
1566 psink = GST_OBJECT_PARENT (sink);
1568 /* if one of the pads has no parent, we allow the link */
1569 if (psrc && psink) {
1570 /* if the parents are the same, we have a loop */
1571 if (psrc == psink) {
1572 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1577 /* if they both have a parent, we check the grandparents */
1578 psrc = gst_object_get_parent (psrc);
1579 psink = gst_object_get_parent (psink);
1581 if (psrc != psink) {
1582 /* if they have grandparents but they are not the same */
1583 GST_CAT_DEBUG (GST_CAT_CAPS,
1584 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1585 GST_PTR_FORMAT, psrc, psink);
1589 gst_object_unref (psrc);
1591 gst_object_unref (psink);
1597 /* FIXME leftover from an attempt at refactoring... */
1598 /* call with the two pads unlocked */
1599 static GstPadLinkReturn
1600 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1602 /* generic checks */
1603 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1604 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1606 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1607 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1609 GST_OBJECT_LOCK (srcpad);
1611 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1614 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1615 goto src_was_linked;
1617 GST_OBJECT_LOCK (sinkpad);
1619 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1622 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1623 goto sink_was_linked;
1625 /* check hierarchy, pads can only be linked if the grandparents
1627 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1628 goto wrong_hierarchy;
1630 /* check pad caps for non-empty intersection */
1631 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1634 /* FIXME check pad scheduling for non-empty intersection */
1636 return GST_PAD_LINK_OK;
1640 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1641 GST_OBJECT_UNLOCK (srcpad);
1642 return GST_PAD_LINK_WRONG_DIRECTION;
1646 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked",
1647 GST_DEBUG_PAD_NAME (srcpad));
1648 /* we do not emit a warning in this case because unlinking cannot
1649 * be made MT safe.*/
1650 GST_OBJECT_UNLOCK (srcpad);
1651 return GST_PAD_LINK_WAS_LINKED;
1655 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1656 GST_OBJECT_UNLOCK (sinkpad);
1657 GST_OBJECT_UNLOCK (srcpad);
1658 return GST_PAD_LINK_WRONG_DIRECTION;
1662 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked",
1663 GST_DEBUG_PAD_NAME (sinkpad));
1664 /* we do not emit a warning in this case because unlinking cannot
1665 * be made MT safe.*/
1666 GST_OBJECT_UNLOCK (sinkpad);
1667 GST_OBJECT_UNLOCK (srcpad);
1668 return GST_PAD_LINK_WAS_LINKED;
1672 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1673 GST_OBJECT_UNLOCK (sinkpad);
1674 GST_OBJECT_UNLOCK (srcpad);
1675 return GST_PAD_LINK_WRONG_HIERARCHY;
1679 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1680 GST_OBJECT_UNLOCK (sinkpad);
1681 GST_OBJECT_UNLOCK (srcpad);
1682 return GST_PAD_LINK_NOFORMAT;
1688 * @srcpad: the source #GstPad to link.
1689 * @sinkpad: the sink #GstPad to link.
1691 * Links the source pad and the sink pad.
1693 * Returns: A result code indicating if the connection worked or
1699 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1701 GstPadLinkReturn result;
1703 /* prepare will also lock the two pads */
1704 result = gst_pad_link_prepare (srcpad, sinkpad);
1706 if (result != GST_PAD_LINK_OK)
1707 goto prepare_failed;
1709 GST_OBJECT_UNLOCK (sinkpad);
1710 GST_OBJECT_UNLOCK (srcpad);
1712 /* FIXME released the locks here, concurrent thread might link
1713 * something else. */
1714 if (GST_PAD_LINKFUNC (srcpad)) {
1715 /* this one will call the peer link function */
1716 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1717 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1718 /* if no source link function, we need to call the sink link
1719 * function ourselves. */
1720 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1722 result = GST_PAD_LINK_OK;
1725 GST_OBJECT_LOCK (srcpad);
1726 GST_OBJECT_LOCK (sinkpad);
1728 if (result == GST_PAD_LINK_OK) {
1729 GST_PAD_PEER (srcpad) = sinkpad;
1730 GST_PAD_PEER (sinkpad) = srcpad;
1732 GST_OBJECT_UNLOCK (sinkpad);
1733 GST_OBJECT_UNLOCK (srcpad);
1735 /* fire off a signal to each of the pads telling them
1736 * that they've been linked */
1737 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1738 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1740 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1741 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1743 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1744 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1746 GST_OBJECT_UNLOCK (sinkpad);
1747 GST_OBJECT_UNLOCK (srcpad);
1758 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1760 /* this function would need checks if it weren't static */
1762 GST_OBJECT_LOCK (pad);
1763 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1764 GST_OBJECT_UNLOCK (pad);
1767 gst_pad_template_pad_created (templ, pad);
1771 * gst_pad_get_pad_template:
1774 * Gets the template for @pad.
1776 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1777 * if this pad has no template.
1779 * FIXME: currently returns an unrefcounted padtemplate.
1782 gst_pad_get_pad_template (GstPad * pad)
1784 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1786 return GST_PAD_PAD_TEMPLATE (pad);
1790 /* should be called with the pad LOCK held */
1791 /* refs the caps, so caller is responsible for getting it unreffed */
1793 gst_pad_get_caps_unlocked (GstPad * pad)
1795 GstCaps *result = NULL;
1797 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1798 GST_DEBUG_PAD_NAME (pad), pad);
1800 if (GST_PAD_GETCAPSFUNC (pad)) {
1801 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1803 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1804 GST_OBJECT_UNLOCK (pad);
1805 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1806 GST_OBJECT_LOCK (pad);
1807 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1809 if (result == NULL) {
1810 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1811 GST_DEBUG_PAD_NAME (pad));
1813 GST_CAT_DEBUG (GST_CAT_CAPS,
1814 "pad getcaps %s:%s returned %" GST_PTR_FORMAT,
1815 GST_DEBUG_PAD_NAME (pad), result);
1816 #ifndef G_DISABLE_ASSERT
1817 /* check that the returned caps are a real subset of the template caps */
1818 if (GST_PAD_PAD_TEMPLATE (pad)) {
1819 const GstCaps *templ_caps =
1820 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1821 if (!gst_caps_is_subset (result, templ_caps)) {
1824 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1825 "pad returned caps %" GST_PTR_FORMAT
1826 " which are not a real subset of its template caps %"
1827 GST_PTR_FORMAT, result, templ_caps);
1829 ("pad %s:%s returned caps that are not a real subset of its template caps",
1830 GST_DEBUG_PAD_NAME (pad));
1831 temp = gst_caps_intersect (templ_caps, result);
1832 gst_caps_unref (result);
1840 if (GST_PAD_PAD_TEMPLATE (pad)) {
1841 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1843 result = GST_PAD_TEMPLATE_CAPS (templ);
1844 GST_CAT_DEBUG (GST_CAT_CAPS,
1845 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1848 result = gst_caps_ref (result);
1851 if (GST_PAD_CAPS (pad)) {
1852 result = GST_PAD_CAPS (pad);
1854 GST_CAT_DEBUG (GST_CAT_CAPS,
1855 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1857 result = gst_caps_ref (result);
1861 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1862 result = gst_caps_new_empty ();
1870 * @pad: a #GstPad to get the capabilities of.
1872 * Gets the capabilities this pad can produce or consume.
1873 * Note that this method doesn't necessarily returns the caps set by
1874 * #gst_pad_set_caps - use #GST_PAD_CAPS for that instead.
1875 * gst_pad_get_caps returns all possible caps a pad can operate with, using
1876 * the pad's get_caps function;
1877 * this returns the pad template caps if not explicitly set.
1879 * Returns: a newly allocated copy of the #GstCaps of this pad.
1884 gst_pad_get_caps (GstPad * pad)
1886 GstCaps *result = NULL;
1888 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1890 GST_OBJECT_LOCK (pad);
1892 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1893 GST_DEBUG_PAD_NAME (pad), pad);
1895 result = gst_pad_get_caps_unlocked (pad);
1896 GST_OBJECT_UNLOCK (pad);
1902 * gst_pad_peer_get_caps:
1903 * @pad: a #GstPad to get the peer capabilities of.
1905 * Gets the capabilities of the peer connected to this pad.
1907 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1908 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1912 gst_pad_peer_get_caps (GstPad * pad)
1915 GstCaps *result = NULL;
1917 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1919 GST_OBJECT_LOCK (pad);
1921 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1922 GST_DEBUG_PAD_NAME (pad), pad);
1924 peerpad = GST_PAD_PEER (pad);
1925 if (G_UNLIKELY (peerpad == NULL))
1928 gst_object_ref (peerpad);
1929 GST_OBJECT_UNLOCK (pad);
1931 result = gst_pad_get_caps (peerpad);
1933 gst_object_unref (peerpad);
1939 GST_OBJECT_UNLOCK (pad);
1945 fixate_value (GValue * dest, const GValue * src)
1947 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
1948 g_value_init (dest, G_TYPE_INT);
1949 g_value_set_int (dest, gst_value_get_int_range_min (src));
1950 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
1951 g_value_init (dest, G_TYPE_DOUBLE);
1952 g_value_set_double (dest, gst_value_get_double_range_min (src));
1953 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1954 GValue temp = { 0 };
1956 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
1957 if (!fixate_value (dest, &temp))
1958 gst_value_init_and_copy (dest, &temp);
1959 g_value_unset (&temp);
1960 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
1961 gboolean res = FALSE;
1964 g_value_init (dest, GST_TYPE_ARRAY);
1965 for (n = 0; n < gst_value_array_get_size (src); n++) {
1967 const GValue *orig_kid = gst_value_array_get_value (src, n);
1969 if (!fixate_value (&kid, orig_kid))
1970 gst_value_init_and_copy (&kid, orig_kid);
1973 gst_value_array_append_value (dest, &kid);
1974 g_value_unset (&kid);
1978 g_value_unset (dest);
1989 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
1991 GstStructure *s = data;
1994 if (fixate_value (&v, value)) {
1995 gst_structure_id_set_value (s, field_id, &v);
2003 * gst_pad_fixate_caps:
2004 * @pad: a #GstPad to fixate
2005 * @caps: the #GstCaps to fixate
2007 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2008 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2011 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2013 GstPadFixateCapsFunction fixatefunc;
2016 g_return_if_fail (GST_IS_PAD (pad));
2017 g_return_if_fail (caps != NULL);
2019 if (gst_caps_is_fixed (caps))
2022 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
2024 fixatefunc (pad, caps);
2027 /* default fixation */
2028 for (n = 0; n < gst_caps_get_size (caps); n++) {
2029 GstStructure *s = gst_caps_get_structure (caps, n);
2031 gst_structure_foreach (s, gst_pad_default_fixate, s);
2036 * gst_pad_accept_caps:
2037 * @pad: a #GstPad to check
2038 * @caps: a #GstCaps to check on the pad
2040 * Check if the given pad accepts the caps.
2042 * Returns: TRUE if the pad can accept the caps.
2045 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2048 GstPadAcceptCapsFunction acceptfunc;
2050 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2052 /* any pad can be unnegotiated */
2056 GST_OBJECT_LOCK (pad);
2057 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2059 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
2060 GST_DEBUG_PAD_NAME (pad), pad);
2061 GST_OBJECT_UNLOCK (pad);
2064 /* we can call the function */
2065 result = acceptfunc (pad, caps);
2067 /* else see get the caps and see if it intersects to something
2072 allowed = gst_pad_get_caps (pad);
2074 intersect = gst_caps_intersect (allowed, caps);
2076 result = !gst_caps_is_empty (intersect);
2078 gst_caps_unref (allowed);
2079 gst_caps_unref (intersect);
2088 * gst_pad_peer_accept_caps:
2089 * @pad: a #GstPad to check
2090 * @caps: a #GstCaps to check on the pad
2092 * Check if the given pad accepts the caps.
2094 * Returns: TRUE if the pad can accept the caps.
2097 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2102 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2104 GST_OBJECT_LOCK (pad);
2106 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
2107 GST_DEBUG_PAD_NAME (pad), pad);
2109 peerpad = GST_PAD_PEER (pad);
2110 if (G_UNLIKELY (peerpad == NULL))
2113 result = gst_pad_accept_caps (peerpad, caps);
2114 GST_OBJECT_UNLOCK (pad);
2120 GST_OBJECT_UNLOCK (pad);
2127 * @pad: a #GstPad to set the capabilities of.
2128 * @caps: a #GstCaps to set.
2130 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2131 * caps on the pad will be unreffed. This function refs the caps so you should
2132 * unref if as soon as you don't need it anymore.
2133 * It is possible to set NULL caps, which will make the pad unnegotiated
2136 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2137 * or bad parameters were provided to this function.
2142 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2144 GstPadSetCapsFunction setcaps;
2147 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2148 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2150 GST_OBJECT_LOCK (pad);
2151 setcaps = GST_PAD_SETCAPSFUNC (pad);
2153 existing = GST_PAD_CAPS (pad);
2154 if (gst_caps_is_equal (caps, existing))
2155 goto setting_same_caps;
2157 /* call setcaps function to configure the pad only if the
2158 * caps is not NULL */
2159 if (setcaps != NULL && caps) {
2160 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2161 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2162 GST_OBJECT_UNLOCK (pad);
2163 if (!setcaps (pad, caps))
2165 GST_OBJECT_LOCK (pad);
2166 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2168 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
2169 GST_DEBUG_PAD_NAME (pad));
2173 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2174 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
2175 GST_DEBUG_PAD_NAME (pad), caps);
2176 GST_OBJECT_UNLOCK (pad);
2178 g_object_notify (G_OBJECT (pad), "caps");
2184 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2185 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2186 "caps %" GST_PTR_FORMAT " same as existing, updating ptr only", caps);
2187 GST_OBJECT_UNLOCK (pad);
2194 GST_OBJECT_LOCK (pad);
2195 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2196 GST_CAT_DEBUG (GST_CAT_CAPS,
2197 "pad %s:%s, caps %" GST_PTR_FORMAT " could not be set",
2198 GST_DEBUG_PAD_NAME (pad), caps);
2199 GST_OBJECT_UNLOCK (pad);
2206 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2208 GstPadAcceptCapsFunction acceptcaps;
2209 GstPadSetCapsFunction setcaps;
2212 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2213 setcaps = GST_PAD_SETCAPSFUNC (pad);
2215 /* See if pad accepts the caps, by calling acceptcaps, only
2216 * needed if no setcaps function */
2217 if (setcaps == NULL && acceptcaps != NULL) {
2218 if (!acceptcaps (pad, caps))
2221 /* set caps on pad if call succeeds */
2222 res = gst_pad_set_caps (pad, caps);
2223 /* no need to unref the caps here, set_caps takes a ref and
2224 * our ref goes away when we leave this function. */
2230 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2235 /* returns TRUE if the src pad could be configured to accept the given caps */
2237 gst_pad_configure_src (GstPad * pad, GstCaps * caps, gboolean dosetcaps)
2239 GstPadAcceptCapsFunction acceptcaps;
2240 GstPadSetCapsFunction setcaps;
2243 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2244 setcaps = GST_PAD_SETCAPSFUNC (pad);
2246 /* See if pad accepts the caps, by calling acceptcaps, only
2247 * needed if no setcaps function */
2248 if (setcaps == NULL && acceptcaps != NULL) {
2249 if (!acceptcaps (pad, caps))
2253 res = gst_pad_set_caps (pad, caps);
2261 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2267 * gst_pad_get_pad_template_caps:
2268 * @pad: a #GstPad to get the template capabilities from.
2270 * Gets the capabilities for @pad's template.
2272 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2273 * on the caps, make a copy (see gst_caps_copy ()).
2276 gst_pad_get_pad_template_caps (GstPad * pad)
2278 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2280 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2282 if (GST_PAD_PAD_TEMPLATE (pad))
2283 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2285 return gst_static_caps_get (&anycaps);
2291 * @pad: a #GstPad to get the peer of.
2293 * Gets the peer of @pad. This function refs the peer pad so
2294 * you need to unref it after use.
2296 * Returns: the peer #GstPad. Unref after usage.
2301 gst_pad_get_peer (GstPad * pad)
2305 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2307 GST_OBJECT_LOCK (pad);
2308 result = GST_PAD_PEER (pad);
2310 gst_object_ref (result);
2311 GST_OBJECT_UNLOCK (pad);
2317 * gst_pad_get_allowed_caps:
2318 * @srcpad: a #GstPad, it must a a source pad.
2320 * Gets the capabilities of the allowed media types that can flow through
2321 * @srcpad and its peer. The pad must be a source pad.
2322 * The caller must free the resulting caps.
2324 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2325 * you no longer need it. This function returns NULL when the @srcpad has no
2331 gst_pad_get_allowed_caps (GstPad * srcpad)
2338 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2339 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2341 GST_OBJECT_LOCK (srcpad);
2343 peer = GST_PAD_PEER (srcpad);
2344 if (G_UNLIKELY (peer == NULL))
2347 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2348 GST_DEBUG_PAD_NAME (srcpad));
2350 gst_object_ref (peer);
2351 GST_OBJECT_UNLOCK (srcpad);
2352 mycaps = gst_pad_get_caps (srcpad);
2354 peercaps = gst_pad_get_caps (peer);
2355 gst_object_unref (peer);
2357 caps = gst_caps_intersect (mycaps, peercaps);
2358 gst_caps_unref (peercaps);
2359 gst_caps_unref (mycaps);
2361 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2367 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2368 GST_DEBUG_PAD_NAME (srcpad));
2369 GST_OBJECT_UNLOCK (srcpad);
2376 * gst_pad_get_negotiated_caps:
2379 * Gets the capabilities of the media type that currently flows through @pad
2382 * This function can be used on both src and sinkpads. Note that srcpads are
2383 * always negotiated before sinkpads so it is possible that the negotiated caps
2384 * on the srcpad do not match the negotiated caps of the peer.
2386 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2387 * you no longer need it. This function returns NULL when the @pad has no
2388 * peer or is not negotiated yet.
2393 gst_pad_get_negotiated_caps (GstPad * pad)
2398 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2400 GST_OBJECT_LOCK (pad);
2402 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2405 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2406 GST_DEBUG_PAD_NAME (pad));
2408 caps = GST_PAD_CAPS (pad);
2410 gst_caps_ref (caps);
2411 GST_OBJECT_UNLOCK (pad);
2413 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2419 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2420 GST_DEBUG_PAD_NAME (pad));
2421 GST_OBJECT_UNLOCK (pad);
2427 static GstFlowReturn
2428 gst_pad_alloc_buffer_full (GstPad * pad, guint64 offset, gint size,
2429 GstCaps * caps, GstBuffer ** buf, gboolean setcaps)
2433 GstPadBufferAllocFunction bufferallocfunc;
2434 gboolean caps_changed;
2436 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2437 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2438 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2440 GST_OBJECT_LOCK (pad);
2441 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2442 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
2445 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2448 gst_object_ref (peer);
2449 GST_OBJECT_UNLOCK (pad);
2451 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2454 GST_OBJECT_LOCK (peer);
2455 /* when the peer is flushing we cannot give a buffer */
2456 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2459 if (offset == GST_BUFFER_OFFSET_NONE) {
2460 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2461 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d offset NONE",
2462 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2463 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size);
2465 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
2466 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d offset %"
2467 G_GUINT64_FORMAT, GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2468 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size, offset);
2470 GST_OBJECT_UNLOCK (peer);
2472 ret = bufferallocfunc (peer, offset, size, caps, buf);
2474 if (G_UNLIKELY (ret != GST_FLOW_OK))
2476 if (G_UNLIKELY (*buf == NULL))
2479 /* If the buffer alloc function didn't set up the caps like it should,
2481 if (caps && (GST_BUFFER_CAPS (*buf) == NULL)) {
2482 GST_WARNING ("Buffer allocation function for pad % " GST_PTR_FORMAT
2483 " did not set up caps. Setting", peer);
2485 gst_buffer_set_caps (*buf, caps);
2489 gst_object_unref (peer);
2491 /* FIXME, move capnego this into a base class? */
2492 caps = GST_BUFFER_CAPS (*buf);
2493 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2494 /* we got a new datatype on the pad, see if it can handle it */
2495 if (G_UNLIKELY (caps_changed)) {
2496 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2497 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, setcaps)))
2498 goto not_negotiated;
2504 GST_CAT_DEBUG (GST_CAT_PADS, "%s:%s pad block stopped by flush",
2505 GST_DEBUG_PAD_NAME (pad));
2506 GST_OBJECT_UNLOCK (pad);
2511 /* pad has no peer */
2512 GST_CAT_DEBUG (GST_CAT_PADS,
2513 "%s:%s called bufferallocfunc but had no peer",
2514 GST_DEBUG_PAD_NAME (pad));
2515 GST_OBJECT_UNLOCK (pad);
2516 return GST_FLOW_NOT_LINKED;
2520 /* peer was flushing */
2521 GST_OBJECT_UNLOCK (peer);
2522 gst_object_unref (peer);
2523 GST_CAT_DEBUG (GST_CAT_PADS,
2524 "%s:%s called bufferallocfunc but peer was flushing",
2525 GST_DEBUG_PAD_NAME (pad));
2526 return GST_FLOW_WRONG_STATE;
2528 /* fallback case, allocate a buffer of our own, add pad caps. */
2531 GST_CAT_DEBUG (GST_CAT_PADS,
2532 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2533 *buf = gst_buffer_new_and_alloc (size);
2534 GST_BUFFER_OFFSET (*buf) = offset;
2535 gst_buffer_set_caps (*buf, caps);
2543 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2544 "alloc function returned unacceptable buffer");
2545 return GST_FLOW_NOT_NEGOTIATED;
2549 gst_object_unref (peer);
2550 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2551 "alloc function returned error %s", gst_flow_get_name (ret));
2557 * gst_pad_alloc_buffer:
2558 * @pad: a source #GstPad
2559 * @offset: the offset of the new buffer in the stream
2560 * @size: the size of the new buffer
2561 * @caps: the caps of the new buffer
2562 * @buf: a newly allocated buffer
2564 * Allocates a new, empty buffer optimized to push to pad @pad. This
2565 * function only works if @pad is a source pad and has a peer.
2567 * You need to check the caps of the buffer after performing this
2568 * function and renegotiate to the format if needed.
2570 * A new, empty #GstBuffer will be put in the @buf argument.
2572 * Returns: a result code indicating success of the operation. Any
2573 * result code other than GST_FLOW_OK is an error and @buf should
2575 * An error can occur if the pad is not connected or when the downstream
2576 * peer elements cannot provide an acceptable buffer.
2581 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2584 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, FALSE);
2588 * gst_pad_alloc_buffer_and_set_caps:
2589 * @pad: a source #GstPad
2590 * @offset: the offset of the new buffer in the stream
2591 * @size: the size of the new buffer
2592 * @caps: the caps of the new buffer
2593 * @buf: a newly allocated buffer
2595 * In addition to the function gst_pad_alloc_buffer(), this function
2596 * automatically calls gst_pad_set_caps() when the caps of the
2597 * newly allocated buffer are different from the @pad caps.
2599 * Returns: a result code indicating success of the operation. Any
2600 * result code other than GST_FLOW_OK is an error and @buf should
2602 * An error can occur if the pad is not connected or when the downstream
2603 * peer elements cannot provide an acceptable buffer.
2608 gst_pad_alloc_buffer_and_set_caps (GstPad * pad, guint64 offset, gint size,
2609 GstCaps * caps, GstBuffer ** buf)
2611 return gst_pad_alloc_buffer_full (pad, offset, size, caps, buf, TRUE);
2615 * gst_pad_get_internal_links_default:
2616 * @pad: the #GstPad to get the internal links of.
2618 * Gets a list of pads to which the given pad is linked to
2619 * inside of the parent element.
2620 * This is the default handler, and thus returns a list of all of the
2621 * pads inside the parent element with opposite direction.
2622 * The caller must free this list after use.
2624 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
2629 gst_pad_get_internal_links_default (GstPad * pad)
2634 GstPadDirection direction;
2636 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2638 direction = pad->direction;
2640 parent = GST_PAD_PARENT (pad);
2644 parent_pads = parent->pads;
2646 while (parent_pads) {
2647 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2649 if (parent_pad->direction != direction) {
2650 res = g_list_prepend (res, parent_pad);
2653 parent_pads = g_list_next (parent_pads);
2660 * gst_pad_get_internal_links:
2661 * @pad: the #GstPad to get the internal links of.
2663 * Gets a list of pads to which the given pad is linked to
2664 * inside of the parent element.
2665 * The caller must free this list after use.
2667 * Returns: a newly allocated #GList of pads.
2672 gst_pad_get_internal_links (GstPad * pad)
2676 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2678 if (GST_PAD_INTLINKFUNC (pad))
2679 res = GST_PAD_INTLINKFUNC (pad) (pad);
2686 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2691 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2694 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2696 orig = pads = gst_pad_get_internal_links (pad);
2699 GstPad *eventpad = GST_PAD_CAST (pads->data);
2701 pads = g_list_next (pads);
2703 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2704 /* for each pad we send to, we should ref the event; it's up
2705 * to downstream to unref again when handled. */
2706 GST_LOG_OBJECT (pad, "Reffing and sending event %p (%s) to %s:%s",
2707 event, gst_event_type_get_name (GST_EVENT_TYPE (event)),
2708 GST_DEBUG_PAD_NAME (eventpad));
2709 gst_event_ref (event);
2710 gst_pad_push_event (eventpad, event);
2712 /* we only send the event on one pad, multi-sinkpad elements
2713 * should implement a handler */
2714 GST_LOG_OBJECT (pad, "sending event %p (%s) to one sink pad %s:%s",
2715 event, gst_event_type_get_name (GST_EVENT_TYPE (event)),
2716 GST_DEBUG_PAD_NAME (eventpad));
2717 result = gst_pad_push_event (eventpad, event);
2721 /* we handled the incoming event so we unref once */
2722 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2723 gst_event_unref (event);
2732 * gst_pad_event_default:
2733 * @pad: a #GstPad to call the default event handler on.
2734 * @event: the #GstEvent to handle.
2736 * Invokes the default event handler for the given pad. End-of-stream and
2737 * discontinuity events are handled specially, and then the event is sent to all
2738 * pads internally linked to @pad. Note that if there are many possible sink
2739 * pads that are internally linked to @pad, only one will be sent an event.
2740 * Multi-sinkpad elements should implement custom event handlers.
2742 * Returns: TRUE if the event was sent succesfully.
2745 gst_pad_event_default (GstPad * pad, GstEvent * event)
2747 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2748 g_return_val_if_fail (event != NULL, FALSE);
2750 switch (GST_EVENT_TYPE (event)) {
2753 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2754 gst_pad_pause_task (pad);
2760 return gst_pad_event_default_dispatch (pad, event);
2764 * gst_pad_dispatcher:
2765 * @pad: a #GstPad to dispatch.
2766 * @dispatch: the #GstDispatcherFunction to call.
2767 * @data: gpointer user data passed to the dispatcher function.
2769 * Invokes the given dispatcher function on all pads that are
2770 * internally linked to the given pad.
2771 * The GstPadDispatcherFunction should return TRUE when no further pads
2772 * need to be processed.
2774 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2777 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2780 gboolean res = FALSE;
2781 GList *int_pads, *orig;
2783 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2784 g_return_val_if_fail (dispatch != NULL, FALSE);
2786 orig = int_pads = gst_pad_get_internal_links (pad);
2789 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2790 GstPad *int_peer = GST_PAD_PEER (int_pad);
2793 res = dispatch (int_peer, data);
2797 int_pads = g_list_next (int_pads);
2807 * @pad: a #GstPad to invoke the default query on.
2808 * @query: the #GstQuery to perform.
2810 * Dispatches a query to a pad. The query should have been allocated by the
2811 * caller via one of the type-specific allocation functions in gstquery.h. The
2812 * element is responsible for filling the query with an appropriate response,
2813 * which should then be parsed with a type-specific query parsing function.
2815 * Again, the caller is responsible for both the allocation and deallocation of
2816 * the query structure.
2818 * Returns: TRUE if the query could be performed.
2821 gst_pad_query (GstPad * pad, GstQuery * query)
2823 GstPadQueryFunction func;
2825 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2826 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2828 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2830 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2833 return func (pad, query);
2837 GST_DEBUG ("pad had no query function");
2843 * gst_pad_query_default:
2844 * @pad: a #GstPad to call the default query handler on.
2845 * @query: the #GstQuery to handle.
2847 * Invokes the default query handler for the given pad.
2848 * The query is sent to all pads internally linked to @pad. Note that
2849 * if there are many possible sink pads that are internally linked to
2850 * @pad, only one will be sent the query.
2851 * Multi-sinkpad elements should implement custom query handlers.
2853 * Returns: TRUE if the query was performed succesfully.
2856 gst_pad_query_default (GstPad * pad, GstQuery * query)
2858 switch (GST_QUERY_TYPE (query)) {
2859 case GST_QUERY_POSITION:
2860 case GST_QUERY_SEEKING:
2861 case GST_QUERY_FORMATS:
2862 case GST_QUERY_LATENCY:
2863 case GST_QUERY_JITTER:
2864 case GST_QUERY_RATE:
2865 case GST_QUERY_CONVERT:
2867 return gst_pad_dispatcher
2868 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2872 #ifndef GST_DISABLE_LOADSAVE
2873 /* FIXME: why isn't this on a GstElement ? */
2875 * gst_pad_load_and_link:
2876 * @self: an #xmlNodePtr to read the description from.
2877 * @parent: the #GstObject element that owns the pad.
2879 * Reads the pad definition from the XML node and links the given pad
2880 * in the element to a pad of an element up in the hierarchy.
2883 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2885 xmlNodePtr field = self->xmlChildrenNode;
2886 GstPad *pad = NULL, *targetpad;
2890 GstObject *grandparent;
2894 if (!strcmp ((char *) field->name, "name")) {
2895 name = (gchar *) xmlNodeGetContent (field);
2896 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2898 } else if (!strcmp ((char *) field->name, "peer")) {
2899 peer = (gchar *) xmlNodeGetContent (field);
2901 field = field->next;
2903 g_return_if_fail (pad != NULL);
2908 split = g_strsplit (peer, ".", 2);
2910 if (split[0] == NULL || split[1] == NULL) {
2911 GST_CAT_DEBUG (GST_CAT_XML,
2912 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2913 peer, GST_DEBUG_PAD_NAME (pad));
2920 g_return_if_fail (split[0] != NULL);
2921 g_return_if_fail (split[1] != NULL);
2923 grandparent = gst_object_get_parent (parent);
2925 if (grandparent && GST_IS_BIN (grandparent)) {
2926 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2933 targetpad = gst_element_get_pad (target, split[1]);
2935 if (targetpad == NULL)
2938 gst_pad_link (pad, targetpad);
2945 * gst_pad_save_thyself:
2946 * @pad: a #GstPad to save.
2947 * @parent: the parent #xmlNodePtr to save the description in.
2949 * Saves the pad into an xml representation.
2951 * Returns: the #xmlNodePtr representation of the pad.
2954 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2959 g_return_val_if_fail (GST_IS_PAD (object), NULL);
2961 pad = GST_PAD (object);
2963 xmlNewChild (parent, NULL, (xmlChar *) "name",
2964 (xmlChar *) GST_PAD_NAME (pad));
2965 if (GST_PAD_PEER (pad) != NULL) {
2968 peer = GST_PAD_PEER (pad);
2969 /* first check to see if the peer's parent's parent is the same */
2970 /* we just save it off */
2971 content = g_strdup_printf ("%s.%s",
2972 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2973 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
2976 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
2983 * gst_ghost_pad_save_thyself:
2984 * @pad: a ghost #GstPad to save.
2985 * @parent: the parent #xmlNodePtr to save the description in.
2987 * Saves the ghost pad into an xml representation.
2989 * Returns: the #xmlNodePtr representation of the pad.
2992 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2996 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2998 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
2999 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
3000 xmlNewChild (self, NULL, (xmlChar *) "parent",
3001 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3003 /* FIXME FIXME FIXME! */
3008 #endif /* GST_DISABLE_LOADSAVE */
3011 * should be called with pad lock held
3015 static GstFlowReturn
3016 handle_pad_block (GstPad * pad)
3018 GstPadBlockCallback callback;
3020 GstFlowReturn ret = GST_FLOW_OK;
3022 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3023 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
3025 /* need to grab extra ref for the callbacks */
3026 gst_object_ref (pad);
3028 callback = pad->block_callback;
3030 user_data = pad->block_data;
3031 GST_OBJECT_UNLOCK (pad);
3032 callback (pad, TRUE, user_data);
3033 GST_OBJECT_LOCK (pad);
3035 GST_PAD_BLOCK_SIGNAL (pad);
3038 while (GST_PAD_IS_BLOCKED (pad)) {
3039 if (GST_PAD_IS_FLUSHING (pad))
3041 GST_PAD_BLOCK_WAIT (pad);
3042 if (GST_PAD_IS_FLUSHING (pad))
3046 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
3048 callback = pad->block_callback;
3050 user_data = pad->block_data;
3051 GST_OBJECT_UNLOCK (pad);
3052 callback (pad, FALSE, user_data);
3053 GST_OBJECT_LOCK (pad);
3055 GST_PAD_BLOCK_SIGNAL (pad);
3058 gst_object_unref (pad);
3064 gst_object_unref (pad);
3065 return GST_FLOW_WRONG_STATE;
3069 /**********************************************************************
3070 * Data passing functions
3074 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
3077 GValue args[2] = { {0}, {0} };
3082 g_value_init (&ret, G_TYPE_BOOLEAN);
3083 g_value_set_boolean (&ret, TRUE);
3084 g_value_init (&args[0], GST_TYPE_PAD);
3085 g_value_set_object (&args[0], pad);
3086 g_value_init (&args[1], GST_TYPE_MINI_OBJECT); // G_TYPE_POINTER);
3087 gst_value_set_mini_object (&args[1], obj);
3089 if (GST_IS_EVENT (obj))
3090 detail = event_quark;
3092 detail = buffer_quark;
3095 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
3096 res = g_value_get_boolean (&ret);
3099 g_value_unset (&ret);
3100 g_value_unset (&args[0]);
3101 g_value_unset (&args[1]);
3108 * @pad: a sink #GstPad.
3109 * @buffer: the #GstBuffer to send.
3111 * Chain a buffer to @pad.
3113 * Returns: a #GstFlowReturn from the pad.
3118 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3121 gboolean caps_changed;
3122 GstPadChainFunction chainfunc;
3124 gboolean emit_signal;
3126 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3127 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3129 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3130 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3132 GST_PAD_STREAM_LOCK (pad);
3134 GST_OBJECT_LOCK (pad);
3135 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3138 caps = GST_BUFFER_CAPS (buffer);
3139 caps_changed = caps && caps != GST_PAD_CAPS (pad);
3141 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3142 GST_OBJECT_UNLOCK (pad);
3144 /* see if the signal should be emited, we emit before caps nego as
3145 * we might drop the buffer and do capsnego for nothing. */
3146 if (G_UNLIKELY (emit_signal)) {
3147 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3151 /* we got a new datatype on the pad, see if it can handle it */
3152 if (G_UNLIKELY (caps_changed)) {
3153 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
3154 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
3155 goto not_negotiated;
3158 /* NOTE: we read the chainfunc unlocked.
3159 * we cannot hold the lock for the pad so we might send
3160 * the data to the wrong function. This is not really a
3161 * problem since functions are assigned at creation time
3162 * and don't change that often... */
3163 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3166 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3167 "calling chainfunction &%s of pad %s:%s",
3168 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
3170 ret = chainfunc (pad, buffer);
3172 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3173 "called chainfunction &%s of pad %s:%s, returned %s",
3174 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad),
3175 gst_flow_get_name (ret));
3177 GST_PAD_STREAM_UNLOCK (pad);
3184 gst_buffer_unref (buffer);
3185 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3186 "pushing, but pad was flushing");
3187 GST_OBJECT_UNLOCK (pad);
3188 GST_PAD_STREAM_UNLOCK (pad);
3189 return GST_FLOW_WRONG_STATE;
3193 gst_buffer_unref (buffer);
3194 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
3195 GST_PAD_STREAM_UNLOCK (pad);
3200 gst_buffer_unref (buffer);
3201 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3202 "pushing buffer but pad did not accept");
3203 GST_PAD_STREAM_UNLOCK (pad);
3204 return GST_FLOW_NOT_NEGOTIATED;
3208 gst_buffer_unref (buffer);
3209 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3210 "pushing, but not chainhandler");
3211 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3212 ("push on pad %s:%s but it has no chainfunction",
3213 GST_DEBUG_PAD_NAME (pad)));
3214 GST_PAD_STREAM_UNLOCK (pad);
3215 return GST_FLOW_ERROR;
3221 * @pad: a source #GstPad.
3222 * @buffer: the #GstBuffer to push.
3224 * Pushes a buffer to the peer of @pad.
3225 * buffer probes will be triggered before the buffer gets pushed.
3227 * Returns: a #GstFlowReturn from the peer pad.
3232 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3237 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3238 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3239 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3240 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3242 GST_OBJECT_LOCK (pad);
3244 /* FIXME: this check can go away; pad_set_blocked could be implemented with
3245 * probes completely */
3246 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3247 if ((ret = handle_pad_block (pad)) != GST_FLOW_OK)
3250 /* we emit signals on the pad arg, the peer will have a chance to
3251 * emit in the _chain() function */
3252 if (G_UNLIKELY (GST_PAD_DO_BUFFER_SIGNALS (pad) > 0)) {
3253 /* unlock before emitting */
3254 GST_OBJECT_UNLOCK (pad);
3256 /* if the signal handler returned FALSE, it means we should just drop the
3258 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3261 GST_OBJECT_LOCK (pad);
3264 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3266 gst_object_ref (peer);
3267 GST_OBJECT_UNLOCK (pad);
3269 ret = gst_pad_chain (peer, buffer);
3271 gst_object_unref (peer);
3275 /* ERROR recovery here */
3278 gst_buffer_unref (buffer);
3279 GST_DEBUG_OBJECT (pad, "pad block stopped by flush");
3280 GST_OBJECT_UNLOCK (pad);
3285 gst_buffer_unref (buffer);
3286 GST_DEBUG_OBJECT (pad, "Dropping buffer due to FALSE probe return");
3291 gst_buffer_unref (buffer);
3292 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3293 "pushing, but it was not linked");
3294 GST_OBJECT_UNLOCK (pad);
3295 return GST_FLOW_NOT_LINKED;
3300 * gst_pad_check_pull_range:
3301 * @pad: a sink #GstPad.
3303 * Checks if a #gst_pad_pull_range() can be performed on the peer
3304 * source pad. This function is used by plugins that want to check
3305 * if they can use random access on the peer source pad.
3307 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
3308 * if it needs to perform some logic to determine if pull_range is
3311 * Returns: a gboolean with the result.
3316 gst_pad_check_pull_range (GstPad * pad)
3320 GstPadCheckGetRangeFunction checkgetrangefunc;
3322 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3324 GST_OBJECT_LOCK (pad);
3325 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
3326 goto wrong_direction;
3328 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3331 gst_object_ref (peer);
3332 GST_OBJECT_UNLOCK (pad);
3334 /* see note in above function */
3335 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
3336 /* FIXME, kindoff ghetto */
3337 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
3339 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3340 "calling checkgetrangefunc %s of peer pad %s:%s",
3341 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
3343 ret = checkgetrangefunc (peer);
3346 gst_object_unref (peer);
3350 /* ERROR recovery here */
3353 GST_OBJECT_UNLOCK (pad);
3358 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3359 "checking pull range, but it was not linked");
3360 GST_OBJECT_UNLOCK (pad);
3366 * gst_pad_get_range:
3367 * @pad: a src #GstPad.
3368 * @offset: The start offset of the buffer
3369 * @size: The length of the buffer
3370 * @buffer: a pointer to hold the #GstBuffer.
3372 * Calls the getrange function of @pad.
3374 * Returns: a #GstFlowReturn from the pad.
3379 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3380 GstBuffer ** buffer)
3383 GstPadGetRangeFunction getrangefunc;
3384 gboolean emit_signal;
3386 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3387 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3388 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3390 GST_PAD_STREAM_LOCK (pad);
3392 GST_OBJECT_LOCK (pad);
3393 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3396 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3397 GST_OBJECT_UNLOCK (pad);
3399 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3402 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3403 "calling getrangefunc %s of peer pad %s:%s, offset %"
3404 G_GUINT64_FORMAT ", size %u",
3405 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
3408 ret = getrangefunc (pad, offset, size, buffer);
3410 /* can only fire the signal if we have a valid buffer */
3411 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3412 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3416 GST_PAD_STREAM_UNLOCK (pad);
3423 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3424 "pulling range, but pad was flushing");
3425 GST_OBJECT_UNLOCK (pad);
3426 GST_PAD_STREAM_UNLOCK (pad);
3427 return GST_FLOW_WRONG_STATE;
3431 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3432 ("pullrange on pad %s:%s but it has no getrangefunction",
3433 GST_DEBUG_PAD_NAME (pad)));
3434 GST_PAD_STREAM_UNLOCK (pad);
3435 return GST_FLOW_ERROR;
3439 GST_DEBUG ("Dropping data after FALSE probe return");
3440 GST_PAD_STREAM_UNLOCK (pad);
3441 gst_buffer_unref (*buffer);
3443 return GST_FLOW_UNEXPECTED;
3449 * gst_pad_pull_range:
3450 * @pad: a sink #GstPad.
3451 * @offset: The start offset of the buffer
3452 * @size: The length of the buffer
3453 * @buffer: a pointer to hold the #GstBuffer.
3455 * Pulls a buffer from the peer pad. @pad must be a linked
3458 * Returns: a #GstFlowReturn from the peer pad.
3463 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3464 GstBuffer ** buffer)
3468 gboolean emit_signal;
3470 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3471 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3473 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3475 GST_OBJECT_LOCK (pad);
3477 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3478 handle_pad_block (pad);
3480 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3483 /* signal emision for the pad, peer has chance to emit when
3484 * we call _get_range() */
3485 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3487 gst_object_ref (peer);
3488 GST_OBJECT_UNLOCK (pad);
3490 ret = gst_pad_get_range (peer, offset, size, buffer);
3492 gst_object_unref (peer);
3494 /* can only fire the signal if we have a valid buffer */
3495 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3496 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3501 /* ERROR recovery here */
3504 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3505 "pulling range, but it was not linked");
3506 GST_OBJECT_UNLOCK (pad);
3507 return GST_FLOW_NOT_LINKED;
3511 GST_DEBUG ("Dropping data after FALSE probe return");
3512 gst_buffer_unref (*buffer);
3514 return GST_FLOW_UNEXPECTED;
3519 * gst_pad_push_event:
3520 * @pad: a #GstPad to push the event to.
3521 * @event: the #GstEvent to send to the pad.
3523 * Sends the event to the peer of the given pad. This function is
3524 * mainly used by elements to send events to their peer
3527 * Returns: TRUE if the event was handled.
3532 gst_pad_push_event (GstPad * pad, GstEvent * event)
3537 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3538 g_return_val_if_fail (event != NULL, FALSE);
3539 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
3541 GST_OBJECT_LOCK (pad);
3542 switch (GST_EVENT_TYPE (event)) {
3543 case GST_EVENT_FLUSH_START:
3544 GST_PAD_SET_FLUSHING (pad);
3546 case GST_EVENT_FLUSH_STOP:
3547 GST_PAD_UNSET_FLUSHING (pad);
3553 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
3554 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) {
3555 GST_PAD_BLOCK_SIGNAL (pad);
3559 if (G_UNLIKELY (GST_PAD_DO_EVENT_SIGNALS (pad) > 0)) {
3560 GST_OBJECT_UNLOCK (pad);
3562 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3565 GST_OBJECT_LOCK (pad);
3567 peerpad = GST_PAD_PEER (pad);
3568 if (peerpad == NULL)
3571 GST_LOG_OBJECT (peerpad, "sending event on peerpad");
3572 gst_object_ref (peerpad);
3573 GST_OBJECT_UNLOCK (pad);
3575 result = gst_pad_send_event (peerpad, event);
3577 gst_object_unref (peerpad);
3578 GST_LOG_OBJECT (peerpad, "sent event on peerpad");
3582 /* ERROR handling */
3585 GST_DEBUG_OBJECT (pad, "Dropping event after FALSE probe return");
3586 gst_event_unref (event);
3591 gst_event_unref (event);
3592 GST_OBJECT_UNLOCK (pad);
3598 * gst_pad_send_event:
3599 * @pad: a #GstPad to send the event to.
3600 * @event: the #GstEvent to send to the pad.
3602 * Sends the event to the pad. This function can be used
3603 * by applications to send events in the pipeline.
3605 * If @pad is a source pad, @event should be an upstream event. If @pad is a
3606 * sink pad, @event should be a downstream event. For example, you would not
3607 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
3608 * Furthermore, some downstream events have to be serialized with data flow,
3609 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
3610 * the event needs to be serialized with data flow, this function will take the
3611 * pad's stream lock while calling its event function.
3613 * To find out whether an event type is upstream, downstream, or downstream and
3614 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
3615 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
3616 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or plugin
3617 * doesn't need to bother itself with this information; the core handles all
3618 * necessary locks and checks.
3620 * Returns: TRUE if the event was handled.
3623 gst_pad_send_event (GstPad * pad, GstEvent * event)
3625 gboolean result = FALSE;
3626 GstPadEventFunction eventfunc;
3627 gboolean emit_signal, serialized;
3629 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3630 g_return_val_if_fail (event != NULL, FALSE);
3632 GST_OBJECT_LOCK (pad);
3633 if (GST_PAD_IS_SINK (pad) && !GST_EVENT_IS_DOWNSTREAM (event))
3634 goto wrong_direction;
3635 if (GST_PAD_IS_SRC (pad) && !GST_EVENT_IS_UPSTREAM (event))
3636 goto wrong_direction;
3638 if (GST_EVENT_SRC (event) == NULL) {
3639 GST_LOG_OBJECT (pad, "event had no source, setting pad as event source");
3640 GST_EVENT_SRC (event) = gst_object_ref (pad);
3643 switch (GST_EVENT_TYPE (event)) {
3644 case GST_EVENT_FLUSH_START:
3645 GST_CAT_DEBUG (GST_CAT_EVENT,
3646 "have event type %d (FLUSH_START) on pad %s:%s",
3647 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3649 /* can't even accept a flush begin event when flushing */
3650 if (GST_PAD_IS_FLUSHING (pad))
3652 GST_PAD_SET_FLUSHING (pad);
3653 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3655 case GST_EVENT_FLUSH_STOP:
3656 GST_PAD_UNSET_FLUSHING (pad);
3657 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3660 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %s on pad %s:%s",
3661 gst_event_type_get_name (GST_EVENT_TYPE (event)),
3662 GST_DEBUG_PAD_NAME (pad));
3664 if (GST_PAD_IS_FLUSHING (pad))
3669 if ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL)
3672 emit_signal = GST_PAD_DO_EVENT_SIGNALS (pad) > 0;
3673 GST_OBJECT_UNLOCK (pad);
3675 /* have to check if it's a sink pad, because e.g. CUSTOM_BOTH is serialized
3676 when going down but not when going up */
3677 serialized = GST_EVENT_IS_SERIALIZED (event) && GST_PAD_IS_SINK (pad);
3679 if (G_UNLIKELY (emit_signal)) {
3680 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3685 GST_PAD_STREAM_LOCK (pad);
3687 result = eventfunc (GST_PAD_CAST (pad), event);
3690 GST_PAD_STREAM_UNLOCK (pad);
3694 /* ERROR handling */
3697 g_warning ("pad %s:%s sending event in wrong direction",
3698 GST_DEBUG_PAD_NAME (pad));
3699 GST_OBJECT_UNLOCK (pad);
3700 gst_event_unref (event);
3705 g_warning ("pad %s:%s has no event handler, file a bug.",
3706 GST_DEBUG_PAD_NAME (pad));
3707 GST_OBJECT_UNLOCK (pad);
3708 gst_event_unref (event);
3713 GST_OBJECT_UNLOCK (pad);
3714 GST_CAT_INFO (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3715 gst_event_unref (event);
3720 GST_DEBUG ("Dropping event after FALSE probe return");
3721 gst_event_unref (event);
3727 * gst_pad_set_element_private:
3728 * @pad: the #GstPad to set the private data of.
3729 * @priv: The private data to attach to the pad.
3731 * Set the given private data gpointer on the pad.
3732 * This function can only be used by the element that owns the pad.
3733 * No locking is performed in this function.
3736 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3738 pad->element_private = priv;
3742 * gst_pad_get_element_private:
3743 * @pad: the #GstPad to get the private data of.
3745 * Gets the private data of a pad.
3746 * No locking is performed in this function.
3748 * Returns: a #gpointer to the private data.
3751 gst_pad_get_element_private (GstPad * pad)
3753 return pad->element_private;
3757 * gst_pad_start_task:
3758 * @pad: the #GstPad to start the task of
3759 * @func: the task function to call
3760 * @data: data passed to the task function
3762 * Starts a task that repeadedly calls @func with @data. This function
3763 * is nostly used in the pad activation function to start the
3764 * dataflow. This function will automatically acauire the STREAM_LOCK of
3765 * the pad before calling @func.
3767 * Returns: a TRUE if the task could be started.
3770 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3774 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3775 g_return_val_if_fail (func != NULL, FALSE);
3777 GST_OBJECT_LOCK (pad);
3778 task = GST_PAD_TASK (pad);
3780 task = gst_task_create (func, data);
3781 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
3782 GST_PAD_TASK (pad) = task;
3784 gst_task_start (task);
3785 GST_OBJECT_UNLOCK (pad);
3791 * gst_pad_pause_task:
3792 * @pad: the #GstPad to pause the task of
3794 * Pause the task of @pad. This function will also make sure that the
3795 * function executed by the task will effectively stop.
3797 * Returns: a TRUE if the task could be paused or FALSE when the pad
3801 gst_pad_pause_task (GstPad * pad)
3805 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3807 GST_OBJECT_LOCK (pad);
3808 task = GST_PAD_TASK (pad);
3811 gst_task_pause (task);
3812 GST_OBJECT_UNLOCK (pad);
3814 GST_PAD_STREAM_LOCK (pad);
3815 GST_PAD_STREAM_UNLOCK (pad);
3821 GST_DEBUG_OBJECT (pad, "pad has no task");
3822 GST_OBJECT_UNLOCK (pad);
3828 * gst_pad_stop_task:
3829 * @pad: the #GstPad to stop the task of
3831 * Stop the task of @pad. This function will also make sure that the
3832 * function executed by the task will effectively stop if not called
3833 * from the GstTaskFunction.
3835 * This function will deadlock if called from the GstTaskFunction of
3836 * the task. Use #gst_task_pause() instead.
3838 * Regardless of whether the pad has a task, the stream lock is acquired and
3839 * released so as to ensure that streaming through this pad has finished.
3841 * Returns: a TRUE if the task could be stopped or FALSE on error.
3844 gst_pad_stop_task (GstPad * pad)
3848 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3850 GST_OBJECT_LOCK (pad);
3851 task = GST_PAD_TASK (pad);
3854 GST_PAD_TASK (pad) = NULL;
3855 gst_task_stop (task);
3856 GST_OBJECT_UNLOCK (pad);
3858 GST_PAD_STREAM_LOCK (pad);
3859 GST_PAD_STREAM_UNLOCK (pad);
3861 gst_task_join (task);
3863 gst_object_unref (task);
3869 GST_OBJECT_UNLOCK (pad);
3871 GST_PAD_STREAM_LOCK (pad);
3872 GST_PAD_STREAM_UNLOCK (pad);