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 (const 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 (const gchar *name, const 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 and the given properties.
87 * Returns: a new capability
90 gst_caps_new_with_props (const gchar *name, const gchar *mime, GstProps *props)
94 caps = gst_caps_new (name, mime);
95 caps->properties = props;
102 * @factory: the factory to register
104 * Register the factory.
106 * Returns: the registered capability
109 gst_caps_register (GstCapsFactory *factory)
113 return gst_caps_register_count (factory, &dummy);
117 * gst_caps_register_count:
118 * @factory: the factory to register
119 * @counter: count how many entries were consumed
121 * Register the factory.
123 * Returns: the registered capability
126 gst_caps_register_count (GstCapsFactory *factory, guint *counter)
128 GstCapsFactoryEntry tag;
134 g_return_val_if_fail (factory != NULL, NULL);
136 tag = (*factory)[i++];
137 g_return_val_if_fail (tag != NULL, NULL);
141 tag = (*factory)[i++];
142 g_return_val_if_fail (tag != NULL, NULL);
144 typeid = get_type_for_mime ((gchar *)tag);
146 caps = g_new0 (GstCaps, 1);
147 g_return_val_if_fail (caps != NULL, NULL);
149 caps->name = g_strdup (name);
151 caps->properties = gst_props_register_count (&(*factory)[i], counter);
160 * @caps: the caps to get the name from
162 * Get the name of a GstCaps structure.
164 * Returns: the name of the caps
167 gst_caps_get_name (GstCaps *caps)
169 g_return_val_if_fail (caps != NULL, NULL);
171 return (const gchar *)caps->name;
176 * @caps: the caps to set the name to
177 * @name: the name to set
179 * Set the name of a caps.
182 gst_caps_set_name (GstCaps *caps, const gchar *name)
184 g_return_if_fail (caps != NULL);
189 caps->name = g_strdup (name);
194 * @caps: the caps to get the mime type from
196 * Get the mime type of the caps as a string.
198 * Returns: the mime type of the caps
201 gst_caps_get_mime (GstCaps *caps)
205 g_return_val_if_fail (caps != NULL, NULL);
207 type = gst_type_find_by_id (caps->id);
212 return "unknown/unknown";
217 * @caps: the caps to set the mime type to
218 * @mime: the mime type to attach to the caps
220 * Set the mime type of the caps as a string.
223 gst_caps_set_mime (GstCaps *caps, const gchar *mime)
225 g_return_if_fail (caps != NULL);
226 g_return_if_fail (mime != NULL);
228 caps->id = get_type_for_mime (mime);
232 * gst_caps_get_type_id:
233 * @caps: the caps to get the type id from
235 * Get the type id of the caps.
237 * Returns: the type id of the caps
240 gst_caps_get_type_id (GstCaps *caps)
242 g_return_val_if_fail (caps != NULL, 0);
248 * gst_caps_set_type_id:
249 * @caps: the caps to set the type id to
250 * @typeid: the type id to set
252 * Set the type id of the caps.
255 gst_caps_set_type_id (GstCaps *caps, guint16 typeid)
257 g_return_if_fail (caps != NULL);
263 * gst_caps_set_props:
264 * @caps: the caps to attach the properties to
265 * @props: the properties to attach
267 * Set the properties to the given caps.
269 * Returns: the new caps structure
272 gst_caps_set_props (GstCaps *caps, GstProps *props)
274 g_return_val_if_fail (caps != NULL, caps);
275 g_return_val_if_fail (props != NULL, caps);
276 g_return_val_if_fail (caps->properties == NULL, caps);
278 caps->properties = props;
284 * gst_caps_get_props:
285 * @caps: the caps to get the properties from
287 * Get the properties of the given caps.
289 * Returns: the properties of the caps
292 gst_caps_get_props (GstCaps *caps)
294 g_return_val_if_fail (caps != NULL, NULL);
296 return caps->properties;
300 * gst_caps_check_compatibility:
301 * @fromcaps: a capabilty
302 * @tocaps: a capabilty
304 * Checks whether two capabilities are compatible.
306 * Returns: TRUE if compatible, FALSE otherwise
309 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
311 g_return_val_if_fail (fromcaps != NULL, FALSE);
312 g_return_val_if_fail (tocaps != NULL, FALSE);
314 if (fromcaps->id != tocaps->id) {
315 GST_DEBUG (0,"gstcaps: mime types differ (%d to %d)\n",
316 fromcaps->id, tocaps->id);
320 if (tocaps->properties) {
321 if (fromcaps->properties) {
322 return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
325 GST_DEBUG (0,"gstcaps: no source caps\n");
330 // assume it accepts everything
331 GST_DEBUG (0,"gstcaps: no caps\n");
337 * gst_caps_list_check_compatibility:
338 * @fromcaps: a capabilty
339 * @tocaps: a capabilty
341 * Checks whether two capability lists are compatible.
343 * Returns: TRUE if compatible, FALSE otherwise
346 gst_caps_list_check_compatibility (GList *fromcaps, GList *tocaps)
349 GstCaps *fromcap = (GstCaps *)fromcaps->data;
350 GList *destcaps = tocaps;
353 GstCaps *destcap = (GstCaps *)destcaps->data;
355 if (gst_caps_check_compatibility (fromcap, destcap))
358 destcaps = g_list_next (destcaps);
360 fromcaps = g_list_next (fromcaps);
366 * gst_caps_save_thyself:
367 * @caps: a capabilty to save
368 * @parent: the parent XML node pointer
370 * Save the capability into an XML representation.
372 * Returns: a new XML node pointer
375 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
379 g_return_val_if_fail (caps != NULL, NULL);
381 xmlNewChild (parent, NULL, "name", caps->name);
382 xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
383 if (caps->properties) {
384 subtree = xmlNewChild (parent, NULL, "properties", NULL);
386 gst_props_save_thyself (caps->properties, subtree);
393 * gst_caps_load_thyself:
394 * @parent: the parent XML node pointer
396 * Load a new caps from the XML representation.
398 * Returns: a new capability
401 gst_caps_load_thyself (xmlNodePtr parent)
403 GstCaps *caps = g_new0 (GstCaps, 1);
404 xmlNodePtr field = parent->xmlChildrenNode;
408 if (!strcmp (field->name, "name")) {
409 caps->name = xmlNodeGetContent (field);
411 if (!strcmp (field->name, "type")) {
412 content = xmlNodeGetContent (field);
413 caps->id = get_type_for_mime (content);
416 else if (!strcmp (field->name, "properties")) {
417 caps->properties = gst_props_load_thyself (field);