- Added value transform functions for caps and props boxed types

Original commit message from CVS:
- Added value transform functions for caps and props boxed types
- implement gst_props_new with a GList
- fixed silly typo in _gst_type_*
This commit is contained in:
Wim Taymans 2002-09-17 21:22:31 +00:00
parent d5e71498dd
commit 8b3c7040d4
4 changed files with 68 additions and 3 deletions

View file

@ -32,6 +32,35 @@ static GMutex *_gst_caps_chunk_lock;
GType _gst_caps_type;
static void
transform_func (const GValue *src_value,
GValue *dest_value)
{
GstCaps *caps = g_value_peek_pointer (src_value);
GString *result = g_string_new ("");
g_string_append_printf (result, "(GstCaps *) ");
while (caps) {
gchar *props;
GValue value = { 0, }; /* the important thing is that value.type = 0 */
g_string_append_printf (result,
"{ %s; ", gst_caps_get_mime (caps));
g_value_init (&value, GST_TYPE_PROPS);
g_value_set_boxed (&value, caps->properties);
props = g_strdup_value_contents (&value);
g_string_append (result, props);
g_free (props);
caps = caps->next;
g_string_append_printf (result, " }%s", caps?", ":"");
}
dest_value->data[0].v_pointer = result->str;
}
void
_gst_caps_initialize (void)
{
@ -44,6 +73,9 @@ _gst_caps_initialize (void)
(GBoxedCopyFunc) gst_caps_ref,
(GBoxedFreeFunc) gst_caps_unref);
g_value_register_transform_func (_gst_caps_type,
G_TYPE_STRING,
transform_func);
}
static guint16

View file

@ -32,7 +32,7 @@ typedef struct _GstCaps GstCaps;
extern GType _gst_caps_type;
#define GST_TYPE_CAPS (_get_caps_type)
#define GST_TYPE_CAPS (_gst_caps_type)
#define GST_CAPS(caps) \

View 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,
@ -185,6 +215,9 @@ G_STMT_START { \
case GST_PROPS_STRING_TYPE: \
entry->data.string_data.string = g_strdup (va_arg (var_args, gchar*)); \
break; \
case GST_PROPS_LIST_TYPE: \
entry->data.list_data.entries = g_list_copy (va_arg (var_args, GList*)); \
break; \
default: \
break; \
} \

View file

@ -33,7 +33,7 @@ G_BEGIN_DECLS
typedef struct _GstProps GstProps;
extern GType _gst_props_type;
#define GST_TYPE_PROPS (_get_props_type)
#define GST_TYPE_PROPS (_gst_props_type)
typedef enum {
GST_PROPS_END_TYPE = 0,