|
1 /* GStreamer PropertyProbe |
|
2 * Copyright (C) 2003 David Schleef <ds@schleef.org> |
|
3 * |
|
4 * property_probe.c: property_probe design virtual class function wrappers |
|
5 * |
|
6 * This library is free software; you can redistribute it and/or |
|
7 * modify it under the terms of the GNU Library General Public |
|
8 * License as published by the Free Software Foundation; either |
|
9 * version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This library is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * Library General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU Library General Public |
|
17 * License along with this library; if not, write to the |
|
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
19 * Boston, MA 02111-1307, USA. |
|
20 */ |
|
21 |
|
22 #ifdef HAVE_CONFIG_H |
|
23 #include "config.h" |
|
24 #endif |
|
25 |
|
26 #include <string.h> |
|
27 |
|
28 #include "propertyprobe.h" |
|
29 |
|
30 enum |
|
31 { |
|
32 SIGNAL_PROBE_NEEDED, |
|
33 LAST_SIGNAL |
|
34 }; |
|
35 |
|
36 static void gst_property_probe_iface_init (GstPropertyProbeInterface * iface); |
|
37 |
|
38 static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 }; |
|
39 #ifdef __SYMBIAN32__ |
|
40 EXPORT_C |
|
41 #endif |
|
42 |
|
43 |
|
44 GType |
|
45 gst_property_probe_get_type (void) |
|
46 { |
|
47 static GType gst_property_probe_type = 0; |
|
48 |
|
49 if (!gst_property_probe_type) { |
|
50 static const GTypeInfo gst_property_probe_info = { |
|
51 sizeof (GstPropertyProbeInterface), |
|
52 (GBaseInitFunc) gst_property_probe_iface_init, |
|
53 NULL, |
|
54 NULL, |
|
55 NULL, |
|
56 NULL, |
|
57 0, |
|
58 0, |
|
59 NULL, |
|
60 }; |
|
61 |
|
62 gst_property_probe_type = |
|
63 g_type_register_static (G_TYPE_INTERFACE, |
|
64 "GstPropertyProbe", &gst_property_probe_info, 0); |
|
65 } |
|
66 |
|
67 return gst_property_probe_type; |
|
68 } |
|
69 |
|
70 static void |
|
71 gst_property_probe_iface_init (GstPropertyProbeInterface * iface) |
|
72 { |
|
73 static gboolean initialized = FALSE; |
|
74 |
|
75 if (!initialized) { |
|
76 gst_property_probe_signals[SIGNAL_PROBE_NEEDED] = |
|
77 g_signal_new ("probe-needed", G_TYPE_FROM_CLASS (iface), |
|
78 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPropertyProbeInterface, |
|
79 probe_needed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, |
|
80 G_TYPE_NONE, 1, G_TYPE_POINTER); |
|
81 initialized = TRUE; |
|
82 } |
|
83 |
|
84 /* default virtual functions */ |
|
85 iface->get_properties = NULL; |
|
86 iface->get_values = NULL; |
|
87 } |
|
88 |
|
89 /** |
|
90 * gst_property_probe_get_properties: |
|
91 * @probe: the #GstPropertyProbe to get the properties for. |
|
92 * |
|
93 * Get a list of properties for which probing is supported. |
|
94 * |
|
95 * Returns: the list of properties for which probing is supported |
|
96 * by this element. |
|
97 */ |
|
98 #ifdef __SYMBIAN32__ |
|
99 EXPORT_C |
|
100 #endif |
|
101 |
|
102 |
|
103 const GList * |
|
104 gst_property_probe_get_properties (GstPropertyProbe * probe) |
|
105 { |
|
106 GstPropertyProbeInterface *iface; |
|
107 |
|
108 g_return_val_if_fail (probe != NULL, NULL); |
|
109 |
|
110 iface = GST_PROPERTY_PROBE_GET_IFACE (probe); |
|
111 |
|
112 if (iface->get_properties) |
|
113 return iface->get_properties (probe); |
|
114 |
|
115 return NULL; |
|
116 } |
|
117 #ifdef __SYMBIAN32__ |
|
118 EXPORT_C |
|
119 #endif |
|
120 |
|
121 |
|
122 const GParamSpec * |
|
123 gst_property_probe_get_property (GstPropertyProbe * probe, const gchar * name) |
|
124 { |
|
125 const GList *pspecs = gst_property_probe_get_properties (probe); |
|
126 |
|
127 g_return_val_if_fail (probe != NULL, NULL); |
|
128 g_return_val_if_fail (name != NULL, NULL); |
|
129 |
|
130 while (pspecs) { |
|
131 const GParamSpec *pspec = pspecs->data; |
|
132 |
|
133 if (!strcmp (pspec->name, name)) |
|
134 return pspec; |
|
135 |
|
136 pspecs = pspecs->next; |
|
137 } |
|
138 |
|
139 return NULL; |
|
140 } |
|
141 #ifdef __SYMBIAN32__ |
|
142 EXPORT_C |
|
143 #endif |
|
144 |
|
145 |
|
146 void |
|
147 gst_property_probe_probe_property (GstPropertyProbe * probe, |
|
148 const GParamSpec * pspec) |
|
149 { |
|
150 GstPropertyProbeInterface *iface; |
|
151 |
|
152 g_return_if_fail (probe != NULL); |
|
153 g_return_if_fail (pspec != NULL); |
|
154 |
|
155 iface = GST_PROPERTY_PROBE_GET_IFACE (probe); |
|
156 |
|
157 if (iface->probe_property) |
|
158 iface->probe_property (probe, pspec->param_id, pspec); |
|
159 } |
|
160 |
|
161 /** |
|
162 * gst_property_probe_probe_property_name: |
|
163 * @probe: the #GstPropertyProbe to check. |
|
164 * @name: name of the property to return. |
|
165 * |
|
166 * Runs a probe on the given property. |
|
167 */ |
|
168 #ifdef __SYMBIAN32__ |
|
169 EXPORT_C |
|
170 #endif |
|
171 |
|
172 |
|
173 void |
|
174 gst_property_probe_probe_property_name (GstPropertyProbe * probe, |
|
175 const gchar * name) |
|
176 { |
|
177 const GParamSpec *pspec; |
|
178 |
|
179 g_return_if_fail (probe != NULL); |
|
180 g_return_if_fail (name != NULL); |
|
181 |
|
182 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name); |
|
183 if (!pspec) { |
|
184 g_warning ("No such property %s", name); |
|
185 return; |
|
186 } |
|
187 |
|
188 gst_property_probe_probe_property (probe, pspec); |
|
189 } |
|
190 |
|
191 /** |
|
192 * gst_property_probe_needs_probe: |
|
193 * @probe: the #GstPropertyProbe object to which the given property belongs. |
|
194 * @pspec: a #GParamSpec that identifies the property to check. |
|
195 * |
|
196 * Checks whether a property needs a probe. This might be because |
|
197 * the property wasn't initialized before, or because host setup |
|
198 * changed. This might be, for example, because a new device was |
|
199 * added, and thus device probing needs to be refreshed to display |
|
200 * the new device. |
|
201 * |
|
202 * Returns: TRUE if the property needs a new probe, FALSE if not. |
|
203 */ |
|
204 #ifdef __SYMBIAN32__ |
|
205 EXPORT_C |
|
206 #endif |
|
207 |
|
208 |
|
209 gboolean |
|
210 gst_property_probe_needs_probe (GstPropertyProbe * probe, |
|
211 const GParamSpec * pspec) |
|
212 { |
|
213 GstPropertyProbeInterface *iface; |
|
214 |
|
215 g_return_val_if_fail (probe != NULL, FALSE); |
|
216 g_return_val_if_fail (pspec != NULL, FALSE); |
|
217 |
|
218 iface = GST_PROPERTY_PROBE_GET_IFACE (probe); |
|
219 |
|
220 if (iface->needs_probe) |
|
221 return iface->needs_probe (probe, pspec->param_id, pspec); |
|
222 |
|
223 return FALSE; |
|
224 } |
|
225 |
|
226 /** |
|
227 * gst_property_probe_needs_probe_name: |
|
228 * @probe: the #GstPropertyProbe object to which the given property belongs. |
|
229 * @name: the name of the property to check. |
|
230 * |
|
231 * Same as gst_property_probe_needs_probe (). |
|
232 * |
|
233 * Returns: TRUE if the property needs a new probe, FALSE if not. |
|
234 */ |
|
235 #ifdef __SYMBIAN32__ |
|
236 EXPORT_C |
|
237 #endif |
|
238 |
|
239 |
|
240 gboolean |
|
241 gst_property_probe_needs_probe_name (GstPropertyProbe * probe, |
|
242 const gchar * name) |
|
243 { |
|
244 const GParamSpec *pspec; |
|
245 |
|
246 g_return_val_if_fail (probe != NULL, FALSE); |
|
247 g_return_val_if_fail (name != NULL, FALSE); |
|
248 |
|
249 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name); |
|
250 if (!pspec) { |
|
251 g_warning ("No such property %s", name); |
|
252 return FALSE; |
|
253 } |
|
254 |
|
255 return gst_property_probe_needs_probe (probe, pspec); |
|
256 } |
|
257 |
|
258 /** |
|
259 * gst_property_probe_get_values: |
|
260 * @probe: the #GstPropertyProbe object. |
|
261 * @pspec: the #GParamSpec property identifier. |
|
262 * |
|
263 * Gets the possible (probed) values for the given property, |
|
264 * requires the property to have been probed before. |
|
265 * |
|
266 * Returns: A list of valid values for the given property. |
|
267 */ |
|
268 #ifdef __SYMBIAN32__ |
|
269 EXPORT_C |
|
270 #endif |
|
271 |
|
272 |
|
273 GValueArray * |
|
274 gst_property_probe_get_values (GstPropertyProbe * probe, |
|
275 const GParamSpec * pspec) |
|
276 { |
|
277 GstPropertyProbeInterface *iface; |
|
278 |
|
279 g_return_val_if_fail (probe != NULL, NULL); |
|
280 g_return_val_if_fail (pspec != NULL, NULL); |
|
281 |
|
282 iface = GST_PROPERTY_PROBE_GET_IFACE (probe); |
|
283 |
|
284 if (iface->get_values) |
|
285 return iface->get_values (probe, pspec->param_id, pspec); |
|
286 |
|
287 return NULL; |
|
288 } |
|
289 |
|
290 /** |
|
291 * gst_property_probe_get_values_name: |
|
292 * @probe: the #GstPropertyProbe object. |
|
293 * @name: the name of the property to get values for. |
|
294 * |
|
295 * Same as gst_property_probe_get_values (). |
|
296 * |
|
297 * Returns: A list of valid values for the given property. |
|
298 */ |
|
299 #ifdef __SYMBIAN32__ |
|
300 EXPORT_C |
|
301 #endif |
|
302 |
|
303 |
|
304 GValueArray * |
|
305 gst_property_probe_get_values_name (GstPropertyProbe * probe, |
|
306 const gchar * name) |
|
307 { |
|
308 const GParamSpec *pspec; |
|
309 |
|
310 g_return_val_if_fail (probe != NULL, NULL); |
|
311 g_return_val_if_fail (name != NULL, NULL); |
|
312 |
|
313 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name); |
|
314 if (!pspec) { |
|
315 g_warning ("No such property %s", name); |
|
316 return NULL; |
|
317 } |
|
318 |
|
319 return gst_property_probe_get_values (probe, pspec); |
|
320 } |
|
321 |
|
322 /** |
|
323 * gst_property_probe_probe_and_get_values: |
|
324 * @probe: the #GstPropertyProbe object. |
|
325 * @pspec: The #GParamSpec property identifier. |
|
326 * |
|
327 * Check whether the given property requires a new probe. If so, |
|
328 * fo the probe. After that, retrieve a value list. Meant as a |
|
329 * utility function that wraps the above functions. |
|
330 * |
|
331 * Returns: the list of valid values for this property. |
|
332 */ |
|
333 #ifdef __SYMBIAN32__ |
|
334 EXPORT_C |
|
335 #endif |
|
336 |
|
337 |
|
338 GValueArray * |
|
339 gst_property_probe_probe_and_get_values (GstPropertyProbe * probe, |
|
340 const GParamSpec * pspec) |
|
341 { |
|
342 GstPropertyProbeInterface *iface; |
|
343 |
|
344 g_return_val_if_fail (probe != NULL, NULL); |
|
345 g_return_val_if_fail (pspec != NULL, NULL); |
|
346 |
|
347 iface = GST_PROPERTY_PROBE_GET_IFACE (probe); |
|
348 |
|
349 if (gst_property_probe_needs_probe (probe, pspec)) |
|
350 gst_property_probe_probe_property (probe, pspec); |
|
351 |
|
352 return gst_property_probe_get_values (probe, pspec); |
|
353 } |
|
354 |
|
355 /** |
|
356 * gst_property_probe_probe_and_get_values_name: |
|
357 * @probe: the #GstPropertyProbe object. |
|
358 * @name: the name of the property to get values for. |
|
359 * |
|
360 * Same as gst_property_probe_probe_and_get_values (). |
|
361 * |
|
362 * Returns: the list of valid values for this property. |
|
363 */ |
|
364 #ifdef __SYMBIAN32__ |
|
365 EXPORT_C |
|
366 #endif |
|
367 |
|
368 |
|
369 GValueArray * |
|
370 gst_property_probe_probe_and_get_values_name (GstPropertyProbe * probe, |
|
371 const gchar * name) |
|
372 { |
|
373 const GParamSpec *pspec; |
|
374 |
|
375 g_return_val_if_fail (probe != NULL, NULL); |
|
376 g_return_val_if_fail (name != NULL, NULL); |
|
377 |
|
378 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name); |
|
379 if (!pspec) { |
|
380 g_warning ("No such property %s", name); |
|
381 return NULL; |
|
382 } |
|
383 |
|
384 return gst_property_probe_probe_and_get_values (probe, pspec); |
|
385 } |