[Transform/Typecast] Change reaction for invalid option using g_critical
authorWook Song <wook16.song@samsung.com>
Tue, 12 Feb 2019 01:34:02 +0000 (10:34 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 15 Feb 2019 06:20:04 +0000 (15:20 +0900)
This patch adds a regular expression for the typecast option string, and
then changes the reaction for invalid option string using the regular
expression and g_critical. In short, if the option string is invalid,
the pipeline would be terminated before it starts.

Signed-off-by: Wook Song <wook16.song@samsung.com>
gst/nnstreamer/tensor_transform/tensor_transform.c

index 2c78d69..1692f62 100644 (file)
@@ -91,6 +91,8 @@
 GST_DEBUG_CATEGORY_STATIC (gst_tensor_transform_debug);
 #define GST_CAT_DEFAULT gst_tensor_transform_debug
 
+#define REGEX_TYPECAST_OPTION "(^[u]?int(8|16|32|64)$|^float(32|64)$)"
+
 /**
  * @brief tensor_transform properties
  */
@@ -179,8 +181,8 @@ gst_tensor_transform_mode_get_type (void)
     static GEnumValue mode_types[] = {
       {GTT_DIMCHG, "Mode for changing tensor dimensions",
           "dimchg"},
-      {GTT_TYPECAST, "Mode for casting type of tensor",
-          "typecast"},
+      {GTT_TYPECAST, "Mode for casting type of tensor, "
+            "option=" REGEX_TYPECAST_OPTION, "typecast"},
       {GTT_ARITHMETIC, "Mode for arithmetic operations with tensor",
           "arithmetic"},
       {GTT_TRANSPOSE, "Mode for transposing shape of tensor",
@@ -740,9 +742,16 @@ gst_tensor_transform_set_option_data (GstTensorTransform * filter)
     }
     case GTT_TYPECAST:
     {
-      filter->data_typecast.to = gst_tensor_get_type (filter->option);
-      if (filter->data_typecast.to != _NNS_END)
+      if (g_regex_match_simple (REGEX_TYPECAST_OPTION, filter->option, 0, 0)) {
+        filter->data_typecast.to = gst_tensor_get_type (filter->option);
         filter->loaded = TRUE;
+      } else {
+        g_critical ("%s: typecast: "
+            "\'%s\' is not valid data type for tensor: "
+            "data type of tensor should be one of %s\n",
+            gst_object_get_name ((GstObject *) filter),
+            filter->option, GST_TENSOR_TYPE_ALL);
+      }
       break;
     }
     case GTT_ARITHMETIC: