[Conf/Subplugin] get registered subplugins
authorJaeyun <jy1210.jung@samsung.com>
Tue, 4 May 2021 10:24:06 +0000 (19:24 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Thu, 6 May 2021 03:32:16 +0000 (12:32 +0900)
Util function to get registrable subplugins list.

If conf file is not loaded (or does not exists), nnstreamer cannot get the subplugin list from configuration.
In this case (e.g., Android), conveter cannot set the pad template from subplugins, and will make negotiation failure.

To prevent this error, get subplugins from table and conf file.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
gst/nnstreamer/nnstreamer_conf.c
gst/nnstreamer/nnstreamer_subplugin.c
gst/nnstreamer/nnstreamer_subplugin.h
gst/nnstreamer/tensor_converter/tensor_converter.c
gst/nnstreamer/tensor_decoder/tensordec.c
gst/nnstreamer/tensor_filter/tensor_filter_common.c

index fb9999d..382cbe9 100644 (file)
@@ -227,6 +227,11 @@ _get_subplugin_with_type (nnsconf_type_path type, gchar *** name,
     return FALSE;
   }
 
+  if (!conf.loaded) {
+    ml_loge ("Configuration file is not loaded.");
+    return FALSE;
+  }
+
   /* Easy custom uses the configuration of custom */
   if (type == NNSCONF_PATH_EASY_CUSTOM_FILTERS)
     type = NNSCONF_PATH_CUSTOM_FILTERS;
index 6f0c94f..7f79b2a 100644 (file)
@@ -168,6 +168,55 @@ get_subplugin (subpluginType type, const char *name)
 }
 
 /** @brief Public function defined in the header */
+gchar **
+get_all_subplugins (subpluginType type)
+{
+  GString *names;
+  subplugin_info_s info;
+  gchar **list = NULL;
+  gchar *name;
+  guint i, total;
+
+  names = g_string_new (NULL);
+
+  /* get registered subplugins */
+  G_LOCK (splock);
+  if (subplugins[type]) {
+    list = (gchar **) g_hash_table_get_keys_as_array (subplugins[type], NULL);
+  }
+  G_UNLOCK (splock);
+
+  if (list) {
+    name = g_strjoinv (",", list);
+    g_string_append (names, name);
+    g_free (name);
+  }
+
+  /* get subplugins from configuration */
+  total = nnsconf_get_subplugin_info ((nnsconf_type_path) type, &info);
+
+  for (i = 0; i < total; i++) {
+    name = info.names[i];
+
+    if (!list || !g_strv_contains ((const gchar * const *) list, name)) {
+      if (list || i > 0)
+        g_string_append (names, ",");
+
+      g_string_append (names, name);
+    }
+  }
+
+  g_free (list);
+
+  /* finally get the list of subplugins */
+  name = g_string_free (names, FALSE);
+  list = g_strsplit (name, ",", -1);
+  g_free (name);
+
+  return list;
+}
+
+/** @brief Public function defined in the header */
 gboolean
 register_subplugin (subpluginType type, const char *name, const void *data)
 {
index d3eb853..45cd88e 100644 (file)
@@ -59,6 +59,15 @@ extern const void *
 get_subplugin (subpluginType type, const char *name);
 
 /**
+ * @brief Get the list of registered subplugins.
+ * @param[in] type Subplugin Type
+ * @return The list of subplugin name
+ * @note Caller should free the returned value using g_strfreev()
+ */
+extern gchar **
+get_all_subplugins (subpluginType type);
+
+/**
  * @brief Register the subplugin. If duplicated name exists, it is rejected.
  * @param[in] type Subplugin Type
  * @param[in] name Subplugin Name. The filename should be subplugin_prefixes[type]${name}.so
index 285cf87..812c235 100644 (file)
@@ -193,9 +193,9 @@ gst_tensor_converter_class_init (GstTensorConverterClass * klass)
   GstElementClass *element_class;
   GstPadTemplate *pad_template;
   GstCaps *pad_caps;
+  gchar **str_array;
   guint total, i;
   const NNStreamerExternalConverter *ex;
-  subplugin_info_s info;
 
   GST_DEBUG_CATEGORY_INIT (gst_tensor_converter_debug, "tensor_converter", 0,
       "Element to convert media stream to tensor stream");
@@ -306,11 +306,17 @@ gst_tensor_converter_class_init (GstTensorConverterClass * klass)
   append_octet_caps_template (pad_caps);
 
   /* append sub-plugin template caps */
-  total = nnsconf_get_subplugin_info (NNSCONF_PATH_CONVERTERS, &info);
-  for (i = 0; i < total; i++) {
-    ex = nnstreamer_converter_find (info.names[i]);
-    if (ex && ex->query_caps)
-      gst_caps_append (pad_caps, ex->query_caps (NULL));
+  str_array = get_all_subplugins (NNS_SUBPLUGIN_CONVERTER);
+  if (str_array) {
+    total = g_strv_length (str_array);
+
+    for (i = 0; i < total; i++) {
+      ex = nnstreamer_converter_find (str_array[i]);
+      if (ex && ex->query_caps)
+        gst_caps_append (pad_caps, ex->query_caps (NULL));
+    }
+
+    g_strfreev (str_array);
   }
 
   pad_template = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
@@ -539,10 +545,14 @@ gst_tensor_converter_get_property (GObject * object, guint prop_id,
       break;
     case PROP_SUBPLUGINS:
     {
-      subplugin_info_s sinfo;
+      gchar **str_array = get_all_subplugins (NNS_SUBPLUGIN_CONVERTER);
 
-      nnsconf_get_subplugin_info (NNSCONF_PATH_CONVERTERS, &sinfo);
-      g_value_take_string (value, g_strjoinv (",", sinfo.names));
+      if (str_array) {
+        g_value_take_string (value, g_strjoinv (",", str_array));
+        g_strfreev (str_array);
+      } else {
+        g_value_set_string (value, "");
+      }
       break;
     }
     case PROP_SILENT:
@@ -1944,31 +1954,38 @@ unregisterExternalConverter (const char *name)
 static const NNStreamerExternalConverter *
 findExternalConverter (const char *media_type)
 {
+  gchar **str_array;
   guint total, i, j, caps_size;
-  subplugin_info_s info;
   GstCaps *caps;
   const gchar *caps_name;
   const NNStreamerExternalConverter *ex;
 
-  total = nnsconf_get_subplugin_info (NNSCONF_PATH_CONVERTERS, &info);
-  for (i = 0; i < total; i++) {
-    ex = nnstreamer_converter_find (info.names[i]);
+  str_array = get_all_subplugins (NNS_SUBPLUGIN_CONVERTER);
+  if (str_array) {
+    total = g_strv_length (str_array);
+
+    for (i = 0; i < total; i++) {
+      ex = nnstreamer_converter_find (str_array[i]);
 
-    if (ex && ex->query_caps) {
-      caps = ex->query_caps (NULL);
-      caps_size = gst_caps_get_size (caps);
+      if (ex && ex->query_caps) {
+        caps = ex->query_caps (NULL);
+        caps_size = gst_caps_get_size (caps);
 
-      for (j = 0; j < caps_size; j++) {
-        caps_name = gst_structure_get_name (gst_caps_get_structure (caps, j));
-        if (g_strcmp0 (media_type, caps_name) == 0) {
-          /* found matched media type */
-          gst_caps_unref (caps);
-          return ex;
+        for (j = 0; j < caps_size; j++) {
+          caps_name = gst_structure_get_name (gst_caps_get_structure (caps, j));
+          if (g_strcmp0 (media_type, caps_name) == 0) {
+            /* found matched media type */
+            gst_caps_unref (caps);
+            g_strfreev (str_array);
+            return ex;
+          }
         }
-      }
 
-      gst_caps_unref (caps);
+        gst_caps_unref (caps);
+      }
     }
+
+    g_strfreev (str_array);
   }
 
   return NULL;
index 4ff27e4..1605194 100644 (file)
@@ -588,10 +588,14 @@ gst_tensordec_get_property (GObject * object, guint prop_id,
       PROP_READ_OPTION (9);
     case PROP_SUBPLUGINS:
     {
-      subplugin_info_s sinfo;
+      gchar **str_array = get_all_subplugins (NNS_SUBPLUGIN_DECODER);
 
-      nnsconf_get_subplugin_info (NNSCONF_PATH_DECODERS, &sinfo);
-      g_value_take_string (value, g_strjoinv (",", sinfo.names));
+      if (str_array) {
+        g_value_take_string (value, g_strjoinv (",", str_array));
+        g_strfreev (str_array);
+      } else {
+        g_value_set_string (value, "");
+      }
       break;
     }
     default:
index 9f096c8..3cc9228 100644 (file)
@@ -2033,24 +2033,14 @@ gst_tensor_filter_common_get_property (GstTensorFilterPrivate * priv,
       break;
     case PROP_SUBPLUGINS:
     {
-      GString *subplugins;
-      subplugin_info_s sinfo;
-      guint i, total;
+      gchar **str_array = get_all_subplugins (NNS_SUBPLUGIN_FILTER);
 
-      subplugins = g_string_new (NULL);
-
-      /* add custom */
-      /** @todo Let's not hardcode default subplugins */
-      g_string_append (subplugins, "custom,custom-easy");
-
-      total = nnsconf_get_subplugin_info (NNSCONF_PATH_FILTERS, &sinfo);
-
-      for (i = 0; i < total; ++i) {
-        g_string_append (subplugins, ",");
-        g_string_append (subplugins, sinfo.names[i]);
+      if (str_array) {
+        g_value_take_string (value, g_strjoinv (",", str_array));
+        g_strfreev (str_array);
+      } else {
+        g_value_set_string (value, "");
       }
-
-      g_value_take_string (value, g_string_free (subplugins, FALSE));
       break;
     }
     case PROP_ACCELERATOR: