From 95d6fb050143b67b255017e80ccb108cd7ea33ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 2 Feb 2009 17:25:21 +0000 Subject: [PATCH] pbutils: remove duplicate detail strings when calling the external codec installer 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 | 19 +++++++++++++++++-- tests/check/libs/pbutils.c | 10 ++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/pbutils/install-plugins.c b/gst-libs/gst/pbutils/install-plugins.c index e87d972601..7ca19deebe 100644 --- a/gst-libs/gst/pbutils/install-plugins.c +++ b/gst-libs/gst/pbutils/install-plugins.c @@ -366,6 +366,8 @@ #include #endif +#include + /* best effort to make things compile and possibly even work on win32 */ #ifndef WEXITSTATUS # define WEXITSTATUS(status) ((((guint)(status)) & 0xff00) >> 8) @@ -489,6 +491,18 @@ gst_install_plugins_get_helper (void) return helper; } +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; } diff --git a/tests/check/libs/pbutils.c b/tests/check/libs/pbutils.c index a07858113e..61b8b60979 100644 --- a/tests/check/libs/pbutils.c +++ b/tests/check/libs/pbutils.c @@ -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);