pluginfeature: Allow updating initial rank of plugin feature

Introducing "GST_PLUGIN_FEATURE_RANK" environment variable in order for users
to adjust rank of plugin(s) via environment.

A "feature" and "rank" key-value pair should be separable by ":",
and each key-value pair is recognized per "," delimiters. The rank
can be a numerical value or one of pre-defined rank values
such as "NONE", "MARGINAL", "SECONDARY", and "PRIMARY" in case-insensitive manner.

In addition to pre-defined { NONE, MARGINAL, SECONDARY, PRIMARY },
"MAX" can be passed to key value used to ensure having a higher rank
than other plugin features.

Example)
- GST_PLUGIN_FEATURE_RANK=qtdemux:256,h264parse:NONE
Set rank of qtdemux plugin to 256 (primary) and 0 (none) for h264parse.
This commit is contained in:
Seungha Yang 2019-08-15 20:56:40 +09:00 committed by Tim-Philipp Müller
parent 72daeee2c4
commit 52706146f5
4 changed files with 116 additions and 0 deletions

View file

@ -312,3 +312,20 @@ Common values are 'egl', 'glx', 'wgl' or 'cgl'.
Influences the OpenGL API requested by the OpenGL platform. Common Influences the OpenGL API requested by the OpenGL platform. Common
values are 'opengl' or 'gles2'. 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`.

View file

@ -809,6 +809,10 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
GST_INFO ("initialized GStreamer successfully"); 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 #ifndef GST_DISABLE_GST_DEBUG
_priv_gst_tracing_init (); _priv_gst_tracing_init ();
#endif #endif

View file

@ -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_context_initialize (void);
G_GNUC_INTERNAL void _priv_gst_toc_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_date_time_initialize (void);
G_GNUC_INTERNAL void _priv_gst_plugin_feature_rank_initialize (void);
/* cleanup functions called from gst_deinit(). */ /* cleanup functions called from gst_deinit(). */
G_GNUC_INTERNAL void _priv_gst_allocator_cleanup (void); G_GNUC_INTERNAL void _priv_gst_allocator_cleanup (void);

View file

@ -405,3 +405,97 @@ gst_plugin_feature_rank_compare_func (gconstpointer p1, gconstpointer p2)
return diff; 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);
}