2 * Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
4 * gst-completion-helper.c: tool to let other tools enjoy fast and powerful
5 * gstreamer-aware completion
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
32 get_pad_templates_info (GstElement * element, GstElementFactory * factory,
33 GstPadDirection direction)
36 GstStaticPadTemplate *padtemplate;
37 GList *caps_list = NULL;
39 if (gst_element_factory_get_num_pad_templates (factory) == 0) {
44 pads = gst_element_factory_get_static_pad_templates (factory);
46 padtemplate = (GstStaticPadTemplate *) (pads->data);
47 pads = g_list_next (pads);
49 if (padtemplate->direction != direction)
52 if (padtemplate->static_caps.string) {
54 g_list_append (caps_list,
55 gst_static_caps_get (&padtemplate->static_caps));
64 _get_pad_caps (const gchar * factory_name, GstPadDirection direction)
66 GstElementFactory *factory = gst_element_factory_find (factory_name);
67 GstElement *element = gst_element_factory_make (factory_name, NULL);
74 GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
78 return get_pad_templates_info (element, factory, direction);
82 _are_linkable (GstPluginFeature * feature, GList * caps_list)
84 gboolean print = FALSE;
85 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
89 for (tmp = caps_list; tmp; tmp = tmp->next) {
90 if (gst_element_factory_can_sink_any_caps (factory, tmp->data)) {
100 _list_features (const gchar * compatible_with)
102 GList *plugins, *orig_plugins;
103 GList *caps_list = NULL;
105 if (compatible_with) {
106 caps_list = _get_pad_caps (compatible_with, GST_PAD_SRC);
109 orig_plugins = plugins = gst_registry_get_plugin_list (gst_registry_get ());
111 GList *features, *orig_features;
114 plugin = (GstPlugin *) (plugins->data);
115 plugins = g_list_next (plugins);
117 if (GST_OBJECT_FLAG_IS_SET (plugin, GST_PLUGIN_FLAG_BLACKLISTED)) {
121 orig_features = features =
122 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
123 gst_plugin_get_name (plugin));
125 GstPluginFeature *feature;
127 if (G_UNLIKELY (features->data == NULL))
129 feature = GST_PLUGIN_FEATURE (features->data);
131 if (GST_IS_ELEMENT_FACTORY (feature)) {
132 gboolean print = TRUE;
134 print = _are_linkable (feature, caps_list);
136 g_print ("%s ", gst_plugin_feature_get_name (feature));
140 features = g_list_next (features);
143 gst_plugin_feature_list_free (orig_features);
146 g_list_free (caps_list);
148 gst_plugin_list_free (orig_plugins);
152 _print_element_properties_info (GstElement * element)
154 GParamSpec **property_specs;
155 guint num_properties, i;
157 property_specs = g_object_class_list_properties
158 (G_OBJECT_GET_CLASS (element), &num_properties);
160 for (i = 0; i < num_properties; i++) {
161 GParamSpec *param = property_specs[i];
163 if (param->flags & G_PARAM_WRITABLE) {
164 g_print ("%s= ", g_param_spec_get_name (param));
168 g_free (property_specs);
172 _list_element_properties (const gchar * factory_name)
174 GstElement *element = gst_element_factory_make (factory_name, NULL);
176 _print_element_properties_info (element);
180 main (int argc, char *argv[])
182 gboolean list_features = FALSE;
183 gchar *compatible_with = NULL;
184 gchar *element = NULL;
186 GOptionEntry options[] = {
187 {"list-features", 'l', 0, G_OPTION_ARG_NONE, &list_features,
188 "list all the available features", NULL},
189 {"compatible-with", '\0', 0, G_OPTION_ARG_STRING, &compatible_with,
190 "Only print the elements that could be queued after this feature name",
192 {"element-properties", '\0', 0, G_OPTION_ARG_STRING, &element,
193 "The element to list properties on", NULL},
200 ctx = g_option_context_new ("PIPELINE-DESCRIPTION");
201 g_option_context_add_main_entries (ctx, options, NULL);
202 g_option_context_add_group (ctx, gst_init_get_option_group ());
203 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
205 g_printerr ("Error initializing: %s\n", GST_STR_NULL (err->message));
207 g_printerr ("Error initializing: Unknown error!\n");
210 g_option_context_free (ctx);
212 if (compatible_with) {
213 _list_features (compatible_with);
218 _list_element_properties (element);
223 _list_features (NULL);