[Decoder] Dynamic update of tensor config
authorgichan-jang <gichan2.jang@samsung.com>
Mon, 6 Jul 2020 07:47:34 +0000 (16:47 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 7 Jul 2020 11:22:16 +0000 (20:22 +0900)
Changed to update tensor config dynamically.
Clear private data of subplugin, and init the subplugin.

Signed-off-by: gichan-jang <gichan2.jang@samsung.com>
gst/nnstreamer/tensor_decoder/tensordec.c
tests/nnstreamer_decoder/runTest.sh

index af67cbf..f3a9756 100644 (file)
@@ -609,13 +609,14 @@ gst_tensordec_class_finalize (GObject * object)
  * @brief Configure tensor metadata from sink caps
  */
 static gboolean
-gst_tensordec_configure (GstTensorDec * self, const GstCaps * caps)
+gst_tensordec_configure (GstTensorDec * self, const GstCaps * in_caps,
+    const GstCaps * out_caps)
 {
   GstStructure *structure;
   GstTensorsConfig config;
 
   /** This caps is coming from tensor */
-  structure = gst_caps_get_structure (caps, 0);
+  structure = gst_caps_get_structure (in_caps, 0);
 
   if (!gst_tensors_config_from_structure (&config, structure)) {
     GST_ERROR_OBJECT (self, "Cannot configure tensor from structure");
@@ -627,16 +628,33 @@ gst_tensordec_configure (GstTensorDec * self, const GstCaps * caps)
     return FALSE;
   }
 
-  if (self->configured && !gst_tensordec_check_consistency (self, &config)) {
-    GST_ERROR_OBJECT (self, "Mismatched to old metadata");
-    return FALSE;
-  }
-
   if (self->decoder == NULL) {
     GST_ERROR_OBJECT (self, "Decoder plugin is not yet configured.");
     return FALSE;
   }
 
+  /**
+   * If previous input configuration is set and is not compatible with incoming caps,
+   * get possible media caps from sub-plugin and change input configuration.
+   */
+  if (self->configured && !gst_tensordec_check_consistency (self, &config)) {
+    GstCaps *supposed;
+    gboolean compatible;
+
+    supposed = gst_tensordec_media_caps_from_tensor (self, &config);
+    compatible = gst_caps_is_always_compatible (out_caps, supposed);
+    gst_caps_unref (supposed);
+
+    /** Check if outcaps is compatible with new caps */
+    if (!compatible) {
+      GST_ERROR_OBJECT (self, "The coming tensor config is not valid.");
+      return FALSE;
+    }
+
+    gst_tensor_decoder_clean_plugin (self);
+    self->decoder->init (&self->plugin_data);
+  }
+
   self->tensor_config = config;
   self->configured = TRUE;
   return TRUE;
@@ -797,7 +815,7 @@ gst_tensordec_fixate_caps (GstBaseTransform * trans,
     return NULL;
   }
 
-  if (gst_tensordec_configure (self, caps)) {
+  if (gst_tensordec_configure (self, caps, othercaps)) {
     supposed =
         gst_tensordec_media_caps_from_tensor (self, &self->tensor_config);
   } else {
@@ -842,7 +860,7 @@ gst_tensordec_set_caps (GstBaseTransform * trans,
   silent_debug_caps (incaps, "from incaps");
   silent_debug_caps (outcaps, "from outcaps");
 
-  if (gst_tensordec_configure (self, incaps)) {
+  if (gst_tensordec_configure (self, incaps, outcaps)) {
     GstCaps *supposed = gst_tensordec_media_caps_from_tensor (self,
         &self->tensor_config);
 
index a5e333a..884025f 100644 (file)
@@ -58,4 +58,23 @@ callCompareTest testcase3.con.log testcase3.dec.log 3 "Compare for case 3" 0 0
 ## Trigger "decoder not configured"
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc ! tensor_converter ! tensor_decoder mode=direct_video ! video/mpeg ! fakesink" 4F_n 0 1 $PERFORMANCE
 
+# Dynamic tensor config update test
+## After converting the flatbuf to the tensor, it is tested whether the config is updated in runtime.
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=3 ! videoconvert ! video/x-raw, width=640, height=480, framerate=5/1,format=RGB ! \
+    tee name=t ! queue ! multifilesink location=\"test_05_raw_%1d.log\"
+    t. ! queue ! tensor_converter ! tensor_decoder mode=flatbuf ! other/flatbuf-tensor ! tensor_converter ! \
+        tensor_decoder mode=direct_video ! multifilesink location=\"test_05_decoded_%1d.log\" sync=true" 5 "Flatbuf dynamic tensor config update" 0 0 $PERFORMANCE
+callCompareTest test_05_raw_0.log test_05_decoded_0.log 5-1 "Compare for case 5-1" 1 0
+callCompareTest test_05_raw_1.log test_05_decoded_1.log 5-2 "Compare for case 5-2" 1 0
+callCompareTest test_05_raw_2.log test_05_decoded_2.log 5-3 "Compare for case 5-3" 1 0
+
+## After converting the protobuf to the tensor, it is tested whether the config is updated in runtime.
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} videotestsrc num-buffers=3 ! videoconvert ! video/x-raw, width=640, height=480, framerate=5/1,format=RGB ! \
+    tee name=t ! queue ! multifilesink location=\"test_06_raw_%1d.log\"
+    t. ! queue ! tensor_converter ! tensor_decoder mode=protobuf ! other/protobuf-tensor ! tensor_converter ! \
+        tensor_decoder mode=direct_video ! multifilesink location=\"test_06_decoded_%1d.log\" sync=true" 6 "Protobuf dynamic tensor config update" 0 0 $PERFORMANCE
+callCompareTest test_06_raw_0.log test_06_decoded_0.log 6-1 "Compare for case 6-1" 1 0
+callCompareTest test_06_raw_1.log test_06_decoded_1.log 6-2 "Compare for case 6-2" 1 0
+callCompareTest test_06_raw_2.log test_06_decoded_2.log 6-3 "Compare for case 6-3" 1 0
+
 report