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.
23 #include "gst_private.h"
26 #include "gstenumtypes.h"
27 #include "gstmarshal.h"
33 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
34 #define DEBUG_DATA(obj,data,notice) G_STMT_START{\
36 GST_CAT_DEBUG_OBJECT (debug_dataflow, obj, "NULL data value"); \
37 } else if (GST_IS_EVENT (data)) { \
38 GST_CAT_DEBUG_OBJECT (debug_dataflow, obj, "%s event %p (type %d, refcount %d)", notice, data, \
39 GST_EVENT_TYPE (data), GST_DATA_REFCOUNT_VALUE (data)); \
41 GST_CAT_LOG_OBJECT (debug_dataflow, obj, "%s buffer %p (size %u, refcount %d)", notice, data, \
42 GST_BUFFER_SIZE (data), GST_BUFFER_REFCOUNT_VALUE (data)); \
45 #define GST_CAT_DEFAULT GST_CAT_PADS
54 static GstObject *padtemplate_parent_class = NULL;
55 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
57 /* Pad signals and args */
77 GType _gst_pad_type = 0;
79 static void gst_pad_class_init (GstPadClass * klass);
80 static void gst_pad_init (GstPad * pad);
81 static void gst_pad_dispose (GObject * object);
82 static void gst_pad_finalize (GObject * object);
83 static void gst_pad_set_property (GObject * object, guint prop_id,
84 const GValue * value, GParamSpec * pspec);
85 static void gst_pad_get_property (GObject * object, guint prop_id,
86 GValue * value, GParamSpec * pspec);
88 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
89 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
90 static gboolean gst_pad_activate_default (GstPad * pad);
92 #ifndef GST_DISABLE_LOADSAVE
93 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
96 static GstObjectClass *pad_parent_class = NULL;
97 static guint gst_pad_signals[PAD_LAST_SIGNAL] = { 0 };
100 gst_pad_get_type (void)
102 if (!_gst_pad_type) {
103 static const GTypeInfo pad_info = {
104 sizeof (GstPadClass), NULL, NULL,
105 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
108 (GInstanceInitFunc) gst_pad_init, NULL
111 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
114 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
115 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
117 return _gst_pad_type;
121 _gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
122 GValue * return_accu, const GValue * handler_return, gpointer dummy)
124 gboolean ret = g_value_get_boolean (handler_return);
126 GST_DEBUG ("accumulated %d", ret);
127 g_value_set_boolean (return_accu, ret);
133 default_have_data (GstPad * pad, GstMiniObject * o)
139 gst_pad_class_init (GstPadClass * klass)
141 GObjectClass *gobject_class;
144 GstObjectClass *gstobject_class;
146 gobject_class = (GObjectClass *) klass;
147 gstobject_class = (GstObjectClass *) klass;
149 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
151 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
152 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_pad_finalize);
153 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_pad_set_property);
154 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_pad_get_property);
158 * @pad: the pad that emitted the signal
159 * @peer: the peer pad that has been connected
161 * Signals that a pad has been linked to the peer pad.
163 gst_pad_signals[PAD_LINKED] =
164 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
165 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
166 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
169 * @pad: the pad that emitted the signal
170 * @peer: the peer pad that has been disconnected
172 * Signals that a pad has been unlinked from the peer pad.
174 gst_pad_signals[PAD_UNLINKED] =
175 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
176 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
177 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
179 * GstPad::request-link:
180 * @pad: the pad that emitted the signal
181 * @peer: the peer pad for which a connection is requested
183 * Signals that a pad connection has been requested.
185 gst_pad_signals[PAD_REQUEST_LINK] =
186 g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
187 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
188 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
192 * @pad: the pad that emitted the signal
193 * @mini_obj: new data
195 * Signals that new data is available on the pad. This signal is used
196 * internally for implementing pad probes.
197 * See gst_pad_add_*_probe functions.
199 * Returns: %TRUE to keep the data, %FALSE to drop it
201 gst_pad_signals[PAD_HAVE_DATA] =
202 g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
203 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, have_data),
204 _gst_do_pass_data_accumulator,
205 NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
206 GST_TYPE_MINI_OBJECT);
208 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_CAPS,
209 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
210 GST_TYPE_CAPS, G_PARAM_READABLE));
211 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_DIRECTION,
212 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
213 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
214 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
215 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_TEMPLATE,
216 g_param_spec_object ("template", "Template",
217 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
220 #ifndef GST_DISABLE_LOADSAVE
221 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
223 gstobject_class->path_string_separator = ".";
225 klass->have_data = default_have_data;
229 gst_pad_init (GstPad * pad)
231 pad->direction = GST_PAD_UNKNOWN;
234 pad->chainfunc = NULL;
238 pad->linkfunc = NULL;
239 pad->getcapsfunc = NULL;
241 pad->activatefunc = gst_pad_activate_default;
242 pad->eventfunc = gst_pad_event_default;
243 pad->querytypefunc = gst_pad_get_query_types_default;
244 pad->queryfunc = gst_pad_query_default;
245 pad->intlinkfunc = gst_pad_get_internal_links_default;
247 pad->do_buffer_signals = 0;
248 pad->do_event_signals = 0;
250 GST_PAD_UNSET_FLUSHING (pad);
252 pad->preroll_lock = g_mutex_new ();
253 pad->preroll_cond = g_cond_new ();
255 pad->stream_rec_lock = g_new (GStaticRecMutex, 1);
256 g_static_rec_mutex_init (pad->stream_rec_lock);
258 pad->block_cond = g_cond_new ();
262 gst_pad_dispose (GObject * object)
264 GstPad *pad = GST_PAD (object);
266 gst_pad_set_pad_template (pad, NULL);
267 /* FIXME, we have links to many other things like caps
268 * and the peer pad... */
270 /* No linked pad can ever be disposed.
271 * It has to have a parent to be linked
272 * and a parent would hold a reference */
273 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
274 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
276 g_assert (GST_PAD_PEER (pad) == NULL);
278 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
279 GST_DEBUG_PAD_NAME (pad));
282 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
284 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
285 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
286 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
288 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
291 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
295 gst_pad_finalize (GObject * object)
297 GstPad *pad = GST_PAD (object);
300 /* in case the task is still around, clean it up */
301 if ((task = GST_PAD_TASK (pad))) {
302 gst_task_join (task);
303 GST_PAD_TASK (pad) = NULL;
304 gst_object_unref (task);
307 if (pad->stream_rec_lock) {
308 g_static_rec_mutex_free (pad->stream_rec_lock);
309 g_free (pad->stream_rec_lock);
310 pad->stream_rec_lock = NULL;
312 if (pad->preroll_lock) {
313 g_mutex_free (pad->preroll_lock);
314 g_cond_free (pad->preroll_cond);
315 pad->preroll_lock = NULL;
316 pad->preroll_cond = NULL;
318 if (pad->block_cond) {
319 g_cond_free (pad->block_cond);
320 pad->block_cond = NULL;
323 G_OBJECT_CLASS (pad_parent_class)->finalize (object);
327 gst_pad_set_property (GObject * object, guint prop_id,
328 const GValue * value, GParamSpec * pspec)
330 g_return_if_fail (GST_IS_PAD (object));
333 case PAD_PROP_DIRECTION:
334 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
336 case PAD_PROP_TEMPLATE:
337 gst_pad_set_pad_template (GST_PAD_CAST (object),
338 (GstPadTemplate *) g_value_dup_object (value));
341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
347 gst_pad_get_property (GObject * object, guint prop_id,
348 GValue * value, GParamSpec * pspec)
350 g_return_if_fail (GST_IS_PAD (object));
354 g_value_set_boxed (value, GST_PAD_CAPS (object));
356 case PAD_PROP_DIRECTION:
357 g_value_set_enum (value, GST_PAD_DIRECTION (object));
359 case PAD_PROP_TEMPLATE:
360 g_value_set_object (value, GST_PAD_TEMPLATE (object));
363 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
370 * @name: the name of the new pad.
371 * @direction: the #GstPadDirection of the pad.
373 * Creates a new pad with the given name in the given direction.
374 * If name is NULL, a guaranteed unique name (across all pads)
376 * This function makes a copy of the name so you can safely free the name.
378 * Returns: a new #GstPad, or NULL in case of an error.
383 gst_pad_new (const gchar * name, GstPadDirection direction)
385 return g_object_new (GST_TYPE_PAD,
386 "name", name, "direction", direction, NULL);
390 * gst_pad_new_from_template:
391 * @templ: the pad template to use
392 * @name: the name of the element
394 * Creates a new pad with the given name from the given template.
395 * If name is NULL, a guaranteed unique name (across all pads)
397 * This function makes a copy of the name so you can safely free the name.
399 * Returns: a new #GstPad, or NULL in case of an error.
402 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
404 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
406 return g_object_new (GST_TYPE_PAD,
407 "name", name, "direction", templ->direction, "template", templ, NULL);
411 * gst_pad_get_direction:
412 * @pad: a #GstPad to get the direction of.
414 * Gets the direction of the pad. The direction of the pad is
415 * decided at construction time so this function does not take
418 * Returns: the #GstPadDirection of the pad.
423 gst_pad_get_direction (GstPad * pad)
425 GstPadDirection result;
427 /* PAD_UNKNOWN is a little silly but we need some sort of
428 * error return value */
429 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
432 result = GST_PAD_DIRECTION (pad);
439 gst_pad_activate_default (GstPad * pad)
441 return gst_pad_activate_push (pad, TRUE);
445 pre_activate_switch (GstPad * pad, gboolean new_active)
451 GST_PAD_SET_FLUSHING (pad);
452 /* unlock blocked pads so element can resume and stop */
453 GST_PAD_BLOCK_SIGNAL (pad);
459 post_activate_switch (GstPad * pad, gboolean new_active)
463 GST_PAD_UNSET_FLUSHING (pad);
466 /* make streaming stop */
467 GST_STREAM_LOCK (pad);
468 GST_STREAM_UNLOCK (pad);
473 * gst_pad_set_active:
474 * @pad: the #GstPad to activate or deactivate.
475 * @active: whether or not the pad should be active.
477 * Activates or deactivates the given pad. Must be called with the STATE_LOCK.
478 * Normally called from within core state change functions.
480 * If @active, makes sure the pad is active. If it is already active, either in
481 * push or pull mode, just return. Otherwise dispatches to the pad's activate
482 * function to perform the actual activation.
484 * If not @active, checks the pad's current mode and calls
485 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
488 * Returns: TRUE if the operation was successfull.
490 * MT safe. Must be called with STATE_LOCK.
493 gst_pad_set_active (GstPad * pad, gboolean active)
496 gboolean ret = FALSE;
498 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
501 old = GST_PAD_ACTIVATE_MODE (pad);
506 case GST_ACTIVATE_PUSH:
507 case GST_ACTIVATE_PULL:
510 case GST_ACTIVATE_NONE:
511 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
516 case GST_ACTIVATE_PUSH:
517 ret = gst_pad_activate_push (pad, FALSE);
519 case GST_ACTIVATE_PULL:
520 ret = gst_pad_activate_pull (pad, FALSE);
522 case GST_ACTIVATE_NONE:
532 * gst_pad_activate_pull:
533 * @pad: the #GstPad to activate or deactivate.
534 * @active: whether or not the pad should be active.
536 * Activates or deactivates the given pad in pull mode via dispatching to the
537 * pad's activatepullfunc. For use from within pad activation functions only.
538 * When called on sink pads, will first proxy the call to the peer pad, which is
539 * expected to activate its internally linked pads from within its activate_pull
542 * If you don't know what this is, you probably don't want to call it.
544 * Returns: TRUE if the operation was successfull.
549 gst_pad_activate_pull (GstPad * pad, gboolean active)
553 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
556 old = GST_PAD_ACTIVATE_MODE (pad);
559 if ((active && old == GST_ACTIVATE_PULL)
560 || (!active && old == GST_ACTIVATE_NONE))
564 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
566 g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE);
569 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
570 GstPad *peer = gst_pad_get_peer (pad);
573 if (!gst_pad_activate_pull (peer, active)) {
575 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
576 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
578 gst_object_unref (peer);
584 pre_activate_switch (pad, active);
586 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
587 if (GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)) {
593 /* can happen for sinks of passthrough elements */
599 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
600 active ? "activated" : "deactivated");
607 GST_PAD_ACTIVATE_MODE (pad) =
608 active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
610 post_activate_switch (pad, active);
612 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
613 active ? "activated" : "deactivated");
619 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
620 active ? "activate" : "deactivate");
626 * gst_pad_activate_push:
627 * @pad: the #GstPad to activate or deactivate.
628 * @active: whether or not the pad should be active.
630 * Activates or deactivates the given pad in push mode via dispatching to the
631 * pad's activatepushfunc. For use from within pad activation functions only.
633 * If you don't know what this is, you probably don't want to call it.
635 * Returns: TRUE if the operation was successfull.
640 gst_pad_activate_push (GstPad * pad, gboolean active)
644 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
645 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
646 active ? "activated" : "deactivated");
649 old = GST_PAD_ACTIVATE_MODE (pad);
652 if ((active && old == GST_ACTIVATE_PUSH)
653 || (!active && old == GST_ACTIVATE_NONE))
657 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
659 g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE);
662 pre_activate_switch (pad, active);
664 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
665 if (GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) {
671 /* quite ok, element relies on state change func to prepare itself */
677 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
678 active ? "activated" : "deactivated");
685 GST_PAD_ACTIVATE_MODE (pad) =
686 active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
688 post_activate_switch (pad, active);
690 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
691 active ? "activated" : "deactivated");
697 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
698 active ? "activate" : "deactivate");
705 * @pad: the #GstPad to query
707 * Query if a pad is active
709 * Returns: TRUE if the pad is active.
714 gst_pad_is_active (GstPad * pad)
716 gboolean result = FALSE;
718 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
721 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
728 * gst_pad_set_blocked_async:
729 * @pad: the #GstPad to block or unblock
730 * @blocked: boolean indicating we should block or unblock
731 * @callback: #GstPadBlockCallback that will be called when the
732 * operation succeeds.
733 * @user_data: user data passed to the callback
735 * Blocks or unblocks the dataflow on a pad. The provided callback
736 * is called when the operation succeeds. This can take a while as
737 * the pad can only become blocked when real dataflow is happening.
738 * When the pipeline is stalled, for example in PAUSED, this can
739 * take an indeterminate amount of time.
740 * You can pass NULL as the callback to make this call block. Be
741 * carefull with this blocking call as it might not return for
742 * reasons stated above.
744 * Returns: TRUE if the pad could be blocked. This function can fail
745 * if wrong parameters were passed or the pad was already in the
751 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
752 GstPadBlockCallback callback, gpointer user_data)
754 gboolean was_blocked;
756 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
760 was_blocked = GST_PAD_IS_BLOCKED (pad);
762 if (G_UNLIKELY (was_blocked == blocked))
763 goto had_right_state;
766 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad %s:%s",
767 GST_DEBUG_PAD_NAME (pad));
769 GST_FLAG_SET (pad, GST_PAD_BLOCKED);
770 pad->block_callback = callback;
771 pad->block_data = user_data;
773 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
774 GST_PAD_BLOCK_WAIT (pad);
775 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
778 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad %s:%s",
779 GST_DEBUG_PAD_NAME (pad));
781 GST_FLAG_UNSET (pad, GST_PAD_BLOCKED);
783 pad->block_callback = callback;
784 pad->block_data = user_data;
787 GST_PAD_BLOCK_SIGNAL (pad);
789 GST_PAD_BLOCK_SIGNAL (pad);
790 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
791 GST_PAD_BLOCK_WAIT (pad);
792 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
801 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
802 "pad %s:%s was in right state", GST_DEBUG_PAD_NAME (pad));
809 * gst_pad_set_blocked:
810 * @pad: the #GstPad to block or unblock
811 * @blocked: boolean indicating we should block or unblock
813 * Blocks or unblocks the dataflow on a pad. This function is
814 * a shortcut for @gst_pad_set_blocked_async() with a NULL
817 * Returns: TRUE if the pad could be blocked. This function can fail
818 * wrong parameters were passed or the pad was already in the
824 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
826 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
830 * gst_pad_is_blocked:
831 * @pad: the #GstPad to query
833 * Checks if the pad is blocked or not. This function returns the
834 * last requested state of the pad. It is not certain that the pad
835 * is actually blocked at this point.
837 * Returns: TRUE if the pad is blocked.
842 gst_pad_is_blocked (GstPad * pad)
844 gboolean result = FALSE;
846 g_return_val_if_fail (GST_IS_PAD (pad), result);
849 result = GST_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
856 * gst_pad_set_activate_function:
857 * @pad: a sink #GstPad.
858 * @activate: the #GstPadActivateFunction to set.
860 * Sets the given activate function for the pad. The activate function will
861 * dispatch to activate_push or activate_pull to perform the actual activation.
862 * Only makes sense to set on sink pads.
864 * Call this function if your sink pad can start a pull-based task.
867 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
869 g_return_if_fail (GST_IS_PAD (pad));
871 GST_PAD_ACTIVATEFUNC (pad) = activate;
872 GST_CAT_DEBUG (GST_CAT_PADS, "activatefunc for %s:%s set to %s",
873 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activate));
877 * gst_pad_set_activatepull_function:
878 * @pad: a sink #GstPad.
879 * @activatepull: the #GstPadActivateModeFunction to set.
881 * Sets the given activate_pull function for the pad. An activate_pull function
882 * prepares the element and any upstream connections for pulling. See XXX
883 * part-activation.txt for details.
886 gst_pad_set_activatepull_function (GstPad * pad,
887 GstPadActivateModeFunction activatepull)
889 g_return_if_fail (GST_IS_PAD (pad));
891 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
892 GST_CAT_DEBUG (GST_CAT_PADS, "activatepullfunc for %s:%s set to %s",
893 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepull));
897 * gst_pad_set_activatepush_function:
898 * @pad: a sink #GstPad.
899 * @activatepush: the #GstPadActivateModeFunction to set.
901 * Sets the given activate_push function for the pad. An activate_push function
902 * prepares the element for pushing. See XXX part-activation.txt for details.
905 gst_pad_set_activatepush_function (GstPad * pad,
906 GstPadActivateModeFunction activatepush)
908 g_return_if_fail (GST_IS_PAD (pad));
910 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
911 GST_CAT_DEBUG (GST_CAT_PADS, "activatepushfunc for %s:%s set to %s",
912 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepush));
916 * gst_pad_set_chain_function:
917 * @pad: a sink #GstPad.
918 * @chain: the #GstPadChainFunction to set.
920 * Sets the given chain function for the pad. The chain function is called to
921 * process a #GstBuffer input buffer.
924 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
926 g_return_if_fail (GST_IS_PAD (pad));
927 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
929 GST_PAD_CHAINFUNC (pad) = chain;
930 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
931 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
935 * gst_pad_set_getrange_function:
936 * @pad: a source #GstPad.
937 * @get: the #GstPadGetRangeFunction to set.
939 * Sets the given getrange function for the pad. The getrange function is called to
940 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
944 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
946 g_return_if_fail (GST_IS_PAD (pad));
947 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
949 GST_PAD_GETRANGEFUNC (pad) = get;
951 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
952 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
956 * gst_pad_set_checkgetrange_function:
957 * @pad: a source #GstPad.
958 * @check: the #GstPadCheckGetRangeFunction to set.
960 * Sets the given checkgetrange function for the pad. Implement this function on
961 * a pad if you dynamically support getrange based scheduling on the pad.
964 gst_pad_set_checkgetrange_function (GstPad * pad,
965 GstPadCheckGetRangeFunction check)
967 g_return_if_fail (GST_IS_PAD (pad));
968 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
970 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
972 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
973 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
977 * gst_pad_set_event_function:
978 * @pad: a source #GstPad.
979 * @event: the #GstPadEventFunction to set.
981 * Sets the given event handler for the pad.
984 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
986 g_return_if_fail (GST_IS_PAD (pad));
988 GST_PAD_EVENTFUNC (pad) = event;
990 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
991 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
995 * gst_pad_set_query_function:
996 * @pad: a #GstPad of either direction.
997 * @query: the #GstPadQueryFunction to set.
999 * Set the given query function for the pad.
1002 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1004 g_return_if_fail (GST_IS_PAD (pad));
1006 GST_PAD_QUERYFUNC (pad) = query;
1008 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
1009 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
1013 * gst_pad_set_query_type_function:
1014 * @pad: a #GstPad of either direction.
1015 * @type_func: the #GstPadQueryTypeFunction to set.
1017 * Set the given query type function for the pad.
1020 gst_pad_set_query_type_function (GstPad * pad,
1021 GstPadQueryTypeFunction type_func)
1023 g_return_if_fail (GST_IS_PAD (pad));
1025 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1027 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
1028 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
1032 * gst_pad_get_query_types:
1035 * Get an array of supported queries that can be performed
1038 * Returns: a zero-terminated array of #GstQueryType.
1040 const GstQueryType *
1041 gst_pad_get_query_types (GstPad * pad)
1043 GstPadQueryTypeFunction func;
1045 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1047 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1059 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1061 *data = gst_pad_get_query_types (pad);
1067 * gst_pad_get_query_types_default:
1070 * Invoke the default dispatcher for the query types on
1073 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1074 * internally-linked pads has a query types function.
1076 const GstQueryType *
1077 gst_pad_get_query_types_default (GstPad * pad)
1079 GstQueryType *result = NULL;
1081 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1083 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1084 gst_pad_get_query_types_dispatcher, &result);
1090 * gst_pad_set_internal_link_function:
1091 * @pad: a #GstPad of either direction.
1092 * @intlink: the #GstPadIntLinkFunction to set.
1094 * Sets the given internal link function for the pad.
1097 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1099 g_return_if_fail (GST_IS_PAD (pad));
1101 GST_PAD_INTLINKFUNC (pad) = intlink;
1102 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1103 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1107 * gst_pad_set_link_function:
1109 * @link: the #GstPadLinkFunction to set.
1111 * Sets the given link function for the pad. It will be called when the pad is
1112 * linked or relinked with caps. The caps passed to the link function is
1113 * the caps for the connnection. It can contain a non fixed caps.
1115 * The return value GST_PAD_LINK_OK should be used when the connection can be
1118 * The return value GST_PAD_LINK_REFUSED should be used when the connection
1119 * cannot be made for some reason.
1122 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1124 g_return_if_fail (GST_IS_PAD (pad));
1126 GST_PAD_LINKFUNC (pad) = link;
1127 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1128 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1132 * gst_pad_set_unlink_function:
1134 * @unlink: the #GstPadUnlinkFunction to set.
1136 * Sets the given unlink function for the pad. It will be called
1137 * when the pad is unlinked.
1140 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1142 g_return_if_fail (GST_IS_PAD (pad));
1144 GST_PAD_UNLINKFUNC (pad) = unlink;
1145 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1146 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1150 * gst_pad_set_getcaps_function:
1152 * @getcaps: the #GstPadGetCapsFunction to set.
1154 * Sets the given getcaps function for the pad. @getcaps should return the
1155 * allowable caps for a pad in the context of the element's state, its link to
1156 * other elements, and the devices or files it has opened. These caps must be a
1157 * subset of the pad template caps. In the NULL state with no links, @getcaps
1158 * should ideally return the same caps as the pad template. In rare
1159 * circumstances, an object property can affect the caps returned by @getcaps,
1160 * but this is discouraged.
1162 * You do not need to call this function if @pad's allowed caps are always the
1163 * same as the pad template caps. This can only be true if the padtemplate
1164 * has fixed simple caps.
1166 * For most filters, the caps returned by @getcaps is directly affected by the
1167 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1168 * the srcpad's getcaps function is directly related to the stream data. Again,
1169 * @getcaps should return the most specific caps it reasonably can, since this
1170 * helps with autoplugging.
1172 * Note that the return value from @getcaps is owned by the caller, so the caller
1173 * should unref the caps after usage.
1176 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1178 g_return_if_fail (GST_IS_PAD (pad));
1180 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1181 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1182 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1186 * gst_pad_set_acceptcaps_function:
1188 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1190 * Sets the given acceptcaps function for the pad. The acceptcaps function
1191 * will be called to check if the pad can accept the given caps.
1194 gst_pad_set_acceptcaps_function (GstPad * pad,
1195 GstPadAcceptCapsFunction acceptcaps)
1197 g_return_if_fail (GST_IS_PAD (pad));
1199 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1200 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1201 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1205 * gst_pad_set_fixatecaps_function:
1207 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1209 * Sets the given fixatecaps function for the pad. The fixatecaps function
1210 * will be called whenever the default values for a GstCaps needs to be
1214 gst_pad_set_fixatecaps_function (GstPad * pad,
1215 GstPadFixateCapsFunction fixatecaps)
1217 g_return_if_fail (GST_IS_PAD (pad));
1219 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1220 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1221 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1225 * gst_pad_set_setcaps_function:
1227 * @setcaps: the #GstPadSetCapsFunction to set.
1229 * Sets the given setcaps function for the pad. The setcaps function
1230 * will be called whenever a buffer with a new media type is pushed or
1231 * pulled from the pad. The pad/element needs to update it's internal
1232 * structures to process the new media type. If this new type is not
1233 * acceptable, the setcaps function should return FALSE.
1236 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1238 g_return_if_fail (GST_IS_PAD (pad));
1240 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1241 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1242 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1246 * gst_pad_set_bufferalloc_function:
1247 * @pad: a sink #GstPad.
1248 * @bufalloc: the #GstPadBufferAllocFunction to set.
1250 * Sets the given bufferalloc function for the pad. Note that the
1251 * bufferalloc function can only be set on sinkpads.
1254 gst_pad_set_bufferalloc_function (GstPad * pad,
1255 GstPadBufferAllocFunction bufalloc)
1257 g_return_if_fail (GST_IS_PAD (pad));
1258 g_return_if_fail (GST_PAD_IS_SINK (pad));
1260 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1261 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1262 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1267 * @srcpad: the source #GstPad to unlink.
1268 * @sinkpad: the sink #GstPad to unlink.
1270 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1273 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1274 * the pads were not linked together.
1279 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1281 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1282 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1284 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1285 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1286 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1290 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1295 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1298 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1299 goto not_linked_together;
1301 if (GST_PAD_UNLINKFUNC (srcpad)) {
1302 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1304 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1305 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1308 /* first clear peers */
1309 GST_PAD_PEER (srcpad) = NULL;
1310 GST_PAD_PEER (sinkpad) = NULL;
1312 GST_UNLOCK (sinkpad);
1313 GST_UNLOCK (srcpad);
1315 /* fire off a signal to each of the pads telling them
1316 * that they've been unlinked */
1317 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1318 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1320 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1321 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1327 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1328 GST_UNLOCK (srcpad);
1333 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1334 GST_UNLOCK (sinkpad);
1335 GST_UNLOCK (srcpad);
1338 not_linked_together:
1340 /* we do not emit a warning in this case because unlinking cannot
1341 * be made MT safe.*/
1342 GST_UNLOCK (sinkpad);
1343 GST_UNLOCK (srcpad);
1349 * gst_pad_is_linked:
1350 * @pad: pad to check
1352 * Checks if a @pad is linked to another pad or not.
1354 * Returns: TRUE if the pad is linked, FALSE otherwise.
1359 gst_pad_is_linked (GstPad * pad)
1363 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1366 result = (GST_PAD_PEER (pad) != NULL);
1372 /* get the caps from both pads and see if the intersection
1375 * This function should be called with the pad LOCK on both
1379 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1384 srccaps = gst_pad_get_caps_unlocked (src);
1385 sinkcaps = gst_pad_get_caps_unlocked (sink);
1386 GST_CAT_DEBUG (GST_CAT_CAPS, " src caps %" GST_PTR_FORMAT, srccaps);
1387 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1389 /* if we have caps on both pads we can check the intersection */
1390 if (srccaps && sinkcaps) {
1393 icaps = gst_caps_intersect (srccaps, sinkcaps);
1394 gst_caps_unref (srccaps);
1395 gst_caps_unref (sinkcaps);
1397 GST_CAT_DEBUG (GST_CAT_CAPS,
1398 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1400 if (!icaps || gst_caps_is_empty (icaps)) {
1401 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is empty");
1402 gst_caps_unref (icaps);
1405 gst_caps_unref (icaps);
1411 /* check if the grandparents of both pads are the same.
1412 * This check is required so that we don't try to link
1413 * pads from elements in different bins without ghostpads.
1415 * The LOCK should be helt on both pads
1418 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1420 GstObject *psrc, *psink;
1421 gboolean res = TRUE;
1423 psrc = GST_OBJECT_PARENT (src);
1424 psink = GST_OBJECT_PARENT (sink);
1426 /* if one of the pads has no parent, we allow the link */
1427 if (psrc && psink) {
1428 /* if the parents are the same, we have a loop */
1429 if (psrc == psink) {
1430 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1435 /* if they both have a parent, we check the grandparents */
1436 psrc = gst_object_get_parent (psrc);
1437 psink = gst_object_get_parent (psink);
1439 if (psrc != psink) {
1440 /* if they have grandparents but they are not the same */
1441 GST_CAT_DEBUG (GST_CAT_CAPS,
1442 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1443 GST_PTR_FORMAT, psrc, psink);
1447 gst_object_unref (psrc);
1449 gst_object_unref (psink);
1455 /* FIXME leftover from an attempt at refactoring... */
1456 /* call with the two pads unlocked */
1457 static GstPadLinkReturn
1458 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1460 /* generic checks */
1461 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1462 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1464 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1465 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1469 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1472 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1473 goto src_was_linked;
1477 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1480 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1481 goto sink_was_linked;
1483 /* check hierarchy, pads can only be linked if the grandparents
1485 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1486 goto wrong_hierarchy;
1488 /* check pad caps for non-empty intersection */
1489 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1492 /* FIXME check pad scheduling for non-empty intersection */
1494 return GST_PAD_LINK_OK;
1498 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1499 GST_UNLOCK (srcpad);
1500 return GST_PAD_LINK_WRONG_DIRECTION;
1504 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was linked",
1505 GST_DEBUG_PAD_NAME (srcpad));
1506 /* we do not emit a warning in this case because unlinking cannot
1507 * be made MT safe.*/
1508 GST_UNLOCK (srcpad);
1509 return GST_PAD_LINK_WAS_LINKED;
1513 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1514 GST_UNLOCK (sinkpad);
1515 GST_UNLOCK (srcpad);
1516 return GST_PAD_LINK_WRONG_DIRECTION;
1520 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was linked",
1521 GST_DEBUG_PAD_NAME (sinkpad));
1522 /* we do not emit a warning in this case because unlinking cannot
1523 * be made MT safe.*/
1524 GST_UNLOCK (sinkpad);
1525 GST_UNLOCK (srcpad);
1526 return GST_PAD_LINK_WAS_LINKED;
1530 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1531 GST_UNLOCK (sinkpad);
1532 GST_UNLOCK (srcpad);
1533 return GST_PAD_LINK_WRONG_HIERARCHY;
1537 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1538 GST_UNLOCK (sinkpad);
1539 GST_UNLOCK (srcpad);
1540 return GST_PAD_LINK_NOFORMAT;
1546 * @srcpad: the source #GstPad to link.
1547 * @sinkpad: the sink #GstPad to link.
1549 * Links the source pad and the sink pad.
1551 * Returns: A result code indicating if the connection worked or
1557 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1559 GstPadLinkReturn result;
1561 /* prepare will also lock the two pads */
1562 result = gst_pad_link_prepare (srcpad, sinkpad);
1564 if (result != GST_PAD_LINK_OK)
1565 goto prepare_failed;
1567 GST_UNLOCK (sinkpad);
1568 GST_UNLOCK (srcpad);
1570 /* FIXME released the locks here, concurrent thread might link
1571 * something else. */
1572 if (GST_PAD_LINKFUNC (srcpad)) {
1573 /* this one will call the peer link function */
1574 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1575 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1576 /* if no source link function, we need to call the sink link
1577 * function ourselves. */
1578 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1580 result = GST_PAD_LINK_OK;
1586 if (result == GST_PAD_LINK_OK) {
1587 GST_PAD_PEER (srcpad) = sinkpad;
1588 GST_PAD_PEER (sinkpad) = srcpad;
1590 GST_UNLOCK (sinkpad);
1591 GST_UNLOCK (srcpad);
1593 /* fire off a signal to each of the pads telling them
1594 * that they've been linked */
1595 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1596 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1598 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1599 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1601 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1602 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1604 GST_UNLOCK (sinkpad);
1605 GST_UNLOCK (srcpad);
1616 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1618 /* this function would need checks if it weren't static */
1621 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1625 gst_object_sink (GST_OBJECT (templ));
1626 g_signal_emit (G_OBJECT (templ),
1627 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1632 * gst_pad_get_pad_template:
1635 * Gets the template for @pad.
1637 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1638 * if this pad has no template.
1640 * FIXME: currently returns an unrefcounted padtemplate.
1643 gst_pad_get_pad_template (GstPad * pad)
1645 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1647 return GST_PAD_PAD_TEMPLATE (pad);
1651 /* should be called with the pad LOCK held */
1652 /* refs the caps, so caller is responsible for getting it unreffed */
1654 gst_pad_get_caps_unlocked (GstPad * pad)
1656 GstCaps *result = NULL;
1658 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1659 GST_DEBUG_PAD_NAME (pad), pad);
1661 if (GST_PAD_GETCAPSFUNC (pad)) {
1662 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1664 GST_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1666 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1668 GST_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1670 if (result == NULL) {
1671 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1672 GST_DEBUG_PAD_NAME (pad));
1674 GST_CAT_DEBUG (GST_CAT_CAPS,
1675 "pad getcaps %s:%s returned %" GST_PTR_FORMAT,
1676 GST_DEBUG_PAD_NAME (pad), result);
1677 #ifndef G_DISABLE_ASSERT
1678 /* check that the returned caps are a real subset of the template caps */
1679 if (GST_PAD_PAD_TEMPLATE (pad)) {
1680 const GstCaps *templ_caps =
1681 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1682 if (!gst_caps_is_subset (result, templ_caps)) {
1685 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1686 "pad returned caps %" GST_PTR_FORMAT
1687 " which are not a real subset of its template caps %"
1688 GST_PTR_FORMAT, result, templ_caps);
1690 ("pad %s:%s returned caps that are not a real subset of its template caps",
1691 GST_DEBUG_PAD_NAME (pad));
1692 temp = gst_caps_intersect (templ_caps, result);
1693 gst_caps_unref (result);
1701 if (GST_PAD_PAD_TEMPLATE (pad)) {
1702 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1704 result = GST_PAD_TEMPLATE_CAPS (templ);
1705 GST_CAT_DEBUG (GST_CAT_CAPS,
1706 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1709 result = gst_caps_ref (result);
1712 if (GST_PAD_CAPS (pad)) {
1713 result = GST_PAD_CAPS (pad);
1715 GST_CAT_DEBUG (GST_CAT_CAPS,
1716 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1718 result = gst_caps_ref (result);
1722 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1723 result = gst_caps_new_empty ();
1731 * @pad: a #GstPad to get the capabilities of.
1733 * Gets the capabilities this pad can produce or consume.
1734 * Note that this method doesn't necessarily returns the caps set by
1735 * #gst_pad_set_caps - use #GST_PAD_CAPS for that instead.
1736 * gst_pad_get_caps returns all possible caps a pad can operate with, using
1737 * the pad's get_caps function;
1738 * this returns the pad template caps if not explicitly set.
1740 * Returns: a newly allocated copy of the #GstCaps of this pad.
1745 gst_pad_get_caps (GstPad * pad)
1747 GstCaps *result = NULL;
1749 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1753 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1754 GST_DEBUG_PAD_NAME (pad), pad);
1756 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (pad)))
1757 goto was_dispatching;
1759 result = gst_pad_get_caps_unlocked (pad);
1766 GST_CAT_DEBUG (GST_CAT_CAPS,
1767 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1768 g_warning ("pad %s:%s recursively called getcaps!",
1769 GST_DEBUG_PAD_NAME (pad));
1776 * gst_pad_peer_get_caps:
1777 * @pad: a #GstPad to get the peer capabilities of.
1779 * Gets the capabilities of the peer connected to this pad.
1781 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1782 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1783 * peer pad or when this function is called recursively from a getcaps function.
1786 gst_pad_peer_get_caps (GstPad * pad)
1789 GstCaps *result = NULL;
1791 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1795 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1796 GST_DEBUG_PAD_NAME (pad), pad);
1798 peerpad = GST_PAD_PEER (pad);
1799 if (G_UNLIKELY (peerpad == NULL))
1802 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (peerpad)))
1803 goto was_dispatching;
1805 gst_object_ref (peerpad);
1808 result = gst_pad_get_caps (peerpad);
1810 gst_object_unref (peerpad);
1821 GST_CAT_DEBUG (GST_CAT_CAPS,
1822 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1823 g_warning ("pad %s:%s recursively called getcaps!",
1824 GST_DEBUG_PAD_NAME (pad));
1831 fixate_value (GValue * dest, const GValue * src)
1833 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
1834 g_value_init (dest, G_TYPE_INT);
1835 g_value_set_int (dest, gst_value_get_int_range_min (src));
1836 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
1837 g_value_init (dest, G_TYPE_DOUBLE);
1838 g_value_set_double (dest, gst_value_get_double_range_min (src));
1839 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1840 GValue temp = { 0 };
1842 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
1843 if (!fixate_value (dest, &temp))
1844 gst_value_init_and_copy (dest, &temp);
1845 g_value_unset (&temp);
1846 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
1847 gboolean res = FALSE;
1850 g_value_init (dest, GST_TYPE_ARRAY);
1851 for (n = 0; n < gst_value_list_get_size (src); n++) {
1853 const GValue *orig_kid = gst_value_list_get_value (src, n);
1855 if (!fixate_value (&kid, orig_kid))
1856 gst_value_init_and_copy (&kid, orig_kid);
1859 gst_value_list_append_value (dest, &kid);
1860 g_value_unset (&kid);
1864 g_value_unset (dest);
1875 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
1877 GstStructure *s = data;
1880 if (fixate_value (&v, value)) {
1881 gst_structure_id_set_value (s, field_id, &v);
1889 * gst_pad_fixate_caps:
1890 * @pad: a #GstPad to fixate
1891 * @caps: the #GstCaps to fixate
1893 * Fixate a caps on the given pad. Modifies the caps in place, so you should
1894 * make sure that the caps are actually writable (see gst_caps_make_writable()).
1897 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
1899 GstPadFixateCapsFunction fixatefunc;
1902 g_return_if_fail (GST_IS_PAD (pad));
1903 g_return_if_fail (caps != NULL);
1905 if (gst_caps_is_fixed (caps))
1908 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
1910 fixatefunc (pad, caps);
1913 /* default fixation */
1914 for (n = 0; n < gst_caps_get_size (caps); n++) {
1915 GstStructure *s = gst_caps_get_structure (caps, n);
1917 gst_structure_foreach (s, gst_pad_default_fixate, s);
1922 * gst_pad_accept_caps:
1923 * @pad: a #GstPad to check
1925 * Check if the given pad accepts the caps.
1927 * Returns: TRUE if the pad can accept the caps.
1930 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
1933 GstPadAcceptCapsFunction acceptfunc;
1935 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1937 /* any pad can be unnegotiated */
1942 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
1944 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
1945 GST_DEBUG_PAD_NAME (pad), pad);
1949 /* we can call the function */
1950 result = acceptfunc (pad, caps);
1952 /* else see get the caps and see if it intersects to something
1957 allowed = gst_pad_get_caps (pad);
1959 intersect = gst_caps_intersect (allowed, caps);
1961 result = !gst_caps_is_empty (intersect);
1963 gst_caps_unref (allowed);
1964 gst_caps_unref (intersect);
1973 * gst_pad_peer_accept_caps:
1974 * @pad: a #GstPad to check
1976 * Check if the given pad accepts the caps.
1978 * Returns: TRUE if the pad can accept the caps.
1981 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
1986 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1990 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
1991 GST_DEBUG_PAD_NAME (pad), pad);
1993 peerpad = GST_PAD_PEER (pad);
1994 if (G_UNLIKELY (peerpad == NULL))
1997 result = gst_pad_accept_caps (peerpad, caps);
2011 * @pad: a #GstPad to set the capabilities of.
2012 * @caps: a #GstCaps to set.
2014 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2015 * caps on the pad will be unreffed. This function refs the caps so you should
2016 * unref if as soon as you don't need it anymore.
2017 * It is possible to set NULL caps, which will make the pad unnegotiated
2020 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2021 * or bad parameters were provided to this function.
2026 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2028 GstPadSetCapsFunction setcaps;
2031 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2032 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2035 setcaps = GST_PAD_SETCAPSFUNC (pad);
2037 existing = GST_PAD_CAPS (pad);
2038 if (caps == existing)
2039 goto setting_same_caps;
2040 else if (caps && existing && gst_caps_is_equal (caps, existing))
2041 goto setting_same_caps;
2043 /* call setcaps function to configure the pad */
2044 if (setcaps != NULL && caps) {
2045 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2046 GST_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2048 if (!setcaps (pad, caps))
2051 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2053 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
2054 GST_DEBUG_PAD_NAME (pad));
2058 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2059 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
2060 GST_DEBUG_PAD_NAME (pad), caps);
2063 g_object_notify (G_OBJECT (pad), "caps");
2070 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2071 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2072 "caps %" GST_PTR_FORMAT " same as existing, updating ptr only", caps);
2079 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2080 GST_CAT_DEBUG (GST_CAT_CAPS,
2081 "pad %s:%s, caps %" GST_PTR_FORMAT " could not be set",
2082 GST_DEBUG_PAD_NAME (pad), caps);
2090 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2092 GstPadAcceptCapsFunction acceptcaps;
2093 GstPadSetCapsFunction setcaps;
2096 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2097 setcaps = GST_PAD_SETCAPSFUNC (pad);
2099 /* See if pad accepts the caps, by calling acceptcaps, only
2100 * needed if no setcaps function */
2101 if (setcaps == NULL && acceptcaps != NULL) {
2102 if (!acceptcaps (pad, caps))
2105 /* set caps on pad if call succeeds */
2106 res = gst_pad_set_caps (pad, caps);
2107 /* no need to unref the caps here, set_caps takes a ref and
2108 * our ref goes away when we leave this function. */
2114 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2119 /* returns TRUE if the src pad could be configured to accept the given caps */
2121 gst_pad_configure_src (GstPad * pad, GstCaps * caps)
2123 GstPadAcceptCapsFunction acceptcaps;
2124 GstPadSetCapsFunction setcaps;
2127 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2128 setcaps = GST_PAD_SETCAPSFUNC (pad);
2130 /* See if pad accepts the caps, by calling acceptcaps, only
2131 * needed if no setcaps function */
2132 if (setcaps == NULL && acceptcaps != NULL) {
2133 if (!acceptcaps (pad, caps))
2136 /* set caps on pad if call succeeds */
2137 res = gst_pad_set_caps (pad, caps);
2138 /* no need to unref the caps here, set_caps takes a ref and
2139 * our ref goes away when we leave this function. */
2145 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2151 * gst_pad_get_pad_template_caps:
2152 * @pad: a #GstPad to get the template capabilities from.
2154 * Gets the capabilities for @pad's template.
2156 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2157 * on the caps, make a copy (see gst_caps_copy ()).
2160 gst_pad_get_pad_template_caps (GstPad * pad)
2162 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2164 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2166 if (GST_PAD_PAD_TEMPLATE (pad))
2167 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2169 return gst_static_caps_get (&anycaps);
2175 * @pad: a #GstPad to get the peer of.
2177 * Gets the peer of @pad. This function refs the peer pad so
2178 * you need to unref it after use.
2180 * Returns: the peer #GstPad. Unref after usage.
2185 gst_pad_get_peer (GstPad * pad)
2189 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2192 result = GST_PAD_PEER (pad);
2194 gst_object_ref (result);
2201 * gst_pad_get_allowed_caps:
2202 * @srcpad: a #GstPad, it must a a source pad.
2204 * Gets the capabilities of the allowed media types that can flow through
2205 * @srcpad and its peer. The pad must be a source pad.
2206 * The caller must free the resulting caps.
2208 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2209 * you no longer need it. This function returns NULL when the @srcpad has no
2215 gst_pad_get_allowed_caps (GstPad * srcpad)
2222 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2223 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2227 peer = GST_PAD_PEER (srcpad);
2228 if (G_UNLIKELY (peer == NULL))
2231 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2232 GST_DEBUG_PAD_NAME (srcpad));
2234 gst_object_ref (peer);
2235 GST_UNLOCK (srcpad);
2236 mycaps = gst_pad_get_caps (srcpad);
2238 peercaps = gst_pad_get_caps (peer);
2239 gst_object_unref (peer);
2241 caps = gst_caps_intersect (mycaps, peercaps);
2242 gst_caps_unref (peercaps);
2243 gst_caps_unref (mycaps);
2245 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2251 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2252 GST_DEBUG_PAD_NAME (srcpad));
2253 GST_UNLOCK (srcpad);
2260 * gst_pad_get_negotiated_caps:
2263 * Gets the capabilities of the media type that currently flows through @pad
2266 * This function can be used on both src and sinkpads. Note that srcpads are
2267 * always negotiated before sinkpads so it is possible that the negotiated caps
2268 * on the srcpad do not match the negotiated caps of the peer.
2270 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2271 * you no longer need it. This function returns NULL when the @pad has no
2272 * peer or is not negotiated yet.
2277 gst_pad_get_negotiated_caps (GstPad * pad)
2282 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2286 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2289 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2290 GST_DEBUG_PAD_NAME (pad));
2292 caps = GST_PAD_CAPS (pad);
2294 gst_caps_ref (caps);
2297 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2303 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2304 GST_DEBUG_PAD_NAME (pad));
2312 * gst_pad_alloc_buffer:
2313 * @pad: a source #GstPad
2314 * @offset: the offset of the new buffer in the stream
2315 * @size: the size of the new buffer
2316 * @caps: the caps of the new buffer
2317 * @buf: a newly allocated buffer
2319 * Allocates a new, empty buffer optimized to push to pad @pad. This
2320 * function only works if @pad is a source pad and has a peer.
2322 * You need to check the caps of the buffer after performing this
2323 * function and renegotiate to the format if needed.
2325 * A new, empty #GstBuffer will be put in the @buf argument.
2327 * Returns: a result code indicating success of the operation. Any
2328 * result code other than GST_FLOW_OK is an error and @buf should
2330 * An error can occur if the pad is not connected or when the downstream
2331 * peer elements cannot provide an acceptable buffer.
2336 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2341 GstPadBufferAllocFunction bufferallocfunc;
2342 gboolean caps_changed;
2344 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2345 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2346 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2349 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2352 gst_object_ref (peer);
2355 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2359 /* when the peer is flushing we cannot give a buffer */
2360 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2363 GST_CAT_DEBUG (GST_CAT_PADS,
2364 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d",
2365 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2366 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size);
2369 ret = bufferallocfunc (peer, offset, size, caps, buf);
2371 if (G_UNLIKELY (ret != GST_FLOW_OK))
2373 if (G_UNLIKELY (*buf == NULL))
2377 gst_object_unref (peer);
2379 /* FIXME, move capnego this into a base class? */
2380 caps = GST_BUFFER_CAPS (*buf);
2381 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2382 /* we got a new datatype on the pad, see if it can handle it */
2383 if (G_UNLIKELY (caps_changed)) {
2384 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2385 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps)))
2386 goto not_negotiated;
2392 /* pad has no peer */
2393 GST_CAT_DEBUG (GST_CAT_PADS,
2394 "%s:%s called bufferallocfunc but had no peer",
2395 GST_DEBUG_PAD_NAME (pad));
2397 return GST_FLOW_NOT_LINKED;
2401 /* peer was flushing */
2403 gst_object_unref (peer);
2404 GST_CAT_DEBUG (GST_CAT_PADS,
2405 "%s:%s called bufferallocfunc but peer was flushing",
2406 GST_DEBUG_PAD_NAME (pad));
2407 return GST_FLOW_WRONG_STATE;
2409 /* fallback case, allocate a buffer of our own, add pad caps. */
2412 GST_CAT_DEBUG (GST_CAT_PADS,
2413 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2414 *buf = gst_buffer_new_and_alloc (size);
2415 gst_buffer_set_caps (*buf, caps);
2423 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2424 "alloc function retured unacceptable buffer");
2425 return GST_FLOW_NOT_NEGOTIATED;
2429 gst_object_unref (peer);
2430 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2431 "alloc function retured error %d", ret);
2437 * gst_pad_get_internal_links_default:
2438 * @pad: the #GstPad to get the internal links of.
2440 * Gets a list of pads to which the given pad is linked to
2441 * inside of the parent element.
2442 * This is the default handler, and thus returns a list of all of the
2443 * pads inside the parent element with opposite direction.
2444 * The caller must free this list after use.
2446 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
2451 gst_pad_get_internal_links_default (GstPad * pad)
2456 GstPadDirection direction;
2458 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2460 direction = pad->direction;
2462 parent = GST_PAD_PARENT (pad);
2466 parent_pads = parent->pads;
2468 while (parent_pads) {
2469 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2471 if (parent_pad->direction != direction) {
2472 res = g_list_prepend (res, parent_pad);
2475 parent_pads = g_list_next (parent_pads);
2482 * gst_pad_get_internal_links:
2483 * @pad: the #GstPad to get the internal links of.
2485 * Gets a list of pads to which the given pad is linked to
2486 * inside of the parent element.
2487 * The caller must free this list after use.
2489 * Returns: a newly allocated #GList of pads.
2494 gst_pad_get_internal_links (GstPad * pad)
2498 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2500 if (GST_PAD_INTLINKFUNC (pad))
2501 res = GST_PAD_INTLINKFUNC (pad) (pad);
2508 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2513 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2516 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2518 orig = pads = gst_pad_get_internal_links (pad);
2521 GstPad *eventpad = GST_PAD_CAST (pads->data);
2523 pads = g_list_next (pads);
2525 /* for all of the internally-linked pads that are actually linked */
2526 if (GST_PAD_IS_LINKED (eventpad)) {
2527 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2528 /* for each pad we send to, we should ref the event; it's up
2529 * to downstream to unref again when handled. */
2530 GST_LOG_OBJECT (pad, "Reffing and sending event %p to %s:%s", event,
2531 GST_DEBUG_PAD_NAME (eventpad));
2532 gst_event_ref (event);
2533 gst_pad_push_event (eventpad, event);
2535 /* we only send the event on one pad, multi-sinkpad elements
2536 * should implement a handler */
2537 GST_LOG_OBJECT (pad, "sending event %p to one sink pad %s:%s", event,
2538 GST_DEBUG_PAD_NAME (eventpad));
2539 result = gst_pad_push_event (eventpad, event);
2544 /* we handled the incoming event so we unref once */
2545 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2546 gst_event_unref (event);
2555 * gst_pad_event_default:
2556 * @pad: a #GstPad to call the default event handler on.
2557 * @event: the #GstEvent to handle.
2559 * Invokes the default event handler for the given pad. End-of-stream and
2560 * discontinuity events are handled specially, and then the event is sent to all
2561 * pads internally linked to @pad. Note that if there are many possible sink
2562 * pads that are internally linked to @pad, only one will be sent an event.
2563 * Multi-sinkpad elements should implement custom event handlers.
2565 * Returns: TRUE if the event was sent succesfully.
2568 gst_pad_event_default (GstPad * pad, GstEvent * event)
2570 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2571 g_return_val_if_fail (event != NULL, FALSE);
2573 switch (GST_EVENT_TYPE (event)) {
2576 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2577 gst_pad_pause_task (pad);
2583 return gst_pad_event_default_dispatch (pad, event);
2587 * gst_pad_dispatcher:
2588 * @pad: a #GstPad to dispatch.
2589 * @dispatch: the #GstDispatcherFunction to call.
2590 * @data: gpointer user data passed to the dispatcher function.
2592 * Invokes the given dispatcher function on all pads that are
2593 * internally linked to the given pad.
2594 * The GstPadDispatcherFunction should return TRUE when no further pads
2595 * need to be processed.
2597 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2600 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2603 gboolean res = FALSE;
2604 GList *int_pads, *orig;
2606 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2607 g_return_val_if_fail (dispatch != NULL, FALSE);
2609 orig = int_pads = gst_pad_get_internal_links (pad);
2612 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2613 GstPad *int_peer = GST_PAD_PEER (int_pad);
2616 res = dispatch (int_peer, data);
2620 int_pads = g_list_next (int_pads);
2630 * @pad: a #GstPad to invoke the default query on.
2631 * @query: the #GstQuery to perform.
2633 * Dispatches a query to a pad. The query should have been allocated by the
2634 * caller via one of the type-specific allocation functions in gstquery.h. The
2635 * element is responsible for filling the query with an appropriate response,
2636 * which should then be parsed with a type-specific query parsing function.
2638 * Again, the caller is responsible for both the allocation and deallocation of
2639 * the query structure.
2641 * Returns: TRUE if the query could be performed.
2644 gst_pad_query (GstPad * pad, GstQuery * query)
2646 GstPadQueryFunction func;
2648 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2649 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2651 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2653 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2656 return func (pad, query);
2660 GST_DEBUG ("pad had no query function");
2666 gst_pad_query_default (GstPad * pad, GstQuery * query)
2668 switch (GST_QUERY_TYPE (query)) {
2669 case GST_QUERY_POSITION:
2670 case GST_QUERY_SEEKING:
2671 case GST_QUERY_FORMATS:
2672 case GST_QUERY_LATENCY:
2673 case GST_QUERY_JITTER:
2674 case GST_QUERY_RATE:
2675 case GST_QUERY_CONVERT:
2677 return gst_pad_dispatcher
2678 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2682 #ifndef GST_DISABLE_LOADSAVE
2683 /* FIXME: why isn't this on a GstElement ? */
2685 * gst_pad_load_and_link:
2686 * @self: an #xmlNodePtr to read the description from.
2687 * @parent: the #GstObject element that owns the pad.
2689 * Reads the pad definition from the XML node and links the given pad
2690 * in the element to a pad of an element up in the hierarchy.
2693 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2695 xmlNodePtr field = self->xmlChildrenNode;
2696 GstPad *pad = NULL, *targetpad;
2700 GstObject *grandparent;
2704 if (!strcmp ((char *) field->name, "name")) {
2705 name = (gchar *) xmlNodeGetContent (field);
2706 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2708 } else if (!strcmp ((char *) field->name, "peer")) {
2709 peer = (gchar *) xmlNodeGetContent (field);
2711 field = field->next;
2713 g_return_if_fail (pad != NULL);
2718 split = g_strsplit (peer, ".", 2);
2720 if (split[0] == NULL || split[1] == NULL) {
2721 GST_CAT_DEBUG (GST_CAT_XML,
2722 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2723 peer, GST_DEBUG_PAD_NAME (pad));
2730 g_return_if_fail (split[0] != NULL);
2731 g_return_if_fail (split[1] != NULL);
2733 grandparent = gst_object_get_parent (parent);
2735 if (grandparent && GST_IS_BIN (grandparent)) {
2736 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2743 targetpad = gst_element_get_pad (target, split[1]);
2745 if (targetpad == NULL)
2748 gst_pad_link (pad, targetpad);
2755 * gst_pad_save_thyself:
2756 * @pad: a #GstPad to save.
2757 * @parent: the parent #xmlNodePtr to save the description in.
2759 * Saves the pad into an xml representation.
2761 * Returns: the #xmlNodePtr representation of the pad.
2764 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2769 g_return_val_if_fail (GST_IS_PAD (object), NULL);
2771 pad = GST_PAD (object);
2773 xmlNewChild (parent, NULL, (xmlChar *) "name",
2774 (xmlChar *) GST_PAD_NAME (pad));
2775 if (GST_PAD_PEER (pad) != NULL) {
2778 peer = GST_PAD_PEER (pad);
2779 /* first check to see if the peer's parent's parent is the same */
2780 /* we just save it off */
2781 content = g_strdup_printf ("%s.%s",
2782 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2783 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
2786 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
2793 * gst_ghost_pad_save_thyself:
2794 * @pad: a ghost #GstPad to save.
2795 * @parent: the parent #xmlNodePtr to save the description in.
2797 * Saves the ghost pad into an xml representation.
2799 * Returns: the #xmlNodePtr representation of the pad.
2802 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2806 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2808 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
2809 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
2810 xmlNewChild (self, NULL, (xmlChar *) "parent",
2811 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2813 /* FIXME FIXME FIXME! */
2818 #endif /* GST_DISABLE_LOADSAVE */
2821 * should be called with pad lock held
2826 handle_pad_block (GstPad * pad)
2828 GstPadBlockCallback callback;
2831 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2832 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2834 /* need to grab extra ref for the callbacks */
2835 gst_object_ref (pad);
2837 callback = pad->block_callback;
2839 user_data = pad->block_data;
2841 callback (pad, TRUE, user_data);
2844 GST_PAD_BLOCK_SIGNAL (pad);
2847 while (GST_PAD_IS_BLOCKED (pad))
2848 GST_PAD_BLOCK_WAIT (pad);
2850 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
2852 callback = pad->block_callback;
2854 user_data = pad->block_data;
2856 callback (pad, FALSE, user_data);
2859 GST_PAD_BLOCK_SIGNAL (pad);
2862 gst_object_unref (pad);
2865 /**********************************************************************
2866 * Data passing functions
2870 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
2873 GValue args[2] = { {0}, {0} };
2877 g_value_init (&ret, G_TYPE_BOOLEAN);
2878 g_value_set_boolean (&ret, TRUE);
2879 g_value_init (&args[0], GST_TYPE_PAD);
2880 g_value_set_object (&args[0], pad);
2881 g_value_init (&args[1], GST_TYPE_MINI_OBJECT); // G_TYPE_POINTER);
2882 gst_value_set_mini_object (&args[1], obj);
2885 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], 0, &ret);
2886 res = g_value_get_boolean (&ret);
2889 g_value_unset (&ret);
2890 g_value_unset (&args[0]);
2891 g_value_unset (&args[1]);
2898 * @pad: a sink #GstPad.
2899 * @buffer: the #GstBuffer to send.
2901 * Chain a buffer to @pad.
2903 * Returns: a #GstFlowReturn from the pad.
2908 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
2911 gboolean caps_changed;
2912 GstPadChainFunction chainfunc;
2914 gboolean emit_signal;
2916 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2917 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2919 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2920 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2922 GST_STREAM_LOCK (pad);
2925 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2928 caps = GST_BUFFER_CAPS (buffer);
2929 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2931 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
2934 /* see if the signal should be emited, we emit before caps nego as
2935 * we might drop the buffer and do capsnego for nothing. */
2936 if (G_UNLIKELY (emit_signal)) {
2937 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
2941 /* we got a new datatype on the pad, see if it can handle it */
2942 if (G_UNLIKELY (caps_changed)) {
2943 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2944 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
2945 goto not_negotiated;
2948 /* NOTE: we read the chainfunc unlocked.
2949 * we cannot hold the lock for the pad so we might send
2950 * the data to the wrong function. This is not really a
2951 * problem since functions are assigned at creation time
2952 * and don't change that often... */
2953 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
2956 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2957 "calling chainfunction &%s of pad %s:%s",
2958 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
2960 ret = chainfunc (pad, buffer);
2962 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2963 "called chainfunction &%s of pad %s:%s, returned %d",
2964 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad), ret);
2966 GST_STREAM_UNLOCK (pad);
2973 gst_buffer_unref (buffer);
2974 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2975 "pushing, but pad was flushing");
2977 GST_STREAM_UNLOCK (pad);
2978 return GST_FLOW_WRONG_STATE;
2982 gst_buffer_unref (buffer);
2983 GST_DEBUG ("Dropping buffer due to FALSE probe return");
2984 GST_STREAM_UNLOCK (pad);
2989 gst_buffer_unref (buffer);
2990 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2991 "pushing buffer but pad did not accept");
2992 GST_STREAM_UNLOCK (pad);
2993 return GST_FLOW_NOT_NEGOTIATED;
2997 gst_buffer_unref (buffer);
2998 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2999 "pushing, but not chainhandler");
3000 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3001 ("push on pad %s:%s but it has no chainfunction",
3002 GST_DEBUG_PAD_NAME (pad)));
3003 GST_STREAM_UNLOCK (pad);
3004 return GST_FLOW_ERROR;
3010 * @pad: a source #GstPad.
3011 * @buffer: the #GstBuffer to push.
3013 * Pushes a buffer to the peer of @pad. @pad must be linked.
3015 * Returns: a #GstFlowReturn from the peer pad.
3020 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3024 gboolean emit_signal;
3026 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3027 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3028 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3029 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3032 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3033 handle_pad_block (pad);
3035 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3038 /* we emit signals on the pad areg, the peer will have a chance to
3039 * emit in the _chain() function */
3040 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3042 gst_object_ref (peer);
3045 if (G_UNLIKELY (emit_signal)) {
3046 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3050 ret = gst_pad_chain (peer, buffer);
3052 gst_object_unref (peer);
3056 /* ERROR recovery here */
3059 gst_buffer_unref (buffer);
3060 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3061 "pushing, but it was not linked");
3063 return GST_FLOW_NOT_LINKED;
3067 gst_buffer_unref (buffer);
3068 gst_object_unref (peer);
3069 GST_DEBUG ("Dropping buffer due to FALSE probe return");
3075 * gst_pad_check_pull_range:
3076 * @pad: a sink #GstPad.
3078 * Checks if a #gst_pad_pull_range() can be performed on the peer
3079 * source pad. This function is used by plugins that want to check
3080 * if they can use random access on the peer source pad.
3082 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
3083 * if it needs to perform some logic to determine if pull_range is
3086 * Returns: a gboolean with the result.
3091 gst_pad_check_pull_range (GstPad * pad)
3095 GstPadCheckGetRangeFunction checkgetrangefunc;
3097 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3100 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
3101 goto wrong_direction;
3103 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3106 gst_object_ref (peer);
3109 /* see note in above function */
3110 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
3111 /* FIXME, kindoff ghetto */
3112 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
3114 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3115 "calling checkgetrangefunc %s of peer pad %s:%s",
3116 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
3118 ret = checkgetrangefunc (peer);
3121 gst_object_unref (peer);
3125 /* ERROR recovery here */
3133 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3134 "checking pull range, but it was not linked");
3141 * gst_pad_get_range:
3142 * @pad: a src #GstPad.
3143 * @offset: The start offset of the buffer
3144 * @size: The length of the buffer
3145 * @buffer: a pointer to hold the #GstBuffer.
3147 * Calls the getrange function of @pad.
3149 * Returns: a #GstFlowReturn from the pad.
3154 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3155 GstBuffer ** buffer)
3158 GstPadGetRangeFunction getrangefunc;
3159 gboolean emit_signal;
3161 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3162 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3163 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3165 GST_STREAM_LOCK (pad);
3168 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3171 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3174 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3177 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3178 "calling getrangefunc %s of peer pad %s:%s, offset %"
3179 G_GUINT64_FORMAT ", size %u",
3180 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
3183 ret = getrangefunc (pad, offset, size, buffer);
3185 /* can only fire the signal if we have a valid buffer */
3186 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3187 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3191 GST_STREAM_UNLOCK (pad);
3198 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3199 "pulling range, but pad was flushing");
3201 GST_STREAM_UNLOCK (pad);
3202 return GST_FLOW_WRONG_STATE;
3206 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3207 ("pullrange on pad %s:%s but it has no getrangefunction",
3208 GST_DEBUG_PAD_NAME (pad)));
3209 GST_STREAM_UNLOCK (pad);
3210 return GST_FLOW_ERROR;
3214 GST_DEBUG ("Dropping data after FALSE probe return");
3215 GST_STREAM_UNLOCK (pad);
3216 gst_buffer_unref (*buffer);
3218 return GST_FLOW_UNEXPECTED;
3224 * gst_pad_pull_range:
3225 * @pad: a sink #GstPad.
3226 * @offset: The start offset of the buffer
3227 * @size: The length of the buffer
3228 * @buffer: a pointer to hold the #GstBuffer.
3230 * Pulls a buffer from the peer pad. @pad must be linked.
3232 * Returns: a #GstFlowReturn from the peer pad.
3237 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3238 GstBuffer ** buffer)
3242 gboolean emit_signal;
3244 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3245 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3247 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3251 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3252 handle_pad_block (pad);
3254 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3257 /* signal emision for the pad, peer has chance to emit when
3258 * we call _get_range() */
3259 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3261 gst_object_ref (peer);
3264 ret = gst_pad_get_range (peer, offset, size, buffer);
3266 gst_object_unref (peer);
3268 /* can only fire the signal if we have a valid buffer */
3269 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3270 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3275 /* ERROR recovery here */
3278 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3279 "pulling range, but it was not linked");
3281 return GST_FLOW_NOT_LINKED;
3285 GST_DEBUG ("Dropping data after FALSE probe return");
3286 gst_buffer_unref (*buffer);
3288 return GST_FLOW_UNEXPECTED;
3293 * gst_pad_push_event:
3294 * @pad: a #GstPad to push the event to.
3295 * @event: the #GstEvent to send to the pad.
3297 * Sends the event to the peer of the given pad. This function is
3298 * mainly used by elements to send events to their peer
3301 * Returns: TRUE if the event was handled.
3306 gst_pad_push_event (GstPad * pad, GstEvent * event)
3310 gboolean emit_signal;
3312 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3313 g_return_val_if_fail (event != NULL, FALSE);
3316 peerpad = GST_PAD_PEER (pad);
3317 if (peerpad == NULL)
3320 emit_signal = GST_PAD_DO_EVENT_SIGNALS (pad) > 0;
3322 gst_object_ref (peerpad);
3325 if (G_UNLIKELY (emit_signal)) {
3326 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3330 result = gst_pad_send_event (peerpad, event);
3332 gst_object_unref (peerpad);
3336 /* ERROR handling */
3339 gst_event_unref (event);
3345 GST_DEBUG ("Dropping event after FALSE probe return");
3346 gst_object_unref (peerpad);
3347 gst_event_unref (event);
3353 * gst_pad_send_event:
3354 * @pad: a #GstPad to send the event to.
3355 * @event: the #GstEvent to send to the pad.
3357 * Sends the event to the pad. This function can be used
3358 * by applications to send events in the pipeline.
3360 * Returns: TRUE if the event was handled.
3363 gst_pad_send_event (GstPad * pad, GstEvent * event)
3365 gboolean result = FALSE;
3366 GstPadEventFunction eventfunc;
3367 gboolean emit_signal;
3369 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3370 g_return_val_if_fail (event != NULL, FALSE);
3374 if (GST_PAD_IS_SINK (pad) && !GST_EVENT_IS_DOWNSTREAM (event))
3375 goto wrong_direction;
3376 if (GST_PAD_IS_SRC (pad) && !GST_EVENT_IS_UPSTREAM (event))
3377 goto wrong_direction;
3379 if (GST_EVENT_SRC (event) == NULL)
3380 GST_EVENT_SRC (event) = gst_object_ref (pad);
3382 switch (GST_EVENT_TYPE (event)) {
3383 case GST_EVENT_FLUSH_START:
3384 GST_CAT_DEBUG (GST_CAT_EVENT,
3385 "have event type %d (FLUSH_START) on pad %s:%s",
3386 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3388 /* can't even accept a flush begin event when flushing */
3389 if (GST_PAD_IS_FLUSHING (pad))
3391 GST_PAD_SET_FLUSHING (pad);
3392 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3394 case GST_EVENT_FLUSH_STOP:
3395 GST_PAD_UNSET_FLUSHING (pad);
3396 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3399 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d on pad %s:%s",
3400 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3402 if (GST_PAD_IS_FLUSHING (pad))
3407 if ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL)
3410 emit_signal = GST_PAD_DO_EVENT_SIGNALS (pad) > 0;
3412 gst_object_ref (pad);
3415 if (G_UNLIKELY (emit_signal)) {
3416 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3420 result = eventfunc (GST_PAD_CAST (pad), event);
3422 gst_object_unref (pad);
3426 /* ERROR handling */
3429 g_warning ("pad %s:%s sending event in wrong direction",
3430 GST_DEBUG_PAD_NAME (pad));
3432 gst_event_unref (event);
3437 g_warning ("pad %s:%s has no event handler, file a bug.",
3438 GST_DEBUG_PAD_NAME (pad));
3440 gst_event_unref (event);
3446 GST_CAT_DEBUG (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3447 gst_event_unref (event);
3452 GST_DEBUG ("Dropping event after FALSE probe return");
3453 gst_object_unref (pad);
3454 gst_event_unref (event);
3459 /************************************************************************
3464 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3465 static void gst_pad_template_init (GstPadTemplate * templ);
3466 static void gst_pad_template_dispose (GObject * object);
3469 gst_pad_template_get_type (void)
3471 static GType padtemplate_type = 0;
3473 if (!padtemplate_type) {
3474 static const GTypeInfo padtemplate_info = {
3475 sizeof (GstPadTemplateClass), NULL, NULL,
3476 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3477 sizeof (GstPadTemplate),
3479 (GInstanceInitFunc) gst_pad_template_init, NULL
3483 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3484 &padtemplate_info, 0);
3486 return padtemplate_type;
3490 gst_pad_template_class_init (GstPadTemplateClass * klass)
3492 GObjectClass *gobject_class;
3493 GstObjectClass *gstobject_class;
3495 gobject_class = (GObjectClass *) klass;
3496 gstobject_class = (GstObjectClass *) klass;
3498 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3500 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3501 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3502 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3503 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3505 gobject_class->dispose = gst_pad_template_dispose;
3507 gstobject_class->path_string_separator = "*";
3511 gst_pad_template_init (GstPadTemplate * templ)
3516 gst_pad_template_dispose (GObject * object)
3518 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3520 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3521 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3522 gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
3525 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3528 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3530 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3532 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3533 * 'sink%d' template is automatically selected), so we need to restrict their
3537 name_is_valid (const gchar * name, GstPadPresence presence)
3541 if (presence == GST_PAD_ALWAYS) {
3542 if (strchr (name, '%')) {
3543 g_warning ("invalid name template %s: conversion specifications are not"
3544 " allowed for GST_PAD_ALWAYS padtemplates", name);
3547 } else if (presence == GST_PAD_REQUEST) {
3548 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3549 g_warning ("invalid name template %s: only one conversion specification"
3550 " allowed in GST_PAD_REQUEST padtemplate", name);
3553 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3554 g_warning ("invalid name template %s: conversion specification must be of"
3555 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3558 if (str && (*(str + 2) != '\0')) {
3559 g_warning ("invalid name template %s: conversion specification must"
3560 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3569 * gst_static_pad_template_get:
3570 * @pad_template: the static pad template
3572 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3574 * Returns: a new #GstPadTemplate.
3577 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3579 GstPadTemplate *new;
3581 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3584 new = g_object_new (gst_pad_template_get_type (),
3585 "name", pad_template->name_template, NULL);
3587 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3588 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3589 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3591 GST_PAD_TEMPLATE_CAPS (new) =
3592 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3598 * gst_pad_template_new:
3599 * @name_template: the name template.
3600 * @direction: the #GstPadDirection of the template.
3601 * @presence: the #GstPadPresence of the pad.
3602 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3604 * Creates a new pad template with a name according to the given template
3605 * and with the given arguments. This functions takes ownership of the provided
3606 * caps, so be sure to not use them afterwards.
3608 * Returns: a new #GstPadTemplate.
3611 gst_pad_template_new (const gchar * name_template,
3612 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3614 GstPadTemplate *new;
3616 g_return_val_if_fail (name_template != NULL, NULL);
3617 g_return_val_if_fail (caps != NULL, NULL);
3618 g_return_val_if_fail (direction == GST_PAD_SRC
3619 || direction == GST_PAD_SINK, NULL);
3620 g_return_val_if_fail (presence == GST_PAD_ALWAYS
3621 || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL);
3623 if (!name_is_valid (name_template, presence))
3626 new = g_object_new (gst_pad_template_get_type (),
3627 "name", name_template, NULL);
3629 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3630 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3631 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3632 GST_PAD_TEMPLATE_CAPS (new) = caps;
3638 * gst_static_pad_template_get_caps:
3639 * @templ: a #GstStaticPadTemplate to get capabilities of.
3641 * Gets the capabilities of the static pad template.
3643 * Returns: the #GstCaps of the static pad template. If you need to keep a
3644 * reference to the caps, take a ref (see gst_caps_ref ()).
3647 gst_static_pad_template_get_caps (GstStaticPadTemplate * templ)
3649 g_return_val_if_fail (templ, NULL);
3651 return (GstCaps *) gst_static_caps_get (&templ->static_caps);
3655 * gst_pad_template_get_caps:
3656 * @templ: a #GstPadTemplate to get capabilities of.
3658 * Gets the capabilities of the pad template.
3660 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3661 * the caps, take a ref (see gst_caps_ref ()).
3664 gst_pad_template_get_caps (GstPadTemplate * templ)
3666 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3668 return GST_PAD_TEMPLATE_CAPS (templ);
3672 * gst_pad_set_element_private:
3673 * @pad: the #GstPad to set the private data of.
3674 * @priv: The private data to attach to the pad.
3676 * Set the given private data gpointer on the pad.
3677 * This function can only be used by the element that owns the pad.
3680 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3682 pad->element_private = priv;
3686 * gst_pad_get_element_private:
3687 * @pad: the #GstPad to get the private data of.
3689 * Gets the private data of a pad.
3691 * Returns: a #gpointer to the private data.
3694 gst_pad_get_element_private (GstPad * pad)
3696 return pad->element_private;
3700 * gst_pad_start_task:
3701 * @pad: the #GstPad to start the task of
3702 * @func: the task function to call
3703 * @data: data passed to the task function
3705 * Starts a task that repeadedly calls @func with @data. This function
3706 * is nostly used in the pad activation function to start the
3707 * dataflow. This function will automatically acauire the STREAM_LOCK of
3708 * the pad before calling @func.
3710 * Returns: a TRUE if the task could be started.
3713 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3717 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3718 g_return_val_if_fail (func != NULL, FALSE);
3721 task = GST_PAD_TASK (pad);
3723 task = gst_task_create (func, data);
3724 gst_task_set_lock (task, GST_STREAM_GET_LOCK (pad));
3725 GST_PAD_TASK (pad) = task;
3727 gst_task_start (task);
3734 * gst_pad_pause_task:
3735 * @pad: the #GstPad to pause the task of
3737 * Pause the task of @pad. This function will also make sure that the
3738 * function executed by the task will effectively stop.
3740 * Returns: a TRUE if the task could be paused or FALSE when the pad
3744 gst_pad_pause_task (GstPad * pad)
3748 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3751 task = GST_PAD_TASK (pad);
3754 gst_task_pause (task);
3757 GST_STREAM_LOCK (pad);
3758 GST_STREAM_UNLOCK (pad);
3770 * gst_pad_stop_task:
3771 * @pad: the #GstPad to stop the task of
3773 * Stop the task of @pad. This function will also make sure that the
3774 * function executed by the task will effectively stop if not called
3775 * from the GstTaskFunction.
3777 * This function will deadlock if called from the GstTaskFunction of
3778 * the task. Use #gst_task_pause() instead.
3780 * Returns: a TRUE if the task could be stopped or FALSE when the pad
3784 gst_pad_stop_task (GstPad * pad)
3788 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3791 task = GST_PAD_TASK (pad);
3794 GST_PAD_TASK (pad) = NULL;
3795 gst_task_stop (task);
3798 GST_STREAM_LOCK (pad);
3799 GST_STREAM_UNLOCK (pad);
3801 gst_task_join (task);
3803 gst_object_unref (task);