structure: API: Add gst_structure_fixate_field_string()
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Sat, 22 May 2010 08:01:44 +0000 (10:01 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Sat, 22 May 2010 08:01:44 +0000 (10:01 +0200)
docs/gst/gstreamer-sections.txt
gst/gststructure.c
gst/gststructure.h
win32/common/libgstreamer.def

index e4dac414b1584487cc38b88a092710a94dc6bf80..99073a746cc4398c7d2d6e1c19527ce9414e0c84 100644 (file)
@@ -2085,6 +2085,7 @@ gst_structure_fixate_field_nearest_int
 gst_structure_fixate_field_nearest_double
 gst_structure_fixate_field_nearest_fraction
 gst_structure_fixate_field_boolean
+gst_structure_fixate_field_string
 <SUBSECTION Standard>
 GST_STRUCTURE
 GST_IS_STRUCTURE
index 6c8f60515c8ab8fb003e0b39e1ae1f09bc13584a..8a3aa6f7c50169623d4956d7c574655a5eccb1d6 100644 (file)
@@ -2344,6 +2344,61 @@ gst_structure_fixate_field_boolean (GstStructure * structure,
   return FALSE;
 }
 
+/**
+ * gst_structure_fixate_field_string:
+ * @structure: a #GstStructure
+ * @field_name: a field in @structure
+ * @target: the target value of the fixation
+ *
+ * Fixates a #GstStructure by changing the given @field_name field to the given
+ * @target string if that field is not fixed yet.
+ *
+ * Returns: TRUE if the structure could be fixated
+ *
+ * Since: 0.10.30
+ */
+gboolean
+gst_structure_fixate_field_string (GstStructure * structure,
+    const gchar * field_name, const gchar * target)
+{
+  const GValue *value;
+
+  g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
+  g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
+
+  value = gst_structure_get_value (structure, field_name);
+
+  if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
+    /* already fixed */
+    return FALSE;
+  } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
+    const GValue *list_value;
+    int i, n;
+    const gchar *best = NULL;
+    int best_index = -1;
+
+    n = gst_value_list_get_size (value);
+    for (i = 0; i < n; i++) {
+      list_value = gst_value_list_get_value (value, i);
+      if (G_VALUE_TYPE (list_value) == G_TYPE_STRING) {
+        const gchar *x = g_value_get_string (list_value);
+
+        if (best_index == -1 || g_str_equal (x, target)) {
+          best_index = i;
+          best = x;
+        }
+      }
+    }
+    if (best_index != -1) {
+      gst_structure_set (structure, field_name, G_TYPE_STRING, best, NULL);
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  return FALSE;
+}
+
 /**
  * gst_structure_fixate_field_nearest_fraction:
  * @structure: a #GstStructure
index 84e09aa2239711d4dc141781df21aedd82727449..bbb89360b7daf95c39f6aae472b314b12d4c7f24 100644 (file)
@@ -230,6 +230,9 @@ gboolean                 gst_structure_fixate_field_nearest_double (GstStructure
 gboolean                 gst_structure_fixate_field_boolean (GstStructure *structure,
                                                                         const char   *field_name,
                                                                         gboolean        target);
+gboolean                 gst_structure_fixate_field_string (GstStructure *structure,
+                                                                        const char   *field_name,
+                                                                        const gchar  *target);
 gboolean                 gst_structure_fixate_field_nearest_fraction (GstStructure *structure,
                                                                         const char   *field_name,
                                                                         const gint target_numerator,
index ee2e13137a137f82aa6ddc878e7e054f50805ea0..ad8d5735faf269391c1acc344d860e3e67cff02c 100644 (file)
@@ -884,6 +884,7 @@ EXPORTS
        gst_structure_fixate_field_nearest_double
        gst_structure_fixate_field_nearest_fraction
        gst_structure_fixate_field_nearest_int
+       gst_structure_fixate_field_string
        gst_structure_foreach
        gst_structure_free
        gst_structure_from_string