1 /* GStreamer PropertyProbe
2 * Copyright (C) 2003 David Schleef <ds@schleef.org>
4 * property_probe.c: property_probe design virtual class function wrappers
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.
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.
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.
22 * SECTION:gstpropertyprobe
23 * @short_description: Interface for probing possible property values
25 * The property probe is a way to autodetect allowed values for a GObject
26 * property. It's primary use is to autodetect device-names in several elements.
28 * The interface is implemented by many hardware sources and sinks.
36 #include "propertyprobe.h"
44 static void gst_property_probe_iface_init (GstPropertyProbeInterface * iface);
46 static guint gst_property_probe_signals[LAST_SIGNAL] = { 0 };
49 gst_property_probe_get_type (void)
51 static GType gst_property_probe_type = 0;
53 if (!gst_property_probe_type) {
54 static const GTypeInfo gst_property_probe_info = {
55 sizeof (GstPropertyProbeInterface),
56 (GBaseInitFunc) gst_property_probe_iface_init,
66 gst_property_probe_type =
67 g_type_register_static (G_TYPE_INTERFACE,
68 "GstPropertyProbe", &gst_property_probe_info, 0);
71 return gst_property_probe_type;
75 gst_property_probe_iface_init (GstPropertyProbeInterface * iface)
77 static gboolean initialized = FALSE;
81 * GstPropertyProbe::probe-needed
82 * @pspec: #GParamSpec that needs a probe
86 * what is the purpose of this signal, I can't find any usage of it
87 * according to proto n *.h, it should be g_cclosure_marshal_VOID__PARAM
89 gst_property_probe_signals[SIGNAL_PROBE_NEEDED] =
90 g_signal_new ("probe-needed", G_TYPE_FROM_CLASS (iface),
91 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPropertyProbeInterface,
92 probe_needed), NULL, NULL, g_cclosure_marshal_VOID__POINTER,
93 G_TYPE_NONE, 1, G_TYPE_POINTER);
97 /* default virtual functions */
98 iface->get_properties = NULL;
99 iface->get_values = NULL;
103 * gst_property_probe_get_properties:
104 * @probe: the #GstPropertyProbe to get the properties for.
106 * Get a list of properties for which probing is supported.
108 * Returns: the list of #GParamSpec * pointers representing
109 * properties for which probing is supported by this element.
112 gst_property_probe_get_properties (GstPropertyProbe * probe)
114 GstPropertyProbeInterface *iface;
116 g_return_val_if_fail (probe != NULL, NULL);
117 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), NULL);
119 iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
121 if (iface->get_properties)
122 return iface->get_properties (probe);
128 * gst_property_probe_get_property:
129 * @probe: the #GstPropertyProbe to get the properties for.
130 * @name: name of the property.
132 * Get #GParamSpec for a property for which probing is supported.
134 * Returns: the #GParamSpec of %NULL.
137 gst_property_probe_get_property (GstPropertyProbe * probe, const gchar * name)
141 g_return_val_if_fail (probe != NULL, NULL);
142 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), NULL);
143 g_return_val_if_fail (name != NULL, NULL);
145 pspecs = gst_property_probe_get_properties (probe);
148 const GParamSpec *pspec = pspecs->data;
151 if (!strcmp (pspec->name, name))
154 GST_WARNING_OBJECT (probe, "NULL paramspec in property probe list");
157 pspecs = pspecs->next;
164 * gst_property_probe_probe_property:
165 * @probe: the #GstPropertyProbe to check.
166 * @pspec: #GParamSpec of the property.
168 * Runs a probe on the property specified by @pspec
171 gst_property_probe_probe_property (GstPropertyProbe * probe,
172 const GParamSpec * pspec)
174 GstPropertyProbeInterface *iface;
176 g_return_if_fail (probe != NULL);
177 g_return_if_fail (GST_IS_PROPERTY_PROBE (probe));
178 g_return_if_fail (pspec != NULL);
180 iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
182 if (iface->probe_property)
183 iface->probe_property (probe, pspec->param_id, pspec);
187 * gst_property_probe_probe_property_name:
188 * @probe: the #GstPropertyProbe to check.
189 * @name: name of the property.
191 * Runs a probe on the property specified by @name.
194 gst_property_probe_probe_property_name (GstPropertyProbe * probe,
197 const GParamSpec *pspec;
199 g_return_if_fail (probe != NULL);
200 g_return_if_fail (GST_IS_PROPERTY_PROBE (probe));
201 g_return_if_fail (name != NULL);
203 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name);
205 g_warning ("No such property %s", name);
209 gst_property_probe_probe_property (probe, pspec);
213 * gst_property_probe_needs_probe:
214 * @probe: the #GstPropertyProbe object to which the given property belongs.
215 * @pspec: a #GParamSpec that identifies the property to check.
217 * Checks whether a property needs a probe. This might be because
218 * the property wasn't initialized before, or because host setup
219 * changed. This might be, for example, because a new device was
220 * added, and thus device probing needs to be refreshed to display
223 * Returns: TRUE if the property needs a new probe, FALSE if not.
226 gst_property_probe_needs_probe (GstPropertyProbe * probe,
227 const GParamSpec * pspec)
229 GstPropertyProbeInterface *iface;
231 g_return_val_if_fail (probe != NULL, FALSE);
232 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), FALSE);
233 g_return_val_if_fail (pspec != NULL, FALSE);
235 iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
237 if (iface->needs_probe)
238 return iface->needs_probe (probe, pspec->param_id, pspec);
244 * gst_property_probe_needs_probe_name:
245 * @probe: the #GstPropertyProbe object to which the given property belongs.
246 * @name: the name of the property to check.
248 * Same as gst_property_probe_needs_probe ().
250 * Returns: TRUE if the property needs a new probe, FALSE if not.
253 gst_property_probe_needs_probe_name (GstPropertyProbe * probe,
256 const GParamSpec *pspec;
258 g_return_val_if_fail (probe != NULL, FALSE);
259 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), FALSE);
260 g_return_val_if_fail (name != NULL, FALSE);
262 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name);
264 g_warning ("No such property %s", name);
268 return gst_property_probe_needs_probe (probe, pspec);
272 * gst_property_probe_get_values:
273 * @probe: the #GstPropertyProbe object.
274 * @pspec: the #GParamSpec property identifier.
276 * Gets the possible (probed) values for the given property,
277 * requires the property to have been probed before.
279 * Returns: A list of valid values for the given property.
282 gst_property_probe_get_values (GstPropertyProbe * probe,
283 const GParamSpec * pspec)
285 GstPropertyProbeInterface *iface;
287 g_return_val_if_fail (probe != NULL, NULL);
288 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), NULL);
289 g_return_val_if_fail (pspec != NULL, NULL);
291 iface = GST_PROPERTY_PROBE_GET_IFACE (probe);
293 if (iface->get_values)
294 return iface->get_values (probe, pspec->param_id, pspec);
300 * gst_property_probe_get_values_name:
301 * @probe: the #GstPropertyProbe object.
302 * @name: the name of the property to get values for.
304 * Same as gst_property_probe_get_values ().
306 * Returns: A list of valid values for the given property.
309 gst_property_probe_get_values_name (GstPropertyProbe * probe,
312 const GParamSpec *pspec;
314 g_return_val_if_fail (probe != NULL, NULL);
315 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), NULL);
316 g_return_val_if_fail (name != NULL, NULL);
318 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name);
320 g_warning ("No such property %s", name);
324 return gst_property_probe_get_values (probe, pspec);
328 * gst_property_probe_probe_and_get_values:
329 * @probe: the #GstPropertyProbe object.
330 * @pspec: The #GParamSpec property identifier.
332 * Check whether the given property requires a new probe. If so,
333 * fo the probe. After that, retrieve a value list. Meant as a
334 * utility function that wraps the above functions.
336 * Returns: the list of valid values for this property.
339 gst_property_probe_probe_and_get_values (GstPropertyProbe * probe,
340 const GParamSpec * pspec)
342 g_return_val_if_fail (probe != NULL, NULL);
343 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), NULL);
344 g_return_val_if_fail (pspec != NULL, NULL);
346 if (gst_property_probe_needs_probe (probe, pspec))
347 gst_property_probe_probe_property (probe, pspec);
349 return gst_property_probe_get_values (probe, pspec);
353 * gst_property_probe_probe_and_get_values_name:
354 * @probe: the #GstPropertyProbe object.
355 * @name: the name of the property to get values for.
357 * Same as gst_property_probe_probe_and_get_values ().
359 * Returns: the list of valid values for this property.
362 gst_property_probe_probe_and_get_values_name (GstPropertyProbe * probe,
365 const GParamSpec *pspec;
367 g_return_val_if_fail (probe != NULL, NULL);
368 g_return_val_if_fail (GST_IS_PROPERTY_PROBE (probe), NULL);
369 g_return_val_if_fail (name != NULL, NULL);
371 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (probe), name);
373 g_warning ("No such property %s", name);
377 return gst_property_probe_probe_and_get_values (probe, pspec);