2005-09-15 00:20:14 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
* 2005 David A. Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* gstregistryxml.c: GstRegistry object, support routines
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it ulnder the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst_private.h>
|
|
|
|
#include <gst/gstelement.h>
|
|
|
|
#include <gst/gsttypefind.h>
|
|
|
|
#include <gst/gsttypefindfactory.h>
|
|
|
|
#include <gst/gsturi.h>
|
|
|
|
#include <gst/gstinfo.h>
|
|
|
|
#include <gst/gstenumtypes.h>
|
|
|
|
#include <gst/gstregistry.h>
|
|
|
|
|
|
|
|
#include <libxml/xmlreader.h>
|
|
|
|
|
2005-11-21 18:03:22 +00:00
|
|
|
#include "glib-compat-private.h"
|
2005-11-16 12:25:22 +00:00
|
|
|
#include <glib/gstdio.h>
|
2005-09-15 01:10:52 +00:00
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
#define BLOCK_SIZE 1024*10
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT GST_CAT_REGISTRY
|
|
|
|
|
|
|
|
#define CLASS(registry) GST_XML_REGISTRY_CLASS (G_OBJECT_GET_CLASS (registry))
|
|
|
|
|
|
|
|
static gboolean
|
2006-03-08 12:57:37 +00:00
|
|
|
gst_registry_save (GstRegistry * registry, gchar * format, ...)
|
2005-09-15 00:20:14 +00:00
|
|
|
{
|
|
|
|
va_list var_args;
|
2008-03-03 18:42:04 +00:00
|
|
|
gsize written, len;
|
2006-03-08 12:57:37 +00:00
|
|
|
gboolean ret;
|
|
|
|
char *str;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
va_start (var_args, format);
|
2006-03-08 12:57:37 +00:00
|
|
|
str = g_strdup_vprintf (format, var_args);
|
|
|
|
va_end (var_args);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
len = strlen (str);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
written = write (registry->cache_file, str, len);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (len == written)
|
|
|
|
ret = TRUE;
|
|
|
|
else {
|
|
|
|
ret = FALSE;
|
|
|
|
GST_ERROR ("Failed to write registry to temporary file: %s",
|
|
|
|
g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
return ret;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_to_char_array (gchar *** array, gchar * value)
|
|
|
|
{
|
|
|
|
gchar **new;
|
|
|
|
gchar **old = *array;
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
/* expensive, but cycles are cheap... */
|
|
|
|
if (old)
|
|
|
|
while (old[i])
|
|
|
|
i++;
|
|
|
|
new = g_new0 (gchar *, i + 2);
|
|
|
|
new[i] = value;
|
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
|
|
|
new[i] = old[i];
|
|
|
|
}
|
|
|
|
g_free (old);
|
|
|
|
*array = new;
|
|
|
|
}
|
|
|
|
|
2005-09-18 21:24:55 +00:00
|
|
|
/* read a string and copy it into the given location */
|
2005-09-15 00:20:14 +00:00
|
|
|
static gboolean
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (xmlTextReaderPtr reader, gchar ** write_to, gboolean allow_blank)
|
2005-09-15 00:20:14 +00:00
|
|
|
{
|
|
|
|
int depth = xmlTextReaderDepth (reader);
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
while (xmlTextReaderRead (reader) == 1) {
|
2006-05-17 14:01:33 +00:00
|
|
|
if (xmlTextReaderDepth (reader) == depth) {
|
|
|
|
if (allow_blank && !found &&
|
|
|
|
xmlTextReaderNodeType (reader) == XML_READER_TYPE_END_ELEMENT) {
|
|
|
|
/* Allow blank strings */
|
|
|
|
*write_to = g_strdup ("");
|
|
|
|
found = TRUE;
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
return found;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_TEXT) {
|
2008-03-01 11:21:30 +00:00
|
|
|
xmlChar *value;
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
if (found)
|
|
|
|
return FALSE;
|
2008-03-01 11:21:30 +00:00
|
|
|
|
|
|
|
value = xmlTextReaderValue (reader);
|
|
|
|
*write_to = g_strdup ((gchar *) value);
|
|
|
|
xmlFree (value);
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-26 18:04:42 +00:00
|
|
|
static gboolean
|
|
|
|
read_const_interned_string (xmlTextReaderPtr reader, const gchar ** write_to,
|
|
|
|
gboolean allow_blank)
|
|
|
|
{
|
|
|
|
gchar *s = NULL;
|
|
|
|
|
|
|
|
if (!read_string (reader, &s, allow_blank))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*write_to = g_intern_string (s);
|
|
|
|
g_free (s);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
static gboolean
|
|
|
|
read_uint (xmlTextReaderPtr reader, guint * write_to)
|
|
|
|
{
|
|
|
|
int depth = xmlTextReaderDepth (reader);
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
while (xmlTextReaderRead (reader) == 1) {
|
|
|
|
if (xmlTextReaderDepth (reader) == depth)
|
|
|
|
return found;
|
|
|
|
if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_TEXT) {
|
|
|
|
gchar *ret;
|
|
|
|
const gchar *s;
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
GST_DEBUG ("failed to read uint, multiple text nodes");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
s = (const gchar *) xmlTextReaderConstValue (reader);
|
|
|
|
*write_to = strtol (s, &ret, 0);
|
|
|
|
if (s == ret) {
|
|
|
|
GST_DEBUG ("failed to read uint, text didn't convert to int");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GST_DEBUG ("failed to read uint, no text node");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
read_enum (xmlTextReaderPtr reader, GType enum_type, guint * write_to)
|
|
|
|
{
|
|
|
|
int depth = xmlTextReaderDepth (reader);
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
if (*write_to)
|
|
|
|
return FALSE;
|
|
|
|
while (xmlTextReaderRead (reader) == 1) {
|
|
|
|
if (xmlTextReaderDepth (reader) == depth)
|
|
|
|
return found;
|
|
|
|
if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_TEXT) {
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *value;
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return FALSE;
|
|
|
|
enum_class = g_type_class_ref (enum_type);
|
|
|
|
if (!enum_class)
|
|
|
|
return FALSE;
|
|
|
|
value =
|
|
|
|
g_enum_get_value_by_nick (enum_class,
|
|
|
|
(gchar *) xmlTextReaderConstValue (reader));
|
|
|
|
if (value) {
|
|
|
|
*write_to = value->value;
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
g_type_class_unref (enum_class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStaticPadTemplate *
|
|
|
|
load_pad_template (xmlTextReaderPtr reader)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int depth = xmlTextReaderDepth (reader);
|
2007-09-26 18:04:42 +00:00
|
|
|
const gchar *name = NULL;
|
|
|
|
gchar *caps_str = NULL;
|
2005-09-15 00:20:14 +00:00
|
|
|
guint direction = 0, presence = 0;
|
|
|
|
|
|
|
|
while ((ret = xmlTextReaderRead (reader)) == 1) {
|
|
|
|
if (xmlTextReaderDepth (reader) == depth) {
|
|
|
|
GstStaticPadTemplate *template;
|
|
|
|
|
|
|
|
template = g_new0 (GstStaticPadTemplate, 1);
|
2007-09-26 18:04:42 +00:00
|
|
|
template->name_template = name; /* must be an interned string! */
|
2005-09-15 00:20:14 +00:00
|
|
|
template->presence = presence;
|
|
|
|
template->direction = direction;
|
|
|
|
template->static_caps.string = caps_str;
|
|
|
|
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
|
|
|
|
xmlTextReaderDepth (reader) == depth + 1) {
|
|
|
|
const gchar *tag = (gchar *) xmlTextReaderConstName (reader);
|
|
|
|
|
|
|
|
if (g_str_equal (tag, "nametemplate")) {
|
2007-09-26 18:04:42 +00:00
|
|
|
read_const_interned_string (reader, &name, FALSE);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "direction")) {
|
|
|
|
read_enum (reader, GST_TYPE_PAD_DIRECTION, &direction);
|
|
|
|
} else if (g_str_equal (tag, "presence")) {
|
|
|
|
read_enum (reader, GST_TYPE_PAD_PRESENCE, &presence);
|
|
|
|
} else if (!strncmp (tag, "caps", 4)) {
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (reader, &caps_str, FALSE);
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (caps_str);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPluginFeature *
|
|
|
|
load_feature (xmlTextReaderPtr reader)
|
|
|
|
{
|
|
|
|
int ret;
|
2005-12-16 19:24:24 +00:00
|
|
|
int depth;
|
2008-03-01 11:21:30 +00:00
|
|
|
xmlChar *feature_name;
|
2005-09-15 00:20:14 +00:00
|
|
|
GstPluginFeature *feature;
|
|
|
|
GType type;
|
|
|
|
|
2005-12-16 19:24:24 +00:00
|
|
|
depth = xmlTextReaderDepth (reader);
|
2008-03-01 11:21:30 +00:00
|
|
|
feature_name = xmlTextReaderGetAttribute (reader, BAD_CAST "typename");
|
2005-12-16 19:24:24 +00:00
|
|
|
|
2008-03-01 11:21:30 +00:00
|
|
|
GST_LOG ("loading feature '%s'", GST_STR_NULL ((const char *) feature_name));
|
2005-09-19 14:09:54 +00:00
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
if (!feature_name)
|
|
|
|
return NULL;
|
2005-12-16 19:24:24 +00:00
|
|
|
|
2008-03-01 11:21:30 +00:00
|
|
|
type = g_type_from_name ((const char *) feature_name);
|
|
|
|
xmlFree (feature_name);
|
2005-09-18 21:24:55 +00:00
|
|
|
feature_name = NULL;
|
|
|
|
|
|
|
|
if (!type) {
|
2005-09-15 00:20:14 +00:00
|
|
|
return NULL;
|
2005-09-18 21:24:55 +00:00
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
feature = g_object_new (type, NULL);
|
2005-09-18 21:24:55 +00:00
|
|
|
if (!feature) {
|
2005-09-15 00:20:14 +00:00
|
|
|
return NULL;
|
2005-09-18 21:24:55 +00:00
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
if (!GST_IS_PLUGIN_FEATURE (feature)) {
|
2005-12-16 19:24:24 +00:00
|
|
|
/* don't really know what it is */
|
|
|
|
if (GST_IS_OBJECT (feature))
|
|
|
|
gst_object_unref (feature);
|
|
|
|
else
|
|
|
|
g_object_unref (feature);
|
2005-09-15 00:20:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
while ((ret = xmlTextReaderRead (reader)) == 1) {
|
2005-09-19 14:09:54 +00:00
|
|
|
if (xmlTextReaderDepth (reader) == depth) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("loaded feature %p with name %s", feature, feature->name);
|
2005-09-15 00:20:14 +00:00
|
|
|
return feature;
|
2005-09-19 14:09:54 +00:00
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
|
|
|
|
xmlTextReaderDepth (reader) == depth + 1) {
|
|
|
|
const gchar *tag = (gchar *) xmlTextReaderConstName (reader);
|
|
|
|
|
|
|
|
if (g_str_equal (tag, "name"))
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (reader, &feature->name, FALSE);
|
gst/: Use _CAST macros to avoid unneeded type checking.
Original commit message from CVS:
* gst/gst.c: (gst_debug_help):
* gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
(gst_plugin_feature_list_free):
* gst/gstregistry.c: (gst_registry_add_plugin),
(gst_registry_add_feature), (gst_registry_plugin_filter),
(gst_registry_feature_filter), (gst_registry_find_plugin),
(gst_registry_find_feature), (gst_registry_get_plugin_list),
(gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
* gst/gstminiobject.c: (gst_mini_object_unref),
(gst_mini_object_replace), (gst_value_mini_object_free),
(gst_value_mini_object_copy):
Use _CAST macros to avoid unneeded type checking.
Added some more G_UNLIKELY.
2006-06-12 09:17:44 +00:00
|
|
|
else if (g_str_equal (tag, "rank"))
|
2005-09-15 00:20:14 +00:00
|
|
|
read_uint (reader, &feature->rank);
|
gst/: Use _CAST macros to avoid unneeded type checking.
Original commit message from CVS:
* gst/gst.c: (gst_debug_help):
* gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
(gst_plugin_feature_list_free):
* gst/gstregistry.c: (gst_registry_add_plugin),
(gst_registry_add_feature), (gst_registry_plugin_filter),
(gst_registry_feature_filter), (gst_registry_find_plugin),
(gst_registry_find_feature), (gst_registry_get_plugin_list),
(gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
* gst/gstminiobject.c: (gst_mini_object_unref),
(gst_mini_object_replace), (gst_value_mini_object_free),
(gst_value_mini_object_copy):
Use _CAST macros to avoid unneeded type checking.
Added some more G_UNLIKELY.
2006-06-12 09:17:44 +00:00
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
if (GST_IS_ELEMENT_FACTORY (feature)) {
|
gst/: Use _CAST macros to avoid unneeded type checking.
Original commit message from CVS:
* gst/gst.c: (gst_debug_help):
* gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
(gst_plugin_feature_list_free):
* gst/gstregistry.c: (gst_registry_add_plugin),
(gst_registry_add_feature), (gst_registry_plugin_filter),
(gst_registry_feature_filter), (gst_registry_find_plugin),
(gst_registry_find_feature), (gst_registry_get_plugin_list),
(gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
* gst/gstminiobject.c: (gst_mini_object_unref),
(gst_mini_object_replace), (gst_value_mini_object_free),
(gst_value_mini_object_copy):
Use _CAST macros to avoid unneeded type checking.
Added some more G_UNLIKELY.
2006-06-12 09:17:44 +00:00
|
|
|
GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (feature);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
if (g_str_equal (tag, "longname")) {
|
|
|
|
int ret;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
ret = read_string (reader, &factory->details.longname, TRUE);
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("longname ret=%d, name=%s", ret, factory->details.longname);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "class")) {
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (reader, &factory->details.klass, TRUE);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "description")) {
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (reader, &factory->details.description, TRUE);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "author")) {
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (reader, &factory->details.author, TRUE);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "uri_type")) {
|
|
|
|
gchar *s = NULL;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
if (read_string (reader, &s, FALSE)) {
|
2005-09-15 00:20:14 +00:00
|
|
|
if (g_ascii_strncasecmp (s, "sink", 4) == 0) {
|
|
|
|
factory->uri_type = GST_URI_SINK;
|
|
|
|
} else if (g_ascii_strncasecmp (s, "source", 5) == 0) {
|
|
|
|
factory->uri_type = GST_URI_SRC;
|
|
|
|
}
|
2005-09-18 21:24:55 +00:00
|
|
|
g_free (s);
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
} else if (g_str_equal (tag, "uri_protocol")) {
|
|
|
|
gchar *s = NULL;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
if (read_string (reader, &s, FALSE))
|
2005-09-15 00:20:14 +00:00
|
|
|
add_to_char_array (&factory->uri_protocols, s);
|
|
|
|
} else if (g_str_equal (tag, "interface")) {
|
|
|
|
gchar *s = NULL;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
if (read_string (reader, &s, FALSE)) {
|
2005-09-15 00:20:14 +00:00
|
|
|
__gst_element_factory_add_interface (factory, s);
|
2005-09-18 21:24:55 +00:00
|
|
|
/* add_interface strdup's s */
|
|
|
|
g_free (s);
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "padtemplate")) {
|
|
|
|
GstStaticPadTemplate *template = load_pad_template (reader);
|
|
|
|
|
|
|
|
if (template) {
|
|
|
|
GST_LOG ("adding template %s to factory %s",
|
2005-11-03 00:39:54 +00:00
|
|
|
GST_STR_NULL (GST_PAD_TEMPLATE_NAME_TEMPLATE (template)),
|
2005-09-15 00:20:14 +00:00
|
|
|
GST_PLUGIN_FEATURE_NAME (feature));
|
|
|
|
__gst_element_factory_add_static_pad_template (factory, template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
|
|
|
|
GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
|
|
|
|
|
|
|
|
if (g_str_equal (tag, "extension")) {
|
|
|
|
gchar *s = NULL;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
if (read_string (reader, &s, TRUE))
|
2005-09-15 00:20:14 +00:00
|
|
|
add_to_char_array (&factory->extensions, s);
|
|
|
|
} else if (g_str_equal (tag, "caps")) {
|
|
|
|
gchar *s = NULL;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
if (read_string (reader, &s, FALSE)) {
|
2005-09-15 00:20:14 +00:00
|
|
|
factory->caps = gst_caps_from_string (s);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (GST_IS_INDEX_FACTORY (feature)) {
|
|
|
|
GstIndexFactory *factory = GST_INDEX_FACTORY (feature);
|
|
|
|
|
|
|
|
if (g_str_equal (tag, "longdesc"))
|
2006-05-17 14:01:33 +00:00
|
|
|
read_string (reader, &factory->longdesc, TRUE);
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-02 11:04:58 +00:00
|
|
|
GST_WARNING ("Error reading feature from registry: registry corrupt?");
|
2005-09-15 00:20:14 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPlugin *
|
2005-09-18 06:59:25 +00:00
|
|
|
load_plugin (xmlTextReaderPtr reader, GList ** feature_list)
|
2005-09-15 00:20:14 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2005-09-19 14:09:54 +00:00
|
|
|
GstPlugin *plugin;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2005-09-18 06:59:25 +00:00
|
|
|
*feature_list = NULL;
|
|
|
|
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("creating new plugin and parsing");
|
2005-09-19 14:09:54 +00:00
|
|
|
|
|
|
|
plugin = g_object_new (GST_TYPE_PLUGIN, NULL);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
plugin->flags |= GST_PLUGIN_FLAG_CACHED;
|
|
|
|
while ((ret = xmlTextReaderRead (reader)) == 1) {
|
|
|
|
if (xmlTextReaderDepth (reader) == 1) {
|
|
|
|
return plugin;
|
|
|
|
}
|
|
|
|
if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
|
|
|
|
xmlTextReaderDepth (reader) == 2) {
|
|
|
|
const gchar *tag = (gchar *) xmlTextReaderConstName (reader);
|
|
|
|
|
|
|
|
if (g_str_equal (tag, "name")) {
|
|
|
|
int ret;
|
|
|
|
|
2007-10-09 14:18:39 +00:00
|
|
|
ret = read_const_interned_string (reader, &plugin->desc.name, FALSE);
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("name ret=%d, name=%s", ret, plugin->desc.name);
|
2005-09-15 00:20:14 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
} else if (g_str_equal (tag, "description")) {
|
2006-05-17 14:01:33 +00:00
|
|
|
if (!read_string (reader, &plugin->desc.description, TRUE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("description field was invalid in registry");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("description %s", plugin->desc.description);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "filename")) {
|
2006-05-17 14:01:33 +00:00
|
|
|
if (!read_string (reader, &plugin->filename, FALSE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("filename field was invalid in registry");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("filename %s", plugin->filename);
|
2005-10-08 13:57:17 +00:00
|
|
|
plugin->basename = g_path_get_basename (plugin->filename);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "version")) {
|
2007-10-09 14:18:39 +00:00
|
|
|
if (!read_const_interned_string (reader, &plugin->desc.version, TRUE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("version field was invalid in registry");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("version %s", plugin->desc.version);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "license")) {
|
2007-10-09 14:18:39 +00:00
|
|
|
if (!read_const_interned_string (reader, &plugin->desc.license, TRUE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("license field was invalid in registry");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("license %s", plugin->desc.license);
|
2005-09-23 11:41:30 +00:00
|
|
|
} else if (g_str_equal (tag, "source")) {
|
2007-10-09 14:18:39 +00:00
|
|
|
if (!read_const_interned_string (reader, &plugin->desc.source, TRUE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("source field was invalid in registry");
|
2005-09-23 11:41:30 +00:00
|
|
|
break;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("source %s", plugin->desc.source);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "package")) {
|
2007-10-09 14:18:39 +00:00
|
|
|
if (!read_const_interned_string (reader, &plugin->desc.package, TRUE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("package field was invalid in registry");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
2006-05-17 14:01:33 +00:00
|
|
|
}
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("package %s", plugin->desc.package);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "origin")) {
|
2007-10-09 14:18:39 +00:00
|
|
|
if (!read_const_interned_string (reader, &plugin->desc.origin, TRUE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("failed to read origin");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (g_str_equal (tag, "m32p")) {
|
|
|
|
char *s;
|
|
|
|
|
2006-05-17 14:01:33 +00:00
|
|
|
if (!read_string (reader, &s, FALSE)) {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("failed to read mtime");
|
2005-09-15 00:20:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
plugin->file_mtime = strtol (s, NULL, 0);
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("mtime %d", (int) plugin->file_mtime);
|
2005-09-18 21:24:55 +00:00
|
|
|
g_free (s);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else if (g_str_equal (tag, "size")) {
|
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
if (read_uint (reader, &x)) {
|
|
|
|
plugin->file_size = x;
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_LOG ("file_size %" G_GINT64_FORMAT, (gint64) plugin->file_size);
|
2005-09-15 00:20:14 +00:00
|
|
|
} else {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("failed to read size");
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
} else if (g_str_equal (tag, "feature")) {
|
|
|
|
GstPluginFeature *feature = load_feature (reader);
|
|
|
|
|
2005-09-18 06:59:25 +00:00
|
|
|
if (feature) {
|
2007-10-13 17:20:09 +00:00
|
|
|
feature->plugin_name = plugin->desc.name; /* interned string */
|
2005-09-18 06:59:25 +00:00
|
|
|
*feature_list = g_list_prepend (*feature_list, feature);
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
} else {
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("unknown tag %s", tag);
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-18 21:24:55 +00:00
|
|
|
gst_object_unref (plugin);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2007-02-09 13:41:24 +00:00
|
|
|
GST_WARNING ("problem reading plugin");
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-02 12:34:47 +00:00
|
|
|
/**
|
|
|
|
* gst_registry_xml_read_cache:
|
|
|
|
* @registry: a #GstRegistry
|
|
|
|
* @location: a filename
|
|
|
|
*
|
commit binary registry (disabled by default, see #359653)
Original commit message from CVS:
* configure.ac:
* docs/gst/gstreamer-sections.txt:
* gst/Makefile.am:
* gst/gstregistry.c: (gst_registry_lookup_feature_locked),
(gst_registry_lookup_locked):
* gst/gstregistry.h:
* gst/gstregistrybinary.c: (gst_registry_binary_write),
(gst_registry_binary_initialize_magic),
(gst_registry_binary_save_string),
(gst_registry_binary_save_pad_template),
(gst_registry_binary_save_feature),
(gst_registry_binary_save_plugin),
(gst_registry_binary_write_cache),
(gst_registry_binary_check_magic),
(gst_registry_binary_load_pad_template),
(gst_registry_binary_load_feature),
(gst_registry_binary_load_plugin),
(gst_registry_binary_read_cache):
* gst/gstregistrybinary.h:
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache):
commit binary registry (disabled by default, see #359653)
2007-01-11 13:45:51 +00:00
|
|
|
* Read the contents of the XML cache file at @location into @registry.
|
2005-12-02 12:34:47 +00:00
|
|
|
*
|
commit binary registry (disabled by default, see #359653)
Original commit message from CVS:
* configure.ac:
* docs/gst/gstreamer-sections.txt:
* gst/Makefile.am:
* gst/gstregistry.c: (gst_registry_lookup_feature_locked),
(gst_registry_lookup_locked):
* gst/gstregistry.h:
* gst/gstregistrybinary.c: (gst_registry_binary_write),
(gst_registry_binary_initialize_magic),
(gst_registry_binary_save_string),
(gst_registry_binary_save_pad_template),
(gst_registry_binary_save_feature),
(gst_registry_binary_save_plugin),
(gst_registry_binary_write_cache),
(gst_registry_binary_check_magic),
(gst_registry_binary_load_pad_template),
(gst_registry_binary_load_feature),
(gst_registry_binary_load_plugin),
(gst_registry_binary_read_cache):
* gst/gstregistrybinary.h:
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache):
commit binary registry (disabled by default, see #359653)
2007-01-11 13:45:51 +00:00
|
|
|
* Returns: %TRUE on success.
|
2005-12-02 12:34:47 +00:00
|
|
|
*/
|
2005-09-15 00:20:14 +00:00
|
|
|
gboolean
|
|
|
|
gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
|
|
|
|
{
|
2006-03-23 11:54:51 +00:00
|
|
|
GMappedFile *mapped = NULL;
|
2005-09-15 00:20:14 +00:00
|
|
|
GTimer *timer;
|
|
|
|
gdouble seconds;
|
2006-03-23 11:54:51 +00:00
|
|
|
xmlTextReaderPtr reader = NULL;
|
2005-09-15 00:20:14 +00:00
|
|
|
int ret;
|
|
|
|
gboolean in_registry = FALSE;
|
2006-03-23 11:54:51 +00:00
|
|
|
FILE *file = NULL;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
/* make sure these types exist */
|
|
|
|
GST_TYPE_ELEMENT_FACTORY;
|
|
|
|
GST_TYPE_TYPE_FIND_FACTORY;
|
|
|
|
GST_TYPE_INDEX_FACTORY;
|
|
|
|
|
|
|
|
timer = g_timer_new ();
|
|
|
|
|
2006-03-23 11:54:51 +00:00
|
|
|
mapped = g_mapped_file_new (location, FALSE, NULL);
|
|
|
|
if (mapped) {
|
|
|
|
reader = xmlReaderForMemory (g_mapped_file_get_contents (mapped),
|
|
|
|
g_mapped_file_get_length (mapped), NULL, NULL, 0);
|
|
|
|
if (reader == NULL) {
|
|
|
|
g_mapped_file_free (mapped);
|
|
|
|
mapped = NULL;
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 11:54:51 +00:00
|
|
|
if (reader == NULL) {
|
|
|
|
file = fopen (location, "r");
|
|
|
|
if (file == NULL) {
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
reader = xmlReaderForFd (fileno (file), NULL, NULL, 0);
|
|
|
|
if (!reader) {
|
|
|
|
fclose (file);
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while ((ret = xmlTextReaderRead (reader)) == 1) {
|
|
|
|
if (xmlTextReaderDepth (reader) == 0) {
|
|
|
|
in_registry = xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
|
|
|
|
g_str_equal ("GST-PluginRegistry", xmlTextReaderConstName (reader));
|
|
|
|
} else if (in_registry) {
|
|
|
|
if (xmlTextReaderDepth (reader) == 1 &&
|
|
|
|
xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT) {
|
|
|
|
const gchar *tag = (const gchar *) xmlTextReaderConstName (reader);
|
|
|
|
|
|
|
|
if (g_str_equal (tag, "plugin")) {
|
2005-09-18 06:59:25 +00:00
|
|
|
GList *feature_list;
|
|
|
|
GstPlugin *plugin = load_plugin (reader, &feature_list);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
if (plugin) {
|
2005-09-18 06:59:25 +00:00
|
|
|
GList *g;
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
gst_registry_add_plugin (registry, plugin);
|
2005-09-18 06:59:25 +00:00
|
|
|
for (g = feature_list; g; g = g_list_next (g)) {
|
gst/: Use _CAST macros to avoid unneeded type checking.
Original commit message from CVS:
* gst/gst.c: (gst_debug_help):
* gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
(gst_plugin_feature_list_free):
* gst/gstregistry.c: (gst_registry_add_plugin),
(gst_registry_add_feature), (gst_registry_plugin_filter),
(gst_registry_feature_filter), (gst_registry_find_plugin),
(gst_registry_find_feature), (gst_registry_get_plugin_list),
(gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
* gst/gstminiobject.c: (gst_mini_object_unref),
(gst_mini_object_replace), (gst_value_mini_object_free),
(gst_value_mini_object_copy):
Use _CAST macros to avoid unneeded type checking.
Added some more G_UNLIKELY.
2006-06-12 09:17:44 +00:00
|
|
|
gst_registry_add_feature (registry,
|
|
|
|
GST_PLUGIN_FEATURE_CAST (g->data));
|
2005-09-18 06:59:25 +00:00
|
|
|
}
|
|
|
|
g_list_free (feature_list);
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlFreeTextReader (reader);
|
|
|
|
if (ret != 0) {
|
|
|
|
GST_ERROR ("parsing registry cache: %s", location);
|
2006-03-23 11:54:51 +00:00
|
|
|
if (mapped)
|
|
|
|
g_mapped_file_free (mapped);
|
|
|
|
if (file)
|
|
|
|
fclose (file);
|
2005-09-15 00:20:14 +00:00
|
|
|
g_timer_destroy (timer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_timer_stop (timer);
|
|
|
|
seconds = g_timer_elapsed (timer, NULL);
|
|
|
|
g_timer_destroy (timer);
|
|
|
|
|
commit binary registry (disabled by default, see #359653)
Original commit message from CVS:
* configure.ac:
* docs/gst/gstreamer-sections.txt:
* gst/Makefile.am:
* gst/gstregistry.c: (gst_registry_lookup_feature_locked),
(gst_registry_lookup_locked):
* gst/gstregistry.h:
* gst/gstregistrybinary.c: (gst_registry_binary_write),
(gst_registry_binary_initialize_magic),
(gst_registry_binary_save_string),
(gst_registry_binary_save_pad_template),
(gst_registry_binary_save_feature),
(gst_registry_binary_save_plugin),
(gst_registry_binary_write_cache),
(gst_registry_binary_check_magic),
(gst_registry_binary_load_pad_template),
(gst_registry_binary_load_feature),
(gst_registry_binary_load_plugin),
(gst_registry_binary_read_cache):
* gst/gstregistrybinary.h:
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache):
commit binary registry (disabled by default, see #359653)
2007-01-11 13:45:51 +00:00
|
|
|
GST_INFO ("loaded %s in %lf seconds", location, seconds);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2006-03-23 11:54:51 +00:00
|
|
|
if (mapped)
|
|
|
|
g_mapped_file_free (mapped);
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
fclose (file);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save
|
|
|
|
*/
|
2006-03-08 12:57:37 +00:00
|
|
|
static gboolean
|
2007-09-19 13:28:40 +00:00
|
|
|
gst_registry_save_escaped (GstRegistry * registry, const char *prefix,
|
|
|
|
const char *tag, const char *value)
|
2006-03-08 12:57:37 +00:00
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
if (value) {
|
2006-12-26 15:06:52 +00:00
|
|
|
gchar *v;
|
|
|
|
|
|
|
|
if (g_utf8_validate (value, -1, NULL)) {
|
|
|
|
v = g_markup_escape_text (value, -1);
|
|
|
|
} else {
|
|
|
|
g_warning ("Invalid UTF-8 while saving registry tag '%s'", tag);
|
|
|
|
v = g_strdup ("[ERROR: invalid UTF-8]");
|
|
|
|
}
|
2006-03-08 12:57:37 +00:00
|
|
|
|
|
|
|
ret = gst_registry_save (registry, "%s<%s>%s</%s>\n", prefix, tag, v, tag);
|
|
|
|
g_free (v);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_registry_xml_save_caps (GstRegistry * registry, const GstCaps * caps)
|
|
|
|
{
|
2005-10-15 15:30:24 +00:00
|
|
|
/* we copy the caps here so we can simplify them before saving. This is a lot
|
2005-09-15 00:20:14 +00:00
|
|
|
* faster when loading them later on */
|
|
|
|
char *s;
|
|
|
|
GstCaps *copy = gst_caps_copy (caps);
|
2006-03-08 12:57:37 +00:00
|
|
|
gboolean ret;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
gst_caps_do_simplify (copy);
|
|
|
|
s = gst_caps_to_string (copy);
|
|
|
|
gst_caps_unref (copy);
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
ret = gst_registry_save_escaped (registry, " ", "caps", s);
|
2005-09-15 00:20:14 +00:00
|
|
|
g_free (s);
|
2006-03-08 12:57:37 +00:00
|
|
|
return ret;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_registry_xml_save_pad_template (GstRegistry * registry,
|
|
|
|
GstStaticPadTemplate * template)
|
|
|
|
{
|
|
|
|
gchar *presence;
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "nametemplate",
|
|
|
|
template->name_template))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_registry_save (registry,
|
|
|
|
" <direction>%s</direction>\n",
|
|
|
|
(template->direction == GST_PAD_SINK ? "sink" : "src")))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
switch (template->presence) {
|
|
|
|
case GST_PAD_ALWAYS:
|
|
|
|
presence = "always";
|
|
|
|
break;
|
|
|
|
case GST_PAD_SOMETIMES:
|
|
|
|
presence = "sometimes";
|
|
|
|
break;
|
|
|
|
case GST_PAD_REQUEST:
|
|
|
|
presence = "request";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
presence = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, " <presence>%s</presence>\n", presence))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
if (template->static_caps.string) {
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, " <caps>%s</caps>\n",
|
|
|
|
template->static_caps.string))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_registry_xml_save_feature (GstRegistry * registry,
|
|
|
|
GstPluginFeature * feature)
|
|
|
|
{
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "name", feature->name))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
if (feature->rank > 0) {
|
|
|
|
gint rank = feature->rank;
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, " <rank>%d</rank>\n", rank))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_IS_ELEMENT_FACTORY (feature)) {
|
|
|
|
GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
|
|
|
|
GList *walk;
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "longname",
|
|
|
|
factory->details.longname))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "class",
|
|
|
|
factory->details.klass))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "description",
|
|
|
|
factory->details.description))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "author",
|
|
|
|
factory->details.author))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
walk = factory->staticpadtemplates;
|
|
|
|
|
|
|
|
while (walk) {
|
|
|
|
GstStaticPadTemplate *template = walk->data;
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, " <padtemplate>\n"))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_xml_save_pad_template (registry, template))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save (registry, " </padtemplate>\n"))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
walk = g_list_next (walk);
|
|
|
|
}
|
|
|
|
|
|
|
|
walk = factory->interfaces;
|
|
|
|
while (walk) {
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "interface",
|
|
|
|
(gchar *) walk->data))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
walk = g_list_next (walk);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_URI_TYPE_IS_VALID (factory->uri_type)) {
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "uri_type",
|
|
|
|
factory->uri_type == GST_URI_SINK ? "sink" : "source"))
|
|
|
|
return FALSE;
|
2006-09-03 11:06:52 +00:00
|
|
|
if (factory->uri_protocols) {
|
|
|
|
gchar **protocol;
|
|
|
|
|
|
|
|
protocol = factory->uri_protocols;
|
|
|
|
while (*protocol) {
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "uri_protocol",
|
|
|
|
*protocol))
|
|
|
|
return FALSE;
|
|
|
|
protocol++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g_warning ("GStreamer feature '%s' is URI handler but does not provide"
|
|
|
|
" any protocols it can handle", feature->name);
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (GST_IS_TYPE_FIND_FACTORY (feature)) {
|
|
|
|
GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (feature);
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
if (factory->caps) {
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_xml_save_caps (registry, factory->caps))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
if (factory->extensions) {
|
|
|
|
while (factory->extensions[i]) {
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "extension",
|
|
|
|
factory->extensions[i]))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (GST_IS_INDEX_FACTORY (feature)) {
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "longdesc",
|
|
|
|
GST_INDEX_FACTORY (feature)->longdesc))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_registry_xml_save_plugin (GstRegistry * registry, GstPlugin * plugin)
|
|
|
|
{
|
2005-09-18 06:59:25 +00:00
|
|
|
GList *list;
|
2005-09-15 00:20:14 +00:00
|
|
|
GList *walk;
|
|
|
|
char s[100];
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "name", plugin->desc.name))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "description",
|
|
|
|
plugin->desc.description))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "filename", plugin->filename))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
sprintf (s, "%d", (int) plugin->file_size);
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "size", s))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
sprintf (s, "%d", (int) plugin->file_mtime);
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save_escaped (registry, " ", "m32p", s))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "version",
|
|
|
|
plugin->desc.version))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "license",
|
|
|
|
plugin->desc.license))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "source", plugin->desc.source))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "package",
|
|
|
|
plugin->desc.package))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_registry_save_escaped (registry, " ", "origin", plugin->desc.origin))
|
|
|
|
return FALSE;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2005-09-18 06:59:25 +00:00
|
|
|
list = gst_registry_get_feature_list_by_plugin (registry, plugin->desc.name);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2005-09-18 06:59:25 +00:00
|
|
|
for (walk = list; walk; walk = g_list_next (walk)) {
|
2005-09-15 00:20:14 +00:00
|
|
|
GstPluginFeature *feature = GST_PLUGIN_FEATURE (walk->data);
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry,
|
|
|
|
" <feature typename=\"%s\">\n",
|
|
|
|
g_type_name (G_OBJECT_TYPE (feature))))
|
|
|
|
goto fail;
|
|
|
|
if (!gst_registry_xml_save_feature (registry, feature))
|
|
|
|
goto fail;
|
|
|
|
if (!gst_registry_save (registry, " </feature>\n"))
|
|
|
|
goto fail;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
2005-09-18 06:59:25 +00:00
|
|
|
|
|
|
|
gst_plugin_feature_list_free (list);
|
2005-09-15 00:20:14 +00:00
|
|
|
return TRUE;
|
2006-03-08 12:57:37 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
gst_plugin_feature_list_free (list);
|
|
|
|
return FALSE;
|
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
2005-12-02 12:34:47 +00:00
|
|
|
/**
|
|
|
|
* gst_registry_xml_write_cache:
|
|
|
|
* @registry: a #GstRegistry
|
|
|
|
* @location: a filename
|
|
|
|
*
|
|
|
|
* Write @registry in an XML format at the location given by
|
|
|
|
* @location. Directories are automatically created.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
|
|
|
*/
|
2005-09-15 00:20:14 +00:00
|
|
|
gboolean
|
|
|
|
gst_registry_xml_write_cache (GstRegistry * registry, const char *location)
|
|
|
|
{
|
|
|
|
GList *walk;
|
|
|
|
char *tmp_location;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_REGISTRY (registry), FALSE);
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
tmp_location = g_strconcat (location, ".tmpXXXXXX", NULL);
|
|
|
|
registry->cache_file = g_mkstemp (tmp_location);
|
|
|
|
if (registry->cache_file == -1) {
|
2005-09-15 00:20:14 +00:00
|
|
|
char *dir;
|
|
|
|
|
|
|
|
/* oops, I bet the directory doesn't exist */
|
|
|
|
dir = g_path_get_dirname (location);
|
2005-09-15 01:10:52 +00:00
|
|
|
g_mkdir_with_parents (dir, 0777);
|
2005-09-15 00:20:14 +00:00
|
|
|
g_free (dir);
|
|
|
|
|
2006-06-13 13:30:46 +00:00
|
|
|
/* the previous g_mkstemp call overwrote the XXXXXX placeholder ... */
|
2006-03-08 12:57:37 +00:00
|
|
|
g_free (tmp_location);
|
2006-06-13 13:30:46 +00:00
|
|
|
tmp_location = g_strconcat (location, ".tmpXXXXXX", NULL);
|
|
|
|
registry->cache_file = g_mkstemp (tmp_location);
|
|
|
|
|
|
|
|
if (registry->cache_file == -1) {
|
|
|
|
GST_DEBUG ("g_mkstemp() failed: %s", g_strerror (errno));
|
|
|
|
g_free (tmp_location);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, "<?xml version=\"1.0\"?>\n"))
|
|
|
|
goto fail;
|
|
|
|
if (!gst_registry_save (registry, "<GST-PluginRegistry>\n"))
|
|
|
|
goto fail;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
for (walk = g_list_last (registry->plugins); walk;
|
|
|
|
walk = g_list_previous (walk)) {
|
gst/: Use _CAST macros to avoid unneeded type checking.
Original commit message from CVS:
* gst/gst.c: (gst_debug_help):
* gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
(gst_plugin_feature_list_free):
* gst/gstregistry.c: (gst_registry_add_plugin),
(gst_registry_add_feature), (gst_registry_plugin_filter),
(gst_registry_feature_filter), (gst_registry_find_plugin),
(gst_registry_find_feature), (gst_registry_get_plugin_list),
(gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
* gst/gstminiobject.c: (gst_mini_object_unref),
(gst_mini_object_replace), (gst_value_mini_object_free),
(gst_value_mini_object_copy):
Use _CAST macros to avoid unneeded type checking.
Added some more G_UNLIKELY.
2006-06-12 09:17:44 +00:00
|
|
|
GstPlugin *plugin = GST_PLUGIN_CAST (walk->data);
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
if (!plugin->filename)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (plugin->flags & GST_PLUGIN_FLAG_CACHED) {
|
|
|
|
int ret;
|
|
|
|
struct stat statbuf;
|
|
|
|
|
|
|
|
ret = g_stat (plugin->filename, &statbuf);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
if (plugin->file_mtime != statbuf.st_mtime ||
|
|
|
|
plugin->file_size != statbuf.st_size) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, "<plugin>\n"))
|
|
|
|
goto fail;
|
|
|
|
if (!gst_registry_xml_save_plugin (registry, plugin))
|
|
|
|
goto fail;
|
|
|
|
if (!gst_registry_save (registry, "</plugin>\n"))
|
|
|
|
goto fail;
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
2006-03-08 12:57:37 +00:00
|
|
|
if (!gst_registry_save (registry, "</GST-PluginRegistry>\n"))
|
|
|
|
goto fail;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
2007-12-16 18:29:25 +00:00
|
|
|
/* check return value of close(), write errors may only get reported here */
|
|
|
|
if (close (registry->cache_file) < 0)
|
|
|
|
goto close_failed;
|
2005-09-15 00:20:14 +00:00
|
|
|
|
|
|
|
if (g_file_test (tmp_location, G_FILE_TEST_EXISTS)) {
|
|
|
|
#ifdef WIN32
|
2006-05-17 13:40:20 +00:00
|
|
|
g_remove (location);
|
2005-09-15 00:20:14 +00:00
|
|
|
#endif
|
2007-12-16 18:29:25 +00:00
|
|
|
if (g_rename (tmp_location, location) < 0)
|
|
|
|
goto rename_failed;
|
|
|
|
} else {
|
|
|
|
/* FIXME: shouldn't we return FALSE here? */
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|
2006-03-08 12:57:37 +00:00
|
|
|
|
2005-09-15 00:20:14 +00:00
|
|
|
g_free (tmp_location);
|
2007-12-16 18:29:25 +00:00
|
|
|
GST_INFO ("Wrote XML registry cache");
|
2005-09-15 00:20:14 +00:00
|
|
|
return TRUE;
|
2006-03-08 12:57:37 +00:00
|
|
|
|
2007-12-16 18:29:25 +00:00
|
|
|
/* ERRORS */
|
2006-03-08 12:57:37 +00:00
|
|
|
fail:
|
2007-12-16 18:29:25 +00:00
|
|
|
{
|
|
|
|
(void) close (registry->cache_file);
|
|
|
|
/* fall through */
|
|
|
|
}
|
|
|
|
fail_after_close:
|
|
|
|
{
|
|
|
|
g_remove (tmp_location);
|
|
|
|
g_free (tmp_location);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
close_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("close() failed: %s", g_strerror (errno));
|
|
|
|
goto fail_after_close;
|
|
|
|
}
|
|
|
|
rename_failed:
|
|
|
|
{
|
|
|
|
GST_ERROR ("g_rename() failed: %s", g_strerror (errno));
|
|
|
|
goto fail_after_close;
|
|
|
|
}
|
2005-09-15 00:20:14 +00:00
|
|
|
}
|