From fc8e61a0272ecdac3182133c6ff0785f0eb3966f Mon Sep 17 00:00:00 2001 From: MyungJoo Ham Date: Thu, 13 Aug 2020 19:44:06 +0900 Subject: [PATCH] [Utility] NNStreamer-Check The new utility, "nnstreamer-check", shows NNStreamer configuration dump to stdout. This helps nnstreamer developers who suffer from installation paths and configuration paths. Fixes #2638 Signed-off-by: MyungJoo Ham --- gst/nnstreamer/nnstreamer_conf.c | 50 +++++++++++++++++++++ gst/nnstreamer/nnstreamer_conf.h | 8 ++++ tools/development/confchk/confchk.c | 83 +++++++++++++++++++++++++++++++++++ tools/development/confchk/meson.build | 30 +++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 tools/development/confchk/confchk.c create mode 100644 tools/development/confchk/meson.build diff --git a/gst/nnstreamer/nnstreamer_conf.c b/gst/nnstreamer/nnstreamer_conf.c index ad3cafd..206c62a 100644 --- a/gst/nnstreamer/nnstreamer_conf.c +++ b/gst/nnstreamer/nnstreamer_conf.c @@ -320,6 +320,7 @@ nnsconf_loadconf (gboolean force_reload) if (TRUE == force_reload && TRUE == conf.loaded) { /* Do Clean Up */ g_free (conf.conffile); + conf.conffile = NULL; for (t = 0; t < NNSCONF_PATH_END; t++) { @@ -360,6 +361,7 @@ nnsconf_loadconf (gboolean force_reload) if (!g_file_test (conf.conffile, G_FILE_TEST_IS_REGULAR)) { /* File not found or not configured */ g_free (conf.conffile); + conf.conffile = NULL; if (g_file_test (NNSTREAMER_DEFAULT_CONF_FILE, G_FILE_TEST_IS_REGULAR)) { conf.conffile = g_strdup (NNSTREAMER_DEFAULT_CONF_FILE); @@ -559,3 +561,51 @@ nnsconf_get_custom_value_bool (const gchar * group, const gchar * key, g_free (strval); return ret; } + +#define STR_BOOL(x) ((x) ? "TRUE" : "FALSE") +/** + * @brief Print out configurations + * @todo Add more configuration values to dump. + */ +void +nnsconf_dump (gchar * str, gulong size) +{ + gchar *cur = str; + gulong _size = size; + gint len; + + if (FALSE == conf.loaded) + nnsconf_loadconf (FALSE); + + len = g_snprintf (cur, _size, + "Configuration Loaded: %s\n" + "Configuration file path: %s\n" + " Candidates: envvar(NNSTREAMER_CONF): %s\n" + " build-config: %s\n" + " hard-coded: %s\n" + "[Common]\n" + " Enable envvar: %s\n" + " Enable sym-linked subplugins: %s\n" + "[Filter]\n" + " Filter paths from .ini: %s\n" + " from envvar: %s\n" + " from hard-coded: %s\n", STR_BOOL (conf.loaded), + /* 1. Configuration file path */ + (conf.conffile ? conf.conffile : " config file not loaded"), +#ifdef __TIZEN__ + "Not available (Tizen)", +#else + g_getenv (NNSTREAMER_ENVVAR_CONF_FILE), +#endif + NNSTREAMER_CONF_FILE, NNSTREAMER_DEFAULT_CONF_FILE, + /* 2. [Common] */ + STR_BOOL (conf.enable_envvar), STR_BOOL (conf.enable_symlink), + /* 3. [Filter] */ + conf.conf[NNSCONF_PATH_FILTERS].path[CONF_SOURCE_INI], + (conf.enable_envvar) ? + conf.conf[NNSCONF_PATH_FILTERS].path[CONF_SOURCE_ENVVAR] : "", + conf.conf[NNSCONF_PATH_FILTERS].path[CONF_SOURCE_HARDCODE]); + + if (len <= 0) + g_printerr ("Config dump is too large. The results show partially.\n"); +} diff --git a/gst/nnstreamer/nnstreamer_conf.h b/gst/nnstreamer/nnstreamer_conf.h index 6ce37d9..e8ce52a 100644 --- a/gst/nnstreamer/nnstreamer_conf.h +++ b/gst/nnstreamer/nnstreamer_conf.h @@ -163,5 +163,13 @@ nnsconf_get_custom_value_string (const gchar * group, const gchar * key); extern gboolean nnsconf_get_custom_value_bool (const gchar * group, const gchar * key, gboolean def); +/** + * @brief NNStreamer configuration dump as string. + * @param[out] str Preallocated string for the output (dump). + * @param[in] size The size of given str. + */ +extern void +nnsconf_dump (gchar * str, gulong size); + G_END_DECLS #endif /* __GST_NNSTREAMER_CONF_H__ */ diff --git a/tools/development/confchk/confchk.c b/tools/development/confchk/confchk.c new file mode 100644 index 0000000..83dc2c8 --- /dev/null +++ b/tools/development/confchk/confchk.c @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/** + * NNStreamer Configuration Checker Utility + * Copyright (C) 2020 MyungJoo Ham + */ +/** + * @file confchk.c + * @date 13 Aug 2020 + * @brief NNStreamer configuration checker utility + * @see http://github.com/nnstreamer/nnstreamer + * @author MyungJoo Ham + * @bug No known bugs except for NYI items + * + * This is a utility for nnstreamer developers. + * This shows the effective nnstreamer configurations. + * + * Internal mechanism: + * Load up libnnstreamer.so with gstreamer + */ +#include +#include +#include + +#define STR_BOOL(x) ((x) ? "TRUE" : "FALSE") + +static int +get_nnsconf_dump (const gchar * path) +{ + void *handle; + void (*nnsconf_dump) (gchar * str, gulong size); + gchar dump[8192]; + + handle = dlopen (path, RTLD_LAZY); + if (!handle) { + g_printerr ("Error opening %s: %s\n", path, dlerror ()); + return -1; + } + + nnsconf_dump = dlsym (handle, "nnsconf_dump"); + + if (!nnsconf_dump) { + g_printerr ("Error loading nnsconf_dump: %s\n", dlerror ()); + dlclose (handle); + return -2; + } + + nnsconf_dump (dump, 8192); + + dlclose (handle); + + g_print ("\n"); + g_print ("NNStreamer configuration:\n"); + g_print ("============================================================\n"); + g_print ("%s\n", dump); + g_print ("============================================================\n"); + + return 0; +} + +int +main (int argc, char *argv[]) +{ + GstPlugin *nnstreamer; + + gst_init (&argc, &argv); + + nnstreamer = gst_plugin_load_by_name ("nnstreamer"); + + if (!nnstreamer) { + g_printerr + ("Cannot load nnstreamer plugin. Please check if nnstreamer is installed and GST_PLUGIN_PATH is properly configured.\n"); + return -1; + } + + g_print ("NNStreamer version: %s\n", gst_plugin_get_version (nnstreamer)); + g_print (" loaded : %s\n", + STR_BOOL (gst_plugin_is_loaded (nnstreamer))); + g_print (" path : %s\n", gst_plugin_get_filename (nnstreamer)); + + get_nnsconf_dump (gst_plugin_get_filename (nnstreamer)); + + return 0; +} diff --git a/tools/development/confchk/meson.build b/tools/development/confchk/meson.build new file mode 100644 index 0000000..a304d66 --- /dev/null +++ b/tools/development/confchk/meson.build @@ -0,0 +1,30 @@ +project('nnstreamer-check', 'c', + version: '1.0.0', + license: ['LGPL'], + meson_version: '>=0.50.0', + default_options: [ + 'werror=true', + 'warning_level=1', + 'c_std=gnu89', + ] +) + +cc = meson.get_compiler('c') +gst_api_verision = '1.0' +glib_dep = dependency('glib-2.0') +gst_dep = dependency('gstreamer-' + gst_api_verision) +gst_base_dep = dependency('gstreamer-base-' + gst_api_verision) +libdl_dep = cc.find_library('dl') # DL library + +nnstchk_deps = [ + glib_dep, + gst_dep, + gst_base_dep, + libdl_dep, +] + +nnstchk_exec = executable('nnstreamer-check', + 'confchk.c', + dependencies: nnstchk_deps, + include_directories: ['../../../gst/nnstreamer', '../../../gst/nnstreamer/include'], +) -- 2.7.4