Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tools/Confchk] Show custom property description for sub-plugins @open sesame 10/15 19:48 #2800

Merged
merged 1 commit into from Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions gst/nnstreamer/include/nnstreamer_plugin_api_converter.h
Expand Up @@ -87,6 +87,12 @@ extern int registerExternalConverter (NNStreamerExternalConverter * ex);
*/
extern void unregisterExternalConverter (const char *prefix);

/**
* @brief set custom property description for tensor converter sub-plugin
*/
extern void
nnstreamer_converter_set_custom_property_desc (const char *name, const char *prop, ...);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions gst/nnstreamer/include/nnstreamer_plugin_api_decoder.h
Expand Up @@ -120,6 +120,12 @@ nnstreamer_decoder_exit (const char *name);
extern const GstTensorDecoderDef *
nnstreamer_decoder_find (const char *name);

/**
* @brief set custom property description for tensor decoder sub-plugin
*/
extern void
nnstreamer_decoder_set_custom_property_desc (const char *name, const char *prop, ...);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 6 additions & 0 deletions gst/nnstreamer/include/nnstreamer_plugin_api_filter.h
Expand Up @@ -500,6 +500,12 @@ nnstreamer_filter_exit (const char *name);
extern const GstTensorFilterFramework *
nnstreamer_filter_find (const char *name);

/**
* @brief set custom property description for tensor filter sub-plugin
*/
extern void
nnstreamer_filter_set_custom_property_desc (const char *name, const char *prop, ...);

/**
* @brief return accl_hw type from string
*/
Expand Down
83 changes: 83 additions & 0 deletions gst/nnstreamer/nnstreamer_conf.c
Expand Up @@ -27,6 +27,7 @@

#include "nnstreamer_log.h"
#include "nnstreamer_conf.h"
#include "nnstreamer_subplugin.h"

/**
* Note that users still can place their custom filters anywhere if they
Expand Down Expand Up @@ -609,3 +610,85 @@ nnsconf_dump (gchar * str, gulong size)
if (len <= 0)
g_printerr ("Config dump is too large. The results show partially.\n");
}

typedef struct
{
gchar *base;
gulong size;
gulong pos;
} dump_buf;

/**
* @brief foreach callback for custom property
*/
static void
_foreach_custom_property (GQuark key_id, gpointer data, gpointer user_data)
{
dump_buf *buf = (dump_buf *) user_data;

if (buf->size > buf->pos) {
buf->pos += g_snprintf (buf->base + buf->pos, buf->size - buf->pos,
" - %s: %s\n", g_quark_to_string (key_id), (gchar *) data);
}
}

/**
* @brief Print out the information of registered sub-plugins
*/
void
nnsconf_subplugin_dump (gchar * str, gulong size)
{
static const nnsconf_type_path dump_list_type[] = {
NNSCONF_PATH_FILTERS, NNSCONF_PATH_DECODERS, NNSCONF_PATH_CONVERTERS
};
static const char *dump_list_str[] = {
"Filter", "Decoder", "Conterver"
};

dump_buf buf;
subplugin_info_s info;
guint i, j, ret;

if (FALSE == conf.loaded)
nnsconf_loadconf (FALSE);

buf.base = str;
buf.size = size;
buf.pos = 0;

for (i = 0; i < sizeof (dump_list_type) / sizeof (nnsconf_type_path); i++) {
buf.pos += g_snprintf (buf.base + buf.pos, buf.size - buf.pos,
"\n[%s]\n", dump_list_str[i]);
if (buf.size <= buf.pos)
goto truncated;

ret = nnsconf_get_subplugin_info (dump_list_type[i], &info);
for (j = 0; j < ret; j++) {
GData *data;

if (!get_subplugin (dump_list_type[i], info.names[j]))
break;

buf.pos += g_snprintf (buf.base + buf.pos, buf.size - buf.pos,
" %s\n", info.names[j]);
if (buf.size <= buf.pos)
goto truncated;

data =
subplugin_get_custom_property_desc (dump_list_type[i], info.names[j]);
if (data) {
g_datalist_foreach (&data, _foreach_custom_property, &buf);
} else {
buf.pos += g_snprintf (buf.base + buf.pos, buf.size - buf.pos,
" - No custom property found\n");
}

if (buf.size <= buf.pos)
goto truncated;
}
}
return;

truncated:
g_printerr ("Config dump is too large. The results show partially.\n");
}
3 changes: 3 additions & 0 deletions gst/nnstreamer/nnstreamer_conf.h
Expand Up @@ -171,5 +171,8 @@ nnsconf_get_custom_value_bool (const gchar * group, const gchar * key, gboolean
extern void
nnsconf_dump (gchar * str, gulong size);

extern void
nnsconf_subplugin_dump (gchar * str, gulong size);

G_END_DECLS
#endif /* __GST_NNSTREAMER_CONF_H__ */
53 changes: 53 additions & 0 deletions gst/nnstreamer/nnstreamer_subplugin.c
Expand Up @@ -40,6 +40,7 @@ typedef struct
{
char *name; /**< The name of subplugin */
const void *data; /**< subplugin specific data forwarded from the subplugin */
GData *custom_dlist; /**< [OPTIONAL] subplugin specific custom property desc list */
} subpluginData;

static GHashTable *subplugins[NNS_SUBPLUGIN_END] = { 0 };
Expand All @@ -52,6 +53,9 @@ static void
_spdata_destroy (gpointer _data)
{
subpluginData *data = _data;

g_datalist_clear (&data->custom_dlist);

g_free (data->name);
g_free (data);
}
Expand Down Expand Up @@ -203,6 +207,7 @@ register_subplugin (subpluginType type, const char *name, const void *data)

spdata->name = g_strdup (name);
spdata->data = data;
g_datalist_init (&spdata->custom_dlist);

G_LOCK (splock);
ret = g_hash_table_insert (subplugins[type], g_strdup (name), spdata);
Expand Down Expand Up @@ -248,6 +253,54 @@ _close_handle (gpointer data)
#endif
}

