| 1 |
/* |
| 2 |
V4L2 API compliance input/output ioctl tests. |
| 3 |
|
| 4 |
Copyright (C) 2011 Hans Verkuil <[email protected]> |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program 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 |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program; if not, write to the Free Software |
| 18 |
Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <map> |
| 22 |
#include <set> |
| 23 |
#include <vector> |
| 24 |
|
| 25 |
#include <sys/types.h> |
| 26 |
|
| 27 |
#include "v4l2-compliance.h" |
| 28 |
|
| 29 |
#define MAGIC 0x1eadbeef |
| 30 |
|
| 31 |
static int checkEnumFreqBands(struct node *node, __u32 tuner, __u32 type, __u32 caps, |
| 32 |
__u32 rangelow, __u32 rangehigh) |
| 33 |
{ |
| 34 |
const __u32 band_caps = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_1HZ; |
| 35 |
__u32 caps_union = 0; |
| 36 |
std::vector<v4l2_frequency_band> bands; |
| 37 |
unsigned low = 0xffffffff; |
| 38 |
unsigned high = 0; |
| 39 |
unsigned i; |
| 40 |
|
| 41 |
for (i = 0; ; i++) { |
| 42 |
struct v4l2_frequency_band band; |
| 43 |
int ret; |
| 44 |
|
| 45 |
memset(band.reserved, 0, sizeof(band.reserved)); |
| 46 |
band.tuner = tuner; |
| 47 |
band.type = type; |
| 48 |
band.index = i; |
| 49 |
ret = doioctl(node, VIDIOC_ENUM_FREQ_BANDS, &band); |
| 50 |
if (ret == EINVAL && i) |
| 51 |
return 0; |
| 52 |
if (ret) |
| 53 |
return fail("couldn't get freq band\n"); |
| 54 |
caps_union |= band.capability; |
| 55 |
if ((caps & band_caps) != (band.capability & band_caps)) |
| 56 |
return fail("Inconsistent CAP_LOW/CAP_1HZ usage\n"); |
| 57 |
fail_on_test(band.rangelow == 0); |
| 58 |
fail_on_test(band.rangehigh < band.rangelow); |
| 59 |
fail_on_test(band.index != i); |
| 60 |
fail_on_test(band.type != type); |
| 61 |
fail_on_test(band.tuner != tuner); |
| 62 |
fail_on_test((band.capability & V4L2_TUNER_CAP_FREQ_BANDS) == 0); |
| 63 |
fail_on_test(check_0(band.reserved, sizeof(band.reserved))); |
| 64 |
if (band.rangelow < low) |
| 65 |
low = band.rangelow; |
| 66 |
if (band.rangehigh > high) |
| 67 |
high = band.rangehigh; |
| 68 |
bands.push_back(band); |
| 69 |
} |
| 70 |
fail_on_test(caps_union != caps); |
| 71 |
fail_on_test(low != rangelow); |
| 72 |
fail_on_test(high != rangehigh); |
| 73 |
|
| 74 |
// Check that the bands do not overlap or are adjacent |
| 75 |
for (i = 0; i < bands.size(); i++) |
| 76 |
for (unsigned j = 1; j < bands.size(); j++) |
| 77 |
fail_on_test(bands[i].rangehigh + 1 >= bands[j].rangelow && |
| 78 |
bands[i].rangelow - 1 <= bands[j].rangehigh); |
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
static int checkTuner(struct node *node, const struct v4l2_tuner &tuner, |
| 83 |
unsigned t, v4l2_std_id std) |
| 84 |
{ |
| 85 |
bool valid_modes[5] = { true, false, false, false, false }; |
| 86 |
bool tv = node->is_video || node->is_vbi || node->is_meta; |
| 87 |
bool hwseek_caps = tuner.capability & (V4L2_TUNER_CAP_HWSEEK_BOUNDED | |
| 88 |
V4L2_TUNER_CAP_HWSEEK_WRAP | V4L2_TUNER_CAP_HWSEEK_PROG_LIM); |
| 89 |
unsigned type = tv ? V4L2_TUNER_ANALOG_TV : V4L2_TUNER_RADIO; |
| 90 |
__u32 audmode; |
| 91 |
|
| 92 |
if (tuner.index != t) |
| 93 |
return fail("invalid index\n"); |
| 94 |
if (check_ustring(tuner.name, sizeof(tuner.name))) |
| 95 |
return fail("invalid name\n"); |
| 96 |
if (check_0(tuner.reserved, sizeof(tuner.reserved))) |
| 97 |
return fail("non-zero reserved fields\n"); |
| 98 |
if (node->is_sdr) { |
| 99 |
fail_on_test(tuner.type != V4L2_TUNER_SDR && tuner.type != V4L2_TUNER_RF); |
| 100 |
} else if (tuner.type != type) { |
| 101 |
return fail("invalid tuner type %d\n", tuner.type); |
| 102 |
} |
| 103 |
if (tv && (tuner.capability & V4L2_TUNER_CAP_RDS)) |
| 104 |
return fail("RDS for TV tuner?\n"); |
| 105 |
if (!tv && (tuner.capability & (V4L2_TUNER_CAP_NORM | |
| 106 |
V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2))) |
| 107 |
return fail("TV capabilities for radio tuner?\n"); |
| 108 |
if (tv && (tuner.capability & (V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_1HZ))) |
| 109 |
return fail("did not expect to see V4L2_TUNER_CAP_LOW/1HZ set for a tv tuner\n"); |
| 110 |
if (node->is_radio && !(tuner.capability & V4L2_TUNER_CAP_LOW)) |
| 111 |
return fail("V4L2_TUNER_CAP_LOW was not set for a radio tuner\n"); |
| 112 |
fail_on_test((tuner.capability & V4L2_TUNER_CAP_LOW) && |
| 113 |
(tuner.capability & V4L2_TUNER_CAP_1HZ)); |
| 114 |
if (node->is_sdr) |
| 115 |
fail_on_test(!(V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_1HZ)); |
| 116 |
fail_on_test(!(tuner.capability & V4L2_TUNER_CAP_FREQ_BANDS)); |
| 117 |
fail_on_test(!(node->g_caps() & V4L2_CAP_HW_FREQ_SEEK) && hwseek_caps); |
| 118 |
fail_on_test((node->g_caps() & V4L2_CAP_HW_FREQ_SEEK) && |
| 119 |
!(tuner.capability & (V4L2_TUNER_CAP_HWSEEK_BOUNDED | V4L2_TUNER_CAP_HWSEEK_WRAP))); |
| 120 |
if (tuner.rangelow > tuner.rangehigh) |
| 121 |
return fail("rangelow > rangehigh\n"); |
| 122 |
if (tuner.rangelow == 0 || tuner.rangehigh == 0xffffffff) |
| 123 |
return fail("invalid rangelow or rangehigh\n"); |
| 124 |
if (!(tuner.capability & V4L2_TUNER_CAP_STEREO) && |
| 125 |
(tuner.rxsubchans & V4L2_TUNER_SUB_STEREO)) |
| 126 |
return fail("stereo subchan, but no stereo caps?\n"); |
| 127 |
if (!(tuner.capability & V4L2_TUNER_CAP_LANG1) && |
| 128 |
(tuner.rxsubchans & V4L2_TUNER_SUB_LANG1)) |
| 129 |
return fail("lang1 subchan, but no lang1 caps?\n"); |
| 130 |
if (!(tuner.capability & V4L2_TUNER_CAP_LANG2) && |
| 131 |
(tuner.rxsubchans & V4L2_TUNER_SUB_LANG2)) |
| 132 |
return fail("lang2 subchan, but no lang2 caps?\n"); |
| 133 |
if (!(tuner.capability & V4L2_TUNER_CAP_RDS) && |
| 134 |
(tuner.rxsubchans & V4L2_TUNER_SUB_RDS)) |
| 135 |
return fail("RDS subchan, but no RDS caps?\n"); |
| 136 |
bool have_rds = tuner.capability & V4L2_TUNER_CAP_RDS; |
| 137 |
bool have_rds_method = tuner.capability & |
| 138 |
(V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_RDS_CONTROLS); |
| 139 |
if (have_rds ^ have_rds_method) |
| 140 |
return fail("V4L2_TUNER_CAP_RDS is set, but not V4L2_TUNER_CAP_RDS_* or vice versa\n"); |
| 141 |
fail_on_test(node->is_sdr && have_rds); |
| 142 |
if ((tuner.capability & V4L2_TUNER_CAP_RDS_BLOCK_IO) && |
| 143 |
!(node->g_caps() & V4L2_CAP_READWRITE)) |
| 144 |
return fail("V4L2_TUNER_CAP_RDS_BLOCK_IO is set, but not V4L2_CAP_READWRITE\n"); |
| 145 |
if (node->is_radio && !(tuner.capability & V4L2_TUNER_CAP_RDS_BLOCK_IO) && |
| 146 |
(node->g_caps() & V4L2_CAP_READWRITE)) |
| 147 |
return fail("V4L2_TUNER_CAP_RDS_BLOCK_IO is not set, but V4L2_CAP_READWRITE is\n"); |
| 148 |
if (std == V4L2_STD_NTSC_M && (tuner.rxsubchans & V4L2_TUNER_SUB_LANG1)) |
| 149 |
return fail("LANG1 subchan, but NTSC-M standard\n"); |
| 150 |
if (tuner.audmode > V4L2_TUNER_MODE_LANG1_LANG2) |
| 151 |
return fail("invalid audio mode\n"); |
| 152 |
if (!tv && tuner.audmode > V4L2_TUNER_MODE_STEREO) |
| 153 |
return fail("invalid audio mode for radio device\n"); |
| 154 |
if (tuner.signal > 65535) |
| 155 |
return fail("signal too large\n"); |
| 156 |
if (tuner.capability & V4L2_TUNER_CAP_STEREO) |
| 157 |
valid_modes[V4L2_TUNER_MODE_STEREO] = true; |
| 158 |
if (tuner.capability & V4L2_TUNER_CAP_LANG1) |
| 159 |
valid_modes[V4L2_TUNER_MODE_LANG1] = true; |
| 160 |
if (tuner.capability & V4L2_TUNER_CAP_LANG2) { |
| 161 |
valid_modes[V4L2_TUNER_MODE_LANG2] = true; |
| 162 |
valid_modes[V4L2_TUNER_MODE_LANG1_LANG2] = true; |
| 163 |
} |
| 164 |
for (audmode = 0; audmode < 5; audmode++) { |
| 165 |
struct v4l2_tuner tun = { 0 }; |
| 166 |
|
| 167 |
tun.index = tuner.index; |
| 168 |
tun.audmode = audmode; |
| 169 |
if (doioctl(node, VIDIOC_S_TUNER, &tun)) |
| 170 |
return fail("cannot set audmode %d\n", audmode); |
| 171 |
if (doioctl(node, VIDIOC_G_TUNER, &tun)) |
| 172 |
fail("failure to get new tuner audmode\n"); |
| 173 |
if (tun.audmode > V4L2_TUNER_MODE_LANG1_LANG2) |
| 174 |
return fail("invalid new audmode\n"); |
| 175 |
if (!valid_modes[tun.audmode]) |
| 176 |
return fail("accepted invalid audmode %d\n", audmode); |
| 177 |
} |
| 178 |
return checkEnumFreqBands(node, tuner.index, tuner.type, tuner.capability, |
| 179 |
tuner.rangelow, tuner.rangehigh); |
| 180 |
} |
| 181 |
|
| 182 |
int testTuner(struct node *node) |
| 183 |
{ |
| 184 |
struct v4l2_tuner tuner; |
| 185 |
v4l2_std_id std; |
| 186 |
unsigned t = 0; |
| 187 |
bool has_rds = false; |
| 188 |
int ret; |
| 189 |
|
| 190 |
if (doioctl(node, VIDIOC_G_STD, &std)) |
| 191 |
std = 0; |
| 192 |
|
| 193 |
for (;;) { |
| 194 |
memset(&tuner, 0xff, sizeof(tuner)); |
| 195 |
memset(tuner.reserved, 0, sizeof(tuner.reserved)); |
| 196 |
tuner.index = t; |
| 197 |
ret = doioctl(node, VIDIOC_G_TUNER, &tuner); |
| 198 |
if (ret == ENOTTY) |
| 199 |
return ret; |
| 200 |
if (ret == EINVAL) |
| 201 |
break; |
| 202 |
if (ret) |
| 203 |
return fail("couldn't get tuner %d\n", t); |
| 204 |
if (checkTuner(node, tuner, t, std)) |
| 205 |
return fail("invalid tuner %d\n", t); |
| 206 |
t++; |
| 207 |
node->tuners++; |
| 208 |
if (tuner.capability & V4L2_TUNER_CAP_RDS) |
| 209 |
has_rds = true; |
| 210 |
} |
| 211 |
memset(&tuner, 0, sizeof(tuner)); |
| 212 |
tuner.index = t; |
| 213 |
if (doioctl(node, VIDIOC_S_TUNER, &tuner) != EINVAL) |
| 214 |
return fail("could set invalid tuner %d\n", t); |
| 215 |
if (node->tuners && !(node->g_caps() & V4L2_CAP_TUNER)) |
| 216 |
return fail("tuners found, but no tuner capability set\n"); |
| 217 |
if (!node->tuners && (node->g_caps() & V4L2_CAP_TUNER)) |
| 218 |
return fail("no tuners found, but tuner capability set\n"); |
| 219 |
if (has_rds && !(node->g_caps() & V4L2_CAP_RDS_CAPTURE)) |
| 220 |
return fail("RDS tuner capability, but no RDS capture capability?\n"); |
| 221 |
if (!has_rds && (node->g_caps() & V4L2_CAP_RDS_CAPTURE)) |
| 222 |
return fail("No RDS tuner capability, but RDS capture capability?\n"); |
| 223 |
return 0; |
| 224 |
} |
| 225 |
|
| 226 |
int testTunerFreq(struct node *node) |
| 227 |
{ |
| 228 |
struct v4l2_frequency freq = { 0 }; |
| 229 |
enum v4l2_tuner_type last_type = V4L2_TUNER_ANALOG_TV; |
| 230 |
unsigned t; |
| 231 |
int ret; |
| 232 |
|
| 233 |
for (t = 0; t < node->tuners; t++) { |
| 234 |
struct v4l2_tuner tuner = { 0 }; |
| 235 |
|
| 236 |
tuner.index = t; |
| 237 |
ret = doioctl(node, VIDIOC_G_TUNER, &tuner); |
| 238 |
if (ret) |
| 239 |
return fail("could not get tuner %d\n", t); |
| 240 |
last_type = static_cast<enum v4l2_tuner_type>(tuner.type); |
| 241 |
memset(&freq, 0, sizeof(freq)); |
| 242 |
freq.tuner = t; |
| 243 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 244 |
if (ret) |
| 245 |
return fail("could not get frequency for tuner %d\n", t); |
| 246 |
if (check_0(freq.reserved, sizeof(freq.reserved))) |
| 247 |
return fail("reserved was not zeroed\n"); |
| 248 |
if (freq.type != V4L2_TUNER_RADIO && freq.type != V4L2_TUNER_ANALOG_TV && |
| 249 |
freq.type != V4L2_TUNER_SDR && freq.type != V4L2_TUNER_RF) |
| 250 |
return fail("returned invalid tuner type %d\n", freq.type); |
| 251 |
if (freq.type == V4L2_TUNER_RADIO && !(node->g_caps() & V4L2_CAP_RADIO)) |
| 252 |
return fail("radio tuner found but no radio capability set\n"); |
| 253 |
if ((freq.type == V4L2_TUNER_SDR || freq.type == V4L2_TUNER_RF) && |
| 254 |
!(node->g_caps() & V4L2_CAP_SDR_CAPTURE)) |
| 255 |
return fail("sdr tuner found but no sdr capture capability set\n"); |
| 256 |
if (freq.type != tuner.type) |
| 257 |
return fail("frequency tuner type and tuner type mismatch\n"); |
| 258 |
if (freq.tuner != t) |
| 259 |
return fail("frequency tuner field changed!\n"); |
| 260 |
if (freq.frequency == 0) |
| 261 |
return fail("frequency not set\n"); |
| 262 |
if (freq.frequency < tuner.rangelow || freq.frequency > tuner.rangehigh) |
| 263 |
warn("returned tuner %d frequency out of range (%d not in [%d...%d])\n", |
| 264 |
t, freq.frequency, tuner.rangelow, tuner.rangehigh); |
| 265 |
|
| 266 |
freq.type = static_cast<enum v4l2_tuner_type>(0); |
| 267 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 268 |
if (ret != EINVAL) |
| 269 |
return fail("did not return EINVAL when passed tuner type 0\n"); |
| 270 |
freq.type = tuner.type; |
| 271 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 272 |
if (ret) |
| 273 |
return fail("could not set current frequency\n"); |
| 274 |
freq.frequency = tuner.rangelow; |
| 275 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 276 |
if (ret) |
| 277 |
return fail("could not set rangelow frequency\n"); |
| 278 |
freq.frequency = tuner.rangehigh; |
| 279 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 280 |
if (ret) |
| 281 |
return fail("could not set rangehigh frequency\n"); |
| 282 |
freq.frequency = tuner.rangelow - 1; |
| 283 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 284 |
if (ret) |
| 285 |
return fail("could not set rangelow-1 frequency\n"); |
| 286 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 287 |
if (ret || freq.frequency != tuner.rangelow) |
| 288 |
return fail("frequency rangelow-1 wasn't mapped to rangelow\n"); |
| 289 |
freq.frequency = tuner.rangehigh + 1; |
| 290 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 291 |
if (ret) |
| 292 |
return fail("could not set rangehigh+1 frequency\n"); |
| 293 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 294 |
if (ret || freq.frequency != tuner.rangehigh) |
| 295 |
return fail("frequency rangehigh+1 wasn't mapped to rangehigh\n"); |
| 296 |
|
| 297 |
for (unsigned i = 0; ; i++) { |
| 298 |
struct v4l2_frequency_band band; |
| 299 |
|
| 300 |
memset(band.reserved, 0, sizeof(band.reserved)); |
| 301 |
band.tuner = t; |
| 302 |
band.type = tuner.type; |
| 303 |
band.index = i; |
| 304 |
ret = doioctl(node, VIDIOC_ENUM_FREQ_BANDS, &band); |
| 305 |
fail_on_test(i == 0 && ret); |
| 306 |
if (ret == EINVAL) |
| 307 |
break; |
| 308 |
fail_on_test(ret); |
| 309 |
|
| 310 |
freq.frequency = band.rangelow; |
| 311 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 312 |
if (ret) |
| 313 |
return fail("could not set rangelow frequency band\n"); |
| 314 |
freq.frequency = band.rangehigh; |
| 315 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 316 |
if (ret) |
| 317 |
return fail("could not set rangehigh frequency band\n"); |
| 318 |
freq.frequency = band.rangelow - 1; |
| 319 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 320 |
if (ret) |
| 321 |
return fail("could not set rangelow-1 frequency band\n"); |
| 322 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 323 |
if (ret || freq.frequency != band.rangelow) |
| 324 |
return fail("frequency band rangelow-1 wasn't mapped to rangelow\n"); |
| 325 |
freq.frequency = band.rangehigh + 1; |
| 326 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 327 |
if (ret) |
| 328 |
return fail("could not set rangehigh+1 frequency band\n"); |
| 329 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 330 |
if (ret || freq.frequency != band.rangehigh) |
| 331 |
return fail("frequency band rangehigh+1 wasn't mapped to rangehigh\n"); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
/* If this is a modulator device, then skip the remaining tests */ |
| 336 |
if (node->g_caps() & V4L2_CAP_MODULATOR) |
| 337 |
return 0; |
| 338 |
|
| 339 |
freq.tuner = t; |
| 340 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 341 |
if (ret != EINVAL && ret != ENOTTY) |
| 342 |
return fail("could get frequency for invalid tuner %d\n", t); |
| 343 |
freq.tuner = t; |
| 344 |
freq.type = last_type; |
| 345 |
// TV: 400 Mhz Radio: 100 MHz |
| 346 |
freq.frequency = last_type == V4L2_TUNER_ANALOG_TV ? 6400 : 1600000; |
| 347 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 348 |
if (ret != EINVAL && ret != ENOTTY) |
| 349 |
return fail("could set frequency for invalid tuner %d\n", t); |
| 350 |
return node->tuners ? 0 : ENOTTY; |
| 351 |
} |
| 352 |
|
| 353 |
int testTunerHwSeek(struct node *node) |
| 354 |
{ |
| 355 |
struct v4l2_hw_freq_seek seek; |
| 356 |
unsigned t; |
| 357 |
int ret; |
| 358 |
|
| 359 |
for (t = 0; t < node->tuners; t++) { |
| 360 |
struct v4l2_tuner tuner = { 0 }; |
| 361 |
|
| 362 |
tuner.index = t; |
| 363 |
ret = doioctl(node, VIDIOC_G_TUNER, &tuner); |
| 364 |
if (ret) |
| 365 |
return fail("could not get tuner %d\n", t); |
| 366 |
|
| 367 |
memset(&seek, 0, sizeof(seek)); |
| 368 |
seek.tuner = t; |
| 369 |
seek.type = V4L2_TUNER_RADIO; |
| 370 |
ret = doioctl(node, VIDIOC_S_HW_FREQ_SEEK, &seek); |
| 371 |
if (!(node->g_caps() & V4L2_CAP_HW_FREQ_SEEK) && ret != ENOTTY) |
| 372 |
return fail("hw seek supported but capability not set\n"); |
| 373 |
if (!node->is_radio && ret != ENOTTY) |
| 374 |
return fail("hw seek supported on a non-radio node?!\n"); |
| 375 |
if (!node->is_radio || !(node->g_caps() & V4L2_CAP_HW_FREQ_SEEK)) |
| 376 |
return ENOTTY; |
| 377 |
seek.type = V4L2_TUNER_ANALOG_TV; |
| 378 |
ret = doioctl(node, VIDIOC_S_HW_FREQ_SEEK, &seek); |
| 379 |
if (ret != EINVAL) |
| 380 |
return fail("hw seek accepted TV tuner\n"); |
| 381 |
seek.type = V4L2_TUNER_RADIO; |
| 382 |
seek.seek_upward = 1; |
| 383 |
ret = doioctl(node, VIDIOC_S_HW_FREQ_SEEK, &seek); |
| 384 |
if (ret == EINVAL && (tuner.capability & V4L2_TUNER_CAP_HWSEEK_BOUNDED)) |
| 385 |
return fail("hw bounded seek failed\n"); |
| 386 |
if (ret && ret != EINVAL && ret != ENODATA) |
| 387 |
return fail("hw bounded seek failed with error %d\n", ret); |
| 388 |
seek.wrap_around = 1; |
| 389 |
ret = doioctl(node, VIDIOC_S_HW_FREQ_SEEK, &seek); |
| 390 |
if (ret == EINVAL && (tuner.capability & V4L2_TUNER_CAP_HWSEEK_WRAP)) |
| 391 |
return fail("hw wrapped seek failed\n"); |
| 392 |
if (ret && ret != EINVAL && ret != ENODATA) |
| 393 |
return fail("hw wrapped seek failed with error %d\n", ret); |
| 394 |
if (check_0(seek.reserved, sizeof(seek.reserved))) |
| 395 |
return fail("non-zero reserved fields\n"); |
| 396 |
} |
| 397 |
memset(&seek, 0, sizeof(seek)); |
| 398 |
seek.tuner = node->tuners; |
| 399 |
seek.type = V4L2_TUNER_RADIO; |
| 400 |
ret = doioctl(node, VIDIOC_S_HW_FREQ_SEEK, &seek); |
| 401 |
if (ret != EINVAL && ret != ENOTTY) |
| 402 |
return fail("hw seek for invalid tuner didn't return EINVAL or ENOTTY\n"); |
| 403 |
return ret == ENOTTY ? ret : 0; |
| 404 |
} |
| 405 |
|
| 406 |
static int checkInput(struct node *node, const struct v4l2_input &descr, unsigned i) |
| 407 |
{ |
| 408 |
__u32 mask = (1 << node->audio_inputs) - 1; |
| 409 |
struct v4l2_selection sel; |
| 410 |
|
| 411 |
if (descr.index != i) |
| 412 |
return fail("invalid index\n"); |
| 413 |
if (check_ustring(descr.name, sizeof(descr.name))) |
| 414 |
return fail("invalid name\n"); |
| 415 |
if (descr.type != V4L2_INPUT_TYPE_TUNER && |
| 416 |
descr.type != V4L2_INPUT_TYPE_CAMERA && |
| 417 |
descr.type != V4L2_INPUT_TYPE_TOUCH) |
| 418 |
return fail("invalid type\n"); |
| 419 |
if (descr.type == V4L2_INPUT_TYPE_CAMERA && descr.tuner) |
| 420 |
return fail("invalid tuner\n"); |
| 421 |
if (descr.type == V4L2_INPUT_TYPE_TUNER && node->tuners == 0) |
| 422 |
return fail("no tuners found for tuner input\n"); |
| 423 |
if (!(descr.capabilities & V4L2_IN_CAP_STD) && descr.std) |
| 424 |
return fail("invalid std\n"); |
| 425 |
if ((descr.capabilities & V4L2_IN_CAP_STD) && !descr.std) |
| 426 |
return fail("std == 0\n"); |
| 427 |
memset(&sel, 0, sizeof(sel)); |
| 428 |
sel.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 429 |
sel.target = V4L2_SEL_TGT_NATIVE_SIZE; |
| 430 |
if (descr.capabilities & V4L2_IN_CAP_NATIVE_SIZE) { |
| 431 |
fail_on_test(doioctl(node, VIDIOC_G_SELECTION, &sel)); |
| 432 |
fail_on_test(doioctl(node, VIDIOC_S_SELECTION, &sel)); |
| 433 |
} else if (!doioctl(node, VIDIOC_G_SELECTION, &sel)) { |
| 434 |
fail_on_test(!doioctl(node, VIDIOC_S_SELECTION, &sel)); |
| 435 |
} |
| 436 |
if (descr.capabilities & ~0x7) |
| 437 |
return fail("invalid capabilities\n"); |
| 438 |
if (check_0(descr.reserved, sizeof(descr.reserved))) |
| 439 |
return fail("non-zero reserved fields\n"); |
| 440 |
if (descr.status & ~0x07070337) |
| 441 |
return fail("invalid status\n"); |
| 442 |
// These bits were for Digital TV, but Digital TV uses the |
| 443 |
// DVB API and no longer V4L2. |
| 444 |
if (descr.status & (V4L2_IN_ST_NO_EQU | V4L2_IN_ST_NO_CARRIER | |
| 445 |
V4L2_IN_ST_NO_ACCESS)) |
| 446 |
return fail("use of deprecated Digital TV status bits\n"); |
| 447 |
if (descr.audioset & ~mask) |
| 448 |
return fail("invalid audioset\n"); |
| 449 |
if (descr.tuner && descr.tuner >= node->tuners) |
| 450 |
return fail("invalid tuner\n"); |
| 451 |
return 0; |
| 452 |
} |
| 453 |
|
| 454 |
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
| 455 |
|
| 456 |
static int checkVividPixelArray(struct node *node) |
| 457 |
{ |
| 458 |
struct v4l2_query_ext_ctrl qextctrl = { |
| 459 |
.id = VIVID_CID_U8_PIXEL_ARRAY |
| 460 |
}; |
| 461 |
cv4l_fmt fmt; |
| 462 |
|
| 463 |
fail_on_test(node->query_ext_ctrl(qextctrl)); |
| 464 |
fail_on_test(node->g_fmt(fmt)); |
| 465 |
fail_on_test(qextctrl.nr_of_dims != 2); |
| 466 |
fail_on_test(qextctrl.dims[0] != DIV_ROUND_UP(fmt.g_height(), PIXEL_ARRAY_DIV)); |
| 467 |
fail_on_test(qextctrl.dims[1] != DIV_ROUND_UP(fmt.g_width(), PIXEL_ARRAY_DIV)); |
| 468 |
fail_on_test(qextctrl.minimum == qextctrl.default_value); |
| 469 |
|
| 470 |
struct v4l2_ext_control ctrl = { |
| 471 |
.id = VIVID_CID_U8_PIXEL_ARRAY |
| 472 |
}; |
| 473 |
struct v4l2_ext_controls ctrls = {}; |
| 474 |
|
| 475 |
ctrl.size = qextctrl.elems * qextctrl.elem_size; |
| 476 |
ctrl.p_u8 = new unsigned char[ctrl.size]; |
| 477 |
ctrls.count = 1; |
| 478 |
ctrls.controls = &ctrl; |
| 479 |
fail_on_test(node->g_ext_ctrls(ctrls)); |
| 480 |
for (unsigned i = 0; i < qextctrl.elems; i++) { |
| 481 |
fail_on_test(ctrl.p_u8[i] != qextctrl.default_value); |
| 482 |
ctrl.p_u8[i] = qextctrl.minimum; |
| 483 |
} |
| 484 |
fail_on_test(node->s_ext_ctrls(ctrls)); |
| 485 |
fail_on_test(node->g_ext_ctrls(ctrls)); |
| 486 |
for (unsigned i = 0; i < qextctrl.elems; i++) { |
| 487 |
fail_on_test(ctrl.p_u8[i] != qextctrl.minimum); |
| 488 |
} |
| 489 |
delete [] ctrl.p_u8; |
| 490 |
return 0; |
| 491 |
} |
| 492 |
|
| 493 |
int testInput(struct node *node) |
| 494 |
{ |
| 495 |
struct v4l2_input descr; |
| 496 |
int cur_input = MAGIC; |
| 497 |
int input; |
| 498 |
int ret = doioctl(node, VIDIOC_G_INPUT, &cur_input); |
| 499 |
int i = 0; |
| 500 |
|
| 501 |
if (ret == ENOTTY) { |
| 502 |
if (node->has_inputs) { |
| 503 |
if (media_fd < 0) |
| 504 |
return fail("G_INPUT not supported for a capture device\n"); |
| 505 |
node->has_inputs = false; |
| 506 |
return ENOTTY; |
| 507 |
} |
| 508 |
descr.index = 0; |
| 509 |
ret = doioctl(node, VIDIOC_ENUMINPUT, &descr); |
| 510 |
if (ret != ENOTTY) |
| 511 |
return fail("G_INPUT not supported, but ENUMINPUT is\n"); |
| 512 |
cur_input = 0; |
| 513 |
ret = doioctl(node, VIDIOC_S_INPUT, &cur_input); |
| 514 |
if (ret != ENOTTY) |
| 515 |
return fail("G_INPUT not supported, but S_INPUT is\n"); |
| 516 |
return ENOTTY; |
| 517 |
} |
| 518 |
if (ret) |
| 519 |
return fail("could not get current input\n"); |
| 520 |
if (cur_input == MAGIC) |
| 521 |
return fail("VIDIOC_G_INPUT didn't fill in the input\n"); |
| 522 |
if (node->is_radio) |
| 523 |
return fail("radio can't have input support\n"); |
| 524 |
if (is_vivid && cur_input == 0) { |
| 525 |
// for vivid start off with a different input than the |
| 526 |
// current one. This ensures that the checkVividPixelArray() |
| 527 |
// call later succeeds since switching to input 0 will reset |
| 528 |
// that control to the default values. |
| 529 |
input = 1; |
| 530 |
doioctl(node, VIDIOC_S_INPUT, &input); |
| 531 |
} |
| 532 |
for (;;) { |
| 533 |
memset(&descr, 0xff, sizeof(descr)); |
| 534 |
descr.index = i; |
| 535 |
ret = doioctl(node, VIDIOC_ENUMINPUT, &descr); |
| 536 |
if (ret == EINVAL) |
| 537 |
break; |
| 538 |
if (ret) |
| 539 |
return fail("could not enumerate input %d\n", i); |
| 540 |
input = i; |
| 541 |
if (doioctl(node, VIDIOC_S_INPUT, &input)) |
| 542 |
return fail("could not set input to %d\n", i); |
| 543 |
if (input != i) |
| 544 |
return fail("input set to %d, but becomes %d?!\n", i, input); |
| 545 |
if (checkInput(node, descr, i)) |
| 546 |
return fail("invalid attributes for input %d\n", i); |
| 547 |
if (is_vivid && node->is_video && checkVividPixelArray(node)) |
| 548 |
return fail("vivid pixel array control test failed\n"); |
| 549 |
node->inputs++; |
| 550 |
i++; |
| 551 |
} |
| 552 |
input = i; |
| 553 |
if (doioctl(node, VIDIOC_S_INPUT, &input) != EINVAL) |
| 554 |
return fail("could set input to invalid input %d\n", i); |
| 555 |
if (doioctl(node, VIDIOC_S_INPUT, &cur_input)) |
| 556 |
return fail("couldn't set input to the original input %d\n", cur_input); |
| 557 |
if (node->inputs && !node->has_inputs) |
| 558 |
return fail("inputs found, but no input capabilities set\n"); |
| 559 |
if (!node->inputs && node->has_inputs) |
| 560 |
return fail("no inputs found, but input capabilities set\n"); |
| 561 |
fail_on_test(node->is_m2m && node->inputs > 1); |
| 562 |
if (node->is_io_mc) { |
| 563 |
fail_on_test(!node->is_video && !node->is_meta); |
| 564 |
fail_on_test(node->inputs != 1); |
| 565 |
} |
| 566 |
return 0; |
| 567 |
} |
| 568 |
|
| 569 |
static int checkInputAudio(const struct v4l2_audio &descr, unsigned i) |
| 570 |
{ |
| 571 |
if (descr.index != i) |
| 572 |
return fail("invalid index\n"); |
| 573 |
if (check_ustring(descr.name, sizeof(descr.name))) |
| 574 |
return fail("invalid name\n"); |
| 575 |
if (descr.capability & ~0x3) |
| 576 |
return fail("invalid capabilities\n"); |
| 577 |
if (descr.mode != 0 && descr.mode != V4L2_AUDMODE_AVL) |
| 578 |
return fail("invalid mode\n"); |
| 579 |
if (!(descr.capability & V4L2_AUDCAP_AVL) && descr.mode) |
| 580 |
return fail("mode != 0\n"); |
| 581 |
if (check_0(descr.reserved, sizeof(descr.reserved))) |
| 582 |
return fail("non-zero reserved fields\n"); |
| 583 |
return 0; |
| 584 |
} |
| 585 |
|
| 586 |
int testEnumInputAudio(struct node *node) |
| 587 |
{ |
| 588 |
struct v4l2_audio input; |
| 589 |
unsigned i = 0; |
| 590 |
int ret; |
| 591 |
|
| 592 |
for (;;) { |
| 593 |
memset(&input, 0xff, sizeof(input)); |
| 594 |
input.index = i; |
| 595 |
|
| 596 |
ret = doioctl(node, VIDIOC_ENUMAUDIO, &input); |
| 597 |
if (ret == ENOTTY) |
| 598 |
return ret; |
| 599 |
if (ret == EINVAL) |
| 600 |
break; |
| 601 |
if (ret) |
| 602 |
return fail("could not enumerate audio input %d\n", i); |
| 603 |
if (checkInputAudio(input, i)) |
| 604 |
return fail("invalid attributes for audio input %d\n", i); |
| 605 |
node->audio_inputs++; |
| 606 |
i++; |
| 607 |
} |
| 608 |
if (node->audio_inputs && !(node->g_caps() & V4L2_CAP_AUDIO)) |
| 609 |
return fail("audio inputs reported, but no CAP_AUDIO set\n"); |
| 610 |
return 0; |
| 611 |
} |
| 612 |
|
| 613 |
static int checkInputAudioSet(struct node *node, __u32 audioset) |
| 614 |
{ |
| 615 |
struct v4l2_audio input = { 0 }; |
| 616 |
unsigned i; |
| 617 |
int ret; |
| 618 |
|
| 619 |
ret = doioctl(node, VIDIOC_G_AUDIO, &input); |
| 620 |
if (audioset == 0 && ret != ENOTTY && ret != EINVAL) |
| 621 |
return fail("No audioset, but G_AUDIO did not return ENOTTY or EINVAL\n"); |
| 622 |
if (audioset) { |
| 623 |
if (ret) |
| 624 |
return fail("Audio inputs, but G_AUDIO returned an error\n"); |
| 625 |
if (input.index >= node->audio_inputs) |
| 626 |
return fail("invalid current audio input %d\n", input.index); |
| 627 |
if (checkInputAudio(input, input.index)) |
| 628 |
return fail("invalid attributes for audio input %d\n", input.index); |
| 629 |
} |
| 630 |
|
| 631 |
for (i = 0; i <= node->audio_inputs; i++) { |
| 632 |
int valid = audioset & (1 << i); |
| 633 |
|
| 634 |
memset(&input, 0xff, sizeof(input)); |
| 635 |
memset(input.reserved, 0, sizeof(input.reserved)); |
| 636 |
input.index = i; |
| 637 |
input.mode = 0; |
| 638 |
ret = doioctl(node, VIDIOC_S_AUDIO, &input); |
| 639 |
if (!valid && ret != EINVAL && ret != ENOTTY) |
| 640 |
return fail("can set invalid audio input %d\n", i); |
| 641 |
if (valid && ret) |
| 642 |
return fail("can't set valid audio input %d\n", i); |
| 643 |
} |
| 644 |
return 0; |
| 645 |
} |
| 646 |
|
| 647 |
int testInputAudio(struct node *node) |
| 648 |
{ |
| 649 |
struct v4l2_input vinput = { 0 }; |
| 650 |
unsigned i = 0; |
| 651 |
int ret; |
| 652 |
|
| 653 |
if (node->audio_inputs && node->inputs == 0) |
| 654 |
return fail("audio inputs found but no video inputs?!\n"); |
| 655 |
|
| 656 |
for (i = 0; i < node->inputs; i++) { |
| 657 |
ret = doioctl(node, VIDIOC_S_INPUT, &i); |
| 658 |
if (ret) |
| 659 |
return fail("could not select input %d\n", i); |
| 660 |
vinput.index = i; |
| 661 |
ret = doioctl(node, VIDIOC_ENUMINPUT, &vinput); |
| 662 |
if (ret) |
| 663 |
return fail("could not enumerate input %d\n", i); |
| 664 |
if (checkInputAudioSet(node, vinput.audioset)) |
| 665 |
return fail("invalid audioset for input %d\n", i); |
| 666 |
} |
| 667 |
return node->audio_inputs ? 0 : ENOTTY; |
| 668 |
} |
| 669 |
|
| 670 |
static int checkModulator(struct node *node, const struct v4l2_modulator &mod, unsigned m) |
| 671 |
{ |
| 672 |
bool tv = !node->is_radio && !node->is_sdr; |
| 673 |
|
| 674 |
if (mod.index != m) |
| 675 |
return fail("invalid index\n"); |
| 676 |
if (check_ustring(mod.name, sizeof(mod.name))) |
| 677 |
return fail("invalid name\n"); |
| 678 |
if (check_0(mod.reserved, sizeof(mod.reserved))) |
| 679 |
return fail("non-zero reserved fields\n"); |
| 680 |
if (tv) |
| 681 |
return fail("currently only radio/sdr modulators are supported\n"); |
| 682 |
if (node->is_sdr) |
| 683 |
fail_on_test(mod.type != V4L2_TUNER_SDR && mod.type != V4L2_TUNER_RF); |
| 684 |
else if (mod.type != V4L2_TUNER_RADIO) |
| 685 |
return fail("invalid modulator type %d\n", mod.type); |
| 686 |
|
| 687 |
if (!(mod.capability & (V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_1HZ))) |
| 688 |
return fail("V4L2_TUNER_CAP_LOW/1HZ was not set for a radio modulator\n"); |
| 689 |
if (mod.capability & (V4L2_TUNER_CAP_NORM | |
| 690 |
V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2)) |
| 691 |
return fail("TV capabilities for radio modulator?\n"); |
| 692 |
fail_on_test(!(mod.capability & V4L2_TUNER_CAP_FREQ_BANDS)); |
| 693 |
if (mod.rangelow > mod.rangehigh) |
| 694 |
return fail("rangelow > rangehigh\n"); |
| 695 |
if (mod.rangelow == 0 || mod.rangehigh == 0xffffffff) |
| 696 |
return fail("invalid rangelow or rangehigh\n"); |
| 697 |
if (!(mod.capability & V4L2_TUNER_CAP_STEREO) && |
| 698 |
(mod.txsubchans & V4L2_TUNER_SUB_STEREO)) |
| 699 |
return fail("stereo subchan, but no stereo caps?\n"); |
| 700 |
if (!(mod.capability & V4L2_TUNER_CAP_LANG1) && |
| 701 |
(mod.txsubchans & V4L2_TUNER_SUB_LANG1)) |
| 702 |
return fail("lang1 subchan, but no lang1 caps?\n"); |
| 703 |
if (!(mod.capability & V4L2_TUNER_CAP_LANG2) && |
| 704 |
(mod.txsubchans & V4L2_TUNER_SUB_LANG2)) |
| 705 |
return fail("lang2 subchan, but no lang2 caps?\n"); |
| 706 |
if (!(mod.capability & V4L2_TUNER_CAP_RDS) && |
| 707 |
(mod.txsubchans & V4L2_TUNER_SUB_RDS)) |
| 708 |
return fail("RDS subchan, but no RDS caps?\n"); |
| 709 |
bool have_rds = mod.capability & V4L2_TUNER_CAP_RDS; |
| 710 |
bool have_rds_method = mod.capability & |
| 711 |
(V4L2_TUNER_CAP_RDS_BLOCK_IO | V4L2_TUNER_CAP_RDS_CONTROLS); |
| 712 |
if (have_rds ^ have_rds_method) |
| 713 |
return fail("V4L2_TUNER_CAP_RDS is set, but not V4L2_TUNER_CAP_RDS_* or vice versa\n"); |
| 714 |
if ((mod.capability & V4L2_TUNER_CAP_RDS_BLOCK_IO) && |
| 715 |
!(node->g_caps() & V4L2_CAP_READWRITE)) |
| 716 |
return fail("V4L2_TUNER_CAP_RDS_BLOCK_IO is set, but not V4L2_CAP_READWRITE\n"); |
| 717 |
if (!node->is_sdr && !(mod.capability & V4L2_TUNER_CAP_RDS_BLOCK_IO) && |
| 718 |
(node->g_caps() & V4L2_CAP_READWRITE)) |
| 719 |
return fail("V4L2_TUNER_CAP_RDS_BLOCK_IO is not set, but V4L2_CAP_READWRITE is\n"); |
| 720 |
return checkEnumFreqBands(node, mod.index, mod.type, mod.capability, |
| 721 |
mod.rangelow, mod.rangehigh); |
| 722 |
} |
| 723 |
|
| 724 |
int testModulator(struct node *node) |
| 725 |
{ |
| 726 |
struct v4l2_modulator mod; |
| 727 |
unsigned m = 0; |
| 728 |
bool has_rds = false; |
| 729 |
int ret; |
| 730 |
|
| 731 |
for (;;) { |
| 732 |
memset(&mod, 0xff, sizeof(mod)); |
| 733 |
memset(mod.reserved, 0, sizeof(mod.reserved)); |
| 734 |
mod.index = m; |
| 735 |
ret = doioctl(node, VIDIOC_G_MODULATOR, &mod); |
| 736 |
if (ret == ENOTTY) |
| 737 |
return ret; |
| 738 |
if (ret == EINVAL) |
| 739 |
break; |
| 740 |
if (ret) |
| 741 |
return fail("couldn't get modulator %d\n", m); |
| 742 |
if (checkModulator(node, mod, m)) |
| 743 |
return fail("invalid modulator %d\n", m); |
| 744 |
if (doioctl(node, VIDIOC_S_MODULATOR, &mod)) |
| 745 |
return fail("cannot set modulator %d\n", m); |
| 746 |
m++; |
| 747 |
node->modulators++; |
| 748 |
if (mod.capability & V4L2_TUNER_CAP_RDS) |
| 749 |
has_rds = true; |
| 750 |
} |
| 751 |
memset(&mod, 0, sizeof(mod)); |
| 752 |
mod.index = m; |
| 753 |
if (doioctl(node, VIDIOC_S_MODULATOR, &mod) != EINVAL) |
| 754 |
return fail("could set invalid modulator %d\n", m); |
| 755 |
if (node->modulators && !(node->g_caps() & V4L2_CAP_MODULATOR)) |
| 756 |
return fail("modulators found, but no modulator capability set\n"); |
| 757 |
if (!node->modulators && (node->g_caps() & V4L2_CAP_MODULATOR)) |
| 758 |
return fail("no modulators found, but modulator capability set\n"); |
| 759 |
if (has_rds && !(node->g_caps() & V4L2_CAP_RDS_OUTPUT)) |
| 760 |
return fail("RDS modulator capability, but no RDS output capability?\n"); |
| 761 |
if (!has_rds && (node->g_caps() & V4L2_CAP_RDS_OUTPUT)) |
| 762 |
return fail("No RDS modulator capability, but RDS output capability?\n"); |
| 763 |
return 0; |
| 764 |
} |
| 765 |
|
| 766 |
int testModulatorFreq(struct node *node) |
| 767 |
{ |
| 768 |
struct v4l2_frequency freq = { 0 }; |
| 769 |
unsigned m; |
| 770 |
int ret; |
| 771 |
|
| 772 |
for (m = 0; m < node->modulators; m++) { |
| 773 |
struct v4l2_modulator modulator; |
| 774 |
|
| 775 |
modulator.index = m; |
| 776 |
memset(modulator.reserved, 0, sizeof(modulator.reserved)); |
| 777 |
ret = doioctl(node, VIDIOC_G_MODULATOR, &modulator); |
| 778 |
if (ret) |
| 779 |
return fail("could not get modulator %d\n", m); |
| 780 |
memset(&freq, 0, sizeof(freq)); |
| 781 |
freq.tuner = m; |
| 782 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 783 |
if (ret) |
| 784 |
return fail("could not get frequency for modulator %d\n", m); |
| 785 |
if (check_0(freq.reserved, sizeof(freq.reserved))) |
| 786 |
return fail("reserved was not zeroed\n"); |
| 787 |
if (freq.tuner != m) |
| 788 |
return fail("frequency modulator field changed!\n"); |
| 789 |
if ((freq.type == V4L2_TUNER_SDR || freq.type == V4L2_TUNER_RF) && |
| 790 |
!(node->g_caps() & V4L2_CAP_SDR_OUTPUT)) |
| 791 |
return fail("sdr tuner found but no sdr output capability set\n"); |
| 792 |
if (freq.frequency == 0) |
| 793 |
return fail("frequency not set\n"); |
| 794 |
if (freq.frequency < modulator.rangelow || freq.frequency > modulator.rangehigh) |
| 795 |
warn("returned modulator %d frequency out of range (%d not in [%d...%d])\n", |
| 796 |
m, freq.frequency, modulator.rangelow, modulator.rangehigh); |
| 797 |
|
| 798 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 799 |
if (ret) |
| 800 |
return fail("could not set current frequency\n"); |
| 801 |
freq.frequency = modulator.rangelow; |
| 802 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 803 |
if (ret) |
| 804 |
return fail("could not set rangelow frequency\n"); |
| 805 |
freq.frequency = modulator.rangehigh; |
| 806 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 807 |
if (ret) |
| 808 |
return fail("could not set rangehigh frequency\n"); |
| 809 |
freq.frequency = modulator.rangelow - 1; |
| 810 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 811 |
if (ret) |
| 812 |
return fail("could not set rangelow-1 frequency\n"); |
| 813 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 814 |
if (ret || freq.frequency != modulator.rangelow) |
| 815 |
return fail("frequency rangelow-1 wasn't mapped to rangelow\n"); |
| 816 |
freq.frequency = modulator.rangehigh + 1; |
| 817 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 818 |
if (ret) |
| 819 |
return fail("could not set rangehigh+1 frequency\n"); |
| 820 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 821 |
if (ret || freq.frequency != modulator.rangehigh) |
| 822 |
return fail("frequency rangehigh+1 wasn't mapped to rangehigh\n"); |
| 823 |
} |
| 824 |
|
| 825 |
/* If this is a tuner device, then skip the remaining tests */ |
| 826 |
if (node->g_caps() & V4L2_CAP_TUNER) |
| 827 |
return 0; |
| 828 |
|
| 829 |
freq.tuner = m; |
| 830 |
ret = doioctl(node, VIDIOC_G_FREQUENCY, &freq); |
| 831 |
if (ret != EINVAL && ret != ENOTTY) |
| 832 |
return fail("could get frequency for invalid modulator %d\n", m); |
| 833 |
freq.tuner = m; |
| 834 |
// Radio: 100 MHz |
| 835 |
freq.frequency = 1600000; |
| 836 |
ret = doioctl(node, VIDIOC_S_FREQUENCY, &freq); |
| 837 |
if (ret != EINVAL && ret != ENOTTY) |
| 838 |
return fail("could set frequency for invalid modulator %d\n", m); |
| 839 |
return node->modulators ? 0 : ENOTTY; |
| 840 |
} |
| 841 |
|
| 842 |
static int checkOutput(struct node *node, const struct v4l2_output &descr, unsigned o) |
| 843 |
{ |
| 844 |
__u32 mask = (1 << node->audio_outputs) - 1; |
| 845 |
struct v4l2_selection sel; |
| 846 |
|
| 847 |
if (descr.index != o) |
| 848 |
return fail("invalid index\n"); |
| 849 |
if (check_ustring(descr.name, sizeof(descr.name))) |
| 850 |
return fail("invalid name\n"); |
| 851 |
if (descr.type != V4L2_OUTPUT_TYPE_MODULATOR && descr.type != V4L2_OUTPUT_TYPE_ANALOG && |
| 852 |
descr.type != V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY) |
| 853 |
return fail("invalid type\n"); |
| 854 |
if (descr.type != V4L2_OUTPUT_TYPE_MODULATOR && descr.modulator) |
| 855 |
return fail("invalid modulator\n"); |
| 856 |
if (descr.type == V4L2_OUTPUT_TYPE_MODULATOR && node->modulators == 0) |
| 857 |
return fail("no modulators found for modulator output\n"); |
| 858 |
if (!(descr.capabilities & V4L2_OUT_CAP_STD) && descr.std) |
| 859 |
return fail("invalid std\n"); |
| 860 |
if ((descr.capabilities & V4L2_OUT_CAP_STD) && !descr.std) |
| 861 |
return fail("std == 0\n"); |
| 862 |
memset(&sel, 0, sizeof(sel)); |
| 863 |
sel.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; |
| 864 |
sel.target = V4L2_SEL_TGT_NATIVE_SIZE; |
| 865 |
if (descr.capabilities & V4L2_OUT_CAP_NATIVE_SIZE) { |
| 866 |
fail_on_test(doioctl(node, VIDIOC_G_SELECTION, &sel)); |
| 867 |
fail_on_test(doioctl(node, VIDIOC_S_SELECTION, &sel)); |
| 868 |
} else if (!doioctl(node, VIDIOC_G_SELECTION, &sel)) { |
| 869 |
fail_on_test(!doioctl(node, VIDIOC_S_SELECTION, &sel)); |
| 870 |
} |
| 871 |
if (descr.capabilities & ~0x7) |
| 872 |
return fail("invalid capabilities\n"); |
| 873 |
if (check_0(descr.reserved, sizeof(descr.reserved))) |
| 874 |
return fail("non-zero reserved fields\n"); |
| 875 |
if (descr.audioset & ~mask) |
| 876 |
return fail("invalid audioset\n"); |
| 877 |
if (descr.modulator && descr.modulator >= node->modulators) |
| 878 |
return fail("invalid modulator\n"); |
| 879 |
return 0; |
| 880 |
} |
| 881 |
|
| 882 |
int testOutput(struct node *node) |
| 883 |
{ |
| 884 |
struct v4l2_output descr; |
| 885 |
int cur_output = MAGIC; |
| 886 |
int output; |
| 887 |
int ret = doioctl(node, VIDIOC_G_OUTPUT, &cur_output); |
| 888 |
int o = 0; |
| 889 |
|
| 890 |
if (ret == ENOTTY) { |
| 891 |
if (node->has_outputs) { |
| 892 |
if (media_fd < 0) |
| 893 |
return fail("G_OUTPUT not supported for an output device\n"); |
| 894 |
node->has_outputs = false; |
| 895 |
return ENOTTY; |
| 896 |
} |
| 897 |
descr.index = 0; |
| 898 |
ret = doioctl(node, VIDIOC_ENUMOUTPUT, &descr); |
| 899 |
if (ret != ENOTTY) |
| 900 |
return fail("G_OUTPUT not supported, but ENUMOUTPUT is\n"); |
| 901 |
output = 0; |
| 902 |
ret = doioctl(node, VIDIOC_S_OUTPUT, &output); |
| 903 |
if (ret != ENOTTY) |
| 904 |
return fail("G_OUTPUT not supported, but S_OUTPUT is\n"); |
| 905 |
} |
| 906 |
if (ret) |
| 907 |
return ret; |
| 908 |
if (cur_output == MAGIC) |
| 909 |
return fail("VIDIOC_G_OUTPUT didn't fill in the output\n"); |
| 910 |
for (;;) { |
| 911 |
memset(&descr, 0xff, sizeof(descr)); |
| 912 |
descr.index = o; |
| 913 |
ret = doioctl(node, VIDIOC_ENUMOUTPUT, &descr); |
| 914 |
if (ret) |
| 915 |
break; |
| 916 |
output = o; |
| 917 |
if (doioctl(node, VIDIOC_S_OUTPUT, &output)) |
| 918 |
return fail("could not set output to %d\n", o); |
| 919 |
if (output != o) |
| 920 |
return fail("output set to %d, but becomes %d?!\n", o, output); |
| 921 |
if (checkOutput(node, descr, o)) |
| 922 |
return fail("invalid attributes for output %d\n", o); |
| 923 |
node->outputs++; |
| 924 |
o++; |
| 925 |
} |
| 926 |
output = o; |
| 927 |
if (doioctl(node, VIDIOC_S_OUTPUT, &output) != EINVAL) |
| 928 |
return fail("could set output to invalid output %d\n", o); |
| 929 |
if (doioctl(node, VIDIOC_S_OUTPUT, &cur_output)) |
| 930 |
return fail("couldn't set output to the original output %d\n", cur_output); |
| 931 |
if (node->outputs && !node->has_outputs) |
| 932 |
return fail("outputs found, but no output capabilities set\n"); |
| 933 |
if (!node->outputs && node->has_outputs) |
| 934 |
return fail("no outputs found, but output capabilities set\n"); |
| 935 |
fail_on_test(node->is_m2m && node->outputs > 1); |
| 936 |
if (node->is_io_mc) { |
| 937 |
fail_on_test(!node->is_video && !node->is_meta); |
| 938 |
fail_on_test(node->outputs != 1); |
| 939 |
} |
| 940 |
return 0; |
| 941 |
} |
| 942 |
|
| 943 |
static int checkOutputAudio(const struct v4l2_audioout &descr, unsigned o) |
| 944 |
{ |
| 945 |
if (descr.index != o) |
| 946 |
return fail("invalid index\n"); |
| 947 |
if (check_ustring(descr.name, sizeof(descr.name))) |
| 948 |
return fail("invalid name\n"); |
| 949 |
if (descr.capability) |
| 950 |
return fail("invalid capabilities\n"); |
| 951 |
if (descr.mode) |
| 952 |
return fail("invalid mode\n"); |
| 953 |
if (check_0(descr.reserved, sizeof(descr.reserved))) |
| 954 |
return fail("non-zero reserved fields\n"); |
| 955 |
return 0; |
| 956 |
} |
| 957 |
|
| 958 |
int testEnumOutputAudio(struct node *node) |
| 959 |
{ |
| 960 |
struct v4l2_audioout output; |
| 961 |
unsigned o = 0; |
| 962 |
int ret; |
| 963 |
|
| 964 |
for (;;) { |
| 965 |
memset(&output, 0xff, sizeof(output)); |
| 966 |
output.index = o; |
| 967 |
|
| 968 |
ret = doioctl(node, VIDIOC_ENUMAUDOUT, &output); |
| 969 |
if (ret == ENOTTY) |
| 970 |
return ENOTTY; |
| 971 |
if (ret == EINVAL) |
| 972 |
break; |
| 973 |
if (ret) |
| 974 |
return fail("could not enumerate audio output %d\n", o); |
| 975 |
if (checkOutputAudio(output, o)) |
| 976 |
return fail("invalid attributes for audio output %d\n", o); |
| 977 |
node->audio_outputs++; |
| 978 |
o++; |
| 979 |
} |
| 980 |
|
| 981 |
if (node->audio_outputs && !(node->g_caps() & V4L2_CAP_AUDIO)) |
| 982 |
return fail("audio outputs reported, but no CAP_AUDIO set\n"); |
| 983 |
return 0; |
| 984 |
} |
| 985 |
|
| 986 |
static int checkOutputAudioSet(struct node *node, __u32 audioset) |
| 987 |
{ |
| 988 |
struct v4l2_audioout output; |
| 989 |
unsigned i; |
| 990 |
int ret; |
| 991 |
|
| 992 |
memset(output.reserved, 0, sizeof(output.reserved)); |
| 993 |
ret = doioctl(node, VIDIOC_G_AUDOUT, &output); |
| 994 |
if (audioset == 0 && ret != EINVAL && ret != ENOTTY) |
| 995 |
return fail("No audio outputs, but G_AUDOUT did not return EINVAL or ENOTTY\n"); |
| 996 |
if (audioset) { |
| 997 |
if (ret) |
| 998 |
return fail("Audio outputs, but G_AUDOUT returned an error\n"); |
| 999 |
if (output.index >= node->audio_outputs) |
| 1000 |
return fail("invalid current audio output %d\n", output.index); |
| 1001 |
if (checkOutputAudio(output, output.index)) |
| 1002 |
return fail("invalid attributes for audio output %d\n", output.index); |
| 1003 |
} |
| 1004 |
|
| 1005 |
for (i = 0; i <= node->audio_outputs; i++) { |
| 1006 |
int valid = audioset & (1 << i); |
| 1007 |
|
| 1008 |
memset(&output, 0xff, sizeof(output)); |
| 1009 |
memset(output.reserved, 0, sizeof(output.reserved)); |
| 1010 |
output.index = i; |
| 1011 |
output.mode = 0; |
| 1012 |
ret = doioctl(node, VIDIOC_S_AUDOUT, &output); |
| 1013 |
if (!valid && ret != EINVAL && ret != ENOTTY) |
| 1014 |
return fail("can set invalid audio output %d\n", i); |
| 1015 |
if (valid && ret) |
| 1016 |
return fail("can't set valid audio output %d\n", i); |
| 1017 |
} |
| 1018 |
return 0; |
| 1019 |
} |
| 1020 |
|
| 1021 |
int testOutputAudio(struct node *node) |
| 1022 |
{ |
| 1023 |
struct v4l2_output voutput; |
| 1024 |
unsigned o = 0; |
| 1025 |
int ret; |
| 1026 |
|
| 1027 |
if (node->audio_outputs && node->outputs == 0) |
| 1028 |
return fail("audio outputs found but no video outputs?!\n"); |
| 1029 |
|
| 1030 |
for (o = 0; o < node->outputs; o++) { |
| 1031 |
ret = doioctl(node, VIDIOC_S_OUTPUT, &o); |
| 1032 |
if (ret) |
| 1033 |
return fail("could not select output %d\n", o); |
| 1034 |
voutput.index = o; |
| 1035 |
ret = doioctl(node, VIDIOC_ENUMOUTPUT, &voutput); |
| 1036 |
if (ret) |
| 1037 |
return fail("could not enumerate output %d\n", o); |
| 1038 |
if (checkOutputAudioSet(node, voutput.audioset)) |
| 1039 |
return fail("invalid audioset for output %d\n", o); |
| 1040 |
} |
| 1041 |
|
| 1042 |
if (node->audio_outputs == 0 && node->audio_inputs == 0 && (node->g_caps() & V4L2_CAP_AUDIO)) |
| 1043 |
return fail("no audio inputs or outputs reported, but CAP_AUDIO set\n"); |
| 1044 |
return node->audio_outputs ? 0 : ENOTTY; |
| 1045 |
} |