gststructure: add gst_structure_get_caps

- Get field of type #GstCaps from #GstStructure

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9184>
This commit is contained in:
Daniel Morin 2025-06-03 22:32:17 -04:00 committed by GStreamer Marge Bot
parent 1fa4d154d8
commit 848d55b96a
3 changed files with 39 additions and 2 deletions

View File

@ -134,7 +134,6 @@ typedef enum {
GST_PADDING_INIT \
}
typedef struct _GstCaps GstCaps;
typedef struct _GstStaticCaps GstStaticCaps;
GST_API GstCaps * _gst_caps_any;

View File

@ -4685,7 +4685,6 @@ gst_structure_get_flags (const GstStructure * structure,
return TRUE;
}
/**
* gst_structure_is_writable:
* @structure: a #GstStructure
@ -4704,3 +4703,37 @@ gst_structure_is_writable (const GstStructure * structure)
return IS_MUTABLE (structure);
}
/**
* gst_structure_get_caps:
* @structure: a #GstStructure
* @fieldname: the name of the field
* @caps: (out): a pointer to a pointer on caps
*
* Set pointer pointed by @caps to the address of the value of type caps
* correspondind to field with fieldname @fieldname. Caller is responsible
* for making sure the field exists and has the correct type.
*
* Returns: %TRUE if could be set correctly. If there was no field with
* @fieldname or the existing field did not contain a caps, this function return
* %FALSE.
*
* Since: 1.28
*/
gboolean
gst_structure_get_caps (const GstStructure * structure,
const gchar * fieldname, const GstCaps ** caps)
{
GstStructureField *field;
g_return_val_if_fail (structure != NULL, FALSE);
g_return_val_if_fail (fieldname != NULL, FALSE);
g_return_val_if_fail (caps != NULL, FALSE);
field = gst_structure_get_field (structure, fieldname);
if (field == NULL || G_VALUE_TYPE (&field->value) != GST_TYPE_CAPS)
return FALSE;
*caps = gst_value_get_caps (&field->value);
return TRUE;
}

View File

@ -32,6 +32,7 @@ G_BEGIN_DECLS
GST_API GType _gst_structure_type;
typedef struct _GstStructure GstStructure;
typedef struct _GstCaps GstCaps;
/**
* GST_SERIALIZE_FLAG_STRICT:
@ -581,6 +582,10 @@ gboolean gst_structure_can_intersect (const GstStructure * struct1,
GST_API
GstStructure * gst_structure_intersect (const GstStructure * struct1,
const GstStructure * struct2) G_GNUC_MALLOC;
GST_API
gboolean gst_structure_get_caps (const GstStructure * structure,
const gchar * fieldname,
const GstCaps ** caps);
GST_API
gboolean gst_structure_is_writable (const GstStructure * structure);