[CodeClean] prepare next caps nego
authorJaeyun <jy1210.jung@samsung.com>
Mon, 5 Jul 2021 05:19:51 +0000 (14:19 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 6 Jul 2021 07:51:17 +0000 (16:51 +0900)
Code clean, prepare caps string with tensor format.
- clean source code and update description

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
ext/nnstreamer/extra/nnstreamer_protobuf.h
gst/nnstreamer/include/tensor_typedef.h
gst/nnstreamer/tensor_aggregator/tensor_aggregator.c
gst/nnstreamer/tensor_common.c
gst/nnstreamer/tensor_converter/tensor_converter.c
nnstreamer_example/custom_example_framecounter/nnscustom_framecounter.c

index 75a5d43..1811ba5 100644 (file)
 #include <nnstreamer_plugin_api.h>
 
 /**
- * @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.
index dd21f44..87a26bd 100644 (file)
     /**
      * 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)
     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
index d8d5e62..5548a5f 100644 (file)
@@ -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;
 
index 89853a7..254eb39 100644 (file)
@@ -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;
index c3c4333..213e408 100644 (file)
@@ -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
index d28d2b4..ded81aa 100644 (file)
@@ -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++;