[Src-IIO] CHANNEL property handling fix
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 21 Apr 2020 02:28:33 +0000 (11:28 +0900)
committerwooksong <wook16.song@samsung.com>
Wed, 22 Apr 2020 01:29:32 +0000 (10:29 +0900)
1. If g_hash_table_insert returns FALSE,
it simply means that the entry is duplicated.
Just skip it, then.

2. If we cannot parse it, don't change status, but
ignore the whole property values.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
gst/nnstreamer/tensor_source/tensor_src_iio.c

index 7073e6a..a44d12e 100644 (file)
@@ -1211,7 +1211,7 @@ gst_tensor_src_iio_set_property (GObject * object, guint prop_id,
         gint64 val;
         gchar **strv;
         gchar *endptr = NULL;
-        gboolean status;
+        gboolean status = TRUE;
 
         /**
          * using direct as we only need to store keys
@@ -1225,17 +1225,24 @@ gst_tensor_src_iio_set_property (GObject * object, guint prop_id,
           val = g_ascii_strtoll (strv[i], &endptr, 10);
           if (errno == ERANGE || errno == EINVAL || (endptr == strv[i]
                   && val == 0)) {
-            GST_ERROR_OBJECT (self, "Cannot parse received custom channels %s",
+            GST_ERROR_OBJECT (self,
+                "Cannot parse received custom channels %s. The property values for CHANNELS are ignored.",
                 param);
             g_hash_table_destroy (self->custom_channel_table);
             self->custom_channel_table = NULL;
+            status = FALSE;
             break;
           }
-          status = g_hash_table_insert (self->custom_channel_table,
-              GINT_TO_POINTER (val), NULL);
-          g_assert (status);
+          if (FALSE == g_hash_table_insert (self->custom_channel_table,
+                  GINT_TO_POINTER (val), NULL)) {
+            /** this means val is duplicated. just skip it, then. */
+            ml_logw
+                ("tensor-src-iio's CHANNELS property value has a duplicated entry, '%s', which is registered only once.\n",
+                strv[i]);
+          }
         }
-        self->channels_enabled = CHANNELS_ENABLED_CUSTOM;
+        if (TRUE == status)
+          self->channels_enabled = CHANNELS_ENABLED_CUSTOM;
         g_strfreev (strv);
         break;
       }