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"
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-12-28 22:12:02 +00:00
|
|
|
|
2000-12-16 17:12:28 +00:00
|
|
|
static void gst_xml_class_init (GstXMLClass *klass);
|
|
|
|
static void gst_xml_init (GstXML *xml);
|
2000-09-24 22:45:48 +00:00
|
|
|
|
|
|
|
static GstObjectClass *parent_class = NULL;
|
|
|
|
|
2000-12-25 01:33:06 +00:00
|
|
|
GtkType
|
|
|
|
gst_xml_get_type(void)
|
|
|
|
{
|
2000-09-24 22:45:48 +00:00
|
|
|
static GtkType xml_type = 0;
|
|
|
|
|
|
|
|
if (!xml_type) {
|
|
|
|
static const GtkTypeInfo xml_info = {
|
|
|
|
"GstXML",
|
|
|
|
sizeof(GstElement),
|
|
|
|
sizeof(GstElementClass),
|
|
|
|
(GtkClassInitFunc)gst_xml_class_init,
|
|
|
|
(GtkObjectInitFunc)gst_xml_init,
|
|
|
|
(GtkArgSetFunc)NULL,
|
|
|
|
(GtkArgGetFunc)NULL,
|
|
|
|
(GtkClassInitFunc)NULL,
|
|
|
|
};
|
2000-12-25 01:33:06 +00:00
|
|
|
xml_type = gtk_type_unique (GST_TYPE_XML, &xml_info);
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
return xml_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-12-25 01:33:06 +00:00
|
|
|
gst_xml_class_init (GstXMLClass *klass)
|
|
|
|
{
|
|
|
|
parent_class = gtk_type_class (GST_TYPE_OBJECT);
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2000-12-25 01:33:06 +00:00
|
|
|
static void
|
|
|
|
gst_xml_init(GstXML *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
|
|
|
|
*
|
2000-09-24 22:45:48 +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
|
|
|
|
*/
|
2000-12-25 01:33:06 +00:00
|
|
|
xmlDocPtr
|
|
|
|
gst_xml_write (GstElement *element)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
xmlDocPtr doc;
|
|
|
|
|
2000-12-25 01:33:06 +00:00
|
|
|
doc = xmlNewDoc ("1.0");
|
|
|
|
doc->root = xmlNewDocNode (doc, NULL, "GST-Pipeline", NULL);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-12-25 01:33:06 +00:00
|
|
|
gst_element_save_thyself (element, doc->root);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
2000-09-24 22:45:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_xml_new:
|
|
|
|
* @fname: The filename with the xml description
|
|
|
|
* @root: The name of the root object to build
|
|
|
|
*
|
|
|
|
* Creates a new GstXML object (and the corresponding elements) from
|
|
|
|
* 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
|
|
|
|
* but not the pipeline it is embedded in. Note also that the XML parse
|
|
|
|
* tree is cached to speed up creating another GstXML object for
|
|
|
|
* the same file
|
|
|
|
*
|
|
|
|
* Returns: a pointer to a new GstElement
|
|
|
|
*/
|
2000-12-16 17:12:28 +00:00
|
|
|
GstXML*
|
|
|
|
gst_xml_new (const guchar *fname, const guchar *root)
|
|
|
|
{
|
2000-09-24 22:45:48 +00:00
|
|
|
xmlDocPtr doc;
|
2000-09-27 19:33:10 +00:00
|
|
|
xmlNodePtr field;
|
2000-09-24 22:45:48 +00:00
|
|
|
GstXML *xml;
|
|
|
|
|
|
|
|
g_return_val_if_fail(fname != NULL, NULL);
|
|
|
|
|
|
|
|
doc = xmlParseFile(fname);
|
|
|
|
|
|
|
|
if (!doc) {
|
|
|
|
g_print("gstxml: XML file \"%s\" could not be read\n", fname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (strcmp(doc->root->name, "GST-Pipeline")) {
|
|
|
|
g_print("gstxml: XML file \"%s\" is in wrong format\n", fname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xml = GST_XML(gtk_type_new(GST_TYPE_XML));
|
|
|
|
|
2000-12-16 17:12:28 +00:00
|
|
|
xml->topelements = NULL;
|
2000-09-27 19:33:10 +00:00
|
|
|
|
|
|
|
field = doc->root->childs;
|
|
|
|
|
|
|
|
while (field) {
|
|
|
|
if (!strcmp(field->name, "element")) {
|
2000-12-16 17:12:28 +00:00
|
|
|
GstElement *element;
|
|
|
|
|
2000-12-22 16:14:33 +00:00
|
|
|
xml->elements = g_hash_table_new(g_str_hash, g_str_equal);
|
|
|
|
|
2000-12-16 17:12:28 +00:00
|
|
|
element = gst_element_load_thyself(field, xml->elements);
|
2000-12-22 16:14:33 +00:00
|
|
|
|
|
|
|
g_hash_table_destroy (xml->elements);
|
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);
|
|
|
|
|
2000-09-24 22:45:48 +00:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
2000-12-16 17:12:28 +00:00
|
|
|
/**
|
|
|
|
* gst_xml_get_topelements:
|
|
|
|
* @xml: The GstXML to get the elements from
|
|
|
|
*
|
|
|
|
* retrive a list of toplevel elements
|
|
|
|
*
|
|
|
|
* Returns: a GList of elements
|
|
|
|
*/
|
|
|
|
GList*
|
|
|
|
gst_xml_get_topelements (GstXML *xml)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
*
|
2000-10-25 19:09:53 +00:00
|
|
|
* This function is used to get a pointer to the GstElement corresponding
|
2000-09-24 22:45:48 +00:00
|
|
|
* to name in the pipeline description. You would use this if you have
|
|
|
|
* to do anything to the element after loading.
|
|
|
|
*
|
|
|
|
* Returns: a pointer to a new GstElement
|
|
|
|
*/
|
2000-12-16 17:12:28 +00:00
|
|
|
GstElement*
|
|
|
|
gst_xml_get_element (GstXML *xml, const guchar *name)
|
|
|
|
{
|
2000-09-27 19:33:10 +00:00
|
|
|
GstElement *element;
|
2000-09-24 22:45:48 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail(xml != NULL, NULL);
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
|
|
|
|
2000-12-22 16:14:33 +00:00
|
|
|
DEBUG ("gstxml: getting element \"%s\"\n", name);
|
2000-09-27 19:33:10 +00:00
|
|
|
|
|
|
|
element = g_hash_table_lookup(xml->elements, name);
|
2000-09-24 22:45:48 +00:00
|
|
|
|
2000-09-27 19:33:10 +00:00
|
|
|
return element;
|
2000-09-24 22:45:48 +00:00
|
|
|
}
|