2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstxml.c: XML save/restore of pipelines
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under 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.
|
|
|
|
*/
|
|
|
|
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstxml.h"
|
2001-01-08 22:08:40 +00:00
|
|
|
#include "gstbin.h"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
enum {
|
|
|
|
OBJECT_LOADED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
static void gst_xml_class_init (GstXMLClass *klass);
|
2000-12-16 17:12:28 +00:00
|
|
|
static void gst_xml_init (GstXML *xml);
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2001-01-30 23:53:04 +00:00
|
|
|
static void gst_xml_object_loaded (GstObject *private, GstObject *object, xmlNodePtr self, gpointer data);
|
|
|
|
|
2000-09-24 22:45:48 +00:00
|
|
|
static GstObjectClass *parent_class = NULL;
|
2001-01-29 00:06:02 +00:00
|
|
|
static guint gst_xml_signals[LAST_SIGNAL] = { 0 };
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
GtkType
|
|
|
|
gst_xml_get_type(void)
|
2000-12-25 01:33:06 +00:00
|
|
|
{
|
2000-09-24 22:45:48 +00:00
|
|
|
static GtkType xml_type = 0;
|
|
|
|
|
|
|
|
if (!xml_type) {
|
|
|
|
static const GtkTypeInfo xml_info = {
|
|
|
|
"GstXML",
|
2001-01-29 00:06:02 +00:00
|
|
|
sizeof(GstXML),
|
|
|
|
sizeof(GstXMLClass),
|
2000-09-24 22:45:48 +00:00
|
|
|
(GtkClassInitFunc)gst_xml_class_init,
|
|
|
|
(GtkObjectInitFunc)gst_xml_init,
|
|
|
|
(GtkArgSetFunc)NULL,
|
|
|
|
(GtkArgGetFunc)NULL,
|
|
|
|
(GtkClassInitFunc)NULL,
|
|
|
|
};
|
2001-01-29 00:06:02 +00:00
|
|
|
xml_type = gtk_type_unique (GST_TYPE_OBJECT, &xml_info);
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
return xml_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-01-21 23:20:46 +00:00
|
|
|
gst_xml_class_init (GstXMLClass *klass)
|
2000-12-25 01:33:06 +00:00
|
|
|
{
|
2001-01-29 00:06:02 +00:00
|
|
|
GtkObjectClass *gtkobject_class;
|
|
|
|
|
|
|
|
gtkobject_class = (GtkObjectClass *)klass;
|
|
|
|
|
2000-12-25 01:33:06 +00:00
|
|
|
parent_class = gtk_type_class (GST_TYPE_OBJECT);
|
2001-01-29 00:06:02 +00:00
|
|
|
|
|
|
|
gst_xml_signals[OBJECT_LOADED] =
|
|
|
|
gtk_signal_new ("object_loaded", GTK_RUN_LAST, gtkobject_class->type,
|
|
|
|
GTK_SIGNAL_OFFSET (GstXMLClass, object_loaded),
|
|
|
|
gtk_marshal_NONE__POINTER_POINTER, GTK_TYPE_NONE, 2,
|
|
|
|
GST_TYPE_OBJECT, GTK_TYPE_POINTER);
|
|
|
|
|
|
|
|
gtk_object_class_add_signals (gtkobject_class, gst_xml_signals, LAST_SIGNAL);
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
static void
|
|
|
|
gst_xml_init(GstXML *xml)
|
2000-12-25 01:33:06 +00:00
|
|
|
{
|
2001-01-29 00:06:02 +00:00
|
|
|
xml->topelements = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_xml_new:
|
|
|
|
*
|
|
|
|
* Create a new GstXML parser object.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to a new GstXML object.
|
|
|
|
*/
|
|
|
|
GstXML*
|
|
|
|
gst_xml_new (void)
|
|
|
|
{
|
|
|
|
return GST_XML (gtk_type_new (GST_TYPE_XML));
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2000-03-27 19:53:43 +00:00
|
|
|
/**
|
|
|
|
* gst_xml_write:
|
|
|
|
* @element: The element to write out
|
|
|
|
*
|
2001-01-10 09:15:00 +00:00
|
|
|
* Converts the given element into an XML presentation.
|
2000-03-27 19:53:43 +00:00
|
|
|
*
|
|
|
|
* Returns: a pointer to an XML document
|
|
|
|
*/
|
2001-01-21 23:20:46 +00:00
|
|
|
xmlDocPtr
|
|
|
|
gst_xml_write (GstElement *element)
|
2000-12-25 01:33:06 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
xmlDocPtr doc;
|
2001-01-29 00:06:02 +00:00
|
|
|
xmlNodePtr elementnode;
|
|
|
|
xmlNsPtr ns;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-12-25 01:33:06 +00:00
|
|
|
doc = xmlNewDoc ("1.0");
|
2001-01-29 00:06:02 +00:00
|
|
|
xmlNewGlobalNs (doc, "http://gstreamer.net/gst-core/1.0/", "gst");
|
|
|
|
ns = xmlNewNs (doc->xmlRootNode, "http://gstreamer.net/gst-core/1.0/", "gst");
|
|
|
|
|
2001-01-29 23:50:29 +00:00
|
|
|
doc->xmlRootNode = xmlNewDocNode (doc, ns, "gstreamer", NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-01-30 23:53:04 +00:00
|
|
|
elementnode = xmlNewChild (doc->xmlRootNode, ns, "element", NULL);
|
2001-01-29 00:06:02 +00:00
|
|
|
|
|
|
|
gst_object_save_thyself (GST_OBJECT (element), elementnode);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2001-01-31 20:27:00 +00:00
|
|
|
/**
|
|
|
|
* gst_xml_parse_doc:
|
|
|
|
* @xml: a pointer to a GstXML object
|
|
|
|
* @doc: a pointer to an xml document to parse
|
|
|
|
* @root: The name of the root object to build
|
|
|
|
*
|
|
|
|
* Fills the GstXML object with the elements from the
|
|
|
|
* xmlDocPtr.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success, FALSE otherwise
|
|
|
|
*/
|
2001-01-30 23:53:04 +00:00
|
|
|
gboolean
|
|
|
|
gst_xml_parse_doc (GstXML *xml, xmlDocPtr doc, const guchar *root)
|
2000-12-16 17:12:28 +00:00
|
|
|
{
|
2001-01-29 00:06:02 +00:00
|
|
|
xmlNodePtr field, cur;
|
|
|
|
xmlNsPtr ns;
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
cur = xmlDocGetRootElement(doc);
|
|
|
|
if (cur == NULL) {
|
|
|
|
g_warning("gstxml: empty document\n");
|
|
|
|
return FALSE ;
|
|
|
|
}
|
|
|
|
ns = xmlSearchNsByHref(doc, cur, "http://gstreamer.net/gst-core/1.0/");
|
|
|
|
if (ns == NULL) {
|
|
|
|
g_warning("gstxml: document of wrong type, core namespace not found\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-01-29 23:50:29 +00:00
|
|
|
if (strcmp(cur->name, "gstreamer")) {
|
2001-01-21 23:20:46 +00:00
|
|
|
g_warning("gstxml: XML file is in wrong format\n");
|
2001-01-29 00:06:02 +00:00
|
|
|
return FALSE;
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-30 23:53:04 +00:00
|
|
|
gst_class_signal_connect (GST_OBJECT_CLASS (GTK_OBJECT (xml)->klass),
|
|
|
|
"object_loaded", gst_xml_object_loaded, xml);
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
xml->ns = ns;
|
2000-09-27 19:33:10 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
field = cur->xmlChildrenNode;
|
2001-01-21 23:20:46 +00:00
|
|
|
|
2000-09-27 19:33:10 +00:00
|
|
|
while (field) {
|
2001-01-29 00:06:02 +00:00
|
|
|
if (!strcmp(field->name, "element") && (field->ns == xml->ns)) {
|
2000-12-16 17:12:28 +00:00
|
|
|
GstElement *element;
|
2001-01-21 23:20:46 +00:00
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
element = gst_element_load_thyself(field, NULL);
|
2000-12-16 17:12:28 +00:00
|
|
|
|
|
|
|
xml->topelements = g_list_prepend (xml->topelements, element);
|
2000-09-27 19:33:10 +00:00
|
|
|
}
|
|
|
|
field = field->next;
|
|
|
|
}
|
|
|
|
|
2000-12-16 17:12:28 +00:00
|
|
|
xml->topelements = g_list_reverse (xml->topelements);
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
return TRUE;
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
/**
|
2001-01-29 00:06:02 +00:00
|
|
|
* gst_xml_parse_file:
|
2001-01-31 20:27:00 +00:00
|
|
|
* @xml: a pointer to a GstXML object
|
2001-01-21 23:20:46 +00:00
|
|
|
* @fname: The filename with the xml description
|
|
|
|
* @root: The name of the root object to build
|
|
|
|
*
|
2001-01-31 20:27:00 +00:00
|
|
|
* Fills the GstXML object with the corresponding elements from
|
2001-01-21 23:20:46 +00:00
|
|
|
* the XML file fname. Optionally it will only build the element from
|
|
|
|
* the element node root (if it is not NULL). This feature is useful
|
|
|
|
* if you only want to build a specific element from an XML file
|
2001-01-31 20:27:00 +00:00
|
|
|
* but not the pipeline it is embedded in.
|
2001-01-21 23:20:46 +00:00
|
|
|
*
|
2001-01-29 00:06:02 +00:00
|
|
|
* Returns: TRUE on success, FALSE otherwise
|
2001-01-21 23:20:46 +00:00
|
|
|
*/
|
2001-01-29 00:06:02 +00:00
|
|
|
gboolean
|
|
|
|
gst_xml_parse_file (GstXML *xml, const guchar *fname, const guchar *root)
|
2001-01-21 23:20:46 +00:00
|
|
|
{
|
|
|
|
xmlDocPtr doc;
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
g_return_val_if_fail(fname != NULL, FALSE);
|
2001-01-21 23:20:46 +00:00
|
|
|
|
|
|
|
doc = xmlParseFile(fname);
|
|
|
|
|
|
|
|
if (!doc) {
|
|
|
|
g_warning("gstxml: XML file \"%s\" could not be read\n", fname);
|
2001-01-29 00:06:02 +00:00
|
|
|
return FALSE;
|
2001-01-21 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2001-01-30 23:53:04 +00:00
|
|
|
return gst_xml_parse_doc (xml, doc, root);
|
2001-01-21 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-01-29 00:06:02 +00:00
|
|
|
* gst_xml_parse_memory:
|
2001-01-31 20:27:00 +00:00
|
|
|
* @xml: a pointer to a GstXML object
|
2001-01-21 23:20:46 +00:00
|
|
|
* @buffer: a pointer to the in memory XML buffer
|
|
|
|
* @size: the size of the buffer
|
|
|
|
* @root: the name of the root objects to build
|
|
|
|
*
|
2001-01-31 20:27:00 +00:00
|
|
|
* Fills the GstXML object with the corresponding elements from
|
2001-01-21 23:20:46 +00:00
|
|
|
* an in memory XML buffer.
|
|
|
|
*
|
2001-01-31 20:27:00 +00:00
|
|
|
* Returns: TRUE on success
|
2001-01-21 23:20:46 +00:00
|
|
|
*/
|
2001-01-29 00:06:02 +00:00
|
|
|
gboolean
|
|
|
|
gst_xml_parse_memory (GstXML *xml, guchar *buffer, guint size, const gchar *root)
|
2001-01-21 23:20:46 +00:00
|
|
|
{
|
|
|
|
xmlDocPtr doc;
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
g_return_val_if_fail(buffer != NULL, FALSE);
|
2001-01-21 23:20:46 +00:00
|
|
|
|
|
|
|
doc = xmlParseMemory (buffer, size);
|
|
|
|
|
2001-01-30 23:53:04 +00:00
|
|
|
return gst_xml_parse_doc (xml, doc, root);
|
2001-01-29 00:06:02 +00:00
|
|
|
}
|
|
|
|
|
2001-01-30 23:53:04 +00:00
|
|
|
static void
|
|
|
|
gst_xml_object_loaded (GstObject *private, GstObject *object, xmlNodePtr self, gpointer data)
|
2001-01-29 00:06:02 +00:00
|
|
|
{
|
2001-01-30 23:53:04 +00:00
|
|
|
GstXML *xml = GST_XML (data);
|
|
|
|
|
|
|
|
// FIXME check that this element was created from the same xmlDocPtr...
|
2001-01-29 00:06:02 +00:00
|
|
|
gtk_signal_emit (GTK_OBJECT (xml), gst_xml_signals[OBJECT_LOADED], object, self);
|
2001-01-21 23:20:46 +00:00
|
|
|
}
|
|
|
|
|
2000-12-16 17:12:28 +00:00
|
|
|
/**
|
|
|
|
* gst_xml_get_topelements:
|
|
|
|
* @xml: The GstXML to get the elements from
|
|
|
|
*
|
2001-01-10 09:15:00 +00:00
|
|
|
* Retrive a list of toplevel elements.
|
2000-12-16 17:12:28 +00:00
|
|
|
*
|
|
|
|
* Returns: a GList of elements
|
|
|
|
*/
|
|
|
|
GList*
|
2001-01-21 23:20:46 +00:00
|
|
|
gst_xml_get_topelements (GstXML *xml)
|
2000-12-16 17:12:28 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (xml != NULL, NULL);
|
|
|
|
|
|
|
|
return xml->topelements;
|
|
|
|
}
|
|
|
|
|
2000-09-24 22:45:48 +00:00
|
|
|
/**
|
|
|
|
* gst_xml_get_element:
|
|
|
|
* @xml: The GstXML to get the element from
|
|
|
|
* @name: The name of element to retreive
|
|
|
|
*
|
2001-01-21 23:20:46 +00:00
|
|
|
* This function is used to get a pointer to the GstElement corresponding
|
|
|
|
* to name in the pipeline description. You would use this if you have
|
2000-09-24 22:45:48 +00:00
|
|
|
* to do anything to the element after loading.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to a new GstElement
|
|
|
|
*/
|
2000-12-16 17:12:28 +00:00
|
|
|
GstElement*
|
2001-01-21 23:20:46 +00:00
|
|
|
gst_xml_get_element (GstXML *xml, const guchar *name)
|
2000-12-16 17:12:28 +00:00
|
|
|
{
|
2000-09-27 19:33:10 +00:00
|
|
|
GstElement *element;
|
2001-01-08 22:08:40 +00:00
|
|
|
GList *topelements;
|
2000-09-24 22:45:48 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(xml != NULL, NULL);
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
2001-01-01 03:14:40 +00:00
|
|
|
GST_DEBUG (0,"gstxml: getting element \"%s\"\n", name);
|
2000-09-27 19:33:10 +00:00
|
|
|
|
2001-01-08 22:08:40 +00:00
|
|
|
topelements = gst_xml_get_topelements (xml);
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2001-01-08 22:08:40 +00:00
|
|
|
while (topelements) {
|
|
|
|
GstElement *top = GST_ELEMENT (topelements->data);
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
GST_DEBUG (0,"gstxml: getting element \"%s\"\n", name);
|
|
|
|
if (!strcmp (GST_ELEMENT_NAME (top), name)) {
|
2001-01-08 22:08:40 +00:00
|
|
|
return top;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (GST_IS_BIN (top)) {
|
|
|
|
element = gst_bin_get_by_name (GST_BIN (top), name);
|
|
|
|
|
2001-01-21 23:20:46 +00:00
|
|
|
if (element)
|
2001-01-08 22:08:40 +00:00
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
topelements = g_list_next (topelements);
|
|
|
|
}
|
|
|
|
return NULL;
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|