First attempt at rebuilding the type/plugin system
[platform/upstream/gstreamer.git] / gst / gstcaps.c
1 /* Gnome-Streamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 //#define DEBUG_ENABLED
21
22 #include <stdarg.h>
23 #include <gst/gst.h>
24
25 void 
26 _gst_caps_initialize (void) 
27 {
28 }
29
30 static guint16
31 get_type_for_mime (gchar *mime)
32 {
33   guint16 typeid;
34
35   typeid = gst_type_find_by_mime (mime);
36   if (typeid == 0) {
37      GstTypeFactory *factory = g_new0 (GstTypeFactory, 1);
38
39      factory->mime = g_strdup (mime);
40      factory->exts = NULL;
41      factory->typefindfunc = NULL;
42
43      typeid = gst_type_register (factory);
44   }
45   return typeid;
46 }
47
48 /**
49  * gst_caps_register:
50  * @factory: the factory to register
51  *
52  * Register the factory. 
53  *
54  * Returns: The registered capability
55  */
56 GstCaps *
57 gst_caps_register (GstCapsFactory factory)
58 {
59   GstCapsFactoryEntry tag;
60   gint i = 0;
61   guint16 typeid;
62   GstCaps *caps;
63   
64   g_return_val_if_fail (factory != NULL, NULL);
65
66   tag = factory[i++];
67
68   g_return_val_if_fail (tag != NULL, NULL);
69   
70   typeid = get_type_for_mime ((gchar *)tag);
71
72   caps = g_new0 (GstCaps, 1);
73   g_return_val_if_fail (caps != NULL, NULL);
74
75   caps->id = typeid;
76   caps->properties = gst_props_register (&factory[i]);
77
78   return caps;
79 }
80
81
82 /**
83  * gst_caps_check_compatibility:
84  * @fromcaps: a capabilty
85  * @tocaps: a capabilty
86  *
87  * Checks whether two capabilities are compatible
88  *
89  * Returns: true if compatible, false otherwise
90  */
91 gboolean
92 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
93 {
94   g_return_val_if_fail (fromcaps != NULL, FALSE);
95   g_return_val_if_fail (tocaps != NULL, FALSE);
96         
97   if (fromcaps->id != tocaps->id)
98     return FALSE;
99
100   return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
101 }
102
103
104 xmlNodePtr      
105 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
106 {
107   xmlNodePtr subtree;
108
109   g_return_val_if_fail (caps != NULL, NULL);
110
111   xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
112   if (caps->properties) {
113     subtree = xmlNewChild (parent, NULL, "properties", NULL);
114
115     gst_props_save_thyself (caps->properties, subtree);
116   }
117
118   return parent;
119 }
120
121 GstCaps*        
122 gst_caps_load_thyself (xmlNodePtr parent)
123 {
124   GstCaps *caps = g_new0 (GstCaps, 1);
125   xmlNodePtr field = parent->childs;
126
127   while (field) {
128     if (!strcmp (field->name, "type")) {
129       caps->id = get_type_for_mime (xmlNodeGetContent (field));
130     }
131     else if (!strcmp (field->name, "properties")) {
132       caps->properties = gst_props_load_thyself (field);
133     }
134     field = field->next;
135   }
136
137   return caps;
138 }
139
140
141