From f5dd59fc9af9d3c37d1c597b7af97bf58ad61fda Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Mon, 5 Jul 2021 14:19:51 +0900 Subject: [PATCH] [CodeClean] prepare next caps nego Code clean, prepare caps string with tensor format. - clean source code and update description Signed-off-by: Jaeyun --- ext/nnstreamer/extra/nnstreamer_protobuf.h | 8 -------- gst/nnstreamer/include/tensor_typedef.h | 22 ++++++++++++---------- .../tensor_aggregator/tensor_aggregator.c | 11 ++++++----- gst/nnstreamer/tensor_common.c | 22 +++++++++++++--------- gst/nnstreamer/tensor_converter/tensor_converter.c | 3 +++ .../nnscustom_framecounter.c | 2 +- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/ext/nnstreamer/extra/nnstreamer_protobuf.h b/ext/nnstreamer/extra/nnstreamer_protobuf.h index 75a5d43..1811ba5 100644 --- a/ext/nnstreamer/extra/nnstreamer_protobuf.h +++ b/ext/nnstreamer/extra/nnstreamer_protobuf.h @@ -20,14 +20,6 @@ #include /** - * @brief Default static capability for Protocol Buffers - * protobuf converter will convert this capability to other/tensor(s) - */ -#define GST_PROTOBUF_TENSOR_CAP_DEFAULT \ - "other/protobuf-tensor, " \ - "framerate = " GST_TENSOR_RATE_RANGE - -/** * @brief tensordec-plugin's GstTensorDecoderDef callback * @param[in] config The structure of input tensor info. * @param[in] input The array of input tensor data. The maximum array size of input data is NNS_TENSOR_SIZE_LIMIT. diff --git a/gst/nnstreamer/include/tensor_typedef.h b/gst/nnstreamer/include/tensor_typedef.h index dd21f44..87a26bd 100644 --- a/gst/nnstreamer/include/tensor_typedef.h +++ b/gst/nnstreamer/include/tensor_typedef.h @@ -71,28 +71,22 @@ /** * type should be one of types in GST_TENSOR_TYPE_ALL * "type = (string) uint8" - * dimension shoule be a formatted string with rank NNS_TENSOR_RANK_LIMIT + * dimension should be a formatted string with rank NNS_TENSOR_RANK_LIMIT * "dimension = (string) dim1:dim2:dim3:dim4" */ /** - * @brief Caps string for the caps template (other/tensors). + * @brief Caps string for the caps template (other/tensors, static tensor stream with fixed number of tensors). * num should be a string format that describes the number of tensors, or the range of incoming tensors. + * The types and dimensions of tensors should be described for caps negotiation. */ #define GST_TENSORS_CAP_WITH_NUM(num) \ NNS_MIMETYPE_TENSORS ", " \ "num_tensors = " num ", " \ "framerate = " GST_TENSOR_RATE_RANGE - /** - * type should be one of types in GST_TENSOR_TYPE_ALL - * "types = (string) uint8, uint8, uint8" - * Dimensions of Tensors for negotiation. It's comment out here, - * but when we call gst_structure_get_string, it actually is working well. - * "dimensions = (string) dim1:dim2:dim3:dim4, dim1:dim2:dim3:dim4" - */ /** - * @brief Default static capability for other/tensors + * @brief Caps string for the caps template of static tensor stream. */ #define GST_TENSORS_CAP_DEFAULT \ GST_TENSORS_CAP_WITH_NUM(GST_TENSOR_NUM_TENSORS_RANGE) @@ -106,6 +100,14 @@ NNS_MIMETYPE_TENSORS_FLEXIBLE /** + * @brief Default static capability for Protocol Buffers + * protobuf converter will convert this capability to other/tensor(s) + */ +#define GST_PROTOBUF_TENSOR_CAP_DEFAULT \ + "other/protobuf-tensor, " \ + "framerate = " GST_TENSOR_RATE_RANGE + +/** * @brief Default static capability for flatbuffers * Flatbuf converter will convert this capability to other/tensor(s) * @todo Move this definition to proper header file diff --git a/gst/nnstreamer/tensor_aggregator/tensor_aggregator.c b/gst/nnstreamer/tensor_aggregator/tensor_aggregator.c index d8d5e62..5548a5f 100644 --- a/gst/nnstreamer/tensor_aggregator/tensor_aggregator.c +++ b/gst/nnstreamer/tensor_aggregator/tensor_aggregator.c @@ -1034,6 +1034,7 @@ gst_tensor_aggregator_parse_caps (GstTensorAggregator * self, { GstStructure *structure; GstTensorsConfig config; + GstTensorInfo *_info; uint32_t per_frame; guint count; @@ -1060,6 +1061,8 @@ gst_tensor_aggregator_parse_caps (GstTensorAggregator * self, } self->in_config = config; + /* tensor-aggregator now handles single tensor. */ + _info = &config.info.info[0]; /** * update dimension in output tensor. @@ -1068,15 +1071,13 @@ gst_tensor_aggregator_parse_caps (GstTensorAggregator * self, * if frames_out=10 and frames_dim=2, then out-dimension is 2:200:2000:1. */ if (self->frames_dim >= NNS_TENSOR_RANK_LIMIT || - (config.info.info[0].dimension[self->frames_dim] % self->frames_in) != - 0) { + (_info->dimension[self->frames_dim] % self->frames_in) != 0) { GST_ERROR_OBJECT (self, "Cannot update dimension in output tensor"); return FALSE; } - per_frame = config.info.info[0].dimension[self->frames_dim] / self->frames_in; + per_frame = _info->dimension[self->frames_dim] / self->frames_in; - config.info.info[0].dimension[self->frames_dim] = - per_frame * self->frames_out; + _info->dimension[self->frames_dim] = per_frame * self->frames_out; self->out_config = config; self->tensor_configured = TRUE; diff --git a/gst/nnstreamer/tensor_common.c b/gst/nnstreamer/tensor_common.c index 89853a7..254eb39 100644 --- a/gst/nnstreamer/tensor_common.c +++ b/gst/nnstreamer/tensor_common.c @@ -1090,13 +1090,12 @@ static gboolean _peer_is_flexible_tensor_caps (GstPad * pad) { GstTensorsConfig config; - gboolean fixed, flexible; + gboolean flexible = FALSE; - fixed = flexible = FALSE; - - if (gst_tensors_config_from_peer (pad, &config, &fixed)) - flexible = (fixed && gst_tensors_info_is_flexible (&config.info)); + if (gst_tensors_config_from_peer (pad, &config, NULL)) + flexible = gst_tensors_info_is_flexible (&config.info); + gst_tensors_config_free (&config); return flexible; } @@ -1120,7 +1119,7 @@ gst_tensor_pad_caps_from_config (GstPad * pad, const GstTensorsConfig * config) templ = gst_pad_get_pad_template_caps (pad); - /* other/tensors-flexible */ + /* other/tensors (flexible) */ is_flexible = gst_tensors_info_is_flexible (&config->info); /* check peer element is flexible */ @@ -1154,7 +1153,7 @@ gst_tensor_pad_caps_from_config (GstPad * pad, const GstTensorsConfig * config) gst_caps_unref (caps); } - /* other/tensors */ + /* other/tensors (static) */ caps = gst_tensors_caps_from_config (config); intersectable: @@ -1185,10 +1184,15 @@ gst_tensor_pad_caps_is_flexible (GstPad * pad) caps = gst_pad_get_current_caps (pad); if (caps) { - GstStructure *structure = gst_caps_get_structure (caps, 0); + GstStructure *structure; + GstTensorsConfig config; + + structure = gst_caps_get_structure (caps, 0); + if (gst_tensors_config_from_structure (&config, structure)) + ret = gst_tensors_info_is_flexible (&config.info); - ret = gst_structure_has_name (structure, NNS_MIMETYPE_TENSORS_FLEXIBLE); gst_caps_unref (caps); + gst_tensors_config_free (&config); } return ret; diff --git a/gst/nnstreamer/tensor_converter/tensor_converter.c b/gst/nnstreamer/tensor_converter/tensor_converter.c index c3c4333..213e408 100644 --- a/gst/nnstreamer/tensor_converter/tensor_converter.c +++ b/gst/nnstreamer/tensor_converter/tensor_converter.c @@ -1184,6 +1184,9 @@ gst_tensor_converter_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) case _NNS_MEDIA_ANY: { GstTensorsConfig new_config; + + gst_tensors_config_init (&new_config); + if (self->mode == _CONVERTER_MODE_CUSTOM_CODE) { if (self->custom.func == NULL) { nns_loge diff --git a/nnstreamer_example/custom_example_framecounter/nnscustom_framecounter.c b/nnstreamer_example/custom_example_framecounter/nnscustom_framecounter.c index d28d2b4..ded81aa 100644 --- a/nnstreamer_example/custom_example_framecounter/nnscustom_framecounter.c +++ b/nnstreamer_example/custom_example_framecounter/nnscustom_framecounter.c @@ -78,7 +78,7 @@ configure (const GstTensorFilterProperties * prop, pt_data * data) } else if (0 == strncmp (parsed, "delay-", 6)) { parsed = parsed + 6; if (*parsed) - data->delay = (uint32_t) g_ascii_strtoll (parsed, NULL, 10);; + data->delay = (uint32_t) g_ascii_strtoll (parsed, NULL, 10); } counter++; -- 2.7.4