*.c: Don't cast to GST_OBJECT when reffing or unreffing. Large source-munging commit!!!
[platform/upstream/gstreamer.git] / tests / old / testsuite / registry / gst-print-formats.c
1 /* GStreamer
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>
5  *
6  * gst-inspect.c: tool to inspect the GStreamer registry
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include <gst/gst.h>
29
30 #include "gst/gst-i18n-app.h"
31
32 #include <string.h>
33 #include <locale.h>
34 #include <glib/gprintf.h>
35
36 #define static
37
38 static void
39 print_pad_templates_info (GstElement * element, GstElementFactory * factory,
40     GstPadDirection dir)
41 {
42   GstElementClass *gstelement_class;
43   const GList *pads;
44   GstPadTemplate *padtemplate;
45
46   if (!factory->numpadtemplates) {
47     return;
48   }
49
50   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
51
52   pads = factory->padtemplates;
53   while (pads) {
54     padtemplate = (GstPadTemplate *) (pads->data);
55     pads = g_list_next (pads);
56
57     if (padtemplate->direction == dir) {
58       if (padtemplate->caps) {
59         GstStructure *structure;
60         int i;
61
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));
65         }
66       }
67     }
68   }
69 }
70
71 static void
72 print_element_list (const char *klass, GstPadDirection dir)
73 {
74   GList *plugins;
75
76   g_print ("Elements in %s:\n", klass);
77   for (plugins = gst_registry_pool_plugin_list (); plugins;
78       plugins = g_list_next (plugins)) {
79     GList *features;
80     GstPlugin *plugin;
81
82     plugin = (GstPlugin *) (plugins->data);
83
84     features = gst_plugin_get_feature_list (plugin);
85     while (features) {
86       GstPluginFeature *feature;
87
88       feature = GST_PLUGIN_FEATURE (features->data);
89
90       if (GST_IS_ELEMENT_FACTORY (feature)) {
91         GstElementFactory *factory;
92         GstElement *element;
93
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 (element);
101         }
102       }
103
104       features = g_list_next (features);
105     }
106   }
107   g_print ("\n");
108 }
109
110 static void
111 print_typefind_list (void)
112 {
113   GList *plugins;
114
115   g_print ("Typefind list:\n");
116   for (plugins = gst_registry_pool_plugin_list (); plugins;
117       plugins = g_list_next (plugins)) {
118     GList *features;
119     GstPlugin *plugin;
120
121     plugin = (GstPlugin *) (plugins->data);
122
123     features = gst_plugin_get_feature_list (plugin);
124     while (features) {
125       GstPluginFeature *feature;
126
127       feature = GST_PLUGIN_FEATURE (features->data);
128
129       if (GST_IS_TYPE_FIND_FACTORY (feature)) {
130         GstTypeFindFactory *factory;
131         char *s;
132
133         gst_plugin_load_file (plugin->filename, NULL);
134
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);
140         g_free (s);
141       }
142
143       features = g_list_next (features);
144     }
145   }
146   g_print ("\n");
147 }
148
149 static int
150 list_sort_func (gconstpointer a, gconstpointer b)
151 {
152   return strcmp ((const char *) a, (const char *) b);
153 }
154
155 static GList *
156 get_typefind_mime_list (void)
157 {
158   GList *plugins;
159   GList *mime_list = NULL;
160
161   for (plugins = gst_registry_pool_plugin_list (); plugins;
162       plugins = g_list_next (plugins)) {
163     GList *features;
164     GstPlugin *plugin;
165
166     plugin = (GstPlugin *) (plugins->data);
167
168     features = gst_plugin_get_feature_list (plugin);
169     while (features) {
170       GstPluginFeature *feature;
171
172       feature = GST_PLUGIN_FEATURE (features->data);
173
174       if (GST_IS_TYPE_FIND_FACTORY (feature)) {
175         GstTypeFindFactory *factory;
176         char *s;
177         int i;
178         const GstCaps *caps;
179
180         factory = GST_TYPE_FIND_FACTORY (feature);
181         caps = gst_type_find_factory_get_caps (factory);
182
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);
186
187             s = g_strdup (gst_structure_get_name (structure));
188             mime_list = g_list_prepend (mime_list, s);
189           }
190         }
191       }
192
193       features = g_list_next (features);
194     }
195   }
196
197   return mime_list;
198 }
199
200 GList *
201 g_list_uniqify (GList * list)
202 {
203   GList *item;
204
205   for (item = g_list_first (list); item; item = g_list_next (item)) {
206     GList *next_item = g_list_next (item);
207
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);
212     }
213   }
214
215   return list;
216 }
217
218 static GList *
219 get_pad_templates_info (GstElement * element, GstElementFactory * factory,
220     GstPadDirection dir)
221 {
222   GstElementClass *gstelement_class;
223   const GList *pads;
224   GstPadTemplate *padtemplate;
225   GList *mime_list = NULL;
226
227   if (!factory->numpadtemplates) {
228     return NULL;
229   }
230
231   gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element));
232
233   pads = factory->padtemplates;
234   while (pads) {
235     padtemplate = (GstPadTemplate *) (pads->data);
236     pads = g_list_next (pads);
237
238     if (padtemplate->direction == dir) {
239       if (padtemplate->caps) {
240         GstStructure *structure;
241         int i;
242
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)));
247         }
248       }
249     }
250   }
251   return mime_list;
252 }
253
254 static GList *
255 get_element_mime_list (const char *klass, GstPadDirection dir)
256 {
257   GList *mime_list = NULL;
258   GList *plugins;
259
260   for (plugins = gst_registry_pool_plugin_list (); plugins;
261       plugins = g_list_next (plugins)) {
262     GList *features;
263     GstPlugin *plugin;
264
265     plugin = (GstPlugin *) (plugins->data);
266
267     features = gst_plugin_get_feature_list (plugin);
268     while (features) {
269       GstPluginFeature *feature;
270
271       feature = GST_PLUGIN_FEATURE (features->data);
272
273       if (GST_IS_ELEMENT_FACTORY (feature)) {
274         GstElementFactory *factory;
275         GstElement *element;
276
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) {
280             GList *list;
281
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 (element);
286           }
287         }
288       }
289
290       features = g_list_next (features);
291     }
292   }
293
294   return mime_list;
295 }
296
297 static void
298 print_mime_list (void)
299 {
300   GList *list;
301   GList *typefind_list;
302   GList *item;
303   GList *item2;
304
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);
308
309   list = get_element_mime_list ("Codec/Demuxer", GST_PAD_SINK);
310   list = g_list_concat (list, get_element_mime_list ("Codec/Decoder",
311           GST_PAD_SINK));
312   list = g_list_sort (list, list_sort_func);
313   list = g_list_uniqify (list);
314
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);
321       }
322     }
323   }
324 }
325
326
327 int
328 main (int argc, char *argv[])
329 {
330
331 #ifdef GETTEXT_PACKAGE
332   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
333   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
334   textdomain (GETTEXT_PACKAGE);
335 #endif
336
337   gst_init (&argc, &argv);
338
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 ();
344   print_mime_list ();
345
346   return 0;
347 }