Remove the duplicated function definition.
Create tensor-converter extra subplugin's common util.
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
# flatbuffer
if flatbuf_support_is_available
converter_sub_flatbuf_sources = [
- 'tensor_converter_flatbuf.cc'
+ 'tensor_converter_flatbuf.cc',
+ 'tensor_converter_util.c'
]
nnstreamer_converter_flatbuf_sources = [fb_gen_src]
)
converter_sub_flexbuf_sources = [
- 'tensor_converter_flexbuf.cc'
+ 'tensor_converter_flexbuf.cc',
+ 'tensor_converter_util.c'
]
nnstreamer_converter_flexbuf_sources = []
# protocol buffer
if protobuf_support_is_available
converter_sub_protobuf_sources = [
- 'tensor_converter_protobuf.cc'
+ 'tensor_converter_protobuf.cc',
+ 'tensor_converter_util.c'
]
nnstreamer_converter_protobuf_sources = []
#include <nnstreamer_plugin_api.h>
#include <typeinfo>
#include "nnstreamer_plugin_api_converter.h"
+#include "tensor_converter_util.h"
namespace nnstreamer
{
return gst_caps_from_string (GST_FLATBUF_TENSOR_CAP_DEFAULT);
}
-/** @brief tensor converter plugin's NNStreamerExternalConverter callback */
-static gboolean
-fbc_get_out_config (const GstCaps *in_cap, GstTensorsConfig *config)
-{
- GstStructure *structure;
- g_return_val_if_fail (config != NULL, FALSE);
- gst_tensors_config_init (config);
- g_return_val_if_fail (in_cap != NULL, FALSE);
-
- structure = gst_caps_get_structure (in_cap, 0);
- g_return_val_if_fail (structure != NULL, FALSE);
-
- /* All tensor info should be updated later in chain function. */
- config->info.info[0].type = _NNS_UINT8;
- config->info.num_tensors = 1;
- if (gst_tensor_parse_dimension ("1:1:1:1", config->info.info[0].dimension) == 0) {
- ml_loge ("Failed to set initial dimension for subplugin");
- return FALSE;
- }
-
- if (gst_structure_has_field (structure, "framerate")) {
- gst_structure_get_fraction (structure, "framerate", &config->rate_n, &config->rate_d);
- } else {
- /* cannot get the framerate */
- config->rate_n = 0;
- config->rate_d = 1;
- }
- return TRUE;
-}
-
/** @brief tensor converter plugin's NNStreamerExternalConverter callback
* @todo : Consider multi frames, return Bufferlist and
* remove frame size and the number of frames
static NNStreamerExternalConverter flatBuf = {
.name = converter_subplugin_flatbuf,
.convert = fbc_convert,
- .get_out_config = fbc_get_out_config,
+ .get_out_config = tcu_get_out_config,
.query_caps = fbc_query_caps
};
#include <nnstreamer_plugin_api.h>
#include <nnstreamer_plugin_api_converter.h>
#include <flatbuffers/flexbuffers.h>
+#include "tensor_converter_util.h"
#ifdef __cplusplus
extern "C" {
return gst_caps_from_string (GST_FLEXBUF_CAP_DEFAULT);
}
-/** @brief tensor converter plugin's NNStreamerExternalConverter callback */
-static gboolean
-flxc_get_out_config (const GstCaps *in_cap, GstTensorsConfig *config)
-{
- GstStructure *structure;
- g_return_val_if_fail (config != NULL, FALSE);
- gst_tensors_config_init (config);
- g_return_val_if_fail (in_cap != NULL, FALSE);
-
- structure = gst_caps_get_structure (in_cap, 0);
- g_return_val_if_fail (structure != NULL, FALSE);
-
- /* All tensor info should be updated later in chain function. */
- config->info.info[0].type = _NNS_UINT8;
- config->info.num_tensors = 1;
- if (gst_tensor_parse_dimension ("1:1:1:1", config->info.info[0].dimension) == 0) {
- ml_loge ("Failed to set initial dimension for subplugin");
- return FALSE;
- }
-
- if (gst_structure_has_field (structure, "framerate")) {
- gst_structure_get_fraction (structure, "framerate", &config->rate_n, &config->rate_d);
- } else {
- /* cannot get the framerate */
- config->rate_n = 0;
- config->rate_d = 1;
- }
- return TRUE;
-}
-
/** @brief tensor converter plugin's NNStreamerExternalConverter callback
*/
static GstBuffer *
static NNStreamerExternalConverter flexBuf = {
.name = converter_subplugin_flexbuf,
.convert = flxc_convert,
- .get_out_config = flxc_get_out_config,
+ .get_out_config = tcu_get_out_config,
.query_caps = flxc_query_caps
};
#include <typeinfo>
#include "nnstreamer_plugin_api_converter.h"
#include "nnstreamer_protobuf.h"
+#include "tensor_converter_util.h"
#ifdef __cplusplus
extern "C" {
}
/** @brief tensor converter plugin's NNStreamerExternalConverter callback */
-static gboolean
-pbc_get_out_config (const GstCaps *in_cap, GstTensorsConfig *config)
-{
- GstStructure *structure;
-
- g_return_val_if_fail (config != NULL, FALSE);
- gst_tensors_config_init (config);
- g_return_val_if_fail (in_cap != NULL, FALSE);
-
- structure = gst_caps_get_structure (in_cap, 0);
- g_return_val_if_fail (structure != NULL, FALSE);
-
- /* All tensor info should be updated later in chain function. */
- config->info.info[0].type = _NNS_UINT8;
- config->info.num_tensors = 1;
- if (gst_tensor_parse_dimension ("1:1:1:1", config->info.info[0].dimension) == 0) {
- ml_loge ("Failed to set initial dimension for subplugin");
- return FALSE;
- }
-
- if (gst_structure_has_field (structure, "framerate")) {
- gst_structure_get_fraction (structure, "framerate", &config->rate_n, &config->rate_d);
- } else {
- /* cannot get the framerate */
- config->rate_n = 0;
- config->rate_d = 1;
- }
- return TRUE;
-}
-
-/** @brief tensor converter plugin's NNStreamerExternalConverter callback */
static GstBuffer *
pbc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data)
{
static NNStreamerExternalConverter protobuf = {
.name = converter_subplugin_protobuf,
.convert = pbc_convert,
- .get_out_config = pbc_get_out_config,
+ .get_out_config = tcu_get_out_config,
.query_caps = pbc_query_caps
};
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-only */
+/**
+* @file tensor_converter_util.h
+* @date 26 May 2021
+* @brief Utility functions for NNStreamer tensor-converter subplugins.
+* @see https://github.com/nnstreamer/nnstreamer
+* @author MyungJoo Ham <myungjoo.ham@samsung.com>
+* @bug No known bugs except for NYI items
+*/
+
+#include <glib.h>
+#include <gst/gst.h>
+#include <nnstreamer_log.h>
+#include <nnstreamer_plugin_api.h>
+#include "tensor_converter_util.h"
+
+/** @brief tensor converter plugin's NNStreamerExternalConverter callback */
+gboolean
+tcu_get_out_config (const GstCaps * in_cap, GstTensorsConfig * config)
+{
+ GstStructure *structure;
+ g_return_val_if_fail (config != NULL, FALSE);
+ gst_tensors_config_init (config);
+ g_return_val_if_fail (in_cap != NULL, FALSE);
+
+ structure = gst_caps_get_structure (in_cap, 0);
+ g_return_val_if_fail (structure != NULL, FALSE);
+
+ /* All tensor info should be updated later in chain function. */
+ config->info.info[0].type = _NNS_UINT8;
+ config->info.num_tensors = 1;
+ if (gst_tensor_parse_dimension ("1:1:1:1",
+ config->info.info[0].dimension) == 0) {
+ ml_loge ("Failed to set initial dimension for subplugin");
+ return FALSE;
+ }
+
+ if (gst_structure_has_field (structure, "framerate")) {
+ gst_structure_get_fraction (structure, "framerate", &config->rate_n,
+ &config->rate_d);
+ } else {
+ /* cannot get the framerate */
+ config->rate_n = 0;
+ config->rate_d = 1;
+ }
+ return TRUE;
+}
--- /dev/null
+/* SPDX-License-Identifier: LGPL-2.1-only */
+/**
+* @file tensor_converter_util.h
+* @date 26 May 2021
+* @brief Utility functions for NNStreamer tensor-converter subplugins.
+* @see https://github.com/nnstreamer/nnstreamer
+* @author MyungJoo Ham <myungjoo.hamt@samsung.com>
+* @bug No known bugs except for NYI items
+*/
+#ifndef _TENSOR_CONVERTER_UTIL_H_
+#define _TENSOR_CONVERTER_UTIL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <gst/gst.h>
+#include <nnstreamer_plugin_api.h>
+
+/** @brief tensor converter plugin's NNStreamerExternalConverter callback */
+gboolean tcu_get_out_config (const GstCaps *in_cap, GstTensorsConfig *config);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _TENSOR_CONVERTER_UTIL_H_ */
# converter flatbuffers
NNSTREAMER_CONVERTER_FLATBUF_SRCS := \
+ $(NNSTREAMER_EXT_HOME)/tensor_converter/tensor_converter_util.c \
$(NNSTREAMER_EXT_HOME)/tensor_converter/tensor_converter_flatbuf.cc
# converter flexbuffers
NNSTREAMER_CONVERTER_FLEXBUF_SRCS := \
+ $(NNSTREAMER_EXT_HOME)/tensor_converter/tensor_converter_util.c \
$(NNSTREAMER_EXT_HOME)/tensor_converter/tensor_converter_flexbuf.cc
# decoder flatbuffers