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
26 #include "gstpropsprivate.h"
28 _gst_caps_initialize (void)
33 get_type_for_mime (gchar *mime)
37 typeid = gst_type_find_by_mime (mime);
39 GstTypeFactory *factory = g_new0 (GstTypeFactory, 1);
41 factory->mime = g_strdup (mime);
43 factory->typefindfunc = NULL;
45 typeid = gst_type_register (factory);
52 * @mime: the mime type to attach to the capability
54 * create a new capability with the given mime type
56 * Returns: a new capability
59 gst_caps_new (gchar *mime)
63 g_return_val_if_fail (mime != NULL, NULL);
65 caps = g_new0 (GstCaps, 1);
66 caps->id = get_type_for_mime (mime);
67 caps->properties = NULL;
73 gst_caps_new_with_props (gchar *mime, GstProps *props)
77 caps = gst_caps_new (mime);
78 caps->properties = props;
85 * @factory: the factory to register
87 * Register the factory.
89 * Returns: The registered capability
92 gst_caps_register (GstCapsFactory *factory)
94 GstCapsFactoryEntry tag;
99 g_return_val_if_fail (factory != NULL, NULL);
101 tag = (*factory)[i++];
103 g_return_val_if_fail (tag != NULL, NULL);
105 typeid = get_type_for_mime ((gchar *)tag);
107 caps = g_new0 (GstCaps, 1);
108 g_return_val_if_fail (caps != NULL, NULL);
111 caps->properties = gst_props_register (&(*factory)[i]);
117 gst_caps_set_props (GstCaps *caps, GstProps *props)
119 g_return_val_if_fail (caps != NULL, caps);
120 g_return_val_if_fail (props != NULL, caps);
121 g_return_val_if_fail (caps->properties == NULL, caps);
123 caps->properties = props;
129 gst_caps_get_props (GstCaps *caps)
131 g_return_val_if_fail (caps != NULL, caps);
133 return caps->properties;
137 * gst_caps_check_compatibility:
138 * @fromcaps: a capabilty
139 * @tocaps: a capabilty
141 * Checks whether two capabilities are compatible
143 * Returns: true if compatible, false otherwise
146 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
148 g_return_val_if_fail (fromcaps != NULL, FALSE);
149 g_return_val_if_fail (tocaps != NULL, FALSE);
151 if (fromcaps->id != tocaps->id) {
152 DEBUG ("gstcaps: mime types wrong\n");
156 if (tocaps->properties) {
157 if (fromcaps->properties) {
158 return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
161 DEBUG ("gstcaps: no source caps\n");
166 // assume it accepts everything
167 DEBUG ("gstcaps: no caps\n");
174 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
178 g_return_val_if_fail (caps != NULL, NULL);
180 xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
181 if (caps->properties) {
182 subtree = xmlNewChild (parent, NULL, "properties", NULL);
184 gst_props_save_thyself (caps->properties, subtree);
191 gst_caps_load_thyself (xmlNodePtr parent)
193 GstCaps *caps = g_new0 (GstCaps, 1);
194 xmlNodePtr field = parent->childs;
197 if (!strcmp (field->name, "type")) {
198 caps->id = get_type_for_mime (xmlNodeGetContent (field));
200 else if (!strcmp (field->name, "properties")) {
201 caps->properties = gst_props_load_thyself (field);