From: Jaeyun Date: Fri, 2 Aug 2019 04:40:32 +0000 (+0900) Subject: [Api/Tizen] base code to check plugin name X-Git-Tag: accepted/tizen/unified/20190905.060558~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09c0a79ff74a22c119f3f4637f8204309ff06b23;p=platform%2Fupstream%2Fnnstreamer.git [Api/Tizen] base code to check plugin name prepare code to validate the plugins in pipeline. TODO: update code to initialize white-list for tizen Signed-off-by: Jaeyun Jung --- diff --git a/api/capi/include/nnstreamer-capi-private.h b/api/capi/include/nnstreamer-capi-private.h index 5f78f2b..2a6e654 100644 --- a/api/capi/include/nnstreamer-capi-private.h +++ b/api/capi/include/nnstreamer-capi-private.h @@ -261,6 +261,11 @@ int ml_get_feature_enabled (void); */ int ml_set_feature_status (int status); +/** + * @brief Checks the availability of the plugin. + */ +int ml_check_plugin_availability (const char *plugin_name, const char *element_name); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/api/capi/src/nnstreamer-capi-pipeline.c b/api/capi/src/nnstreamer-capi-pipeline.c index 2d2320f..473bb41 100644 --- a/api/capi/src/nnstreamer-capi-pipeline.c +++ b/api/capi/src/nnstreamer-capi-pipeline.c @@ -342,7 +342,7 @@ ml_pipeline_construct (const char *pipeline_description, GError *err = NULL; GstElement *pipeline; GstIterator *it = NULL; - int ret = ML_ERROR_NONE; + int status = ML_ERROR_NONE; ml_pipeline *pipe_h; @@ -406,10 +406,6 @@ ml_pipeline_construct (const char *pipeline_description, GValue item = G_VALUE_INIT; GObject *obj; gchar *name; - GstElementFactory *tensor_sink = gst_element_factory_find ("tensor_sink"); - GstElementFactory *valve = gst_element_factory_find ("valve"); - GstElementFactory *inputs = gst_element_factory_find ("input-selector"); - GstElementFactory *outputs = gst_element_factory_find ("output-selector"); /* Fill in the hashtable, "namednodes" with named Elements */ while (!done) { @@ -419,26 +415,34 @@ ml_pipeline_construct (const char *pipeline_description, if (GST_IS_ELEMENT (obj)) { GstElement *elem = GST_ELEMENT (obj); + GstPluginFeature *feature = + GST_PLUGIN_FEATURE (gst_element_get_factory (elem)); + const gchar *plugin_name = + gst_plugin_feature_get_plugin_name (feature); + const gchar *element_name = gst_plugin_feature_get_name (feature); + + /* validate the availability of the plugin */ + if (ml_check_plugin_availability (plugin_name, element_name) != ML_ERROR_NONE) { + status = ML_ERROR_NOT_SUPPORTED; + done = TRUE; + break; + } name = gst_element_get_name (elem); if (name != NULL) { ml_pipeline_element_e element_type = ML_PIPELINE_ELEMENT_UNKNOWN; - if (G_TYPE_CHECK_INSTANCE_TYPE (elem, - gst_element_factory_get_element_type (tensor_sink))) { + if (g_str_equal (element_name, "tensor_sink")) { element_type = ML_PIPELINE_ELEMENT_SINK; - } else if (G_TYPE_CHECK_INSTANCE_TYPE (elem, GST_TYPE_APP_SRC)) { + } else if (g_str_equal (element_name, "appsrc")) { element_type = ML_PIPELINE_ELEMENT_APP_SRC; - } else if (G_TYPE_CHECK_INSTANCE_TYPE (elem, GST_TYPE_APP_SINK)) { + } else if (g_str_equal (element_name, "appsink")) { element_type = ML_PIPELINE_ELEMENT_APP_SINK; - } else if (G_TYPE_CHECK_INSTANCE_TYPE (elem, - gst_element_factory_get_element_type (valve))) { + } else if (g_str_equal (element_name, "valve")) { element_type = ML_PIPELINE_ELEMENT_VALVE; - } else if (G_TYPE_CHECK_INSTANCE_TYPE (elem, - gst_element_factory_get_element_type (inputs))) { + } else if (g_str_equal (element_name, "input-selector")) { element_type = ML_PIPELINE_ELEMENT_SWITCH_INPUT; - } else if (G_TYPE_CHECK_INSTANCE_TYPE (elem, - gst_element_factory_get_element_type (outputs))) { + } else if (g_str_equal (element_name, "output-selector")) { element_type = ML_PIPELINE_ELEMENT_SWITCH_OUTPUT; } else { /** @todo CRITICAL HANDLE THIS! */ @@ -469,15 +473,17 @@ ml_pipeline_construct (const char *pipeline_description, g_value_unset (&item); /** @todo CRITICAL check the validity of elem=item registered in e */ gst_iterator_free (it); - - g_object_unref (tensor_sink); - g_object_unref (valve); - g_object_unref (inputs); - g_object_unref (outputs); } g_mutex_unlock (&pipe_h->lock); - return ret; + + if (status != ML_ERROR_NONE) { + /* failed to construct the pipeline */ + ml_pipeline_destroy (*pipe); + *pipe = NULL; + } + + return status; } /** diff --git a/api/capi/src/nnstreamer-capi-util.c b/api/capi/src/nnstreamer-capi-util.c index ac74c1b..3907eba 100644 --- a/api/capi/src/nnstreamer-capi-util.c +++ b/api/capi/src/nnstreamer-capi-util.c @@ -925,3 +925,23 @@ ml_set_feature_status (int status) g_mutex_unlock (&feature_info->mutex); return ML_ERROR_NONE; } + +/** + * @brief Checks the availability of the plugin. + */ +int +ml_check_plugin_availability (const char *plugin_name, const char *element_name) +{ +#ifdef __TIZEN__ + if (!plugin_name || !element_name) { + ml_loge ("The name is invalid, failed to check the availability."); + return ML_ERROR_INVALID_PARAMETER; + } + + /** + * @todo check white-list of available plugins + * e.g, plugin name 'nnstreamer', element name 'tensor_converter' + */ +#endif /* __TIZEN__ */ + return ML_ERROR_NONE; +}