gst_util_seqnum_next (void)
{
static gint counter = 0;
- return G_ATOMIC_INT_ADD (&counter, 1);
+ return g_atomic_int_add (&counter, 1);
}
/**
*/
GstPad *
gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
- const GstCaps * caps)
+ GstCaps * caps)
{
GstIterator *pads;
GstPadTemplate *templ;
gboolean compatible;
/* Now check if the two pads' caps are compatible */
- temp = gst_pad_get_caps (pad, NULL);
+ 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 (current, NULL);
+ temp = gst_pad_query_caps (current, NULL);
compatible = gst_caps_can_intersect (temp, intersection);
gst_caps_unref (temp);
gst_caps_unref (intersection);
/* 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 (pad, NULL);
+ 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);
void
gst_pad_use_fixed_caps (GstPad * pad)
{
- GST_OBJECT_FLAG_SET (pad, GST_PAD_FIXED_CAPS);
+ GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_FIXED_CAPS);
}
/**
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.
* @pad: a #GstPad to proxy.
* @query: an ACCEPT_CAPS #GstQuery.
*
- * Calls gst_pad_accept_caps() for every pad with oposite direction belonging
- * to the same element as @pad, and returns the intersection of the results.
+ * Calls gst_pad_accept_caps() for all internally linked pads of @pad and
+ * returns the intersection of the results.
*
* 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
gboolean
gst_pad_proxy_query_accept_caps (GstPad * pad, GstQuery * query)
{
- GstElement *element;
QueryAcceptCapsData data;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
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;
-
data.query = query;
/* value to hold the return, by default it holds TRUE */
data.ret = TRUE;
gst_pad_forward (pad, (GstPadForwardFunction) query_accept_caps_func, &data);
-
- gst_object_unref (element);
-
gst_query_set_accept_caps_result (query, data.ret);
return TRUE;
-
- /* ERRORS */
-no_parent:
- {
- GST_DEBUG_OBJECT (pad, "no parent");
- return FALSE;
- }
}
typedef struct
* @pad: a #GstPad to proxy.
* @query: a CAPS #GstQuery.
*
- * Calls gst_pad_get_caps() for every pad with oposite direction belonging
- * to the same element as @pad, and returns the intersection of the results.
+ * Calls gst_pad_query_caps() for all internally linked pads fof @pad and returns
+ * the intersection of the results.
*
* 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
gboolean
gst_pad_proxy_query_caps (GstPad * pad, GstQuery * query)
{
- GstElement *element;
- GstCaps *intersected;
+ GstCaps *templ, *intersected;
QueryCapsData data;
g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
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)
- goto no_parent;
-
data.query = query;
/* value to hold the return, by default it holds ANY */
data.ret = gst_caps_new_any ();
gst_pad_forward (pad, (GstPadForwardFunction) query_caps_func, &data);
- gst_object_unref (element);
-
+ templ = gst_pad_get_pad_template_caps (pad);
if (data.ret) {
- intersected =
- gst_caps_intersect (data.ret, gst_pad_get_pad_template_caps (pad));
+ intersected = gst_caps_intersect (data.ret, templ);
gst_caps_unref (data.ret);
} else {
- intersected = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
+ intersected = templ;
}
gst_query_set_caps_result (query, intersected);
+ gst_caps_unref (templ);
gst_caps_unref (intersected);
return TRUE;
-
- /* ERRORS */
-no_parent:
- {
- GST_DEBUG_OBJECT (pad, "no parent");
- return FALSE;
- }
}
/**
}
/**
- * 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: the #GstFormat requested
* 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;
}
/**
- * 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: the #GstFormat requested
* 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;
}
/**
- * 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.
* Returns: TRUE if the query could be performed.
*/
gboolean
-gst_pad_query_peer_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
+gst_pad_peer_query_convert (GstPad * pad, GstFormat src_format, gint64 src_val,
GstFormat dest_format, gint64 * dest_val)
{
GstQuery *query;
return ret;
}
+/**
+ * gst_pad_query_caps:
+ * @pad: a #GstPad to get the capabilities of.
+ * @filter: (allow-none): suggested #GstCaps, or NULL
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Note that this function does not return writable #GstCaps, use
+ * gst_caps_make_writable() before modifying the caps.
+ *
+ * Returns: (transfer full): the caps of the pad with incremented ref-count.
+ */
+GstCaps *
+gst_pad_query_caps (GstPad * pad, GstCaps * filter)
+{
+ GstCaps *result = NULL;
+ GstQuery *query;
+
+ g_return_val_if_fail (GST_IS_PAD (pad), NULL);
+ g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
+
+ GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
+
+ 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);
+
+ return result;
+}
+
+/**
+ * gst_pad_peer_query_caps:
+ * @pad: a #GstPad to get the capabilities of.
+ * @filter: (allow-none): a #GstCaps filter, or NULL.
+ *
+ * Gets the capabilities of the peer connected to this pad. Similar to
+ * gst_pad_query_caps().
+ *
+ * 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.
+ *
+ * Returns: the caps of the peer pad with incremented ref-count. This function
+ * returns %NULL when there is no peer pad.
+ */
+GstCaps *
+gst_pad_peer_query_caps (GstPad * pad, GstCaps * filter)
+{
+ GstCaps *result = NULL;
+ GstQuery *query;
+
+ 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_query_accept_caps:
+ * @pad: a #GstPad to check
+ * @caps: a #GstCaps to check on the pad
+ *
+ * Check if the given pad accepts the caps.
+ *
+ * Returns: TRUE if the pad can accept the caps.
+ */
+gboolean
+gst_pad_query_accept_caps (GstPad * pad, GstCaps * caps)
+{
+ gboolean res = TRUE;
+ GstQuery *query;
+
+ 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);
+
+ 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);
+
+ return res;
+}
+
+/**
+ * gst_pad_peer_query_accept_caps:
+ * @pad: a #GstPad to check the peer of
+ * @caps: a #GstCaps to check on the pad
+ *
+ * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
+ * returns TRUE.
+ *
+ * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
+ */
+gboolean
+gst_pad_peer_query_accept_caps (GstPad * pad, GstCaps * caps)
+{
+ gboolean res = TRUE;
+ GstQuery *query;
+
+ g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
+ g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
+
+ 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);
+
+ return res;
+}
+
static GstPad *
element_find_unlinked_pad (GstElement * element, GstPadDirection direction)
{
* 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_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