2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU Library General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include <sys/ioctl.h>
26
#include <linux/videodev.h>
29
typedef struct _V4L1RadioDev V4L1RadioDev;
32
struct _RadioDev parent;
39
v4l1_radio_init(RadioDev *radio_dev, char *device)
41
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
42
struct video_tuner tuner;
44
if ((dev->fd = open(device, O_RDONLY)) < 0)
48
if (ioctl (dev->fd, VIDIOCGTUNER, &tuner) < 0)
52
if ((tuner.flags & VIDEO_TUNER_LOW) == 0)
55
dev->freq_fact = 16000;
61
int v4l1_radio_is_init(RadioDev *radio_dev)
63
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
64
return (dev->fd >= 0);
68
v4l1_radio_set_freq(RadioDev *radio_dev, float freq)
70
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
76
ifreq = (freq+1.0/32)*dev->freq_fact;
78
printf("Setting to %i (= %.2f)\n", ifreq, freq);
81
/* FIXME: Do we need really need these checks? */
82
if ((freq > 108) || (freq < 65))
85
assert ((freq <= 108) && (freq > 65));
87
if (ioctl(dev->fd, VIDIOCSFREQ, &ifreq) < 0)
88
perror ("VIDIOCSFREQ");
92
v4l1_radio_mute(RadioDev *radio_dev, int mute)
94
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
95
struct video_audio vid_aud;
100
if (ioctl(dev->fd, VIDIOCGAUDIO, &vid_aud)) {
101
perror("VIDIOCGAUDIO");
102
memset (&vid_aud, 0, sizeof (struct video_audio));
105
vid_aud.flags |= VIDEO_AUDIO_MUTE;
107
vid_aud.volume = 0xFFFF;
108
vid_aud.flags &= ~VIDEO_AUDIO_MUTE;
109
vid_aud.mode = VIDEO_SOUND_STEREO;
111
if (ioctl(dev->fd, VIDIOCSAUDIO, &vid_aud))
112
perror("VIDIOCSAUDIO");
116
v4l1_radio_get_stereo(RadioDev *radio_dev)
118
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
119
struct video_audio va;
125
if (ioctl (dev->fd, VIDIOCGAUDIO, &va) < 0)
127
if (va.mode == VIDEO_SOUND_STEREO)
134
v4l1_radio_get_signal(RadioDev *radio_dev)
136
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
137
struct video_tuner vt;
143
memset(&vt,0,sizeof(vt));
144
ioctl (dev->fd, VIDIOCGTUNER, &vt);
145
signal=vt.signal>>13;
151
v4l1_radio_finalize(RadioDev *radio_dev)
153
V4L1RadioDev *dev = (V4L1RadioDev*)radio_dev;
161
v4l1_radio_dev_new (void)
164
V4L1RadioDev *v4l1_dev;
166
v4l1_dev = malloc(sizeof(V4L1RadioDev));
168
dev = (RadioDev*)v4l1_dev;
170
dev->init = v4l1_radio_init;
171
dev->is_init = v4l1_radio_is_init;
172
dev->set_freq = v4l1_radio_set_freq;
173
dev->mute = v4l1_radio_mute;
174
dev->get_stereo = v4l1_radio_get_stereo;
175
dev->get_signal = v4l1_radio_get_signal;
176
dev->finalize = v4l1_radio_finalize;