2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2004 Thomas Vander Stichele <thomas@apestaart.org>
6 * gst-inspect.c: tool to inspect the GStreamer registry
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
30 #include "gst/gst-i18n-app.h"
34 #include <glib/gprintf.h>
39 print_pad_templates_info (GstElement * element, GstElementFactory * factory,
42 GstElementClass *gstelement_class;
44 GstPadTemplate *padtemplate;
46 if (!factory->numpadtemplates) {
50 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
52 pads = factory->padtemplates;
54 padtemplate = (GstPadTemplate *) (pads->data);
55 pads = g_list_next (pads);
57 if (padtemplate->direction == dir) {
58 if (padtemplate->caps) {
59 GstStructure *structure;
62 for (i = 0; i < gst_caps_get_size (padtemplate->caps); i++) {
63 structure = gst_caps_get_structure (padtemplate->caps, i);
64 g_print (" %s\n", gst_structure_get_name (structure));
72 print_element_list (const char *klass, GstPadDirection dir)
76 g_print ("Elements in %s:\n", klass);
77 for (plugins = gst_registry_pool_plugin_list (); plugins;
78 plugins = g_list_next (plugins)) {
82 plugin = (GstPlugin *) (plugins->data);
84 features = gst_plugin_get_feature_list (plugin);
86 GstPluginFeature *feature;
88 feature = GST_PLUGIN_FEATURE (features->data);
90 if (GST_IS_ELEMENT_FACTORY (feature)) {
91 GstElementFactory *factory;
94 factory = GST_ELEMENT_FACTORY (feature);
95 if (strncmp (factory->details.klass, klass, strlen (klass)) == 0) {
96 g_print (" %s: %s (%d)\n", GST_PLUGIN_FEATURE_NAME (factory),
97 factory->details.longname, gst_plugin_feature_get_rank (feature));
98 element = gst_element_factory_create (factory, NULL);
99 print_pad_templates_info (element, factory, dir);
100 gst_object_unref (GST_OBJECT (element));
104 features = g_list_next (features);
111 print_typefind_list (void)
115 g_print ("Typefind list:\n");
116 for (plugins = gst_registry_pool_plugin_list (); plugins;
117 plugins = g_list_next (plugins)) {
121 plugin = (GstPlugin *) (plugins->data);
123 features = gst_plugin_get_feature_list (plugin);
125 GstPluginFeature *feature;
127 feature = GST_PLUGIN_FEATURE (features->data);
129 if (GST_IS_TYPE_FIND_FACTORY (feature)) {
130 GstTypeFindFactory *factory;
133 gst_plugin_load_file (plugin->filename, NULL);
135 factory = GST_TYPE_FIND_FACTORY (feature);
136 g_print (" %s: (%d)\n", GST_PLUGIN_FEATURE_NAME (factory),
137 gst_plugin_feature_get_rank (feature));
138 s = gst_caps_to_string (gst_type_find_factory_get_caps (factory));
139 g_print (" %s\n", s);
143 features = g_list_next (features);
150 list_sort_func (gconstpointer a, gconstpointer b)
152 return strcmp ((const char *) a, (const char *) b);
156 get_typefind_mime_list (void)
159 GList *mime_list = NULL;
161 for (plugins = gst_registry_pool_plugin_list (); plugins;
162 plugins = g_list_next (plugins)) {
166 plugin = (GstPlugin *) (plugins->data);
168 features = gst_plugin_get_feature_list (plugin);
170 GstPluginFeature *feature;
172 feature = GST_PLUGIN_FEATURE (features->data);
174 if (GST_IS_TYPE_FIND_FACTORY (feature)) {
175 GstTypeFindFactory *factory;
180 factory = GST_TYPE_FIND_FACTORY (feature);
181 caps = gst_type_find_factory_get_caps (factory);
183 if (gst_plugin_feature_get_rank (feature) > 0 && caps != NULL) {
184 for (i = 0; i < gst_caps_get_size (caps); i++) {
185 const GstStructure *structure = gst_caps_get_structure (caps, i);
187 s = g_strdup (gst_structure_get_name (structure));
188 mime_list = g_list_prepend (mime_list, s);
193 features = g_list_next (features);
201 g_list_uniqify (GList * list)
205 for (item = g_list_first (list); item; item = g_list_next (item)) {
206 GList *next_item = g_list_next (item);
208 while (next_item && strcmp (item->data, next_item->data) == 0) {
209 g_free (next_item->data);
210 list = g_list_delete_link (list, next_item);
211 next_item = g_list_next (item);
219 get_pad_templates_info (GstElement * element, GstElementFactory * factory,
222 GstElementClass *gstelement_class;
224 GstPadTemplate *padtemplate;
225 GList *mime_list = NULL;
227 if (!factory->numpadtemplates) {
231 gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
233 pads = factory->padtemplates;
235 padtemplate = (GstPadTemplate *) (pads->data);
236 pads = g_list_next (pads);
238 if (padtemplate->direction == dir) {
239 if (padtemplate->caps) {
240 GstStructure *structure;
243 for (i = 0; i < gst_caps_get_size (padtemplate->caps); i++) {
244 structure = gst_caps_get_structure (padtemplate->caps, i);
245 mime_list = g_list_prepend (mime_list,
246 g_strdup (gst_structure_get_name (structure)));
255 get_element_mime_list (const char *klass, GstPadDirection dir)
257 GList *mime_list = NULL;
260 for (plugins = gst_registry_pool_plugin_list (); plugins;
261 plugins = g_list_next (plugins)) {
265 plugin = (GstPlugin *) (plugins->data);
267 features = gst_plugin_get_feature_list (plugin);
269 GstPluginFeature *feature;
271 feature = GST_PLUGIN_FEATURE (features->data);
273 if (GST_IS_ELEMENT_FACTORY (feature)) {
274 GstElementFactory *factory;
277 factory = GST_ELEMENT_FACTORY (feature);
278 if (strncmp (factory->details.klass, klass, strlen (klass)) == 0) {
279 if (gst_plugin_feature_get_rank (feature) > 0) {
282 element = gst_element_factory_create (factory, NULL);
283 list = get_pad_templates_info (element, factory, dir);
284 mime_list = g_list_concat (mime_list, list);
285 gst_object_unref (GST_OBJECT (element));
290 features = g_list_next (features);
298 print_mime_list (void)
301 GList *typefind_list;
305 typefind_list = get_typefind_mime_list ();
306 typefind_list = g_list_sort (typefind_list, list_sort_func);
307 typefind_list = g_list_uniqify (typefind_list);
309 list = get_element_mime_list ("Codec/Demuxer", GST_PAD_SINK);
310 list = g_list_concat (list, get_element_mime_list ("Codec/Decoder",
312 list = g_list_sort (list, list_sort_func);
313 list = g_list_uniqify (list);
315 g_print ("MIME media type list:\n");
316 for (item = g_list_first (list); item; item = g_list_next (item)) {
317 for (item2 = g_list_first (typefind_list); item2;
318 item2 = g_list_next (item2)) {
319 if (strcmp ((char *) item->data, (char *) item2->data) == 0) {
320 g_print (" %s\n", (char *) item->data);
328 main (int argc, char *argv[])
331 #ifdef GETTEXT_PACKAGE
332 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
333 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
334 textdomain (GETTEXT_PACKAGE);
337 gst_init (&argc, &argv);
339 print_element_list ("Codec/Demuxer", GST_PAD_SINK);
340 print_element_list ("Codec/Decoder", GST_PAD_SINK);
341 print_element_list ("Codec/Muxer", GST_PAD_SRC);
342 print_element_list ("Codec/Encoder", GST_PAD_SRC);
343 print_typefind_list ();