- implement FLOATING flag on caps/props
[platform/upstream/gstreamer.git] / gst / gstcaps.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstcaps.h: Header for caps subsystem
6  *
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.
11  *
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.
16  *
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.
21  */
22
23
24 #ifndef __GST_CAPS_H__
25 #define __GST_CAPS_H__
26
27 #include <gst/gstprops.h>
28
29 G_BEGIN_DECLS
30
31 typedef struct _GstCaps GstCaps;
32
33 #define GST_CAPS_TRACE_NAME "GstCaps"
34
35 extern GType _gst_caps_type;
36
37 #define GST_TYPE_CAPS  (_gst_caps_type)
38
39 typedef enum {
40   GST_CAPS_FIXED        = (1 << 0),     /* caps has no variable properties */
41   GST_CAPS_FLOATING     = (1 << 1)      /* caps is floating */
42 } GstCapsFlags;
43
44 #define GST_CAPS(caps)          ((GstCaps *)(caps))
45
46 #define GST_CAPS_FLAGS(caps)            ((caps)->flags)
47 #define GST_CAPS_FLAG_IS_SET(caps,flag) (GST_CAPS_FLAGS (caps) & flag)
48 #define GST_CAPS_FLAG_SET(caps,flag)    (GST_CAPS_FLAGS (caps) |= (flag))
49 #define GST_CAPS_FLAG_UNSET(caps,flag)  (GST_CAPS_FLAGS (caps) &= ~(flag))
50
51 #define GST_CAPS_REFCOUNT(caps)         ((caps)->refcount)
52 #define GST_CAPS_PROPERTIES(caps)       ((caps)->properties)
53 #define GST_CAPS_NEXT(caps)             ((caps)->next)
54
55 #define GST_CAPS_IS_FIXED(caps)         (GST_CAPS_FLAGS (caps) & GST_CAPS_FIXED)
56 #define GST_CAPS_IS_FLOATING(caps)      (GST_CAPS_FLAGS (caps) & GST_CAPS_FLOATING)
57 #define GST_CAPS_IS_CHAINED(caps)       (GST_CAPS_NEXT (caps) != NULL)
58
59 struct _GstCaps {
60   /* --- public --- */
61   gchar         *name;                  /* the name of this caps */
62   guint16        id;                    /* type id (major type) representing 
63                                            the mime type, it's stored as a GQuark 
64                                            for speed/space reasons */
65
66   guint16        flags;                 /* flags */
67   guint          refcount;              
68
69   GstProps      *properties;            /* properties for this capability */
70   GstCaps       *next;                  /* not with a GList for efficiency */
71 };
72
73 /* factory macros which make it easier for plugins to instantiate */
74
75 #ifdef G_HAVE_ISO_VARARGS
76 #define GST_CAPS_NEW(name, type, ...)           \
77 gst_caps_new (                                  \
78   name,                                         \
79   type,                                         \
80   gst_props_new (                               \
81     __VA_ARGS__,                                \
82     NULL))
83
84 #define GST_CAPS_FACTORY(factoryname, ...)      \
85 static GstCaps*                                 \
86 factoryname (void)                              \
87 {                                               \
88   static GstCaps *caps = NULL;                  \
89   if (!caps) {                                  \
90     caps = gst_caps_chain (__VA_ARGS__, NULL);  \
91   }                                             \
92   return caps;                                  \
93 }
94 #elif defined(G_HAVE_GNUC_VARARGS)
95 #define GST_CAPS_NEW(name, type, a...)          \
96 gst_caps_new (                                  \
97   name,                                         \
98   type,                                         \
99   gst_props_new (                               \
100     a,                                          \
101     NULL))
102
103 #define GST_CAPS_FACTORY(factoryname, a...)     \
104 static GstCaps*                                 \
105 factoryname (void)                              \
106 {                                               \
107   static GstCaps *caps = NULL;                  \
108   if (!caps) {                                  \
109     caps = gst_caps_chain (a, NULL);            \
110   }                                             \
111   return caps;                                  \
112 }
113 #endif
114
115 /* get caps from a factory */
116 #define GST_CAPS_GET(fact) (fact)()
117
118
119 /* initialize the subsystem */
120 void            _gst_caps_initialize                    (void);
121
122 /* creating new caps */
123 GstCaps*        gst_caps_new                            (const gchar *name, const gchar *mime, GstProps *props);
124 GstCaps*        gst_caps_new_id                         (const gchar *name, const guint16 id, GstProps *props);
125 /* replace pointer to caps, doing proper refcounting */
126 void            gst_caps_replace                        (GstCaps **oldcaps, GstCaps *newcaps);
127 void            gst_caps_replace_sink                   (GstCaps **oldcaps, GstCaps *newcaps);
128
129 /* caps lifecycle control */
130 GstCaps*        gst_caps_unref                          (GstCaps *caps);
131 GstCaps*        gst_caps_ref                            (GstCaps *caps);
132 void            gst_caps_sink                           (GstCaps *caps);
133 void            gst_caps_destroy                        (GstCaps *caps);
134
135 /* write debug lines to the log */
136 void            gst_caps_debug                          (GstCaps *caps, const gchar *label);
137
138 /* copy caps */
139 GstCaps*        gst_caps_copy                           (GstCaps *caps);
140 GstCaps*        gst_caps_copy_1                         (GstCaps *caps);
141 GstCaps*        gst_caps_copy_on_write                  (GstCaps *caps);
142
143 const gchar*    gst_caps_get_name                       (GstCaps *caps);
144 void            gst_caps_set_name                       (GstCaps *caps, const gchar *name);
145
146 const gchar*    gst_caps_get_mime                       (GstCaps *caps);
147 void            gst_caps_set_mime                       (GstCaps *caps, const gchar *mime);
148
149 guint16         gst_caps_get_type_id                    (GstCaps *caps);
150 void            gst_caps_set_type_id                    (GstCaps *caps, guint16 type_id);
151
152 GstCaps*        gst_caps_set_props                      (GstCaps *caps, GstProps *props);
153 GstProps*       gst_caps_get_props                      (GstCaps *caps);
154
155 #ifdef G_HAVE_ISO_VARARGS
156 #define         gst_caps_set(caps, ...)                 gst_props_set ((caps)->properties, __VA_ARGS__)
157 #define         gst_caps_get(caps, ...)                 gst_props_get ((caps)->properties, __VA_ARGS__)
158 #elif defined(G_HAVE_GNUC_VARARGS)
159 #define         gst_caps_set(caps, name, args...)       gst_props_set ((caps)->properties, name, ##args)
160 #define         gst_caps_get(caps, name, args...)       gst_props_get ((caps)->properties, name, ##args)
161 #endif
162
163 #define         gst_caps_get_int(caps,name,res)         gst_props_entry_get_int(gst_props_get_entry((caps)->properties,name),res)
164 #define         gst_caps_get_float(caps,name,res)       gst_props_entry_get_float(gst_props_get_entry((caps)->properties,name),res)
165 #define         gst_caps_get_fourcc_int(caps,name,res)  gst_props_entry_get_fourcc_int(gst_props_get_entry((caps)->properties,name),res)
166 #define         gst_caps_get_boolean(caps,name,res)     gst_props_entry_get_boolean(gst_props_get_entry((caps)->properties,name),res)
167 #define         gst_caps_get_string(caps,name,res)      gst_props_entry_get_string(gst_props_get_entry((caps)->properties,name),res)
168
169 #define         gst_caps_has_property(caps, name)       gst_props_has_property ((caps)->properties, name)
170 #define         gst_caps_has_property_typed(caps, name, type)   gst_props_has_property_typed ((caps)->properties, name, type)
171 #define         gst_caps_has_fixed_property(caps, name) gst_props_has_fixed_property ((caps)->properties, name)
172
173 GstCaps*        gst_caps_get_by_name                    (GstCaps *caps, const gchar *name);
174
175 /* use and construct chained caps */
176 GstCaps*        gst_caps_next                           (GstCaps *caps); 
177 GstCaps*        gst_caps_chain                          (GstCaps *caps, ...); 
178 GstCaps*        gst_caps_append                         (GstCaps *caps, GstCaps *capstoadd); 
179 GstCaps*        gst_caps_prepend                        (GstCaps *caps, GstCaps *capstoadd); 
180
181 /* see if fromcaps is a subset of tocaps */
182 gboolean        gst_caps_is_always_compatible           (GstCaps *fromcaps, GstCaps *tocaps);
183
184 /* operations on caps */
185 GstCaps*        gst_caps_intersect                      (GstCaps *caps1, GstCaps *caps2);
186 GstCaps*        gst_caps_union                          (GstCaps *caps1, GstCaps *caps2);
187 GstCaps*        gst_caps_normalize                      (GstCaps *caps);
188
189 #ifndef GST_DISABLE_LOADSAVE
190 xmlNodePtr      gst_caps_save_thyself                   (GstCaps *caps, xmlNodePtr parent);
191 GstCaps*        gst_caps_load_thyself                   (xmlNodePtr parent);
192 #endif
193
194 G_END_DECLS
195
196 #endif /* __GST_CAPS_H__ */