gstreamer/tools/gst-compprep.c

138 lines
4.1 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <locale.h>
#include <gst/gst.h>
GST_DEBUG_CATEGORY_STATIC (debug_compprep);
#define GST_CAT_DEFAULT debug_compprep
#define GST_COMPREG_FILE (GST_CACHE_DIR "/compreg.xml")
#ifdef HAVE_LIBXML2
#if LIBXML_VERSION >= 20600
void
handle_xmlerror (void *userData, xmlErrorPtr error)
{
g_print ("Error writing the completion registry: %s, %s\n", GST_COMPREG_FILE,
error->message);
}
#endif
#endif
int
main (int argc, char *argv[])
{
xmlDocPtr doc;
xmlNodePtr factorynode, padnode, argnode, optionnode;
GList *element_factories, *padtemplates, *g;
const GList *pads;
GstElement *element;
GstPad *pad;
Use libxml2 for registry parsing, use staticpadtemplates in elementfactories. Makes gst_init() +/- 10x faster. Original commit message from CVS: * docs/gst/tmpl/gstelementfactory.sgml: * gst/gstelement.h: * gst/gstelementfactory.c: (gst_element_factory_init), (gst_element_factory_cleanup), (gst_element_register), (__gst_element_factory_add_static_pad_template), (gst_element_factory_get_static_pad_templates), (gst_element_factory_can_src_caps), (gst_element_factory_can_sink_caps): * gst/registries/Makefile.am: * gst/registries/gstlibxmlregistry.c: (gst_xml_registry_get_type), (gst_xml_registry_class_init), (gst_xml_registry_init), (gst_xml_registry_new), (gst_xml_registry_set_property), (gst_xml_registry_get_property), (get_time), (make_dir), (gst_xml_registry_get_perms_func), (plugin_times_older_than_recurse), (plugin_times_older_than), (gst_xml_registry_open_func), (gst_xml_registry_load_func), (gst_xml_registry_save_func), (gst_xml_registry_close_func), (add_to_char_array), (read_string), (read_uint), (read_enum), (load_pad_template), (load_feature), (load_plugin), (load_paths), (gst_xml_registry_load), (gst_xml_registry_load_plugin), (gst_xml_registry_save_caps), (gst_xml_registry_save_pad_template), (gst_xml_registry_save_feature), (gst_xml_registry_save_plugin), (gst_xml_registry_save), (gst_xml_registry_rebuild_recurse), (gst_xml_registry_rebuild): * gst/registries/gstlibxmlregistry.h: * tools/gst-compprep.c: (main): * tools/gst-inspect.c: (print_pad_templates_info): * tools/gst-xmlinspect.c: (print_element_info): Use libxml2 for registry parsing, use staticpadtemplates in elementfactories. Makes gst_init() +/- 10x faster.
2005-04-12 15:00:30 +00:00
GstStaticPadTemplate *padtemplate;
GParamSpec **property_specs;
guint num_properties, i;
setlocale (LC_ALL, "");
gst_init (&argc, &argv);
GST_DEBUG_CATEGORY_INIT (debug_compprep, "compprep", GST_DEBUG_BOLD,
"gst-compprep application");
GCC 4 fixen. Original commit message from CVS: 2005-05-04 Andy Wingo <wingo@pobox.com> * check/Makefile.am: * docs/gst/tmpl/gstatomic.sgml: * docs/gst/tmpl/gstplugin.sgml: * gst/base/gstbasesink.c: (gst_basesink_activate): * gst/base/gstbasesrc.c: (gst_basesrc_class_init), (gst_basesrc_init), (gst_basesrc_set_dataflow_funcs), (gst_basesrc_query), (gst_basesrc_set_property), (gst_basesrc_get_property), (gst_basesrc_check_get_range), (gst_basesrc_activate): * gst/base/gstbasesrc.h: * gst/base/gstbasetransform.c: (gst_base_transform_sink_activate), (gst_base_transform_src_activate): * gst/elements/gstelements.c: * gst/elements/gstfakesrc.c: (gst_fakesrc_class_init), (gst_fakesrc_set_property), (gst_fakesrc_get_property): * gst/elements/gsttee.c: (gst_tee_sink_activate): * gst/elements/gsttypefindelement.c: (find_element_get_length), (gst_type_find_element_checkgetrange), (gst_type_find_element_activate): * gst/gstbin.c: (gst_bin_save_thyself), (gst_bin_restore_thyself): * gst/gstcaps.c: (gst_caps_do_simplify), (gst_caps_save_thyself), (gst_caps_load_thyself): * gst/gstelement.c: (gst_element_pads_activate), (gst_element_save_thyself), (gst_element_restore_thyself): * gst/gstpad.c: (gst_pad_load_and_link), (gst_pad_save_thyself), (gst_ghost_pad_save_thyself), (gst_pad_check_pull_range): * gst/gstpad.h: * gst/gstxml.c: (gst_xml_write), (gst_xml_parse_doc), (gst_xml_parse_file), (gst_xml_parse_memory), (gst_xml_get_element), (gst_xml_make_element): * gst/indexers/gstfileindex.c: (gst_file_index_load), (_file_index_id_save_xml), (gst_file_index_commit): * gst/registries/gstlibxmlregistry.c: (read_string), (read_uint), (read_enum), (load_pad_template), (load_feature), (load_plugin), (load_paths): * libs/gst/dataprotocol/dataprotocol.c: (gst_dp_packet_from_caps), (gst_dp_packet_from_event), (gst_dp_caps_from_packet): * tools/gst-complete.c: (main): * tools/gst-compprep.c: (main): * tools/gst-inspect.c: (print_element_properties_info): * tools/gst-launch.c: (xmllaunch_parse_cmdline): * tools/gst-xmlinspect.c: (print_element_properties): GCC 4 fixen.
2005-05-04 21:29:44 +00:00
doc = xmlNewDoc ((xmlChar *) "1.0");
doc->xmlRootNode = xmlNewDocNode (doc, NULL,
(xmlChar *) "GST-CompletionRegistry", NULL);
element_factories =
gst_registry_get_feature_list (gst_registry_get_default (),
GST_TYPE_ELEMENT_FACTORY);
for (g = element_factories; g; g = g_list_next (g)) {
GstElementFactory *factory;
factory = GST_ELEMENT_FACTORY (g->data);
factorynode = xmlNewChild (doc->xmlRootNode, NULL, (xmlChar *) "element",
NULL);
xmlNewChild (factorynode, NULL, (xmlChar *) "name",
(xmlChar *) GST_PLUGIN_FEATURE_NAME (factory));
element = gst_element_factory_create (factory, NULL);
GST_DEBUG ("adding factory %s", GST_PLUGIN_FEATURE_NAME (factory));
if (element == NULL) {
GST_ERROR ("couldn't construct element from factory %s\n",
gst_object_get_name (GST_OBJECT (factory)));
return 1;
}
/* write out the padtemplates */
padtemplates = factory->staticpadtemplates;
while (padtemplates) {
padtemplate = (GstStaticPadTemplate *) (padtemplates->data);
padtemplates = g_list_next (padtemplates);
if (padtemplate->direction == GST_PAD_SRC)
padnode =
xmlNewChild (factorynode, NULL, (xmlChar *) "srcpadtemplate",
(xmlChar *) padtemplate->name_template);
else if (padtemplate->direction == GST_PAD_SINK)
padnode =
xmlNewChild (factorynode, NULL, (xmlChar *) "sinkpadtemplate",
(xmlChar *) padtemplate->name_template);
}
pads = element->pads;
while (pads) {
pad = (GstPad *) (pads->data);
pads = g_list_next (pads);
if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC)
padnode = xmlNewChild (factorynode, NULL, (xmlChar *) "srcpad",
(xmlChar *) GST_PAD_NAME (pad));
else if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK)
padnode = xmlNewChild (factorynode, NULL, (xmlChar *) "sinkpad",
(xmlChar *) GST_PAD_NAME (pad));
}
/* write out the args */
property_specs =
g_object_class_list_properties (G_OBJECT_GET_CLASS (element),
&num_properties);
for (i = 0; i < num_properties; i++) {
GParamSpec *param = property_specs[i];
argnode = xmlNewChild (factorynode, NULL, (xmlChar *) "argument",
(xmlChar *) param->name);
if (param->value_type == GST_TYPE_URI) {
xmlNewChild (argnode, NULL, (xmlChar *) "filename", NULL);
} else if (G_IS_PARAM_SPEC_ENUM (param) == G_TYPE_ENUM) {
GEnumValue *values;
gint j;
values = G_ENUM_CLASS (g_type_class_ref (param->value_type))->values;
for (j = 0; values[j].value_name; j++) {
gchar *value = g_strdup_printf ("%d", values[j].value);
optionnode = xmlNewChild (argnode, NULL, (xmlChar *) "option",
(xmlChar *) value);
xmlNewChild (optionnode, NULL, (xmlChar *) "value_nick",
(xmlChar *) values[j].value_nick);
g_free (value);
}
}
g_free (property_specs);
}
}
#ifdef HAVE_LIBXML2
#if LIBXML_VERSION >= 20600
xmlSetStructuredErrorFunc (NULL, handle_xmlerror);
#endif
xmlSaveFormatFile (GST_COMPREG_FILE, doc, 1);
#else
xmlSaveFile (GST_COMPREG_FILE, doc);
#endif
return 0;
}