pbutils: remove duplicate detail strings when calling the external codec installer
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 2 Feb 2009 17:25:21 +0000 (17:25 +0000)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 2 Feb 2009 17:34:23 +0000 (17:34 +0000)
It doesn't make sense to ask installers for the same codec or element twice, so filter out duplicate requests before calling the external helper script and make the unit test check this works right. Fixes #567636.

gst-libs/gst/pbutils/install-plugins.c
tests/check/libs/pbutils.c

index e87d972..7ca19de 100644 (file)
 #include <sys/wait.h>
 #endif
 
+#include <string.h>
+
 /* best effort to make things compile and possibly even work on win32 */
 #ifndef WEXITSTATUS
 # define WEXITSTATUS(status) ((((guint)(status)) & 0xff00) >> 8)
@@ -490,6 +492,18 @@ gst_install_plugins_get_helper (void)
 }
 
 static gboolean
+ptr_array_contains_string (GPtrArray * arr, const gchar * s)
+{
+  gint i;
+
+  for (i = 0; i < arr->len; ++i) {
+    if (strcmp ((const char *) g_ptr_array_index (arr, i), s) == 0)
+      return TRUE;
+  }
+  return FALSE;
+}
+
+static gboolean
 gst_install_plugins_spawn_child (gchar ** details,
     GstInstallPluginsContext * ctx, GPid * child_pid, gint * exit_status)
 {
@@ -509,9 +523,10 @@ gst_install_plugins_spawn_child (gchar ** details,
     g_ptr_array_add (arr, xid_str);
   }
 
-  /* finally, add the detail strings */
+  /* finally, add the detail strings, but without duplicates */
   while (details != NULL && details[0] != NULL) {
-    g_ptr_array_add (arr, details[0]);
+    if (!ptr_array_contains_string (arr, details[0]))
+      g_ptr_array_add (arr, details[0]);
     ++details;
   }
 
index a078581..61b8b60 100644 (file)
@@ -549,6 +549,7 @@ GST_START_TEST (test_pb_utils_install_plugins)
   GstInstallPluginsContext *ctx;
   GstInstallPluginsReturn ret;
   gchar *details[] = { "detail1", "detail2", NULL };
+  gchar *details_multi[] = { "detail1", "detail1", "detail2", NULL };
 
   ctx = gst_install_plugins_context_new ();
 
@@ -583,6 +584,15 @@ GST_START_TEST (test_pb_utils_install_plugins)
   test_pb_utils_install_plugins_do_callout (details, ctx, SCRIPT_WITH_XID,
       GST_INSTALL_PLUGINS_SUCCESS);
 
+  /* and make sure that duplicate detail strings get dropped */
+  test_pb_utils_install_plugins_do_callout (details_multi, NULL, SCRIPT_NO_XID,
+      GST_INSTALL_PLUGINS_NOT_FOUND);
+
+  /* and the same again with context */
+  gst_install_plugins_context_set_xid (ctx, 42);
+  test_pb_utils_install_plugins_do_callout (details_multi, ctx, SCRIPT_WITH_XID,
+      GST_INSTALL_PLUGINS_SUCCESS);
+
   /* and free the context now that we don't need it any longer */
   gst_install_plugins_context_free (ctx);