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 * @name: the name of this capability
58 * @mime: the mime type to attach to the capability
60 * create a new capability with the given mime type
62 * Returns: a new capability
65 gst_caps_new (gchar *name, gchar *mime)
69 g_return_val_if_fail (mime != NULL, NULL);
71 caps = g_new0 (GstCaps, 1);
72 caps->name = g_strdup (name);
73 caps->id = get_type_for_mime (mime);
74 caps->properties = NULL;
80 * gst_caps_new_with_props:
81 * @name: the name of this capability
82 * @mime: the mime type to attach to the capability
83 * @props: the properties for this capability
85 * create a new capability with the given mime type
86 * and the given properties
88 * Returns: a new capability
91 gst_caps_new_with_props (gchar *name, gchar *mime, GstProps *props)
95 caps = gst_caps_new (name, mime);
96 caps->properties = props;
103 * @factory: the factory to register
105 * Register the factory.
107 * Returns: The registered capability
110 gst_caps_register (GstCapsFactory *factory)
114 return gst_caps_register_count (factory, &dummy);
118 * gst_caps_register_count:
119 * @factory: the factory to register
120 * @counter: count how many entries were consumed
122 * Register the factory.
124 * Returns: The registered capability
127 gst_caps_register_count (GstCapsFactory *factory, guint *counter)
129 GstCapsFactoryEntry tag;
135 g_return_val_if_fail (factory != NULL, NULL);
137 tag = (*factory)[i++];
138 g_return_val_if_fail (tag != NULL, NULL);
142 tag = (*factory)[i++];
143 g_return_val_if_fail (tag != NULL, NULL);
145 typeid = get_type_for_mime ((gchar *)tag);
147 caps = g_new0 (GstCaps, 1);
148 g_return_val_if_fail (caps != NULL, NULL);
150 caps->name = g_strdup (name);
152 caps->properties = gst_props_register_count (&(*factory)[i], counter);
160 * gst_caps_set_props:
161 * @caps: the caps to attach the properties to
162 * @props: the properties to attach
164 * set the properties to the given caps
166 * Returns: The new caps structure
169 gst_caps_set_props (GstCaps *caps, GstProps *props)
171 g_return_val_if_fail (caps != NULL, caps);
172 g_return_val_if_fail (props != NULL, caps);
173 g_return_val_if_fail (caps->properties == NULL, caps);
175 caps->properties = props;
181 * gst_caps_get_props:
182 * @caps: the caps to get the properties from
184 * get the properties of the given caps
186 * Returns: The properties of the caps
189 gst_caps_get_props (GstCaps *caps)
191 g_return_val_if_fail (caps != NULL, NULL);
193 return caps->properties;
197 * gst_caps_check_compatibility:
198 * @fromcaps: a capabilty
199 * @tocaps: a capabilty
201 * Checks whether two capabilities are compatible
203 * Returns: true if compatible, false otherwise
206 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
208 g_return_val_if_fail (fromcaps != NULL, FALSE);
209 g_return_val_if_fail (tocaps != NULL, FALSE);
211 if (fromcaps->id != tocaps->id) {
212 DEBUG ("gstcaps: mime types wrong\n");
216 if (tocaps->properties) {
217 if (fromcaps->properties) {
218 return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
221 DEBUG ("gstcaps: no source caps\n");
226 // assume it accepts everything
227 DEBUG ("gstcaps: no caps\n");
233 * gst_caps_list_check_compatibility:
234 * @fromcaps: a capabilty
235 * @tocaps: a capabilty
237 * Checks whether two capability lists are compatible
239 * Returns: true if compatible, false otherwise
242 gst_caps_list_check_compatibility (GList *fromcaps, GList *tocaps)
245 GstCaps *fromcap = (GstCaps *)fromcaps->data;
246 GList *destcaps = tocaps;
249 GstCaps *destcap = (GstCaps *)destcaps->data;
251 if (gst_caps_check_compatibility (fromcap, destcap))
254 destcaps = g_list_next (destcaps);
256 fromcaps = g_list_next (fromcaps);
262 * gst_caps_save_thyself:
263 * @caps: a capabilty to save
264 * @parent: the parent XML node pointer
266 * save the capability into an XML representation
268 * Returns: a new XML node pointer
271 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
275 g_return_val_if_fail (caps != NULL, NULL);
277 xmlNewChild (parent, NULL, "name", caps->name);
278 xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
279 if (caps->properties) {
280 subtree = xmlNewChild (parent, NULL, "properties", NULL);
282 gst_props_save_thyself (caps->properties, subtree);
289 * gst_caps_load_thyself:
290 * @parent: the parent XML node pointer
292 * load a new caps from the XML representation
294 * Returns: a new capability
297 gst_caps_load_thyself (xmlNodePtr parent)
299 GstCaps *caps = g_new0 (GstCaps, 1);
300 xmlNodePtr field = parent->childs;
303 if (!strcmp (field->name, "name")) {
304 caps->name = g_strdup (xmlNodeGetContent (field));
306 if (!strcmp (field->name, "type")) {
307 caps->id = get_type_for_mime (xmlNodeGetContent (field));
309 else if (!strcmp (field->name, "properties")) {
310 caps->properties = gst_props_load_thyself (field);