2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstxml.c: XML save/restore of pipelines
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "gst_private.h"
28 static void gst_xml_class_init (GstXMLClass *klass);
29 static void gst_xml_init (GstXML *xml);
31 static GstObjectClass *parent_class = NULL;
34 gst_xml_get_type(void)
36 static GtkType xml_type = 0;
39 static const GtkTypeInfo xml_info = {
42 sizeof(GstElementClass),
43 (GtkClassInitFunc)gst_xml_class_init,
44 (GtkObjectInitFunc)gst_xml_init,
47 (GtkClassInitFunc)NULL,
49 xml_type = gtk_type_unique (GST_TYPE_XML, &xml_info);
55 gst_xml_class_init (GstXMLClass *klass)
57 parent_class = gtk_type_class (GST_TYPE_OBJECT);
61 gst_xml_init(GstXML *xml)
67 * @element: The element to write out
69 * converts the given element into an XML presentation
71 * Returns: a pointer to an XML document
74 gst_xml_write (GstElement *element)
78 doc = xmlNewDoc ("1.0");
79 doc->root = xmlNewDocNode (doc, NULL, "GST-Pipeline", NULL);
81 gst_element_save_thyself (element, doc->root);
88 * @fname: The filename with the xml description
89 * @root: The name of the root object to build
91 * Creates a new GstXML object (and the corresponding elements) from
92 * the XML file fname. Optionally it will only build the element from
93 * the element node root (if it is not NULL). This feature is useful
94 * if you only want to build a specific element from an XML file
95 * but not the pipeline it is embedded in. Note also that the XML parse
96 * tree is cached to speed up creating another GstXML object for
99 * Returns: a pointer to a new GstElement
102 gst_xml_new (const guchar *fname, const guchar *root)
108 g_return_val_if_fail(fname != NULL, NULL);
110 doc = xmlParseFile(fname);
113 g_print("gstxml: XML file \"%s\" could not be read\n", fname);
116 if (strcmp(doc->root->name, "GST-Pipeline")) {
117 g_print("gstxml: XML file \"%s\" is in wrong format\n", fname);
121 xml = GST_XML(gtk_type_new(GST_TYPE_XML));
123 xml->topelements = NULL;
125 field = doc->root->childs;
128 if (!strcmp(field->name, "element")) {
131 xml->elements = g_hash_table_new(g_str_hash, g_str_equal);
133 element = gst_element_load_thyself(field, xml->elements);
135 g_hash_table_destroy (xml->elements);
137 xml->topelements = g_list_prepend (xml->topelements, element);
142 xml->topelements = g_list_reverse (xml->topelements);
148 * gst_xml_get_topelements:
149 * @xml: The GstXML to get the elements from
151 * retrive a list of toplevel elements
153 * Returns: a GList of elements
156 gst_xml_get_topelements (GstXML *xml)
158 g_return_val_if_fail (xml != NULL, NULL);
160 return xml->topelements;
164 * gst_xml_get_element:
165 * @xml: The GstXML to get the element from
166 * @name: The name of element to retreive
168 * This function is used to get a pointer to the GstElement corresponding
169 * to name in the pipeline description. You would use this if you have
170 * to do anything to the element after loading.
172 * Returns: a pointer to a new GstElement
175 gst_xml_get_element (GstXML *xml, const guchar *name)
179 g_return_val_if_fail(xml != NULL, NULL);
180 g_return_val_if_fail(name != NULL, NULL);
182 GST_DEBUG (0,"gstxml: getting element \"%s\"\n", name);
184 element = g_hash_table_lookup(xml->elements, name);