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/videodev2.h>
29
typedef struct _V4L2RadioDev V4L2RadioDev;
32
struct _RadioDev parent;
41
v4l2_radio_init(RadioDev *radio_dev, char *device)
43
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
44
struct v4l2_capability caps;
45
struct v4l2_tuner tuner;
47
if ((dev->fd = open(device, O_RDONLY))< 0)
50
/* does this device provide a tuner? */
51
memset(&caps, 0, sizeof(caps));
52
if (ioctl(dev->fd, VIDIOC_QUERYCAP, &caps) < 0) {
53
perror("VIDIOC_QUERYCAP");
56
if ((caps.capabilities & V4L2_CAP_TUNER) == 0) {
57
fprintf(stderr, "Not a radio tuner\n");
62
memset(&tuner, 0, sizeof(tuner));
64
if (ioctl(dev->fd, VIDIOC_G_TUNER, &tuner) < 0) {
65
perror("VIDIOC_G_TUNER");
68
if (tuner.type != V4L2_TUNER_RADIO) {
69
fprintf(stderr, "Not a radio tuner\n");
72
/* Does this tuner expect data in 62.5Hz or 62.5kHz multiples? */
73
dev->radio_rangelow = tuner.rangelow;
74
dev->radio_rangehigh = tuner.rangehigh;
75
if ((tuner.capability & V4L2_TUNER_CAP_LOW) != 0)
76
dev->freq_fact = 16000;
90
v4l2_radio_is_init(RadioDev *radio_dev)
92
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
93
return (dev->fd >= 0);
97
v4l2_radio_set_freq(RadioDev *radio_dev, float frequency)
99
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
100
struct v4l2_frequency freq;
105
memset(&freq, 0, sizeof(freq));
107
freq.type = V4L2_TUNER_RADIO;
108
freq.frequency = frequency * dev->freq_fact;
110
if (freq.frequency < dev->radio_rangelow ||
111
freq.frequency > dev->radio_rangehigh)
113
if (ioctl(dev->fd, VIDIOC_S_FREQUENCY, &freq) < 0)
114
perror("VIDIOC_S_FREQUENCY");
118
v4l2_radio_mute(RadioDev *radio_dev, int mute)
120
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
121
struct v4l2_control control;
126
memset(&control, 0, sizeof(control));
127
control.id = V4L2_CID_AUDIO_MUTE;
128
control.value = mute;
129
if (ioctl(dev->fd, VIDIOC_S_CTRL, &control) < 0)
130
perror("VIDIOC_S_CTRL");
134
v4l2_radio_get_stereo(RadioDev *radio_dev)
136
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
137
struct v4l2_tuner tuner;
142
memset(&tuner, 0, sizeof(tuner));
144
if (ioctl(dev->fd, VIDIOC_G_TUNER, &tuner) < 0) {
145
perror("VIDIOC_G_TUNER");
149
return tuner.audmode == V4L2_TUNER_MODE_STEREO;
153
v4l2_radio_get_signal(RadioDev *radio_dev)
155
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
156
struct v4l2_tuner tuner;
161
memset(&tuner, 0, sizeof(tuner));
163
if (ioctl(dev->fd, VIDIOC_G_TUNER, &tuner) < 0) {
164
perror("VIDIOC_G_TUNER");
168
return tuner.signal >> 13;
172
v4l2_radio_finalize(RadioDev *radio_dev)
174
V4L2RadioDev *dev = (V4L2RadioDev*)radio_dev;
182
v4l2_radio_dev_new (void)
185
V4L2RadioDev *v4l2_dev;
187
v4l2_dev = malloc (sizeof (V4L2RadioDev));
190
dev = (RadioDev*)v4l2_dev;
191
dev->init = v4l2_radio_init;
192
dev->is_init = v4l2_radio_is_init;
193
dev->set_freq = v4l2_radio_set_freq;
194
dev->mute = v4l2_radio_mute;
195
dev->get_stereo = v4l2_radio_get_stereo;
196
dev->get_signal = v4l2_radio_get_signal;
197
dev->finalize = v4l2_radio_finalize;