typefind: pass extensions as comma-separated list in a simple string
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 2 Feb 2012 01:30:12 +0000 (01:30 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Thu, 2 Feb 2012 01:32:07 +0000 (01:32 +0000)
Fix annoying gst_type_find_register() function signature. A simple
string with comma-separated extensions works just as well and saves
lines of code, casts, relocations and ultimately kittens.

gst/gsttypefind.c
gst/gsttypefind.h
tests/check/libs/typefindhelper.c

index bc4f85b..2cfb8d0 100644 (file)
@@ -47,8 +47,8 @@ G_DEFINE_POINTER_TYPE (GstTypeFind, gst_type_find);
  * @name: The name for registering
  * @rank: The rank (or importance) of this typefind function
  * @func: The #GstTypeFindFunction to use
- * @extensions: (transfer none) (array zero-terminated=1) (element-type utf8):
- *     Optional extensions that could belong to this type
+ * @extensions: (allow-none): Optional comma-separated list of extensions
+ *     that could belong to this type
  * @possible_caps: Optionally the caps that could be returned when typefinding
  *                 succeeds
  * @data: Optional user data. This user data must be available until the plugin
@@ -64,7 +64,7 @@ G_DEFINE_POINTER_TYPE (GstTypeFind, gst_type_find);
  */
 gboolean
 gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
-    GstTypeFindFunction func, gchar ** extensions,
+    GstTypeFindFunction func, const gchar * extensions,
     GstCaps * possible_caps, gpointer data, GDestroyNotify data_notify)
 {
   GstTypeFindFactory *factory;
@@ -80,9 +80,12 @@ gst_type_find_register (GstPlugin * plugin, const gchar * name, guint rank,
   gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
   gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank);
 
-  if (factory->extensions)
+  if (factory->extensions) {
     g_strfreev (factory->extensions);
-  factory->extensions = g_strdupv (extensions);
+    factory->extensions = NULL;
+  }
+  if (extensions)
+    factory->extensions = g_strsplit (extensions, ",", -1);
 
   gst_caps_replace (&factory->caps, possible_caps);
   factory->function = func;
index 4dcdc85..31a0a2e 100644 (file)
@@ -114,7 +114,7 @@ gboolean  gst_type_find_register   (GstPlugin            * plugin,
                                     const gchar          * name,
                                     guint                  rank,
                                     GstTypeFindFunction    func,
-                                    gchar               ** extensions,
+                                    const gchar          * extensions,
                                     GstCaps              * possible_caps,
                                     gpointer               data,
                                     GDestroyNotify         data_notify);
index 8a55f84..3798094 100644 (file)
@@ -42,14 +42,12 @@ static GstStaticCaps foobar_caps = GST_STATIC_CAPS ("foo/x-bar");
 /* make sure the entire data in the buffer is available for peeking */
 GST_START_TEST (test_buffer_range)
 {
-  static gchar *foobar_exts[] = { (char *) "foobar", NULL };
-
   GstStructure *s;
   GstBuffer *buf;
   GstCaps *caps;
 
   fail_unless (gst_type_find_register (NULL, "foo/x-bar",
-          GST_RANK_PRIMARY + 50, foobar_typefind, (gchar **) foobar_exts,
+          GST_RANK_PRIMARY + 50, foobar_typefind, "foobar",
           FOOBAR_CAPS, NULL, NULL));
 
   buf = gst_buffer_new ();