2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 //#define DEBUG_ENABLED
25 #include "gstpropsprivate.h"
27 _gst_caps_initialize (void)
32 get_type_for_mime (gchar *mime)
36 typeid = gst_type_find_by_mime (mime);
38 GstTypeFactory *factory = g_new0 (GstTypeFactory, 1);
40 factory->mime = g_strdup (mime);
42 factory->typefindfunc = NULL;
44 typeid = gst_type_register (factory);
51 * @mime: the mime type to attach to the capability
53 * create a new capability with the given mime type
55 * Returns: a new capability
58 gst_caps_new (gchar *mime)
62 g_return_val_if_fail (mime != NULL, NULL);
64 caps = g_new0 (GstCaps, 1);
65 caps->id = get_type_for_mime (mime);
66 caps->properties = NULL;
73 * @factory: the factory to register
75 * Register the factory.
77 * Returns: The registered capability
80 gst_caps_register (GstCapsFactory *factory)
82 GstCapsFactoryEntry tag;
87 g_return_val_if_fail (factory != NULL, NULL);
89 tag = (*factory)[i++];
91 g_return_val_if_fail (tag != NULL, NULL);
93 typeid = get_type_for_mime ((gchar *)tag);
95 caps = g_new0 (GstCaps, 1);
96 g_return_val_if_fail (caps != NULL, NULL);
99 caps->properties = gst_props_register (&(*factory)[i]);
106 * gst_caps_check_compatibility:
107 * @fromcaps: a capabilty
108 * @tocaps: a capabilty
110 * Checks whether two capabilities are compatible
112 * Returns: true if compatible, false otherwise
115 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
117 g_return_val_if_fail (fromcaps != NULL, FALSE);
118 g_return_val_if_fail (tocaps != NULL, FALSE);
120 if (fromcaps->id != tocaps->id) {
121 //g_print ("gstcaps: mime types wrong\n");
125 if (tocaps->properties) {
126 GstPropsEntry *entry = (GstPropsEntry *)tocaps->properties;
128 if (fromcaps->properties) {
129 return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
132 //g_print ("gstcaps: no source caps\n");
137 // assume it accepts everything
138 //g_print ("gstcaps: no caps\n");
145 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
149 g_return_val_if_fail (caps != NULL, NULL);
151 xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
152 if (caps->properties) {
153 subtree = xmlNewChild (parent, NULL, "properties", NULL);
155 gst_props_save_thyself (caps->properties, subtree);
162 gst_caps_load_thyself (xmlNodePtr parent)
164 GstCaps *caps = g_new0 (GstCaps, 1);
165 xmlNodePtr field = parent->childs;
168 if (!strcmp (field->name, "type")) {
169 caps->id = get_type_for_mime (xmlNodeGetContent (field));
171 else if (!strcmp (field->name, "properties")) {
172 caps->properties = gst_props_load_thyself (field);