mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 19:21:06 +00:00
gst: caps: Add API for creating caps / setting caps fields from static strings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7432>
This commit is contained in:
parent
ba552fb76f
commit
21af7061eb
2 changed files with 206 additions and 4 deletions
|
@ -318,6 +318,44 @@ gst_caps_new_empty_simple (const char *media_type)
|
|||
return caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_new_empty_simple_static_str:
|
||||
* @media_type: the media type of the structure
|
||||
*
|
||||
* Creates a new #GstCaps that contains one #GstStructure with name
|
||||
* @media_type.
|
||||
*
|
||||
* @media_type needs to be valid for the remaining lifetime of the process, e.g.
|
||||
* has to be a static string.
|
||||
*
|
||||
* Returns: (transfer full): the new #GstCaps
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstCaps *
|
||||
gst_caps_new_empty_simple_static_str (const char *media_type)
|
||||
{
|
||||
GstCaps *caps;
|
||||
GstStructure *structure;
|
||||
|
||||
caps = gst_caps_new_empty ();
|
||||
if (strcmp ("ANY", media_type) == 0) {
|
||||
g_warning
|
||||
("media_type should not be ANY. Please consider using `gst_caps_new_any` or `gst_caps_from_string`.");
|
||||
}
|
||||
if (strcmp ("", media_type) == 0 || strcmp ("EMPTY", media_type) == 0
|
||||
|| strcmp ("NONE", media_type) == 0) {
|
||||
g_warning
|
||||
("media_type should not be `%s`. Please consider using `gst_caps_new_empty` or `gst_caps_from_string`.",
|
||||
media_type);
|
||||
}
|
||||
structure = gst_structure_new_static_str_empty (media_type);
|
||||
if (structure)
|
||||
gst_caps_append_structure_unchecked (caps, structure, NULL);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_new_simple:
|
||||
* @media_type: the media type of the structure
|
||||
|
@ -351,6 +389,46 @@ gst_caps_new_simple (const char *media_type, const char *fieldname, ...)
|
|||
return caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_new_simple_static_str:
|
||||
* @media_type: the media type of the structure
|
||||
* @fieldname: first field to set
|
||||
* @...: additional arguments
|
||||
*
|
||||
* Creates a new #GstCaps that contains one #GstStructure. The
|
||||
* structure is defined by the arguments, which have the same format
|
||||
* as gst_structure_new().
|
||||
*
|
||||
* @media_type, @fieldname and all other fieldnames need to be valid for the
|
||||
* remaining lifetime of the process, e.g. have to be static strings.
|
||||
*
|
||||
* Returns: (transfer full): the new #GstCaps
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstCaps *
|
||||
gst_caps_new_simple_static_str (const char *media_type, const char *fieldname,
|
||||
...)
|
||||
{
|
||||
GstCaps *caps;
|
||||
GstStructure *structure;
|
||||
va_list var_args;
|
||||
|
||||
caps = gst_caps_new_empty ();
|
||||
|
||||
va_start (var_args, fieldname);
|
||||
structure =
|
||||
gst_structure_new_static_str_valist (media_type, fieldname, var_args);
|
||||
va_end (var_args);
|
||||
|
||||
if (structure)
|
||||
gst_caps_append_structure_unchecked (caps, structure, NULL);
|
||||
else
|
||||
gst_caps_replace (&caps, NULL);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_new_full:
|
||||
* @struct1: the first structure to add
|
||||
|
@ -1120,6 +1198,39 @@ gst_caps_set_value (GstCaps * caps, const char *field, const GValue * value)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_set_value_static_str:
|
||||
* @caps: a writable caps
|
||||
* @field: name of the field to set
|
||||
* @value: value to set the field to
|
||||
*
|
||||
* Sets the given @field on all structures of @caps to the given @value.
|
||||
* This is a convenience function for calling gst_structure_set_value() on
|
||||
* all structures of @caps.
|
||||
*
|
||||
* @field needs to be valid for the remaining lifetime of the process, e.g.
|
||||
* has to be a static string.
|
||||
*
|
||||
* Since: 1.26
|
||||
**/
|
||||
void
|
||||
gst_caps_set_value_static_str (GstCaps * caps, const char *field,
|
||||
const GValue * value)
|
||||
{
|
||||
guint i, len;
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS (caps));
|
||||
g_return_if_fail (IS_WRITABLE (caps));
|
||||
g_return_if_fail (field != NULL);
|
||||
g_return_if_fail (G_IS_VALUE (value));
|
||||
|
||||
len = GST_CAPS_LEN (caps);
|
||||
for (i = 0; i < len; i++) {
|
||||
GstStructure *structure = gst_caps_get_structure_unchecked (caps, i);
|
||||
gst_structure_set_value_static_str (structure, field, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_set_simple_valist:
|
||||
* @caps: the #GstCaps to set
|
||||
|
@ -1158,6 +1269,50 @@ gst_caps_set_simple_valist (GstCaps * caps, const char *field, va_list varargs)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_set_simple_static_str_valist:
|
||||
* @caps: the #GstCaps to set
|
||||
* @field: first field to set
|
||||
* @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.
|
||||
*
|
||||
* @field and all other field names need to be valid for the remaining lifetime
|
||||
* of the process, e.g. have to be static strings.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_caps_set_simple_static_str_valist (GstCaps * caps, const char *field,
|
||||
va_list varargs)
|
||||
{
|
||||
GValue value = { 0, };
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS (caps));
|
||||
g_return_if_fail (IS_WRITABLE (caps));
|
||||
|
||||
while (field) {
|
||||
GType type;
|
||||
char *err;
|
||||
|
||||
type = va_arg (varargs, GType);
|
||||
|
||||
G_VALUE_COLLECT_INIT (&value, type, varargs, 0, &err);
|
||||
if (G_UNLIKELY (err)) {
|
||||
g_critical ("%s", err);
|
||||
g_free (err);
|
||||
return;
|
||||
}
|
||||
|
||||
gst_caps_set_value_static_str (caps, field, &value);
|
||||
|
||||
g_value_unset (&value);
|
||||
|
||||
field = va_arg (varargs, const gchar *);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_set_simple:
|
||||
* @caps: the #GstCaps to set
|
||||
|
@ -1180,6 +1335,33 @@ gst_caps_set_simple (GstCaps * caps, const char *field, ...)
|
|||
va_end (var_args);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_caps_set_simple_static_str:
|
||||
* @caps: the #GstCaps to set
|
||||
* @field: first field to set
|
||||
* @...: additional parameters
|
||||
*
|
||||
* Sets fields in a #GstCaps. The arguments must be passed in the same
|
||||
* manner as gst_structure_set(), and be %NULL-terminated.
|
||||
*
|
||||
* @field and all other field names need to be valid for the remaining lifetime
|
||||
* of the process, e.g. have to be static strings.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_caps_set_simple_static_str (GstCaps * caps, const char *field, ...)
|
||||
{
|
||||
va_list var_args;
|
||||
|
||||
g_return_if_fail (GST_IS_CAPS (caps));
|
||||
g_return_if_fail (IS_WRITABLE (caps));
|
||||
|
||||
va_start (var_args, field);
|
||||
gst_caps_set_simple_static_str_valist (caps, field, var_args);
|
||||
va_end (var_args);
|
||||
}
|
||||
|
||||
/* tests */
|
||||
|
||||
/**
|
||||
|
@ -1255,7 +1437,8 @@ gst_caps_is_fixed (const GstCaps * caps)
|
|||
|
||||
structure = gst_caps_get_structure_unchecked (caps, 0);
|
||||
|
||||
return gst_structure_foreach_id_str (structure, gst_caps_is_fixed_foreach, NULL);
|
||||
return gst_structure_foreach_id_str (structure, gst_caps_is_fixed_foreach,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1973,7 +2156,8 @@ typedef struct _NormalizeForeach
|
|||
} NormalizeForeach;
|
||||
|
||||
static gboolean
|
||||
gst_caps_normalize_foreach (const GstIdStr * field, const GValue * value, gpointer ptr)
|
||||
gst_caps_normalize_foreach (const GstIdStr * field, const GValue * value,
|
||||
gpointer ptr)
|
||||
{
|
||||
NormalizeForeach *nf = (NormalizeForeach *) ptr;
|
||||
GValue val = { 0 };
|
||||
|
@ -2060,8 +2244,8 @@ typedef struct
|
|||
} UnionField;
|
||||
|
||||
static gboolean
|
||||
gst_caps_structure_figure_out_union (const GstIdStr * field, const GValue * value,
|
||||
gpointer user_data)
|
||||
gst_caps_structure_figure_out_union (const GstIdStr * field,
|
||||
const GValue * value, gpointer user_data)
|
||||
{
|
||||
UnionField *u = user_data;
|
||||
const GValue *val = gst_structure_id_str_get_value (u->compare, field);
|
||||
|
|
|
@ -369,11 +369,18 @@ GstCaps * gst_caps_new_any (void);
|
|||
GST_API
|
||||
GstCaps * gst_caps_new_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
GST_API
|
||||
GstCaps * gst_caps_new_empty_simple_static_str (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
GST_API
|
||||
GstCaps * gst_caps_new_simple (const char *media_type,
|
||||
const char *fieldname,
|
||||
...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
|
||||
GST_API
|
||||
GstCaps * gst_caps_new_simple_static_str (const char *media_type,
|
||||
const char *fieldname,
|
||||
...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
|
||||
GST_API
|
||||
GstCaps * gst_caps_new_full (GstStructure *struct1,
|
||||
...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
|
||||
GST_API
|
||||
|
@ -448,13 +455,24 @@ void gst_caps_set_value (GstCaps *caps,
|
|||
const char *field,
|
||||
const GValue *value);
|
||||
GST_API
|
||||
void gst_caps_set_value_static_str (GstCaps *caps,
|
||||
const char *field,
|
||||
const GValue *value);
|
||||
GST_API
|
||||
void gst_caps_set_simple (GstCaps *caps,
|
||||
const char *field, ...) G_GNUC_NULL_TERMINATED;
|
||||
GST_API
|
||||
void gst_caps_set_simple_static_str (GstCaps *caps,
|
||||
const char *field, ...) G_GNUC_NULL_TERMINATED;
|
||||
GST_API
|
||||
void gst_caps_set_simple_valist (GstCaps *caps,
|
||||
const char *field,
|
||||
va_list varargs);
|
||||
GST_API
|
||||
void gst_caps_set_simple_static_str_valist (GstCaps *caps,
|
||||
const char *field,
|
||||
va_list varargs);
|
||||
GST_API
|
||||
gboolean gst_caps_foreach (const GstCaps *caps,
|
||||
GstCapsForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
|
Loading…
Reference in a new issue