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"
33 * @short_description: Interface for elements providing tuner operations
45 static void gst_tuner_class_init (GstTunerClass * klass);
47 static guint gst_tuner_signals[LAST_SIGNAL] = { 0 };
50 gst_tuner_get_type (void)
52 static GType gst_tuner_type = 0;
54 if (!gst_tuner_type) {
55 static const GTypeInfo gst_tuner_info = {
56 sizeof (GstTunerClass),
57 (GBaseInitFunc) gst_tuner_class_init,
67 gst_tuner_type = g_type_register_static (G_TYPE_INTERFACE,
68 "GstTuner", &gst_tuner_info, 0);
69 g_type_interface_add_prerequisite (gst_tuner_type,
70 GST_TYPE_IMPLEMENTS_INTERFACE);
73 return gst_tuner_type;
77 gst_tuner_class_init (GstTunerClass * klass)
79 static gboolean initialized = FALSE;
82 gst_tuner_signals[NORM_CHANGED] =
83 g_signal_new ("norm-changed",
84 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
85 G_STRUCT_OFFSET (GstTunerClass, norm_changed),
87 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_TUNER_NORM);
88 gst_tuner_signals[CHANNEL_CHANGED] =
89 g_signal_new ("channel-changed",
90 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
91 G_STRUCT_OFFSET (GstTunerClass, channel_changed),
93 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
94 GST_TYPE_TUNER_CHANNEL);
95 gst_tuner_signals[FREQUENCY_CHANGED] =
96 g_signal_new ("frequency-changed",
97 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
98 G_STRUCT_OFFSET (GstTunerClass, frequency_changed),
100 gst_interfaces_marshal_VOID__OBJECT_ULONG, G_TYPE_NONE, 2,
101 GST_TYPE_TUNER_CHANNEL, G_TYPE_ULONG);
102 gst_tuner_signals[SIGNAL_CHANGED] =
103 g_signal_new ("signal-changed",
104 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST,
105 G_STRUCT_OFFSET (GstTunerClass, signal_changed),
107 gst_interfaces_marshal_VOID__OBJECT_INT, G_TYPE_NONE, 2,
108 GST_TYPE_TUNER_CHANNEL, G_TYPE_INT);
113 /* default virtual functions */
114 klass->list_channels = NULL;
115 klass->set_channel = NULL;
116 klass->get_channel = NULL;
118 klass->list_norms = NULL;
119 klass->set_norm = NULL;
120 klass->get_norm = NULL;
122 klass->set_frequency = NULL;
123 klass->get_frequency = NULL;
124 klass->signal_strength = NULL;
128 * gst_tuner_list_channels:
129 * @tuner: the #GstTuner (a #GstElement) to get the channels from.
131 * Retrieve a list of channels (e.g. 'composite', 's-video', ...)
132 * from the given tuner object.
134 * Returns: a list of channels available on this tuner.
138 gst_tuner_list_channels (GstTuner * tuner)
140 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
142 if (klass->list_channels) {
143 return klass->list_channels (tuner);
150 * gst_tuner_set_channel:
151 * @tuner: the #GstTuner (a #GstElement) that owns the channel.
152 * @channel: the channel to tune to.
154 * Tunes the object to the given channel.
158 gst_tuner_set_channel (GstTuner * tuner, GstTunerChannel * channel)
160 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
162 if (klass->set_channel) {
163 klass->set_channel (tuner, channel);
168 * gst_Tuner_get_channel:
169 * @tuner: the #GstTuner (a #GstElement) to get the current channel from.
171 * Retrieve the current channel from the tuner.
173 * Returns: the current channel of the tuner object.
177 gst_tuner_get_channel (GstTuner * tuner)
179 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
181 if (klass->get_channel) {
182 return klass->get_channel (tuner);
189 * gst_tuner_get_norms_list:
190 * @tuner: the #GstTuner (*a #GstElement) to get the list of norms from.
192 * Retrieve a list of available norms on the currently tuned channel
193 * from the given tuner object.
195 * Returns: A list of norms available on the current channel for this
200 gst_tuner_list_norms (GstTuner * tuner)
202 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
204 if (klass->list_norms) {
205 return klass->list_norms (tuner);
212 * gst_tuner_set_norm:
213 * @tuner: the #GstTuner (a #GstElement) to set the norm on.
214 * @norm: the norm to use for the current channel.
216 * Changes the video norm on this tuner to the given norm.
220 gst_tuner_set_norm (GstTuner * tuner, GstTunerNorm * norm)
222 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
224 if (klass->set_norm) {
225 klass->set_norm (tuner, norm);
230 * gst_tuner_get_norm:
231 * @tuner: the #GstTuner (a #GstElement) to get the current norm from.
233 * Get the current video norm from the given tuner object for the
234 * currently selected channel.
236 * Returns: the current norm.
240 gst_tuner_get_norm (GstTuner * tuner)
242 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
244 if (klass->get_norm) {
245 return klass->get_norm (tuner);
252 * gst_tuner_set_frequency:
253 * @tuner: the #Gsttuner (a #GstElement) that owns the given channel.
254 * @channel: the #GstTunerChannel to set the frequency on.
255 * @frequency: the frequency to tune in to.
257 * Sets a tuning frequency on the given tuner/channel. Note that this
258 * requires the given channel to be a "tuning" channel, which can be
259 * checked using GST_TUNER_CHANNEL_HAS_FLAG (), with the proper flag
260 * being GST_TUNER_CHANNEL_FREQUENCY.
264 gst_tuner_set_frequency (GstTuner * tuner,
265 GstTunerChannel * channel, gulong frequency)
267 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
269 g_return_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
270 GST_TUNER_CHANNEL_FREQUENCY));
272 if (klass->set_frequency) {
273 klass->set_frequency (tuner, channel, frequency);
278 * gst_tuner_get_frequency:
279 * @tuner: the #GstTuner (a #GstElement) that owns the given channel.
280 * @channel: the #GstTunerChannel to retrieve the frequency from.
282 * Retrieve the current frequency from the given channel. The same
283 * applies as for set_frequency (): check the flag.
285 * Returns: the current frequency, or 0 on error.
289 gst_tuner_get_frequency (GstTuner * tuner, GstTunerChannel * channel)
291 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
293 g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
294 GST_TUNER_CHANNEL_FREQUENCY), 0);
296 if (klass->get_frequency) {
297 return klass->get_frequency (tuner, channel);
304 * gst_tuner_get_signal_strength:
305 * @tuner: the #GstTuner (a #GstElement) that owns the given channel.
306 * @channel: the #GstTunerChannel to get the signal strength from.
308 * get the strength of the signal on this channel. Note that this
309 * requires the current channel to be a "tuning" channel, e.g. a
310 * channel on which frequency can be set. This can be checked using
311 * GST_TUNER_CHANNEL_HAS_FLAG (), and the appropriate flag to check
312 * for is GST_TUNER_CHANNEL_FREQUENCY.
314 * Returns: signal strength, or 0 on error.
318 gst_tuner_signal_strength (GstTuner * tuner, GstTunerChannel * channel)
320 GstTunerClass *klass = GST_TUNER_GET_CLASS (tuner);
322 g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel,
323 GST_TUNER_CHANNEL_FREQUENCY), 0);
325 if (klass->signal_strength) {
326 return klass->signal_strength (tuner, channel);
333 gst_tuner_find_norm_by_name (GstTuner * tuner, gchar * norm)
337 g_return_val_if_fail (GST_TUNER (tuner), NULL);
338 g_return_val_if_fail (norm != NULL, NULL);
340 walk = (GList *) gst_tuner_list_norms (tuner);
342 if (strcmp (GST_TUNER_NORM (walk->data)->label, norm) == 0)
343 return GST_TUNER_NORM (walk->data);
344 walk = g_list_next (walk);
350 gst_tuner_find_channel_by_name (GstTuner * tuner, gchar * channel)
354 g_return_val_if_fail (GST_TUNER (tuner), NULL);
355 g_return_val_if_fail (channel != NULL, NULL);
357 walk = (GList *) gst_tuner_list_channels (tuner);
359 if (strcmp (GST_TUNER_CHANNEL (walk->data)->label, channel) == 0)
360 return GST_TUNER_CHANNEL (walk->data);
361 walk = g_list_next (walk);
367 gst_tuner_channel_changed (GstTuner * tuner, GstTunerChannel * channel)
369 g_return_if_fail (GST_IS_TUNER (tuner));
370 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel));
372 g_signal_emit (G_OBJECT (tuner),
373 gst_tuner_signals[CHANNEL_CHANGED], 0, channel);
377 gst_tuner_norm_changed (GstTuner * tuner, GstTunerNorm * norm)
379 g_return_if_fail (GST_IS_TUNER (tuner));
380 g_return_if_fail (GST_IS_TUNER_NORM (norm));
382 g_signal_emit (G_OBJECT (tuner), gst_tuner_signals[NORM_CHANGED], 0, norm);
386 gst_tuner_frequency_changed (GstTuner * tuner,
387 GstTunerChannel * channel, gulong frequency)
389 g_return_if_fail (GST_IS_TUNER (tuner));
390 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel));
392 g_signal_emit (G_OBJECT (tuner),
393 gst_tuner_signals[FREQUENCY_CHANGED], 0, channel, frequency);
395 g_signal_emit_by_name (G_OBJECT (channel), "frequency_changed", frequency);
399 gst_tuner_signal_changed (GstTuner * tuner,
400 GstTunerChannel * channel, gint signal)
402 g_return_if_fail (GST_IS_TUNER (tuner));
403 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel));
405 g_signal_emit (G_OBJECT (tuner),
406 gst_tuner_signals[SIGNAL_CHANGED], 0, channel, signal);
408 g_signal_emit_by_name (G_OBJECT (channel), "signal_changed", signal);