From b1573e98650008ca5b4845c47efcda18b5e28ac3 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 17 Aug 2011 17:56:40 +0200 Subject: [PATCH] structure: add method to fixate one field --- gst/gststructure.c | 48 ++++++++++++++++++++++++++++++++----------- gst/gststructure.h | 2 ++ win32/common/libgstreamer.def | 1 + 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/gst/gststructure.c b/gst/gststructure.c index 34cf806..e542106 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -2683,6 +2683,42 @@ gst_structure_fixate_field_nearest_fraction (GstStructure * structure, return FALSE; } +static gboolean +default_fixate (GQuark field_id, const GValue * value, gpointer data) +{ + GstStructure *s = data; + GValue v = { 0 }; + + if (gst_value_fixate (&v, value)) { + gst_structure_id_set_value (s, field_id, &v); + g_value_unset (&v); + } + return TRUE; +} + +/** + * gst_structure_fixate_field: + * @structure: a #GstStructure + * @field_name: a field in @structure + * + * Fixates a #GstStructure by changing the given field with its fixated value. + * + * Returns: TRUE if the structure field could be fixated + */ +gboolean +gst_structure_fixate_field (GstStructure * structure, const char *field_name) +{ + GstStructureField *field; + + g_return_val_if_fail (structure != NULL, FALSE); + g_return_val_if_fail (IS_MUTABLE (structure), FALSE); + + if (!(field = gst_structure_get_field (structure, field_name))) + return FALSE; + + return default_fixate (field->name, &field->value, structure); +} + /* our very own version of G_VALUE_LCOPY that allows NULL return locations * (useful for message parsing functions where the return location is user * supplied and the user may pass NULL if the value isn't of interest) */ @@ -3192,18 +3228,6 @@ gst_structure_is_subset (const GstStructure * subset, gst_caps_structure_is_subset_field, (gpointer) superset); } -static gboolean -default_fixate (GQuark field_id, const GValue * value, gpointer data) -{ - GstStructure *s = data; - GValue v = { 0 }; - - if (gst_value_fixate (&v, value)) { - gst_structure_id_set_value (s, field_id, &v); - g_value_unset (&v); - } - return TRUE; -} /** * gst_structure_fixate: diff --git a/gst/gststructure.h b/gst/gststructure.h index 41d4dfe..1af54de 100644 --- a/gst/gststructure.h +++ b/gst/gststructure.h @@ -242,6 +242,8 @@ gboolean gst_structure_fixate_field_nearest_fraction (GstStructu const char *field_name, const gint target_numerator, const gint target_denominator); +gboolean gst_structure_fixate_field (GstStructure *structure, + const char *field_name); gboolean gst_structure_is_equal(const GstStructure *structure1, const GstStructure *structure2); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 8c000d4..c10d1ba 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -970,6 +970,7 @@ EXPORTS gst_structure_copy gst_structure_empty_new gst_structure_fixate + gst_structure_fixate_field gst_structure_fixate_field_boolean gst_structure_fixate_field_nearest_double gst_structure_fixate_field_nearest_fraction -- 2.7.4