completion-helper: Add filtering by klass and sink caps.
authorMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Mon, 23 Feb 2015 20:17:16 +0000 (21:17 +0100)
committerMathieu Duponchelle <mathieu.duponchelle@opencreed.com>
Mon, 23 Feb 2015 20:17:54 +0000 (21:17 +0100)
libs/gst/helpers/gst-completion-helper.c

index 2e83dd5..e99b73b 100644 (file)
@@ -27,6 +27,7 @@
 #include <gst/gst.h>
 #include <glib.h>
 #include <stdlib.h>
+#include <string.h>
 
 static GList *
 get_pad_templates_info (GstElement * element, GstElementFactory * factory,
@@ -96,8 +97,22 @@ _are_linkable (GstPluginFeature * feature, GList * caps_list)
   return print;
 }
 
+static gboolean
+_belongs_to_klass (GstElementFactory * factory, const gchar * klass)
+{
+  const gchar *factory_klass;
+
+
+  factory_klass =
+      gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
+  if (strstr (factory_klass, klass))
+    return TRUE;
+  return FALSE;
+}
+
 static void
-_list_features (const gchar * compatible_with)
+_list_features (const gchar * compatible_with, const gchar * klass,
+    GstCaps * sinkcaps)
 {
   GList *plugins, *orig_plugins;
   GList *caps_list = NULL;
@@ -132,6 +147,13 @@ _list_features (const gchar * compatible_with)
         gboolean print = TRUE;
         if (caps_list)
           print = _are_linkable (feature, caps_list);
+        if (print && klass)
+          print = _belongs_to_klass (GST_ELEMENT_FACTORY (feature), klass);
+        if (print && sinkcaps)
+          print =
+              gst_element_factory_can_sink_any_caps (GST_ELEMENT_FACTORY
+              (feature), sinkcaps);
+
         if (print)
           g_print ("%s ", gst_plugin_feature_get_name (feature));
       }
@@ -182,6 +204,10 @@ main (int argc, char *argv[])
   gboolean list_features = FALSE;
   gchar *compatible_with = NULL;
   gchar *element = NULL;
+  gchar *klass = NULL;
+  gchar *caps_str = NULL;
+  GstCaps *sinkcaps = NULL;
+  gint exit_code = EXIT_SUCCESS;
 
   GOptionEntry options[] = {
     {"list-features", 'l', 0, G_OPTION_ARG_NONE, &list_features,
@@ -191,6 +217,10 @@ main (int argc, char *argv[])
         NULL},
     {"element-properties", '\0', 0, G_OPTION_ARG_STRING, &element,
         "The element to list properties on", NULL},
+    {"klass", '\0', 0, G_OPTION_ARG_STRING, &klass,
+        "Only print the elements belonging to that klass", NULL},
+    {"sinkcaps", '\0', 0, G_OPTION_ARG_STRING, &caps_str,
+        "Only print the elements that can sink these caps", NULL},
     {NULL}
   };
 
@@ -209,18 +239,31 @@ main (int argc, char *argv[])
   }
   g_option_context_free (ctx);
 
-  if (compatible_with) {
-    _list_features (compatible_with);
-    exit (EXIT_SUCCESS);
+  if (caps_str) {
+    sinkcaps = gst_caps_from_string (caps_str);
+    if (!sinkcaps) {
+      exit_code = EXIT_FAILURE;
+      goto done;
+    }
+  }
+
+  if (compatible_with || klass || sinkcaps) {
+    _list_features (compatible_with, klass, sinkcaps);
+    goto done;
   }
 
   if (element) {
     _list_element_properties (element);
-    exit (EXIT_SUCCESS);
+    goto done;
   }
 
   if (list_features) {
-    _list_features (NULL);
-    exit (EXIT_SUCCESS);
+    _list_features (NULL, NULL, NULL);
+    goto done;
   }
+
+done:
+  if (sinkcaps)
+    gst_caps_unref (sinkcaps);
+  exit (exit_code);
 }