2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstcaps.c: Element capabilities subsystem
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 //#define GST_DEBUG_ENABLED
24 #include "gst_private.h"
29 #include "gstpropsprivate.h"
33 _gst_caps_initialize (void)
38 get_type_for_mime (gchar *mime)
42 typeid = gst_type_find_by_mime (mime);
44 GstTypeFactory *factory = g_new0 (GstTypeFactory, 1);
46 factory->mime = g_strdup (mime);
48 factory->typefindfunc = NULL;
50 typeid = gst_type_register (factory);
57 * @mime: the mime type to attach to the capability
59 * create a new capability with the given mime type
61 * Returns: a new capability
64 gst_caps_new (gchar *mime)
68 g_return_val_if_fail (mime != NULL, NULL);
70 caps = g_new0 (GstCaps, 1);
71 caps->id = get_type_for_mime (mime);
72 caps->properties = NULL;
78 * gst_caps_new_with_props:
79 * @mime: the mime type to attach to the capability
80 * @props: the properties for this capability
82 * create a new capability with the given mime type
83 * and the given properties
85 * Returns: a new capability
88 gst_caps_new_with_props (gchar *mime, GstProps *props)
92 caps = gst_caps_new (mime);
93 caps->properties = props;
100 * @factory: the factory to register
102 * Register the factory.
104 * Returns: The registered capability
107 gst_caps_register (GstCapsFactory *factory)
109 GstCapsFactoryEntry tag;
114 g_return_val_if_fail (factory != NULL, NULL);
116 tag = (*factory)[i++];
118 g_return_val_if_fail (tag != NULL, NULL);
120 typeid = get_type_for_mime ((gchar *)tag);
122 caps = g_new0 (GstCaps, 1);
123 g_return_val_if_fail (caps != NULL, NULL);
126 caps->properties = gst_props_register (&(*factory)[i]);
132 * gst_caps_set_props:
133 * @caps: the caps to attach the properties to
134 * @props: the properties to attach
136 * set the properties to the given caps
138 * Returns: The new caps structure
141 gst_caps_set_props (GstCaps *caps, GstProps *props)
143 g_return_val_if_fail (caps != NULL, caps);
144 g_return_val_if_fail (props != NULL, caps);
145 g_return_val_if_fail (caps->properties == NULL, caps);
147 caps->properties = props;
153 * gst_caps_get_props:
154 * @caps: the caps to get the properties from
156 * get the properties of the given caps
158 * Returns: The properties of the caps
161 gst_caps_get_props (GstCaps *caps)
163 g_return_val_if_fail (caps != NULL, caps);
165 return caps->properties;
169 * gst_caps_check_compatibility:
170 * @fromcaps: a capabilty
171 * @tocaps: a capabilty
173 * Checks whether two capabilities are compatible
175 * Returns: true if compatible, false otherwise
178 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
180 g_return_val_if_fail (fromcaps != NULL, FALSE);
181 g_return_val_if_fail (tocaps != NULL, FALSE);
183 if (fromcaps->id != tocaps->id) {
184 DEBUG ("gstcaps: mime types wrong\n");
188 if (tocaps->properties) {
189 if (fromcaps->properties) {
190 return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
193 DEBUG ("gstcaps: no source caps\n");
198 // assume it accepts everything
199 DEBUG ("gstcaps: no caps\n");
206 * gst_caps_save_thyself:
207 * @caps: a capabilty to save
208 * @parent: the parent XML node pointer
210 * save the capability into an XML representation
212 * Returns: a new XML node pointer
215 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
219 g_return_val_if_fail (caps != NULL, NULL);
221 xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
222 if (caps->properties) {
223 subtree = xmlNewChild (parent, NULL, "properties", NULL);
225 gst_props_save_thyself (caps->properties, subtree);
232 * gst_caps_load_thyself:
233 * @parent: the parent XML node pointer
235 * load a new caps from the XML representation
237 * Returns: a new capability
240 gst_caps_load_thyself (xmlNodePtr parent)
242 GstCaps *caps = g_new0 (GstCaps, 1);
243 xmlNodePtr field = parent->childs;
246 if (!strcmp (field->name, "type")) {
247 caps->id = get_type_for_mime (xmlNodeGetContent (field));
249 else if (!strcmp (field->name, "properties")) {
250 caps->properties = gst_props_load_thyself (field);