* SECTION:gstutils
* @short_description: Various utility functions
*
- * When defining own plugins, use the GST_BOILERPLATE ease gobject creation.
*/
#include "gst_private.h"
gst_util_seqnum_next (void)
{
static gint counter = 0;
- return G_ATOMIC_INT_ADD (&counter, 1);
+ return g_atomic_int_add (&counter, 1);
}
/**
{
GstCaps *caps;
- caps = pad->caps;
+ caps = gst_pad_get_current_caps (pad);
if (!caps) {
string_append_indent (buf, indent);
s = gst_caps_to_string (caps);
g_string_append (buf, s);
g_free (s);
+
+ gst_caps_unref (caps);
}
}
*/
GstPad *
gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
- const GstCaps * caps)
+ GstCaps * caps)
{
GstIterator *pads;
GstPadTemplate *templ;
GstCaps *templcaps;
GstPad *foundpad = NULL;
gboolean done;
+ GValue padptr = { 0, };
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
}
while (!done) {
- gpointer padptr;
-
switch (gst_iterator_next (pads, &padptr)) {
case GST_ITERATOR_OK:
{
GstPad *srcpad;
GstPad *sinkpad;
- current = GST_PAD (padptr);
+ current = g_value_get_object (&padptr);
GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
GST_DEBUG_PAD_NAME (current));
gboolean compatible;
/* Now check if the two pads' caps are compatible */
- temp = gst_pad_get_caps_reffed (pad);
+ temp = gst_pad_query_caps (pad, NULL);
if (caps) {
intersection = gst_caps_intersect (temp, caps);
gst_caps_unref (temp);
intersection = temp;
}
- temp = gst_pad_get_caps_reffed (current);
+ temp = gst_pad_query_caps (current, NULL);
compatible = gst_caps_can_intersect (temp, intersection);
gst_caps_unref (temp);
gst_caps_unref (intersection);
GST_DEBUG_PAD_NAME (current));
gst_iterator_free (pads);
+ current = gst_object_ref (current);
+ g_value_unset (&padptr);
+
return current;
} else {
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "incompatible pads");
}
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS, "unreffing pads");
- gst_object_unref (current);
+ g_value_reset (&padptr);
if (peer)
gst_object_unref (peer);
break;
break;
}
}
+ g_value_unset (&padptr);
gst_iterator_free (pads);
GST_CAT_DEBUG_OBJECT (GST_CAT_ELEMENT_PADS, element,
/* try to create a new one */
/* requesting is a little crazy, we need a template. Let's create one */
/* FIXME: why not gst_pad_get_pad_template (pad); */
- templcaps = gst_pad_get_caps_reffed (pad);
-
+ templcaps = gst_pad_query_caps (pad, NULL);
templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
+ gst_caps_unref (templcaps);
foundpad = gst_element_request_compatible_pad (element, templ);
gst_object_unref (templ);
}
/**
- * gst_element_factory_can_src_caps:
- * @factory: factory to query
- * @caps: the caps to check
- *
- * Checks if the factory can source the given capability.
- *
- * Returns: %TRUE if it can src the capabilities
- *
- * Deprecated: use gst_element_factory_can_src_all_caps() instead.
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-gboolean gst_element_factory_can_src_caps (GstElementFactory * factory,
- const GstCaps * caps);
-#endif
-gboolean
-gst_element_factory_can_src_caps (GstElementFactory * factory,
- const GstCaps * caps)
-{
- return gst_element_factory_can_accept_all_caps_in_direction (factory, caps,
- GST_PAD_SRC);
-}
-#endif /* GST_REMOVE_DEPRECATED */
-
-/**
- * gst_element_factory_can_sink_caps:
- * @factory: factory to query
- * @caps: the caps to check
- *
- * Checks if the factory can sink the given capability.
- *
- * Returns: %TRUE if it can sink the capabilities
- *
- * Deprecated: use gst_element_factory_can_sink_all_caps() instead.
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-gboolean gst_element_factory_can_sink_caps (GstElementFactory * factory,
- const GstCaps * caps);
-#endif
-gboolean
-gst_element_factory_can_sink_caps (GstElementFactory * factory,
- const GstCaps * caps)
-{
- return gst_element_factory_can_accept_all_caps_in_direction (factory, caps,
- GST_PAD_SINK);
-}
-#endif /* GST_REMOVE_DEPRECATED */
-
-/**
* gst_element_factory_can_sink_all_caps:
* @factory: factory to query
* @caps: the caps to check
desttempl = (GstPadTemplate *) l->data;
if (desttempl->presence == GST_PAD_REQUEST &&
desttempl->direction != srctempl->direction) {
- if (gst_caps_is_always_compatible (gst_pad_template_get_caps
- (srctempl), gst_pad_template_get_caps (desttempl))) {
+ GstCaps *srccaps, *destcaps;
+
+ srccaps = gst_pad_template_get_caps (srctempl);
+ destcaps = gst_pad_template_get_caps (desttempl);
+ if (gst_caps_is_always_compatible (srccaps, destcaps)) {
srcpad =
gst_element_request_pad (src, srctempl,
srctempl->name_template, NULL);
GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (destpad));
gst_object_unref (srcpad);
gst_object_unref (destpad);
+ gst_caps_unref (srccaps);
+ gst_caps_unref (destcaps);
return TRUE;
}
/* it failed, so we release the request pads */
if (destpad)
gst_element_release_request_pad (dest, destpad);
}
+ gst_caps_unref (srccaps);
+ gst_caps_unref (destcaps);
}
}
}
{
GstIterator *pads;
gboolean done = FALSE;
+ GValue data = { 0, };
g_return_if_fail (GST_IS_ELEMENT (src));
g_return_if_fail (GST_IS_ELEMENT (dest));
pads = gst_element_iterate_pads (src);
while (!done) {
- gpointer data;
-
switch (gst_iterator_next (pads, &data)) {
case GST_ITERATOR_OK:
{
- GstPad *pad = GST_PAD_CAST (data);
+ GstPad *pad = g_value_get_object (&data);
if (GST_PAD_IS_SRC (pad)) {
GstPad *peerpad = gst_pad_get_peer (pad);
gst_object_unref (peerpad);
}
}
- gst_object_unref (pad);
+ g_value_reset (&data);
break;
}
case GST_ITERATOR_RESYNC:
break;
}
}
+ g_value_unset (&data);
gst_iterator_free (pads);
}
/**
* gst_element_query_position:
* @element: a #GstElement to invoke the position query on.
- * @format: (inout): a pointer to the #GstFormat asked for.
- * On return contains the #GstFormat used.
+ * @format: the #GstFormat requested
* @cur: (out) (allow-none): a location in which to store the current
* position, or NULL.
*
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_element_query_position (GstElement * element, GstFormat * format,
+gst_element_query_position (GstElement * element, GstFormat format,
gint64 * cur)
{
GstQuery *query;
gboolean ret;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
- g_return_val_if_fail (format != NULL, FALSE);
+ g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
- query = gst_query_new_position (*format);
+ query = gst_query_new_position (format);
ret = gst_element_query (element, query);
if (ret)
- gst_query_parse_position (query, format, cur);
+ gst_query_parse_position (query, NULL, cur);
gst_query_unref (query);
/**
* gst_element_query_duration:
* @element: a #GstElement to invoke the duration query on.
- * @format: (inout): a pointer to the #GstFormat asked for.
- * On return contains the #GstFormat used.
+ * @format: the #GstFormat requested
* @duration: (out): A location in which to store the total duration, or NULL.
*
* Queries an element for the total stream duration.
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_element_query_duration (GstElement * element, GstFormat * format,
+gst_element_query_duration (GstElement * element, GstFormat format,
gint64 * duration)
{
GstQuery *query;
gboolean ret;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
- g_return_val_if_fail (format != NULL, FALSE);
+ g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
- query = gst_query_new_duration (*format);
+ query = gst_query_new_duration (format);
ret = gst_element_query (element, query);
if (ret)
- gst_query_parse_duration (query, format, duration);
+ gst_query_parse_duration (query, NULL, duration);
gst_query_unref (query);
* @element: a #GstElement to invoke the convert query on.
* @src_format: (inout): a #GstFormat to convert from.
* @src_val: a value to convert.
- * @dest_format: (inout): a pointer to the #GstFormat to convert to.
+ * @dest_format: the #GstFormat to convert to.
* @dest_val: (out): a pointer to the result.
*
* Queries an element to convert @src_val in @src_format to @dest_format.
*/
gboolean
gst_element_query_convert (GstElement * element, GstFormat src_format,
- gint64 src_val, GstFormat * dest_format, gint64 * dest_val)
+ gint64 src_val, GstFormat dest_format, gint64 * dest_val)
{
GstQuery *query;
gboolean ret;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
- g_return_val_if_fail (dest_format != NULL, FALSE);
+ g_return_val_if_fail (dest_format != GST_FORMAT_UNDEFINED, FALSE);
g_return_val_if_fail (dest_val != NULL, FALSE);
- if (*dest_format == src_format || src_val == -1) {
+ if (dest_format == src_format || src_val == -1) {
*dest_val = src_val;
return TRUE;
}
- query = gst_query_new_convert (src_format, src_val, *dest_format);
+ query = gst_query_new_convert (src_format, src_val, dest_format);
ret = gst_element_query (element, query);
if (ret)
- gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
+ gst_query_parse_convert (query, NULL, NULL, NULL, dest_val);
gst_query_unref (query);
* gst_pad_use_fixed_caps:
* @pad: the pad to use
*
- * A helper function you can use that sets the
- * @gst_pad_get_fixed_caps_func as the getcaps function for the
- * pad. This way the function will always return the negotiated caps
+ * A helper function you can use that sets the FIXED_CAPS flag
+ * This way the default getcaps function will always return the negotiated caps
* or in case the pad is not negotiated, the padtemplate caps.
*
* Use this function on a pad that, once gst_pad_set_caps() has been called
void
gst_pad_use_fixed_caps (GstPad * pad)
{
- gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
-}
-
-/**
- * gst_pad_get_fixed_caps_func:
- * @pad: the pad to use
- *
- * A helper function you can use as a GetCaps function that
- * will return the currently negotiated caps or the padtemplate
- * when NULL.
- *
- * Free-function: gst_caps_unref
- *
- * Returns: (transfer full): the currently negotiated caps or the padtemplate.
- */
-GstCaps *
-gst_pad_get_fixed_caps_func (GstPad * pad)
-{
- GstCaps *result;
-
- g_return_val_if_fail (GST_IS_PAD (pad), NULL);
-
- GST_OBJECT_LOCK (pad);
- if (GST_PAD_CAPS (pad)) {
- result = GST_PAD_CAPS (pad);
-
- GST_CAT_DEBUG (GST_CAT_CAPS,
- "using pad caps %p %" GST_PTR_FORMAT, result, result);
-
- result = gst_caps_ref (result);
- } else if (GST_PAD_PAD_TEMPLATE (pad)) {
- GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
-
- result = GST_PAD_TEMPLATE_CAPS (templ);
- GST_CAT_DEBUG (GST_CAT_CAPS,
- "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
- result);
-
- result = gst_caps_ref (result);
- } else {
- GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
- result = gst_caps_new_empty ();
- }
- GST_OBJECT_UNLOCK (pad);
-
- return result;
+ GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_FIXED_CAPS);
}
/**
* @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);
}
va_end (args);
}
-static void
-gst_element_populate_std_props (GObjectClass * klass, const gchar * prop_name,
- guint arg_id, GParamFlags flags)
-{
- GQuark prop_id = g_quark_from_string (prop_name);
- GParamSpec *pspec;
-
- static GQuark fd_id = 0;
- static GQuark blocksize_id;
- static GQuark bytesperread_id;
- static GQuark dump_id;
- static GQuark filesize_id;
- static GQuark mmapsize_id;
- static GQuark location_id;
- static GQuark offset_id;
- static GQuark silent_id;
- static GQuark touch_id;
-
- flags |= G_PARAM_STATIC_STRINGS;
-
- if (!fd_id) {
- fd_id = g_quark_from_static_string ("fd");
- blocksize_id = g_quark_from_static_string ("blocksize");
- bytesperread_id = g_quark_from_static_string ("bytesperread");
- dump_id = g_quark_from_static_string ("dump");
- filesize_id = g_quark_from_static_string ("filesize");
- mmapsize_id = g_quark_from_static_string ("mmapsize");
- location_id = g_quark_from_static_string ("location");
- offset_id = g_quark_from_static_string ("offset");
- silent_id = g_quark_from_static_string ("silent");
- touch_id = g_quark_from_static_string ("touch");
- }
-
- if (prop_id == fd_id) {
- pspec = g_param_spec_int ("fd", "File-descriptor",
- "File-descriptor for the file being read", 0, G_MAXINT, 0, flags);
- } else if (prop_id == blocksize_id) {
- pspec = g_param_spec_ulong ("blocksize", "Block Size",
- "Block size to read per buffer", 0, G_MAXULONG, 4096, flags);
-
- } else if (prop_id == bytesperread_id) {
- pspec = g_param_spec_int ("bytesperread", "Bytes per read",
- "Number of bytes to read per buffer", G_MININT, G_MAXINT, 0, flags);
-
- } else if (prop_id == dump_id) {
- pspec = g_param_spec_boolean ("dump", "Dump",
- "Dump bytes to stdout", FALSE, flags);
-
- } else if (prop_id == filesize_id) {
- pspec = g_param_spec_int64 ("filesize", "File Size",
- "Size of the file being read", 0, G_MAXINT64, 0, flags);
-
- } else if (prop_id == mmapsize_id) {
- pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
- "Size in bytes of mmap()d regions", 0, G_MAXULONG, 4 * 1048576, flags);
-
- } else if (prop_id == location_id) {
- pspec = g_param_spec_string ("location", "File Location",
- "Location of the file to read", NULL, flags);
-
- } else if (prop_id == offset_id) {
- pspec = g_param_spec_int64 ("offset", "File Offset",
- "Byte offset of current read pointer", 0, G_MAXINT64, 0, flags);
-
- } else if (prop_id == silent_id) {
- pspec = g_param_spec_boolean ("silent", "Silent", "Don't produce events",
- FALSE, flags);
-
- } else if (prop_id == touch_id) {
- pspec = g_param_spec_boolean ("touch", "Touch read data",
- "Touch data to force disk read before " "push ()", TRUE, flags);
- } else {
- g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
- prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
- pspec = NULL;
- }
-
- if (pspec) {
- g_object_class_install_property (klass, arg_id, pspec);
- }
-}
-
-/**
- * gst_element_class_install_std_props:
- * @klass: the #GstElementClass to add the properties to.
- * @first_name: the name of the first property.
- * in a NULL terminated
- * @...: the id and flags of the first property, followed by
- * further 'name', 'id', 'flags' triplets and terminated by NULL.
- *
- * Adds a list of standardized properties with types to the @klass.
- * the id is for the property switch in your get_prop method, and
- * the flags determine readability / writeability.
- **/
-void
-gst_element_class_install_std_props (GstElementClass * klass,
- const gchar * first_name, ...)
-{
- const char *name;
-
- va_list args;
-
- g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
-
- va_start (args, first_name);
-
- name = first_name;
-
- while (name) {
- int arg_id = va_arg (args, int);
- GParamFlags flags = (GParamFlags) va_arg (args, int);
-
- gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id,
- flags);
-
- name = va_arg (args, char *);
- }
-
- va_end (args);
-}
-
-
/**
* gst_buffer_merge:
* @buf1: (transfer none): the first source #GstBuffer to merge.
gst_buffer_merge (GstBuffer * buf1, GstBuffer * buf2)
{
GstBuffer *result;
+ gsize size1, size2;
+
+ size1 = gst_buffer_get_size (buf1);
+ size2 = gst_buffer_get_size (buf2);
/* we're just a specific case of the more general gst_buffer_span() */
- result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
+ result = gst_buffer_span (buf1, 0, buf2, size1 + size2);
return result;
}
/**
* gst_buffer_join:
- * @buf1: the first source #GstBuffer.
- * @buf2: the second source #GstBuffer.
+ * @buf1: (transfer full): the first source #GstBuffer.
+ * @buf2: (transfer full): the second source #GstBuffer.
*
* Create a new buffer that is the concatenation of the two source
* buffers, and unrefs the original source buffers.
gst_buffer_join (GstBuffer * buf1, GstBuffer * buf2)
{
GstBuffer *result;
+ gsize size1, size2;
+
+ size1 = gst_buffer_get_size (buf1);
+ size2 = gst_buffer_get_size (buf2);
- result = gst_buffer_span (buf1, 0, buf2, buf1->size + buf2->size);
+ result = gst_buffer_span (buf1, 0, buf2, size1 + size2);
gst_buffer_unref (buf1);
gst_buffer_unref (buf2);
return result;
}
-
-/**
- * gst_buffer_stamp:
- * @dest: (transfer none): buffer to stamp
- * @src: buffer to stamp from
- *
- * Copies additional information (the timestamp, duration, and offset start
- * and end) from one buffer to the other.
- *
- * This function does not copy any buffer flags or caps and is equivalent to
- * gst_buffer_copy_metadata(@dest, @src, GST_BUFFER_COPY_TIMESTAMPS).
- *
- * Deprecated: use gst_buffer_copy_metadata() instead, it provides more
- * control.
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-void gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src);
-#endif
-void
-gst_buffer_stamp (GstBuffer * dest, const GstBuffer * src)
+typedef struct
{
- gst_buffer_copy_metadata (dest, src, GST_BUFFER_COPY_TIMESTAMPS);
-}
-#endif /* GST_REMOVE_DEPRECATED */
+ GstQuery *query;
+ gboolean ret;
+} QueryAcceptCapsData;
static gboolean
-getcaps_fold_func (GstPad * pad, GValue * ret, GstPad * orig)
+query_accept_caps_func (GstPad * pad, QueryAcceptCapsData * data)
{
- gboolean empty = FALSE;
- GstCaps *peercaps, *existing;
-
- existing = g_value_get_pointer (ret);
- peercaps = gst_pad_peer_get_caps_reffed (pad);
- if (G_LIKELY (peercaps)) {
- GstCaps *intersection = gst_caps_intersect (existing, peercaps);
-
- empty = gst_caps_is_empty (intersection);
+ if (G_LIKELY (gst_pad_peer_query (pad, data->query))) {
+ gboolean result;
- g_value_set_pointer (ret, intersection);
- gst_caps_unref (existing);
- gst_caps_unref (peercaps);
+ gst_query_parse_accept_caps_result (data->query, &result);
+ data->ret &= result;
}
- gst_object_unref (pad);
- return !empty;
+ return FALSE;
}
/**
- * gst_pad_proxy_getcaps:
+ * gst_pad_proxy_query_accept_caps:
* @pad: a #GstPad to proxy.
+ * @query: an ACCEPT_CAPS #GstQuery.
*
- * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
- * same element as @pad, and returns the intersection of the results.
- *
- * This function is useful as a default getcaps function for an element
- * that can handle any stream format, but requires all its pads to have
- * the same caps. Two such elements are tee and adder.
+ * Calls gst_pad_accept_caps() for all internally linked pads of @pad and
+ * returns the intersection of the results.
*
- * Free-function: gst_caps_unref
+ * This function is useful as a default accept caps query function for an element
+ * that can handle any stream format, but requires caps that are acceptable for
+ * all oposite pads.
*
- * Returns: (transfer full): the intersection of the other pads' allowed caps.
+ * Returns: TRUE if @query could be executed
*/
-GstCaps *
-gst_pad_proxy_getcaps (GstPad * pad)
+gboolean
+gst_pad_proxy_query_accept_caps (GstPad * pad, GstQuery * query)
{
- GstElement *element;
- GstCaps *caps, *intersected;
- GstIterator *iter;
- GstIteratorResult res;
- GValue ret = { 0, };
+ QueryAcceptCapsData data;
- g_return_val_if_fail (GST_IS_PAD (pad), NULL);
+ g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
+ g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
+ g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_ACCEPT_CAPS, FALSE);
- GST_CAT_DEBUG (GST_CAT_PADS, "proxying getcaps for %s:%s",
+ GST_CAT_DEBUG (GST_CAT_PADS, "proxying accept caps query for %s:%s",
GST_DEBUG_PAD_NAME (pad));
- element = gst_pad_get_parent_element (pad);
- if (element == NULL)
- goto no_parent;
-
- /* value to hold the return, by default it holds ANY, the ref is taken by
- * the GValue. */
- g_value_init (&ret, G_TYPE_POINTER);
- g_value_set_pointer (&ret, gst_caps_new_any ());
-
- /* 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);
-
- while (1) {
- res =
- gst_iterator_fold (iter, (GstIteratorFoldFunction) getcaps_fold_func,
- &ret, pad);
- switch (res) {
- case GST_ITERATOR_RESYNC:
- /* unref any value stored */
- if ((caps = g_value_get_pointer (&ret)))
- gst_caps_unref (caps);
- /* need to reset the result again to ANY */
- g_value_set_pointer (&ret, gst_caps_new_any ());
- gst_iterator_resync (iter);
- break;
- case GST_ITERATOR_DONE:
- /* all pads iterated, return collected value */
- goto done;
- case GST_ITERATOR_OK:
- /* premature exit (happens if caps intersection is empty) */
- goto done;
- default:
- /* iterator returned _ERROR, mark an error and exit */
- if ((caps = g_value_get_pointer (&ret)))
- gst_caps_unref (caps);
- g_value_set_pointer (&ret, NULL);
- goto error;
- }
- }
-done:
- gst_iterator_free (iter);
-
- gst_object_unref (element);
-
- caps = g_value_get_pointer (&ret);
- g_value_unset (&ret);
-
- if (caps) {
- intersected =
- gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
- gst_caps_unref (caps);
- } else {
- intersected = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
- }
+ data.query = query;
+ /* value to hold the return, by default it holds TRUE */
+ data.ret = TRUE;
- return intersected;
+ gst_pad_forward (pad, (GstPadForwardFunction) query_accept_caps_func, &data);
+ gst_query_set_accept_caps_result (query, data.ret);
- /* ERRORS */
-no_parent:
- {
- GST_DEBUG_OBJECT (pad, "no parent");
- return gst_caps_copy (gst_pad_get_pad_template_caps (pad));
- }
-error:
- {
- g_warning ("Pad list returned error on element %s",
- GST_ELEMENT_NAME (element));
- gst_iterator_free (iter);
- gst_object_unref (element);
- return gst_caps_copy (gst_pad_get_pad_template_caps (pad));
- }
+ return TRUE;
}
typedef struct
{
- GstPad *orig;
- GstCaps *caps;
-} SetCapsFoldData;
+ GstQuery *query;
+ GstCaps *ret;
+} QueryCapsData;
static gboolean
-setcaps_fold_func (GstPad * pad, GValue * ret, SetCapsFoldData * data)
+query_caps_func (GstPad * pad, QueryCapsData * data)
{
- gboolean success = TRUE;
+ gboolean empty = FALSE;
- if (pad != data->orig) {
- success = gst_pad_set_caps (pad, data->caps);
- g_value_set_boolean (ret, success);
- }
- gst_object_unref (pad);
+ if (G_LIKELY (gst_pad_peer_query (pad, data->query))) {
+ GstCaps *peercaps, *intersection;
- return success;
+ gst_query_parse_caps_result (data->query, &peercaps);
+ GST_DEBUG_OBJECT (pad, "intersect with result %" GST_PTR_FORMAT, peercaps);
+ intersection = gst_caps_intersect (data->ret, peercaps);
+ GST_DEBUG_OBJECT (pad, "intersected %" GST_PTR_FORMAT, intersection);
+
+ gst_caps_unref (data->ret);
+ data->ret = intersection;
+
+ /* stop when empty */
+ empty = gst_caps_is_empty (intersection);
+ }
+ return empty;
}
/**
- * gst_pad_proxy_setcaps
- * @pad: a #GstPad to proxy from
- * @caps: (transfer none): the #GstCaps to link with
+ * gst_pad_proxy_query_caps:
+ * @pad: a #GstPad to proxy.
+ * @query: a CAPS #GstQuery.
*
- * 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.
+ * Calls gst_pad_query_caps() for all internally linked pads fof @pad and returns
+ * the intersection of the results.
*
- * Returns: TRUE if successful
+ * This function is useful as a default caps query function for an element
+ * that can handle any stream format, but requires all its pads to have
+ * the same caps. Two such elements are tee and adder.
+ *
+ * Returns: TRUE if @query could be executed
*/
gboolean
-gst_pad_proxy_setcaps (GstPad * pad, GstCaps * caps)
+gst_pad_proxy_query_caps (GstPad * pad, GstQuery * query)
{
- GstElement *element;
- GstIterator *iter;
- GstIteratorResult res;
- GValue ret = { 0, };
- SetCapsFoldData data;
+ GstCaps *templ, *intersected;
+ QueryCapsData data;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
- g_return_val_if_fail (caps != NULL, FALSE);
+ g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
+ g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CAPS, FALSE);
- GST_CAT_DEBUG (GST_CAT_PADS, "proxying pad link for %s:%s",
+ GST_CAT_DEBUG (GST_CAT_PADS, "proxying caps query for %s:%s",
GST_DEBUG_PAD_NAME (pad));
- element = gst_pad_get_parent_element (pad);
- if (element == NULL)
- return FALSE;
+ data.query = query;
+ /* value to hold the return, by default it holds ANY */
+ data.ret = gst_caps_new_any ();
- /* 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);
+ gst_pad_forward (pad, (GstPadForwardFunction) query_caps_func, &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;
- }
+ templ = gst_pad_get_pad_template_caps (pad);
+ if (data.ret) {
+ intersected = gst_caps_intersect (data.ret, templ);
+ gst_caps_unref (data.ret);
+ } else {
+ intersected = templ;
}
-done:
- gst_iterator_free (iter);
-
- gst_object_unref (element);
-
- /* ok not to unset the gvalue */
- return g_value_get_boolean (&ret);
+ gst_query_set_caps_result (query, intersected);
+ gst_caps_unref (templ);
+ gst_caps_unref (intersected);
- /* 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;
- }
+ return TRUE;
}
/**
* gst_pad_query_position:
* @pad: a #GstPad to invoke the position query on.
- * @format: (inout): a pointer to the #GstFormat asked for.
- * On return contains the #GstFormat used.
+ * @format: the #GstFormat requested
* @cur: (out): A location in which to store the current position, or NULL.
*
* Queries a pad for the stream position.
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_pad_query_position (GstPad * pad, GstFormat * format, gint64 * cur)
+gst_pad_query_position (GstPad * pad, GstFormat format, gint64 * cur)
{
GstQuery *query;
gboolean ret;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
- g_return_val_if_fail (format != NULL, FALSE);
-
- query = gst_query_new_position (*format);
- ret = gst_pad_query (pad, query);
-
- if (ret)
- gst_query_parse_position (query, format, cur);
+ g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
+ query = gst_query_new_position (format);
+ if ((ret = gst_pad_query (pad, query)))
+ gst_query_parse_position (query, NULL, cur);
gst_query_unref (query);
return ret;
}
/**
- * gst_pad_query_peer_position:
+ * gst_pad_peer_query_position:
* @pad: a #GstPad on whose peer to invoke the position query on.
* Must be a sink pad.
- * @format: (inout): a pointer to the #GstFormat asked for.
- * On return contains the #GstFormat used.
+ * @format: the #GstFormat requested
* @cur: (out) (allow-none): a location in which to store the current
* position, or NULL.
*
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_pad_query_peer_position (GstPad * pad, GstFormat * format, gint64 * cur)
+gst_pad_peer_query_position (GstPad * pad, GstFormat format, gint64 * cur)
{
+ GstQuery *query;
gboolean ret = FALSE;
- GstPad *peer;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
- g_return_val_if_fail (format != NULL, FALSE);
+ g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
- peer = gst_pad_get_peer (pad);
- if (peer) {
- ret = gst_pad_query_position (peer, format, cur);
- gst_object_unref (peer);
- }
+ query = gst_query_new_position (format);
+ if ((ret = gst_pad_peer_query (pad, query)))
+ gst_query_parse_position (query, NULL, cur);
+ gst_query_unref (query);
return ret;
}
/**
* gst_pad_query_duration:
* @pad: a #GstPad to invoke the duration query on.
- * @format: (inout): a pointer to the #GstFormat asked for.
- * On return contains the #GstFormat used.
+ * @format: the #GstFormat requested
* @duration: (out) (allow-none): a location in which to store the total
* duration, or NULL.
*
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_pad_query_duration (GstPad * pad, GstFormat * format, gint64 * duration)
+gst_pad_query_duration (GstPad * pad, GstFormat format, gint64 * duration)
{
GstQuery *query;
gboolean ret;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
- g_return_val_if_fail (format != NULL, FALSE);
-
- query = gst_query_new_duration (*format);
- ret = gst_pad_query (pad, query);
-
- if (ret)
- gst_query_parse_duration (query, format, duration);
+ g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
+ query = gst_query_new_duration (format);
+ if ((ret = gst_pad_query (pad, query)))
+ gst_query_parse_duration (query, NULL, duration);
gst_query_unref (query);
return ret;
}
/**
- * gst_pad_query_peer_duration:
+ * gst_pad_peer_query_duration:
* @pad: a #GstPad on whose peer pad to invoke the duration query on.
* Must be a sink pad.
- * @format: (inout) :a pointer to the #GstFormat asked for.
- * On return contains the #GstFormat used.
+ * @format: the #GstFormat requested
* @duration: (out) (allow-none): a location in which to store the total
* duration, or NULL.
*
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_pad_query_peer_duration (GstPad * pad, GstFormat * format,
- gint64 * duration)
+gst_pad_peer_query_duration (GstPad * pad, GstFormat format, gint64 * duration)
{
+ GstQuery *query;
gboolean ret = FALSE;
- GstPad *peer;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
- g_return_val_if_fail (format != NULL, FALSE);
+ g_return_val_if_fail (format != GST_FORMAT_UNDEFINED, FALSE);
- peer = gst_pad_get_peer (pad);
- if (peer) {
- ret = gst_pad_query_duration (peer, format, duration);
- gst_object_unref (peer);
- }
+ query = gst_query_new_duration (format);
+ if ((ret = gst_pad_peer_query (pad, query)))
+ gst_query_parse_duration (query, NULL, duration);
+ gst_query_unref (query);
return ret;
}
* @pad: a #GstPad to invoke the convert query on.
* @src_format: a #GstFormat to convert from.
* @src_val: a value to convert.
- * @dest_format: (inout): a pointer to the #GstFormat to convert to.
+ * @dest_format: the #GstFormat to convert to.
* @dest_val: (out): a pointer to the result.
*
* Queries a pad to convert @src_val in @src_format to @dest_format.
*/
gboolean
gst_pad_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
- GstFormat * dest_format, gint64 * dest_val)
+ GstFormat dest_format, gint64 * dest_val)
{
GstQuery *query;
gboolean ret;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
- g_return_val_if_fail (dest_format != NULL, FALSE);
+ g_return_val_if_fail (dest_format != GST_FORMAT_UNDEFINED, FALSE);
g_return_val_if_fail (dest_val != NULL, FALSE);
- if (*dest_format == src_format || src_val == -1) {
+ if (dest_format == src_format || src_val == -1) {
*dest_val = src_val;
return TRUE;
}
- query = gst_query_new_convert (src_format, src_val, *dest_format);
- ret = gst_pad_query (pad, query);
-
- if (ret)
- gst_query_parse_convert (query, NULL, NULL, dest_format, dest_val);
-
+ query = gst_query_new_convert (src_format, src_val, dest_format);
+ if ((ret = gst_pad_query (pad, query)))
+ gst_query_parse_convert (query, NULL, NULL, NULL, dest_val);
gst_query_unref (query);
return ret;
}
/**
- * gst_pad_query_peer_convert:
+ * gst_pad_peer_query_convert:
* @pad: a #GstPad, on whose peer pad to invoke the convert query on.
* Must be a sink pad.
* @src_format: a #GstFormat to convert from.
* @src_val: a value to convert.
- * @dest_format: (inout): a pointer to the #GstFormat to convert to.
+ * @dest_format: the #GstFormat to convert to.
* @dest_val: (out): a pointer to the result.
*
* Queries the peer pad of a given sink pad to convert @src_val in @src_format
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_pad_query_peer_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
- GstFormat * dest_format, gint64 * dest_val)
+gst_pad_peer_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
+ GstFormat dest_format, gint64 * dest_val)
{
+ GstQuery *query;
gboolean ret = FALSE;
- GstPad *peer;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
g_return_val_if_fail (GST_PAD_IS_SINK (pad), FALSE);
- g_return_val_if_fail (dest_format != NULL, FALSE);
+ g_return_val_if_fail (dest_format != GST_FORMAT_UNDEFINED, FALSE);
g_return_val_if_fail (dest_val != NULL, FALSE);
- peer = gst_pad_get_peer (pad);
- if (peer) {
- ret = gst_pad_query_convert (peer, src_format, src_val, dest_format,
- dest_val);
- gst_object_unref (peer);
- }
+ query = gst_query_new_convert (src_format, src_val, dest_format);
+ if ((ret = gst_pad_peer_query (pad, query)))
+ gst_query_parse_convert (query, NULL, NULL, NULL, dest_val);
+ gst_query_unref (query);
return ret;
}
/**
- * gst_atomic_int_set:
- * @atomic_int: (inout): pointer to an atomic integer
- * @value: value to set
- *
- * Unconditionally sets the atomic integer to @value.
- *
- * Deprecated: Use g_atomic_int_set().
- *
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-void gst_atomic_int_set (gint * atomic_int, gint value);
-#endif
-void
-gst_atomic_int_set (gint * atomic_int, gint value)
-{
- g_atomic_int_set (atomic_int, value);
-}
-#endif
-
-/**
- * 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
+ * gst_pad_query_caps:
+ * @pad: a #GstPad to get the capabilities of.
+ * @filter: (allow-none): suggested #GstCaps, 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.
+ * Gets the capabilities this pad can produce or consume.
+ * Note that this method doesn't necessarily return the caps set by
+ * gst_pad_set_caps() - use gst_pad_get_current_caps() for that instead.
+ * gst_pad_query_caps returns all possible caps a pad can operate with, using
+ * the pad's CAPS query function, If the query fails, this function will return
+ * @filter, if not #NULL, otherwise ANY.
*
- * The @notify function is called when the probe is disconnected and usually
- * used to free @data.
+ * When called on sinkpads @filter contains the caps that
+ * upstream could produce in the order preferred by upstream. When
+ * called on srcpads @filter contains the caps accepted by
+ * downstream in the preffered order. @filter might be %NULL but
+ * if it is not %NULL the returned caps will be a subset of @filter.
*
- * Returns: The handler id
+ * Note that this function does not return writable #GstCaps, use
+ * gst_caps_make_writable() before modifying the caps.
*
- * Since: 0.10.20
+ * Returns: (transfer full): the caps of the pad with incremented ref-count.
*/
-gulong
-gst_pad_add_event_probe_full (GstPad * pad, GCallback handler,
- gpointer data, GDestroyNotify notify)
+GstCaps *
+gst_pad_query_caps (GstPad * pad, GstCaps * filter)
{
- gulong sigid;
-
- g_return_val_if_fail (GST_IS_PAD (pad), 0);
- g_return_val_if_fail (handler != NULL, 0);
-
- GST_OBJECT_LOCK (pad);
+ GstCaps *result = NULL;
+ GstQuery *query;
- /* 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);
+ g_return_val_if_fail (GST_IS_PAD (pad), NULL);
+ g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
- 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);
+ GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
- return sigid;
-}
+ query = gst_query_new_caps (filter);
+ if (gst_pad_query (pad, query)) {
+ gst_query_parse_caps_result (query, &result);
+ gst_caps_ref (result);
+ GST_DEBUG_OBJECT (pad, "query returned %" GST_PTR_FORMAT, result);
+ } else if (filter) {
+ result = gst_caps_ref (filter);
+ } else {
+ result = gst_caps_new_any ();
+ }
+ gst_query_unref (query);
-/**
- * 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);
+ return result;
}
/**
- * 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.
+ * gst_pad_peer_query_caps:
+ * @pad: a #GstPad to get the capabilities of.
+ * @filter: (allow-none): a #GstCaps filter, or NULL.
*
- * The @notify function is called when the probe is disconnected and usually
- * used to free @data.
+ * Gets the capabilities of the peer connected to this pad. Similar to
+ * gst_pad_query_caps().
*
- * Returns: The handler id
+ * When called on srcpads @filter contains the caps that
+ * upstream could produce in the order preferred by upstream. When
+ * called on sinkpads @filter contains the caps accepted by
+ * downstream in the preffered order. @filter might be %NULL but
+ * if it is not %NULL the returned caps will be a subset of @filter.
*
- * Since: 0.10.20
+ * Returns: the caps of the peer pad with incremented ref-count. This function
+ * returns %NULL when there is no peer pad.
*/
-gulong
-gst_pad_add_buffer_probe_full (GstPad * pad, GCallback handler,
- gpointer data, GDestroyNotify notify)
+GstCaps *
+gst_pad_peer_query_caps (GstPad * pad, GstCaps * filter)
{
- 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;
-}
+ GstCaps *result = NULL;
+ GstQuery *query;
-/**
- * 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);
+ g_return_val_if_fail (GST_IS_PAD (pad), NULL);
+ g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
+
+ query = gst_query_new_caps (filter);
+ if (gst_pad_peer_query (pad, query)) {
+ gst_query_parse_caps_result (query, &result);
+ gst_caps_ref (result);
+ GST_DEBUG_OBJECT (pad, "peer query returned %" GST_PTR_FORMAT, result);
+ } else if (filter) {
+ result = gst_caps_ref (filter);
+ } else {
+ result = gst_caps_new_any ();
+ }
+ gst_query_unref (query);
+ return result;
}
/**
- * 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
+ * gst_pad_query_accept_caps:
+ * @pad: a #GstPad to check
+ * @caps: a #GstCaps to check on the pad
*
- * 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
+ * Check if the given pad accepts the caps.
*
- * Removes a buffer probe from @pad.
+ * Returns: TRUE if the pad can accept the caps.
*/
-void
-gst_pad_remove_buffer_probe (GstPad * pad, guint handler_id)
+gboolean
+gst_pad_query_accept_caps (GstPad * pad, GstCaps * caps)
{
- g_return_if_fail (GST_IS_PAD (pad));
- g_return_if_fail (handler_id > 0);
+ gboolean res = TRUE;
+ GstQuery *query;
- 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);
+ g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
+ g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
-}
+ GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "accept caps of %p", caps);
-/**
- * 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
- * @list: (transfer full): the taglist to post on the bus and create event from
- *
- * Posts a message to the bus that new tags were found and pushes the
- * tags as event. Takes ownership of the @list.
- *
- * This is a utility method for elements. Applications should use the
- * #GstTagSetter interface.
- */
-void
-gst_element_found_tags_for_pad (GstElement * element,
- GstPad * pad, GstTagList * list)
-{
- g_return_if_fail (element != NULL);
- g_return_if_fail (pad != NULL);
- g_return_if_fail (list != NULL);
-
- gst_pad_push_event (pad, gst_event_new_tag (gst_tag_list_copy (list)));
- /* FIXME 0.11: Set the pad as source. */
- gst_element_post_message (element,
- gst_message_new_tag_full (GST_OBJECT (element), pad, list));
-}
+ query = gst_query_new_accept_caps (caps);
+ if (gst_pad_query (pad, query)) {
+ gst_query_parse_accept_caps_result (query, &res);
+ GST_DEBUG_OBJECT (pad, "query returned %d", res);
+ }
+ gst_query_unref (query);
-static void
-push_and_ref (GstPad * pad, GstEvent * event)
-{
- gst_pad_push_event (pad, gst_event_ref (event));
- /* iterator refs pad, we unref when we are done with it */
- gst_object_unref (pad);
+ return res;
}
/**
- * gst_element_found_tags:
- * @element: element for which we found the tags.
- * @list: (transfer full): list of tags.
+ * gst_pad_peer_query_accept_caps:
+ * @pad: a #GstPad to check the peer of
+ * @caps: a #GstCaps to check on the pad
*
- * Posts a message to the bus that new tags were found, and pushes an event
- * to all sourcepads. Takes ownership of the @list.
+ * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
+ * returns TRUE.
*
- * This is a utility method for elements. Applications should use the
- * #GstTagSetter interface.
+ * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
*/
-void
-gst_element_found_tags (GstElement * element, GstTagList * list)
+gboolean
+gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps * caps)
{
- GstIterator *iter;
- GstEvent *event;
+ gboolean res = TRUE;
+ GstQuery *query;
- g_return_if_fail (element != NULL);
- g_return_if_fail (list != NULL);
+ g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
+ g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
- iter = gst_element_iterate_src_pads (element);
- event = gst_event_new_tag (gst_tag_list_copy (list));
- gst_iterator_foreach (iter, (GFunc) push_and_ref, event);
- gst_iterator_free (iter);
- gst_event_unref (event);
+ query = gst_query_new_accept_caps (caps);
+ if (gst_pad_peer_query (pad, query)) {
+ gst_query_parse_accept_caps_result (query, &res);
+ GST_DEBUG_OBJECT (pad, "query returned %d", res);
+ }
+ gst_query_unref (query);
- gst_element_post_message (element,
- gst_message_new_tag (GST_OBJECT (element), list));
+ return res;
}
static GstPad *
GstIterator *iter;
GstPad *unlinked_pad = NULL;
gboolean done;
+ GValue data = { 0, };
switch (direction) {
case GST_PAD_SRC:
done = FALSE;
while (!done) {
- gpointer pad;
-
- switch (gst_iterator_next (iter, &pad)) {
+ switch (gst_iterator_next (iter, &data)) {
case GST_ITERATOR_OK:{
GstPad *peer;
+ GstPad *pad = g_value_get_object (&data);
GST_CAT_LOG (GST_CAT_ELEMENT_PADS, "examining pad %s:%s",
GST_DEBUG_PAD_NAME (pad));
- peer = gst_pad_get_peer (GST_PAD (pad));
+ peer = gst_pad_get_peer (pad);
if (peer == NULL) {
- unlinked_pad = pad;
+ unlinked_pad = gst_object_ref (pad);
done = TRUE;
GST_CAT_DEBUG (GST_CAT_ELEMENT_PADS,
"found existing unlinked pad %s:%s",
GST_DEBUG_PAD_NAME (unlinked_pad));
} else {
- gst_object_unref (pad);
gst_object_unref (peer);
}
+ g_value_reset (&data);
break;
}
case GST_ITERATOR_DONE:
break;
}
}
-
+ g_value_unset (&data);
gst_iterator_free (iter);
return unlinked_pad;
GstIterator *iter;
gboolean done;
GstPad *pad = NULL;
+ GValue data = { 0, };
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
done = FALSE;
iter = gst_bin_iterate_recurse (bin);
while (!done) {
- gpointer element;
+ switch (gst_iterator_next (iter, &data)) {
+ case GST_ITERATOR_OK:{
+ GstElement *element = g_value_get_object (&data);
- switch (gst_iterator_next (iter, &element)) {
- case GST_ITERATOR_OK:
- pad = element_find_unlinked_pad (GST_ELEMENT (element), direction);
- gst_object_unref (element);
+ pad = element_find_unlinked_pad (element, direction);
if (pad != NULL)
done = TRUE;
+ g_value_reset (&data);
break;
+ }
case GST_ITERATOR_DONE:
done = TRUE;
break;
break;
}
}
-
+ g_value_unset (&data);
gst_iterator_free (iter);
return pad;
}
/**
- * gst_bin_find_unconnected_pad:
- * @bin: bin in which to look for elements with unlinked pads
- * @direction: whether to look for an unlinked source or sink pad
- *
- * Recursively looks for elements with an unlinked pad of the given
- * direction within the specified bin and returns an unlinked pad
- * if one is found, or NULL otherwise. If a pad is found, the caller
- * owns a reference to it and should use gst_object_unref() on the
- * pad when it is not needed any longer.
- *
- * Returns: (transfer full): unlinked pad of the given direction, or NULL.
- *
- * Since: 0.10.3
- *
- * Deprecated: use gst_bin_find_unlinked_pad() instead.
- */
-#ifndef GST_REMOVE_DEPRECATED
-#ifdef GST_DISABLE_DEPRECATED
-GstPad *gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction);
-#endif
-GstPad *
-gst_bin_find_unconnected_pad (GstBin * bin, GstPadDirection direction)
-{
- return gst_bin_find_unlinked_pad (bin, direction);
-}
-#endif
-
-/**
* gst_parse_bin_from_description:
* @bin_description: command line describing the bin
* @ghost_unlinked_pads: whether to automatically create ghost pads
* and want them all ghosted, you will have to create the ghost pads
* yourself).
*
- * Returns: (transfer full): a newly-created bin, or NULL if an error occurred.
+ * Returns: (transfer floating): a newly-created bin, or NULL if an error occurred.
*
* Since: 0.10.3
*/
}
/**
- * gst_type_register_static_full:
- * @parent_type: The GType of the parent type the newly registered type will
- * derive from
- * @type_name: NULL-terminated string used as the name of the new type
- * @class_size: Size of the class structure.
- * @base_init: Location of the base initialization function (optional).
- * @base_finalize: Location of the base finalization function (optional).
- * @class_init: Location of the class initialization function for class types
- * Location of the default vtable initialization function for interface
- * types. (optional)
- * @class_finalize: Location of the class finalization function for class types.
- * Location of the default vtable finalization function for interface types.
- * (optional)
- * @class_data: User-supplied data passed to the class init/finalize functions.
- * @instance_size: Size of the instance (object) structure (required for
- * instantiatable types only).
- * @n_preallocs: The number of pre-allocated (cached) instances to reserve
- * memory for (0 indicates no caching). Ignored on recent GLib's.
- * @instance_init: Location of the instance initialization function (optional,
- * for instantiatable types only).
- * @value_table: A GTypeValueTable function table for generic handling of
- * GValues of this type (usually only useful for fundamental types).
- * @flags: #GTypeFlags for this GType. E.g: G_TYPE_FLAG_ABSTRACT
- *
- * Helper function which constructs a #GTypeInfo structure and registers a
- * GType, but which generates less linker overhead than a static const
- * #GTypeInfo structure. For further details of the parameters, please see
- * #GTypeInfo in the GLib documentation.
- *
- * Registers type_name as the name of a new static type derived from
- * parent_type. The value of flags determines the nature (e.g. abstract or
- * not) of the type. It works by filling a GTypeInfo struct and calling
- * g_type_register_static().
- *
- * Returns: A #GType for the newly-registered type.
- *
- * Since: 0.10.14
- */
-GType
-gst_type_register_static_full (GType parent_type,
- const gchar * type_name,
- guint class_size,
- GBaseInitFunc base_init,
- GBaseFinalizeFunc base_finalize,
- GClassInitFunc class_init,
- GClassFinalizeFunc class_finalize,
- gconstpointer class_data,
- guint instance_size,
- guint16 n_preallocs,
- GInstanceInitFunc instance_init,
- const GTypeValueTable * value_table, GTypeFlags flags)
-{
- GTypeInfo info;
-
- g_return_val_if_fail (class_size <= G_MAXUINT16, G_TYPE_INVALID);
- g_return_val_if_fail (instance_size <= G_MAXUINT16, G_TYPE_INVALID);
-
- info.class_size = class_size;
- info.base_init = base_init;
- info.base_finalize = base_finalize;
- info.class_init = class_init;
- info.class_finalize = class_finalize;
- info.class_data = class_data;
- info.instance_size = instance_size;
- info.n_preallocs = n_preallocs;
- info.instance_init = instance_init;
- info.value_table = value_table;
-
- return g_type_register_static (parent_type, type_name, &info, flags);
-}
-
-
-/**
* gst_util_get_timestamp:
*
* Get a timestamp as GstClockTime to be used for interval measurements.
}
/**
+ * gst_util_greatest_common_divisor_int64:
+ * @a: First value as #gint64
+ * @b: Second value as #gint64
+ *
+ * Calculates the greatest common divisor of @a
+ * and @b.
+ *
+ * Returns: Greatest common divisor of @a and @b
+ *
+ * Since: 0.11.0
+ */
+gint64
+gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b)
+{
+ while (b != 0) {
+ gint64 temp = a;
+
+ a = b;
+ b = temp % b;
+ }
+
+ return ABS (a);
+}
+
+
+/**
* gst_util_fraction_to_double:
* @src_n: Fraction numerator as #gint
* @src_d: Fraction denominator #gint