[Demux] accept flex tensor
authorJaeyun <jy1210.jung@samsung.com>
Mon, 26 Apr 2021 10:45:26 +0000 (19:45 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 28 May 2021 04:40:52 +0000 (13:40 +0900)
add pad template to accept flex tensor, and update source to configure tensor info for static/flex tensor stream.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
gst/nnstreamer/tensor_demux/gsttensordemux.c

index 5ac42d6..921d0f2 100644 (file)
 
 GST_DEBUG_CATEGORY_STATIC (gst_tensor_demux_debug);
 #define GST_CAT_DEFAULT gst_tensor_demux_debug
-#define CAPS_STRING GST_TENSOR_CAP_DEFAULT "; " GST_TENSORS_CAP_DEFAULT
+
+/**
+ * @brief Default caps string for sink pad.
+ */
+#define CAPS_STRING_SINK GST_TENSORS_CAP_DEFAULT ";" GST_TENSORS_FLEX_CAP_DEFAULT
+
+/**
+ * @brief Default caps string for src pad.
+ */
+#define CAPS_STRING_SRC GST_TENSOR_CAP_DEFAULT ";" GST_TENSORS_CAP_DEFAULT ";" GST_TENSORS_FLEX_CAP_DEFAULT
 
 enum
 {
@@ -86,13 +95,13 @@ enum
 static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src_%u",
     GST_PAD_SRC,
     GST_PAD_SOMETIMES,
-    GST_STATIC_CAPS (CAPS_STRING)
+    GST_STATIC_CAPS (CAPS_STRING_SRC)
     );
 
 static GstStaticPadTemplate sink_templ = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (GST_TENSORS_CAP_DEFAULT)
+    GST_STATIC_CAPS (CAPS_STRING_SINK)
     );
 
 static GstFlowReturn gst_tensor_demux_chain (GstPad * pad, GstObject * parent,
@@ -463,11 +472,16 @@ gst_tensor_demux_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
   GList *list = NULL;
   tensor_demux = GST_TENSOR_DEMUX (parent);
 
-  num_tensors = tensor_demux->tensors_config.info.num_tensors;
-  GST_DEBUG_OBJECT (tensor_demux, " Number of Tensors: %d", num_tensors);
+  if (gst_tensors_info_is_flexible (&tensor_demux->tensors_config.info)) {
+    /* cannot get exact number of tensors from config */
+    num_tensors = gst_buffer_n_memory (buf);
+  } else {
+    num_tensors = tensor_demux->tensors_config.info.num_tensors;
 
-  /* supposed n memory blocks in buffer */
-  g_assert (gst_buffer_n_memory (buf) == num_tensors);
+    /* supposed n memory blocks in buffer */
+    g_assert (gst_buffer_n_memory (buf) == num_tensors);
+  }
+  GST_DEBUG_OBJECT (tensor_demux, " Number of Tensors: %d", num_tensors);
 
   num_srcs = num_tensors;
   if (tensor_demux->tensorpick != NULL) {