* SECTION:gstutils
* @short_description: Various utility functions
*
- * When defining own plugins, use the GST_BOILERPLATE ease gobject creation.
*/
#include "gst_private.h"
#include "gstparse.h"
#include "gstvalue.h"
#include "gst-i18n-lib.h"
+#include "glib-compat-private.h"
#include <math.h>
/**
gst_util_seqnum_next (void)
{
static gint counter = 0;
- return g_atomic_int_exchange_and_add (&counter, 1);
+ return G_ATOMIC_INT_ADD (&counter, 1);
}
/**
* @error: (in): the GError.
* @debug: (in) (allow-none): an additional debug information string, or NULL
*
- * A default error function.
+ * A default error function that uses g_printerr() to display the error message
+ * and the optional debug sting..
*
* The default handler will simply print the error string using g_print.
*/
{
gchar *name = gst_object_get_path_string (source);
- /* FIXME 0.11: should change this to g_printerr() */
- g_print (_("ERROR: from element %s: %s\n"), name, error->message);
+ g_printerr (_("ERROR: from element %s: %s\n"), name, error->message);
if (debug)
- g_print (_("Additional debug info:\n%s\n"), debug);
+ g_printerr (_("Additional debug info:\n%s\n"), debug);
g_free (name);
}
}
}
-typedef struct
-{
- GstPad *orig;
- GstCaps *caps;
-} SetCapsFoldData;
-
-static gboolean
-setcaps_fold_func (const GValue * vpad, GValue * ret, SetCapsFoldData * data)
-{
- gboolean success = TRUE;
- GstPad *pad = g_value_get_object (vpad);
-
- if (pad != data->orig) {
- success = gst_pad_set_caps (pad, data->caps);
- g_value_set_boolean (ret, success);
- }
-
- return success;
-}
-
-/**
- * gst_pad_proxy_setcaps
- * @pad: a #GstPad to proxy from
- * @caps: (transfer none): the #GstCaps to link with
- *
- * Calls gst_pad_set_caps() for every other pad belonging to the
- * same element as @pad. If gst_pad_set_caps() fails on any pad,
- * the proxy setcaps fails. May be used only during negotiation.
- *
- * Returns: TRUE if sucessful
- */
-gboolean
-gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
-{
- GstElement *element;
- GstIterator *iter;
- GstIteratorResult res;
- GValue ret = { 0, };
- SetCapsFoldData data;
-
- g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
- g_return_val_if_fail (caps != NULL, FALSE);
-
- GST_CAT_DEBUG (GST_CAT_PADS, "proxying pad link for %s:%s",
- GST_DEBUG_PAD_NAME (pad));
-
- element = gst_pad_get_parent_element (pad);
- if (element == NULL)
- return FALSE;
-
- /* only iterate the pads in the oposite direction */
- if (GST_PAD_IS_SRC (pad))
- iter = gst_element_iterate_sink_pads (element);
- else
- iter = gst_element_iterate_src_pads (element);
-
- g_value_init (&ret, G_TYPE_BOOLEAN);
- g_value_set_boolean (&ret, TRUE);
- data.orig = pad;
- data.caps = caps;
-
- while (1) {
- res = gst_iterator_fold (iter, (GstIteratorFoldFunction) setcaps_fold_func,
- &ret, &data);
-
- switch (res) {
- case GST_ITERATOR_RESYNC:
- /* reset return value */
- g_value_set_boolean (&ret, TRUE);
- gst_iterator_resync (iter);
- break;
- case GST_ITERATOR_DONE:
- /* all pads iterated, return collected value */
- goto done;
- default:
- /* iterator returned _ERROR or premature end with _OK,
- * mark an error and exit */
- goto error;
- }
- }
-done:
- gst_iterator_free (iter);
-
- gst_object_unref (element);
-
- /* ok not to unset the gvalue */
- return g_value_get_boolean (&ret);
-
- /* ERRORS */
-error:
- {
- g_warning ("Pad list return error on element %s",
- GST_ELEMENT_NAME (element));
- gst_iterator_free (iter);
- gst_object_unref (element);
- return FALSE;
- }
-}
-
/**
* gst_pad_query_position:
* @pad: a #GstPad to invoke the position query on.
}
/**
- * gst_pad_add_data_probe:
- * @pad: pad to add the data probe handler to
- * @handler: function to call when data is passed over pad
- * @data: (closure): data to pass along with the handler
- *
- * Adds a "data probe" to a pad. This function will be called whenever data
- * passes through a pad. In this case data means both events and buffers. The
- * probe will be called with the data as an argument, meaning @handler should
- * have the same callback signature as the #GstPad::have-data signal.
- * Note that the data will have a reference count greater than 1, so it will
- * be immutable -- you must not change it.
- *
- * For source pads, the probe will be called after the blocking function, if any
- * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
- * to. For sink pads, the probe function will be called before configuring the
- * sink with new caps, if any, and before calling the pad's chain function.
- *
- * Your data probe should return TRUE to let the data continue to flow, or FALSE
- * to drop it. Dropping data is rarely useful, but occasionally comes in handy
- * with events.
- *
- * Although probes are implemented internally by connecting @handler to the
- * have-data signal on the pad, if you want to remove a probe it is insufficient
- * to only call g_signal_handler_disconnect on the returned handler id. To
- * remove a probe, use the appropriate function, such as
- * gst_pad_remove_data_probe().
- *
- * Returns: The handler id.
- */
-gulong
-gst_pad_add_data_probe (GstPad * pad, GCallback handler, gpointer data)
-{
- return gst_pad_add_data_probe_full (pad, handler, data, NULL);
-}
-
-/**
- * gst_pad_add_data_probe_full:
- * @pad: pad to add the data probe handler to
- * @handler: function to call when data is passed over pad
- * @data: (closure): data to pass along with the handler
- * @notify: (allow-none): function to call when the probe is disconnected,
- * or NULL
- *
- * Adds a "data probe" to a pad. This function will be called whenever data
- * passes through a pad. In this case data means both events and buffers. The
- * probe will be called with the data as an argument, meaning @handler should
- * have the same callback signature as the #GstPad::have-data signal.
- * Note that the data will have a reference count greater than 1, so it will
- * be immutable -- you must not change it.
- *
- * For source pads, the probe will be called after the blocking function, if any
- * (see gst_pad_set_blocked_async()), but before looking up the peer to chain
- * to. For sink pads, the probe function will be called before configuring the
- * sink with new caps, if any, and before calling the pad's chain function.
- *
- * Your data probe should return TRUE to let the data continue to flow, or FALSE
- * to drop it. Dropping data is rarely useful, but occasionally comes in handy
- * with events.
- *
- * Although probes are implemented internally by connecting @handler to the
- * have-data signal on the pad, if you want to remove a probe it is insufficient
- * to only call g_signal_handler_disconnect on the returned handler id. To
- * remove a probe, use the appropriate function, such as
- * gst_pad_remove_data_probe().
- *
- * The @notify function is called when the probe is disconnected and usually
- * used to free @data.
- *
- * Returns: The handler id.
- *
- * Since: 0.10.20
- */
-gulong
-gst_pad_add_data_probe_full (GstPad * pad, GCallback handler,
- gpointer data, GDestroyNotify notify)
-{
- gulong sigid;
-
- g_return_val_if_fail (GST_IS_PAD (pad), 0);
- g_return_val_if_fail (handler != NULL, 0);
-
- GST_OBJECT_LOCK (pad);
-
- /* we only expose a GDestroyNotify in our API because that's less confusing */
- sigid = g_signal_connect_data (pad, "have-data", handler, data,
- (GClosureNotify) notify, 0);
-
- GST_PAD_DO_EVENT_SIGNALS (pad)++;
- GST_PAD_DO_BUFFER_SIGNALS (pad)++;
- GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
- "adding data probe, now %d data, %d event probes",
- GST_PAD_DO_BUFFER_SIGNALS (pad), GST_PAD_DO_EVENT_SIGNALS (pad));
- _priv_gst_pad_invalidate_cache (pad);
- GST_OBJECT_UNLOCK (pad);
-
- return sigid;
-}
-
-/**
- * gst_pad_add_event_probe:
- * @pad: pad to add the event probe handler to
- * @handler: function to call when events are passed over pad
- * @data: (closure): data to pass along with the handler
- *
- * Adds a probe that will be called for all events passing through a pad. See
- * gst_pad_add_data_probe() for more information.
- *
- * Returns: The handler id
- */
-gulong
-gst_pad_add_event_probe (GstPad * pad, GCallback handler, gpointer data)
-{
- return gst_pad_add_event_probe_full (pad, handler, data, NULL);
-}
-
-/**
- * gst_pad_add_event_probe_full:
- * @pad: pad to add the event probe handler to
- * @handler: function to call when events are passed over pad
- * @data: (closure): data to pass along with the handler, or NULL
- * @notify: (allow-none): function to call when probe is disconnected, or NULL
- *
- * Adds a probe that will be called for all events passing through a pad. See
- * gst_pad_add_data_probe() for more information.
- *
- * The @notify function is called when the probe is disconnected and usually
- * used to free @data.
- *
- * Returns: The handler id
- *
- * Since: 0.10.20
- */
-gulong
-gst_pad_add_event_probe_full (GstPad * pad, GCallback handler,
- gpointer data, GDestroyNotify notify)
-{
- gulong sigid;
-
- g_return_val_if_fail (GST_IS_PAD (pad), 0);
- g_return_val_if_fail (handler != NULL, 0);
-
- GST_OBJECT_LOCK (pad);
-
- /* we only expose a GDestroyNotify in our API because that's less confusing */
- sigid = g_signal_connect_data (pad, "have-data::event", handler, data,
- (GClosureNotify) notify, 0);
-
- GST_PAD_DO_EVENT_SIGNALS (pad)++;
- GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding event probe, now %d probes",
- GST_PAD_DO_EVENT_SIGNALS (pad));
- _priv_gst_pad_invalidate_cache (pad);
- GST_OBJECT_UNLOCK (pad);
-
- return sigid;
-}
-
-/**
- * gst_pad_add_buffer_probe:
- * @pad: pad to add the buffer probe handler to
- * @handler: function to call when buffers are passed over pad
- * @data: (closure): data to pass along with the handler
- *
- * Adds a probe that will be called for all buffers passing through a pad. See
- * gst_pad_add_data_probe() for more information.
- *
- * Returns: The handler id
- */
-gulong
-gst_pad_add_buffer_probe (GstPad * pad, GCallback handler, gpointer data)
-{
- return gst_pad_add_buffer_probe_full (pad, handler, data, NULL);
-}
-
-/**
- * gst_pad_add_buffer_probe_full:
- * @pad: pad to add the buffer probe handler to
- * @handler: function to call when buffer are passed over pad
- * @data: (closure): data to pass along with the handler
- * @notify: (allow-none): function to call when the probe is disconnected,
- * or NULL
- *
- * Adds a probe that will be called for all buffers passing through a pad. See
- * gst_pad_add_data_probe() for more information.
- *
- * The @notify function is called when the probe is disconnected and usually
- * used to free @data.
- *
- * Returns: The handler id
- *
- * Since: 0.10.20
- */
-gulong
-gst_pad_add_buffer_probe_full (GstPad * pad, GCallback handler,
- gpointer data, GDestroyNotify notify)
-{
- gulong sigid;
-
- g_return_val_if_fail (GST_IS_PAD (pad), 0);
- g_return_val_if_fail (handler != NULL, 0);
-
- GST_OBJECT_LOCK (pad);
-
- /* we only expose a GDestroyNotify in our API because that's less confusing */
- sigid = g_signal_connect_data (pad, "have-data::buffer", handler, data,
- (GClosureNotify) notify, 0);
-
- GST_PAD_DO_BUFFER_SIGNALS (pad)++;
- GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "adding buffer probe, now %d probes",
- GST_PAD_DO_BUFFER_SIGNALS (pad));
- _priv_gst_pad_invalidate_cache (pad);
- GST_OBJECT_UNLOCK (pad);
-
- return sigid;
-}
-
-/**
- * gst_pad_remove_data_probe:
- * @pad: pad to remove the data probe handler from
- * @handler_id: handler id returned from gst_pad_add_data_probe
- *
- * Removes a data probe from @pad.
- */
-void
-gst_pad_remove_data_probe (GstPad * pad, guint handler_id)
-{
- g_return_if_fail (GST_IS_PAD (pad));
- g_return_if_fail (handler_id > 0);
-
- GST_OBJECT_LOCK (pad);
- g_signal_handler_disconnect (pad, handler_id);
- GST_PAD_DO_BUFFER_SIGNALS (pad)--;
- GST_PAD_DO_EVENT_SIGNALS (pad)--;
- GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
- "removed data probe, now %d event, %d buffer probes",
- GST_PAD_DO_EVENT_SIGNALS (pad), GST_PAD_DO_BUFFER_SIGNALS (pad));
- GST_OBJECT_UNLOCK (pad);
-
-}
-
-/**
- * gst_pad_remove_event_probe:
- * @pad: pad to remove the event probe handler from
- * @handler_id: handler id returned from gst_pad_add_event_probe
- *
- * Removes an event probe from @pad.
- */
-void
-gst_pad_remove_event_probe (GstPad * pad, guint handler_id)
-{
- g_return_if_fail (GST_IS_PAD (pad));
- g_return_if_fail (handler_id > 0);
-
- GST_OBJECT_LOCK (pad);
- g_signal_handler_disconnect (pad, handler_id);
- GST_PAD_DO_EVENT_SIGNALS (pad)--;
- GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
- "removed event probe, now %d event probes",
- GST_PAD_DO_EVENT_SIGNALS (pad));
- GST_OBJECT_UNLOCK (pad);
-}
-
-/**
- * gst_pad_remove_buffer_probe:
- * @pad: pad to remove the buffer probe handler from
- * @handler_id: handler id returned from gst_pad_add_buffer_probe
- *
- * Removes a buffer probe from @pad.
- */
-void
-gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
-{
- g_return_if_fail (GST_IS_PAD (pad));
- g_return_if_fail (handler_id > 0);
-
- GST_OBJECT_LOCK (pad);
- g_signal_handler_disconnect (pad, handler_id);
- GST_PAD_DO_BUFFER_SIGNALS (pad)--;
- GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
- "removed buffer probe, now %d buffer probes",
- GST_PAD_DO_BUFFER_SIGNALS (pad));
- GST_OBJECT_UNLOCK (pad);
-
-}
-
-/**
* gst_element_found_tags_for_pad:
* @element: element for which to post taglist to bus.
* @pad: (transfer none): pad on which to push tag-event