|
1 /* GStreamer Tuner |
|
2 * Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net> |
|
3 * |
|
4 * tuner.c: tuner 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 "tuner.h" |
|
27 #include "interfaces-marshal.h" |
|
28 |
|
29 #include <string.h> |
|
30 |
|
31 /** |
|
32 * SECTION:gsttuner |
|
33 * @short_description: Interface for elements providing tuner operations |
|
34 */ |
|
35 |
|
36 enum |
|
37 { |
|
38 NORM_CHANGED, |
|
39 CHANNEL_CHANGED, |
|
40 FREQUENCY_CHANGED, |
|
41 SIGNAL_CHANGED, |
|
42 LAST_SIGNAL |
|
43 }; |
|
44 |
|
45 static void gst_tuner_class_init (GstTunerClass * klass); |
|
46 |
|
47 static guint gst_tuner_signals[LAST_SIGNAL] = { 0 }; |
|
48 #ifdef __SYMBIAN32__ |
|
49 EXPORT_C |
|
50 #endif |
|
51 |
|
52 |
|
53 GType |
|
54 gst_tuner_get_type (void) |
|
55 { |
|
56 static GType gst_tuner_type = 0; |
|
57 |
|
58 if (!gst_tuner_type) { |
|
59 static const GTypeInfo gst_tuner_info = { |
|
60 sizeof (GstTunerClass), |
|
61 (GBaseInitFunc) gst_tuner_class_init, |
|
62 NULL, |
|
63 NULL, |
|
64 NULL, |
|
65 NULL, |
|
66 0, |
|
67 0, |
|
68 NULL, |
|
69 }; |
|
70 |
|
71 gst_tuner_type = g_type_register_static (G_TYPE_INTERFACE, |
|
72 "GstTuner", &gst_tuner_info, 0); |
|
73 g_type_interface_add_prerequisite (gst_tuner_type, |
|
74 GST_TYPE_IMPLEMENTS_INTERFACE); |
|
75 } |
|
76 |
|
77 return gst_tuner_type; |
|
78 } |
|
79 |
|
80 static void |
|
81 gst_tuner_class_init (GstTunerClass * klass) |
|
82 { |
|
83 static gboolean initialized = FALSE; |
|
84 |
|
85 if (!initialized) { |
|
86 gst_tuner_signals[NORM_CHANGED] = |
|
87 g_signal_new ("norm-changed", |
|
88 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, |
|
89 G_STRUCT_OFFSET (GstTunerClass, norm_changed), |
|
90 NULL, NULL, |
|
91 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_TUNER_NORM); |
|
92 gst_tuner_signals[CHANNEL_CHANGED] = |
|
93 g_signal_new ("channel-changed", |
|
94 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, |
|
95 G_STRUCT_OFFSET (GstTunerClass, channel_changed), |
|
96 NULL, NULL, |
|
97 g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, |
|
98 GST_TYPE_TUNER_CHANNEL); |
|
99 gst_tuner_signals[FREQUENCY_CHANGED] = |
|
100 g_signal_new ("frequency-changed", |
|
101 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, |
|
102 G_STRUCT_OFFSET (GstTunerClass, frequency_changed), |
|
103 NULL, NULL, |
|
104 gst_interfaces_marshal_VOID__OBJECT_ULONG, G_TYPE_NONE, 2, |
|
105 GST_TYPE_TUNER_CHANNEL, G_TYPE_ULONG); |
|
106 gst_tuner_signals[SIGNAL_CHANGED] = |
|
107 g_signal_new ("signal-changed", |
|
108 GST_TYPE_TUNER, G_SIGNAL_RUN_LAST, |
|
109 G_STRUCT_OFFSET (GstTunerClass, signal_changed), |
|
110 NULL, NULL, |
|
111 gst_interfaces_marshal_VOID__OBJECT_INT, G_TYPE_NONE, 2, |
|
112 GST_TYPE_TUNER_CHANNEL, G_TYPE_INT); |
|
113 |
|
114 initialized = TRUE; |
|
115 } |
|
116 |
|
117 /* default virtual functions */ |
|
118 klass->list_channels = NULL; |
|
119 klass->set_channel = NULL; |
|
120 klass->get_channel = NULL; |
|
121 |
|
122 klass->list_norms = NULL; |
|
123 klass->set_norm = NULL; |
|
124 klass->get_norm = NULL; |
|
125 |
|
126 klass->set_frequency = NULL; |
|
127 klass->get_frequency = NULL; |
|
128 klass->signal_strength = NULL; |
|
129 } |
|
130 |
|
131 /** |
|
132 * gst_tuner_list_channels: |
|
133 * @tuner: the #GstTuner (a #GstElement) to get the channels from. |
|
134 * |
|
135 * Retrieve a list of channels (e.g. 'composite', 's-video', ...) |
|
136 * from the given tuner object. |
|
137 * |
|
138 * Returns: a list of channels available on this tuner. |
|
139 */ |
|
140 #ifdef __SYMBIAN32__ |
|
141 EXPORT_C |
|
142 #endif |
|
143 |
|
144 |
|
145 const GList * |
|
146 gst_tuner_list_channels (GstTuner * tuner) |
|
147 { |
|
148 GstTunerClass *klass; |
|
149 |
|
150 g_return_val_if_fail (GST_IS_TUNER (tuner), NULL); |
|
151 |
|
152 klass = GST_TUNER_GET_CLASS (tuner); |
|
153 if (klass->list_channels) { |
|
154 return klass->list_channels (tuner); |
|
155 } |
|
156 |
|
157 return NULL; |
|
158 } |
|
159 |
|
160 /** |
|
161 * gst_tuner_set_channel: |
|
162 * @tuner: the #GstTuner (a #GstElement) that owns the channel. |
|
163 * @channel: the channel to tune to. |
|
164 * |
|
165 * Tunes the object to the given channel. |
|
166 */ |
|
167 #ifdef __SYMBIAN32__ |
|
168 EXPORT_C |
|
169 #endif |
|
170 |
|
171 |
|
172 void |
|
173 gst_tuner_set_channel (GstTuner * tuner, GstTunerChannel * channel) |
|
174 { |
|
175 GstTunerClass *klass; |
|
176 |
|
177 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
178 |
|
179 klass = GST_TUNER_GET_CLASS (tuner); |
|
180 if (klass->set_channel) { |
|
181 klass->set_channel (tuner, channel); |
|
182 } |
|
183 } |
|
184 |
|
185 /** |
|
186 * gst_Tuner_get_channel: |
|
187 * @tuner: the #GstTuner (a #GstElement) to get the current channel from. |
|
188 * |
|
189 * Retrieve the current channel from the tuner. |
|
190 * |
|
191 * Returns: the current channel of the tuner object. |
|
192 */ |
|
193 #ifdef __SYMBIAN32__ |
|
194 EXPORT_C |
|
195 #endif |
|
196 |
|
197 |
|
198 GstTunerChannel * |
|
199 gst_tuner_get_channel (GstTuner * tuner) |
|
200 { |
|
201 GstTunerClass *klass; |
|
202 |
|
203 g_return_val_if_fail (GST_IS_TUNER (tuner), NULL); |
|
204 |
|
205 klass = GST_TUNER_GET_CLASS (tuner); |
|
206 if (klass->get_channel) { |
|
207 return klass->get_channel (tuner); |
|
208 } |
|
209 |
|
210 return NULL; |
|
211 } |
|
212 |
|
213 /** |
|
214 * gst_tuner_get_norms_list: |
|
215 * @tuner: the #GstTuner (*a #GstElement) to get the list of norms from. |
|
216 * |
|
217 * Retrieve a list of available norms on the currently tuned channel |
|
218 * from the given tuner object. |
|
219 * |
|
220 * Returns: A list of norms available on the current channel for this |
|
221 * tuner object. |
|
222 */ |
|
223 #ifdef __SYMBIAN32__ |
|
224 EXPORT_C |
|
225 #endif |
|
226 |
|
227 |
|
228 const GList * |
|
229 gst_tuner_list_norms (GstTuner * tuner) |
|
230 { |
|
231 GstTunerClass *klass; |
|
232 |
|
233 g_return_val_if_fail (GST_IS_TUNER (tuner), NULL); |
|
234 |
|
235 klass = GST_TUNER_GET_CLASS (tuner); |
|
236 if (klass->list_norms) { |
|
237 return klass->list_norms (tuner); |
|
238 } |
|
239 |
|
240 return NULL; |
|
241 } |
|
242 |
|
243 /** |
|
244 * gst_tuner_set_norm: |
|
245 * @tuner: the #GstTuner (a #GstElement) to set the norm on. |
|
246 * @norm: the norm to use for the current channel. |
|
247 * |
|
248 * Changes the video norm on this tuner to the given norm. |
|
249 */ |
|
250 #ifdef __SYMBIAN32__ |
|
251 EXPORT_C |
|
252 #endif |
|
253 |
|
254 |
|
255 void |
|
256 gst_tuner_set_norm (GstTuner * tuner, GstTunerNorm * norm) |
|
257 { |
|
258 GstTunerClass *klass; |
|
259 |
|
260 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
261 |
|
262 klass = GST_TUNER_GET_CLASS (tuner); |
|
263 if (klass->set_norm) { |
|
264 klass->set_norm (tuner, norm); |
|
265 } |
|
266 } |
|
267 |
|
268 /** |
|
269 * gst_tuner_get_norm: |
|
270 * @tuner: the #GstTuner (a #GstElement) to get the current norm from. |
|
271 * |
|
272 * Get the current video norm from the given tuner object for the |
|
273 * currently selected channel. |
|
274 * |
|
275 * Returns: the current norm. |
|
276 */ |
|
277 #ifdef __SYMBIAN32__ |
|
278 EXPORT_C |
|
279 #endif |
|
280 |
|
281 |
|
282 GstTunerNorm * |
|
283 gst_tuner_get_norm (GstTuner * tuner) |
|
284 { |
|
285 GstTunerClass *klass; |
|
286 |
|
287 g_return_val_if_fail (GST_IS_TUNER (tuner), NULL); |
|
288 |
|
289 klass = GST_TUNER_GET_CLASS (tuner); |
|
290 if (klass->get_norm) { |
|
291 return klass->get_norm (tuner); |
|
292 } |
|
293 |
|
294 return NULL; |
|
295 } |
|
296 |
|
297 /** |
|
298 * gst_tuner_set_frequency: |
|
299 * @tuner: the #Gsttuner (a #GstElement) that owns the given channel. |
|
300 * @channel: the #GstTunerChannel to set the frequency on. |
|
301 * @frequency: the frequency to tune in to. |
|
302 * |
|
303 * Sets a tuning frequency on the given tuner/channel. Note that this |
|
304 * requires the given channel to be a "tuning" channel, which can be |
|
305 * checked using GST_TUNER_CHANNEL_HAS_FLAG (), with the proper flag |
|
306 * being GST_TUNER_CHANNEL_FREQUENCY. |
|
307 */ |
|
308 #ifdef __SYMBIAN32__ |
|
309 EXPORT_C |
|
310 #endif |
|
311 |
|
312 |
|
313 void |
|
314 gst_tuner_set_frequency (GstTuner * tuner, |
|
315 GstTunerChannel * channel, gulong frequency) |
|
316 { |
|
317 GstTunerClass *klass; |
|
318 |
|
319 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
320 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); |
|
321 g_return_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel, |
|
322 GST_TUNER_CHANNEL_FREQUENCY)); |
|
323 |
|
324 klass = GST_TUNER_GET_CLASS (tuner); |
|
325 if (klass->set_frequency) { |
|
326 klass->set_frequency (tuner, channel, frequency); |
|
327 } |
|
328 } |
|
329 |
|
330 /** |
|
331 * gst_tuner_get_frequency: |
|
332 * @tuner: the #GstTuner (a #GstElement) that owns the given channel. |
|
333 * @channel: the #GstTunerChannel to retrieve the frequency from. |
|
334 * |
|
335 * Retrieve the current frequency from the given channel. The same |
|
336 * applies as for set_frequency (): check the flag. |
|
337 * |
|
338 * Returns: the current frequency, or 0 on error. |
|
339 */ |
|
340 #ifdef __SYMBIAN32__ |
|
341 EXPORT_C |
|
342 #endif |
|
343 |
|
344 |
|
345 gulong |
|
346 gst_tuner_get_frequency (GstTuner * tuner, GstTunerChannel * channel) |
|
347 { |
|
348 GstTunerClass *klass; |
|
349 |
|
350 g_return_val_if_fail (GST_IS_TUNER (tuner), 0); |
|
351 g_return_val_if_fail (GST_IS_TUNER_CHANNEL (channel), 0); |
|
352 g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel, |
|
353 GST_TUNER_CHANNEL_FREQUENCY), 0); |
|
354 |
|
355 klass = GST_TUNER_GET_CLASS (tuner); |
|
356 |
|
357 if (klass->get_frequency) { |
|
358 return klass->get_frequency (tuner, channel); |
|
359 } |
|
360 |
|
361 return 0; |
|
362 } |
|
363 |
|
364 /** |
|
365 * gst_tuner_get_signal_strength: |
|
366 * @tuner: the #GstTuner (a #GstElement) that owns the given channel. |
|
367 * @channel: the #GstTunerChannel to get the signal strength from. |
|
368 * |
|
369 * get the strength of the signal on this channel. Note that this |
|
370 * requires the current channel to be a "tuning" channel, e.g. a |
|
371 * channel on which frequency can be set. This can be checked using |
|
372 * GST_TUNER_CHANNEL_HAS_FLAG (), and the appropriate flag to check |
|
373 * for is GST_TUNER_CHANNEL_FREQUENCY. |
|
374 * |
|
375 * Returns: signal strength, or 0 on error. |
|
376 */ |
|
377 #ifdef __SYMBIAN32__ |
|
378 EXPORT_C |
|
379 #endif |
|
380 |
|
381 |
|
382 gint |
|
383 gst_tuner_signal_strength (GstTuner * tuner, GstTunerChannel * channel) |
|
384 { |
|
385 GstTunerClass *klass; |
|
386 |
|
387 g_return_val_if_fail (GST_IS_TUNER (tuner), 0); |
|
388 g_return_val_if_fail (GST_IS_TUNER_CHANNEL (channel), 0); |
|
389 g_return_val_if_fail (GST_TUNER_CHANNEL_HAS_FLAG (channel, |
|
390 GST_TUNER_CHANNEL_FREQUENCY), 0); |
|
391 |
|
392 klass = GST_TUNER_GET_CLASS (tuner); |
|
393 if (klass->signal_strength) { |
|
394 return klass->signal_strength (tuner, channel); |
|
395 } |
|
396 |
|
397 return 0; |
|
398 } |
|
399 #ifdef __SYMBIAN32__ |
|
400 EXPORT_C |
|
401 #endif |
|
402 |
|
403 |
|
404 GstTunerNorm * |
|
405 gst_tuner_find_norm_by_name (GstTuner * tuner, gchar * norm) |
|
406 { |
|
407 GList *walk; |
|
408 |
|
409 g_return_val_if_fail (GST_IS_TUNER (tuner), NULL); |
|
410 g_return_val_if_fail (norm != NULL, NULL); |
|
411 |
|
412 walk = (GList *) gst_tuner_list_norms (tuner); |
|
413 while (walk) { |
|
414 if (strcmp (GST_TUNER_NORM (walk->data)->label, norm) == 0) |
|
415 return GST_TUNER_NORM (walk->data); |
|
416 walk = g_list_next (walk); |
|
417 } |
|
418 return NULL; |
|
419 } |
|
420 #ifdef __SYMBIAN32__ |
|
421 EXPORT_C |
|
422 #endif |
|
423 |
|
424 |
|
425 GstTunerChannel * |
|
426 gst_tuner_find_channel_by_name (GstTuner * tuner, gchar * channel) |
|
427 { |
|
428 GList *walk; |
|
429 |
|
430 g_return_val_if_fail (GST_IS_TUNER (tuner), NULL); |
|
431 g_return_val_if_fail (channel != NULL, NULL); |
|
432 |
|
433 walk = (GList *) gst_tuner_list_channels (tuner); |
|
434 while (walk) { |
|
435 if (strcmp (GST_TUNER_CHANNEL (walk->data)->label, channel) == 0) |
|
436 return GST_TUNER_CHANNEL (walk->data); |
|
437 walk = g_list_next (walk); |
|
438 } |
|
439 return NULL; |
|
440 } |
|
441 #ifdef __SYMBIAN32__ |
|
442 EXPORT_C |
|
443 #endif |
|
444 |
|
445 |
|
446 void |
|
447 gst_tuner_channel_changed (GstTuner * tuner, GstTunerChannel * channel) |
|
448 { |
|
449 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
450 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); |
|
451 |
|
452 g_signal_emit (G_OBJECT (tuner), |
|
453 gst_tuner_signals[CHANNEL_CHANGED], 0, channel); |
|
454 } |
|
455 #ifdef __SYMBIAN32__ |
|
456 EXPORT_C |
|
457 #endif |
|
458 |
|
459 |
|
460 void |
|
461 gst_tuner_norm_changed (GstTuner * tuner, GstTunerNorm * norm) |
|
462 { |
|
463 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
464 g_return_if_fail (GST_IS_TUNER_NORM (norm)); |
|
465 |
|
466 g_signal_emit (G_OBJECT (tuner), gst_tuner_signals[NORM_CHANGED], 0, norm); |
|
467 } |
|
468 #ifdef __SYMBIAN32__ |
|
469 EXPORT_C |
|
470 #endif |
|
471 |
|
472 |
|
473 void |
|
474 gst_tuner_frequency_changed (GstTuner * tuner, |
|
475 GstTunerChannel * channel, gulong frequency) |
|
476 { |
|
477 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
478 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); |
|
479 |
|
480 g_signal_emit (G_OBJECT (tuner), |
|
481 gst_tuner_signals[FREQUENCY_CHANGED], 0, channel, frequency); |
|
482 |
|
483 g_signal_emit_by_name (G_OBJECT (channel), "frequency_changed", frequency); |
|
484 } |
|
485 #ifdef __SYMBIAN32__ |
|
486 EXPORT_C |
|
487 #endif |
|
488 |
|
489 |
|
490 void |
|
491 gst_tuner_signal_changed (GstTuner * tuner, |
|
492 GstTunerChannel * channel, gint signal) |
|
493 { |
|
494 g_return_if_fail (GST_IS_TUNER (tuner)); |
|
495 g_return_if_fail (GST_IS_TUNER_CHANNEL (channel)); |
|
496 |
|
497 g_signal_emit (G_OBJECT (tuner), |
|
498 gst_tuner_signals[SIGNAL_CHANGED], 0, channel, signal); |
|
499 |
|
500 g_signal_emit_by_name (G_OBJECT (channel), "signal_changed", signal); |
|
501 } |