2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 David A. Schleef <ds@schleef.org>
6 * gstregistryxml.c: GstRegistry object, support routines
8 * This library is free software; you can redistribute it and/or
9 * modify it ulnder 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 <sys/types.h>
38 #include <gst/gst_private.h>
39 #include <gst/gstelement.h>
40 #include <gst/gsttypefind.h>
41 #include <gst/gsttypefindfactory.h>
42 #include <gst/gsturi.h>
43 #include <gst/gstinfo.h>
44 #include <gst/gstenumtypes.h>
45 #include <gst/gstregistry.h>
47 #include <libxml/xmlreader.h>
49 #include "glib-compat.h"
51 #define BLOCK_SIZE 1024*10
53 #define GST_CAT_DEFAULT GST_CAT_REGISTRY
55 #define CLASS(registry) GST_XML_REGISTRY_CLASS (G_OBJECT_GET_CLASS (registry))
58 //static gboolean gst_registry_xml_load (GstRegistry * registry);
59 //static gboolean gst_registry_xml_save (GstRegistry * registry);
60 //static gboolean gst_registry_xml_rebuild (GstRegistry * registry);
65 gst_registry_xml_class_init (GstRegistryClass * klass)
67 GObjectClass *gobject_class;
68 GstRegistryClass *gstregistry_class;
69 GstRegistryClass *gstxmlregistry_class;
71 gobject_class = (GObjectClass *) klass;
72 gstregistry_class = (GstRegistryClass *) klass;
73 gstxmlregistry_class = (GstRegistryClass *) klass;
75 parent_class = g_type_class_ref (GST_TYPE_REGISTRY);
77 gobject_class->get_property =
78 GST_DEBUG_FUNCPTR (gst_registry_xml_get_property);
79 gobject_class->set_property =
80 GST_DEBUG_FUNCPTR (gst_registry_xml_set_property);
82 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LOCATION,
83 g_param_spec_string ("location", "Location",
84 "Location of the registry file", NULL, G_PARAM_READWRITE));
86 gstregistry_class->load = GST_DEBUG_FUNCPTR (gst_registry_xml_load);
87 gstregistry_class->save = GST_DEBUG_FUNCPTR (gst_registry_xml_save);
88 gstregistry_class->rebuild = GST_DEBUG_FUNCPTR (gst_registry_xml_rebuild);
90 gstregistry_class->load_plugin =
91 GST_DEBUG_FUNCPTR (gst_registry_xml_load_plugin);
93 gstxmlregistry_class->get_perms_func =
94 GST_DEBUG_FUNCPTR (gst_registry_xml_get_perms_func);
95 gstxmlregistry_class->open_func =
96 GST_DEBUG_FUNCPTR (gst_registry_xml_open_func);
97 gstxmlregistry_class->load_func =
98 GST_DEBUG_FUNCPTR (gst_registry_xml_load_func);
102 gst_registry_xml_init (GstRegistry * registry)
104 registry->location = NULL;
108 /* this function returns the biggest of the path's mtime and ctime
109 * mtime is updated through an actual write (data)
110 * ctime is updated through changing inode information
111 * so this function returns the last time *anything* changed to this path
112 * it also sets the given boolean to TRUE if the given path is a directory
116 get_time (const char *path, gboolean * is_dir)
120 if (stat (path, &statbuf)) {
126 *is_dir = S_ISDIR (statbuf.st_mode);
128 if (statbuf.st_mtime > statbuf.st_ctime)
129 return statbuf.st_mtime;
130 return statbuf.st_ctime;
137 gst_registry_xml_get_perms_func (GstRegistry * registry)
141 /* if the dir does not exist, make it. if that can't be done, flags = 0x0.
142 if the file can be appended to, it's writable. if it can then be read,
144 After that check if it exists. */
146 if (make_dir (registry->location) != TRUE) {
147 /* we can't do anything with it, leave flags as 0x0 */
151 dirname = g_path_get_dirname (registry->location);
153 if (g_file_test (registry->location, G_FILE_TEST_EXISTS)) {
154 GST_REGISTRY (registry)->flags |= GST_REGISTRY_EXISTS;
157 if (!access (dirname, W_OK)) {
158 GST_REGISTRY (registry)->flags |= GST_REGISTRY_WRITABLE;
161 if (!access (dirname, R_OK)) {
162 GST_REGISTRY (registry)->flags |= GST_REGISTRY_READABLE;
170 /* return TRUE iff regtime is more recent than the times of all the .so files
171 * in the plugin dirs; ie return TRUE if this path does not need to trigger
172 * a rebuild of registry
174 * - if it's a directory, recurse on subdirs
176 * - if entry is not newer, return TRUE.
178 * - and it's a plugin, return FALSE
179 * - otherwise return TRUE
182 plugin_times_older_than_recurse (gchar * path, time_t regtime)
185 struct dirent *dirent;
189 time_t pathtime = get_time (path, &is_dir);
192 dir = opendir (path);
194 while ((dirent = readdir (dir))) {
195 /* don't want to recurse in place or backwards */
196 if (strcmp (dirent->d_name, ".") && strcmp (dirent->d_name, "..")) {
197 new_path = g_build_filename (path, dirent->d_name, NULL);
198 if (!plugin_times_older_than_recurse (new_path, regtime)) {
199 GST_CAT_INFO (GST_CAT_PLUGIN_LOADING,
200 "path %s is more recent than registry time of %ld",
201 new_path, (long) regtime);
215 if (pathtime <= regtime) {
219 /* it's a file, and it's more recent */
220 if (g_str_has_suffix (path, ".so") || g_str_has_suffix (path, ".dll")) {
221 if (!gst_plugin_check_file (path, NULL))
224 /* it's a newer GStreamer plugin */
225 GST_CAT_INFO (GST_CAT_PLUGIN_LOADING,
226 "%s looks like a plugin and is more recent than registry time of %ld",
227 path, (long) regtime);
235 /* return TRUE iff regtime is more recent than the times of all the .so files
236 * in the plugin dirs; ie return TRUE if registry is up to date.
239 plugin_times_older_than (GList * paths, time_t regtime)
242 GST_CAT_LOG (GST_CAT_PLUGIN_LOADING,
243 "comparing plugin times from %s with %ld",
244 (gchar *) paths->data, (long) regtime);
245 if (!plugin_times_older_than_recurse (paths->data, regtime))
247 paths = g_list_next (paths);
249 GST_CAT_LOG (GST_CAT_PLUGIN_LOADING,
250 "everything's fine, no registry rebuild needed.");
257 gst_registry_xml_open_func (GstRegistry * registry, GstRegistryMode mode)
259 GstRegistry *gst_registry;
262 gst_registry = GST_REGISTRY (registry);
263 paths = gst_registry->paths;
264 GST_CAT_DEBUG (GST_CAT_GST_INIT, "opening registry %s", registry->location);
266 g_return_val_if_fail (registry->open == FALSE, FALSE);
268 /* if it doesn't exist, first try to build it, and check if it worked
269 * if it's not readable, return false
270 * if it's out of date, rebuild it */
271 if (mode == GST_XML_REGISTRY_READ) {
272 if (!(gst_registry->flags & GST_REGISTRY_EXISTS)) {
273 /* if it's not writable, then don't bother */
274 if (!(gst_registry->flags & GST_REGISTRY_WRITABLE)) {
275 GST_CAT_INFO (GST_CAT_GST_INIT, "Registry isn't writable");
278 GST_CAT_INFO (GST_CAT_GST_INIT,
279 "Registry doesn't exist, trying to build...");
280 gst_registry_rebuild (gst_registry);
281 gst_registry_save (gst_registry);
282 /* FIXME: verify that the flags actually get updated ! */
283 if (!(gst_registry->flags & GST_REGISTRY_EXISTS)) {
287 /* at this point we know it exists */
288 g_return_val_if_fail (gst_registry->flags & GST_REGISTRY_READABLE, FALSE);
290 if (!plugin_times_older_than (paths, get_time (registry->location, NULL))) {
291 if (gst_registry->flags & GST_REGISTRY_WRITABLE) {
292 GST_CAT_INFO (GST_CAT_GST_INIT, "Registry out of date, rebuilding...");
294 gst_registry_rebuild (gst_registry);
296 gst_registry_save (gst_registry);
298 if (!plugin_times_older_than (paths, get_time (registry->location,
300 GST_CAT_INFO (GST_CAT_GST_INIT,
301 "Registry still out of date, something is wrong...");
305 GST_CAT_INFO (GST_CAT_GST_INIT,
306 "Can't write to this registry and it's out of date, ignoring it");
311 GST_CAT_DEBUG (GST_CAT_GST_INIT, "opening registry %s for reading",
313 registry->cache_file = fopen (registry->location, "r");
314 } else if (mode == GST_XML_REGISTRY_WRITE) {
318 g_return_val_if_fail (gst_registry->flags & GST_REGISTRY_WRITABLE, FALSE);
320 tmploc = g_strconcat (registry->location, ".tmp", NULL);
322 GST_CAT_DEBUG (GST_CAT_GST_INIT, "opening registry %s for writing", tmploc);
324 if ((fd = open (tmploc, O_WRONLY | O_CREAT, 0644)) < 0) {
330 registry->cache_file = fdopen (fd, "w");
333 if (!registry->cache_file)
336 registry->open = TRUE;
343 gst_registry_xml_save (GstRegistry * registry, gchar * format, ...)
347 va_start (var_args, format);
349 vfprintf (registry->cache_file, format, var_args);
357 add_to_char_array (gchar *** array, gchar * value)
360 gchar **old = *array;
363 /* expensive, but cycles are cheap... */
367 new = g_new0 (gchar *, i + 2);
377 /* read a string and copy it into the given location */
379 read_string (xmlTextReaderPtr reader, gchar ** write_to)
381 int depth = xmlTextReaderDepth (reader);
382 gboolean found = FALSE;
384 while (xmlTextReaderRead (reader) == 1) {
385 if (xmlTextReaderDepth (reader) == depth)
387 if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_TEXT) {
390 *write_to = g_strdup ((gchar *) xmlTextReaderConstValue (reader));
398 read_uint (xmlTextReaderPtr reader, guint * write_to)
400 int depth = xmlTextReaderDepth (reader);
401 gboolean found = FALSE;
403 while (xmlTextReaderRead (reader) == 1) {
404 if (xmlTextReaderDepth (reader) == depth)
406 if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_TEXT) {
411 GST_DEBUG ("failed to read uint, multiple text nodes");
414 s = (const gchar *) xmlTextReaderConstValue (reader);
415 *write_to = strtol (s, &ret, 0);
417 GST_DEBUG ("failed to read uint, text didn't convert to int");
423 GST_DEBUG ("failed to read uint, no text node");
428 read_enum (xmlTextReaderPtr reader, GType enum_type, guint * write_to)
430 int depth = xmlTextReaderDepth (reader);
431 gboolean found = FALSE;
435 while (xmlTextReaderRead (reader) == 1) {
436 if (xmlTextReaderDepth (reader) == depth)
438 if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_TEXT) {
439 GEnumClass *enum_class;
444 enum_class = g_type_class_ref (enum_type);
448 g_enum_get_value_by_nick (enum_class,
449 (gchar *) xmlTextReaderConstValue (reader));
451 *write_to = value->value;
454 g_type_class_unref (enum_class);
460 static GstStaticPadTemplate *
461 load_pad_template (xmlTextReaderPtr reader)
464 int depth = xmlTextReaderDepth (reader);
465 gchar *name = NULL, *caps_str = NULL;
466 guint direction = 0, presence = 0;
468 while ((ret = xmlTextReaderRead (reader)) == 1) {
469 if (xmlTextReaderDepth (reader) == depth) {
470 GstStaticPadTemplate *template;
472 template = g_new0 (GstStaticPadTemplate, 1);
473 template->name_template = name;
474 template->presence = presence;
475 template->direction = direction;
476 template->static_caps.string = caps_str;
480 if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
481 xmlTextReaderDepth (reader) == depth + 1) {
482 const gchar *tag = (gchar *) xmlTextReaderConstName (reader);
484 if (g_str_equal (tag, "nametemplate")) {
485 read_string (reader, &name);
486 } else if (g_str_equal (tag, "direction")) {
487 read_enum (reader, GST_TYPE_PAD_DIRECTION, &direction);
488 } else if (g_str_equal (tag, "presence")) {
489 read_enum (reader, GST_TYPE_PAD_PRESENCE, &presence);
490 } else if (!strncmp (tag, "caps", 4)) {
491 read_string (reader, &caps_str);
501 static GstPluginFeature *
502 load_feature (xmlTextReaderPtr reader)
505 int depth = xmlTextReaderDepth (reader);
506 gchar *feature_name =
507 (gchar *) xmlTextReaderGetAttribute (reader, BAD_CAST "typename");
508 GstPluginFeature *feature;
511 GST_DEBUG ("loading feature");
515 type = g_type_from_name (feature_name);
516 g_free (feature_name);
522 feature = g_object_new (type, NULL);
526 if (!GST_IS_PLUGIN_FEATURE (feature)) {
527 g_object_unref (feature);
530 while ((ret = xmlTextReaderRead (reader)) == 1) {
531 if (xmlTextReaderDepth (reader) == depth) {
532 GST_DEBUG ("loaded feature %p with name %s", feature, feature->name);
535 if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
536 xmlTextReaderDepth (reader) == depth + 1) {
537 const gchar *tag = (gchar *) xmlTextReaderConstName (reader);
539 if (g_str_equal (tag, "name"))
540 read_string (reader, &feature->name);
541 if (g_str_equal (tag, "rank"))
542 read_uint (reader, &feature->rank);
543 if (GST_IS_ELEMENT_FACTORY (feature)) {
544 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
546 if (g_str_equal (tag, "longname")) {
549 ret = read_string (reader, &factory->details.longname);
550 GST_DEBUG ("longname ret=%d, name=%s",
551 ret, factory->details.longname);
552 } else if (g_str_equal (tag, "class")) {
553 read_string (reader, &factory->details.klass);
554 } else if (g_str_equal (tag, "description")) {
555 read_string (reader, &factory->details.description);
556 } else if (g_str_equal (tag, "author")) {
557 read_string (reader, &factory->details.author);
558 } else if (g_str_equal (tag, "uri_type")) {
561 if (read_string (reader, &s)) {
562 if (g_ascii_strncasecmp (s, "sink", 4) == 0) {
563 factory->uri_type = GST_URI_SINK;
564 } else if (g_ascii_strncasecmp (s, "source", 5) == 0) {
565 factory->uri_type = GST_URI_SRC;
569 } else if (g_str_equal (tag, "uri_protocol")) {
572 if (read_string (reader, &s))
573 add_to_char_array (&factory->uri_protocols, s);
574 } else if (g_str_equal (tag, "interface")) {
577 if (read_string (reader, &s)) {
578 __gst_element_factory_add_interface (factory, s);
579 /* add_interface strdup's s */
582 } else if (g_str_equal (tag, "padtemplate")) {
583 GstStaticPadTemplate *template = load_pad_template (reader);
586 GST_LOG ("adding template %s to factory %s",
587 GST_STR_NULL (GST_PAD_TEMPLATE_NAME_TEMPLATE (template)),
588 GST_PLUGIN_FEATURE_NAME (feature));
589 __gst_element_factory_add_static_pad_template (factory, template);
592 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
593 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
595 if (g_str_equal (tag, "extension")) {
598 if (read_string (reader, &s))
599 add_to_char_array (&factory->extensions, s);
600 } else if (g_str_equal (tag, "caps")) {
603 if (read_string (reader, &s)) {
604 factory->caps = gst_caps_from_string (s);
608 } else if (GST_IS_INDEX_FACTORY (feature)) {
609 GstIndexFactory *factory = GST_INDEX_FACTORY (feature);
611 if (g_str_equal (tag, "longdesc"))
612 read_string (reader, &factory->longdesc);
617 g_assert_not_reached ();
622 load_plugin (xmlTextReaderPtr reader, GList ** feature_list)
627 *feature_list = NULL;
629 GST_DEBUG ("creating new plugin and parsing");
631 plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
633 plugin->flags |= GST_PLUGIN_FLAG_CACHED;
634 while ((ret = xmlTextReaderRead (reader)) == 1) {
635 if (xmlTextReaderDepth (reader) == 1) {
638 if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
639 xmlTextReaderDepth (reader) == 2) {
640 const gchar *tag = (gchar *) xmlTextReaderConstName (reader);
642 if (g_str_equal (tag, "name")) {
645 ret = read_string (reader, &plugin->desc.name);
646 GST_DEBUG ("name ret=%d, name=%s", ret, plugin->desc.name);
649 } else if (g_str_equal (tag, "description")) {
650 if (!read_string (reader, &plugin->desc.description))
652 GST_DEBUG ("description %s", plugin->desc.description);
653 } else if (g_str_equal (tag, "filename")) {
654 if (!read_string (reader, &plugin->filename))
656 GST_DEBUG ("filename %s", plugin->filename);
657 plugin->basename = g_path_get_basename (plugin->filename);
658 } else if (g_str_equal (tag, "version")) {
659 if (!read_string (reader, &plugin->desc.version))
661 GST_DEBUG ("version %s", plugin->desc.version);
662 } else if (g_str_equal (tag, "license")) {
663 if (!read_string (reader, &plugin->desc.license))
665 GST_DEBUG ("license %s", plugin->desc.license);
666 } else if (g_str_equal (tag, "source")) {
667 if (!read_string (reader, &plugin->desc.source))
669 GST_DEBUG ("source %s", plugin->desc.source);
670 } else if (g_str_equal (tag, "package")) {
671 if (!read_string (reader, &plugin->desc.package))
673 GST_DEBUG ("package %s", plugin->desc.package);
674 } else if (g_str_equal (tag, "origin")) {
675 if (!read_string (reader, &plugin->desc.origin)) {
676 GST_DEBUG ("failed to read origin");
679 } else if (g_str_equal (tag, "m32p")) {
682 if (!read_string (reader, &s)) {
683 GST_DEBUG ("failed to read mtime");
686 plugin->file_mtime = strtol (s, NULL, 0);
687 GST_DEBUG ("mtime %d", (int) plugin->file_mtime);
689 } else if (g_str_equal (tag, "size")) {
692 if (read_uint (reader, &x)) {
693 plugin->file_size = x;
694 GST_DEBUG ("file_size %d", plugin->file_size);
696 GST_DEBUG ("failed to read size");
698 } else if (g_str_equal (tag, "feature")) {
699 GstPluginFeature *feature = load_feature (reader);
701 feature->plugin_name = g_strdup (plugin->desc.name);
704 *feature_list = g_list_prepend (*feature_list, feature);
707 GST_DEBUG ("unknown tag %s", tag);
711 gst_object_unref (plugin);
713 GST_DEBUG ("problem reading plugin");
719 gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
723 xmlTextReaderPtr reader;
725 gboolean in_registry = FALSE;
728 /* make sure these types exist */
729 GST_TYPE_ELEMENT_FACTORY;
730 GST_TYPE_TYPE_FIND_FACTORY;
731 GST_TYPE_INDEX_FACTORY;
733 timer = g_timer_new ();
735 file = fopen (location, "r");
737 g_timer_destroy (timer);
741 reader = xmlReaderForFd (fileno (file), NULL, NULL, 0);
744 g_timer_destroy (timer);
748 while ((ret = xmlTextReaderRead (reader)) == 1) {
749 if (xmlTextReaderDepth (reader) == 0) {
750 in_registry = xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
751 g_str_equal ("GST-PluginRegistry", xmlTextReaderConstName (reader));
752 } else if (in_registry) {
753 if (xmlTextReaderDepth (reader) == 1 &&
754 xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT) {
755 const gchar *tag = (const gchar *) xmlTextReaderConstName (reader);
757 if (g_str_equal (tag, "plugin")) {
759 GstPlugin *plugin = load_plugin (reader, &feature_list);
764 GST_DEBUG ("adding plugin %s", plugin->desc.name);
765 gst_registry_add_plugin (registry, plugin);
766 for (g = feature_list; g; g = g_list_next (g)) {
767 gst_registry_add_feature (registry, GST_PLUGIN_FEATURE (g->data));
769 g_list_free (feature_list);
775 xmlFreeTextReader (reader);
777 GST_ERROR ("parsing registry cache: %s", location);
779 g_timer_destroy (timer);
783 g_timer_stop (timer);
784 seconds = g_timer_elapsed (timer, NULL);
785 g_timer_destroy (timer);
787 GST_INFO ("loaded %s in %f seconds", location, seconds);
796 gst_registry_xml_load_plugin (GstRegistry * registry, GstPlugin * plugin)
798 GError *error = NULL;
799 GstPlugin *loaded_plugin;
801 /* FIXME: add gerror support */
802 loaded_plugin = gst_plugin_load_file (plugin->filename, &error);
805 g_warning ("could not load plugin %s: %s", plugin->desc.name,
807 g_error_free (error);
810 } else if (loaded_plugin != plugin) {
811 g_critical ("how to remove plugins?");
821 #define PUT_ESCAPED(prefix,tag,value) \
823 const gchar *toconv = value; \
825 gchar *v = g_markup_escape_text (toconv, strlen (toconv)); \
826 gst_registry_xml_save (registry, prefix "<%s>%s</%s>\n", tag, v, tag); \
833 gst_registry_xml_save_caps (GstRegistry * registry, const GstCaps * caps)
835 /* we copy the caps here so we can simplify them before saving. This is a lot
836 * faster when loading them later on */
838 GstCaps *copy = gst_caps_copy (caps);
840 gst_caps_do_simplify (copy);
841 s = gst_caps_to_string (copy);
842 gst_caps_unref (copy);
844 PUT_ESCAPED (" ", "caps", s);
850 gst_registry_xml_save_pad_template (GstRegistry * registry,
851 GstStaticPadTemplate * template)
855 PUT_ESCAPED (" ", "nametemplate", template->name_template);
856 gst_registry_xml_save (registry, " <direction>%s</direction>\n",
857 (template->direction == GST_PAD_SINK ? "sink" : "src"));
859 switch (template->presence) {
863 case GST_PAD_SOMETIMES:
864 presence = "sometimes";
866 case GST_PAD_REQUEST:
867 presence = "request";
870 presence = "unknown";
873 gst_registry_xml_save (registry, " <presence>%s</presence>\n", presence);
875 if (template->static_caps.string) {
876 gst_registry_xml_save (registry, " <caps>%s</caps>\n",
877 template->static_caps.string);
883 gst_registry_xml_save_feature (GstRegistry * registry,
884 GstPluginFeature * feature)
886 PUT_ESCAPED (" ", "name", feature->name);
888 if (feature->rank > 0) {
889 gint rank = feature->rank;
891 gst_registry_xml_save (registry, " <rank>%d</rank>\n", rank);
894 if (GST_IS_ELEMENT_FACTORY (feature)) {
895 GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
898 PUT_ESCAPED (" ", "longname", factory->details.longname);
899 PUT_ESCAPED (" ", "class", factory->details.klass);
900 PUT_ESCAPED (" ", "description", factory->details.description);
901 PUT_ESCAPED (" ", "author", factory->details.author);
903 walk = factory->staticpadtemplates;
906 GstStaticPadTemplate *template = walk->data;
908 gst_registry_xml_save (registry, " <padtemplate>\n");
909 gst_registry_xml_save_pad_template (registry, template);
910 gst_registry_xml_save (registry, " </padtemplate>\n");
912 walk = g_list_next (walk);
915 walk = factory->interfaces;
917 PUT_ESCAPED (" ", "interface", (gchar *) walk->data);
918 walk = g_list_next (walk);
921 if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
924 PUT_ESCAPED (" ", "uri_type",
925 factory->uri_type == GST_URI_SINK ? "sink" : "source");
926 g_assert (factory->uri_protocols);
927 protocol = factory->uri_protocols;
929 PUT_ESCAPED (" ", "uri_protocol", *protocol);
933 } else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
934 GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
938 gst_registry_xml_save_caps (registry, factory->caps);
940 if (factory->extensions) {
941 while (factory->extensions[i]) {
942 PUT_ESCAPED (" ", "extension", factory->extensions[i]);
946 } else if (GST_IS_INDEX_FACTORY (feature)) {
947 PUT_ESCAPED (" ", "longdesc", GST_INDEX_FACTORY (feature)->longdesc);
953 gst_registry_xml_save_plugin (GstRegistry * registry, GstPlugin * plugin)
959 PUT_ESCAPED (" ", "name", plugin->desc.name);
960 PUT_ESCAPED (" ", "description", plugin->desc.description);
961 PUT_ESCAPED (" ", "filename", plugin->filename);
962 sprintf (s, "%d", (int) plugin->file_size);
963 PUT_ESCAPED (" ", "size", s);
964 sprintf (s, "%d", (int) plugin->file_mtime);
965 PUT_ESCAPED (" ", "m32p", s);
966 PUT_ESCAPED (" ", "version", plugin->desc.version);
967 PUT_ESCAPED (" ", "license", plugin->desc.license);
968 PUT_ESCAPED (" ", "source", plugin->desc.source);
969 PUT_ESCAPED (" ", "package", plugin->desc.package);
970 PUT_ESCAPED (" ", "origin", plugin->desc.origin);
972 list = gst_registry_get_feature_list_by_plugin (registry, plugin->desc.name);
974 for (walk = list; walk; walk = g_list_next (walk)) {
975 GstPluginFeature *feature = GST_PLUGIN_FEATURE (walk->data);
977 gst_registry_xml_save (registry, " <feature typename=\"%s\">\n",
978 g_type_name (G_OBJECT_TYPE (feature)));
979 gst_registry_xml_save_feature (registry, feature);
980 gst_registry_xml_save (registry, " </feature>\n");
983 gst_plugin_feature_list_free (list);
989 gst_registry_xml_write_cache (GstRegistry * registry, const char *location)
994 g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
996 tmp_location = g_strconcat (location, ".tmp", NULL);
997 registry->cache_file = fopen (tmp_location, "w");
998 if (registry->cache_file == NULL) {
1001 /* oops, I bet the directory doesn't exist */
1002 dir = g_path_get_dirname (location);
1003 g_mkdir_with_parents (dir, 0777);
1006 registry->cache_file = fopen (tmp_location, "w");
1008 if (registry->cache_file == NULL) {
1012 gst_registry_xml_save (registry, "<?xml version=\"1.0\"?>\n");
1013 gst_registry_xml_save (registry, "<GST-PluginRegistry>\n");
1016 for (walk = g_list_last (registry->plugins); walk;
1017 walk = g_list_previous (walk)) {
1018 GstPlugin *plugin = GST_PLUGIN (walk->data);
1020 if (!plugin->filename)
1023 if (plugin->flags & GST_PLUGIN_FLAG_CACHED) {
1025 struct stat statbuf;
1027 ret = g_stat (plugin->filename, &statbuf);
1030 if (plugin->file_mtime != statbuf.st_mtime ||
1031 plugin->file_size != statbuf.st_size) {
1036 gst_registry_xml_save (registry, "<plugin>\n");
1037 gst_registry_xml_save_plugin (registry, plugin);
1038 gst_registry_xml_save (registry, "</plugin>\n");
1040 gst_registry_xml_save (registry, "</GST-PluginRegistry>\n");
1042 fclose (registry->cache_file);
1044 if (g_file_test (tmp_location, G_FILE_TEST_EXISTS)) {
1048 rename (tmp_location, location);
1050 g_free (tmp_location);
1057 gst_registry_xml_rebuild_recurse (GstRegistry * registry,
1058 const gchar * directory)
1061 gint dr_len, sf_len;
1063 if (g_file_test (directory, G_FILE_TEST_IS_DIR)) {
1064 GDir *dir = g_dir_open (directory, 0, NULL);
1067 const gchar *dirent;
1069 while ((dirent = g_dir_read_name (dir))) {
1072 if (*dirent == '=') {
1073 /* =build, =inst, etc. -- automake distcheck directories */
1077 dirname = g_strjoin ("/", directory, dirent, NULL);
1079 g_list_concat (ret, gst_registry_xml_rebuild_recurse (registry,
1086 dr_len = strlen (directory);
1087 sf_len = strlen (G_MODULE_SUFFIX);
1088 if (dr_len >= sf_len &&
1089 strcmp (directory + dr_len - sf_len, G_MODULE_SUFFIX) == 0) {
1090 ret = g_list_prepend (ret, g_strdup (directory));
1098 gst_registry_xml_rebuild (GstRegistry * registry)
1100 GList *walk = NULL, *plugins = NULL, *prune = NULL;
1101 GError *error = NULL;
1104 GstRegistry *registry = GST_XML_REGISTRY (registry);
1106 walk = registry->paths;
1109 gchar *path = (gchar *) walk->data;
1111 GST_CAT_INFO (GST_CAT_PLUGIN_LOADING,
1112 "Rebuilding registry %p in directory %s...", registry, path);
1114 plugins = g_list_concat (plugins,
1115 gst_registry_xml_rebuild_recurse (registry, path));
1117 walk = g_list_next (walk);
1120 plugins = g_list_reverse (plugins);
1123 length = g_list_length (plugins);
1127 g_assert (walk->data);
1128 plugin = gst_plugin_load_file ((gchar *) walk->data, NULL);
1130 prune = g_list_prepend (prune, walk->data);
1131 gst_registry_add_plugin (registry, plugin);
1134 walk = g_list_next (walk);
1139 plugins = g_list_remove (plugins, walk->data);
1140 g_free (walk->data);
1141 walk = g_list_next (walk);
1143 g_list_free (prune);
1145 } while (g_list_length (plugins) != length);
1149 if ((plugin = gst_plugin_load_file ((gchar *) walk->data, &error))) {
1150 g_warning ("Bizarre behavior: plugin %s actually loaded",
1151 (gchar *) walk->data);
1152 gst_registry_add_plugin (registry, plugin);
1154 GST_CAT_INFO (GST_CAT_PLUGIN_LOADING, "Plugin %s failed to load: %s",
1155 (gchar *) walk->data, error->message);
1157 g_free (walk->data);
1158 g_error_free (error);
1162 walk = g_list_next (walk);