/* same as gst_caps_is_any () */
#define CAPS_IS_ANY(caps) \
- (GST_CAPS_FLAGS(caps) & GST_CAPS_FLAG_ANY)
+ (!!(GST_CAPS_FLAGS(caps) & GST_CAPS_FLAG_ANY))
/* same as gst_caps_is_empty () */
#define CAPS_IS_EMPTY(caps) \
G_TYPE_STRING, gst_caps_transform_to_string);
}
+GstCapsFeatures *
+__gst_caps_get_features_unchecked (const GstCaps * caps, guint idx)
+{
+ return gst_caps_get_features_unchecked (caps, idx);
+}
+
static GstCaps *
_gst_caps_copy (const GstCaps * caps)
{
* @...: additional structures to add
*
* Creates a new #GstCaps and adds all the structures listed as
- * arguments. The list must be NULL-terminated. The structures
+ * arguments. The list must be %NULL-terminated. The structures
* are not copied; the returned #GstCaps owns the structures.
*
* Returns: (transfer full): the new #GstCaps
* @var_args: additional structures to add
*
* Creates a new #GstCaps and adds all the structures listed as
- * arguments. The list must be NULL-terminated. The structures
+ * arguments. The list must be %NULL-terminated. The structures
* are not copied; the returned #GstCaps owns the structures.
*
* Returns: (transfer full): the new #GstCaps
return s;
}
-
-
/**
* gst_caps_steal_structure:
* @caps: the #GstCaps to retrieve from
if (features)
gst_caps_features_set_parent_refcount (features, &GST_CAPS_REFCOUNT (caps));
- if (old)
+ if (old) {
+ gst_caps_features_set_parent_refcount (old, NULL);
gst_caps_features_free (old);
+ }
}
/**
* @varargs: additional parameters
*
* Sets fields in a #GstCaps. The arguments must be passed in the same
- * manner as gst_structure_set(), and be NULL-terminated.
+ * manner as gst_structure_set(), and be %NULL-terminated.
*/
void
gst_caps_set_simple_valist (GstCaps * caps, const char *field, va_list varargs)
* @...: additional parameters
*
* Sets fields in a #GstCaps. The arguments must be passed in the same
- * manner as gst_structure_set(), and be NULL-terminated.
+ * manner as gst_structure_set(), and be %NULL-terminated.
*/
void
gst_caps_set_simple (GstCaps * caps, const char *field, ...)
*
* Determines if @caps represents any media format.
*
- * Returns: TRUE if @caps represents any format.
+ * Returns: %TRUE if @caps represents any format.
*/
gboolean
gst_caps_is_any (const GstCaps * caps)
*
* Determines if @caps represents no media formats.
*
- * Returns: TRUE if @caps represents no formats.
+ * Returns: %TRUE if @caps represents no formats.
*/
gboolean
gst_caps_is_empty (const GstCaps * caps)
* one structure, and each field in the structure describes a fixed type.
* Examples of non-fixed types are GST_TYPE_INT_RANGE and GST_TYPE_LIST.
*
- * Returns: TRUE if @caps is fixed
+ * Returns: %TRUE if @caps is fixed
*/
gboolean
gst_caps_is_fixed (const GstCaps * caps)
* Tests if two #GstCaps are equal. This function only works on fixed
* #GstCaps.
*
- * Returns: TRUE if the arguments represent the same format
+ * Returns: %TRUE if the arguments represent the same format
*/
gboolean
gst_caps_is_equal_fixed (const GstCaps * caps1, const GstCaps * caps2)
* every media format that is in the first is also contained in the
* second. That is, @caps1 is a subset of @caps2.
*
- * Returns: TRUE if @caps1 is a subset of @caps2.
+ * Returns: %TRUE if @caps1 is a subset of @caps2.
*/
gboolean
gst_caps_is_always_compatible (const GstCaps * caps1, const GstCaps * caps2)
*
* Checks if the given caps represent the same set of caps.
*
- * Returns: TRUE if both caps are equal.
+ * Returns: %TRUE if both caps are equal.
*/
gboolean
gst_caps_is_equal (const GstCaps * caps1, const GstCaps * caps2)
*
* Checks if the given caps are exactly the same set of caps.
*
- * Returns: TRUE if both caps are strictly equal.
+ * Returns: %TRUE if both caps are strictly equal.
*/
gboolean
gst_caps_is_strictly_equal (const GstCaps * caps1, const GstCaps * caps2)
if (!priv_gst_structure_parse_fields (s, &s, structure)) {
gst_structure_free (structure);
+ if (features)
+ gst_caps_features_free (features);
g_free (copy);
return FALSE;
}
append:
gst_caps_append_structure_unchecked (caps, structure, features);
+ features = NULL;
if (*s == '\0')
break;
} while (TRUE);
g_value_take_string (dest_value,
gst_caps_to_string (gst_value_get_caps (src_value)));
}
+
+/**
+ * gst_caps_foreach:
+ * @caps: a #GstCaps
+ * @func: (scope call): a function to call for each field
+ * @user_data: (closure): private data
+ *
+ * Calls the provided function once for each structure and caps feature in the
+ * #GstCaps. The function must not modify the fields.
+ * Also see gst_caps_map_in_place() and gst_caps_filter_and_map_in_place().
+ *
+ * Returns: %TRUE if the supplied function returns %TRUE for each call,
+ * %FALSE otherwise.
+ *
+ * Since: 1.6
+ */
+gboolean
+gst_caps_foreach (const GstCaps * caps, GstCapsForeachFunc func,
+ gpointer user_data)
+{
+ guint i, n;
+ GstCapsFeatures *features;
+ GstStructure *structure;
+ gboolean ret;
+
+ g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
+ g_return_val_if_fail (func != NULL, FALSE);
+
+ n = GST_CAPS_LEN (caps);
+
+ for (i = 0; i < n; i++) {
+ features = gst_caps_get_features_unchecked (caps, i);
+ structure = gst_caps_get_structure_unchecked (caps, i);
+
+ ret = func (features, structure, user_data);
+ if (G_UNLIKELY (!ret))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * gst_caps_map_in_place:
+ * @caps: a #GstCaps
+ * @func: (scope call): a function to call for each field
+ * @user_data: (closure): private data
+ *
+ * Calls the provided function once for each structure and caps feature in the
+ * #GstCaps. In contrast to gst_caps_foreach(), the function may modify but not
+ * delete the structures and features. The caps must be mutable.
+ *
+ * Returns: %TRUE if the supplied function returns %TRUE for each call,
+ * %FALSE otherwise.
+ *
+ * Since: 1.6
+ */
+gboolean
+gst_caps_map_in_place (GstCaps * caps, GstCapsMapFunc func, gpointer user_data)
+{
+ guint i, n;
+ GstCapsFeatures *features;
+ GstStructure *structure;
+ gboolean ret;
+
+ g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
+ g_return_val_if_fail (gst_caps_is_writable (caps), FALSE);
+ g_return_val_if_fail (func != NULL, FALSE);
+
+ n = GST_CAPS_LEN (caps);
+
+ for (i = 0; i < n; i++) {
+ features = gst_caps_get_features_unchecked (caps, i);
+ structure = gst_caps_get_structure_unchecked (caps, i);
+
+ /* Provide sysmem features if there are none yet */
+ if (!features) {
+ features =
+ gst_caps_features_copy (GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY);
+ gst_caps_set_features (caps, i, features);
+ }
+
+ ret = func (features, structure, user_data);
+ if (G_UNLIKELY (!ret))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ * gst_caps_filter_and_map_in_place:
+ * @caps: a #GstCaps
+ * @func: (scope call): a function to call for each field
+ * @user_data: (closure): private data
+ *
+ * Calls the provided function once for each structure and caps feature in the
+ * #GstCaps. In contrast to gst_caps_foreach(), the function may modify the
+ * structure and features. In contrast to gst_caps_filter_and_map_in_place(),
+ * the structure and features are removed from the caps if %FALSE is returned
+ * from the function.
+ * The caps must be mutable.
+ *
+ * Since: 1.6
+ */
+void
+gst_caps_filter_and_map_in_place (GstCaps * caps, GstCapsFilterMapFunc func,
+ gpointer user_data)
+{
+ guint i, n;
+ GstCapsFeatures *features;
+ GstStructure *structure;
+ gboolean ret;
+
+ g_return_if_fail (GST_IS_CAPS (caps));
+ g_return_if_fail (gst_caps_is_writable (caps));
+ g_return_if_fail (func != NULL);
+
+ n = GST_CAPS_LEN (caps);
+
+ for (i = 0; i < n;) {
+ features = gst_caps_get_features_unchecked (caps, i);
+ structure = gst_caps_get_structure_unchecked (caps, i);
+
+ /* Provide sysmem features if there are none yet */
+ if (!features) {
+ features =
+ gst_caps_features_copy (GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY);
+ gst_caps_set_features (caps, i, features);
+ }
+
+ ret = func (features, structure, user_data);
+ if (!ret) {
+ GST_CAPS_ARRAY (caps) = g_array_remove_index (GST_CAPS_ARRAY (caps), i);
+
+ gst_structure_set_parent_refcount (structure, NULL);
+ gst_structure_free (structure);
+ if (features) {
+ gst_caps_features_set_parent_refcount (features, NULL);
+ gst_caps_features_free (features);
+ }
+
+ n = GST_CAPS_LEN (caps);
+ } else {
+ i++;
+ }
+ }
+}