1 | /* GStreamer |
---|
2 | * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
---|
3 | * 2000 Wim Taymans <wtay@chello.be> |
---|
4 | * |
---|
5 | * gstutils.h: Header for various utility functions |
---|
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_UTILS_H__ |
---|
25 | #define __GST_UTILS_H__ |
---|
26 | |
---|
27 | #include <glib.h> |
---|
28 | #include <gst/gstelement.h> |
---|
29 | |
---|
30 | G_BEGIN_DECLS |
---|
31 | |
---|
32 | void gst_util_set_value_from_string (GValue *value, const gchar *value_str); |
---|
33 | void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value); |
---|
34 | |
---|
35 | void gst_util_dump_mem (const guchar *mem, guint size); |
---|
36 | |
---|
37 | void gst_print_pad_caps (GString *buf, gint indent, GstPad *pad); |
---|
38 | void gst_print_element_args (GString *buf, gint indent, GstElement *element); |
---|
39 | |
---|
40 | |
---|
41 | /* Macros for defining classes. Ideas taken from Bonobo, which took theirs |
---|
42 | from Nautilus and GOB. */ |
---|
43 | |
---|
44 | /* Define the boilerplate type stuff to reduce typos and code size. Defines |
---|
45 | the get_type method and the parent_class static variable. |
---|
46 | void additional_initializations (GType type) is for initializing interfaces |
---|
47 | and stuff like that */ |
---|
48 | |
---|
49 | #define GST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations) \ |
---|
50 | \ |
---|
51 | static void type_as_function ## _base_init (gpointer g_class); \ |
---|
52 | static void type_as_function ## _class_init (type ## Class *g_class); \ |
---|
53 | static void type_as_function ## _init (type *object); \ |
---|
54 | static parent_type ## Class *parent_class = NULL; \ |
---|
55 | static void \ |
---|
56 | type_as_function ## _class_init_trampoline (gpointer g_class, \ |
---|
57 | gpointer data) \ |
---|
58 | { \ |
---|
59 | parent_class = (parent_type ## Class *) g_type_class_peek_parent (g_class); \ |
---|
60 | type_as_function ## _class_init ((type ## Class *)g_class); \ |
---|
61 | } \ |
---|
62 | \ |
---|
63 | GType \ |
---|
64 | type_as_function ## _get_type (void) \ |
---|
65 | { \ |
---|
66 | static GType object_type = 0; \ |
---|
67 | if (object_type == 0) { \ |
---|
68 | static const GTypeInfo object_info = { \ |
---|
69 | sizeof (type ## Class), \ |
---|
70 | type_as_function ## _base_init, \ |
---|
71 | NULL, /* base_finalize */ \ |
---|
72 | type_as_function ## _class_init_trampoline, \ |
---|
73 | NULL, /* class_finalize */ \ |
---|
74 | NULL, /* class_data */ \ |
---|
75 | sizeof (type), \ |
---|
76 | 0, /* n_preallocs */ \ |
---|
77 | (GInstanceInitFunc) type_as_function ## _init \ |
---|
78 | }; \ |
---|
79 | object_type = g_type_register_static (parent_type_macro, #type, \ |
---|
80 | &object_info, (GTypeFlags) 0); \ |
---|
81 | additional_initializations (object_type); \ |
---|
82 | } \ |
---|
83 | return object_type; \ |
---|
84 | } |
---|
85 | |
---|
86 | #define __GST_DO_NOTHING(type) /* NOP */ |
---|
87 | #define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro) \ |
---|
88 | GST_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro, \ |
---|
89 | __GST_DO_NOTHING) |
---|
90 | |
---|
91 | /* Just call the parent handler. This assumes that there is a variable |
---|
92 | * named parent_class that points to the (duh!) parent class. Note that |
---|
93 | * this macro is not to be used with things that return something, use |
---|
94 | * the _WITH_DEFAULT version for that */ |
---|
95 | #define GST_CALL_PARENT(parent_class_cast, name, args) \ |
---|
96 | ((parent_class_cast(parent_class)->name != NULL) ? \ |
---|
97 | parent_class_cast(parent_class)->name args : (void) 0) |
---|
98 | |
---|
99 | /* Same as above, but in case there is no implementation, it evaluates |
---|
100 | * to def_return */ |
---|
101 | #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return) \ |
---|
102 | ((parent_class_cast(parent_class)->name != NULL) ? \ |
---|
103 | parent_class_cast(parent_class)->name args : def_return) |
---|
104 | |
---|
105 | /* Define possibly unaligned memory access method whether the type of |
---|
106 | * architecture. */ |
---|
107 | #if GST_HAVE_UNALIGNED_ACCESS |
---|
108 | |
---|
109 | #define _GST_GET(__data, __size, __end) \ |
---|
110 | (GUINT##__size##_FROM_##__end (* ((guint##__size *) (__data)))) |
---|
111 | |
---|
112 | #define GST_READ_UINT64_BE(data) _GST_GET (data, 64, BE) |
---|
113 | #define GST_READ_UINT64_LE(data) _GST_GET (data, 64, LE) |
---|
114 | #define GST_READ_UINT32_BE(data) _GST_GET (data, 32, BE) |
---|
115 | #define GST_READ_UINT32_LE(data) _GST_GET (data, 32, LE) |
---|
116 | #define GST_READ_UINT16_BE(data) _GST_GET (data, 16, BE) |
---|
117 | #define GST_READ_UINT16_LE(data) _GST_GET (data, 16, LE) |
---|
118 | #define GST_READ_UINT8(data) (* ((guint8 *) (data))) |
---|
119 | |
---|
120 | #define _GST_PUT(__data, __size, __end, __num) \ |
---|
121 | ((* (guint##__size *) (__data)) = GUINT##__size##_TO_##__end (__num)) |
---|
122 | |
---|
123 | #define GST_WRITE_UINT64_BE(data, num) _GST_PUT(data, 64, BE, num) |
---|
124 | #define GST_WRITE_UINT64_LE(data, num) _GST_PUT(data, 64, LE, num) |
---|
125 | #define GST_WRITE_UINT32_BE(data, num) _GST_PUT(data, 32, BE, num) |
---|
126 | #define GST_WRITE_UINT32_LE(data, num) _GST_PUT(data, 32, LE, num) |
---|
127 | #define GST_WRITE_UINT16_BE(data, num) _GST_PUT(data, 16, BE, num) |
---|
128 | #define GST_WRITE_UINT16_LE(data, num) _GST_PUT(data, 16, LE, num) |
---|
129 | #define GST_WRITE_UINT8(data, num) ((* (guint8 *) (data)) = (num)) |
---|
130 | |
---|
131 | #else /* GST_HAVE_UNALIGNED_ACCESS */ |
---|
132 | |
---|
133 | #define _GST_GET(__data, __idx, __size, __shift) \ |
---|
134 | (((guint##__size) (((guint8 *) (__data))[__idx])) << __shift) |
---|
135 | |
---|
136 | #define GST_READ_UINT64_BE(data) (_GST_GET (data, 0, 64, 56) | \ |
---|
137 | _GST_GET (data, 1, 64, 48) | \ |
---|
138 | _GST_GET (data, 2, 64, 40) | \ |
---|
139 | _GST_GET (data, 3, 64, 32) | \ |
---|
140 | _GST_GET (data, 4, 64, 24) | \ |
---|
141 | _GST_GET (data, 5, 64, 16) | \ |
---|
142 | _GST_GET (data, 6, 64, 8) | \ |
---|
143 | _GST_GET (data, 7, 64, 0)) |
---|
144 | |
---|
145 | #define GST_READ_UINT64_LE(data) (_GST_GET (data, 7, 64, 56) | \ |
---|
146 | _GST_GET (data, 6, 64, 48) | \ |
---|
147 | _GST_GET (data, 5, 64, 40) | \ |
---|
148 | _GST_GET (data, 4, 64, 32) | \ |
---|
149 | _GST_GET (data, 3, 64, 24) | \ |
---|
150 | _GST_GET (data, 2, 64, 16) | \ |
---|
151 | _GST_GET (data, 1, 64, 8) | \ |
---|
152 | _GST_GET (data, 0, 64, 0)) |
---|
153 | |
---|
154 | #define GST_READ_UINT32_BE(data) (_GST_GET (data, 0, 32, 24) | \ |
---|
155 | _GST_GET (data, 1, 32, 16) | \ |
---|
156 | _GST_GET (data, 2, 32, 8) | \ |
---|
157 | _GST_GET (data, 3, 32, 0)) |
---|
158 | |
---|
159 | #define GST_READ_UINT32_LE(data) (_GST_GET (data, 3, 32, 24) | \ |
---|
160 | _GST_GET (data, 2, 32, 16) | \ |
---|
161 | _GST_GET (data, 1, 32, 8) | \ |
---|
162 | _GST_GET (data, 0, 32, 0)) |
---|
163 | |
---|
164 | #define GST_READ_UINT16_BE(data) (_GST_GET (data, 0, 16, 8) | \ |
---|
165 | _GST_GET (data, 1, 16, 0)) |
---|
166 | |
---|
167 | #define GST_READ_UINT16_LE(data) (_GST_GET (data, 1, 16, 8) | \ |
---|
168 | _GST_GET (data, 0, 16, 0)) |
---|
169 | |
---|
170 | #define GST_READ_UINT8(data) (_GST_GET (data, 0, 8, 0)) |
---|
171 | |
---|
172 | #define _GST_PUT(__data, __idx, __size, __shift, __num) \ |
---|
173 | (((guint8 *) (__data))[__idx] = (((guint##__size) __num) >> __shift) & 0xff) |
---|
174 | |
---|
175 | #define GST_WRITE_UINT64_BE(data, num) do { \ |
---|
176 | _GST_PUT (data, 0, 64, 56, num); \ |
---|
177 | _GST_PUT (data, 1, 64, 48, num); \ |
---|
178 | _GST_PUT (data, 2, 64, 40, num); \ |
---|
179 | _GST_PUT (data, 3, 64, 32, num); \ |
---|
180 | _GST_PUT (data, 4, 64, 24, num); \ |
---|
181 | _GST_PUT (data, 5, 64, 16, num); \ |
---|
182 | _GST_PUT (data, 6, 64, 8, num); \ |
---|
183 | _GST_PUT (data, 7, 64, 0, num); \ |
---|
184 | } while (0) |
---|
185 | |
---|
186 | #define GST_WRITE_UINT64_LE(data, num) do { \ |
---|
187 | _GST_PUT (data, 0, 64, 0, num); \ |
---|
188 | _GST_PUT (data, 1, 64, 8, num); \ |
---|
189 | _GST_PUT (data, 2, 64, 16, num); \ |
---|
190 | _GST_PUT (data, 3, 64, 24, num); \ |
---|
191 | _GST_PUT (data, 4, 64, 32, num); \ |
---|
192 | _GST_PUT (data, 5, 64, 40, num); \ |
---|
193 | _GST_PUT (data, 6, 64, 48, num); \ |
---|
194 | _GST_PUT (data, 7, 64, 56, num); \ |
---|
195 | } while (0) |
---|
196 | |
---|
197 | #define GST_WRITE_UINT32_BE(data, num) do { \ |
---|
198 | _GST_PUT (data, 0, 32, 24, num); \ |
---|
199 | _GST_PUT (data, 1, 32, 16, num); \ |
---|
200 | _GST_PUT (data, 2, 32, 8, num); \ |
---|
201 | _GST_PUT (data, 3, 32, 0, num); \ |
---|
202 | } while (0) |
---|
203 | |
---|
204 | #define GST_WRITE_UINT32_LE(data, num) do { \ |
---|
205 | _GST_PUT (data, 0, 32, 0, num); \ |
---|
206 | _GST_PUT (data, 1, 32, 8, num); \ |
---|
207 | _GST_PUT (data, 2, 32, 16, num); \ |
---|
208 | _GST_PUT (data, 3, 32, 24, num); \ |
---|
209 | } while (0) |
---|
210 | |
---|
211 | #define GST_WRITE_UINT16_BE(data, num) do { \ |
---|
212 | _GST_PUT (data, 0, 16, 8, num); \ |
---|
213 | _GST_PUT (data, 1, 16, 0, num); \ |
---|
214 | } while (0) |
---|
215 | |
---|
216 | #define GST_WRITE_UINT16_LE(data, num) do { \ |
---|
217 | _GST_PUT (data, 0, 16, 0, num); \ |
---|
218 | _GST_PUT (data, 1, 16, 8, num); \ |
---|
219 | } while (0) |
---|
220 | |
---|
221 | #define GST_WRITE_UINT8(data, num) do { \ |
---|
222 | _GST_PUT (data, 0, 8, 0, num); \ |
---|
223 | } while (0) |
---|
224 | |
---|
225 | #endif /* GST_HAVE_UNALIGNED_ACCESS */ |
---|
226 | |
---|
227 | G_END_DECLS |
---|
228 | |
---|
229 | #endif /* __GST_UTILS_H__ */ |
---|