mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 03:31:05 +00:00
gst: add more GstIdStr functions to Caps & Structure
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7644>
This commit is contained in:
parent
375acaed51
commit
7fc418e08c
4 changed files with 295 additions and 2 deletions
|
@ -285,6 +285,42 @@ gst_caps_new_any (void)
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_caps_new_id_str_empty_simple:
|
||||||
|
* @media_type: the media type of the structure
|
||||||
|
*
|
||||||
|
* Creates a new #GstCaps that contains one #GstStructure with name
|
||||||
|
* @media_type.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): the new #GstCaps
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
GstCaps *
|
||||||
|
gst_caps_new_id_str_empty_simple (const GstIdStr * media_type)
|
||||||
|
{
|
||||||
|
GstCaps *caps;
|
||||||
|
GstStructure *structure;
|
||||||
|
|
||||||
|
caps = gst_caps_new_empty ();
|
||||||
|
if (gst_id_str_is_equal_to_str (media_type, "ANY")) {
|
||||||
|
g_warning
|
||||||
|
("media_type should not be ANY. Please consider using `gst_caps_new_any` or `gst_caps_from_string`.");
|
||||||
|
}
|
||||||
|
if (gst_id_str_get_len (media_type) == 0
|
||||||
|
|| gst_id_str_is_equal_to_str (media_type, "EMPTY")
|
||||||
|
|| gst_id_str_is_equal_to_str (media_type, "NONE")) {
|
||||||
|
g_warning
|
||||||
|
("media_type should not be `%s`. Please consider using `gst_caps_new_empty` or `gst_caps_from_string`.",
|
||||||
|
gst_id_str_as_str (media_type));
|
||||||
|
}
|
||||||
|
structure = gst_structure_new_id_str_empty (media_type);
|
||||||
|
if (structure)
|
||||||
|
gst_caps_append_structure_unchecked (caps, structure, NULL);
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_caps_new_empty_simple:
|
* gst_caps_new_empty_simple:
|
||||||
* @media_type: the media type of the structure
|
* @media_type: the media type of the structure
|
||||||
|
@ -356,6 +392,42 @@ gst_caps_new_static_str_empty_simple (const char *media_type)
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_caps_new_id_str_simple:
|
||||||
|
* @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().
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): the new #GstCaps
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
GstCaps *
|
||||||
|
gst_caps_new_id_str_simple (const GstIdStr * media_type,
|
||||||
|
const GstIdStr * fieldname, ...)
|
||||||
|
{
|
||||||
|
GstCaps *caps;
|
||||||
|
GstStructure *structure;
|
||||||
|
va_list var_args;
|
||||||
|
|
||||||
|
caps = gst_caps_new_empty ();
|
||||||
|
|
||||||
|
va_start (var_args, fieldname);
|
||||||
|
structure = gst_structure_new_id_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_simple:
|
* gst_caps_new_simple:
|
||||||
* @media_type: the media type of the structure
|
* @media_type: the media type of the structure
|
||||||
|
@ -1171,6 +1243,36 @@ gst_caps_truncate (GstCaps * caps)
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_caps_id_str_set_value:
|
||||||
|
* @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.
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
gst_caps_id_str_set_value (GstCaps * caps, const GstIdStr * 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_id_str_set_value (structure, field, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_caps_set_value:
|
* gst_caps_set_value:
|
||||||
* @caps: a writable caps
|
* @caps: a writable caps
|
||||||
|
@ -1231,6 +1333,47 @@ gst_caps_set_value_static_str (GstCaps * caps, const char *field,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_caps_id_str_set_simple_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_id_str_set(), and be %NULL-terminated.
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_caps_id_str_set_simple_valist (GstCaps * caps, const GstIdStr * 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_id_str_set_value (caps, field, &value);
|
||||||
|
|
||||||
|
g_value_unset (&value);
|
||||||
|
|
||||||
|
field = va_arg (varargs, const GstIdStr *);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_caps_set_simple_valist:
|
* gst_caps_set_simple_valist:
|
||||||
* @caps: the #GstCaps to set
|
* @caps: the #GstCaps to set
|
||||||
|
@ -1313,6 +1456,30 @@ gst_caps_set_simple_static_str_valist (GstCaps * caps, const char *field,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_caps_id_str_set_simple:
|
||||||
|
* @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_id_str_set(), and be %NULL-terminated.
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_caps_id_str_set_simple (GstCaps * caps, const GstIdStr * 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_id_str_set_simple_valist (caps, field, var_args);
|
||||||
|
va_end (var_args);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_caps_set_simple:
|
* gst_caps_set_simple:
|
||||||
* @caps: the #GstCaps to set
|
* @caps: the #GstCaps to set
|
||||||
|
|
|
@ -366,12 +366,19 @@ GstCaps * gst_caps_new_empty (void);
|
||||||
GST_API
|
GST_API
|
||||||
GstCaps * gst_caps_new_any (void);
|
GstCaps * gst_caps_new_any (void);
|
||||||
|
|
||||||
|
GST_API
|
||||||
|
GstCaps * gst_caps_new_id_str_empty_simple (const GstIdStr *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
GST_API
|
GST_API
|
||||||
GstCaps * gst_caps_new_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
GstCaps * gst_caps_new_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
GST_API
|
GST_API
|
||||||
GstCaps * gst_caps_new_static_str_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
GstCaps * gst_caps_new_static_str_empty_simple (const char *media_type) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
GST_API
|
||||||
|
GstCaps * gst_caps_new_id_str_simple (const GstIdStr *media_type,
|
||||||
|
const GstIdStr *fieldname,
|
||||||
|
...) G_GNUC_NULL_TERMINATED G_GNUC_WARN_UNUSED_RESULT;
|
||||||
GST_API
|
GST_API
|
||||||
GstCaps * gst_caps_new_simple (const char *media_type,
|
GstCaps * gst_caps_new_simple (const char *media_type,
|
||||||
const char *fieldname,
|
const char *fieldname,
|
||||||
|
@ -450,6 +457,10 @@ GstCaps * gst_caps_copy_nth (const GstCaps *caps, guint n
|
||||||
GST_API
|
GST_API
|
||||||
GstCaps * gst_caps_truncate (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
|
GstCaps * gst_caps_truncate (GstCaps *caps) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
GST_API
|
||||||
|
void gst_caps_id_str_set_value (GstCaps *caps,
|
||||||
|
const GstIdStr *field,
|
||||||
|
const GValue *value);
|
||||||
GST_API
|
GST_API
|
||||||
void gst_caps_set_value (GstCaps *caps,
|
void gst_caps_set_value (GstCaps *caps,
|
||||||
const char *field,
|
const char *field,
|
||||||
|
@ -459,12 +470,19 @@ void gst_caps_set_value_static_str (GstCaps *caps,
|
||||||
const char *field,
|
const char *field,
|
||||||
const GValue *value);
|
const GValue *value);
|
||||||
GST_API
|
GST_API
|
||||||
|
void gst_caps_id_str_set_simple (GstCaps *caps,
|
||||||
|
const GstIdStr *field, ...) G_GNUC_NULL_TERMINATED;
|
||||||
|
GST_API
|
||||||
void gst_caps_set_simple (GstCaps *caps,
|
void gst_caps_set_simple (GstCaps *caps,
|
||||||
const char *field, ...) G_GNUC_NULL_TERMINATED;
|
const char *field, ...) G_GNUC_NULL_TERMINATED;
|
||||||
GST_API
|
GST_API
|
||||||
void gst_caps_set_simple_static_str (GstCaps *caps,
|
void gst_caps_set_simple_static_str (GstCaps *caps,
|
||||||
const char *field, ...) G_GNUC_NULL_TERMINATED;
|
const char *field, ...) G_GNUC_NULL_TERMINATED;
|
||||||
GST_API
|
GST_API
|
||||||
|
void gst_caps_id_str_set_simple_valist(GstCaps *caps,
|
||||||
|
const GstIdStr *field,
|
||||||
|
va_list varargs);
|
||||||
|
GST_API
|
||||||
void gst_caps_set_simple_valist (GstCaps *caps,
|
void gst_caps_set_simple_valist (GstCaps *caps,
|
||||||
const char *field,
|
const char *field,
|
||||||
va_list varargs);
|
va_list varargs);
|
||||||
|
|
|
@ -510,6 +510,53 @@ gst_structure_new (const gchar * name, const gchar * firstfield, ...)
|
||||||
return structure;
|
return structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_structure_new_id_str_valist:
|
||||||
|
* @name: name of new structure
|
||||||
|
* @firstfield: name of first field to set
|
||||||
|
* @varargs: variable argument list
|
||||||
|
*
|
||||||
|
* Creates a new #GstStructure with the given @name. Structure fields
|
||||||
|
* are set according to the varargs in a manner similar to
|
||||||
|
* gst_structure_new_id_str().
|
||||||
|
*
|
||||||
|
* Free-function: gst_structure_free
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a new #GstStructure
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
GstStructure *
|
||||||
|
gst_structure_new_id_str_valist (const GstIdStr * name,
|
||||||
|
const GstIdStr * firstfield, va_list varargs)
|
||||||
|
{
|
||||||
|
GstStructure *structure;
|
||||||
|
va_list copy;
|
||||||
|
guint len = 0;
|
||||||
|
const GstIdStr *field_copy = firstfield;
|
||||||
|
GType type_copy;
|
||||||
|
|
||||||
|
g_return_val_if_fail (gst_structure_validate_name (gst_id_str_as_str (name)),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
/* Calculate size of varargs */
|
||||||
|
va_copy (copy, varargs);
|
||||||
|
while (field_copy) {
|
||||||
|
type_copy = va_arg (copy, GType);
|
||||||
|
G_VALUE_COLLECT_SKIP (type_copy, copy);
|
||||||
|
field_copy = va_arg (copy, const GstIdStr *);
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
va_end (copy);
|
||||||
|
|
||||||
|
structure = gst_structure_new_id_str_empty_with_size (name, len);
|
||||||
|
|
||||||
|
if (structure)
|
||||||
|
gst_structure_id_str_set_valist (structure, firstfield, varargs);
|
||||||
|
|
||||||
|
return structure;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_structure_new_valist:
|
* gst_structure_new_valist:
|
||||||
* @name: name of new structure
|
* @name: name of new structure
|
||||||
|
@ -860,6 +907,27 @@ gst_structure_get_name_id_str (const GstStructure * structure)
|
||||||
return GST_STRUCTURE_NAME (structure);
|
return GST_STRUCTURE_NAME (structure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_structure_set_name_id_str:
|
||||||
|
* @structure: a #GstStructure
|
||||||
|
* @name: the new name of the structure
|
||||||
|
*
|
||||||
|
* Sets the name of the structure to the given @name. The string
|
||||||
|
* provided is copied before being used. It must not be empty, start with a
|
||||||
|
* letter and can be followed by letters, numbers and any of "/-_.:".
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_structure_set_name_id_str (GstStructure * structure, const GstIdStr * name)
|
||||||
|
{
|
||||||
|
g_return_if_fail (structure != NULL);
|
||||||
|
g_return_if_fail (IS_MUTABLE (structure));
|
||||||
|
g_return_if_fail (gst_structure_validate_name (gst_id_str_as_str (name)));
|
||||||
|
|
||||||
|
gst_id_str_copy_into (GST_STRUCTURE_NAME (structure), name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_structure_set_name:
|
* gst_structure_set_name:
|
||||||
* @structure: a #GstStructure
|
* @structure: a #GstStructure
|
||||||
|
@ -1482,8 +1550,8 @@ gst_structure_new_id (GQuark name_quark, GQuark field_quark, ...)
|
||||||
*
|
*
|
||||||
* Creates a new #GstStructure with the given name as a GQuark, followed by
|
* Creates a new #GstStructure with the given name as a GQuark, followed by
|
||||||
* fieldname GstIdStr, GType, argument(s) "triplets" in the same format as
|
* fieldname GstIdStr, GType, argument(s) "triplets" in the same format as
|
||||||
* gst_structure_id_set(). Basically a convenience wrapper around
|
* gst_structure_id_str_set(). Basically a convenience wrapper around
|
||||||
* gst_structure_new_id_empty() and gst_structure_id_set().
|
* gst_structure_new_id_str_empty() and gst_structure_id_str_set().
|
||||||
*
|
*
|
||||||
* The last variable argument must be %NULL (or 0).
|
* The last variable argument must be %NULL (or 0).
|
||||||
*
|
*
|
||||||
|
@ -1968,6 +2036,35 @@ gst_structure_get_field_type (const GstStructure * structure,
|
||||||
return G_VALUE_TYPE (&field->value);
|
return G_VALUE_TYPE (&field->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_structure_id_str_get_field_type:
|
||||||
|
* @structure: a #GstStructure
|
||||||
|
* @fieldname: the name of the field
|
||||||
|
*
|
||||||
|
* Finds the field with the given name, and returns the type of the
|
||||||
|
* value it contains. If the field is not found, G_TYPE_INVALID is
|
||||||
|
* returned.
|
||||||
|
*
|
||||||
|
* Returns: the #GValue of the field
|
||||||
|
*
|
||||||
|
* Since: 1.26
|
||||||
|
*/
|
||||||
|
GType
|
||||||
|
gst_structure_id_str_get_field_type (const GstStructure * structure,
|
||||||
|
const GstIdStr * fieldname)
|
||||||
|
{
|
||||||
|
GstStructureField *field;
|
||||||
|
|
||||||
|
g_return_val_if_fail (structure != NULL, G_TYPE_INVALID);
|
||||||
|
g_return_val_if_fail (fieldname != NULL, G_TYPE_INVALID);
|
||||||
|
|
||||||
|
field = gst_structure_id_str_get_field (structure, fieldname);
|
||||||
|
if (field == NULL)
|
||||||
|
return G_TYPE_INVALID;
|
||||||
|
|
||||||
|
return G_VALUE_TYPE (&field->value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_structure_n_fields:
|
* gst_structure_n_fields:
|
||||||
* @structure: a #GstStructure
|
* @structure: a #GstStructure
|
||||||
|
|
|
@ -207,6 +207,10 @@ GstStructure * gst_structure_new_static_str (const gchar * name,
|
||||||
const gchar * firstfield,
|
const gchar * firstfield,
|
||||||
...) G_GNUC_NULL_TERMINATED G_GNUC_MALLOC;
|
...) G_GNUC_NULL_TERMINATED G_GNUC_MALLOC;
|
||||||
GST_API
|
GST_API
|
||||||
|
GstStructure * gst_structure_new_id_str_valist (const GstIdStr * name,
|
||||||
|
const GstIdStr * firstfield,
|
||||||
|
va_list varargs) G_GNUC_MALLOC;
|
||||||
|
GST_API
|
||||||
GstStructure * gst_structure_new_valist (const gchar * name,
|
GstStructure * gst_structure_new_valist (const gchar * name,
|
||||||
const gchar * firstfield,
|
const gchar * firstfield,
|
||||||
va_list varargs) G_GNUC_MALLOC;
|
va_list varargs) G_GNUC_MALLOC;
|
||||||
|
@ -256,8 +260,12 @@ GST_API
|
||||||
gboolean gst_structure_has_name (const GstStructure * structure,
|
gboolean gst_structure_has_name (const GstStructure * structure,
|
||||||
const gchar * name);
|
const gchar * name);
|
||||||
GST_API
|
GST_API
|
||||||
|
void gst_structure_set_name_id_str (GstStructure * structure,
|
||||||
|
const GstIdStr * name);
|
||||||
|
GST_API
|
||||||
void gst_structure_set_name (GstStructure * structure,
|
void gst_structure_set_name (GstStructure * structure,
|
||||||
const gchar * name);
|
const gchar * name);
|
||||||
|
GST_API
|
||||||
void gst_structure_set_name_static_str (GstStructure * structure,
|
void gst_structure_set_name_static_str (GstStructure * structure,
|
||||||
const gchar * name);
|
const gchar * name);
|
||||||
GST_DEPRECATED_FOR(gst_structure_id_str_set_value)
|
GST_DEPRECATED_FOR(gst_structure_id_str_set_value)
|
||||||
|
@ -393,6 +401,9 @@ void gst_structure_remove_all_fields (GstStructure *
|
||||||
GST_API
|
GST_API
|
||||||
GType gst_structure_get_field_type (const GstStructure * structure,
|
GType gst_structure_get_field_type (const GstStructure * structure,
|
||||||
const gchar * fieldname);
|
const gchar * fieldname);
|
||||||
|
GST_API
|
||||||
|
GType gst_structure_id_str_get_field_type(const GstStructure * structure,
|
||||||
|
const GstIdStr * fieldname);
|
||||||
GST_DEPRECATED_FOR(gst_structure_foreach_id_str)
|
GST_DEPRECATED_FOR(gst_structure_foreach_id_str)
|
||||||
gboolean gst_structure_foreach (const GstStructure * structure,
|
gboolean gst_structure_foreach (const GstStructure * structure,
|
||||||
GstStructureForeachFunc func,
|
GstStructureForeachFunc func,
|
||||||
|
|
Loading…
Reference in a new issue