[Transform] available caps without peer
authorJaeyun Jung <jy1210.jung@samsung.com>
Wed, 22 Nov 2023 08:22:44 +0000 (17:22 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 30 Nov 2023 06:40:03 +0000 (15:40 +0900)
tensor-transform cannot determine the caps, this element can set out-caps by using incoming caps.
Remove unnecessary query for peer caps and update types of out-caps if input has tensors.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/nnstreamer/elements/gsttensor_transform.c
tests/nnstreamer_plugins/unittest_plugins.cc

index 76403db..99887ab 100644 (file)
@@ -2009,11 +2009,9 @@ gst_tensor_transform_transform_caps (GstBaseTransform * trans,
     gboolean is_types_not_fixed = FALSE;
     GstCaps *result_aux = gst_caps_new_empty ();
 
-    structure = gst_caps_get_structure (caps, i);
-
-    gst_tensors_config_init (&in_config);
     gst_tensors_config_init (&out_config);
 
+    structure = gst_caps_get_structure (caps, i);
     gst_tensors_config_from_structure (&in_config, structure);
 
     if (gst_tensors_config_is_flexible (&in_config)) {
@@ -2041,42 +2039,28 @@ gst_tensor_transform_transform_caps (GstBaseTransform * trans,
       gst_caps_append (result_aux, gst_tensor_caps_from_config (&out_config));
     } else {
       gst_caps_append (result_aux, gst_tensors_caps_from_config (&out_config));
-    }
 
-    /* remove `types` field from caps */
-    if (is_types_not_fixed) {
-      GstStructure *s;
-      for (j = 0; j < gst_caps_get_size (result_aux); ++j) {
-        s = gst_caps_get_structure (result_aux, j);
+      /* remove `types` field from caps */
+      if (is_types_not_fixed) {
+        GstStructure *s = gst_caps_get_structure (result_aux, 0);
         gst_structure_remove_field (s, "types");
       }
     }
 
     gst_caps_append (result, result_aux);
+
+    gst_tensors_config_free (&in_config);
+    gst_tensors_config_free (&out_config);
   }
 
   if (filtercap && gst_caps_get_size (filtercap) > 0) {
     GstCaps *intersection;
-    GstPad *pad;
-    GstCaps *peer_caps;
-
-    gst_tensor_caps_update_dimension (result, filtercap);
 
     intersection =
         gst_caps_intersect_full (result, filtercap, GST_CAPS_INTERSECT_FIRST);
 
     gst_caps_unref (result);
     result = intersection;
-
-    if (direction == GST_PAD_SINK)
-      pad = GST_BASE_TRANSFORM_SRC_PAD (filter);
-    else
-      pad = GST_BASE_TRANSFORM_SINK_PAD (filter);
-
-    if ((peer_caps = gst_pad_peer_query_caps (pad, NULL))) {
-      gst_tensor_caps_update_dimension (result, peer_caps);
-      gst_caps_unref (peer_caps);
-    }
   }
 
   silent_debug_caps (filter, result, "to");
index 04ad0dd..5e658b0 100644 (file)
@@ -5124,6 +5124,59 @@ error:
 #endif /* HAVE_ORC */
 
 /**
+ * @brief caps negotiation with tensor-filter.
+ */
+TEST_REQUIRE_TFLITE (testTensorTransform, negotiationFilter)
+{
+  GstHarness *h;
+  GstBuffer *in_buf, *out_buf;
+  gsize in_size, out_size;
+  GstTensorsConfig config;
+
+  const gchar *root_path = g_getenv ("NNSTREAMER_SOURCE_ROOT_PATH");
+
+  /* supposed to run test in build directory */
+  if (root_path == NULL)
+    root_path = "..";
+
+  g_autofree gchar *test_model = g_build_filename (root_path, "tests",
+      "test_models", "models", "mobilenet_v1_1.0_224_quant.tflite", NULL);
+  ASSERT_TRUE (g_file_test (test_model, G_FILE_TEST_EXISTS));
+
+  g_autofree gchar *pipeline = g_strdup_printf (
+      "tensor_transform mode=typecast option=uint8 ! tensor_filter framework=tensorflow-lite model=%s",
+      test_model);
+
+  h = gst_harness_new_parse (pipeline);
+  ASSERT_TRUE (h != NULL);
+
+  /* input tensor info */
+  gst_tensors_config_init (&config);
+  config.info.num_tensors = 1U;
+  config.info.info[0].type = _NNS_UINT32;
+  gst_tensor_parse_dimension ("3:224:224", config.info.info[0].dimension);
+  config.rate_n = 0;
+  config.rate_d = 1;
+
+  gst_harness_set_src_caps (h, gst_tensors_caps_from_config (&config));
+
+  /* push buffer (dummy input RGB 224x224, output 1001) */
+  in_size = gst_tensors_info_get_size (&config.info, 0);
+  out_size = 1001;
+
+  in_buf = gst_harness_create_buffer (h, in_size);
+  EXPECT_EQ (gst_harness_push (h, in_buf), GST_FLOW_OK);
+
+  /* get output buffer */
+  out_buf = gst_harness_pull (h);
+  EXPECT_EQ (gst_buffer_n_memory (out_buf), 1U);
+  EXPECT_EQ (gst_buffer_get_size (out_buf), out_size);
+  gst_buffer_unref (out_buf);
+
+  gst_harness_teardown (h);
+}
+
+/**
  * @brief Test to re-open tf-lite model file in tensor-filter.
  */
 TEST_REQUIRE_TFLITE (testTensorFilter, reopenTFlite01)