2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstprobe.h: Header for GstProbe object
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.
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.
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.
23 #include "gst_private.h"
27 _gst_probe_copy (const GstProbe * src)
29 return gst_probe_new (src->single_shot, src->callback, src->user_data);
33 gst_probe_get_type (void)
35 static GType gst_probe_type = 0;
37 if (!gst_probe_type) {
38 gst_probe_type = g_boxed_type_register_static ("GstProbe",
39 (GBoxedCopyFunc) _gst_probe_copy, (GBoxedFreeFunc) gst_probe_destroy);
42 return gst_probe_type;
48 * @single_shot: TRUE if a single shot probe is required
49 * @callback: the function to call when the probe is triggered
50 * @user_data: data passed to the callback function
52 * Create a new probe with the specified parameters. The single shot
53 * probe will be fired only once. It is the responsability of the
54 * application to free the single probe after it has been fired.
56 * Returns: a new #GstProbe.
59 gst_probe_new (gboolean single_shot,
60 GstProbeCallback callback, gpointer user_data)
64 g_return_val_if_fail (callback, NULL);
66 probe = g_new0 (GstProbe, 1);
68 probe->single_shot = single_shot;
69 probe->callback = callback;
70 probe->user_data = user_data;
72 GST_CAT_DEBUG (GST_CAT_PROBE, "created probe %p", probe);
79 * @probe: The probe to destroy
81 * Free the memory associated with the probe.
84 gst_probe_destroy (GstProbe * probe)
86 g_return_if_fail (probe);
89 memset (probe, 0xff, sizeof (*probe));
97 * @probe: The probe to trigger
98 * @data: the GstData that triggered the probe.
100 * Perform the callback associated with the given probe.
102 * Returns: the result of the probe callback function.
105 gst_probe_perform (GstProbe * probe, GstData ** data)
109 g_return_val_if_fail (probe, res);
111 GST_CAT_DEBUG (GST_CAT_PROBE, "performing probe %p", probe);
114 res = probe->callback (probe, data, probe->user_data);
120 * gst_probe_dispatcher_new:
122 * Create a new probe dispatcher
124 * Returns: a new probe dispatcher.
127 gst_probe_dispatcher_new (void)
129 GstProbeDispatcher *disp;
131 disp = g_new0 (GstProbeDispatcher, 1);
133 gst_probe_dispatcher_init (disp);
139 * gst_probe_dispatcher_destroy:
140 * @disp: the dispatcher to destroy
142 * Free the memory allocated by the probe dispatcher. All pending
143 * probes are removed first.
146 gst_probe_dispatcher_destroy (GstProbeDispatcher * disp)
148 g_return_if_fail (disp);
151 memset (disp, 0xff, sizeof (*disp));
154 /* FIXME, free pending probes */
159 * gst_probe_dispatcher_init:
160 * @disp: the dispatcher to initialize
162 * Initialize the dispatcher. Useful for statically allocated probe
166 gst_probe_dispatcher_init (GstProbeDispatcher * disp)
168 g_return_if_fail (disp);
175 * gst_probe_dispatcher_set_active:
176 * @disp: the dispatcher to activate
177 * @active: boolean to indicate activation or deactivation
179 * Activate or deactivate the given dispatcher
183 gst_probe_dispatcher_set_active (GstProbeDispatcher * disp, gboolean active)
185 g_return_if_fail (disp);
187 disp->active = active;
191 * gst_probe_dispatcher_add_probe:
192 * @disp: the dispatcher to add the probe to
193 * @probe: the probe to add to the dispatcher
195 * Adds the given probe to the dispatcher.
198 gst_probe_dispatcher_add_probe (GstProbeDispatcher * disp, GstProbe * probe)
200 g_return_if_fail (disp);
201 g_return_if_fail (probe);
203 GST_CAT_DEBUG (GST_CAT_PROBE, "adding probe %p to dispatcher %p", probe,
206 disp->probes = g_slist_prepend (disp->probes, probe);
210 * gst_probe_dispatcher_remove_probe:
211 * @disp: the dispatcher to remove the probe from
212 * @probe: the probe to remove from the dispatcher
214 * Removes the given probe from the dispatcher.
217 gst_probe_dispatcher_remove_probe (GstProbeDispatcher * disp, GstProbe * probe)
219 g_return_if_fail (disp);
220 g_return_if_fail (probe);
222 GST_CAT_DEBUG (GST_CAT_PROBE, "removing probe %p from dispatcher %p",
225 disp->probes = g_slist_remove (disp->probes, probe);
229 * gst_probe_dispatcher_dispatch:
230 * @disp: the dispatcher to dispatch
231 * @data: the data that triggered the dispatch
233 * Trigger all registered probes on the given dispatcher.
235 * Returns: TRUE if all callbacks returned TRUE.
238 gst_probe_dispatcher_dispatch (GstProbeDispatcher * disp, GstData ** data)
243 g_return_val_if_fail (disp, res);
245 GST_CAT_DEBUG (GST_CAT_PROBE, "dispatching data %p on dispatcher %p",
250 GstProbe *probe = (GstProbe *) walk->data;
252 walk = g_slist_next (walk);
254 res &= gst_probe_perform (probe, data);
255 /* it might have disappeared in the callback */
257 g_slist_find (disp->probes, probe) && probe->single_shot) {
258 disp->probes = g_slist_remove (disp->probes, probe);
260 /* do not free the probe here as it cannot be made threadsafe */
261 //gst_probe_destroy (probe);