2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * tuner.c: tuner 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.
27 #include "interfaces-marshal.h"
40 static void gst_tuner_class_init (GstTunerClass * klass);
42 static guint gst_tuner_signals[LAST_SIGNAL] = { 0 };
45 gst_tuner_get_type (void)
47 static GType gst_tuner_type = 0;
49 if (!gst_tuner_type) {
50 static const GTypeInfo gst_tuner_info = {
51 sizeof (GstTunerClass),
52 (GBaseInitFunc) gst_tuner_class_init,
62 gst_tuner_type = g_type_register_static (G_TYPE_INTERFACE,
63 "GstTuner", &gst_tuner_info, 0);
64 g_type_interface_add_prerequisite (gst_tuner_type,
65 GST_TYPE_IMPLEMENTS_INTERFACE);
68 return gst_tuner_type;
72 gst_tuner_class_init (GstTunerClass * klass)
74 static gboolean initialized = FALSE;
77 gst_tuner_signals[NORM_CHANGED] =
78 g_signal_new ("norm-changed",
79 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
80 G_STRUCT_OFFSET (GstTunerClass, norm_changed),
82 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_TUNER_NORM);
83 gst_tuner_signals[CHANNEL_CHANGED] =
84 g_signal_new ("channel-changed",
85 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
86 G_STRUCT_OFFSET (GstTunerClass, channel_changed),
88 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
89 GST_TYPE_TUNER_CHANNEL);
90 gst_tuner_signals[FREQUENCY_CHANGED] =
91 g_signal_new ("frequency-changed",
92 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
93 G_STRUCT_OFFSET (GstTunerClass, frequency_changed),
95 gst_interfaces_marshal_VOID__OBJECT_ULONG, G_TYPE_NONE, 2,
96 GST_TYPE_TUNER_CHANNEL, G_TYPE_ULONG);
97 gst_tuner_signals[SIGNAL_CHANGED] =
98 g_signal_new ("signal-changed",
99 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
100 G_STRUCT_OFFSET (GstTunerClass, signal_changed),
102 gst_interfaces_marshal_VOID__OBJECT_INT, G_TYPE_NONE, 2,
103 GST_TYPE_TUNER_CHANNEL, G_TYPE_INT);
108 /* default virtual functions */
109 klass->list_channels = NULL;
110 klass->set_channel = NULL;
111 klass->get_channel = NULL;
113 klass->list_norms = NULL;
114 klass->set_norm = NULL;
115 klass->get_norm = NULL;
117 klass->set_frequency = NULL;
118 klass->get_frequency = NULL;
119 klass->signal_strength = NULL;
123 * gst_tuner_list_channels:
124 * @tuner: the #GstTuner (a #GstElement) to get the channels from.
126 * Retrieve a list of channels (e.g. 'composite', 's-video', ...)
127 * from the given tuner object.
129 * Returns: a list of channels available on this tuner.
133 gst_tuner_list_channels (GstTuner * tuner)
135 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
137 if (klass->list_channels) {
138 return klass->list_channels (tuner);
145 * gst_tuner_set_channel:
146 * @tuner: the #GstTuner (a #GstElement) that owns the channel.
147 * @channel: the channel to tune to.
149 * Tunes the object to the given channel.
153 gst_tuner_set_channel (GstTuner * tuner, GstTunerChannel * channel)
155 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
157 if (klass->set_channel) {
158 klass->set_channel (tuner, channel);
163 * gst_Tuner_get_channel:
164 * @tuner: the #GstTuner (a #GstElement) to get the current channel from.
166 * Retrieve the current channel from the tuner.
168 * Returns: the current channel of the tuner object.
172 gst_tuner_get_channel (GstTuner * tuner)
174 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
176 if (klass->get_channel) {
177 return klass->get_channel (tuner);
184 * gst_tuner_get_norms_list:
185 * @tuner: the #GstTuner (*a #GstElement) to get the list of norms from.
187 * Retrieve a list of available norms on the currently tuned channel
188 * from the given tuner object.
190 * Returns: A list of norms available on the current channel for this
195 gst_tuner_list_norms (GstTuner * tuner)
197 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
199 if (klass->list_norms) {
200 return klass->list_norms (tuner);
207 * gst_tuner_set_norm:
208 * @tuner: the #GstTuner (a #GstElement) to set the norm on.
209 * @norm: the norm to use for the current channel.
211 * Changes the video norm on this tuner to the given norm.
215 gst_tuner_set_norm (GstTuner * tuner, GstTunerNorm * norm)
217 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
219 if (klass->set_norm) {
220 klass->set_norm (tuner, norm);
225 * gst_tuner_get_norm:
226 * @tuner: the #GstTuner (a #GstElement) to get the current norm from.
228 * Get the current video norm from the given tuner object for the
229 * currently selected channel.
231 * Returns: the current norm.
235 gst_tuner_get_norm (GstTuner * tuner)
237 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
239 if (klass->get_norm) {
240 return klass->get_norm (tuner);
247 * gst_tuner_set_frequency:
248 * @tuner: the #Gsttuner (a #GstElement) that owns the given channel.
249 * @channel: the #GstTunerChannel to set the frequency on.
250 * @frequency: the frequency to tune in to.
252 * Sets a tuning frequency on the given tuner/channel. Note that this
253 * requires the given channel to be a "tuning" channel, which can be
254 * checked using GST_TUNER_CHANNEL_HAS_FLAG (), with the proper flag
255 * being GST_TUNER_CHANNEL_FREQUENCY.
259 gst_tuner_set_frequency (GstTuner * tuner,
260 GstTunerChannel * channel, gulong frequency)
262 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
264 g_return_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
265 GST_TUNER_CHANNEL_FREQUENCY));
267 if (klass->set_frequency) {
268 klass->set_frequency (tuner, channel, frequency);
273 * gst_tuner_get_frequency:
274 * @tuner: the #GstTuner (a #GstElement) that owns the given channel.
275 * @channel: the #GstTunerChannel to retrieve the frequency from.
277 * Retrieve the current frequency from the given channel. The same
278 * applies as for set_frequency (): check the flag.
280 * Returns: the current frequency, or 0 on error.
284 gst_tuner_get_frequency (GstTuner * tuner, GstTunerChannel * channel)
286 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
288 g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
289 GST_TUNER_CHANNEL_FREQUENCY), 0);
291 if (klass->get_frequency) {
292 return klass->get_frequency (tuner, channel);
299 * gst_tuner_get_signal_strength:
300 * @tuner: the #GstTuner (a #GstElement) that owns the given channel.
301 * @channel: the #GstTunerChannel to get the signal strength from.
303 * get the strength of the signal on this channel. Note that this
304 * requires the current channel to be a "tuning" channel, e.g. a
305 * channel on which frequency can be set. This can be checked using
306 * GST_TUNER_CHANNEL_HAS_FLAG (), and the appropriate flag to check
307 * for is GST_TUNER_CHANNEL_FREQUENCY.
309 * Returns: signal strength, or 0 on error.
313 gst_tuner_signal_strength (GstTuner * tuner, GstTunerChannel * channel)
315 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
317 g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
318 GST_TUNER_CHANNEL_FREQUENCY), 0);
320 if (klass->signal_strength) {
321 return klass->signal_strength (tuner, channel);
328 gst_tuner_find_norm_by_name (GstTuner * tuner, gchar * norm)
332 g_return_val_if_fail (GST_TUNER (tuner), NULL);
333 g_return_val_if_fail (norm != NULL, NULL);
335 walk = (GList *) gst_tuner_list_norms (tuner);
337 if (strcmp (GST_TUNER_NORM (walk->data)->label, norm) == 0)
338 return GST_TUNER_NORM (walk->data);
339 walk = g_list_next (walk);
345 gst_tuner_find_channel_by_name (GstTuner * tuner, gchar * channel)
349 g_return_val_if_fail (GST_TUNER (tuner), NULL);
350 g_return_val_if_fail (channel != NULL, NULL);
352 walk = (GList *) gst_tuner_list_channels (tuner);
354 if (strcmp (GST_TUNER_CHANNEL (walk->data)->label, channel) == 0)
355 return GST_TUNER_CHANNEL (walk->data);
356 walk = g_list_next (walk);
362 gst_tuner_channel_changed (GstTuner * tuner, GstTunerChannel * channel)
364 g_return_if_fail (GST_IS_TUNER (tuner));
365 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel));
367 g_signal_emit (G_OBJECT (tuner),
368 gst_tuner_signals[CHANNEL_CHANGED], 0, channel);
372 gst_tuner_norm_changed (GstTuner * tuner, GstTunerNorm * norm)
374 g_return_if_fail (GST_IS_TUNER (tuner));
375 g_return_if_fail (GST_IS_TUNER_NORM (norm));
377 g_signal_emit (G_OBJECT (tuner), gst_tuner_signals[NORM_CHANGED], 0, norm);
381 gst_tuner_frequency_changed (GstTuner * tuner,
382 GstTunerChannel * channel, gulong frequency)
384 g_return_if_fail (GST_IS_TUNER (tuner));
385 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel));
387 g_signal_emit (G_OBJECT (tuner),
388 gst_tuner_signals[FREQUENCY_CHANGED], 0, channel, frequency);
390 g_signal_emit_by_name (G_OBJECT (channel), "frequency_changed", frequency);
394 gst_tuner_signal_changed (GstTuner * tuner,
395 GstTunerChannel * channel, gint signal)
397 g_return_if_fail (GST_IS_TUNER (tuner));
398 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel));
400 g_signal_emit (G_OBJECT (tuner),
401 gst_tuner_signals[SIGNAL_CHANGED], 0, channel, signal);
403 g_signal_emit_by_name (G_OBJECT (channel), "signal_changed", signal);