diff --git a/docs/gst/running.md b/docs/gst/running.md index f057c6e830..7eb156df7a 100644 --- a/docs/gst/running.md +++ b/docs/gst/running.md @@ -312,3 +312,20 @@ Common values are 'egl', 'glx', 'wgl' or 'cgl'. Influences the OpenGL API requested by the OpenGL platform. Common values are 'opengl' or 'gles2'. + +**`GST_PLUGIN_FEATURE_RANK`. (Since: 1.18)** + +This environment variable can be used to adjust rank of each plugin feature. + +The variable takes a comma-separated list of `plugin_feature:rank` +pairs to set specific ranks for the individual plugin features. +The rank can be an arbitrary numerical value or one of pre-defined rank values +from `NONE`(0) to `PRIMARY`(256) in case-insensitive manner. +In addition to the pre-defined rank values, `MAX` is an acceptable value to set +higher rank than the rank of other existing plugin features. + +Example: `GST_PLUGIN_FEATURE_RANK=foo:PRIMARY,bar:primary,foobar:128` + +As a result of the above example, +the `foo` and` bar` plugin feature rank values are `PRIMARY`(256) +and `SECONDARY`(128) rank value will be assigned to `foobar`. \ No newline at end of file diff --git a/gst/gst.c b/gst/gst.c index ee9b08f193..6e10cabe34 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -809,6 +809,10 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); GST_INFO ("initialized GStreamer successfully"); + /* Adjust initial plugin rank based on the GST_PLUGIN_FEATURE_RANK + * environment variable */ + _priv_gst_plugin_feature_rank_initialize (); + #ifndef GST_DISABLE_GST_DEBUG _priv_gst_tracing_init (); #endif diff --git a/gst/gst_private.h b/gst/gst_private.h index b4567d6830..2c686e69ba 100644 --- a/gst/gst_private.h +++ b/gst/gst_private.h @@ -137,6 +137,7 @@ G_GNUC_INTERNAL void _priv_gst_debug_init (void); G_GNUC_INTERNAL void _priv_gst_context_initialize (void); G_GNUC_INTERNAL void _priv_gst_toc_initialize (void); G_GNUC_INTERNAL void _priv_gst_date_time_initialize (void); +G_GNUC_INTERNAL void _priv_gst_plugin_feature_rank_initialize (void); /* cleanup functions called from gst_deinit(). */ G_GNUC_INTERNAL void _priv_gst_allocator_cleanup (void); diff --git a/gst/gstpluginfeature.c b/gst/gstpluginfeature.c index 831236e2b1..e7c741de8b 100644 --- a/gst/gstpluginfeature.c +++ b/gst/gstpluginfeature.c @@ -405,3 +405,97 @@ gst_plugin_feature_rank_compare_func (gconstpointer p1, gconstpointer p2) return diff; } + +static gboolean +parse_feature_name (gchar * str, const gchar ** feature) +{ + if (!str) + return FALSE; + + /* works in place */ + g_strstrip (str); + + if (str[0] != '\0') { + *feature = str; + return TRUE; + } + + return FALSE; +} + +static gboolean +parse_feature_rank (gchar * str, GstRank * rank) +{ + if (!str) + return FALSE; + + /* works in place */ + g_strstrip (str); + + if (g_ascii_isdigit (str[0])) { + unsigned long l; + char *endptr; + l = strtoul (str, &endptr, 10); + if (endptr > str && endptr[0] == 0) { + *rank = (GstRank) l; + } else { + return FALSE; + } + } else if (g_ascii_strcasecmp (str, "NONE") == 0) { + *rank = GST_RANK_NONE; + } else if (g_ascii_strcasecmp (str, "MARGINAL") == 0) { + *rank = GST_RANK_MARGINAL; + } else if (g_ascii_strcasecmp (str, "SECONDARY") == 0) { + *rank = GST_RANK_SECONDARY; + } else if (g_ascii_strcasecmp (str, "PRIMARY") == 0) { + *rank = GST_RANK_PRIMARY; + } else if (g_ascii_strcasecmp (str, "MAX") == 0) { + *rank = (GstRank) G_MAXINT; + } else { + return FALSE; + } + + return TRUE; +} + +void +_priv_gst_plugin_feature_rank_initialize (void) +{ + const gchar *env; + gchar **split; + gchar **walk; + + env = g_getenv ("GST_PLUGIN_FEATURE_RANK"); + + if (!env) + return; + + split = g_strsplit (env, ",", 0); + + for (walk = split; *walk; walk++) { + if (strchr (*walk, ':')) { + gchar **values = g_strsplit (*walk, ":", 2); + + if (values[0] && values[1]) { + GstRank rank; + const gchar *str; + + if (parse_feature_name (values[0], &str) + && parse_feature_rank (values[1], &rank)) { + GstPluginFeature *feature; + + feature = gst_registry_find_feature (gst_registry_get (), str, + GST_TYPE_ELEMENT_FACTORY); + if (feature) { + gst_plugin_feature_set_rank (feature, rank); + GST_DEBUG ("Update rank of plugin feature \"%s\" to %d", str, rank); + } + } + } + + g_strfreev (values); + } + } + + g_strfreev (split); +}