*
* @param[in] data the data element.
*/
+
+ int (*reloadModel) (const GstTensorFilterProperties * prop, void **private_data);
+ /**< Optional. tensor_filter.c will call it when a model property is newly configured.
+ * @todo add more detail comments.
+ *
+ * @param[in] prop read-only property values
+ * @param[in/out] private_data A subplugin may save its internal private data here. The subplugin is responsible for alloc/free of this pointer. Normally, close() frees private_data and set NULL.
+ * @return 0 if ok. < 0 if error.
+ */
} GstTensorFilterFramework;
/* extern functions for subplugin management, exist in tensor_filter.c */
#include "tensor_filter.h"
+/** @todo rename & move this to better location */
+#define EVENT_NAME_UPDATE_MODEL "evt_update_model"
+
/**
* @brief Macro for debug mode.
*/
GstCaps * othercaps, gsize * othersize);
static gboolean gst_tensor_filter_start (GstBaseTransform * trans);
static gboolean gst_tensor_filter_stop (GstBaseTransform * trans);
+static gboolean gst_tensor_filter_sink_event (GstBaseTransform * trans,
+ GstEvent * event);
/**
* @brief Invoke callbacks of nn framework. Guarantees calling open for the first call.
trans_class->transform_size =
GST_DEBUG_FUNCPTR (gst_tensor_filter_transform_size);
+ /* setup sink event */
+ trans_class->sink_event = GST_DEBUG_FUNCPTR (gst_tensor_filter_sink_event);
+
/* start/stop to call open/close */
trans_class->start = GST_DEBUG_FUNCPTR (gst_tensor_filter_start);
trans_class->stop = GST_DEBUG_FUNCPTR (gst_tensor_filter_stop);
}
/**
+ * @brief Event handler for sink pad of tensor filter.
+ * @param trans "this" pointer
+ * @param event a passed event object
+ * @return TRUE if there is no error.
+ */
+static gboolean
+gst_tensor_filter_sink_event (GstBaseTransform * trans, GstEvent * event)
+{
+ GstTensorFilter *self;
+ GstTensorFilterPrivate *priv;
+
+ self = GST_TENSOR_FILTER_CAST (trans);
+ priv = &self->priv;
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_CUSTOM_DOWNSTREAM:
+ {
+ const GstStructure *structure = gst_event_get_structure (event);
+ int ret = -1;
+
+ if (structure == NULL ||
+ !gst_structure_has_name (structure, EVENT_NAME_UPDATE_MODEL))
+ break;
+
+ if (priv->is_updatable) {
+ const GValue *value =
+ gst_structure_get_value (structure, "model_files");
+
+ if (value != NULL) {
+ g_object_set (self, "model", value, NULL);
+ ret = 0;
+ }
+ }
+
+ gst_event_unref (event);
+
+ return (ret == 0);
+ }
+ default:
+ break;
+ }
+
+ /** other events are handled in the default event handler */
+ return GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event);
+}
+
+/**
* @brief Called when the element starts processing. optional vmethod of BaseTransform
* @param trans "this" pointer
* @return TRUE if there is no error.
PROP_CUSTOM,
PROP_SUBPLUGINS,
PROP_ACCELERATOR,
- PROP_UPDATABLE_MODEL,
+ PROP_IS_UPDATABLE,
};
/**
"list of accelerators determines the backend (ignored with false). "
"Example, if GPU, NPU can be used but not CPU - true:(GPU,NPU,!CPU).",
"", G_PARAM_READWRITE));
- g_object_class_install_property (gobject_class, PROP_UPDATABLE_MODEL,
- g_param_spec_string ("is-updatable", "Updatable model",
+ g_object_class_install_property (gobject_class, PROP_IS_UPDATABLE,
+ g_param_spec_boolean ("is-updatable", "Updatable model",
"Indicate whether a given model to this tensor filter is "
"updatable in runtime. (e.g., with on-device training)",
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
idx, prop->model_files[idx]);
}
}
+
+ /* reload model if FW has been already opened */
+ if (priv->prop.fw_opened && priv->is_updatable) {
+ if (priv->fw && priv->fw->reloadModel) {
+ if (priv->fw->reloadModel (&priv->prop, &priv->privateData) != 0) {
+ g_critical ("Fail to reload model\n");
+ }
+ }
+ }
+
break;
}
case PROP_INPUT:
break;
}
- case PROP_UPDATABLE_MODEL:
+ case PROP_IS_UPDATABLE:
{
- priv->updatable_model = g_value_get_boolean (value);
+ if (priv->fw->reloadModel != NULL)
+ priv->is_updatable = g_value_get_boolean (value);
break;
}
default:
g_value_set_string (value, "");
}
break;
- case PROP_UPDATABLE_MODEL:
- g_value_set_boolean (value, priv->updatable_model);
+ case PROP_IS_UPDATABLE:
+ g_value_set_boolean (value, priv->is_updatable);
break;
default:
/* unknown property */
/* internal properties for tensor-filter */
gboolean silent; /**< Verbose mode if FALSE. int instead of gboolean for non-glib custom plugins */
gboolean configured; /**< True if already successfully configured tensor metadata */
- gboolean updatable_model; /**< a given model to the filter is updatable if TRUE */
+ gboolean is_updatable; /**< a given model to the filter is updatable if TRUE */
GstTensorsConfig in_config; /**< input tensor info */
GstTensorsConfig out_config; /**< output tensor info */
} GstTensorFilterPrivate;