/**
* @brief common interface to set custom property description of a sub-plugin.
*/
void
subplugin_set_custom_property_desc (subpluginType type, const char *name,
const gchar * prop, va_list varargs)
{
subpluginData *spdata;

g_return_if_fail (name != NULL);
g_return_if_fail (subplugins[type] != NULL);

spdata = _get_subplugin_data (type, name);
g_return_if_fail (spdata != NULL);

g_datalist_clear (&spdata->custom_dlist);

while (prop) {
gchar *desc = va_arg (varargs, gchar *);

if (G_UNLIKELY (desc == NULL)) {
g_critical ("no description for %s", prop);
return;
}

g_datalist_set_data (&spdata->custom_dlist, prop, desc);
prop = va_arg (varargs, gchar *);
}
}

/**
* @brief common interface to get custom property description of a sub-plugin.
*/
GData *
subplugin_get_custom_property_desc (subpluginType type, const char *name)
{
subpluginData *spdata;

g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (subplugins[type] != NULL, NULL);

spdata = _get_subplugin_data (type, name);
if (spdata)
return spdata->custom_dlist;

return NULL;
}

/** @brief Create handles at the start of library */
static void
init_subplugin (void)
Expand Down
7 changes: 7 additions & 0 deletions gst/nnstreamer/nnstreamer_subplugin.h
Expand Up @@ -76,4 +76,11 @@ register_subplugin (subpluginType type, const char *name, const void *data);
extern gboolean
unregister_subplugin (subpluginType type, const char *name);

extern void
subplugin_set_custom_property_desc (subpluginType type, const char *name,
const gchar * prop, va_list varargs);

extern GData *
subplugin_get_custom_property_desc (subpluginType type, const char *name);

#endif /* __GST_NNSTREAMER_SUBPLUGIN_H__ */
15 changes: 15 additions & 0 deletions gst/nnstreamer/tensor_converter/tensor_converter.c
Expand Up @@ -1854,3 +1854,18 @@ findExternalConverter (const char *media_type)

return NULL;
}

/**
* @brief set custom property description for tensor converter sub-plugin
*/
void
nnstreamer_converter_set_custom_property_desc (const char *name,
const char *prop, ...)
{
va_list varargs;

va_start (varargs, prop);
subplugin_set_custom_property_desc (NNS_SUBPLUGIN_CONVERTER, name, prop,
varargs);
va_end (varargs);
}
15 changes: 15 additions & 0 deletions gst/nnstreamer/tensor_decoder/tensordec.c
Expand Up @@ -201,6 +201,21 @@ nnstreamer_decoder_find (const char *name)
return get_subplugin (NNS_SUBPLUGIN_DECODER, name);
}

/**
* @brief set custom property description for tensor decoder sub-plugin
*/
void
nnstreamer_decoder_set_custom_property_desc (const char *name, const char *prop,
...)
{
va_list varargs;

va_start (varargs, prop);
subplugin_set_custom_property_desc (NNS_SUBPLUGIN_DECODER, name, prop,
varargs);
va_end (varargs);
}

/**
* @brief Macro to clean sub-plugin data
*/
Expand Down
15 changes: 15 additions & 0 deletions gst/nnstreamer/tensor_filter/tensor_filter_common.c
Expand Up @@ -502,6 +502,21 @@ nnstreamer_filter_exit (const char *name)
unregister_subplugin (NNS_SUBPLUGIN_FILTER, name);
}

/**
* @brief set custom property description for tensor filter sub-plugin
*/
void
nnstreamer_filter_set_custom_property_desc (const char *name, const char *prop,
...)
{
va_list varargs;

va_start (varargs, prop);
subplugin_set_custom_property_desc (NNS_SUBPLUGIN_FILTER, name, prop,
varargs);
va_end (varargs);
}

/**
* @brief Find filter sub-plugin with the name.
* @param[in] name The name of filter sub-plugin.
Expand Down
28 changes: 25 additions & 3 deletions tools/development/confchk/confchk.c
Expand Up @@ -23,11 +23,16 @@

#define STR_BOOL(x) ((x) ? "TRUE" : "FALSE")

/**
* @brief Dump NNStreamer configurations
* @param[in] path the filepath of nnstreamer library
*/
static int
get_nnsconf_dump (const gchar * path)
{
void *handle;
void (*nnsconf_dump) (gchar * str, gulong size);
void (*nnsconf_subplugin_dump) (gchar * str, gulong size);
gchar dump[8192];

handle = dlopen (path, RTLD_LAZY);
Expand All @@ -37,26 +42,43 @@ get_nnsconf_dump (const gchar * path)
}

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);
nnsconf_subplugin_dump = dlsym (handle, "nnsconf_subplugin_dump");
if (!nnsconf_subplugin_dump) {
g_printerr ("Error loading nnsconf_subplugin_dump: %s\n", dlerror ());
dlclose (handle);
return -2;
}

dlclose (handle);
nnsconf_dump (dump, 8192);

g_print ("\n");
g_print ("NNStreamer configuration:\n");
g_print ("============================================================\n");
g_print ("%s\n", dump);
g_print ("============================================================\n");

nnsconf_subplugin_dump (dump, 8192);

g_print ("\n");
g_print ("NNStreamer registered sub-plugins:\n");
g_print ("============================================================\n");
g_print ("%s\n", dump);
g_print ("============================================================\n");

dlclose (handle);

return 0;
}

/**
* @brief Main routine
*/
int
main (int argc, char *argv[])
{
Expand Down