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 };
99 static GQuark buffer_quark;
100 static GQuark event_quark;
103 gst_pad_get_type (void)
105 if (!_gst_pad_type) {
106 static const GTypeInfo pad_info = {
107 sizeof (GstPadClass), NULL, NULL,
108 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
111 (GInstanceInitFunc) gst_pad_init, NULL
114 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
117 buffer_quark = g_quark_from_static_string ("buffer");
118 event_quark = g_quark_from_static_string ("event");
120 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
121 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
123 return _gst_pad_type;
127 _gst_do_pass_data_accumulator (GSignalInvocationHint * ihint,
128 GValue * return_accu, const GValue * handler_return, gpointer dummy)
130 gboolean ret = g_value_get_boolean (handler_return);
132 GST_DEBUG ("accumulated %d", ret);
133 g_value_set_boolean (return_accu, ret);
139 default_have_data (GstPad * pad, GstMiniObject * o)
145 gst_pad_class_init (GstPadClass * klass)
147 GObjectClass *gobject_class;
150 GstObjectClass *gstobject_class;
152 gobject_class = (GObjectClass *) klass;
153 gstobject_class = (GstObjectClass *) klass;
155 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
157 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
158 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_pad_finalize);
159 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_pad_set_property);
160 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_pad_get_property);
164 * @pad: the pad that emitted the signal
165 * @peer: the peer pad that has been connected
167 * Signals that a pad has been linked to the peer pad.
169 gst_pad_signals[PAD_LINKED] =
170 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
171 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
172 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
175 * @pad: the pad that emitted the signal
176 * @peer: the peer pad that has been disconnected
178 * Signals that a pad has been unlinked from the peer pad.
180 gst_pad_signals[PAD_UNLINKED] =
181 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
182 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
183 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
185 * GstPad::request-link:
186 * @pad: the pad that emitted the signal
187 * @peer: the peer pad for which a connection is requested
189 * Signals that a pad connection has been requested.
191 gst_pad_signals[PAD_REQUEST_LINK] =
192 g_signal_new ("request-link", G_TYPE_FROM_CLASS (klass),
193 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
194 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
198 * @pad: the pad that emitted the signal
199 * @mini_obj: new data
201 * Signals that new data is available on the pad. This signal is used
202 * internally for implementing pad probes.
203 * See gst_pad_add_*_probe functions.
205 * Returns: %TRUE to keep the data, %FALSE to drop it
207 gst_pad_signals[PAD_HAVE_DATA] =
208 g_signal_new ("have-data", G_TYPE_FROM_CLASS (klass),
209 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
210 G_STRUCT_OFFSET (GstPadClass, have_data),
211 _gst_do_pass_data_accumulator,
212 NULL, gst_marshal_BOOLEAN__POINTER, G_TYPE_BOOLEAN, 1,
213 GST_TYPE_MINI_OBJECT);
215 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_CAPS,
216 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
217 GST_TYPE_CAPS, G_PARAM_READABLE));
218 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_DIRECTION,
219 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
220 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
221 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
222 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_TEMPLATE,
223 g_param_spec_object ("template", "Template",
224 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
227 #ifndef GST_DISABLE_LOADSAVE
228 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
230 gstobject_class->path_string_separator = ".";
232 klass->have_data = default_have_data;
236 gst_pad_init (GstPad * pad)
238 pad->direction = GST_PAD_UNKNOWN;
241 pad->chainfunc = NULL;
245 pad->linkfunc = NULL;
246 pad->getcapsfunc = NULL;
248 pad->activatefunc = gst_pad_activate_default;
249 pad->eventfunc = gst_pad_event_default;
250 pad->querytypefunc = gst_pad_get_query_types_default;
251 pad->queryfunc = gst_pad_query_default;
252 pad->intlinkfunc = gst_pad_get_internal_links_default;
254 pad->do_buffer_signals = 0;
255 pad->do_event_signals = 0;
257 GST_PAD_UNSET_FLUSHING (pad);
259 pad->preroll_lock = g_mutex_new ();
260 pad->preroll_cond = g_cond_new ();
262 pad->stream_rec_lock = g_new (GStaticRecMutex, 1);
263 g_static_rec_mutex_init (pad->stream_rec_lock);
265 pad->block_cond = g_cond_new ();
269 gst_pad_dispose (GObject * object)
271 GstPad *pad = GST_PAD (object);
273 gst_pad_set_pad_template (pad, NULL);
274 /* FIXME, we have links to many other things like caps
275 * and the peer pad... */
277 /* No linked pad can ever be disposed.
278 * It has to have a parent to be linked
279 * and a parent would hold a reference */
280 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
281 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
283 g_assert (GST_PAD_PEER (pad) == NULL);
285 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
286 GST_DEBUG_PAD_NAME (pad));
289 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
291 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
292 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
293 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
295 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
298 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
302 gst_pad_finalize (GObject * object)
304 GstPad *pad = GST_PAD (object);
307 /* in case the task is still around, clean it up */
308 if ((task = GST_PAD_TASK (pad))) {
309 gst_task_join (task);
310 GST_PAD_TASK (pad) = NULL;
311 gst_object_unref (task);
314 if (pad->stream_rec_lock) {
315 g_static_rec_mutex_free (pad->stream_rec_lock);
316 g_free (pad->stream_rec_lock);
317 pad->stream_rec_lock = NULL;
319 if (pad->preroll_lock) {
320 g_mutex_free (pad->preroll_lock);
321 g_cond_free (pad->preroll_cond);
322 pad->preroll_lock = NULL;
323 pad->preroll_cond = NULL;
325 if (pad->block_cond) {
326 g_cond_free (pad->block_cond);
327 pad->block_cond = NULL;
330 G_OBJECT_CLASS (pad_parent_class)->finalize (object);
334 gst_pad_set_property (GObject * object, guint prop_id,
335 const GValue * value, GParamSpec * pspec)
337 g_return_if_fail (GST_IS_PAD (object));
340 case PAD_PROP_DIRECTION:
341 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
343 case PAD_PROP_TEMPLATE:
344 gst_pad_set_pad_template (GST_PAD_CAST (object),
345 (GstPadTemplate *) g_value_dup_object (value));
348 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
354 gst_pad_get_property (GObject * object, guint prop_id,
355 GValue * value, GParamSpec * pspec)
357 g_return_if_fail (GST_IS_PAD (object));
361 g_value_set_boxed (value, GST_PAD_CAPS (object));
363 case PAD_PROP_DIRECTION:
364 g_value_set_enum (value, GST_PAD_DIRECTION (object));
366 case PAD_PROP_TEMPLATE:
367 g_value_set_object (value, GST_PAD_TEMPLATE (object));
370 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
377 * @name: the name of the new pad.
378 * @direction: the #GstPadDirection of the pad.
380 * Creates a new pad with the given name in the given direction.
381 * If name is NULL, a guaranteed unique name (across all pads)
383 * This function makes a copy of the name so you can safely free the name.
385 * Returns: a new #GstPad, or NULL in case of an error.
390 gst_pad_new (const gchar * name, GstPadDirection direction)
392 return g_object_new (GST_TYPE_PAD,
393 "name", name, "direction", direction, NULL);
397 * gst_pad_new_from_template:
398 * @templ: the pad template to use
399 * @name: the name of the element
401 * Creates a new pad with the given name from the given template.
402 * If name is NULL, a guaranteed unique name (across all pads)
404 * This function makes a copy of the name so you can safely free the name.
406 * Returns: a new #GstPad, or NULL in case of an error.
409 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
411 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
413 return g_object_new (GST_TYPE_PAD,
414 "name", name, "direction", templ->direction, "template", templ, NULL);
418 * gst_pad_get_direction:
419 * @pad: a #GstPad to get the direction of.
421 * Gets the direction of the pad. The direction of the pad is
422 * decided at construction time so this function does not take
425 * Returns: the #GstPadDirection of the pad.
430 gst_pad_get_direction (GstPad * pad)
432 GstPadDirection result;
434 /* PAD_UNKNOWN is a little silly but we need some sort of
435 * error return value */
436 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
439 result = GST_PAD_DIRECTION (pad);
446 gst_pad_activate_default (GstPad * pad)
448 return gst_pad_activate_push (pad, TRUE);
452 pre_activate_switch (GstPad * pad, gboolean new_active)
458 GST_PAD_SET_FLUSHING (pad);
459 /* unlock blocked pads so element can resume and stop */
460 GST_PAD_BLOCK_SIGNAL (pad);
466 post_activate_switch (GstPad * pad, gboolean new_active)
470 GST_PAD_UNSET_FLUSHING (pad);
473 /* make streaming stop */
474 GST_STREAM_LOCK (pad);
475 GST_STREAM_UNLOCK (pad);
480 * gst_pad_set_active:
481 * @pad: the #GstPad to activate or deactivate.
482 * @active: whether or not the pad should be active.
484 * Activates or deactivates the given pad. Must be called with the %GST_STATE_LOCK.
485 * Normally called from within core state change functions.
487 * If @active, makes sure the pad is active. If it is already active, either in
488 * push or pull mode, just return. Otherwise dispatches to the pad's activate
489 * function to perform the actual activation.
491 * If not @active, checks the pad's current mode and calls
492 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
495 * Returns: TRUE if the operation was successfull.
497 * MT safe. Must be called with %GST_STATE_LOCK.
500 gst_pad_set_active (GstPad * pad, gboolean active)
503 gboolean ret = FALSE;
505 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
508 old = GST_PAD_ACTIVATE_MODE (pad);
513 case GST_ACTIVATE_PUSH:
514 case GST_ACTIVATE_PULL:
517 case GST_ACTIVATE_NONE:
518 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
523 case GST_ACTIVATE_PUSH:
524 ret = gst_pad_activate_push (pad, FALSE);
526 case GST_ACTIVATE_PULL:
527 ret = gst_pad_activate_pull (pad, FALSE);
529 case GST_ACTIVATE_NONE:
539 * gst_pad_activate_pull:
540 * @pad: the #GstPad to activate or deactivate.
541 * @active: whether or not the pad should be active.
543 * Activates or deactivates the given pad in pull mode via dispatching to the
544 * pad's activatepullfunc. For use from within pad activation functions only.
545 * When called on sink pads, will first proxy the call to the peer pad, which is
546 * expected to activate its internally linked pads from within its activate_pull
549 * If you don't know what this is, you probably don't want to call it.
551 * Returns: TRUE if the operation was successfull.
556 gst_pad_activate_pull (GstPad * pad, gboolean active)
560 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
563 old = GST_PAD_ACTIVATE_MODE (pad);
566 if ((active && old == GST_ACTIVATE_PULL)
567 || (!active && old == GST_ACTIVATE_NONE))
571 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
573 g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE);
576 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
577 GstPad *peer = gst_pad_get_peer (pad);
580 if (!gst_pad_activate_pull (peer, active)) {
582 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
583 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
585 gst_object_unref (peer);
591 pre_activate_switch (pad, active);
593 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
594 if (GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)) {
600 /* can happen for sinks of passthrough elements */
606 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
607 active ? "activated" : "deactivated");
614 GST_PAD_ACTIVATE_MODE (pad) =
615 active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
617 post_activate_switch (pad, active);
619 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
620 active ? "activated" : "deactivated");
626 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
627 active ? "activate" : "deactivate");
633 * gst_pad_activate_push:
634 * @pad: the #GstPad to activate or deactivate.
635 * @active: whether or not the pad should be active.
637 * Activates or deactivates the given pad in push mode via dispatching to the
638 * pad's activatepushfunc. For use from within pad activation functions only.
640 * If you don't know what this is, you probably don't want to call it.
642 * Returns: TRUE if the operation was successfull.
647 gst_pad_activate_push (GstPad * pad, gboolean active)
651 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
652 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
653 active ? "activated" : "deactivated");
656 old = GST_PAD_ACTIVATE_MODE (pad);
659 if ((active && old == GST_ACTIVATE_PUSH)
660 || (!active && old == GST_ACTIVATE_NONE))
664 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
666 g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE);
669 pre_activate_switch (pad, active);
671 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
672 if (GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) {
678 /* quite ok, element relies on state change func to prepare itself */
684 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
685 active ? "activated" : "deactivated");
692 GST_PAD_ACTIVATE_MODE (pad) =
693 active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
695 post_activate_switch (pad, active);
697 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
698 active ? "activated" : "deactivated");
704 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
705 active ? "activate" : "deactivate");
712 * @pad: the #GstPad to query
714 * Query if a pad is active
716 * Returns: TRUE if the pad is active.
721 gst_pad_is_active (GstPad * pad)
723 gboolean result = FALSE;
725 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
728 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
735 * gst_pad_set_blocked_async:
736 * @pad: the #GstPad to block or unblock
737 * @blocked: boolean indicating we should block or unblock
738 * @callback: #GstPadBlockCallback that will be called when the
739 * operation succeeds.
740 * @user_data: user data passed to the callback
742 * Blocks or unblocks the dataflow on a pad. The provided callback
743 * is called when the operation succeeds. This can take a while as
744 * the pad can only become blocked when real dataflow is happening.
745 * When the pipeline is stalled, for example in PAUSED, this can
746 * take an indeterminate amount of time.
747 * You can pass NULL as the callback to make this call block. Be
748 * carefull with this blocking call as it might not return for
749 * reasons stated above.
751 * Returns: TRUE if the pad could be blocked. This function can fail
752 * if wrong parameters were passed or the pad was already in the
758 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
759 GstPadBlockCallback callback, gpointer user_data)
761 gboolean was_blocked;
763 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
767 was_blocked = GST_PAD_IS_BLOCKED (pad);
769 if (G_UNLIKELY (was_blocked == blocked))
770 goto had_right_state;
773 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad %s:%s",
774 GST_DEBUG_PAD_NAME (pad));
776 GST_FLAG_SET (pad, GST_PAD_BLOCKED);
777 pad->block_callback = callback;
778 pad->block_data = user_data;
780 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
781 GST_PAD_BLOCK_WAIT (pad);
782 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
785 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad %s:%s",
786 GST_DEBUG_PAD_NAME (pad));
788 GST_FLAG_UNSET (pad, GST_PAD_BLOCKED);
790 pad->block_callback = callback;
791 pad->block_data = user_data;
794 GST_PAD_BLOCK_SIGNAL (pad);
796 GST_PAD_BLOCK_SIGNAL (pad);
797 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
798 GST_PAD_BLOCK_WAIT (pad);
799 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
808 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
809 "pad %s:%s was in right state", GST_DEBUG_PAD_NAME (pad));
816 * gst_pad_set_blocked:
817 * @pad: the #GstPad to block or unblock
818 * @blocked: boolean indicating we should block or unblock
820 * Blocks or unblocks the dataflow on a pad. This function is
821 * a shortcut for @gst_pad_set_blocked_async() with a NULL
824 * Returns: TRUE if the pad could be blocked. This function can fail
825 * wrong parameters were passed or the pad was already in the
831 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
833 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
837 * gst_pad_is_blocked:
838 * @pad: the #GstPad to query
840 * Checks if the pad is blocked or not. This function returns the
841 * last requested state of the pad. It is not certain that the pad
842 * is actually blocked at this point.
844 * Returns: TRUE if the pad is blocked.
849 gst_pad_is_blocked (GstPad * pad)
851 gboolean result = FALSE;
853 g_return_val_if_fail (GST_IS_PAD (pad), result);
856 result = GST_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
863 * gst_pad_set_activate_function:
864 * @pad: a sink #GstPad.
865 * @activate: the #GstPadActivateFunction to set.
867 * Sets the given activate function for the pad. The activate function will
868 * dispatch to activate_push or activate_pull to perform the actual activation.
869 * Only makes sense to set on sink pads.
871 * Call this function if your sink pad can start a pull-based task.
874 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
876 g_return_if_fail (GST_IS_PAD (pad));
878 GST_PAD_ACTIVATEFUNC (pad) = activate;
879 GST_CAT_DEBUG (GST_CAT_PADS, "activatefunc for %s:%s set to %s",
880 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activate));
884 * gst_pad_set_activatepull_function:
885 * @pad: a sink #GstPad.
886 * @activatepull: the #GstPadActivateModeFunction to set.
888 * Sets the given activate_pull function for the pad. An activate_pull function
889 * prepares the element and any upstream connections for pulling. See XXX
890 * part-activation.txt for details.
893 gst_pad_set_activatepull_function (GstPad * pad,
894 GstPadActivateModeFunction activatepull)
896 g_return_if_fail (GST_IS_PAD (pad));
898 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
899 GST_CAT_DEBUG (GST_CAT_PADS, "activatepullfunc for %s:%s set to %s",
900 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepull));
904 * gst_pad_set_activatepush_function:
905 * @pad: a sink #GstPad.
906 * @activatepush: the #GstPadActivateModeFunction to set.
908 * Sets the given activate_push function for the pad. An activate_push function
909 * prepares the element for pushing. See XXX part-activation.txt for details.
912 gst_pad_set_activatepush_function (GstPad * pad,
913 GstPadActivateModeFunction activatepush)
915 g_return_if_fail (GST_IS_PAD (pad));
917 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
918 GST_CAT_DEBUG (GST_CAT_PADS, "activatepushfunc for %s:%s set to %s",
919 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepush));
923 * gst_pad_set_chain_function:
924 * @pad: a sink #GstPad.
925 * @chain: the #GstPadChainFunction to set.
927 * Sets the given chain function for the pad. The chain function is called to
928 * process a #GstBuffer input buffer.
931 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
933 g_return_if_fail (GST_IS_PAD (pad));
934 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
936 GST_PAD_CHAINFUNC (pad) = chain;
937 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
938 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
942 * gst_pad_set_getrange_function:
943 * @pad: a source #GstPad.
944 * @get: the #GstPadGetRangeFunction to set.
946 * Sets the given getrange function for the pad. The getrange function is called to
947 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
951 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
953 g_return_if_fail (GST_IS_PAD (pad));
954 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
956 GST_PAD_GETRANGEFUNC (pad) = get;
958 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
959 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
963 * gst_pad_set_checkgetrange_function:
964 * @pad: a source #GstPad.
965 * @check: the #GstPadCheckGetRangeFunction to set.
967 * Sets the given checkgetrange function for the pad. Implement this function on
968 * a pad if you dynamically support getrange based scheduling on the pad.
971 gst_pad_set_checkgetrange_function (GstPad * pad,
972 GstPadCheckGetRangeFunction check)
974 g_return_if_fail (GST_IS_PAD (pad));
975 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
977 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
979 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
980 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
984 * gst_pad_set_event_function:
985 * @pad: a source #GstPad.
986 * @event: the #GstPadEventFunction to set.
988 * Sets the given event handler for the pad.
991 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
993 g_return_if_fail (GST_IS_PAD (pad));
995 GST_PAD_EVENTFUNC (pad) = event;
997 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
998 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
1002 * gst_pad_set_query_function:
1003 * @pad: a #GstPad of either direction.
1004 * @query: the #GstPadQueryFunction to set.
1006 * Set the given query function for the pad.
1009 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1011 g_return_if_fail (GST_IS_PAD (pad));
1013 GST_PAD_QUERYFUNC (pad) = query;
1015 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
1016 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
1020 * gst_pad_set_query_type_function:
1021 * @pad: a #GstPad of either direction.
1022 * @type_func: the #GstPadQueryTypeFunction to set.
1024 * Set the given query type function for the pad.
1027 gst_pad_set_query_type_function (GstPad * pad,
1028 GstPadQueryTypeFunction type_func)
1030 g_return_if_fail (GST_IS_PAD (pad));
1032 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1034 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
1035 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
1039 * gst_pad_get_query_types:
1042 * Get an array of supported queries that can be performed
1045 * Returns: a zero-terminated array of #GstQueryType.
1047 const GstQueryType *
1048 gst_pad_get_query_types (GstPad * pad)
1050 GstPadQueryTypeFunction func;
1052 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1054 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1066 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1068 *data = gst_pad_get_query_types (pad);
1074 * gst_pad_get_query_types_default:
1077 * Invoke the default dispatcher for the query types on
1080 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1081 * internally-linked pads has a query types function.
1083 const GstQueryType *
1084 gst_pad_get_query_types_default (GstPad * pad)
1086 GstQueryType *result = NULL;
1088 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1090 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1091 gst_pad_get_query_types_dispatcher, &result);
1097 * gst_pad_set_internal_link_function:
1098 * @pad: a #GstPad of either direction.
1099 * @intlink: the #GstPadIntLinkFunction to set.
1101 * Sets the given internal link function for the pad.
1104 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1106 g_return_if_fail (GST_IS_PAD (pad));
1108 GST_PAD_INTLINKFUNC (pad) = intlink;
1109 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1110 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1114 * gst_pad_set_link_function:
1116 * @link: the #GstPadLinkFunction to set.
1118 * Sets the given link function for the pad. It will be called when the pad is
1119 * linked or relinked with caps. The caps passed to the link function is
1120 * the caps for the connnection. It can contain a non fixed caps.
1122 * The return value GST_PAD_LINK_OK should be used when the connection can be
1125 * The return value GST_PAD_LINK_REFUSED should be used when the connection
1126 * cannot be made for some reason.
1129 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1131 g_return_if_fail (GST_IS_PAD (pad));
1133 GST_PAD_LINKFUNC (pad) = link;
1134 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1135 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1139 * gst_pad_set_unlink_function:
1141 * @unlink: the #GstPadUnlinkFunction to set.
1143 * Sets the given unlink function for the pad. It will be called
1144 * when the pad is unlinked.
1147 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1149 g_return_if_fail (GST_IS_PAD (pad));
1151 GST_PAD_UNLINKFUNC (pad) = unlink;
1152 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1153 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1157 * gst_pad_set_getcaps_function:
1159 * @getcaps: the #GstPadGetCapsFunction to set.
1161 * Sets the given getcaps function for the pad. @getcaps should return the
1162 * allowable caps for a pad in the context of the element's state, its link to
1163 * other elements, and the devices or files it has opened. These caps must be a
1164 * subset of the pad template caps. In the NULL state with no links, @getcaps
1165 * should ideally return the same caps as the pad template. In rare
1166 * circumstances, an object property can affect the caps returned by @getcaps,
1167 * but this is discouraged.
1169 * You do not need to call this function if @pad's allowed caps are always the
1170 * same as the pad template caps. This can only be true if the padtemplate
1171 * has fixed simple caps.
1173 * For most filters, the caps returned by @getcaps is directly affected by the
1174 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1175 * the srcpad's getcaps function is directly related to the stream data. Again,
1176 * @getcaps should return the most specific caps it reasonably can, since this
1177 * helps with autoplugging.
1179 * Note that the return value from @getcaps is owned by the caller, so the caller
1180 * should unref the caps after usage.
1183 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1185 g_return_if_fail (GST_IS_PAD (pad));
1187 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1188 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1189 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1193 * gst_pad_set_acceptcaps_function:
1195 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1197 * Sets the given acceptcaps function for the pad. The acceptcaps function
1198 * will be called to check if the pad can accept the given caps.
1201 gst_pad_set_acceptcaps_function (GstPad * pad,
1202 GstPadAcceptCapsFunction acceptcaps)
1204 g_return_if_fail (GST_IS_PAD (pad));
1206 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1207 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1208 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1212 * gst_pad_set_fixatecaps_function:
1214 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1216 * Sets the given fixatecaps function for the pad. The fixatecaps function
1217 * will be called whenever the default values for a GstCaps needs to be
1221 gst_pad_set_fixatecaps_function (GstPad * pad,
1222 GstPadFixateCapsFunction fixatecaps)
1224 g_return_if_fail (GST_IS_PAD (pad));
1226 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1227 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1228 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1232 * gst_pad_set_setcaps_function:
1234 * @setcaps: the #GstPadSetCapsFunction to set.
1236 * Sets the given setcaps function for the pad. The setcaps function
1237 * will be called whenever a buffer with a new media type is pushed or
1238 * pulled from the pad. The pad/element needs to update it's internal
1239 * structures to process the new media type. If this new type is not
1240 * acceptable, the setcaps function should return FALSE.
1243 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1245 g_return_if_fail (GST_IS_PAD (pad));
1247 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1248 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1249 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1253 * gst_pad_set_bufferalloc_function:
1254 * @pad: a sink #GstPad.
1255 * @bufalloc: the #GstPadBufferAllocFunction to set.
1257 * Sets the given bufferalloc function for the pad. Note that the
1258 * bufferalloc function can only be set on sinkpads.
1261 gst_pad_set_bufferalloc_function (GstPad * pad,
1262 GstPadBufferAllocFunction bufalloc)
1264 g_return_if_fail (GST_IS_PAD (pad));
1265 g_return_if_fail (GST_PAD_IS_SINK (pad));
1267 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1268 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1269 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1274 * @srcpad: the source #GstPad to unlink.
1275 * @sinkpad: the sink #GstPad to unlink.
1277 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1280 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1281 * the pads were not linked together.
1286 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1288 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1289 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1291 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1292 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1293 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1297 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1302 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1305 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1306 goto not_linked_together;
1308 if (GST_PAD_UNLINKFUNC (srcpad)) {
1309 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1311 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1312 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1315 /* first clear peers */
1316 GST_PAD_PEER (srcpad) = NULL;
1317 GST_PAD_PEER (sinkpad) = NULL;
1319 GST_UNLOCK (sinkpad);
1320 GST_UNLOCK (srcpad);
1322 /* fire off a signal to each of the pads telling them
1323 * that they've been unlinked */
1324 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1325 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1327 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1328 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1334 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1335 GST_UNLOCK (srcpad);
1340 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1341 GST_UNLOCK (sinkpad);
1342 GST_UNLOCK (srcpad);
1345 not_linked_together:
1347 /* we do not emit a warning in this case because unlinking cannot
1348 * be made MT safe.*/
1349 GST_UNLOCK (sinkpad);
1350 GST_UNLOCK (srcpad);
1356 * gst_pad_is_linked:
1357 * @pad: pad to check
1359 * Checks if a @pad is linked to another pad or not.
1361 * Returns: TRUE if the pad is linked, FALSE otherwise.
1366 gst_pad_is_linked (GstPad * pad)
1370 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1373 result = (GST_PAD_PEER (pad) != NULL);
1379 /* get the caps from both pads and see if the intersection
1382 * This function should be called with the pad LOCK on both
1386 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1391 srccaps = gst_pad_get_caps_unlocked (src);
1392 sinkcaps = gst_pad_get_caps_unlocked (sink);
1393 GST_CAT_DEBUG (GST_CAT_CAPS, " src caps %" GST_PTR_FORMAT, srccaps);
1394 GST_CAT_DEBUG (GST_CAT_CAPS, "sink caps %" GST_PTR_FORMAT, sinkcaps);
1396 /* if we have caps on both pads we can check the intersection */
1397 if (srccaps && sinkcaps) {
1400 icaps = gst_caps_intersect (srccaps, sinkcaps);
1401 gst_caps_unref (srccaps);
1402 gst_caps_unref (sinkcaps);
1404 GST_CAT_DEBUG (GST_CAT_CAPS,
1405 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1407 if (!icaps || gst_caps_is_empty (icaps)) {
1408 GST_CAT_DEBUG (GST_CAT_CAPS, "intersection is empty");
1409 gst_caps_unref (icaps);
1412 gst_caps_unref (icaps);
1418 /* check if the grandparents of both pads are the same.
1419 * This check is required so that we don't try to link
1420 * pads from elements in different bins without ghostpads.
1422 * The LOCK should be helt on both pads
1425 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1427 GstObject *psrc, *psink;
1428 gboolean res = TRUE;
1430 psrc = GST_OBJECT_PARENT (src);
1431 psink = GST_OBJECT_PARENT (sink);
1433 /* if one of the pads has no parent, we allow the link */
1434 if (psrc && psink) {
1435 /* if the parents are the same, we have a loop */
1436 if (psrc == psink) {
1437 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1442 /* if they both have a parent, we check the grandparents */
1443 psrc = gst_object_get_parent (psrc);
1444 psink = gst_object_get_parent (psink);
1446 if (psrc != psink) {
1447 /* if they have grandparents but they are not the same */
1448 GST_CAT_DEBUG (GST_CAT_CAPS,
1449 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1450 GST_PTR_FORMAT, psrc, psink);
1454 gst_object_unref (psrc);
1456 gst_object_unref (psink);
1462 /* FIXME leftover from an attempt at refactoring... */
1463 /* call with the two pads unlocked */
1464 static GstPadLinkReturn
1465 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1467 /* generic checks */
1468 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1469 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1471 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1472 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1476 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1479 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1480 goto src_was_linked;
1484 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1487 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1488 goto sink_was_linked;
1490 /* check hierarchy, pads can only be linked if the grandparents
1492 if (!gst_pad_link_check_hierarchy (srcpad, sinkpad))
1493 goto wrong_hierarchy;
1495 /* check pad caps for non-empty intersection */
1496 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad))
1499 /* FIXME check pad scheduling for non-empty intersection */
1501 return GST_PAD_LINK_OK;
1505 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1506 GST_UNLOCK (srcpad);
1507 return GST_PAD_LINK_WRONG_DIRECTION;
1511 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was linked",
1512 GST_DEBUG_PAD_NAME (srcpad));
1513 /* we do not emit a warning in this case because unlinking cannot
1514 * be made MT safe.*/
1515 GST_UNLOCK (srcpad);
1516 return GST_PAD_LINK_WAS_LINKED;
1520 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1521 GST_UNLOCK (sinkpad);
1522 GST_UNLOCK (srcpad);
1523 return GST_PAD_LINK_WRONG_DIRECTION;
1527 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was linked",
1528 GST_DEBUG_PAD_NAME (sinkpad));
1529 /* we do not emit a warning in this case because unlinking cannot
1530 * be made MT safe.*/
1531 GST_UNLOCK (sinkpad);
1532 GST_UNLOCK (srcpad);
1533 return GST_PAD_LINK_WAS_LINKED;
1537 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1538 GST_UNLOCK (sinkpad);
1539 GST_UNLOCK (srcpad);
1540 return GST_PAD_LINK_WRONG_HIERARCHY;
1544 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1545 GST_UNLOCK (sinkpad);
1546 GST_UNLOCK (srcpad);
1547 return GST_PAD_LINK_NOFORMAT;
1553 * @srcpad: the source #GstPad to link.
1554 * @sinkpad: the sink #GstPad to link.
1556 * Links the source pad and the sink pad.
1558 * Returns: A result code indicating if the connection worked or
1564 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1566 GstPadLinkReturn result;
1568 /* prepare will also lock the two pads */
1569 result = gst_pad_link_prepare (srcpad, sinkpad);
1571 if (result != GST_PAD_LINK_OK)
1572 goto prepare_failed;
1574 GST_UNLOCK (sinkpad);
1575 GST_UNLOCK (srcpad);
1577 /* FIXME released the locks here, concurrent thread might link
1578 * something else. */
1579 if (GST_PAD_LINKFUNC (srcpad)) {
1580 /* this one will call the peer link function */
1581 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1582 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1583 /* if no source link function, we need to call the sink link
1584 * function ourselves. */
1585 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1587 result = GST_PAD_LINK_OK;
1593 if (result == GST_PAD_LINK_OK) {
1594 GST_PAD_PEER (srcpad) = sinkpad;
1595 GST_PAD_PEER (sinkpad) = srcpad;
1597 GST_UNLOCK (sinkpad);
1598 GST_UNLOCK (srcpad);
1600 /* fire off a signal to each of the pads telling them
1601 * that they've been linked */
1602 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1603 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1605 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1606 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1608 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1609 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1611 GST_UNLOCK (sinkpad);
1612 GST_UNLOCK (srcpad);
1623 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1625 /* this function would need checks if it weren't static */
1628 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1632 gst_object_sink (GST_OBJECT (templ));
1633 g_signal_emit (G_OBJECT (templ),
1634 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1639 * gst_pad_get_pad_template:
1642 * Gets the template for @pad.
1644 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1645 * if this pad has no template.
1647 * FIXME: currently returns an unrefcounted padtemplate.
1650 gst_pad_get_pad_template (GstPad * pad)
1652 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1654 return GST_PAD_PAD_TEMPLATE (pad);
1658 /* should be called with the pad LOCK held */
1659 /* refs the caps, so caller is responsible for getting it unreffed */
1661 gst_pad_get_caps_unlocked (GstPad * pad)
1663 GstCaps *result = NULL;
1665 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1666 GST_DEBUG_PAD_NAME (pad), pad);
1668 if (GST_PAD_GETCAPSFUNC (pad)) {
1669 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1671 GST_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1673 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1675 GST_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1677 if (result == NULL) {
1678 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1679 GST_DEBUG_PAD_NAME (pad));
1681 GST_CAT_DEBUG (GST_CAT_CAPS,
1682 "pad getcaps %s:%s returned %" GST_PTR_FORMAT,
1683 GST_DEBUG_PAD_NAME (pad), result);
1684 #ifndef G_DISABLE_ASSERT
1685 /* check that the returned caps are a real subset of the template caps */
1686 if (GST_PAD_PAD_TEMPLATE (pad)) {
1687 const GstCaps *templ_caps =
1688 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1689 if (!gst_caps_is_subset (result, templ_caps)) {
1692 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1693 "pad returned caps %" GST_PTR_FORMAT
1694 " which are not a real subset of its template caps %"
1695 GST_PTR_FORMAT, result, templ_caps);
1697 ("pad %s:%s returned caps that are not a real subset of its template caps",
1698 GST_DEBUG_PAD_NAME (pad));
1699 temp = gst_caps_intersect (templ_caps, result);
1700 gst_caps_unref (result);
1708 if (GST_PAD_PAD_TEMPLATE (pad)) {
1709 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1711 result = GST_PAD_TEMPLATE_CAPS (templ);
1712 GST_CAT_DEBUG (GST_CAT_CAPS,
1713 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1716 result = gst_caps_ref (result);
1719 if (GST_PAD_CAPS (pad)) {
1720 result = GST_PAD_CAPS (pad);
1722 GST_CAT_DEBUG (GST_CAT_CAPS,
1723 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1725 result = gst_caps_ref (result);
1729 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1730 result = gst_caps_new_empty ();
1738 * @pad: a #GstPad to get the capabilities of.
1740 * Gets the capabilities this pad can produce or consume.
1741 * Note that this method doesn't necessarily returns the caps set by
1742 * #gst_pad_set_caps - use #GST_PAD_CAPS for that instead.
1743 * gst_pad_get_caps returns all possible caps a pad can operate with, using
1744 * the pad's get_caps function;
1745 * this returns the pad template caps if not explicitly set.
1747 * Returns: a newly allocated copy of the #GstCaps of this pad.
1752 gst_pad_get_caps (GstPad * pad)
1754 GstCaps *result = NULL;
1756 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1760 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1761 GST_DEBUG_PAD_NAME (pad), pad);
1763 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (pad)))
1764 goto was_dispatching;
1766 result = gst_pad_get_caps_unlocked (pad);
1773 GST_CAT_DEBUG (GST_CAT_CAPS,
1774 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1775 g_warning ("pad %s:%s recursively called getcaps!",
1776 GST_DEBUG_PAD_NAME (pad));
1783 * gst_pad_peer_get_caps:
1784 * @pad: a #GstPad to get the peer capabilities of.
1786 * Gets the capabilities of the peer connected to this pad.
1788 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1789 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1790 * peer pad or when this function is called recursively from a getcaps function.
1793 gst_pad_peer_get_caps (GstPad * pad)
1796 GstCaps *result = NULL;
1798 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1802 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1803 GST_DEBUG_PAD_NAME (pad), pad);
1805 peerpad = GST_PAD_PEER (pad);
1806 if (G_UNLIKELY (peerpad == NULL))
1809 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (peerpad)))
1810 goto was_dispatching;
1812 gst_object_ref (peerpad);
1815 result = gst_pad_get_caps (peerpad);
1817 gst_object_unref (peerpad);
1828 GST_CAT_DEBUG (GST_CAT_CAPS,
1829 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1830 g_warning ("pad %s:%s recursively called getcaps!",
1831 GST_DEBUG_PAD_NAME (pad));
1838 fixate_value (GValue * dest, const GValue * src)
1840 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
1841 g_value_init (dest, G_TYPE_INT);
1842 g_value_set_int (dest, gst_value_get_int_range_min (src));
1843 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
1844 g_value_init (dest, G_TYPE_DOUBLE);
1845 g_value_set_double (dest, gst_value_get_double_range_min (src));
1846 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
1847 GValue temp = { 0 };
1849 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
1850 if (!fixate_value (dest, &temp))
1851 gst_value_init_and_copy (dest, &temp);
1852 g_value_unset (&temp);
1853 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
1854 gboolean res = FALSE;
1857 g_value_init (dest, GST_TYPE_ARRAY);
1858 for (n = 0; n < gst_value_list_get_size (src); n++) {
1860 const GValue *orig_kid = gst_value_list_get_value (src, n);
1862 if (!fixate_value (&kid, orig_kid))
1863 gst_value_init_and_copy (&kid, orig_kid);
1866 gst_value_list_append_value (dest, &kid);
1867 g_value_unset (&kid);
1871 g_value_unset (dest);
1882 gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data)
1884 GstStructure *s = data;
1887 if (fixate_value (&v, value)) {
1888 gst_structure_id_set_value (s, field_id, &v);
1896 * gst_pad_fixate_caps:
1897 * @pad: a #GstPad to fixate
1898 * @caps: the #GstCaps to fixate
1900 * Fixate a caps on the given pad. Modifies the caps in place, so you should
1901 * make sure that the caps are actually writable (see gst_caps_make_writable()).
1904 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
1906 GstPadFixateCapsFunction fixatefunc;
1909 g_return_if_fail (GST_IS_PAD (pad));
1910 g_return_if_fail (caps != NULL);
1912 if (gst_caps_is_fixed (caps))
1915 fixatefunc = GST_PAD_FIXATECAPSFUNC (pad);
1917 fixatefunc (pad, caps);
1920 /* default fixation */
1921 for (n = 0; n < gst_caps_get_size (caps); n++) {
1922 GstStructure *s = gst_caps_get_structure (caps, n);
1924 gst_structure_foreach (s, gst_pad_default_fixate, s);
1929 * gst_pad_accept_caps:
1930 * @pad: a #GstPad to check
1932 * Check if the given pad accepts the caps.
1934 * Returns: TRUE if the pad can accept the caps.
1937 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
1940 GstPadAcceptCapsFunction acceptfunc;
1942 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1944 /* any pad can be unnegotiated */
1949 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
1951 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
1952 GST_DEBUG_PAD_NAME (pad), pad);
1956 /* we can call the function */
1957 result = acceptfunc (pad, caps);
1959 /* else see get the caps and see if it intersects to something
1964 allowed = gst_pad_get_caps (pad);
1966 intersect = gst_caps_intersect (allowed, caps);
1968 result = !gst_caps_is_empty (intersect);
1970 gst_caps_unref (allowed);
1971 gst_caps_unref (intersect);
1980 * gst_pad_peer_accept_caps:
1981 * @pad: a #GstPad to check
1983 * Check if the given pad accepts the caps.
1985 * Returns: TRUE if the pad can accept the caps.
1988 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
1993 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1997 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
1998 GST_DEBUG_PAD_NAME (pad), pad);
2000 peerpad = GST_PAD_PEER (pad);
2001 if (G_UNLIKELY (peerpad == NULL))
2004 result = gst_pad_accept_caps (peerpad, caps);
2018 * @pad: a #GstPad to set the capabilities of.
2019 * @caps: a #GstCaps to set.
2021 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2022 * caps on the pad will be unreffed. This function refs the caps so you should
2023 * unref if as soon as you don't need it anymore.
2024 * It is possible to set NULL caps, which will make the pad unnegotiated
2027 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2028 * or bad parameters were provided to this function.
2033 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2035 GstPadSetCapsFunction setcaps;
2038 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2039 g_return_val_if_fail (caps == NULL || gst_caps_is_fixed (caps), FALSE);
2042 setcaps = GST_PAD_SETCAPSFUNC (pad);
2044 existing = GST_PAD_CAPS (pad);
2045 if (caps == existing)
2046 goto setting_same_caps;
2047 else if (caps && existing && gst_caps_is_equal (caps, existing))
2048 goto setting_same_caps;
2050 /* call setcaps function to configure the pad */
2051 if (setcaps != NULL && caps) {
2052 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
2053 GST_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
2055 if (!setcaps (pad, caps))
2058 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2060 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
2061 GST_DEBUG_PAD_NAME (pad));
2065 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2066 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
2067 GST_DEBUG_PAD_NAME (pad), caps);
2070 g_object_notify (G_OBJECT (pad), "caps");
2077 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
2078 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2079 "caps %" GST_PTR_FORMAT " same as existing, updating ptr only", caps);
2086 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
2087 GST_CAT_DEBUG (GST_CAT_CAPS,
2088 "pad %s:%s, caps %" GST_PTR_FORMAT " could not be set",
2089 GST_DEBUG_PAD_NAME (pad), caps);
2097 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
2099 GstPadAcceptCapsFunction acceptcaps;
2100 GstPadSetCapsFunction setcaps;
2103 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2104 setcaps = GST_PAD_SETCAPSFUNC (pad);
2106 /* See if pad accepts the caps, by calling acceptcaps, only
2107 * needed if no setcaps function */
2108 if (setcaps == NULL && acceptcaps != NULL) {
2109 if (!acceptcaps (pad, caps))
2112 /* set caps on pad if call succeeds */
2113 res = gst_pad_set_caps (pad, caps);
2114 /* no need to unref the caps here, set_caps takes a ref and
2115 * our ref goes away when we leave this function. */
2121 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2126 /* returns TRUE if the src pad could be configured to accept the given caps */
2128 gst_pad_configure_src (GstPad * pad, GstCaps * caps)
2130 GstPadAcceptCapsFunction acceptcaps;
2131 GstPadSetCapsFunction setcaps;
2134 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
2135 setcaps = GST_PAD_SETCAPSFUNC (pad);
2137 /* See if pad accepts the caps, by calling acceptcaps, only
2138 * needed if no setcaps function */
2139 if (setcaps == NULL && acceptcaps != NULL) {
2140 if (!acceptcaps (pad, caps))
2143 /* set caps on pad if call succeeds */
2144 res = gst_pad_set_caps (pad, caps);
2145 /* no need to unref the caps here, set_caps takes a ref and
2146 * our ref goes away when we leave this function. */
2152 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
2158 * gst_pad_get_pad_template_caps:
2159 * @pad: a #GstPad to get the template capabilities from.
2161 * Gets the capabilities for @pad's template.
2163 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2164 * on the caps, make a copy (see gst_caps_copy ()).
2167 gst_pad_get_pad_template_caps (GstPad * pad)
2169 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2171 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2173 if (GST_PAD_PAD_TEMPLATE (pad))
2174 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2176 return gst_static_caps_get (&anycaps);
2182 * @pad: a #GstPad to get the peer of.
2184 * Gets the peer of @pad. This function refs the peer pad so
2185 * you need to unref it after use.
2187 * Returns: the peer #GstPad. Unref after usage.
2192 gst_pad_get_peer (GstPad * pad)
2196 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2199 result = GST_PAD_PEER (pad);
2201 gst_object_ref (result);
2208 * gst_pad_get_allowed_caps:
2209 * @srcpad: a #GstPad, it must a a source pad.
2211 * Gets the capabilities of the allowed media types that can flow through
2212 * @srcpad and its peer. The pad must be a source pad.
2213 * The caller must free the resulting caps.
2215 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2216 * you no longer need it. This function returns NULL when the @srcpad has no
2222 gst_pad_get_allowed_caps (GstPad * srcpad)
2229 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2230 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2234 peer = GST_PAD_PEER (srcpad);
2235 if (G_UNLIKELY (peer == NULL))
2238 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2239 GST_DEBUG_PAD_NAME (srcpad));
2241 gst_object_ref (peer);
2242 GST_UNLOCK (srcpad);
2243 mycaps = gst_pad_get_caps (srcpad);
2245 peercaps = gst_pad_get_caps (peer);
2246 gst_object_unref (peer);
2248 caps = gst_caps_intersect (mycaps, peercaps);
2249 gst_caps_unref (peercaps);
2250 gst_caps_unref (mycaps);
2252 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2258 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2259 GST_DEBUG_PAD_NAME (srcpad));
2260 GST_UNLOCK (srcpad);
2267 * gst_pad_get_negotiated_caps:
2270 * Gets the capabilities of the media type that currently flows through @pad
2273 * This function can be used on both src and sinkpads. Note that srcpads are
2274 * always negotiated before sinkpads so it is possible that the negotiated caps
2275 * on the srcpad do not match the negotiated caps of the peer.
2277 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2278 * you no longer need it. This function returns NULL when the @pad has no
2279 * peer or is not negotiated yet.
2284 gst_pad_get_negotiated_caps (GstPad * pad)
2289 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2293 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2296 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2297 GST_DEBUG_PAD_NAME (pad));
2299 caps = GST_PAD_CAPS (pad);
2301 gst_caps_ref (caps);
2304 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2310 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2311 GST_DEBUG_PAD_NAME (pad));
2319 * gst_pad_alloc_buffer:
2320 * @pad: a source #GstPad
2321 * @offset: the offset of the new buffer in the stream
2322 * @size: the size of the new buffer
2323 * @caps: the caps of the new buffer
2324 * @buf: a newly allocated buffer
2326 * Allocates a new, empty buffer optimized to push to pad @pad. This
2327 * function only works if @pad is a source pad and has a peer.
2329 * You need to check the caps of the buffer after performing this
2330 * function and renegotiate to the format if needed.
2332 * A new, empty #GstBuffer will be put in the @buf argument.
2334 * Returns: a result code indicating success of the operation. Any
2335 * result code other than GST_FLOW_OK is an error and @buf should
2337 * An error can occur if the pad is not connected or when the downstream
2338 * peer elements cannot provide an acceptable buffer.
2343 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2348 GstPadBufferAllocFunction bufferallocfunc;
2349 gboolean caps_changed;
2351 GST_DEBUG_OBJECT (pad, "offset %" G_GUINT64_FORMAT, offset);
2353 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2354 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2355 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2358 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2361 gst_object_ref (peer);
2364 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2368 /* when the peer is flushing we cannot give a buffer */
2369 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2372 GST_CAT_DEBUG (GST_CAT_PADS,
2373 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s for size %d ...",
2374 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2375 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer), size);
2376 if (offset == GST_BUFFER_OFFSET_NONE)
2377 GST_CAT_DEBUG (GST_CAT_PADS, "... and offset NONE");
2379 GST_CAT_DEBUG (GST_CAT_PADS, "... and offset %" G_GUINT64_FORMAT, offset);
2382 ret = bufferallocfunc (peer, offset, size, caps, buf);
2384 if (G_UNLIKELY (ret != GST_FLOW_OK))
2386 if (G_UNLIKELY (*buf == NULL))
2389 /* If the buffer alloc function didn't set up the caps like it should,
2391 if (caps && (GST_BUFFER_CAPS (*buf) == NULL)) {
2392 GST_WARNING ("Buffer allocation function for pad % " GST_PTR_FORMAT
2393 " did not set up caps. Setting", peer);
2395 gst_buffer_set_caps (*buf, caps);
2399 gst_object_unref (peer);
2401 /* FIXME, move capnego this into a base class? */
2402 caps = GST_BUFFER_CAPS (*buf);
2403 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2404 /* we got a new datatype on the pad, see if it can handle it */
2405 if (G_UNLIKELY (caps_changed)) {
2406 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2407 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps)))
2408 goto not_negotiated;
2414 /* pad has no peer */
2415 GST_CAT_DEBUG (GST_CAT_PADS,
2416 "%s:%s called bufferallocfunc but had no peer",
2417 GST_DEBUG_PAD_NAME (pad));
2419 return GST_FLOW_NOT_LINKED;
2423 /* peer was flushing */
2425 gst_object_unref (peer);
2426 GST_CAT_DEBUG (GST_CAT_PADS,
2427 "%s:%s called bufferallocfunc but peer was flushing",
2428 GST_DEBUG_PAD_NAME (pad));
2429 return GST_FLOW_WRONG_STATE;
2431 /* fallback case, allocate a buffer of our own, add pad caps. */
2434 GST_CAT_DEBUG (GST_CAT_PADS,
2435 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2436 *buf = gst_buffer_new_and_alloc (size);
2437 GST_BUFFER_OFFSET (*buf) = offset;
2438 gst_buffer_set_caps (*buf, caps);
2446 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2447 "alloc function retured unacceptable buffer");
2448 return GST_FLOW_NOT_NEGOTIATED;
2452 gst_object_unref (peer);
2453 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2454 "alloc function retured error %d", ret);
2460 * gst_pad_get_internal_links_default:
2461 * @pad: the #GstPad to get the internal links of.
2463 * Gets a list of pads to which the given pad is linked to
2464 * inside of the parent element.
2465 * This is the default handler, and thus returns a list of all of the
2466 * pads inside the parent element with opposite direction.
2467 * The caller must free this list after use.
2469 * Returns: a newly allocated #GList of pads, or NULL if the pad has no parent.
2474 gst_pad_get_internal_links_default (GstPad * pad)
2479 GstPadDirection direction;
2481 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2483 direction = pad->direction;
2485 parent = GST_PAD_PARENT (pad);
2489 parent_pads = parent->pads;
2491 while (parent_pads) {
2492 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2494 if (parent_pad->direction != direction) {
2495 res = g_list_prepend (res, parent_pad);
2498 parent_pads = g_list_next (parent_pads);
2505 * gst_pad_get_internal_links:
2506 * @pad: the #GstPad to get the internal links of.
2508 * Gets a list of pads to which the given pad is linked to
2509 * inside of the parent element.
2510 * The caller must free this list after use.
2512 * Returns: a newly allocated #GList of pads.
2517 gst_pad_get_internal_links (GstPad * pad)
2521 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2523 if (GST_PAD_INTLINKFUNC (pad))
2524 res = GST_PAD_INTLINKFUNC (pad) (pad);
2531 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2536 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2539 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2541 orig = pads = gst_pad_get_internal_links (pad);
2544 GstPad *eventpad = GST_PAD_CAST (pads->data);
2546 pads = g_list_next (pads);
2548 /* for all of the internally-linked pads that are actually linked */
2549 if (GST_PAD_IS_LINKED (eventpad)) {
2550 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2551 /* for each pad we send to, we should ref the event; it's up
2552 * to downstream to unref again when handled. */
2553 GST_LOG_OBJECT (pad, "Reffing and sending event %p to %s:%s", event,
2554 GST_DEBUG_PAD_NAME (eventpad));
2555 gst_event_ref (event);
2556 gst_pad_push_event (eventpad, event);
2558 /* we only send the event on one pad, multi-sinkpad elements
2559 * should implement a handler */
2560 GST_LOG_OBJECT (pad, "sending event %p to one sink pad %s:%s", event,
2561 GST_DEBUG_PAD_NAME (eventpad));
2562 result = gst_pad_push_event (eventpad, event);
2567 /* we handled the incoming event so we unref once */
2568 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2569 gst_event_unref (event);
2578 * gst_pad_event_default:
2579 * @pad: a #GstPad to call the default event handler on.
2580 * @event: the #GstEvent to handle.
2582 * Invokes the default event handler for the given pad. End-of-stream and
2583 * discontinuity events are handled specially, and then the event is sent to all
2584 * pads internally linked to @pad. Note that if there are many possible sink
2585 * pads that are internally linked to @pad, only one will be sent an event.
2586 * Multi-sinkpad elements should implement custom event handlers.
2588 * Returns: TRUE if the event was sent succesfully.
2591 gst_pad_event_default (GstPad * pad, GstEvent * event)
2593 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2594 g_return_val_if_fail (event != NULL, FALSE);
2596 switch (GST_EVENT_TYPE (event)) {
2599 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2600 gst_pad_pause_task (pad);
2606 return gst_pad_event_default_dispatch (pad, event);
2610 * gst_pad_dispatcher:
2611 * @pad: a #GstPad to dispatch.
2612 * @dispatch: the #GstDispatcherFunction to call.
2613 * @data: gpointer user data passed to the dispatcher function.
2615 * Invokes the given dispatcher function on all pads that are
2616 * internally linked to the given pad.
2617 * The GstPadDispatcherFunction should return TRUE when no further pads
2618 * need to be processed.
2620 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2623 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2626 gboolean res = FALSE;
2627 GList *int_pads, *orig;
2629 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2630 g_return_val_if_fail (dispatch != NULL, FALSE);
2632 orig = int_pads = gst_pad_get_internal_links (pad);
2635 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2636 GstPad *int_peer = GST_PAD_PEER (int_pad);
2639 res = dispatch (int_peer, data);
2643 int_pads = g_list_next (int_pads);
2653 * @pad: a #GstPad to invoke the default query on.
2654 * @query: the #GstQuery to perform.
2656 * Dispatches a query to a pad. The query should have been allocated by the
2657 * caller via one of the type-specific allocation functions in gstquery.h. The
2658 * element is responsible for filling the query with an appropriate response,
2659 * which should then be parsed with a type-specific query parsing function.
2661 * Again, the caller is responsible for both the allocation and deallocation of
2662 * the query structure.
2664 * Returns: TRUE if the query could be performed.
2667 gst_pad_query (GstPad * pad, GstQuery * query)
2669 GstPadQueryFunction func;
2671 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2672 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2674 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2676 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2679 return func (pad, query);
2683 GST_DEBUG ("pad had no query function");
2689 gst_pad_query_default (GstPad * pad, GstQuery * query)
2691 switch (GST_QUERY_TYPE (query)) {
2692 case GST_QUERY_POSITION:
2693 case GST_QUERY_SEEKING:
2694 case GST_QUERY_FORMATS:
2695 case GST_QUERY_LATENCY:
2696 case GST_QUERY_JITTER:
2697 case GST_QUERY_RATE:
2698 case GST_QUERY_CONVERT:
2700 return gst_pad_dispatcher
2701 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2705 #ifndef GST_DISABLE_LOADSAVE
2706 /* FIXME: why isn't this on a GstElement ? */
2708 * gst_pad_load_and_link:
2709 * @self: an #xmlNodePtr to read the description from.
2710 * @parent: the #GstObject element that owns the pad.
2712 * Reads the pad definition from the XML node and links the given pad
2713 * in the element to a pad of an element up in the hierarchy.
2716 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2718 xmlNodePtr field = self->xmlChildrenNode;
2719 GstPad *pad = NULL, *targetpad;
2723 GstObject *grandparent;
2727 if (!strcmp ((char *) field->name, "name")) {
2728 name = (gchar *) xmlNodeGetContent (field);
2729 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2731 } else if (!strcmp ((char *) field->name, "peer")) {
2732 peer = (gchar *) xmlNodeGetContent (field);
2734 field = field->next;
2736 g_return_if_fail (pad != NULL);
2741 split = g_strsplit (peer, ".", 2);
2743 if (split[0] == NULL || split[1] == NULL) {
2744 GST_CAT_DEBUG (GST_CAT_XML,
2745 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2746 peer, GST_DEBUG_PAD_NAME (pad));
2753 g_return_if_fail (split[0] != NULL);
2754 g_return_if_fail (split[1] != NULL);
2756 grandparent = gst_object_get_parent (parent);
2758 if (grandparent && GST_IS_BIN (grandparent)) {
2759 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2766 targetpad = gst_element_get_pad (target, split[1]);
2768 if (targetpad == NULL)
2771 gst_pad_link (pad, targetpad);
2778 * gst_pad_save_thyself:
2779 * @pad: a #GstPad to save.
2780 * @parent: the parent #xmlNodePtr to save the description in.
2782 * Saves the pad into an xml representation.
2784 * Returns: the #xmlNodePtr representation of the pad.
2787 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2792 g_return_val_if_fail (GST_IS_PAD (object), NULL);
2794 pad = GST_PAD (object);
2796 xmlNewChild (parent, NULL, (xmlChar *) "name",
2797 (xmlChar *) GST_PAD_NAME (pad));
2798 if (GST_PAD_PEER (pad) != NULL) {
2801 peer = GST_PAD_PEER (pad);
2802 /* first check to see if the peer's parent's parent is the same */
2803 /* we just save it off */
2804 content = g_strdup_printf ("%s.%s",
2805 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2806 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
2809 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
2816 * gst_ghost_pad_save_thyself:
2817 * @pad: a ghost #GstPad to save.
2818 * @parent: the parent #xmlNodePtr to save the description in.
2820 * Saves the ghost pad into an xml representation.
2822 * Returns: the #xmlNodePtr representation of the pad.
2825 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2829 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2831 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
2832 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
2833 xmlNewChild (self, NULL, (xmlChar *) "parent",
2834 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2836 /* FIXME FIXME FIXME! */
2841 #endif /* GST_DISABLE_LOADSAVE */
2844 * should be called with pad lock held
2849 handle_pad_block (GstPad * pad)
2851 GstPadBlockCallback callback;
2854 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2855 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2857 /* need to grab extra ref for the callbacks */
2858 gst_object_ref (pad);
2860 callback = pad->block_callback;
2862 user_data = pad->block_data;
2864 callback (pad, TRUE, user_data);
2867 GST_PAD_BLOCK_SIGNAL (pad);
2870 while (GST_PAD_IS_BLOCKED (pad))
2871 GST_PAD_BLOCK_WAIT (pad);
2873 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
2875 callback = pad->block_callback;
2877 user_data = pad->block_data;
2879 callback (pad, FALSE, user_data);
2882 GST_PAD_BLOCK_SIGNAL (pad);
2885 gst_object_unref (pad);
2888 /**********************************************************************
2889 * Data passing functions
2893 gst_pad_emit_have_data_signal (GstPad * pad, GstMiniObject * obj)
2896 GValue args[2] = { {0}, {0} };
2901 g_value_init (&ret, G_TYPE_BOOLEAN);
2902 g_value_set_boolean (&ret, TRUE);
2903 g_value_init (&args[0], GST_TYPE_PAD);
2904 g_value_set_object (&args[0], pad);
2905 g_value_init (&args[1], GST_TYPE_MINI_OBJECT); // G_TYPE_POINTER);
2906 gst_value_set_mini_object (&args[1], obj);
2908 if (GST_IS_EVENT (obj))
2909 detail = event_quark;
2911 detail = buffer_quark;
2914 g_signal_emitv (args, gst_pad_signals[PAD_HAVE_DATA], detail, &ret);
2915 res = g_value_get_boolean (&ret);
2918 g_value_unset (&ret);
2919 g_value_unset (&args[0]);
2920 g_value_unset (&args[1]);
2927 * @pad: a sink #GstPad.
2928 * @buffer: the #GstBuffer to send.
2930 * Chain a buffer to @pad.
2932 * Returns: a #GstFlowReturn from the pad.
2937 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
2940 gboolean caps_changed;
2941 GstPadChainFunction chainfunc;
2943 gboolean emit_signal;
2945 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2946 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2948 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2949 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2951 GST_STREAM_LOCK (pad);
2954 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2957 caps = GST_BUFFER_CAPS (buffer);
2958 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2960 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
2963 /* see if the signal should be emited, we emit before caps nego as
2964 * we might drop the buffer and do capsnego for nothing. */
2965 if (G_UNLIKELY (emit_signal)) {
2966 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
2970 /* we got a new datatype on the pad, see if it can handle it */
2971 if (G_UNLIKELY (caps_changed)) {
2972 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2973 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
2974 goto not_negotiated;
2977 /* NOTE: we read the chainfunc unlocked.
2978 * we cannot hold the lock for the pad so we might send
2979 * the data to the wrong function. This is not really a
2980 * problem since functions are assigned at creation time
2981 * and don't change that often... */
2982 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
2985 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2986 "calling chainfunction &%s of pad %s:%s",
2987 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
2989 ret = chainfunc (pad, buffer);
2991 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2992 "called chainfunction &%s of pad %s:%s, returned %d",
2993 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad), ret);
2995 GST_STREAM_UNLOCK (pad);
3002 gst_buffer_unref (buffer);
3003 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3004 "pushing, but pad was flushing");
3006 GST_STREAM_UNLOCK (pad);
3007 return GST_FLOW_WRONG_STATE;
3011 gst_buffer_unref (buffer);
3012 GST_DEBUG ("Dropping buffer due to FALSE probe return");
3013 GST_STREAM_UNLOCK (pad);
3018 gst_buffer_unref (buffer);
3019 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3020 "pushing buffer but pad did not accept");
3021 GST_STREAM_UNLOCK (pad);
3022 return GST_FLOW_NOT_NEGOTIATED;
3026 gst_buffer_unref (buffer);
3027 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3028 "pushing, but not chainhandler");
3029 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3030 ("push on pad %s:%s but it has no chainfunction",
3031 GST_DEBUG_PAD_NAME (pad)));
3032 GST_STREAM_UNLOCK (pad);
3033 return GST_FLOW_ERROR;
3039 * @pad: a source #GstPad.
3040 * @buffer: the #GstBuffer to push.
3042 * Pushes a buffer to the peer of @pad. @pad must be linked.
3044 * Returns: a #GstFlowReturn from the peer pad.
3049 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3053 gboolean emit_signal;
3055 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3056 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3057 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3058 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3061 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3062 handle_pad_block (pad);
3064 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3067 /* we emit signals on the pad areg, the peer will have a chance to
3068 * emit in the _chain() function */
3069 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3071 gst_object_ref (peer);
3074 if (G_UNLIKELY (emit_signal)) {
3075 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (buffer)))
3079 ret = gst_pad_chain (peer, buffer);
3081 gst_object_unref (peer);
3085 /* ERROR recovery here */
3088 gst_buffer_unref (buffer);
3089 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3090 "pushing, but it was not linked");
3092 return GST_FLOW_NOT_LINKED;
3096 gst_buffer_unref (buffer);
3097 gst_object_unref (peer);
3098 GST_DEBUG ("Dropping buffer due to FALSE probe return");
3104 * gst_pad_check_pull_range:
3105 * @pad: a sink #GstPad.
3107 * Checks if a #gst_pad_pull_range() can be performed on the peer
3108 * source pad. This function is used by plugins that want to check
3109 * if they can use random access on the peer source pad.
3111 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
3112 * if it needs to perform some logic to determine if pull_range is
3115 * Returns: a gboolean with the result.
3120 gst_pad_check_pull_range (GstPad * pad)
3124 GstPadCheckGetRangeFunction checkgetrangefunc;
3126 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3129 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
3130 goto wrong_direction;
3132 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3135 gst_object_ref (peer);
3138 /* see note in above function */
3139 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
3140 /* FIXME, kindoff ghetto */
3141 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
3143 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3144 "calling checkgetrangefunc %s of peer pad %s:%s",
3145 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
3147 ret = checkgetrangefunc (peer);
3150 gst_object_unref (peer);
3154 /* ERROR recovery here */
3162 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3163 "checking pull range, but it was not linked");
3170 * gst_pad_get_range:
3171 * @pad: a src #GstPad.
3172 * @offset: The start offset of the buffer
3173 * @size: The length of the buffer
3174 * @buffer: a pointer to hold the #GstBuffer.
3176 * Calls the getrange function of @pad.
3178 * Returns: a #GstFlowReturn from the pad.
3183 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3184 GstBuffer ** buffer)
3187 GstPadGetRangeFunction getrangefunc;
3188 gboolean emit_signal;
3190 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3191 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
3192 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3194 GST_STREAM_LOCK (pad);
3197 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3200 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3203 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3206 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3207 "calling getrangefunc %s of peer pad %s:%s, offset %"
3208 G_GUINT64_FORMAT ", size %u",
3209 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
3212 ret = getrangefunc (pad, offset, size, buffer);
3214 /* can only fire the signal if we have a valid buffer */
3215 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3216 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3220 GST_STREAM_UNLOCK (pad);
3227 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3228 "pulling range, but pad was flushing");
3230 GST_STREAM_UNLOCK (pad);
3231 return GST_FLOW_WRONG_STATE;
3235 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3236 ("pullrange on pad %s:%s but it has no getrangefunction",
3237 GST_DEBUG_PAD_NAME (pad)));
3238 GST_STREAM_UNLOCK (pad);
3239 return GST_FLOW_ERROR;
3243 GST_DEBUG ("Dropping data after FALSE probe return");
3244 GST_STREAM_UNLOCK (pad);
3245 gst_buffer_unref (*buffer);
3247 return GST_FLOW_UNEXPECTED;
3253 * gst_pad_pull_range:
3254 * @pad: a sink #GstPad.
3255 * @offset: The start offset of the buffer
3256 * @size: The length of the buffer
3257 * @buffer: a pointer to hold the #GstBuffer.
3259 * Pulls a buffer from the peer pad. @pad must be linked.
3261 * Returns: a #GstFlowReturn from the peer pad.
3266 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3267 GstBuffer ** buffer)
3271 gboolean emit_signal;
3273 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3274 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3276 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3280 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
3281 handle_pad_block (pad);
3283 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3286 /* signal emision for the pad, peer has chance to emit when
3287 * we call _get_range() */
3288 emit_signal = GST_PAD_DO_BUFFER_SIGNALS (pad) > 0;
3290 gst_object_ref (peer);
3293 ret = gst_pad_get_range (peer, offset, size, buffer);
3295 gst_object_unref (peer);
3297 /* can only fire the signal if we have a valid buffer */
3298 if (G_UNLIKELY (emit_signal) && (ret == GST_FLOW_OK)) {
3299 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (*buffer)))
3304 /* ERROR recovery here */
3307 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3308 "pulling range, but it was not linked");
3310 return GST_FLOW_NOT_LINKED;
3314 GST_DEBUG ("Dropping data after FALSE probe return");
3315 gst_buffer_unref (*buffer);
3317 return GST_FLOW_UNEXPECTED;
3322 * gst_pad_push_event:
3323 * @pad: a #GstPad to push the event to.
3324 * @event: the #GstEvent to send to the pad.
3326 * Sends the event to the peer of the given pad. This function is
3327 * mainly used by elements to send events to their peer
3330 * Returns: TRUE if the event was handled.
3335 gst_pad_push_event (GstPad * pad, GstEvent * event)
3339 gboolean emit_signal;
3341 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3342 g_return_val_if_fail (event != NULL, FALSE);
3345 peerpad = GST_PAD_PEER (pad);
3346 if (peerpad == NULL)
3349 emit_signal = GST_PAD_DO_EVENT_SIGNALS (pad) > 0;
3351 gst_object_ref (peerpad);
3354 if (G_UNLIKELY (emit_signal)) {
3355 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3359 result = gst_pad_send_event (peerpad, event);
3361 gst_object_unref (peerpad);
3365 /* ERROR handling */
3368 gst_event_unref (event);
3374 GST_DEBUG ("Dropping event after FALSE probe return");
3375 gst_object_unref (peerpad);
3376 gst_event_unref (event);
3382 * gst_pad_send_event:
3383 * @pad: a #GstPad to send the event to.
3384 * @event: the #GstEvent to send to the pad.
3386 * Sends the event to the pad. This function can be used
3387 * by applications to send events in the pipeline.
3389 * Returns: TRUE if the event was handled.
3392 gst_pad_send_event (GstPad * pad, GstEvent * event)
3394 gboolean result = FALSE;
3395 GstPadEventFunction eventfunc;
3396 gboolean emit_signal;
3398 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3399 g_return_val_if_fail (event != NULL, FALSE);
3403 if (GST_PAD_IS_SINK (pad) && !GST_EVENT_IS_DOWNSTREAM (event))
3404 goto wrong_direction;
3405 if (GST_PAD_IS_SRC (pad) && !GST_EVENT_IS_UPSTREAM (event))
3406 goto wrong_direction;
3408 if (GST_EVENT_SRC (event) == NULL)
3409 GST_EVENT_SRC (event) = gst_object_ref (pad);
3411 switch (GST_EVENT_TYPE (event)) {
3412 case GST_EVENT_FLUSH_START:
3413 GST_CAT_DEBUG (GST_CAT_EVENT,
3414 "have event type %d (FLUSH_START) on pad %s:%s",
3415 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3417 /* can't even accept a flush begin event when flushing */
3418 if (GST_PAD_IS_FLUSHING (pad))
3420 GST_PAD_SET_FLUSHING (pad);
3421 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3423 case GST_EVENT_FLUSH_STOP:
3424 GST_PAD_UNSET_FLUSHING (pad);
3425 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3428 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d on pad %s:%s",
3429 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3431 if (GST_PAD_IS_FLUSHING (pad))
3436 if ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL)
3439 emit_signal = GST_PAD_DO_EVENT_SIGNALS (pad) > 0;
3441 gst_object_ref (pad);
3444 if (G_UNLIKELY (emit_signal)) {
3445 if (!gst_pad_emit_have_data_signal (pad, GST_MINI_OBJECT (event)))
3449 result = eventfunc (GST_PAD_CAST (pad), event);
3451 gst_object_unref (pad);
3455 /* ERROR handling */
3458 g_warning ("pad %s:%s sending event in wrong direction",
3459 GST_DEBUG_PAD_NAME (pad));
3461 gst_event_unref (event);
3466 g_warning ("pad %s:%s has no event handler, file a bug.",
3467 GST_DEBUG_PAD_NAME (pad));
3469 gst_event_unref (event);
3475 GST_CAT_DEBUG (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3476 gst_event_unref (event);
3481 GST_DEBUG ("Dropping event after FALSE probe return");
3482 gst_object_unref (pad);
3483 gst_event_unref (event);
3488 /************************************************************************
3493 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3494 static void gst_pad_template_init (GstPadTemplate * templ);
3495 static void gst_pad_template_dispose (GObject * object);
3498 gst_pad_template_get_type (void)
3500 static GType padtemplate_type = 0;
3502 if (!padtemplate_type) {
3503 static const GTypeInfo padtemplate_info = {
3504 sizeof (GstPadTemplateClass), NULL, NULL,
3505 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3506 sizeof (GstPadTemplate),
3508 (GInstanceInitFunc) gst_pad_template_init, NULL
3512 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3513 &padtemplate_info, 0);
3515 return padtemplate_type;
3519 gst_pad_template_class_init (GstPadTemplateClass * klass)
3521 GObjectClass *gobject_class;
3522 GstObjectClass *gstobject_class;
3524 gobject_class = (GObjectClass *) klass;
3525 gstobject_class = (GstObjectClass *) klass;
3527 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3529 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3530 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3531 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3532 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3534 gobject_class->dispose = gst_pad_template_dispose;
3536 gstobject_class->path_string_separator = "*";
3540 gst_pad_template_init (GstPadTemplate * templ)
3545 gst_pad_template_dispose (GObject * object)
3547 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3549 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3550 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3551 gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
3554 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3557 /* ALWAYS padtemplates cannot have conversion specifications (like src_%d),
3558 * since it doesn't make sense.
3559 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3561 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3562 * 'sink%d' template is automatically selected), so we need to restrict their
3566 name_is_valid (const gchar * name, GstPadPresence presence)
3570 if (presence == GST_PAD_ALWAYS) {
3571 if (strchr (name, '%')) {
3572 g_warning ("invalid name template %s: conversion specifications are not"
3573 " allowed for GST_PAD_ALWAYS padtemplates", name);
3576 } else if (presence == GST_PAD_REQUEST) {
3577 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3578 g_warning ("invalid name template %s: only one conversion specification"
3579 " allowed in GST_PAD_REQUEST padtemplate", name);
3582 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3583 g_warning ("invalid name template %s: conversion specification must be of"
3584 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3587 if (str && (*(str + 2) != '\0')) {
3588 g_warning ("invalid name template %s: conversion specification must"
3589 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3598 * gst_static_pad_template_get:
3599 * @pad_template: the static pad template
3601 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3603 * Returns: a new #GstPadTemplate.
3606 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3608 GstPadTemplate *new;
3610 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3613 new = g_object_new (gst_pad_template_get_type (),
3614 "name", pad_template->name_template, NULL);
3616 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3617 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3618 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3620 GST_PAD_TEMPLATE_CAPS (new) =
3621 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3627 * gst_pad_template_new:
3628 * @name_template: the name template.
3629 * @direction: the #GstPadDirection of the template.
3630 * @presence: the #GstPadPresence of the pad.
3631 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3633 * Creates a new pad template with a name according to the given template
3634 * and with the given arguments. This functions takes ownership of the provided
3635 * caps, so be sure to not use them afterwards.
3637 * Returns: a new #GstPadTemplate.
3640 gst_pad_template_new (const gchar * name_template,
3641 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3643 GstPadTemplate *new;
3645 g_return_val_if_fail (name_template != NULL, NULL);
3646 g_return_val_if_fail (caps != NULL, NULL);
3647 g_return_val_if_fail (direction == GST_PAD_SRC
3648 || direction == GST_PAD_SINK, NULL);
3649 g_return_val_if_fail (presence == GST_PAD_ALWAYS
3650 || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL);
3652 if (!name_is_valid (name_template, presence)) {
3653 gst_caps_unref (caps);
3657 new = g_object_new (gst_pad_template_get_type (),
3658 "name", name_template, NULL);
3660 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3661 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3662 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3663 GST_PAD_TEMPLATE_CAPS (new) = caps;
3669 * gst_static_pad_template_get_caps:
3670 * @templ: a #GstStaticPadTemplate to get capabilities of.
3672 * Gets the capabilities of the static pad template.
3674 * Returns: the #GstCaps of the static pad template. If you need to keep a
3675 * reference to the caps, take a ref (see gst_caps_ref ()).
3678 gst_static_pad_template_get_caps (GstStaticPadTemplate * templ)
3680 g_return_val_if_fail (templ, NULL);
3682 return (GstCaps *) gst_static_caps_get (&templ->static_caps);
3686 * gst_pad_template_get_caps:
3687 * @templ: a #GstPadTemplate to get capabilities of.
3689 * Gets the capabilities of the pad template.
3691 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3692 * the caps, take a ref (see gst_caps_ref ()).
3695 gst_pad_template_get_caps (GstPadTemplate * templ)
3697 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3699 return GST_PAD_TEMPLATE_CAPS (templ);
3703 * gst_pad_set_element_private:
3704 * @pad: the #GstPad to set the private data of.
3705 * @priv: The private data to attach to the pad.
3707 * Set the given private data gpointer on the pad.
3708 * This function can only be used by the element that owns the pad.
3711 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3713 pad->element_private = priv;
3717 * gst_pad_get_element_private:
3718 * @pad: the #GstPad to get the private data of.
3720 * Gets the private data of a pad.
3722 * Returns: a #gpointer to the private data.
3725 gst_pad_get_element_private (GstPad * pad)
3727 return pad->element_private;
3731 * gst_pad_start_task:
3732 * @pad: the #GstPad to start the task of
3733 * @func: the task function to call
3734 * @data: data passed to the task function
3736 * Starts a task that repeadedly calls @func with @data. This function
3737 * is nostly used in the pad activation function to start the
3738 * dataflow. This function will automatically acauire the STREAM_LOCK of
3739 * the pad before calling @func.
3741 * Returns: a TRUE if the task could be started.
3744 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3748 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3749 g_return_val_if_fail (func != NULL, FALSE);
3752 task = GST_PAD_TASK (pad);
3754 task = gst_task_create (func, data);
3755 gst_task_set_lock (task, GST_STREAM_GET_LOCK (pad));
3756 GST_PAD_TASK (pad) = task;
3758 gst_task_start (task);
3765 * gst_pad_pause_task:
3766 * @pad: the #GstPad to pause the task of
3768 * Pause the task of @pad. This function will also make sure that the
3769 * function executed by the task will effectively stop.
3771 * Returns: a TRUE if the task could be paused or FALSE when the pad
3775 gst_pad_pause_task (GstPad * pad)
3779 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3782 task = GST_PAD_TASK (pad);
3785 gst_task_pause (task);
3788 GST_STREAM_LOCK (pad);
3789 GST_STREAM_UNLOCK (pad);
3801 * gst_pad_stop_task:
3802 * @pad: the #GstPad to stop the task of
3804 * Stop the task of @pad. This function will also make sure that the
3805 * function executed by the task will effectively stop if not called
3806 * from the GstTaskFunction.
3808 * This function will deadlock if called from the GstTaskFunction of
3809 * the task. Use #gst_task_pause() instead.
3811 * Returns: a TRUE if the task could be stopped or FALSE when the pad
3815 gst_pad_stop_task (GstPad * pad)
3819 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3822 task = GST_PAD_TASK (pad);
3825 GST_PAD_TASK (pad) = NULL;
3826 gst_task_stop (task);
3829 GST_STREAM_LOCK (pad);
3830 GST_STREAM_UNLOCK (pad);
3832 gst_task_join (task);
3834 gst_object_unref (task);