From 5f02d6676e1de6152f488cfe01fb26d84b030b8d Mon Sep 17 00:00:00 2001 From: Jaeyun Jung Date: Tue, 19 Aug 2025 17:24:16 +0900 Subject: [PATCH] [Util] sync to latest update Code clean, sync to latest update of nnstreamer. Signed-off-by: Jaeyun Jung --- src/hal-backend-ml-util.cc | 4 +--- src/nnstreamer_plugin_api_filter.h | 20 ++++++++++++++++++++ src/tensor_typedef.h | 10 ++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/hal-backend-ml-util.cc b/src/hal-backend-ml-util.cc index b91bb7e..9ebe9f0 100644 --- a/src/hal-backend-ml-util.cc +++ b/src/hal-backend-ml-util.cc @@ -174,9 +174,7 @@ void gst_tensors_info_copy (GstTensorsInfo * dest, const GstTensorsInfo * src) num = dest->num_tensors = src->num_tensors; dest->format = src->format; - if (src->format != _NNS_TENSOR_FORMAT_STATIC) - return; - + /* Try to copy tensor info even if its format is not static. */ for (i = 0; i < num; i++) { _dest = gst_tensors_info_get_nth_info (dest, i); _src = gst_tensors_info_get_nth_info ((GstTensorsInfo *) src, i); diff --git a/src/nnstreamer_plugin_api_filter.h b/src/nnstreamer_plugin_api_filter.h index 552a041..e655303 100644 --- a/src/nnstreamer_plugin_api_filter.h +++ b/src/nnstreamer_plugin_api_filter.h @@ -136,6 +136,10 @@ typedef struct _GstTensorFilterProperties int invoke_dynamic; /**< True for supporting invoke with flexible output. */ uint32_t suspend; /**< Timeout (ms) for suspend. (Unload the framework) */ + + int invoke_async; /**< The sub-plugin must support asynchronous output to use this option. If set to TRUE, the sub-plugin can generate multiple outputs asynchronously per single input. Otherwise, only synchronous single-output is expected and async callback is ignored. */ + GstTensorDataCallback async_callback; /**< The callback function pointer to be called every time the sub-plugin generates a new output tensor asynchronously. Note that this is internal data for tensor-filter and DO NOT change this value. */ + void *async_user_data; /**< The private data to be passed to tensor data callback of asynchronous invoke. Note that this is internal data for tensor-filter and DO NOT change this value. */ } GstTensorFilterProperties; /** @@ -590,6 +594,22 @@ extern void nnstreamer_filter_shared_model_replace (void *instance, const char *key, void *new_interpreter, void (*replace_callback) (void *, void *), void (*free_callback) (void*)); +/** + * @brief Dispatches the asynchronously generated output to the registered callback. + * + * This function is used by the sub-plugin to dispatch the output that has been generated asynchronously. + * It invokes the internal callback function of tensor-filter to handle the output data. + * + * Note: + * Before calling this function, you must enable asynchronous invocation by setting the property 'invoke-async' as true. + * Failure to do so will result in undefined behavior, as no callback and handle will be registered. + * + * @param[in] prop GstTensorFilterProperties object. + * @param[in] output The GstTensorMemory holding the asynchronously generated output. Note that this function takes the ownership of each tensor data. + */ +extern void +nnstreamer_filter_dispatch_output_async (GstTensorFilterProperties * prop, GstTensorMemory * output); + #ifdef __cplusplus } #endif diff --git a/src/tensor_typedef.h b/src/tensor_typedef.h index fa1b445..c8c986a 100644 --- a/src/tensor_typedef.h +++ b/src/tensor_typedef.h @@ -310,4 +310,14 @@ typedef struct } GstTensorMetaInfo; +/** + * @brief Type definition for a callback function of tensor data stream. + * @details Note that the buffer may be deallocated after the return. To use outside, make a copy. Do not spend too much time in the callback. + * @param data The array of tensor data. + * @param info The information of tensor data. + * @param user_data The private data for the callback. + * @return 0 on success. Otherwise a negative error value. + */ +typedef int (*GstTensorDataCallback) (GstTensorMemory *data, GstTensorsInfo *info, void *user_data); + #endif /*__GST_TENSOR_TYPEDEF_H__*/