[Tools/Parser] Find element name in the pipeline
authorDongju Chae <dongju.chae@samsung.com>
Tue, 11 May 2021 09:03:56 +0000 (18:03 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 13 May 2021 06:35:02 +0000 (15:35 +0900)
This patch finds element name in the pipeline.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
tools/development/parser/types.c
tools/development/parser/types.h

index 02a3825..f5a9532 100644 (file)
@@ -131,7 +131,31 @@ gboolean
 nnstparser_element_link_pads_filtered (_Element *src, const gchar *src_pad,
     _Element *dst, const gchar *dst_pad, gchar *filter)
 {
-  /* NYI */
+  g_debug (
+      "trying to link element %s:%s to element %s:%s, filter %s\n",
+      __GST_ELEMENT_NAME(src), src_pad ? src_pad : "(any)",
+      __GST_ELEMENT_NAME(dst), dst_pad ? dst_pad : "(any)",
+      filter);
+
+  /**
+   * It's impossible to decide link compatibility of each pad
+   * because we don't have any available pad info. of elements.
+   * Thus, let's just assume that users provide valid pipelines.
+   * TODO: reconsider this assumption later.
+   */
+  return TRUE;
+}
+
+/**
+ * @brief Internal function to compare element names
+ */
+static int
+nnstparser_bin_compare_name (gconstpointer a, gconstpointer b)
+{
+  const _Element *elem = (const _Element *) a;
+  const gchar *name = (const gchar *) b;
+
+  return g_strcmp0 (elem->name, name);
 }
 
 /**
@@ -140,7 +164,16 @@ nnstparser_element_link_pads_filtered (_Element *src, const gchar *src_pad,
 _Element *
 nnstparser_bin_get_by_name (_Element * bin, const gchar * name)
 {
-  /* NYI */
+  GSList *elem;
+
+  g_return_val_if_fail (__GST_IS_BIN (bin), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  elem = g_slist_find_custom (bin->elements, name, nnstparser_bin_compare_name);
+  if (elem == NULL)
+    return NULL;
+
+  return nnstparser_element_ref (elem->data);
 }
 
 /**
@@ -149,16 +182,10 @@ nnstparser_bin_get_by_name (_Element * bin, const gchar * name)
 _Element *
 nnstparser_bin_get_by_name_recurse_up (_Element * bin, const gchar * name)
 {
-  _Element *result;
-
   g_return_val_if_fail (__GST_IS_BIN (bin), NULL);
   g_return_val_if_fail (name != NULL, NULL);
 
-  result = nnstparser_bin_get_by_name (bin, name);
-
-  if (!result) {
-    /* NYI: May need to analyze gst object parent structure */
-  }
+  return nnstparser_bin_get_by_name (bin, name);
 }
 
 /**
index b35b4eb..f733c0a 100644 (file)
@@ -25,7 +25,7 @@
   (e) : NULL)
 #define __GST_ELEMENT_CAST(e) ((_Element *)(e))
 #define __GST_ELEMENT_NAME(e) (__GST_IS_ELEMENT(e) ?\
-  (e)->name : "__InvalidElement__")
+  (e)->name : "(inv)")
 
 #define __GST_STR_NULL(s) ((s) ? (s) : "(NULL)")