Changed the GstPadFactory and added the GstPadTemplate.
[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_new:
50  * @mime: the mime type to attach to the capability
51  *
52  * create a new capability with the given mime type
53  *
54  * Returns: a new capability
55  */
56 GstCaps*
57 gst_caps_new (gchar *mime)
58 {
59   GstCaps *caps;
60
61   g_return_val_if_fail (mime != NULL, NULL);
62   
63   caps = g_new0 (GstCaps, 1);
64   caps->id = get_type_for_mime (mime);
65   
66   return caps;
67 }
68
69 /**
70  * gst_caps_register:
71  * @factory: the factory to register
72  *
73  * Register the factory. 
74  *
75  * Returns: The registered capability
76  */
77 GstCaps*
78 gst_caps_register (GstCapsFactory *factory)
79 {
80   GstCapsFactoryEntry tag;
81   gint i = 0;
82   guint16 typeid;
83   GstCaps *caps;
84   
85   g_return_val_if_fail (factory != NULL, NULL);
86
87   tag = (*factory)[i++];
88
89   g_return_val_if_fail (tag != NULL, NULL);
90   
91   typeid = get_type_for_mime ((gchar *)tag);
92
93   caps = g_new0 (GstCaps, 1);
94   g_return_val_if_fail (caps != NULL, NULL);
95
96   caps->id = typeid;
97   caps->properties = gst_props_register (&(*factory)[i]);
98
99   return caps;
100 }
101
102
103 /**
104  * gst_caps_check_compatibility:
105  * @fromcaps: a capabilty
106  * @tocaps: a capabilty
107  *
108  * Checks whether two capabilities are compatible
109  *
110  * Returns: true if compatible, false otherwise
111  */
112 gboolean
113 gst_caps_check_compatibility (GstCaps *fromcaps, GstCaps *tocaps)
114 {
115   g_return_val_if_fail (fromcaps != NULL, FALSE);
116   g_return_val_if_fail (tocaps != NULL, FALSE);
117         
118   if (fromcaps->id != tocaps->id)
119     return FALSE;
120
121   return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
122 }
123
124
125 xmlNodePtr      
126 gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
127 {
128   xmlNodePtr subtree;
129
130   g_return_val_if_fail (caps != NULL, NULL);
131
132   xmlNewChild (parent, NULL, "type", gst_type_find_by_id (caps->id)->mime);
133   if (caps->properties) {
134     subtree = xmlNewChild (parent, NULL, "properties", NULL);
135
136     gst_props_save_thyself (caps->properties, subtree);
137   }
138
139   return parent;
140 }
141
142 GstCaps*        
143 gst_caps_load_thyself (xmlNodePtr parent)
144 {
145   GstCaps *caps = g_new0 (GstCaps, 1);
146   xmlNodePtr field = parent->childs;
147
148   while (field) {
149     if (!strcmp (field->name, "type")) {
150       caps->id = get_type_for_mime (xmlNodeGetContent (field));
151     }
152     else if (!strcmp (field->name, "properties")) {
153       caps->properties = gst_props_load_thyself (field);
154     }
155     field = field->next;
156   }
157
158   return caps;
159 }
160
161
162