Commit 95d6fb05 authored by Tim-Philipp Müller's avatar Tim-Philipp Müller
Browse files

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.
parent 486fe43c
......@@ -366,6 +366,8 @@
#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)
......@@ -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;
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment