| 1 |
/* |
| 2 |
V4L2 API compliance test tool. |
| 3 |
|
| 4 |
Copyright (C) 2008, 2010 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 <cctype> |
| 22 |
#include <csignal> |
| 23 |
#include <cstring> |
| 24 |
#include <map> |
| 25 |
#include <set> |
| 26 |
#include <vector> |
| 27 |
|
| 28 |
#include <dirent.h> |
| 29 |
#include <getopt.h> |
| 30 |
#include <sys/types.h> |
| 31 |
#include <unistd.h> |
| 32 |
|
| 33 |
#include "v4l2-compliance.h" |
| 34 |
#include <media-info.h> |
| 35 |
#include <v4l-getsubopt.h> |
| 36 |
|
| 37 |
/* Short option list |
| 38 |
|
| 39 |
Please keep in alphabetical order. |
| 40 |
That makes it easier to see which short options are still free. |
| 41 |
|
| 42 |
In general the lower case is used to set something and the upper |
| 43 |
case is used to retrieve a setting. */ |
| 44 |
enum Option { |
| 45 |
OptStreamAllIO = 'a', |
| 46 |
OptStreamAllColorTest = 'c', |
| 47 |
OptColor = 'C', |
| 48 |
OptSetDevice = 'd', |
| 49 |
OptSetExpBufDevice = 'e', |
| 50 |
OptExitOnFail = 'E', |
| 51 |
OptStreamAllFormats = 'f', |
| 52 |
OptHelp = 'h', |
| 53 |
OptSetMediaDevice = 'm', |
| 54 |
OptSetMediaDeviceOnly = 'M', |
| 55 |
OptNoWarnings = 'n', |
| 56 |
OptNoProgress = 'P', |
| 57 |
OptSetRadioDevice = 'r', |
| 58 |
OptStreaming = 's', |
| 59 |
OptSetSWRadioDevice = 'S', |
| 60 |
OptSetTouchDevice = 't', |
| 61 |
OptTrace = 'T', |
| 62 |
OptSetSubDevDevice = 'u', |
| 63 |
OptVerbose = 'v', |
| 64 |
OptSetVbiDevice = 'V', |
| 65 |
OptUseWrapper = 'w', |
| 66 |
OptExitOnWarn = 'W', |
| 67 |
OptMediaBusInfo = 'z', |
| 68 |
OptStreamFrom = 128, |
| 69 |
OptStreamFromHdr, |
| 70 |
OptVersion, |
| 71 |
OptLast = 256 |
| 72 |
}; |
| 73 |
|
| 74 |
static char options[OptLast]; |
| 75 |
|
| 76 |
static int app_result; |
| 77 |
static int tests_total, tests_ok; |
| 78 |
static int grand_total, grand_ok, grand_warnings; |
| 79 |
|
| 80 |
// Globals |
| 81 |
bool show_info; |
| 82 |
bool no_progress; |
| 83 |
bool show_warnings = true; |
| 84 |
bool show_colors; |
| 85 |
bool exit_on_fail; |
| 86 |
bool exit_on_warn; |
| 87 |
bool is_vivid; |
| 88 |
bool is_uvcvideo; |
| 89 |
int media_fd = -1; |
| 90 |
unsigned warnings; |
| 91 |
bool has_mmu = true; |
| 92 |
|
| 93 |
static unsigned color_component; |
| 94 |
static unsigned color_skip; |
| 95 |
static unsigned color_perc = 90; |
| 96 |
|
| 97 |
struct dev_state { |
| 98 |
struct node *node; |
| 99 |
std::vector<v4l2_ext_control> control_vec; |
| 100 |
v4l2_ext_controls controls; |
| 101 |
v4l2_rect crop; |
| 102 |
v4l2_rect compose; |
| 103 |
v4l2_rect native_size; |
| 104 |
v4l2_format fmt; |
| 105 |
v4l2_input input; |
| 106 |
v4l2_output output; |
| 107 |
v4l2_audio ainput; |
| 108 |
v4l2_audioout aoutput; |
| 109 |
v4l2_frequency freq; |
| 110 |
v4l2_tuner tuner; |
| 111 |
v4l2_modulator modulator; |
| 112 |
v4l2_std_id std; |
| 113 |
v4l2_dv_timings timings; |
| 114 |
v4l2_fract interval; |
| 115 |
}; |
| 116 |
|
| 117 |
static struct dev_state state; |
| 118 |
|
| 119 |
static struct option long_options[] = { |
| 120 |
{"device", required_argument, nullptr, OptSetDevice}, |
| 121 |
{"radio-device", required_argument, nullptr, OptSetRadioDevice}, |
| 122 |
{"vbi-device", required_argument, nullptr, OptSetVbiDevice}, |
| 123 |
{"sdr-device", required_argument, nullptr, OptSetSWRadioDevice}, |
| 124 |
{"subdev-device", required_argument, nullptr, OptSetSubDevDevice}, |
| 125 |
{"expbuf-device", required_argument, nullptr, OptSetExpBufDevice}, |
| 126 |
{"touch-device", required_argument, nullptr, OptSetTouchDevice}, |
| 127 |
{"media-device", required_argument, nullptr, OptSetMediaDevice}, |
| 128 |
{"media-device-only", required_argument, nullptr, OptSetMediaDeviceOnly}, |
| 129 |
{"media-bus-info", required_argument, nullptr, OptMediaBusInfo}, |
| 130 |
{"help", no_argument, nullptr, OptHelp}, |
| 131 |
{"verbose", no_argument, nullptr, OptVerbose}, |
| 132 |
{"color", required_argument, nullptr, OptColor}, |
| 133 |
{"no-warnings", no_argument, nullptr, OptNoWarnings}, |
| 134 |
{"no-progress", no_argument, nullptr, OptNoProgress}, |
| 135 |
{"exit-on-fail", no_argument, nullptr, OptExitOnFail}, |
| 136 |
{"exit-on-warn", no_argument, nullptr, OptExitOnWarn}, |
| 137 |
{"trace", no_argument, nullptr, OptTrace}, |
| 138 |
#ifndef NO_LIBV4L2 |
| 139 |
{"wrapper", no_argument, nullptr, OptUseWrapper}, |
| 140 |
#endif |
| 141 |
{"streaming", optional_argument, nullptr, OptStreaming}, |
| 142 |
{"stream-from", required_argument, nullptr, OptStreamFrom}, |
| 143 |
{"stream-from-hdr", required_argument, nullptr, OptStreamFromHdr}, |
| 144 |
{"stream-all-formats", optional_argument, nullptr, OptStreamAllFormats}, |
| 145 |
{"stream-all-io", no_argument, nullptr, OptStreamAllIO}, |
| 146 |
{"stream-all-color", required_argument, nullptr, OptStreamAllColorTest}, |
| 147 |
{"version", no_argument, nullptr, OptVersion}, |
| 148 |
{nullptr, 0, nullptr, 0} |
| 149 |
}; |
| 150 |
|
| 151 |
#define STR(x) #x |
| 152 |
#define STRING(x) STR(x) |
| 153 |
|
| 154 |
static void print_sha() |
| 155 |
{ |
| 156 |
int fd = open("/dev/null", O_RDONLY); |
| 157 |
|
| 158 |
if (fd >= 0) { |
| 159 |
// FIONBIO is a write-only ioctl that takes an int argument that |
| 160 |
// enables (!= 0) or disables (== 0) nonblocking mode of a fd. |
| 161 |
// |
| 162 |
// Passing a nullptr should return EFAULT on MMU capable machines, |
| 163 |
// and it works if there is no MMU. |
| 164 |
has_mmu = ioctl(fd, FIONBIO, nullptr); |
| 165 |
close(fd); |
| 166 |
} |
| 167 |
printf("v4l2-compliance %s%s, ", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT)); |
| 168 |
printf("%zd bits, %zd-bit time_t%s\n", |
| 169 |
sizeof(void *) * 8, sizeof(time_t) * 8, |
| 170 |
has_mmu ? "" : ", has no MMU"); |
| 171 |
if (strlen(STRING(GIT_SHA))) |
| 172 |
printf("v4l2-compliance SHA: %s %s\n", |
| 173 |
STRING(GIT_SHA), STRING(GIT_COMMIT_DATE)); |
| 174 |
} |
| 175 |
|
| 176 |
static void usage() |
| 177 |
{ |
| 178 |
printf("Usage:\n"); |
| 179 |
printf("Common options:\n"); |
| 180 |
printf(" -d, --device <dev> Use device <dev> as the video device.\n"); |
| 181 |
printf(" If <dev> starts with a digit, then /dev/video<dev> is used.\n"); |
| 182 |
printf(" Otherwise if -z was specified earlier, then <dev> is the entity name\n"); |
| 183 |
printf(" or interface ID (if prefixed with 0x) as found in the topology of the\n"); |
| 184 |
printf(" media device with the bus info string as specified by the -z option.\n"); |
| 185 |
printf(" -V, --vbi-device <dev>\n"); |
| 186 |
printf(" Use device <dev> as the vbi device.\n"); |
| 187 |
printf(" If <dev> starts with a digit, then /dev/vbi<dev> is used.\n"); |
| 188 |
printf(" See the -d description of how <dev> is used in combination with -z.\n"); |
| 189 |
printf(" -r, --radio-device <dev>\n"); |
| 190 |
printf(" Use device <dev> as the radio device.\n"); |
| 191 |
printf(" If <dev> starts with a digit, then /dev/radio<dev> is used.\n"); |
| 192 |
printf(" See the -d description of how <dev> is used in combination with -z.\n"); |
| 193 |
printf(" -S, --sdr-device <dev>\n"); |
| 194 |
printf(" Use device <dev> as the SDR device.\n"); |
| 195 |
printf(" If <dev> starts with a digit, then /dev/swradio<dev> is used.\n"); |
| 196 |
printf(" See the -d description of how <dev> is used in combination with -z.\n"); |
| 197 |
printf(" -t, --touch-device <dev>\n"); |
| 198 |
printf(" Use device <dev> as the touch device.\n"); |
| 199 |
printf(" If <dev> starts with a digit, then /dev/v4l-touch<dev> is used.\n"); |
| 200 |
printf(" See the -d description of how <dev> is used in combination with -z.\n"); |
| 201 |
printf(" -u, --subdev-device <dev>\n"); |
| 202 |
printf(" Use device <dev> as the v4l-subdev device.\n"); |
| 203 |
printf(" If <dev> starts with a digit, then /dev/v4l-subdev<dev> is used.\n"); |
| 204 |
printf(" See the -d description of how <dev> is used in combination with -z.\n"); |
| 205 |
printf(" -e, --expbuf-device <dev>\n"); |
| 206 |
printf(" Use video device <dev> to obtain DMABUF handles.\n"); |
| 207 |
printf(" If <dev> starts with a digit, then /dev/video<dev> is used.\n"); |
| 208 |
printf(" See the -d description of how <dev> is used in combination with -z.\n"); |
| 209 |
printf(" -z, --media-bus-info <bus-info>\n"); |
| 210 |
printf(" Find the media device with the given bus info string. If set, then\n"); |
| 211 |
printf(" the options above can use the entity name or interface ID to refer\n"); |
| 212 |
printf(" to the device nodes.\n"); |
| 213 |
printf(" -m, --media-device <dev>\n"); |
| 214 |
printf(" Use device <dev> as the media controller device. Besides this\n"); |
| 215 |
printf(" device it also tests all interfaces it finds.\n"); |
| 216 |
printf(" If <dev> starts with a digit, then /dev/media<dev> is used.\n"); |
| 217 |
printf(" If <dev> doesn't exist, then attempt to find a media device with a\n"); |
| 218 |
printf(" bus info string equal to <dev>.\n"); |
| 219 |
printf(" -M, --media-device-only <dev>\n"); |
| 220 |
printf(" Use device <dev> as the media controller device. Only test this\n"); |
| 221 |
printf(" device, don't walk over all the interfaces.\n"); |
| 222 |
printf(" If <dev> starts with a digit, then /dev/media<dev> is used.\n"); |
| 223 |
printf(" If <dev> doesn't exist, then attempt to find a media device with a\n"); |
| 224 |
printf(" bus info string equal to <dev>.\n"); |
| 225 |
printf(" -s, --streaming <count>\n"); |
| 226 |
printf(" Enable the streaming tests. Set <count> to the number of\n"); |
| 227 |
printf(" frames to stream (default 60). Requires a valid input/output\n"); |
| 228 |
printf(" and frequency (when dealing with a tuner). For DMABUF testing\n"); |
| 229 |
printf(" --expbuf-device needs to be set as well.\n"); |
| 230 |
printf(" --stream-from [<pixelformat>=]<file>\n"); |
| 231 |
printf(" --stream-from-hdr [<pixelformat>=]<file>\n"); |
| 232 |
printf(" Use the contents of the file to fill in output buffers.\n"); |
| 233 |
printf(" If the fourcc of the pixelformat is given, then use the file\n"); |
| 234 |
printf(" for output buffers using that pixelformat only.\n"); |
| 235 |
printf(" The --stream-from-hdr variant uses the format written by\n"); |
| 236 |
printf(" v4l2-ctl --stream-to-hdr where the payload sizes for each\n"); |
| 237 |
printf(" buffer are stored in a header. Useful for compressed formats.\n"); |
| 238 |
printf(" -f, --stream-all-formats [<count>]\n"); |
| 239 |
printf(" Test streaming all available formats.\n"); |
| 240 |
printf(" This attempts to stream using MMAP mode or read/write\n"); |
| 241 |
printf(" for one second for all formats, at all sizes, at all intervals\n"); |
| 242 |
printf(" and with all field values. If <count> is given, then stream\n"); |
| 243 |
printf(" for that many frames instead of one second.\n"); |
| 244 |
printf(" -a, --stream-all-io\n"); |
| 245 |
printf(" Do streaming tests for all inputs or outputs instead of just\n"); |
| 246 |
printf(" the current input or output. This requires that a valid video\n"); |
| 247 |
printf(" signal is present on all inputs and all outputs are hooked up.\n"); |
| 248 |
printf(" -c, --stream-all-color color=red|green|blue,skip=<skip>,perc=<percentage>\n"); |
| 249 |
printf(" For all formats stream <skip + 1> frames and check if\n"); |
| 250 |
printf(" the last frame has at least <perc> percent of the pixels with\n"); |
| 251 |
printf(" a <color> component that is higher than the other two color\n"); |
| 252 |
printf(" components. This requires that a valid red, green or blue video\n"); |
| 253 |
printf(" signal is present on the input(s). If <skip> is not specified,\n"); |
| 254 |
printf(" then just capture the first frame. If <perc> is not specified,\n"); |
| 255 |
printf(" then this defaults to 90%%.\n"); |
| 256 |
printf(" -E, --exit-on-fail Exit on the first fail.\n"); |
| 257 |
printf(" -h, --help Display this help message.\n"); |
| 258 |
printf(" -C, --color <when> Highlight OK/warn/fail/FAIL strings with colors\n"); |
| 259 |
printf(" <when> can be set to always, never, or auto (the default)\n"); |
| 260 |
printf(" -n, --no-warnings Turn off warning messages.\n"); |
| 261 |
printf(" -P, --no-progress Turn off progress messages.\n"); |
| 262 |
printf(" -T, --trace Trace all called ioctls.\n"); |
| 263 |
printf(" -v, --verbose Turn on verbose reporting.\n"); |
| 264 |
printf(" --version Show version information.\n"); |
| 265 |
#ifndef NO_LIBV4L2 |
| 266 |
printf(" -w, --wrapper Use the libv4l2 wrapper library.\n"); |
| 267 |
#endif |
| 268 |
printf(" -W, --exit-on-warn Exit on the first warning.\n"); |
| 269 |
} |
| 270 |
|
| 271 |
const char *ok(int res) |
| 272 |
{ |
| 273 |
static char buf[100]; |
| 274 |
|
| 275 |
if (res == ENOTTY) { |
| 276 |
strcpy(buf, show_colors ? |
| 277 |
COLOR_GREEN("OK") " (Not Supported)" : |
| 278 |
"OK (Not Supported)"); |
| 279 |
res = 0; |
| 280 |
} else { |
| 281 |
strcpy(buf, show_colors ? COLOR_GREEN("OK") : "OK"); |
| 282 |
} |
| 283 |
tests_total++; |
| 284 |
if (res) { |
| 285 |
app_result = res; |
| 286 |
sprintf(buf, show_colors ? COLOR_RED("FAIL") : "FAIL"); |
| 287 |
} else { |
| 288 |
tests_ok++; |
| 289 |
} |
| 290 |
return buf; |
| 291 |
} |
| 292 |
|
| 293 |
int check_string(const char *s, size_t len) |
| 294 |
{ |
| 295 |
size_t sz = strnlen(s, len); |
| 296 |
|
| 297 |
if (sz == 0) |
| 298 |
return fail("string empty\n"); |
| 299 |
if (sz == len) |
| 300 |
return fail("string not 0-terminated\n"); |
| 301 |
return 0; |
| 302 |
} |
| 303 |
|
| 304 |
int check_ustring(const __u8 *s, int len) |
| 305 |
{ |
| 306 |
return check_string(reinterpret_cast<const char *>(s), len); |
| 307 |
} |
| 308 |
|
| 309 |
int check_0(const void *p, int len) |
| 310 |
{ |
| 311 |
const __u8 *q = static_cast<const __u8 *>(p); |
| 312 |
|
| 313 |
while (len--) |
| 314 |
if (*q++) |
| 315 |
return 1; |
| 316 |
return 0; |
| 317 |
} |
| 318 |
|
| 319 |
static std::map<std::string, std::string> stream_from_map; |
| 320 |
static std::map<std::string, bool> stream_hdr_map; |
| 321 |
|
| 322 |
std::string stream_from(const std::string &pixelformat, bool &use_hdr) |
| 323 |
{ |
| 324 |
if (stream_from_map.find(pixelformat) == stream_from_map.end()) { |
| 325 |
if (pixelformat.empty()) |
| 326 |
return ""; |
| 327 |
return stream_from("", use_hdr); |
| 328 |
} |
| 329 |
use_hdr = stream_hdr_map[pixelformat]; |
| 330 |
return stream_from_map[pixelformat]; |
| 331 |
} |
| 332 |
|
| 333 |
static void storeStateTimings(struct node *node, __u32 caps) |
| 334 |
{ |
| 335 |
if (caps & V4L2_IN_CAP_STD) |
| 336 |
node->g_std(state.std); |
| 337 |
if (caps & V4L2_IN_CAP_DV_TIMINGS) |
| 338 |
node->g_dv_timings(state.timings); |
| 339 |
if (caps & V4L2_IN_CAP_NATIVE_SIZE) { |
| 340 |
v4l2_selection sel = { |
| 341 |
node->g_selection_type(), |
| 342 |
V4L2_SEL_TGT_NATIVE_SIZE |
| 343 |
}; |
| 344 |
|
| 345 |
node->g_selection(sel); |
| 346 |
state.native_size = sel.r; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
static void storeState(struct node *node) |
| 351 |
{ |
| 352 |
state.node = node; |
| 353 |
if (node->has_inputs) { |
| 354 |
__u32 input; |
| 355 |
|
| 356 |
node->g_input(input); |
| 357 |
node->enum_input(state.input, true, input); |
| 358 |
if (state.input.audioset) |
| 359 |
node->g_audio(state.ainput); |
| 360 |
if (node->g_caps() & V4L2_CAP_TUNER) { |
| 361 |
node->g_tuner(state.tuner, state.input.tuner); |
| 362 |
node->g_frequency(state.freq, state.input.tuner); |
| 363 |
} |
| 364 |
storeStateTimings(node, state.input.capabilities); |
| 365 |
} |
| 366 |
if (node->has_outputs) { |
| 367 |
__u32 output; |
| 368 |
|
| 369 |
node->g_output(output); |
| 370 |
node->enum_output(state.output, true, output); |
| 371 |
if (state.output.audioset) |
| 372 |
node->g_audout(state.aoutput); |
| 373 |
if (node->g_caps() & V4L2_CAP_MODULATOR) { |
| 374 |
node->g_modulator(state.modulator, state.output.modulator); |
| 375 |
node->g_frequency(state.freq, state.output.modulator); |
| 376 |
} |
| 377 |
storeStateTimings(node, state.output.capabilities); |
| 378 |
} |
| 379 |
node->g_fmt(state.fmt); |
| 380 |
|
| 381 |
v4l2_selection sel = { |
| 382 |
node->g_selection_type(), |
| 383 |
V4L2_SEL_TGT_CROP |
| 384 |
}; |
| 385 |
if (!node->g_selection(sel)) |
| 386 |
state.crop = sel.r; |
| 387 |
sel.target = V4L2_SEL_TGT_COMPOSE; |
| 388 |
if (!node->g_selection(sel)) |
| 389 |
state.compose = sel.r; |
| 390 |
node->get_interval(state.interval); |
| 391 |
|
| 392 |
v4l2_query_ext_ctrl qec = { 0 }; |
| 393 |
|
| 394 |
while (!node->query_ext_ctrl(qec, true, true)) { |
| 395 |
if (qec.flags & (V4L2_CTRL_FLAG_DISABLED | |
| 396 |
V4L2_CTRL_FLAG_READ_ONLY | |
| 397 |
V4L2_CTRL_FLAG_WRITE_ONLY | |
| 398 |
V4L2_CTRL_FLAG_VOLATILE)) |
| 399 |
continue; |
| 400 |
v4l2_ext_control ctrl = { qec.id }; |
| 401 |
if (qec.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) { |
| 402 |
ctrl.size = qec.elems * qec.elem_size; |
| 403 |
ctrl.ptr = malloc(ctrl.size); |
| 404 |
} |
| 405 |
state.control_vec.push_back(ctrl); |
| 406 |
} |
| 407 |
if (state.control_vec.empty()) |
| 408 |
return; |
| 409 |
state.controls.count = state.control_vec.size(); |
| 410 |
state.controls.controls = &state.control_vec[0]; |
| 411 |
node->g_ext_ctrls(state.controls); |
| 412 |
} |
| 413 |
|
| 414 |
static void restoreStateTimings(struct node *node, __u32 caps) |
| 415 |
{ |
| 416 |
if (caps & V4L2_IN_CAP_STD) |
| 417 |
node->s_std(state.std); |
| 418 |
if (caps & V4L2_IN_CAP_DV_TIMINGS) |
| 419 |
node->s_dv_timings(state.timings); |
| 420 |
if (caps & V4L2_IN_CAP_NATIVE_SIZE) { |
| 421 |
v4l2_selection sel = { |
| 422 |
node->g_selection_type(), |
| 423 |
V4L2_SEL_TGT_NATIVE_SIZE, |
| 424 |
0, state.native_size |
| 425 |
}; |
| 426 |
|
| 427 |
node->s_selection(sel); |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
static void restoreState() |
| 432 |
{ |
| 433 |
struct node *node = state.node; |
| 434 |
|
| 435 |
node->reopen(); |
| 436 |
if (node->has_inputs) { |
| 437 |
node->s_input(state.input.index); |
| 438 |
if (state.input.audioset) |
| 439 |
node->s_audio(state.ainput.index); |
| 440 |
if (node->g_caps() & V4L2_CAP_TUNER) { |
| 441 |
node->s_tuner(state.tuner); |
| 442 |
node->s_frequency(state.freq); |
| 443 |
} |
| 444 |
restoreStateTimings(node, state.input.capabilities); |
| 445 |
} |
| 446 |
if (node->has_outputs) { |
| 447 |
node->s_output(state.output.index); |
| 448 |
if (state.output.audioset) |
| 449 |
node->s_audout(state.aoutput.index); |
| 450 |
|
| 451 |
if (node->g_caps() & V4L2_CAP_MODULATOR) { |
| 452 |
node->s_modulator(state.modulator); |
| 453 |
node->s_frequency(state.freq); |
| 454 |
} |
| 455 |
restoreStateTimings(node, state.output.capabilities); |
| 456 |
} |
| 457 |
|
| 458 |
/* First restore the format */ |
| 459 |
node->s_fmt(state.fmt); |
| 460 |
|
| 461 |
v4l2_selection sel_compose = { |
| 462 |
node->g_selection_type(), |
| 463 |
V4L2_SEL_TGT_COMPOSE, |
| 464 |
0, state.compose |
| 465 |
}; |
| 466 |
v4l2_selection sel_crop = { |
| 467 |
node->g_selection_type(), |
| 468 |
V4L2_SEL_TGT_CROP, |
| 469 |
0, state.crop |
| 470 |
}; |
| 471 |
if (node->has_inputs) { |
| 472 |
/* |
| 473 |
* For capture restore the compose rectangle |
| 474 |
* before the crop rectangle. |
| 475 |
*/ |
| 476 |
if (sel_compose.r.width && sel_compose.r.height) |
| 477 |
node->s_selection(sel_compose); |
| 478 |
if (sel_crop.r.width && sel_crop.r.height) |
| 479 |
node->s_selection(sel_crop); |
| 480 |
} |
| 481 |
if (node->has_outputs) { |
| 482 |
/* |
| 483 |
* For output the crop rectangle should be |
| 484 |
* restored before the compose rectangle. |
| 485 |
*/ |
| 486 |
if (sel_crop.r.width && sel_crop.r.height) |
| 487 |
node->s_selection(sel_crop); |
| 488 |
if (sel_compose.r.width && sel_compose.r.height) |
| 489 |
node->s_selection(sel_compose); |
| 490 |
} |
| 491 |
if (state.interval.denominator) |
| 492 |
node->set_interval(state.interval); |
| 493 |
|
| 494 |
node->s_ext_ctrls(state.controls); |
| 495 |
// We need to reopen again so QUERYCAP is called again. |
| 496 |
// The vivid driver has controls (RDS related) that change |
| 497 |
// the capabilities, and if we don't do this, then the |
| 498 |
// internal caps stored in v4l_fd is out-of-sync with the |
| 499 |
// actual caps. |
| 500 |
node->reopen(); |
| 501 |
} |
| 502 |
|
| 503 |
__attribute__((noreturn)) |
| 504 |
static void signal_handler_interrupt(int signum) |
| 505 |
{ |
| 506 |
restoreState(); |
| 507 |
printf("\n"); |
| 508 |
std::exit(EXIT_FAILURE); |
| 509 |
} |
| 510 |
|
| 511 |
static void determine_codec_mask(struct node &node) |
| 512 |
{ |
| 513 |
struct v4l2_fmtdesc fmt_desc; |
| 514 |
int num_cap_fmts = 0; |
| 515 |
int num_compressed_cap_fmts = 0; |
| 516 |
int num_out_fmts = 0; |
| 517 |
int num_compressed_out_fmts = 0; |
| 518 |
unsigned mask = 0; |
| 519 |
|
| 520 |
node.codec_mask = 0; |
| 521 |
if (!node.has_vid_m2m()) |
| 522 |
return; |
| 523 |
|
| 524 |
if (node.enum_fmt(fmt_desc, true, 0, node.g_type())) |
| 525 |
return; |
| 526 |
|
| 527 |
do { |
| 528 |
if (is_codec_format(fmt_desc)) { |
| 529 |
num_compressed_cap_fmts++; |
| 530 |
switch (fmt_desc.pixelformat) { |
| 531 |
case V4L2_PIX_FMT_JPEG: |
| 532 |
case V4L2_PIX_FMT_MJPEG: |
| 533 |
mask |= JPEG_ENCODER; |
| 534 |
break; |
| 535 |
case V4L2_PIX_FMT_H263: |
| 536 |
case V4L2_PIX_FMT_H264: |
| 537 |
case V4L2_PIX_FMT_H264_NO_SC: |
| 538 |
case V4L2_PIX_FMT_H264_MVC: |
| 539 |
case V4L2_PIX_FMT_MPEG1: |
| 540 |
case V4L2_PIX_FMT_MPEG2: |
| 541 |
case V4L2_PIX_FMT_MPEG4: |
| 542 |
case V4L2_PIX_FMT_XVID: |
| 543 |
case V4L2_PIX_FMT_VC1_ANNEX_G: |
| 544 |
case V4L2_PIX_FMT_VC1_ANNEX_L: |
| 545 |
case V4L2_PIX_FMT_VP8: |
| 546 |
case V4L2_PIX_FMT_VP9: |
| 547 |
case V4L2_PIX_FMT_HEVC: |
| 548 |
case V4L2_PIX_FMT_FWHT: |
| 549 |
mask |= STATEFUL_ENCODER; |
| 550 |
break; |
| 551 |
#if 0 // There are no stateless encoders (yet) |
| 552 |
case V4L2_PIX_FMT_MPEG2_SLICE: |
| 553 |
mask |= STATELESS_ENCODER; |
| 554 |
break; |
| 555 |
#endif |
| 556 |
default: |
| 557 |
return; |
| 558 |
} |
| 559 |
} |
| 560 |
num_cap_fmts++; |
| 561 |
} while (!node.enum_fmt(fmt_desc)); |
| 562 |
|
| 563 |
|
| 564 |
if (node.enum_fmt(fmt_desc, true, 0, v4l_type_invert(node.g_type()))) |
| 565 |
return; |
| 566 |
|
| 567 |
do { |
| 568 |
if (is_codec_format(fmt_desc)) { |
| 569 |
num_compressed_out_fmts++; |
| 570 |
switch (fmt_desc.pixelformat) { |
| 571 |
case V4L2_PIX_FMT_JPEG: |
| 572 |
case V4L2_PIX_FMT_MJPEG: |
| 573 |
mask |= JPEG_DECODER; |
| 574 |
break; |
| 575 |
case V4L2_PIX_FMT_H263: |
| 576 |
case V4L2_PIX_FMT_H264: |
| 577 |
case V4L2_PIX_FMT_H264_NO_SC: |
| 578 |
case V4L2_PIX_FMT_H264_MVC: |
| 579 |
case V4L2_PIX_FMT_MPEG1: |
| 580 |
case V4L2_PIX_FMT_MPEG2: |
| 581 |
case V4L2_PIX_FMT_MPEG4: |
| 582 |
case V4L2_PIX_FMT_XVID: |
| 583 |
case V4L2_PIX_FMT_VC1_ANNEX_G: |
| 584 |
case V4L2_PIX_FMT_VC1_ANNEX_L: |
| 585 |
case V4L2_PIX_FMT_VP8: |
| 586 |
case V4L2_PIX_FMT_VP9: |
| 587 |
case V4L2_PIX_FMT_HEVC: |
| 588 |
case V4L2_PIX_FMT_FWHT: |
| 589 |
mask |= STATEFUL_DECODER; |
| 590 |
break; |
| 591 |
case V4L2_PIX_FMT_MPEG2_SLICE: |
| 592 |
case V4L2_PIX_FMT_H264_SLICE: |
| 593 |
case V4L2_PIX_FMT_HEVC_SLICE: |
| 594 |
case V4L2_PIX_FMT_VP8_FRAME: |
| 595 |
case V4L2_PIX_FMT_VP9_FRAME: |
| 596 |
case V4L2_PIX_FMT_AV1_FRAME: |
| 597 |
case V4L2_PIX_FMT_FWHT_STATELESS: |
| 598 |
mask |= STATELESS_DECODER; |
| 599 |
break; |
| 600 |
default: |
| 601 |
return; |
| 602 |
} |
| 603 |
} |
| 604 |
num_out_fmts++; |
| 605 |
} while (!node.enum_fmt(fmt_desc)); |
| 606 |
|
| 607 |
if (num_compressed_out_fmts == 0 && num_compressed_cap_fmts == num_cap_fmts) |
| 608 |
node.codec_mask = mask; |
| 609 |
else if (num_compressed_cap_fmts == 0 && num_compressed_out_fmts == num_out_fmts) |
| 610 |
node.codec_mask = mask; |
| 611 |
} |
| 612 |
|
| 613 |
static int testCap(struct node *node) |
| 614 |
{ |
| 615 |
struct v4l2_capability vcap; |
| 616 |
__u32 caps, dcaps; |
| 617 |
const __u32 video_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT | |
| 618 |
V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE | |
| 619 |
V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE | |
| 620 |
V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY; |
| 621 |
const __u32 vbi_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 622 |
V4L2_CAP_VBI_OUTPUT | V4L2_CAP_SLICED_VBI_OUTPUT; |
| 623 |
const __u32 sdr_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_SDR_OUTPUT; |
| 624 |
const __u32 radio_caps = V4L2_CAP_RADIO | V4L2_CAP_MODULATOR; |
| 625 |
const __u32 input_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY | |
| 626 |
V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 627 |
V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_HW_FREQ_SEEK | |
| 628 |
V4L2_CAP_TUNER | V4L2_CAP_SDR_CAPTURE | V4L2_CAP_META_CAPTURE; |
| 629 |
const __u32 output_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE | |
| 630 |
V4L2_CAP_VIDEO_OUTPUT_OVERLAY | V4L2_CAP_VBI_OUTPUT | |
| 631 |
V4L2_CAP_SDR_OUTPUT | V4L2_CAP_SLICED_VBI_OUTPUT | |
| 632 |
V4L2_CAP_MODULATOR | V4L2_CAP_META_OUTPUT; |
| 633 |
const __u32 overlay_caps = V4L2_CAP_VIDEO_OVERLAY | V4L2_CAP_VIDEO_OUTPUT_OVERLAY; |
| 634 |
const __u32 m2m_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE; |
| 635 |
const __u32 io_caps = V4L2_CAP_STREAMING | V4L2_CAP_READWRITE; |
| 636 |
const __u32 mplane_caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE | |
| 637 |
V4L2_CAP_VIDEO_M2M_MPLANE; |
| 638 |
const __u32 splane_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT | |
| 639 |
V4L2_CAP_VIDEO_M2M; |
| 640 |
const __u32 edid_caps = V4L2_CAP_EDID; |
| 641 |
|
| 642 |
memset(&vcap, 0xff, sizeof(vcap)); |
| 643 |
fail_on_test(doioctl(node, VIDIOC_QUERYCAP, &vcap)); |
| 644 |
if (has_mmu) |
| 645 |
fail_on_test(doioctl(node, VIDIOC_QUERYCAP, nullptr) != EFAULT); |
| 646 |
fail_on_test(check_ustring(vcap.driver, sizeof(vcap.driver))); |
| 647 |
fail_on_test(check_ustring(vcap.card, sizeof(vcap.card))); |
| 648 |
fail_on_test(check_ustring(vcap.bus_info, sizeof(vcap.bus_info))); |
| 649 |
// Check for valid prefixes |
| 650 |
if (memcmp(vcap.bus_info, "usb-", 4) && |
| 651 |
memcmp(vcap.bus_info, "PCI:", 4) && |
| 652 |
memcmp(vcap.bus_info, "PCIe:", 5) && |
| 653 |
memcmp(vcap.bus_info, "ISA:", 4) && |
| 654 |
memcmp(vcap.bus_info, "I2C:", 4) && |
| 655 |
memcmp(vcap.bus_info, "parport", 7) && |
| 656 |
memcmp(vcap.bus_info, "platform:", 9) && |
| 657 |
memcmp(vcap.bus_info, "rmi4:", 5) && |
| 658 |
memcmp(vcap.bus_info, "libcamera:", 10) && |
| 659 |
memcmp(vcap.bus_info, "serio:", 6) && |
| 660 |
memcmp(vcap.bus_info, "gadget.", 7)) |
| 661 |
return fail("missing bus_info prefix ('%s')\n", vcap.bus_info); |
| 662 |
if (!node->media_bus_info.empty() && |
| 663 |
node->media_bus_info != std::string(reinterpret_cast<const char *>(vcap.bus_info))) |
| 664 |
warn("media bus_info '%s' differs from V4L2 bus_info '%s'\n", |
| 665 |
node->media_bus_info.c_str(), vcap.bus_info); |
| 666 |
fail_on_test((vcap.version >> 16) < 3); |
| 667 |
if (vcap.version >= 0x050900) // Present from 5.9.0 onwards |
| 668 |
node->might_support_cache_hints = true; |
| 669 |
fail_on_test(check_0(vcap.reserved, sizeof(vcap.reserved))); |
| 670 |
caps = vcap.capabilities; |
| 671 |
dcaps = vcap.device_caps; |
| 672 |
node->is_m2m = dcaps & m2m_caps; |
| 673 |
fail_on_test(caps == 0); |
| 674 |
fail_on_test(!(caps & V4L2_CAP_DEVICE_CAPS)); |
| 675 |
fail_on_test(dcaps & V4L2_CAP_DEVICE_CAPS); |
| 676 |
fail_on_test(dcaps & ~caps); |
| 677 |
fail_on_test(!(dcaps & caps)); |
| 678 |
// set by the core, so this really should always be there |
| 679 |
// for a modern driver for both caps and dcaps |
| 680 |
fail_on_test(!(caps & V4L2_CAP_EXT_PIX_FORMAT)); |
| 681 |
//fail_on_test(!(dcaps & V4L2_CAP_EXT_PIX_FORMAT)); |
| 682 |
if (node->is_video) { |
| 683 |
fail_on_test(!(dcaps & (video_caps | edid_caps))); |
| 684 |
if (dcaps & edid_caps) |
| 685 |
fail_on_test(dcaps & video_caps); |
| 686 |
else if (dcaps & video_caps) |
| 687 |
fail_on_test(dcaps & edid_caps); |
| 688 |
} |
| 689 |
fail_on_test(node->is_radio && !(dcaps & radio_caps)); |
| 690 |
// V4L2_CAP_AUDIO is invalid for radio and sdr |
| 691 |
fail_on_test(node->is_radio && (dcaps & V4L2_CAP_AUDIO)); |
| 692 |
fail_on_test(node->is_sdr && (dcaps & V4L2_CAP_AUDIO)); |
| 693 |
fail_on_test(node->is_vbi && !(dcaps & vbi_caps)); |
| 694 |
fail_on_test(node->is_sdr && !(dcaps & sdr_caps)); |
| 695 |
// You can't have both set due to missing buffer type in VIDIOC_G/S_FBUF |
| 696 |
fail_on_test((dcaps & overlay_caps) == overlay_caps); |
| 697 |
// Overlay support makes no sense for m2m devices |
| 698 |
fail_on_test((dcaps & m2m_caps) && (dcaps & overlay_caps)); |
| 699 |
fail_on_test(node->is_video && (dcaps & (vbi_caps | radio_caps | sdr_caps))); |
| 700 |
fail_on_test(node->is_radio && (dcaps & (vbi_caps | video_caps | sdr_caps))); |
| 701 |
fail_on_test(node->is_vbi && (dcaps & (video_caps | radio_caps | sdr_caps))); |
| 702 |
fail_on_test(node->is_sdr && (dcaps & (video_caps | V4L2_CAP_RADIO | vbi_caps))); |
| 703 |
if (node->is_m2m) { |
| 704 |
fail_on_test((dcaps & input_caps) && (dcaps & output_caps)); |
| 705 |
} else { |
| 706 |
if (dcaps & input_caps) |
| 707 |
fail_on_test(dcaps & output_caps); |
| 708 |
if (dcaps & output_caps) |
| 709 |
fail_on_test(dcaps & input_caps); |
| 710 |
} |
| 711 |
if (node->can_capture || node->can_output) { |
| 712 |
// whether io_caps need to be set for RDS capture/output is |
| 713 |
// checked elsewhere as that depends on the tuner/modulator |
| 714 |
// capabilities. |
| 715 |
if (!(dcaps & (V4L2_CAP_RDS_CAPTURE | V4L2_CAP_RDS_OUTPUT))) |
| 716 |
fail_on_test(!(dcaps & io_caps)); |
| 717 |
} else { |
| 718 |
fail_on_test(dcaps & io_caps); |
| 719 |
} |
| 720 |
// having both mplane and splane caps is not allowed (at least for now) |
| 721 |
fail_on_test((dcaps & mplane_caps) && (dcaps & splane_caps)); |
| 722 |
|
| 723 |
if (node->codec_mask) { |
| 724 |
bool found_bit = false; |
| 725 |
|
| 726 |
// Only one bit may be set in the mask |
| 727 |
for (unsigned i = 0; i < 32; i++) |
| 728 |
if (node->codec_mask & (1U << i)) { |
| 729 |
fail_on_test(found_bit); |
| 730 |
found_bit = true; |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
return 0; |
| 735 |
} |
| 736 |
|
| 737 |
#define NR_OPENS 100 |
| 738 |
static int testUnlimitedOpens(struct node *node) |
| 739 |
{ |
| 740 |
int fds[NR_OPENS]; |
| 741 |
unsigned i; |
| 742 |
bool ok; |
| 743 |
|
| 744 |
/* |
| 745 |
* There should *not* be an artificial limit to the number |
| 746 |
* of open()s you can do on a V4L2 device node. So test whether |
| 747 |
* you can open a device node at least 100 times. |
| 748 |
* |
| 749 |
* And please don't start rejecting opens in your driver at 101! |
| 750 |
* There really shouldn't be a limit in the driver. |
| 751 |
* |
| 752 |
* If there are resource limits, then check against those limits |
| 753 |
* where they are actually needed. |
| 754 |
*/ |
| 755 |
for (i = 0; i < NR_OPENS; i++) { |
| 756 |
fds[i] = open(node->device, O_RDWR); |
| 757 |
if (fds[i] < 0) |
| 758 |
break; |
| 759 |
} |
| 760 |
ok = i == NR_OPENS; |
| 761 |
while (i--) |
| 762 |
close(fds[i]); |
| 763 |
fail_on_test(!ok); |
| 764 |
return 0; |
| 765 |
} |
| 766 |
|
| 767 |
static int check_prio(struct node *node, struct node *node2, enum v4l2_priority match) |
| 768 |
{ |
| 769 |
enum v4l2_priority prio; |
| 770 |
|
| 771 |
// Must be able to get priority |
| 772 |
fail_on_test(doioctl(node, VIDIOC_G_PRIORITY, &prio)); |
| 773 |
// Must match the expected prio |
| 774 |
fail_on_test(prio != match); |
| 775 |
fail_on_test(doioctl(node2, VIDIOC_G_PRIORITY, &prio)); |
| 776 |
fail_on_test(prio != match); |
| 777 |
return 0; |
| 778 |
} |
| 779 |
|
| 780 |
static int testPrio(struct node *node, struct node *node2) |
| 781 |
{ |
| 782 |
enum v4l2_priority prio; |
| 783 |
int err; |
| 784 |
|
| 785 |
err = check_prio(node, node2, V4L2_PRIORITY_DEFAULT); |
| 786 |
if (err) |
| 787 |
return err; |
| 788 |
|
| 789 |
prio = V4L2_PRIORITY_RECORD; |
| 790 |
// Must be able to change priority |
| 791 |
fail_on_test(doioctl(node, VIDIOC_S_PRIORITY, &prio)); |
| 792 |
// Must match the new prio |
| 793 |
fail_on_test(check_prio(node, node2, V4L2_PRIORITY_RECORD)); |
| 794 |
|
| 795 |
prio = V4L2_PRIORITY_INTERACTIVE; |
| 796 |
// Going back to interactive on the other node must fail |
| 797 |
fail_on_test(!doioctl(node2, VIDIOC_S_PRIORITY, &prio)); |
| 798 |
prio = V4L2_PRIORITY_INTERACTIVE; |
| 799 |
// Changing it on the first node must work. |
| 800 |
fail_on_test(doioctl(node, VIDIOC_S_PRIORITY, &prio)); |
| 801 |
fail_on_test(check_prio(node, node2, V4L2_PRIORITY_INTERACTIVE)); |
| 802 |
return 0; |
| 803 |
} |
| 804 |
|
| 805 |
static int testInvalidIoctls(struct node *node, char type) |
| 806 |
{ |
| 807 |
unsigned ioc = _IOC(_IOC_NONE, type, 0xff, 0); |
| 808 |
unsigned char buf[0x4000] = {}; |
| 809 |
|
| 810 |
fail_on_test(doioctl(node, ioc, nullptr) != ENOTTY); |
| 811 |
ioc = _IOC(_IOC_NONE, type, 0, 0x3fff); |
| 812 |
fail_on_test(doioctl(node, ioc, nullptr) != ENOTTY); |
| 813 |
ioc = _IOC(_IOC_READ, type, 0, 0x3fff); |
| 814 |
fail_on_test(doioctl(node, ioc, buf) != ENOTTY); |
| 815 |
fail_on_test(check_0(buf, sizeof(buf))); |
| 816 |
ioc = _IOC(_IOC_WRITE, type, 0, 0x3fff); |
| 817 |
fail_on_test(doioctl(node, ioc, buf) != ENOTTY); |
| 818 |
fail_on_test(check_0(buf, sizeof(buf))); |
| 819 |
ioc = _IOC(_IOC_READ | _IOC_WRITE, type, 0, 0x3fff); |
| 820 |
fail_on_test(doioctl(node, ioc, buf) != ENOTTY); |
| 821 |
fail_on_test(check_0(buf, sizeof(buf))); |
| 822 |
return 0; |
| 823 |
} |
| 824 |
|
| 825 |
static void streamingSetup(struct node *node) |
| 826 |
{ |
| 827 |
if (node->can_capture) { |
| 828 |
v4l2_fract min_period = { 1, 1000 }; |
| 829 |
struct v4l2_input input; |
| 830 |
|
| 831 |
memset(&input, 0, sizeof(input)); |
| 832 |
doioctl(node, VIDIOC_G_INPUT, &input.index); |
| 833 |
doioctl(node, VIDIOC_ENUMINPUT, &input); |
| 834 |
node->cur_io_caps = input.capabilities; |
| 835 |
node->set_interval(min_period); |
| 836 |
} else if (node->can_output) { |
| 837 |
struct v4l2_output output; |
| 838 |
|
| 839 |
memset(&output, 0, sizeof(output)); |
| 840 |
doioctl(node, VIDIOC_G_OUTPUT, &output.index); |
| 841 |
doioctl(node, VIDIOC_ENUMOUTPUT, &output); |
| 842 |
node->cur_io_caps = output.capabilities; |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
static int parse_subopt(char **subs, const char * const *subopts, char **value) |
| 847 |
{ |
| 848 |
int opt = v4l_getsubopt(subs, const_cast<char * const *>(subopts), value); |
| 849 |
|
| 850 |
if (opt == -1) { |
| 851 |
fprintf(stderr, "Invalid suboptions specified\n"); |
| 852 |
return -1; |
| 853 |
} |
| 854 |
if (*value == nullptr) { |
| 855 |
fprintf(stderr, "No value given to suboption <%s>\n", |
| 856 |
subopts[opt]); |
| 857 |
return -1; |
| 858 |
} |
| 859 |
return opt; |
| 860 |
} |
| 861 |
|
| 862 |
static int open_media_bus_info(const std::string &bus_info, std::string &media_devname) |
| 863 |
{ |
| 864 |
DIR *dp; |
| 865 |
struct dirent *ep; |
| 866 |
|
| 867 |
dp = opendir("/dev"); |
| 868 |
if (dp == nullptr) |
| 869 |
return -1; |
| 870 |
|
| 871 |
while ((ep = readdir(dp))) { |
| 872 |
const char *name = ep->d_name; |
| 873 |
|
| 874 |
if (!memcmp(name, "media", 5) && isdigit(name[5])) { |
| 875 |
struct media_device_info mdi; |
| 876 |
media_devname = std::string("/dev/") + name; |
| 877 |
|
| 878 |
int fd = open(media_devname.c_str(), O_RDWR); |
| 879 |
if (fd < 0) |
| 880 |
continue; |
| 881 |
if (!ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi) && |
| 882 |
bus_info == mdi.bus_info) { |
| 883 |
closedir(dp); |
| 884 |
return fd; |
| 885 |
} |
| 886 |
close(fd); |
| 887 |
} |
| 888 |
} |
| 889 |
closedir(dp); |
| 890 |
return -1; |
| 891 |
} |
| 892 |
|
| 893 |
static std::string make_devname(const char *device, const char *devname, |
| 894 |
const std::string &media_bus_info, bool is_media = false) |
| 895 |
{ |
| 896 |
if (device[0] >= '0' && device[0] <= '9' && strlen(device) <= 3) { |
| 897 |
char newdev[32]; |
| 898 |
|
| 899 |
sprintf(newdev, "/dev/%s%s", devname, device); |
| 900 |
return newdev; |
| 901 |
} |
| 902 |
if (media_bus_info.empty()) |
| 903 |
return device; |
| 904 |
|
| 905 |
std::string media_devname; |
| 906 |
int media_fd = open_media_bus_info(media_bus_info, media_devname); |
| 907 |
if (media_fd < 0) |
| 908 |
return device; |
| 909 |
if (is_media) { |
| 910 |
close(media_fd); |
| 911 |
return media_devname; |
| 912 |
} |
| 913 |
|
| 914 |
media_v2_topology topology; |
| 915 |
memset(&topology, 0, sizeof(topology)); |
| 916 |
if (ioctl(media_fd, MEDIA_IOC_G_TOPOLOGY, &topology)) { |
| 917 |
close(media_fd); |
| 918 |
return device; |
| 919 |
} |
| 920 |
|
| 921 |
auto ents = new media_v2_entity[topology.num_entities]; |
| 922 |
topology.ptr_entities = (uintptr_t)ents; |
| 923 |
auto links = new media_v2_link[topology.num_links]; |
| 924 |
topology.ptr_links = (uintptr_t)links; |
| 925 |
auto ifaces = new media_v2_interface[topology.num_interfaces]; |
| 926 |
topology.ptr_interfaces = (uintptr_t)ifaces; |
| 927 |
|
| 928 |
unsigned i, ent_id, iface_id = 0; |
| 929 |
|
| 930 |
std::string result(device); |
| 931 |
|
| 932 |
if (ioctl(media_fd, MEDIA_IOC_G_TOPOLOGY, &topology)) |
| 933 |
goto err; |
| 934 |
|
| 935 |
if (device[0] == '0' && device[1] == 'x') |
| 936 |
iface_id = strtoul(device, nullptr, 16); |
| 937 |
|
| 938 |
if (!iface_id) { |
| 939 |
for (i = 0; i < topology.num_entities; i++) |
| 940 |
if (!strcmp(ents[i].name, device)) |
| 941 |
break; |
| 942 |
if (i >= topology.num_entities) |
| 943 |
goto err; |
| 944 |
ent_id = ents[i].id; |
| 945 |
for (i = 0; i < topology.num_links; i++) |
| 946 |
if (links[i].sink_id == ent_id && |
| 947 |
(links[i].flags & MEDIA_LNK_FL_LINK_TYPE) == |
| 948 |
MEDIA_LNK_FL_INTERFACE_LINK) |
| 949 |
break; |
| 950 |
if (i >= topology.num_links) |
| 951 |
goto err; |
| 952 |
iface_id = links[i].source_id; |
| 953 |
} |
| 954 |
for (i = 0; i < topology.num_interfaces; i++) |
| 955 |
if (ifaces[i].id == iface_id) |
| 956 |
break; |
| 957 |
if (i >= topology.num_interfaces) |
| 958 |
goto err; |
| 959 |
|
| 960 |
result = mi_media_get_device(ifaces[i].devnode.major, ifaces[i].devnode.minor); |
| 961 |
|
| 962 |
err: |
| 963 |
delete [] ents; |
| 964 |
delete [] links; |
| 965 |
delete [] ifaces; |
| 966 |
close(media_fd); |
| 967 |
return result; |
| 968 |
} |
| 969 |
|
| 970 |
void testNode(struct node &node, struct node &node_m2m_cap, struct node &expbuf_node, media_type type, |
| 971 |
unsigned frame_count, unsigned all_fmt_frame_count, int parent_media_fd) |
| 972 |
{ |
| 973 |
struct node node2; |
| 974 |
struct v4l2_capability vcap = {}; |
| 975 |
struct v4l2_subdev_capability subdevcap = {}; |
| 976 |
struct v4l2_subdev_client_capability subdevclientcap = {}; |
| 977 |
std::string driver; |
| 978 |
|
| 979 |
tests_total = tests_ok = warnings = 0; |
| 980 |
|
| 981 |
node.is_video = type == MEDIA_TYPE_VIDEO; |
| 982 |
node.is_vbi = type == MEDIA_TYPE_VBI; |
| 983 |
node.is_radio = type == MEDIA_TYPE_RADIO; |
| 984 |
node.is_sdr = type == MEDIA_TYPE_SDR; |
| 985 |
node.is_touch = type == MEDIA_TYPE_TOUCH; |
| 986 |
|
| 987 |
if (node.is_v4l2()) { |
| 988 |
doioctl(&node, VIDIOC_QUERYCAP, &vcap); |
| 989 |
driver = reinterpret_cast<const char *>(vcap.driver); |
| 990 |
is_uvcvideo = driver == "uvcvideo"; |
| 991 |
is_vivid = driver == "vivid"; |
| 992 |
if (is_vivid) |
| 993 |
node.bus_info = reinterpret_cast<const char *>(vcap.bus_info); |
| 994 |
determine_codec_mask(node); |
| 995 |
} else if (node.is_subdev()) { |
| 996 |
doioctl(&node, VIDIOC_SUBDEV_QUERYCAP, &subdevcap); |
| 997 |
subdevclientcap.capabilities = ~0ULL; |
| 998 |
if (doioctl(&node, VIDIOC_SUBDEV_S_CLIENT_CAP, &subdevclientcap)) |
| 999 |
subdevclientcap.capabilities = 0ULL; |
| 1000 |
} else { |
| 1001 |
memset(&vcap, 0, sizeof(vcap)); |
| 1002 |
} |
| 1003 |
|
| 1004 |
if (!node.is_media()) { |
| 1005 |
if (parent_media_fd >= 0) |
| 1006 |
media_fd = parent_media_fd; |
| 1007 |
else |
| 1008 |
media_fd = mi_get_media_fd(node.g_fd(), node.bus_info); |
| 1009 |
} |
| 1010 |
|
| 1011 |
int fd = node.is_media() ? node.g_fd() : media_fd; |
| 1012 |
if (fd >= 0) { |
| 1013 |
struct media_device_info mdinfo; |
| 1014 |
|
| 1015 |
if (!ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdinfo)) { |
| 1016 |
if (!node.is_v4l2()) |
| 1017 |
driver = mdinfo.driver; |
| 1018 |
node.media_bus_info = mdinfo.bus_info; |
| 1019 |
node.has_media = true; |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
if (driver.empty()) |
| 1024 |
printf("Compliance test for device "); |
| 1025 |
else |
| 1026 |
printf("Compliance test for %s device ", driver.c_str()); |
| 1027 |
printf("%s%s:\n\n", node.device, node.g_direct() ? "" : " (using libv4l2)"); |
| 1028 |
|
| 1029 |
if (node.g_caps() & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE | |
| 1030 |
V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 1031 |
V4L2_CAP_META_CAPTURE)) |
| 1032 |
node.has_inputs = true; |
| 1033 |
if (node.g_caps() & (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VBI_OUTPUT | |
| 1034 |
V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_SLICED_VBI_OUTPUT | |
| 1035 |
V4L2_CAP_META_OUTPUT)) |
| 1036 |
node.has_outputs = true; |
| 1037 |
if (node.g_caps() & V4L2_CAP_EDID) { |
| 1038 |
int tmp; |
| 1039 |
|
| 1040 |
if (!ioctl(node.g_fd(), VIDIOC_G_INPUT, &tmp)) |
| 1041 |
node.has_inputs = true; |
| 1042 |
else if (!ioctl(node.g_fd(), VIDIOC_G_OUTPUT, &tmp)) |
| 1043 |
node.has_outputs = true; |
| 1044 |
} |
| 1045 |
if (node.g_caps() & (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE | |
| 1046 |
V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_M2M_MPLANE | |
| 1047 |
V4L2_CAP_VIDEO_M2M | V4L2_CAP_SLICED_VBI_CAPTURE | |
| 1048 |
V4L2_CAP_RDS_CAPTURE | V4L2_CAP_SDR_CAPTURE | |
| 1049 |
V4L2_CAP_META_CAPTURE)) |
| 1050 |
node.can_capture = true; |
| 1051 |
if (node.g_caps() & (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VBI_OUTPUT | |
| 1052 |
V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_VIDEO_M2M_MPLANE | |
| 1053 |
V4L2_CAP_VIDEO_M2M | V4L2_CAP_SLICED_VBI_OUTPUT | |
| 1054 |
V4L2_CAP_RDS_OUTPUT | V4L2_CAP_SDR_OUTPUT | |
| 1055 |
V4L2_CAP_META_OUTPUT)) |
| 1056 |
node.can_output = true; |
| 1057 |
if (node.g_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE | |
| 1058 |
V4L2_CAP_VIDEO_M2M_MPLANE)) |
| 1059 |
node.is_planar = true; |
| 1060 |
if (node.g_caps() & (V4L2_CAP_META_CAPTURE | V4L2_CAP_META_OUTPUT)) { |
| 1061 |
node.is_video = false; |
| 1062 |
node.is_meta = true; |
| 1063 |
} |
| 1064 |
if (node.g_caps() & V4L2_CAP_IO_MC) |
| 1065 |
node.is_io_mc = true; |
| 1066 |
|
| 1067 |
/* Information Opts */ |
| 1068 |
|
| 1069 |
if (node.is_v4l2()) { |
| 1070 |
printf("Driver Info:\n"); |
| 1071 |
v4l2_info_capability(vcap); |
| 1072 |
switch (node.codec_mask) { |
| 1073 |
case JPEG_ENCODER: |
| 1074 |
printf("\tDetected JPEG Encoder\n"); |
| 1075 |
break; |
| 1076 |
case JPEG_DECODER: |
| 1077 |
printf("\tDetected JPEG Decoder\n"); |
| 1078 |
break; |
| 1079 |
case STATEFUL_ENCODER: |
| 1080 |
printf("\tDetected Stateful Encoder\n"); |
| 1081 |
break; |
| 1082 |
case STATEFUL_DECODER: |
| 1083 |
printf("\tDetected Stateful Decoder\n"); |
| 1084 |
break; |
| 1085 |
case STATELESS_ENCODER: |
| 1086 |
printf("\tDetected Stateless Encoder\n"); |
| 1087 |
break; |
| 1088 |
case STATELESS_DECODER: |
| 1089 |
printf("\tDetected Stateless Decoder\n"); |
| 1090 |
break; |
| 1091 |
} |
| 1092 |
} else if (node.is_subdev()) { |
| 1093 |
printf("Driver Info:\n"); |
| 1094 |
v4l2_info_subdev_capability(subdevcap, subdevclientcap); |
| 1095 |
} |
| 1096 |
|
| 1097 |
__u32 ent_id = 0; |
| 1098 |
bool is_invalid = false; |
| 1099 |
|
| 1100 |
if (node.is_media()) |
| 1101 |
mi_media_info_for_fd(node.g_fd(), -1, &is_invalid); |
| 1102 |
else if (media_fd >= 0) |
| 1103 |
ent_id = mi_media_info_for_fd(media_fd, node.g_fd(), &is_invalid, &node.function); |
| 1104 |
|
| 1105 |
if (ent_id != MEDIA_ENT_F_UNKNOWN) { |
| 1106 |
memset(&node.entity, 0, sizeof(node.entity)); |
| 1107 |
node.entity.id = ent_id; |
| 1108 |
if (!ioctl(media_fd, MEDIA_IOC_ENUM_ENTITIES, &node.entity)) { |
| 1109 |
struct media_links_enum links_enum; |
| 1110 |
|
| 1111 |
node.pads = new media_pad_desc[node.entity.pads]; |
| 1112 |
node.links = new media_link_desc[node.entity.links]; |
| 1113 |
memset(&links_enum, 0, sizeof(links_enum)); |
| 1114 |
links_enum.entity = ent_id; |
| 1115 |
links_enum.pads = node.pads; |
| 1116 |
links_enum.links = node.links; |
| 1117 |
if (ioctl(media_fd, MEDIA_IOC_ENUM_LINKS, &links_enum)) |
| 1118 |
node.entity.id = 0; |
| 1119 |
} else { |
| 1120 |
node.entity.id = 0; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
/* Required ioctls */ |
| 1125 |
|
| 1126 |
printf("\nRequired ioctls:\n"); |
| 1127 |
|
| 1128 |
if (ent_id) |
| 1129 |
printf("\ttest MC information (see 'Media Driver Info' above): %s\n", ok(is_invalid ? -1 : 0)); |
| 1130 |
|
| 1131 |
if (node.is_v4l2()) |
| 1132 |
printf("\ttest VIDIOC_QUERYCAP: %s\n", ok(testCap(&node))); |
| 1133 |
else if (node.is_subdev()) |
| 1134 |
printf("\ttest VIDIOC_SUDBEV_QUERYCAP: %s\n", ok(testSubDevCap(&node))); |
| 1135 |
|
| 1136 |
if (node.is_v4l2() || node.is_subdev()) |
| 1137 |
printf("\ttest invalid ioctls: %s\n", ok(testInvalidIoctls(&node, 'V'))); |
| 1138 |
|
| 1139 |
if (node.is_media()) { |
| 1140 |
printf("\ttest MEDIA_IOC_DEVICE_INFO: %s\n", |
| 1141 |
ok(testMediaDeviceInfo(&node))); |
| 1142 |
printf("\ttest invalid ioctls: %s\n", ok(testInvalidIoctls(&node, '|'))); |
| 1143 |
} |
| 1144 |
printf("\n"); |
| 1145 |
|
| 1146 |
/* Multiple opens */ |
| 1147 |
|
| 1148 |
printf("Allow for multiple opens:\n"); |
| 1149 |
node2 = node; |
| 1150 |
switch (type) { |
| 1151 |
case MEDIA_TYPE_SUBDEV: |
| 1152 |
printf("\ttest second %s open: %s\n", node.device, |
| 1153 |
ok(node2.subdev_open(node.device, false) >= 0 ? 0 : errno)); |
| 1154 |
if (node2.g_fd() >= 0) |
| 1155 |
printf("\ttest VIDIOC_SUBDEV_QUERYCAP: %s\n", ok(testSubDevCap(&node2))); |
| 1156 |
break; |
| 1157 |
case MEDIA_TYPE_MEDIA: |
| 1158 |
printf("\ttest second %s open: %s\n", node.device, |
| 1159 |
ok(node2.media_open(node.device, false) >= 0 ? 0 : errno)); |
| 1160 |
if (node2.g_fd() >= 0) |
| 1161 |
printf("\ttest MEDIA_IOC_DEVICE_INFO: %s\n", ok(testMediaDeviceInfo(&node2))); |
| 1162 |
break; |
| 1163 |
default: |
| 1164 |
printf("\ttest second %s open: %s\n", node.device, |
| 1165 |
ok(node2.open(node.device, false) >= 0 ? 0 : errno)); |
| 1166 |
if (node2.g_fd() >= 0) { |
| 1167 |
printf("\ttest VIDIOC_QUERYCAP: %s\n", ok(testCap(&node2))); |
| 1168 |
printf("\ttest VIDIOC_G/S_PRIORITY: %s\n", |
| 1169 |
ok(testPrio(&node, &node2))); |
| 1170 |
} |
| 1171 |
break; |
| 1172 |
} |
| 1173 |
if (node2.g_fd() >= 0) |
| 1174 |
node.node2 = &node2; |
| 1175 |
|
| 1176 |
printf("\ttest for unlimited opens: %s\n", |
| 1177 |
ok(testUnlimitedOpens(&node))); |
| 1178 |
|
| 1179 |
printf("\n"); |
| 1180 |
storeState(&node); |
| 1181 |
|
| 1182 |
/* register signal handler for interrupt signal, to exit gracefully */ |
| 1183 |
signal(SIGINT, signal_handler_interrupt); |
| 1184 |
|
| 1185 |
unsigned cur_io = 0; |
| 1186 |
unsigned min_io = 0; |
| 1187 |
unsigned max_io = 0; |
| 1188 |
|
| 1189 |
/* Media ioctls */ |
| 1190 |
|
| 1191 |
if (node.is_media()) { |
| 1192 |
printf("Media Controller ioctls:\n"); |
| 1193 |
printf("\ttest MEDIA_IOC_G_TOPOLOGY: %s\n", ok(testMediaTopology(&node))); |
| 1194 |
if (node.topology) |
| 1195 |
printf("\tEntities: %u Interfaces: %u Pads: %u Links: %u\n", |
| 1196 |
node.topology->num_entities, |
| 1197 |
node.topology->num_interfaces, |
| 1198 |
node.topology->num_pads, |
| 1199 |
node.topology->num_links); |
| 1200 |
printf("\ttest MEDIA_IOC_ENUM_ENTITIES/LINKS: %s\n", ok(testMediaEnum(&node))); |
| 1201 |
printf("\ttest MEDIA_IOC_SETUP_LINK: %s\n", ok(testMediaSetupLink(&node))); |
| 1202 |
printf("\n"); |
| 1203 |
goto show_total; |
| 1204 |
} |
| 1205 |
|
| 1206 |
/* Debug ioctls */ |
| 1207 |
|
| 1208 |
printf("Debug ioctls:\n"); |
| 1209 |
if (node.is_v4l2()) |
| 1210 |
printf("\ttest VIDIOC_DBG_G/S_REGISTER: %s\n", ok(testRegister(&node))); |
| 1211 |
printf("\ttest VIDIOC_LOG_STATUS: %s\n", ok(testLogStatus(&node))); |
| 1212 |
printf("\n"); |
| 1213 |
|
| 1214 |
/* Input ioctls */ |
| 1215 |
|
| 1216 |
printf("Input ioctls:\n"); |
| 1217 |
printf("\ttest VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: %s\n", ok(testTuner(&node))); |
| 1218 |
printf("\ttest VIDIOC_G/S_FREQUENCY: %s\n", ok(testTunerFreq(&node))); |
| 1219 |
printf("\ttest VIDIOC_S_HW_FREQ_SEEK: %s\n", ok(testTunerHwSeek(&node))); |
| 1220 |
printf("\ttest VIDIOC_ENUMAUDIO: %s\n", ok(testEnumInputAudio(&node))); |
| 1221 |
printf("\ttest VIDIOC_G/S/ENUMINPUT: %s\n", ok(testInput(&node))); |
| 1222 |
printf("\ttest VIDIOC_G/S_AUDIO: %s\n", ok(testInputAudio(&node))); |
| 1223 |
printf("\tInputs: %d Audio Inputs: %d Tuners: %d\n", |
| 1224 |
node.inputs, node.audio_inputs, node.tuners); |
| 1225 |
printf("\n"); |
| 1226 |
|
| 1227 |
/* Output ioctls */ |
| 1228 |
|
| 1229 |
printf("Output ioctls:\n"); |
| 1230 |
printf("\ttest VIDIOC_G/S_MODULATOR: %s\n", ok(testModulator(&node))); |
| 1231 |
printf("\ttest VIDIOC_G/S_FREQUENCY: %s\n", ok(testModulatorFreq(&node))); |
| 1232 |
printf("\ttest VIDIOC_ENUMAUDOUT: %s\n", ok(testEnumOutputAudio(&node))); |
| 1233 |
printf("\ttest VIDIOC_G/S/ENUMOUTPUT: %s\n", ok(testOutput(&node))); |
| 1234 |
printf("\ttest VIDIOC_G/S_AUDOUT: %s\n", ok(testOutputAudio(&node))); |
| 1235 |
printf("\tOutputs: %d Audio Outputs: %d Modulators: %d\n", |
| 1236 |
node.outputs, node.audio_outputs, node.modulators); |
| 1237 |
printf("\n"); |
| 1238 |
|
| 1239 |
/* I/O configuration ioctls */ |
| 1240 |
|
| 1241 |
printf("Input/Output configuration ioctls:\n"); |
| 1242 |
printf("\ttest VIDIOC_ENUM/G/S/QUERY_STD: %s\n", ok(testStd(&node))); |
| 1243 |
printf("\ttest VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: %s\n", ok(testTimings(&node))); |
| 1244 |
printf("\ttest VIDIOC_DV_TIMINGS_CAP: %s\n", ok(testTimingsCap(&node))); |
| 1245 |
printf("\ttest VIDIOC_G/S_EDID: %s\n", ok(testEdid(&node))); |
| 1246 |
printf("\n"); |
| 1247 |
|
| 1248 |
/* Sub-device ioctls */ |
| 1249 |
|
| 1250 |
if (node.is_subdev()) { |
| 1251 |
bool has_source = false; |
| 1252 |
bool has_sink = false; |
| 1253 |
struct v4l2_subdev_routing sd_routing[2] = {}; |
| 1254 |
struct v4l2_subdev_route sd_routes[2][NUM_ROUTES_MAX] = {}; |
| 1255 |
bool has_routes = !!(subdevcap.capabilities & V4L2_SUBDEV_CAP_STREAMS); |
| 1256 |
int ret; |
| 1257 |
|
| 1258 |
node.frame_interval_pad = -1; |
| 1259 |
node.enum_frame_interval_pad = -1; |
| 1260 |
for (unsigned pad = 0; pad < node.entity.pads; pad++) { |
| 1261 |
if (node.pads[pad].flags & MEDIA_PAD_FL_SINK) |
| 1262 |
has_sink = true; |
| 1263 |
if (node.pads[pad].flags & MEDIA_PAD_FL_SOURCE) |
| 1264 |
has_source = true; |
| 1265 |
} |
| 1266 |
node.is_passthrough_subdev = has_source && has_sink; |
| 1267 |
|
| 1268 |
if (has_routes) { |
| 1269 |
printf("Sub-Device routing ioctls:\n"); |
| 1270 |
|
| 1271 |
for (unsigned which = V4L2_SUBDEV_FORMAT_TRY; |
| 1272 |
which <= V4L2_SUBDEV_FORMAT_ACTIVE; which++) { |
| 1273 |
|
| 1274 |
printf("\ttest %s VIDIOC_SUBDEV_G_ROUTING/VIDIOC_SUBDEV_S_ROUTING: %s\n", |
| 1275 |
which ? "Active" : "Try", |
| 1276 |
ok(testSubDevRouting(&node, which))); |
| 1277 |
} |
| 1278 |
|
| 1279 |
printf("\n"); |
| 1280 |
|
| 1281 |
for (unsigned which = V4L2_SUBDEV_FORMAT_TRY; |
| 1282 |
which <= V4L2_SUBDEV_FORMAT_ACTIVE; which++) { |
| 1283 |
struct v4l2_subdev_routing &routing = sd_routing[which]; |
| 1284 |
|
| 1285 |
routing.which = which; |
| 1286 |
routing.routes = (uintptr_t)sd_routes[which]; |
| 1287 |
routing.len_routes = NUM_ROUTES_MAX; |
| 1288 |
routing.num_routes = 0; |
| 1289 |
|
| 1290 |
ret = doioctl(&node, VIDIOC_SUBDEV_G_ROUTING, &routing); |
| 1291 |
if (ret) { |
| 1292 |
fail("VIDIOC_SUBDEV_G_ROUTING: failed to get routing\n"); |
| 1293 |
routing.num_routes = 0; |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
|
| 1298 |
for (unsigned pad = 0; pad < node.entity.pads; pad++) { |
| 1299 |
printf("Sub-Device ioctls (%s Pad %u):\n", |
| 1300 |
(node.pads[pad].flags & MEDIA_PAD_FL_SINK) ? |
| 1301 |
"Sink" : "Source", pad); |
| 1302 |
node.has_subdev_enum_code = 0; |
| 1303 |
node.has_subdev_enum_fsize = 0; |
| 1304 |
node.has_subdev_enum_fival = 0; |
| 1305 |
for (unsigned which = V4L2_SUBDEV_FORMAT_TRY; |
| 1306 |
which <= V4L2_SUBDEV_FORMAT_ACTIVE; which++) { |
| 1307 |
struct v4l2_subdev_routing dummy_routing; |
| 1308 |
struct v4l2_subdev_route dummy_routes[1]; |
| 1309 |
|
| 1310 |
const struct v4l2_subdev_routing *routing; |
| 1311 |
const struct v4l2_subdev_route *routes; |
| 1312 |
|
| 1313 |
if (has_routes) { |
| 1314 |
routing = &sd_routing[which]; |
| 1315 |
routes = sd_routes[which]; |
| 1316 |
} else { |
| 1317 |
dummy_routing.num_routes = 1; |
| 1318 |
dummy_routing.routes = (uintptr_t)&dummy_routes; |
| 1319 |
dummy_routes[0].source_pad = pad; |
| 1320 |
dummy_routes[0].source_stream = 0; |
| 1321 |
dummy_routes[0].sink_pad = pad; |
| 1322 |
dummy_routes[0].sink_stream = 0; |
| 1323 |
dummy_routes[0].flags = V4L2_SUBDEV_ROUTE_FL_ACTIVE; |
| 1324 |
|
| 1325 |
routing = &dummy_routing; |
| 1326 |
routes = dummy_routes; |
| 1327 |
} |
| 1328 |
|
| 1329 |
for (unsigned i = 0; i < routing->num_routes; ++i) { |
| 1330 |
const struct v4l2_subdev_route *r = &routes[i]; |
| 1331 |
unsigned stream; |
| 1332 |
|
| 1333 |
if (!(r->flags & V4L2_SUBDEV_ROUTE_FL_ACTIVE)) |
| 1334 |
continue; |
| 1335 |
|
| 1336 |
if ((node.pads[pad].flags & MEDIA_PAD_FL_SINK) && |
| 1337 |
(r->sink_pad == pad)) |
| 1338 |
stream = r->sink_stream; |
| 1339 |
else if ((node.pads[pad].flags & MEDIA_PAD_FL_SOURCE) && |
| 1340 |
(r->source_pad == pad)) |
| 1341 |
stream = r->source_stream; |
| 1342 |
else |
| 1343 |
continue; |
| 1344 |
|
| 1345 |
printf("\t%s Stream %u\n",which ? "Active" : "Try", |
| 1346 |
stream); |
| 1347 |
|
| 1348 |
printf("\ttest %s VIDIOC_SUBDEV_ENUM_MBUS_CODE/FRAME_SIZE/FRAME_INTERVAL: %s\n", |
| 1349 |
which ? "Active" : "Try", |
| 1350 |
ok(testSubDevEnum(&node, which, pad, stream))); |
| 1351 |
printf("\ttest %s VIDIOC_SUBDEV_G/S_FMT: %s\n", |
| 1352 |
which ? "Active" : "Try", |
| 1353 |
ok(testSubDevFormat(&node, which, pad, stream))); |
| 1354 |
printf("\ttest %s VIDIOC_SUBDEV_G/S_SELECTION/CROP: %s\n", |
| 1355 |
which ? "Active" : "Try", |
| 1356 |
ok(testSubDevSelection(&node, which, pad, stream))); |
| 1357 |
if (which) |
| 1358 |
printf("\ttest %s VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: %s\n", |
| 1359 |
which ? "Active" : "Try", |
| 1360 |
ok(testSubDevFrameInterval(&node, which, pad, stream))); |
| 1361 |
} |
| 1362 |
} |
| 1363 |
|
| 1364 |
/* |
| 1365 |
* These tests do not make sense for subdevs with multiplexed streams, |
| 1366 |
* as the try & active cases may have different routing and thus different |
| 1367 |
* behavior. |
| 1368 |
*/ |
| 1369 |
if (!has_routes) { |
| 1370 |
if (node.has_subdev_enum_code && node.has_subdev_enum_code < 3) |
| 1371 |
fail("VIDIOC_SUBDEV_ENUM_MBUS_CODE: try/active mismatch\n"); |
| 1372 |
if (node.has_subdev_enum_fsize && node.has_subdev_enum_fsize < 3) |
| 1373 |
fail("VIDIOC_SUBDEV_ENUM_FRAME_SIZE: try/active mismatch\n"); |
| 1374 |
if (node.has_subdev_enum_fival && node.has_subdev_enum_fival < 3) |
| 1375 |
fail("VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL: try/active mismatch\n"); |
| 1376 |
if (node.has_subdev_fmt && node.has_subdev_fmt < 3) |
| 1377 |
fail("VIDIOC_SUBDEV_G/S_FMT: try/active mismatch\n"); |
| 1378 |
if (node.has_subdev_selection && node.has_subdev_selection < 3) |
| 1379 |
fail("VIDIOC_SUBDEV_G/S_SELECTION: try/active mismatch\n"); |
| 1380 |
if (node.has_subdev_selection && |
| 1381 |
node.has_subdev_selection != node.has_subdev_fmt) |
| 1382 |
fail("VIDIOC_SUBDEV_G/S_SELECTION: fmt/selection mismatch\n"); |
| 1383 |
if (node.has_ival_uses_which()) { |
| 1384 |
if (node.has_subdev_frame_interval && node.has_subdev_frame_interval < 3) |
| 1385 |
fail("VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: try/active mismatch\n"); |
| 1386 |
if (node.has_subdev_frame_interval && |
| 1387 |
node.has_subdev_frame_interval != node.has_subdev_fmt) |
| 1388 |
fail("VIDIOC_SUBDEV_G/S_FRAME_INTERVAL: fmt/frame_interval mismatch\n"); |
| 1389 |
} |
| 1390 |
} |
| 1391 |
printf("\n"); |
| 1392 |
} |
| 1393 |
} |
| 1394 |
|
| 1395 |
max_io = node.inputs > node.outputs ? node.inputs : node.outputs; |
| 1396 |
|
| 1397 |
for (unsigned io = 0; io < (max_io ? max_io : 1); io++) { |
| 1398 |
v4l2_fract min_period = { 1, 1000 }; |
| 1399 |
char suffix[100] = ""; |
| 1400 |
|
| 1401 |
node.std_controls = node.priv_controls = 0; |
| 1402 |
node.std_compound_controls = node.priv_compound_controls = 0; |
| 1403 |
node.controls.clear(); |
| 1404 |
node.frmsizes.clear(); |
| 1405 |
node.frmsizes_count.clear(); |
| 1406 |
node.has_frmintervals = false; |
| 1407 |
node.has_enc_cap_frame_interval = false; |
| 1408 |
node.valid_buftypes = 0; |
| 1409 |
node.valid_memorytype = 0; |
| 1410 |
node.buf_caps = 0; |
| 1411 |
node.cur_io_caps = 0; |
| 1412 |
for (auto &buftype_pixfmt : node.buftype_pixfmts) |
| 1413 |
buftype_pixfmt.clear(); |
| 1414 |
|
| 1415 |
if (max_io) { |
| 1416 |
sprintf(suffix, " (%s %u)", |
| 1417 |
node.can_capture ? "Input" : "Output", io); |
| 1418 |
if (node.has_inputs) { |
| 1419 |
struct v4l2_input descr; |
| 1420 |
|
| 1421 |
doioctl(&node, VIDIOC_S_INPUT, &io); |
| 1422 |
descr.index = io; |
| 1423 |
doioctl(&node, VIDIOC_ENUMINPUT, &descr); |
| 1424 |
node.cur_io_caps = descr.capabilities; |
| 1425 |
} else if (node.has_outputs) { |
| 1426 |
struct v4l2_output descr; |
| 1427 |
|
| 1428 |
doioctl(&node, VIDIOC_S_OUTPUT, &io); |
| 1429 |
descr.index = io; |
| 1430 |
doioctl(&node, VIDIOC_ENUMOUTPUT, &descr); |
| 1431 |
node.cur_io_caps = descr.capabilities; |
| 1432 |
} |
| 1433 |
} |
| 1434 |
|
| 1435 |
/* Control ioctls */ |
| 1436 |
|
| 1437 |
printf("Control ioctls%s:\n", suffix); |
| 1438 |
printf("\ttest VIDIOC_QUERY_EXT_CTRL/QUERYMENU: %s\n", ok(testQueryExtControls(&node))); |
| 1439 |
printf("\ttest VIDIOC_QUERYCTRL: %s\n", ok(testQueryControls(&node))); |
| 1440 |
printf("\ttest VIDIOC_G/S_CTRL: %s\n", ok(testSimpleControls(&node))); |
| 1441 |
printf("\ttest VIDIOC_G/S/TRY_EXT_CTRLS: %s\n", ok(testExtendedControls(&node))); |
| 1442 |
printf("\ttest VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: %s\n", ok(testEvents(&node))); |
| 1443 |
printf("\ttest VIDIOC_G/S_JPEGCOMP: %s\n", ok(testJpegComp(&node))); |
| 1444 |
printf("\tStandard Controls: %d Private Controls: %d\n", |
| 1445 |
node.std_controls - node.std_compound_controls, |
| 1446 |
node.priv_controls - node.priv_compound_controls); |
| 1447 |
if (node.std_compound_controls || node.priv_compound_controls) |
| 1448 |
printf("\tStandard Compound Controls: %d Private Compound Controls: %d\n", |
| 1449 |
node.std_compound_controls, node.priv_compound_controls); |
| 1450 |
printf("\n"); |
| 1451 |
|
| 1452 |
/* Format ioctls */ |
| 1453 |
|
| 1454 |
printf("Format ioctls%s:\n", suffix); |
| 1455 |
printf("\ttest VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: %s\n", ok(testEnumFormats(&node))); |
| 1456 |
printf("\ttest VIDIOC_G/S_PARM: %s\n", ok(testParm(&node))); |
| 1457 |
printf("\ttest VIDIOC_G_FBUF: %s\n", ok(testFBuf(&node))); |
| 1458 |
printf("\ttest VIDIOC_G_FMT: %s\n", ok(testGetFormats(&node))); |
| 1459 |
printf("\ttest VIDIOC_TRY_FMT: %s\n", ok(testTryFormats(&node))); |
| 1460 |
printf("\ttest VIDIOC_S_FMT: %s\n", ok(testSetFormats(&node))); |
| 1461 |
printf("\ttest VIDIOC_G_SLICED_VBI_CAP: %s\n", ok(testSlicedVBICap(&node))); |
| 1462 |
printf("\ttest Cropping: %s\n", ok(testCropping(&node))); |
| 1463 |
printf("\ttest Composing: %s\n", ok(testComposing(&node))); |
| 1464 |
printf("\ttest Scaling: %s\n", ok(testScaling(&node))); |
| 1465 |
printf("\n"); |
| 1466 |
|
| 1467 |
/* Codec ioctls */ |
| 1468 |
|
| 1469 |
printf("Codec ioctls%s:\n", suffix); |
| 1470 |
printf("\ttest VIDIOC_(TRY_)ENCODER_CMD: %s\n", ok(testEncoder(&node))); |
| 1471 |
printf("\ttest VIDIOC_G_ENC_INDEX: %s\n", ok(testEncIndex(&node))); |
| 1472 |
printf("\ttest VIDIOC_(TRY_)DECODER_CMD: %s\n", ok(testDecoder(&node))); |
| 1473 |
printf("\n"); |
| 1474 |
|
| 1475 |
/* Buffer ioctls */ |
| 1476 |
|
| 1477 |
printf("Buffer ioctls%s:\n", suffix); |
| 1478 |
printf("\ttest VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: %s\n", ok(testReqBufs(&node))); |
| 1479 |
printf("\ttest CREATE_BUFS maximum buffers: %s\n", ok(testCreateBufsMax(&node))); |
| 1480 |
printf("\ttest VIDIOC_REMOVE_BUFS: %s\n", ok(testRemoveBufs(&node))); |
| 1481 |
// Reopen after each streaming test to reset the streaming state |
| 1482 |
// in case of any errors in the preceeding test. |
| 1483 |
node.reopen(); |
| 1484 |
printf("\ttest VIDIOC_EXPBUF: %s\n", ok(testExpBuf(&node))); |
| 1485 |
if (node.can_capture) |
| 1486 |
node.set_interval(min_period); |
| 1487 |
printf("\ttest Requests: %s\n", ok(testRequests(&node, options[OptStreaming]))); |
| 1488 |
if (sizeof(void *) == 4) |
| 1489 |
printf("\ttest TIME32/64: %s\n", ok(testTime32_64(&node))); |
| 1490 |
// If this is a media-centric device, then only run when streaming |
| 1491 |
if (!node.is_io_mc || options[OptStreaming]) |
| 1492 |
printf("\ttest blocking wait: %s\n", ok(testBlockingWait(&node))); |
| 1493 |
|
| 1494 |
// Reopen after each streaming test to reset the streaming state |
| 1495 |
// in case of any errors in the preceeding test. |
| 1496 |
node.reopen(); |
| 1497 |
printf("\n"); |
| 1498 |
} |
| 1499 |
|
| 1500 |
cur_io = node.has_inputs ? state.input.index : state.output.index; |
| 1501 |
min_io = 0; |
| 1502 |
|
| 1503 |
if (!options[OptStreamAllIO]) { |
| 1504 |
min_io = cur_io; |
| 1505 |
max_io = min_io + 1; |
| 1506 |
} |
| 1507 |
|
| 1508 |
for (unsigned io = min_io; io < (max_io ? max_io : 1); io++) { |
| 1509 |
restoreState(); |
| 1510 |
|
| 1511 |
if (!node.is_v4l2()) |
| 1512 |
break; |
| 1513 |
|
| 1514 |
if (options[OptStreaming] || (node.is_video && options[OptStreamAllFormats]) || |
| 1515 |
(node.is_video && node.can_capture && options[OptStreamAllColorTest])) |
| 1516 |
printf("Test %s %d:\n\n", |
| 1517 |
node.can_capture ? "input" : "output", io); |
| 1518 |
|
| 1519 |
if (node.can_capture) |
| 1520 |
doioctl(&node, VIDIOC_S_INPUT, &io); |
| 1521 |
else |
| 1522 |
doioctl(&node, VIDIOC_S_OUTPUT, &io); |
| 1523 |
|
| 1524 |
if (options[OptStreaming]) { |
| 1525 |
printf("Streaming ioctls:\n"); |
| 1526 |
streamingSetup(&node); |
| 1527 |
|
| 1528 |
printf("\ttest read/write: %s\n", ok(testReadWrite(&node))); |
| 1529 |
// Reopen after each streaming test to reset the streaming state |
| 1530 |
// in case of any errors in the preceeding test. |
| 1531 |
node.reopen(); |
| 1532 |
if (!(node.codec_mask & (STATEFUL_ENCODER | STATEFUL_DECODER))) { |
| 1533 |
printf("\ttest MMAP (no poll, REQBUFS): %s\n", |
| 1534 |
ok(testMmap(&node, &node_m2m_cap, frame_count, POLL_MODE_NONE, false))); |
| 1535 |
node.reopen(); |
| 1536 |
} |
| 1537 |
printf("\ttest MMAP (select, REQBUFS): %s\n", |
| 1538 |
ok(testMmap(&node, &node_m2m_cap, frame_count, POLL_MODE_SELECT, false))); |
| 1539 |
node.reopen(); |
| 1540 |
printf("\ttest MMAP (epoll, REQBUFS): %s\n", |
| 1541 |
ok(testMmap(&node, &node_m2m_cap, frame_count, POLL_MODE_EPOLL, false))); |
| 1542 |
node.reopen(); |
| 1543 |
if (!(node.codec_mask & (STATEFUL_ENCODER | STATEFUL_DECODER))) { |
| 1544 |
printf("\ttest MMAP (no poll, CREATE_BUFS): %s\n", |
| 1545 |
ok(testMmap(&node, &node_m2m_cap, frame_count, POLL_MODE_NONE, true))); |
| 1546 |
node.reopen(); |
| 1547 |
} |
| 1548 |
printf("\ttest MMAP (select, CREATE_BUFS): %s\n", |
| 1549 |
ok(testMmap(&node, &node_m2m_cap, frame_count, POLL_MODE_SELECT, true))); |
| 1550 |
node.reopen(); |
| 1551 |
printf("\ttest MMAP (epoll, CREATE_BUFS): %s\n", |
| 1552 |
ok(testMmap(&node, &node_m2m_cap, frame_count, POLL_MODE_EPOLL, true))); |
| 1553 |
node.reopen(); |
| 1554 |
if (!(node.codec_mask & (STATEFUL_ENCODER | STATEFUL_DECODER))) { |
| 1555 |
printf("\ttest USERPTR (no poll): %s\n", |
| 1556 |
ok(testUserPtr(&node, &node_m2m_cap, frame_count, POLL_MODE_NONE))); |
| 1557 |
node.reopen(); |
| 1558 |
} |
| 1559 |
printf("\ttest USERPTR (select): %s\n", |
| 1560 |
ok(testUserPtr(&node, &node_m2m_cap, frame_count, POLL_MODE_SELECT))); |
| 1561 |
node.reopen(); |
| 1562 |
if (options[OptSetExpBufDevice] || |
| 1563 |
!(node.valid_memorytype & (1 << V4L2_MEMORY_DMABUF))) { |
| 1564 |
if (!(node.codec_mask & (STATEFUL_ENCODER | STATEFUL_DECODER))) { |
| 1565 |
printf("\ttest DMABUF (no poll): %s\n", |
| 1566 |
ok(testDmaBuf(&expbuf_node, &node, &node_m2m_cap, |
| 1567 |
frame_count, POLL_MODE_NONE))); |
| 1568 |
node.reopen(); |
| 1569 |
} |
| 1570 |
printf("\ttest DMABUF (select): %s\n", |
| 1571 |
ok(testDmaBuf(&expbuf_node, &node, &node_m2m_cap, frame_count, POLL_MODE_SELECT))); |
| 1572 |
node.reopen(); |
| 1573 |
} else if (!options[OptSetExpBufDevice]) { |
| 1574 |
printf("\ttest DMABUF: Cannot test, specify --expbuf-device\n"); |
| 1575 |
} |
| 1576 |
|
| 1577 |
printf("\n"); |
| 1578 |
} |
| 1579 |
|
| 1580 |
if (node.is_video && options[OptStreamAllFormats]) { |
| 1581 |
printf("Stream using all formats:\n"); |
| 1582 |
|
| 1583 |
if (node.is_m2m) { |
| 1584 |
if (node.codec_mask & |
| 1585 |
(JPEG_DECODER | STATEFUL_DECODER | STATELESS_DECODER)) { |
| 1586 |
printf("\tNot supported for decoder devices\n"); |
| 1587 |
} else { |
| 1588 |
streamM2MAllFormats(&node, all_fmt_frame_count); |
| 1589 |
} |
| 1590 |
} else { |
| 1591 |
streamingSetup(&node); |
| 1592 |
streamAllFormats(&node, all_fmt_frame_count); |
| 1593 |
} |
| 1594 |
} |
| 1595 |
|
| 1596 |
if (node.is_video && node.can_capture && options[OptStreamAllColorTest]) { |
| 1597 |
printf("Stream using all formats and do a color check:\n"); |
| 1598 |
|
| 1599 |
if (node.is_m2m) { |
| 1600 |
printf("\tNot supported for M2M devices\n"); |
| 1601 |
} else { |
| 1602 |
streamingSetup(&node); |
| 1603 |
testColorsAllFormats(&node, color_component, |
| 1604 |
color_skip, color_perc); |
| 1605 |
} |
| 1606 |
} |
| 1607 |
} |
| 1608 |
|
| 1609 |
/* |
| 1610 |
* TODO: VIDIOC_S_FBUF/OVERLAY |
| 1611 |
* S_SELECTION flags tests |
| 1612 |
*/ |
| 1613 |
|
| 1614 |
if (is_vivid && |
| 1615 |
node.controls.find(VIVID_CID_DISCONNECT) != node.controls.end()) { |
| 1616 |
if (node.node2) |
| 1617 |
node.node2->close(); |
| 1618 |
node.node2 = nullptr; |
| 1619 |
printf("\ttest Disconnect: %s\n\n", ok(testVividDisconnect(&node))); |
| 1620 |
} |
| 1621 |
|
| 1622 |
restoreState(); |
| 1623 |
|
| 1624 |
show_total: |
| 1625 |
/* Final test report */ |
| 1626 |
if (driver.empty()) |
| 1627 |
printf("Total for device %s%s: %d, Succeeded: %d, Failed: %d, Warnings: %d\n", |
| 1628 |
node.device, node.g_direct() ? "" : " (using libv4l2)", |
| 1629 |
tests_total, tests_ok, tests_total - tests_ok, warnings); |
| 1630 |
else |
| 1631 |
printf("Total for %s device %s%s: %d, Succeeded: %d, Failed: %d, Warnings: %d\n", |
| 1632 |
driver.c_str(), node.device, node.g_direct() ? "" : " (using libv4l2)", |
| 1633 |
tests_total, tests_ok, tests_total - tests_ok, warnings); |
| 1634 |
grand_total += tests_total; |
| 1635 |
grand_ok += tests_ok; |
| 1636 |
grand_warnings += warnings; |
| 1637 |
|
| 1638 |
if (node.is_media() && options[OptSetMediaDevice]) { |
| 1639 |
walkTopology(node, expbuf_node, |
| 1640 |
frame_count, all_fmt_frame_count); |
| 1641 |
/* Final test report */ |
| 1642 |
printf("\nGrand Total for %s device %s: %d, Succeeded: %d, Failed: %d, Warnings: %d\n", |
| 1643 |
driver.c_str(), node.device, |
| 1644 |
grand_total, grand_ok, grand_total - grand_ok, grand_warnings); |
| 1645 |
} |
| 1646 |
|
| 1647 |
node.close(); |
| 1648 |
if (node.node2) |
| 1649 |
node.node2->close(); |
| 1650 |
} |
| 1651 |
|
| 1652 |
int main(int argc, char **argv) |
| 1653 |
{ |
| 1654 |
int i; |
| 1655 |
struct node node; |
| 1656 |
media_type type = MEDIA_TYPE_UNKNOWN; |
| 1657 |
struct node expbuf_node; |
| 1658 |
std::string media_bus_info; |
| 1659 |
const char *env_media_apps_color = getenv("MEDIA_APPS_COLOR"); |
| 1660 |
|
| 1661 |
/* command args */ |
| 1662 |
int ch; |
| 1663 |
std::string device("/dev/video0"); |
| 1664 |
std::string expbuf_device; /* --expbuf-device device */ |
| 1665 |
unsigned frame_count = 60; |
| 1666 |
unsigned all_fmt_frame_count = 0; |
| 1667 |
char short_options[26 * 2 * 3 + 1]; |
| 1668 |
char *value, *subs; |
| 1669 |
int idx = 0; |
| 1670 |
|
| 1671 |
if (!env_media_apps_color || !strcmp(env_media_apps_color, "auto")) |
| 1672 |
show_colors = isatty(STDOUT_FILENO); |
| 1673 |
else if (!strcmp(env_media_apps_color, "always")) |
| 1674 |
show_colors = true; |
| 1675 |
else if (!strcmp(env_media_apps_color, "never")) |
| 1676 |
show_colors = false; |
| 1677 |
else { |
| 1678 |
fprintf(stderr, |
| 1679 |
"v4l2-compliance: invalid value for MEDIA_APPS_COLOR environment variable\n"); |
| 1680 |
} |
| 1681 |
|
| 1682 |
for (i = 0; long_options[i].name; i++) { |
| 1683 |
if (!isalpha(long_options[i].val)) |
| 1684 |
continue; |
| 1685 |
short_options[idx++] = long_options[i].val; |
| 1686 |
if (long_options[i].has_arg == required_argument) { |
| 1687 |
short_options[idx++] = ':'; |
| 1688 |
} else if (long_options[i].has_arg == optional_argument) { |
| 1689 |
short_options[idx++] = ':'; |
| 1690 |
short_options[idx++] = ':'; |
| 1691 |
} |
| 1692 |
} |
| 1693 |
while (true) { |
| 1694 |
int option_index = 0; |
| 1695 |
|
| 1696 |
short_options[idx] = 0; |
| 1697 |
ch = getopt_long(argc, argv, short_options, |
| 1698 |
long_options, &option_index); |
| 1699 |
if (ch == -1) |
| 1700 |
break; |
| 1701 |
|
| 1702 |
options[ch] = 1; |
| 1703 |
if (!option_index) { |
| 1704 |
for (i = 0; long_options[i].val; i++) { |
| 1705 |
if (long_options[i].val == ch) { |
| 1706 |
option_index = i; |
| 1707 |
break; |
| 1708 |
} |
| 1709 |
} |
| 1710 |
} |
| 1711 |
if (long_options[option_index].has_arg == optional_argument && |
| 1712 |
!optarg && argv[optind] && argv[optind][0] != '-') |
| 1713 |
optarg = argv[optind++]; |
| 1714 |
|
| 1715 |
switch (ch) { |
| 1716 |
case OptHelp: |
| 1717 |
usage(); |
| 1718 |
std::exit(EXIT_FAILURE); |
| 1719 |
case OptSetDevice: |
| 1720 |
device = make_devname(optarg, "video", media_bus_info); |
| 1721 |
break; |
| 1722 |
case OptSetVbiDevice: |
| 1723 |
device = make_devname(optarg, "vbi", media_bus_info); |
| 1724 |
break; |
| 1725 |
case OptSetRadioDevice: |
| 1726 |
device = make_devname(optarg, "radio", media_bus_info); |
| 1727 |
break; |
| 1728 |
case OptSetSWRadioDevice: |
| 1729 |
device = make_devname(optarg, "swradio", media_bus_info); |
| 1730 |
break; |
| 1731 |
case OptSetTouchDevice: |
| 1732 |
device = make_devname(optarg, "v4l-touch", media_bus_info); |
| 1733 |
break; |
| 1734 |
case OptSetSubDevDevice: |
| 1735 |
device = make_devname(optarg, "v4l-subdev", media_bus_info); |
| 1736 |
break; |
| 1737 |
case OptSetMediaDevice: |
| 1738 |
case OptSetMediaDeviceOnly: |
| 1739 |
device = make_devname(optarg, "media", optarg, true); |
| 1740 |
type = MEDIA_TYPE_MEDIA; |
| 1741 |
break; |
| 1742 |
case OptMediaBusInfo: |
| 1743 |
media_bus_info = optarg; |
| 1744 |
break; |
| 1745 |
case OptSetExpBufDevice: |
| 1746 |
expbuf_device = make_devname(optarg, "video", media_bus_info); |
| 1747 |
break; |
| 1748 |
case OptStreaming: |
| 1749 |
if (optarg) |
| 1750 |
frame_count = strtoul(optarg, nullptr, 0); |
| 1751 |
break; |
| 1752 |
case OptStreamFrom: |
| 1753 |
case OptStreamFromHdr: { |
| 1754 |
char *equal = std::strchr(optarg, '='); |
| 1755 |
bool has_hdr = ch == OptStreamFromHdr; |
| 1756 |
|
| 1757 |
if (equal == optarg) |
| 1758 |
equal = nullptr; |
| 1759 |
if (equal) { |
| 1760 |
*equal = '\0'; |
| 1761 |
stream_from_map[optarg] = equal + 1; |
| 1762 |
stream_hdr_map[optarg] = has_hdr; |
| 1763 |
} else { |
| 1764 |
stream_from_map[""] = optarg; |
| 1765 |
stream_hdr_map[""] = has_hdr; |
| 1766 |
} |
| 1767 |
break; |
| 1768 |
} |
| 1769 |
case OptStreamAllFormats: |
| 1770 |
if (optarg) |
| 1771 |
all_fmt_frame_count = strtoul(optarg, nullptr, 0); |
| 1772 |
break; |
| 1773 |
case OptStreamAllColorTest: |
| 1774 |
subs = optarg; |
| 1775 |
while (*subs != '\0') { |
| 1776 |
static constexpr const char *subopts[] = { |
| 1777 |
"color", |
| 1778 |
"skip", |
| 1779 |
"perc", |
| 1780 |
nullptr |
| 1781 |
}; |
| 1782 |
|
| 1783 |
switch (parse_subopt(&subs, subopts, &value)) { |
| 1784 |
case 0: |
| 1785 |
if (!strcmp(value, "red")) |
| 1786 |
color_component = 0; |
| 1787 |
else if (!strcmp(value, "green")) |
| 1788 |
color_component = 1; |
| 1789 |
else if (!strcmp(value, "blue")) |
| 1790 |
color_component = 2; |
| 1791 |
else { |
| 1792 |
usage(); |
| 1793 |
std::exit(EXIT_FAILURE); |
| 1794 |
} |
| 1795 |
break; |
| 1796 |
case 1: |
| 1797 |
color_skip = strtoul(value, nullptr, 0); |
| 1798 |
break; |
| 1799 |
case 2: |
| 1800 |
color_perc = strtoul(value, nullptr, 0); |
| 1801 |
if (color_perc == 0) |
| 1802 |
color_perc = 90; |
| 1803 |
if (color_perc > 100) |
| 1804 |
color_perc = 100; |
| 1805 |
break; |
| 1806 |
default: |
| 1807 |
usage(); |
| 1808 |
std::exit(EXIT_FAILURE); |
| 1809 |
} |
| 1810 |
} |
| 1811 |
break; |
| 1812 |
case OptColor: |
| 1813 |
if (!strcmp(optarg, "always")) |
| 1814 |
show_colors = true; |
| 1815 |
else if (!strcmp(optarg, "never")) |
| 1816 |
show_colors = false; |
| 1817 |
else if (!strcmp(optarg, "auto")) |
| 1818 |
show_colors = isatty(STDOUT_FILENO); |
| 1819 |
else { |
| 1820 |
usage(); |
| 1821 |
std::exit(EXIT_FAILURE); |
| 1822 |
} |
| 1823 |
break; |
| 1824 |
case OptNoWarnings: |
| 1825 |
show_warnings = false; |
| 1826 |
break; |
| 1827 |
case OptExitOnWarn: |
| 1828 |
exit_on_warn = true; |
| 1829 |
break; |
| 1830 |
case OptExitOnFail: |
| 1831 |
exit_on_fail = true; |
| 1832 |
break; |
| 1833 |
case OptVerbose: |
| 1834 |
show_info = true; |
| 1835 |
break; |
| 1836 |
case OptNoProgress: |
| 1837 |
no_progress = true; |
| 1838 |
break; |
| 1839 |
case OptVersion: |
| 1840 |
print_sha(); |
| 1841 |
std::exit(EXIT_SUCCESS); |
| 1842 |
case ':': |
| 1843 |
fprintf(stderr, "Option `%s' requires a value\n", |
| 1844 |
argv[optind]); |
| 1845 |
usage(); |
| 1846 |
std::exit(EXIT_FAILURE); |
| 1847 |
case '?': |
| 1848 |
if (argv[optind]) |
| 1849 |
fprintf(stderr, "Unknown argument `%s'\n", |
| 1850 |
argv[optind]); |
| 1851 |
usage(); |
| 1852 |
std::exit(EXIT_FAILURE); |
| 1853 |
} |
| 1854 |
} |
| 1855 |
if (optind < argc) { |
| 1856 |
fprintf(stderr, "unknown arguments: "); |
| 1857 |
while (optind < argc) |
| 1858 |
fprintf(stderr, "%s ", argv[optind++]); |
| 1859 |
fprintf(stderr, "\n"); |
| 1860 |
usage(); |
| 1861 |
std::exit(EXIT_FAILURE); |
| 1862 |
} |
| 1863 |
|
| 1864 |
print_sha(); |
| 1865 |
printf("\n"); |
| 1866 |
|
| 1867 |
bool direct = !options[OptUseWrapper]; |
| 1868 |
int fd; |
| 1869 |
|
| 1870 |
if (type == MEDIA_TYPE_UNKNOWN) |
| 1871 |
type = mi_media_detect_type(device.c_str()); |
| 1872 |
if (type == MEDIA_TYPE_CANT_STAT) { |
| 1873 |
fprintf(stderr, "Cannot open device %s, exiting.\n", |
| 1874 |
device.c_str()); |
| 1875 |
std::exit(EXIT_FAILURE); |
| 1876 |
} |
| 1877 |
if (type == MEDIA_TYPE_UNKNOWN) { |
| 1878 |
fprintf(stderr, "Unable to detect what device %s is, exiting.\n", |
| 1879 |
device.c_str()); |
| 1880 |
std::exit(EXIT_FAILURE); |
| 1881 |
} |
| 1882 |
|
| 1883 |
node.device = device.c_str(); |
| 1884 |
node.s_trace(options[OptTrace]); |
| 1885 |
switch (type) { |
| 1886 |
case MEDIA_TYPE_MEDIA: |
| 1887 |
node.s_direct(true); |
| 1888 |
fd = node.media_open(device.c_str(), false); |
| 1889 |
break; |
| 1890 |
case MEDIA_TYPE_SUBDEV: |
| 1891 |
node.s_direct(true); |
| 1892 |
fd = node.subdev_open(device.c_str(), false); |
| 1893 |
break; |
| 1894 |
default: |
| 1895 |
node.s_direct(direct); |
| 1896 |
fd = node.open(device.c_str(), false); |
| 1897 |
break; |
| 1898 |
} |
| 1899 |
if (fd < 0) { |
| 1900 |
fprintf(stderr, "Failed to open %s: %s\n", device.c_str(), |
| 1901 |
strerror(errno)); |
| 1902 |
std::exit(EXIT_FAILURE); |
| 1903 |
} |
| 1904 |
|
| 1905 |
if (!expbuf_device.empty()) { |
| 1906 |
expbuf_node.s_trace(options[OptTrace]); |
| 1907 |
expbuf_node.s_direct(true); |
| 1908 |
fd = expbuf_node.open(expbuf_device.c_str(), false); |
| 1909 |
if (fd < 0) { |
| 1910 |
fprintf(stderr, "Failed to open %s: %s\n", expbuf_device.c_str(), |
| 1911 |
strerror(errno)); |
| 1912 |
std::exit(EXIT_FAILURE); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
|
| 1916 |
testNode(node, node, expbuf_node, type, frame_count, all_fmt_frame_count); |
| 1917 |
|
| 1918 |
if (!expbuf_device.empty()) |
| 1919 |
expbuf_node.close(); |
| 1920 |
if (media_fd >= 0) |
| 1921 |
close(media_fd); |
| 1922 |
|
| 1923 |
std::exit(app_result); |
| 1924 |
} |