From efda5ffd9a2993c36a38a36d1c8ab3123a1d43b0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 19 Dec 2000 16:36:10 +0000 Subject: [PATCH] Added API to dynamically create GstCaps and GstProps Original commit message from CVS: Added API to dynamically create GstCaps and GstProps Changed typefind of mpeg1 to set the GstProps. autoplugging now works again for mpeg1, whoohoo! --- gst/gstcaps.c | 39 ++++++++++++++++++++++++++++++++----- gst/gstcaps.h | 4 ++++ gst/gstprops.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ gst/gstprops.h | 6 +++++- tests/Makefile.am | 2 +- 5 files changed, 101 insertions(+), 7 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 9ddb335..db76863 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -19,6 +19,7 @@ //#define DEBUG_ENABLED +#include "gstdebug.h" #include "gstcaps.h" #include "gsttype.h" @@ -68,6 +69,17 @@ gst_caps_new (gchar *mime) return caps; } +GstCaps* +gst_caps_new_with_props (gchar *mime, GstProps *props) +{ + GstCaps *caps; + + caps = gst_caps_new (mime); + caps->properties = props; + + return caps; +} + /** * gst_caps_register: * @factory: the factory to register @@ -101,6 +113,25 @@ gst_caps_register (GstCapsFactory *factory) return caps; } +GstCaps* +gst_caps_set_props (GstCaps *caps, GstProps *props) +{ + g_return_val_if_fail (caps != NULL, caps); + g_return_val_if_fail (props != NULL, caps); + g_return_val_if_fail (caps->properties == NULL, caps); + + caps->properties = props; + + return caps; +} + +GstProps* +gst_caps_get_props (GstCaps *caps) +{ + g_return_val_if_fail (caps != NULL, caps); + + return caps->properties; +} /** * gst_caps_check_compatibility: @@ -118,24 +149,22 @@ gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps) g_return_val_if_fail (tocaps != NULL, FALSE); if (fromcaps->id != tocaps->id) { - //g_print ("gstcaps: mime types wrong\n"); + DEBUG ("gstcaps: mime types wrong\n"); return FALSE; } if (tocaps->properties) { - GstPropsEntry *entry = (GstPropsEntry *)tocaps->properties; - if (fromcaps->properties) { return gst_props_check_compatibility (fromcaps->properties, tocaps->properties); } else { - //g_print ("gstcaps: no source caps\n"); + DEBUG ("gstcaps: no source caps\n"); return FALSE; } } else { // assume it accepts everything - //g_print ("gstcaps: no caps\n"); + DEBUG ("gstcaps: no caps\n"); return TRUE; } } diff --git a/gst/gstcaps.h b/gst/gstcaps.h index b564f7e..8f850c7 100644 --- a/gst/gstcaps.h +++ b/gst/gstcaps.h @@ -44,8 +44,12 @@ struct _GstCaps { void _gst_caps_initialize (void); GstCaps* gst_caps_new (gchar *mime); +GstCaps* gst_caps_new_with_props (gchar *mime, GstProps *props); GstCaps* gst_caps_register (GstCapsFactory *factory); +GstCaps* gst_caps_set_props (GstCaps *caps, GstProps *props); +GstProps* gst_caps_get_props (GstCaps *caps); + gboolean gst_caps_check_compatibility (GstCaps *caps1, GstCaps *caps2); xmlNodePtr gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent); diff --git a/gst/gstprops.c b/gst/gstprops.c index 8613dda..e430641 100644 --- a/gst/gstprops.c +++ b/gst/gstprops.c @@ -158,6 +158,63 @@ gst_props_register (GstPropsFactory factory) return props; } +GstProps * +gst_props_new (GstPropsFactoryEntry entry, ...) +{ + va_list var_args; + GstPropsFactoryEntry value; + gint i = 0; + gint size; + GstPropsFactoryEntry *factory; + + + size = 16; + factory = (GstPropsFactoryEntry *) g_malloc (size*sizeof(GstPropsFactoryEntry)); + + va_start (var_args, entry); + + value = (GstPropsFactoryEntry) entry; + + while (value) { + DEBUG ("%p\n", value); + + factory[i++] = value; + + if (i >= size) { + size += 16; + factory = (GstPropsFactoryEntry *) g_realloc (factory, size*sizeof(GstPropsFactoryEntry)); + } + + value = va_arg (var_args, GstPropsFactoryEntry); + } + factory[i++] = NULL; + + return gst_props_register (factory); +} + +GstProps* +gst_props_merge (GstProps *props, GstProps *tomerge) +{ + GSList *merge_props; + + g_return_val_if_fail (props != NULL, NULL); + g_return_val_if_fail (tomerge != NULL, NULL); + + merge_props = tomerge->properties; + + // FIXME do proper merging here... + while (merge_props) { + GstPropsEntry *entry = (GstPropsEntry *)merge_props->data; + + props->properties = g_slist_insert_sorted (props->properties, entry, props_compare_func); + + merge_props = g_slist_next (merge_props); + } + + return props; +} + + /* entry2 is always a list, entry1 never is */ static gboolean gst_props_entry_check_list_compatibility (GstPropsEntry *entry1, GstPropsEntry *entry2) diff --git a/gst/gstprops.h b/gst/gstprops.h index 4bf45a1..4ab1293 100644 --- a/gst/gstprops.h +++ b/gst/gstprops.h @@ -53,7 +53,7 @@ typedef enum { struct _GstProps { - GSList *properties; /* properties for this capability */ + GSList *properties; /* real properties for this property */ }; /* initialize the subsystem */ @@ -61,6 +61,10 @@ void _gst_props_initialize (void); GstProps* gst_props_register (GstPropsFactory factory); +GstProps* gst_props_new (GstPropsFactoryEntry entry, ...); + +GstProps* gst_props_merge (GstProps *props, GstProps *tomerge); + gboolean gst_props_check_compatibility (GstProps *props1, GstProps *props2); xmlNodePtr gst_props_save_thyself (GstProps *props, xmlNodePtr parent); diff --git a/tests/Makefile.am b/tests/Makefile.am index 7ae299f..019363d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = init loadall simplefake states caps queue registry paranoia rip mp3encode autoplug +noinst_PROGRAMS = init loadall simplefake states caps queue registry paranoia rip mp3encode autoplug props LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(top_builddir)/gst/libgst.la CFLAGS = -Wall -- 2.7.4