I'm sure you'll appreciate my getting out of bed for this..
[platform/upstream/gstreamer.git] / gst / gstprops.c
index 22c8515..db36867 100644 (file)
@@ -68,6 +68,33 @@ static GMutex *_gst_props_chunk_lock;
 static gboolean        gst_props_entry_check_compatibility     (GstPropsEntry *entry1, GstPropsEntry *entry2);
 static GList*          gst_props_list_copy                     (GList *propslist);
 
+static void
+transform_func (const GValue *src_value,
+               GValue *dest_value)
+{
+  GstProps *props = g_value_peek_pointer (src_value);
+  GString *result = g_string_new ("");
+  GList *propslist = props->properties;
+
+  while (propslist) { 
+    GstPropsEntry *entry = (GstPropsEntry *)propslist->data;
+    const gchar *name = g_quark_to_string (entry->propid);
+
+    switch (entry->propstype) {
+      case GST_PROPS_STRING_TYPE:
+       g_string_append_printf (result, "%s='%s'", name, entry->data.string_data.string);
+      default:
+       break;
+    }
+    
+    propslist = g_list_next (propslist);
+    if (propslist) {
+      g_string_append (result, "; ");
+    }
+  }
+  dest_value->data[0].v_pointer = result->str;
+}
+
        
 void 
 _gst_props_initialize (void) 
@@ -86,6 +113,9 @@ _gst_props_initialize (void)
                                       (GBoxedCopyFunc) gst_props_ref,
                                       (GBoxedFreeFunc) gst_props_unref);
 
+  g_value_register_transform_func (_gst_props_type,
+                                   G_TYPE_STRING,
+                                   transform_func);
 }
 
 static void
@@ -107,7 +137,7 @@ gst_props_debug_entry (GstPropsEntry *entry)
       GST_DEBUG (GST_CAT_PROPERTIES, "%s: bool %d", name, entry->data.bool_data);
       break;
     case GST_PROPS_STRING_TYPE:
-      GST_DEBUG (GST_CAT_PROPERTIES, "%s: string %s", name, entry->data.string_data.string);
+      GST_DEBUG (GST_CAT_PROPERTIES, "%s: string \"%s\"", name, entry->data.string_data.string);
       break;
     case GST_PROPS_INT_RANGE_TYPE:
       GST_DEBUG (GST_CAT_PROPERTIES, "%s: int range %d-%d", name, entry->data.int_range_data.min,
@@ -157,7 +187,7 @@ props_find_func (gconstpointer a,
 /* This is implemented as a huge macro because we cannot pass
  * va_list variables by reference on some architectures.
  */
-#define GST_PROPS_ENTRY_FILL(entry, var_args)                                  \
+#define GST_PROPS_ENTRY_FILL(entry, var_args)                                  \
 G_STMT_START {                                                                         \
   entry->propstype = va_arg (var_args, GstPropsType);                          \
                                                                                \
@@ -185,6 +215,10 @@ G_STMT_START {                                                                     \
     case GST_PROPS_STRING_TYPE:                                                        \
       entry->data.string_data.string = g_strdup (va_arg (var_args, gchar*));   \
       break;                                                                   \
+    case GST_PROPS_GLIST_TYPE:                                                 \
+      entry->propstype = GST_PROPS_LIST_TYPE;                                  \
+      entry->data.list_data.entries = g_list_copy (va_arg (var_args, GList*)); \
+      break;                                                                   \
     default:                                                                   \
       break;                                                                   \
   }                                                                            \
@@ -193,11 +227,11 @@ G_STMT_START {                                                                    \
 
 #define GST_PROPS_ENTRY_READ(entry, var_args, safe, result)                    \
 G_STMT_START {                                                                         \
-  GstPropsType propstype = va_arg (var_args, GstPropsType);                    \
                                                                                \
   *result = TRUE;                                                              \
                                                                                \
   if (safe) {                                                                  \
+    GstPropsType propstype = va_arg (var_args, GstPropsType);                  \
     if (propstype != entry->propstype) {                                       \
       *result = FALSE;                                                         \
     }                                                                          \
@@ -478,7 +512,7 @@ gst_props_entry_newv (const gchar *name, va_list var_args)
   entry = gst_props_alloc_entry ();
   entry->propid = g_quark_from_string (name);
   GST_PROPS_ENTRY_FILL (entry, var_args);
-  
+
   return entry;
 }
 
@@ -667,7 +701,7 @@ gst_props_set (GstProps *props, const gchar *name, ...)
     va_end (var_args);
   }
   else {
-    g_print("gstprops: no property '%s' to change\n", name);
+    g_warning ("gstprops: no property '%s' to change\n", name);
   }
 
   return props;
@@ -1008,6 +1042,22 @@ gst_props_entry_get_safe (const GstPropsEntry *entry, ...)
   return result;
 }
 
+static gboolean
+gst_props_getv (GstProps *props, gboolean safe, gchar *first_name, va_list var_args)
+{
+  while (first_name) {
+    const GstPropsEntry *entry = gst_props_get_entry (props, first_name);
+    gboolean result;
+
+    if (!entry) return FALSE;
+    GST_PROPS_ENTRY_READ (entry, var_args, FALSE, &result);
+    if (!result) return FALSE;
+
+    first_name = va_arg (var_args, gchar *);
+  }
+  return TRUE;
+}
+
 /**
  * gst_props_get:
  * @props: the props to query
@@ -1022,22 +1072,36 @@ gboolean
 gst_props_get (GstProps *props, gchar *first_name, ...)
 {
   va_list var_args;
+  gboolean ret;
 
   va_start (var_args, first_name);
+  ret = gst_props_getv (props, FALSE, first_name, var_args);
+  va_end (var_args);
+  
+  return ret;
+}
 
-  while (first_name) {
-    const GstPropsEntry *entry = gst_props_get_entry (props, first_name);
-    gboolean result;
-
-    if (!entry) return FALSE;
-    GST_PROPS_ENTRY_READ (entry, var_args, FALSE, &result);
-    if (!result) return FALSE;
+/**
+ * gst_props_get_safe:
+ * @props: the props to query
+ * @first_name: the first key
+ * @...: a pointer to a datastructure that can hold the value.
+ *
+ * Gets the contents of the props into given key/value pairs.
+ *
+ * Returns: TRUE is the props entry could be fetched.
+ */
+gboolean
+gst_props_get_safe (GstProps *props, gchar *first_name, ...)
+{
+  va_list var_args;
+  gboolean ret;
 
-    first_name = va_arg (var_args, gchar *);
-  }
+  va_start (var_args, first_name);
+  ret = gst_props_getv (props, TRUE, first_name, var_args);
   va_end (var_args);
   
-  return TRUE;
+  return ret;
 }
 
 /**
@@ -1432,7 +1496,8 @@ gst_props_entry_intersect (GstPropsEntry *entry1, GstPropsEntry *entry2)
 
        if (intersectentry) {
          if (intersectentry->propstype == GST_PROPS_LIST_TYPE) {
-           intersection = g_list_concat (intersection, intersectentry->data.list_data.entries);
+           intersection = g_list_concat (intersection, 
+                           g_list_copy (intersectentry->data.list_data.entries));
            /* set the list to NULL because the entries are concatenated to the above
             * list and we don't want to free them */
            intersectentry->data.list_data.entries = NULL;