| 1 |
#include <cctype> |
| 2 |
|
| 3 |
#include "v4l2-ctl.h" |
| 4 |
|
| 5 |
static v4l2_std_id standard; /* get_std/set_std */ |
| 6 |
static struct v4l2_dv_timings dv_timings; /* set_dv_bt_timings/get_dv_timings/query_dv_timings */ |
| 7 |
static bool query_and_set_dv_timings = false; |
| 8 |
static bool cleared_dv_timings = false; |
| 9 |
static int enum_and_set_dv_timings = -1; |
| 10 |
static unsigned set_dv_timing_opts; |
| 11 |
static __u32 list_dv_timings_pad; |
| 12 |
static __u32 dv_timings_cap_pad; |
| 13 |
|
| 14 |
void stds_usage() |
| 15 |
{ |
| 16 |
printf("\nStandards/Timings options:\n" |
| 17 |
" --list-standards display supported video standards [VIDIOC_ENUMSTD]\n" |
| 18 |
" -S, --get-standard\n" |
| 19 |
" query the video standard [VIDIOC_G_STD]\n" |
| 20 |
" -s, --set-standard <num>\n" |
| 21 |
" set the video standard to <num> [VIDIOC_S_STD]\n" |
| 22 |
" <num> a numerical v4l2_std value, or one of:\n" |
| 23 |
" pal or pal-X (X = B/G/H/N/Nc/I/D/K/M/60) (V4L2_STD_PAL)\n" |
| 24 |
" ntsc or ntsc-X (X = M/J/K) (V4L2_STD_NTSC)\n" |
| 25 |
" secam or secam-X (X = B/G/H/D/K/L/Lc) (V4L2_STD_SECAM)\n" |
| 26 |
" --get-detected-standard\n" |
| 27 |
" display detected input video standard [VIDIOC_QUERYSTD]\n" |
| 28 |
" --list-dv-timings [<pad>]\n" |
| 29 |
" list supp. standard dv timings [VIDIOC_ENUM_DV_TIMINGS]\n" |
| 30 |
" for subdevs the pad can be specified (default is 0)\n" |
| 31 |
" --set-dv-bt-timings\n" |
| 32 |
" query: use the output of VIDIOC_QUERY_DV_TIMINGS\n" |
| 33 |
" index=<index>: use the index as provided by --list-dv-timings\n" |
| 34 |
" or specify timings using cvt/gtf options as follows:\n" |
| 35 |
" cvt/gtf,width=<width>,height=<height>,fps=<frames per sec>\n" |
| 36 |
" interlaced=<0/1>,reduced-blanking=<0/1/2>,reduced-fps=<0/1>\n" |
| 37 |
" The value of reduced-blanking, if greater than 0, indicates\n" |
| 38 |
" that reduced blanking is to be used and the value indicate the\n" |
| 39 |
" version. For gtf, there is no version 2 for reduced blanking, and\n" |
| 40 |
" the value 1 or 2 will give same results.\n" |
| 41 |
" reduced-fps = 1, slows down pixel clock by factor of 1000 / 1001, allowing\n" |
| 42 |
" to support NTSC frame rates like 29.97 or 59.94.\n" |
| 43 |
" Reduced fps flag takes effect only with reduced blanking version 2 and,\n" |
| 44 |
" when refresh rate is an integer multiple of 6, say, fps = 24,30,60 etc.\n" |
| 45 |
" or update all or part of the current timings fields:\n" |
| 46 |
" width=<width>,height=<height>,interlaced=<0/1>,\n" |
| 47 |
" polarities=<polarities mask>,pixelclock=<pixelclock Hz>,\n" |
| 48 |
" hfp=<horizontal front porch>,hs=<horizontal sync>,\n" |
| 49 |
" hbp=<horizontal back porch>,vfp=<vertical front porch>,\n" |
| 50 |
" vs=<vertical sync>,vbp=<vertical back porch>,\n" |
| 51 |
" il_vfp=<vertical front porch for bottom field>,\n" |
| 52 |
" il_vs=<vertical sync for bottom field>,\n" |
| 53 |
" il_vbp=<vertical back porch for bottom field>.\n" |
| 54 |
" clear: start with zeroed timings instead of the current timings.\n" |
| 55 |
" set the digital video timings according to the BT 656/1120\n" |
| 56 |
" standard [VIDIOC_S_DV_TIMINGS]\n" |
| 57 |
" --get-dv-timings get the digital video timings in use [VIDIOC_G_DV_TIMINGS]\n" |
| 58 |
" --query-dv-timings query the detected dv timings [VIDIOC_QUERY_DV_TIMINGS]\n" |
| 59 |
" --get-dv-timings-cap [<pad>]\n" |
| 60 |
" get the dv timings capabilities [VIDIOC_DV_TIMINGS_CAP]\n" |
| 61 |
" for subdevs the pad can be specified (default is 0)\n" |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
static v4l2_std_id parse_pal(const char *pal) |
| 66 |
{ |
| 67 |
if (pal[0] == '-') { |
| 68 |
switch (tolower(pal[1])) { |
| 69 |
case '6': |
| 70 |
return V4L2_STD_PAL_60; |
| 71 |
case 'b': |
| 72 |
case 'g': |
| 73 |
return V4L2_STD_PAL_BG; |
| 74 |
case 'h': |
| 75 |
return V4L2_STD_PAL_H; |
| 76 |
case 'n': |
| 77 |
if (tolower(pal[2]) == 'c') |
| 78 |
return V4L2_STD_PAL_Nc; |
| 79 |
return V4L2_STD_PAL_N; |
| 80 |
case 'i': |
| 81 |
return V4L2_STD_PAL_I; |
| 82 |
case 'd': |
| 83 |
case 'k': |
| 84 |
return V4L2_STD_PAL_DK; |
| 85 |
case 'm': |
| 86 |
return V4L2_STD_PAL_M; |
| 87 |
} |
| 88 |
} |
| 89 |
fprintf(stderr, "pal specifier not recognised\n"); |
| 90 |
stds_usage(); |
| 91 |
std::exit(EXIT_FAILURE); |
| 92 |
} |
| 93 |
|
| 94 |
static v4l2_std_id parse_secam(const char *secam) |
| 95 |
{ |
| 96 |
if (secam[0] == '-') { |
| 97 |
switch (tolower(secam[1])) { |
| 98 |
case 'b': |
| 99 |
case 'g': |
| 100 |
case 'h': |
| 101 |
return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; |
| 102 |
case 'd': |
| 103 |
case 'k': |
| 104 |
return V4L2_STD_SECAM_DK; |
| 105 |
case 'l': |
| 106 |
if (tolower(secam[2]) == 'c') |
| 107 |
return V4L2_STD_SECAM_LC; |
| 108 |
return V4L2_STD_SECAM_L; |
| 109 |
} |
| 110 |
} |
| 111 |
fprintf(stderr, "secam specifier not recognised\n"); |
| 112 |
stds_usage(); |
| 113 |
std::exit(EXIT_FAILURE); |
| 114 |
} |
| 115 |
|
| 116 |
static v4l2_std_id parse_ntsc(const char *ntsc) |
| 117 |
{ |
| 118 |
if (ntsc[0] == '-') { |
| 119 |
switch (tolower(ntsc[1])) { |
| 120 |
case 'm': |
| 121 |
return V4L2_STD_NTSC_M; |
| 122 |
case 'j': |
| 123 |
return V4L2_STD_NTSC_M_JP; |
| 124 |
case 'k': |
| 125 |
return V4L2_STD_NTSC_M_KR; |
| 126 |
} |
| 127 |
} |
| 128 |
fprintf(stderr, "ntsc specifier not recognised\n"); |
| 129 |
stds_usage(); |
| 130 |
std::exit(EXIT_FAILURE); |
| 131 |
} |
| 132 |
|
| 133 |
enum timing_opts { |
| 134 |
WIDTH = 0, |
| 135 |
HEIGHT, |
| 136 |
INTERLACED, |
| 137 |
POLARITIES, |
| 138 |
PIXEL_CLOCK, |
| 139 |
HORZ_FRONT_PORCH, |
| 140 |
HORZ_SYNC, |
| 141 |
HORZ_BACK_PORCH, |
| 142 |
VERT_FRONT_PORCH, |
| 143 |
VERT_SYNC, |
| 144 |
VERT_BACK_PORCH, |
| 145 |
IL_VERT_FRONT_PORCH, |
| 146 |
IL_VERT_SYNC, |
| 147 |
IL_VERT_BACK_PORCH, |
| 148 |
INDEX, |
| 149 |
CVT, |
| 150 |
GTF, |
| 151 |
FPS, |
| 152 |
REDUCED_BLANK, |
| 153 |
REDUCED_FPS, |
| 154 |
CLEAR, |
| 155 |
MAX_TIMINGS_OPTIONS |
| 156 |
}; |
| 157 |
|
| 158 |
static int parse_timing_subopt(char **subopt_str, int *value) |
| 159 |
{ |
| 160 |
int opt; |
| 161 |
char *opt_str; |
| 162 |
|
| 163 |
static constexpr const char *subopt_list[] = { |
| 164 |
"width", |
| 165 |
"height", |
| 166 |
"interlaced", |
| 167 |
"polarities", |
| 168 |
"pixelclock", |
| 169 |
"hfp", |
| 170 |
"hs", |
| 171 |
"hbp", |
| 172 |
"vfp", |
| 173 |
"vs", |
| 174 |
"vbp", |
| 175 |
"il_vfp", |
| 176 |
"il_vs", |
| 177 |
"il_vbp", |
| 178 |
"index", |
| 179 |
"cvt", |
| 180 |
"gtf", |
| 181 |
"fps", |
| 182 |
"reduced-blanking", |
| 183 |
"reduced-fps", |
| 184 |
"clear", |
| 185 |
nullptr |
| 186 |
}; |
| 187 |
|
| 188 |
opt = v4l_getsubopt(subopt_str, (char* const*) subopt_list, &opt_str); |
| 189 |
|
| 190 |
if (opt == -1) { |
| 191 |
fprintf(stderr, "Invalid suboptions specified\n"); |
| 192 |
stds_usage(); |
| 193 |
std::exit(EXIT_FAILURE); |
| 194 |
} |
| 195 |
if (opt_str == nullptr && opt != CVT && opt != GTF && opt != CLEAR) { |
| 196 |
fprintf(stderr, "No value given to suboption <%s>\n", |
| 197 |
subopt_list[opt]); |
| 198 |
stds_usage(); |
| 199 |
std::exit(EXIT_FAILURE); |
| 200 |
} |
| 201 |
|
| 202 |
if (opt_str) |
| 203 |
*value = strtol(opt_str, nullptr, 0); |
| 204 |
return opt; |
| 205 |
} |
| 206 |
|
| 207 |
static void get_cvt_gtf_timings(char *subopt, int standard, |
| 208 |
struct v4l2_bt_timings *bt) |
| 209 |
{ |
| 210 |
int width = 0; |
| 211 |
int height = 0; |
| 212 |
int fps = 0; |
| 213 |
int r_blank = 0; |
| 214 |
bool interlaced = false; |
| 215 |
bool reduced_fps = false; |
| 216 |
bool timings_valid = false; |
| 217 |
|
| 218 |
char *subopt_str = subopt; |
| 219 |
while (*subopt_str != '\0') { |
| 220 |
int opt; |
| 221 |
int opt_val; |
| 222 |
|
| 223 |
opt = parse_timing_subopt(&subopt_str, &opt_val); |
| 224 |
|
| 225 |
switch (opt) { |
| 226 |
case WIDTH: |
| 227 |
width = opt_val; |
| 228 |
break; |
| 229 |
case HEIGHT: |
| 230 |
height = opt_val; |
| 231 |
break; |
| 232 |
case FPS: |
| 233 |
fps = opt_val; |
| 234 |
break; |
| 235 |
case REDUCED_BLANK: |
| 236 |
r_blank = opt_val; |
| 237 |
break; |
| 238 |
case INTERLACED: |
| 239 |
interlaced = opt_val; |
| 240 |
break; |
| 241 |
case REDUCED_FPS: |
| 242 |
reduced_fps = opt_val; |
| 243 |
break; |
| 244 |
default: |
| 245 |
break; |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
if (standard == V4L2_DV_BT_STD_CVT) |
| 250 |
timings_valid = calc_cvt_modeline(width, height, fps, r_blank, |
| 251 |
interlaced, reduced_fps, bt); |
| 252 |
else |
| 253 |
timings_valid = calc_gtf_modeline(width, height, fps, r_blank, |
| 254 |
interlaced, bt); |
| 255 |
|
| 256 |
if (!timings_valid) { |
| 257 |
stds_usage(); |
| 258 |
std::exit(EXIT_FAILURE); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
static void parse_dv_bt_timings(char *optarg, struct v4l2_dv_timings *dv_timings) |
| 263 |
{ |
| 264 |
char *subs = optarg; |
| 265 |
struct v4l2_bt_timings *bt = &dv_timings->bt; |
| 266 |
bool parse_cvt_gtf = false; |
| 267 |
|
| 268 |
dv_timings->type = V4L2_DV_BT_656_1120; |
| 269 |
|
| 270 |
if (!strcmp(subs, "query")) { |
| 271 |
query_and_set_dv_timings = true; |
| 272 |
return; |
| 273 |
} |
| 274 |
|
| 275 |
while (*subs != '\0' && !parse_cvt_gtf) { |
| 276 |
int opt; |
| 277 |
int opt_val; |
| 278 |
|
| 279 |
opt = parse_timing_subopt(&subs, &opt_val); |
| 280 |
|
| 281 |
switch (opt) { |
| 282 |
case WIDTH: |
| 283 |
bt->width = opt_val; |
| 284 |
break; |
| 285 |
case HEIGHT: |
| 286 |
bt->height = opt_val; |
| 287 |
break; |
| 288 |
case INTERLACED: |
| 289 |
bt->interlaced = opt_val; |
| 290 |
break; |
| 291 |
case POLARITIES: |
| 292 |
bt->polarities = opt_val; |
| 293 |
break; |
| 294 |
case PIXEL_CLOCK: |
| 295 |
bt->pixelclock = opt_val; |
| 296 |
break; |
| 297 |
case HORZ_FRONT_PORCH: |
| 298 |
bt->hfrontporch = opt_val; |
| 299 |
break; |
| 300 |
case HORZ_SYNC: |
| 301 |
bt->hsync = opt_val; |
| 302 |
break; |
| 303 |
case HORZ_BACK_PORCH: |
| 304 |
bt->hbackporch = opt_val; |
| 305 |
break; |
| 306 |
case VERT_FRONT_PORCH: |
| 307 |
bt->vfrontporch = opt_val; |
| 308 |
break; |
| 309 |
case VERT_SYNC: |
| 310 |
bt->vsync = opt_val; |
| 311 |
break; |
| 312 |
case VERT_BACK_PORCH: |
| 313 |
bt->vbackporch = opt_val; |
| 314 |
break; |
| 315 |
case IL_VERT_FRONT_PORCH: |
| 316 |
bt->il_vfrontporch = opt_val; |
| 317 |
break; |
| 318 |
case IL_VERT_SYNC: |
| 319 |
bt->il_vsync = opt_val; |
| 320 |
break; |
| 321 |
case IL_VERT_BACK_PORCH: |
| 322 |
bt->il_vbackporch = opt_val; |
| 323 |
break; |
| 324 |
case INDEX: |
| 325 |
enum_and_set_dv_timings = opt_val; |
| 326 |
break; |
| 327 |
case CVT: |
| 328 |
parse_cvt_gtf = true; |
| 329 |
cleared_dv_timings = true; |
| 330 |
get_cvt_gtf_timings(subs, V4L2_DV_BT_STD_CVT, bt); |
| 331 |
break; |
| 332 |
case GTF: |
| 333 |
parse_cvt_gtf = true; |
| 334 |
cleared_dv_timings = true; |
| 335 |
get_cvt_gtf_timings(subs, V4L2_DV_BT_STD_GTF, bt); |
| 336 |
break; |
| 337 |
case REDUCED_FPS: |
| 338 |
bt->flags |= opt_val ? V4L2_DV_FL_REDUCED_FPS : 0; |
| 339 |
break; |
| 340 |
case CLEAR: |
| 341 |
cleared_dv_timings = true; |
| 342 |
break; |
| 343 |
default: |
| 344 |
stds_usage(); |
| 345 |
std::exit(EXIT_FAILURE); |
| 346 |
} |
| 347 |
set_dv_timing_opts |= 1 << opt; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
static void print_dv_timings(const struct v4l2_dv_timings *t) |
| 352 |
{ |
| 353 |
const struct v4l2_bt_timings *bt; |
| 354 |
double tot_width, tot_height; |
| 355 |
|
| 356 |
switch (t->type) { |
| 357 |
case V4L2_DV_BT_656_1120: |
| 358 |
bt = &t->bt; |
| 359 |
|
| 360 |
tot_height = bt->height + |
| 361 |
bt->vfrontporch + bt->vsync + bt->vbackporch + |
| 362 |
bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch; |
| 363 |
tot_width = bt->width + |
| 364 |
bt->hfrontporch + bt->hsync + bt->hbackporch; |
| 365 |
if (options[OptConcise]) { |
| 366 |
printf("\t%ux%u%c%.2f %s\n", bt->width, bt->height, |
| 367 |
bt->interlaced ? 'i' : 'p', |
| 368 |
static_cast<double>(bt->pixelclock) / |
| 369 |
(tot_width * (tot_height / (bt->interlaced ? 2 : 1))), |
| 370 |
dvflags2s(bt->vsync, bt->flags).c_str()); |
| 371 |
break; |
| 372 |
} |
| 373 |
printf("\tActive width: %d\n", bt->width); |
| 374 |
printf("\tActive height: %d\n", bt->height); |
| 375 |
printf("\tTotal width: %d\n",bt->width + |
| 376 |
bt->hfrontporch + bt->hsync + bt->hbackporch); |
| 377 |
printf("\tTotal height: %d\n", bt->height + |
| 378 |
bt->vfrontporch + bt->vsync + bt->vbackporch + |
| 379 |
bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch); |
| 380 |
|
| 381 |
printf("\tFrame format: %s\n", bt->interlaced ? "interlaced" : "progressive"); |
| 382 |
printf("\tPolarities: %cvsync %chsync\n", |
| 383 |
(bt->polarities & V4L2_DV_VSYNC_POS_POL) ? '+' : '-', |
| 384 |
(bt->polarities & V4L2_DV_HSYNC_POS_POL) ? '+' : '-'); |
| 385 |
printf("\tPixelclock: %lld Hz", bt->pixelclock); |
| 386 |
if (bt->width && bt->height) { |
| 387 |
if (bt->interlaced) |
| 388 |
printf(" (%.2f fields per second)", static_cast<double>(bt->pixelclock) / |
| 389 |
(tot_width * (tot_height / 2))); |
| 390 |
else |
| 391 |
printf(" (%.2f frames per second)", static_cast<double>(bt->pixelclock) / |
| 392 |
(tot_width * tot_height)); |
| 393 |
} |
| 394 |
printf("\n"); |
| 395 |
printf("\tHorizontal frontporch: %d\n", bt->hfrontporch); |
| 396 |
printf("\tHorizontal sync: %d\n", bt->hsync); |
| 397 |
printf("\tHorizontal backporch: %d\n", bt->hbackporch); |
| 398 |
if (bt->interlaced) |
| 399 |
printf("\tField 1:\n"); |
| 400 |
printf("\tVertical frontporch: %d\n", bt->vfrontporch); |
| 401 |
printf("\tVertical sync: %d\n", bt->vsync); |
| 402 |
printf("\tVertical backporch: %d\n", bt->vbackporch); |
| 403 |
if (bt->interlaced) { |
| 404 |
printf("\tField 2:\n"); |
| 405 |
printf("\tVertical frontporch: %d\n", bt->il_vfrontporch); |
| 406 |
printf("\tVertical sync: %d\n", bt->il_vsync); |
| 407 |
printf("\tVertical backporch: %d\n", bt->il_vbackporch); |
| 408 |
} |
| 409 |
printf("\tStandards: %s\n", dv_standards2s(bt->standards).c_str()); |
| 410 |
if (bt->flags & V4L2_DV_FL_HAS_PICTURE_ASPECT) |
| 411 |
printf("\tPicture aspect: %u:%u\n", |
| 412 |
bt->picture_aspect.numerator, |
| 413 |
bt->picture_aspect.denominator); |
| 414 |
if (bt->flags & V4L2_DV_FL_HAS_CEA861_VIC) |
| 415 |
printf("\tCTA-861 VIC: %u\n", bt->cea861_vic); |
| 416 |
if (bt->flags & V4L2_DV_FL_HAS_HDMI_VIC) |
| 417 |
printf("\tHDMI VIC: %u\n", bt->hdmi_vic); |
| 418 |
printf("\tFlags: %s\n", dvflags2s(bt->vsync, bt->flags).c_str()); |
| 419 |
break; |
| 420 |
default: |
| 421 |
printf("Timing type not defined\n"); |
| 422 |
break; |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
void stds_cmd(int ch, char *optarg) |
| 427 |
{ |
| 428 |
switch (ch) { |
| 429 |
case OptSetStandard: |
| 430 |
if (!strncasecmp(optarg, "pal", 3)) { |
| 431 |
if (optarg[3]) |
| 432 |
standard = parse_pal(optarg + 3); |
| 433 |
else |
| 434 |
standard = V4L2_STD_PAL; |
| 435 |
} |
| 436 |
else if (!strncasecmp(optarg, "ntsc", 4)) { |
| 437 |
if (optarg[4]) |
| 438 |
standard = parse_ntsc(optarg + 4); |
| 439 |
else |
| 440 |
standard = V4L2_STD_NTSC; |
| 441 |
} |
| 442 |
else if (!strncasecmp(optarg, "secam", 5)) { |
| 443 |
if (optarg[5]) |
| 444 |
standard = parse_secam(optarg + 5); |
| 445 |
else |
| 446 |
standard = V4L2_STD_SECAM; |
| 447 |
} |
| 448 |
else if (isdigit(optarg[0])) { |
| 449 |
standard = strtoul(optarg, nullptr, 0) | (1ULL << 63); |
| 450 |
} else { |
| 451 |
fprintf(stderr, "Unknown standard '%s'\n", optarg); |
| 452 |
stds_usage(); |
| 453 |
std::exit(EXIT_FAILURE); |
| 454 |
} |
| 455 |
break; |
| 456 |
case OptSetDvBtTimings: |
| 457 |
parse_dv_bt_timings(optarg, &dv_timings); |
| 458 |
break; |
| 459 |
case OptListDvTimings: |
| 460 |
if (optarg) |
| 461 |
list_dv_timings_pad = strtoul(optarg, nullptr, 0); |
| 462 |
break; |
| 463 |
case OptGetDvTimingsCap: |
| 464 |
if (optarg) |
| 465 |
dv_timings_cap_pad = strtoul(optarg, nullptr, 0); |
| 466 |
break; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
void stds_set(cv4l_fd &_fd) |
| 471 |
{ |
| 472 |
int fd = _fd.g_fd(); |
| 473 |
|
| 474 |
if (options[OptSetStandard]) { |
| 475 |
if (standard & (1ULL << 63)) { |
| 476 |
struct v4l2_standard vs; |
| 477 |
|
| 478 |
vs.index = standard & 0xffff; |
| 479 |
if (test_ioctl(fd, VIDIOC_ENUMSTD, &vs) >= 0) { |
| 480 |
standard = vs.id; |
| 481 |
} |
| 482 |
} |
| 483 |
if (doioctl(fd, VIDIOC_S_STD, &standard) == 0) |
| 484 |
printf("Standard set to %08llx\n", static_cast<unsigned long long>(standard)); |
| 485 |
} |
| 486 |
|
| 487 |
if (options[OptSetDvBtTimings]) { |
| 488 |
struct v4l2_enum_dv_timings et = {}; |
| 489 |
struct v4l2_dv_timings new_dv_timings = {}; |
| 490 |
|
| 491 |
if (query_and_set_dv_timings) |
| 492 |
doioctl(fd, VIDIOC_QUERY_DV_TIMINGS, &new_dv_timings); |
| 493 |
else if (enum_and_set_dv_timings >= 0) { |
| 494 |
__u32 reduced_fps = dv_timings.bt.flags & V4L2_DV_FL_REDUCED_FPS; |
| 495 |
|
| 496 |
et.index = enum_and_set_dv_timings; |
| 497 |
doioctl(fd, VIDIOC_ENUM_DV_TIMINGS, &et); |
| 498 |
et.timings.bt.flags |= reduced_fps; |
| 499 |
new_dv_timings = et.timings; |
| 500 |
} else if (cleared_dv_timings) { |
| 501 |
new_dv_timings = dv_timings; |
| 502 |
} else { |
| 503 |
struct v4l2_bt_timings *bt = &new_dv_timings.bt; |
| 504 |
struct v4l2_bt_timings *update_bt = &dv_timings.bt; |
| 505 |
|
| 506 |
doioctl(fd, VIDIOC_G_DV_TIMINGS, &new_dv_timings); |
| 507 |
for (unsigned i = 0; i < MAX_TIMINGS_OPTIONS; i++) { |
| 508 |
if (!(set_dv_timing_opts & (1 << i))) |
| 509 |
continue; |
| 510 |
switch (i) { |
| 511 |
case WIDTH: |
| 512 |
bt->width = update_bt->width; |
| 513 |
break; |
| 514 |
case HEIGHT: |
| 515 |
bt->height = update_bt->height; |
| 516 |
break; |
| 517 |
case INTERLACED: |
| 518 |
bt->interlaced = update_bt->interlaced; |
| 519 |
break; |
| 520 |
case POLARITIES: |
| 521 |
bt->polarities = update_bt->polarities; |
| 522 |
break; |
| 523 |
case PIXEL_CLOCK: |
| 524 |
bt->pixelclock = update_bt->pixelclock; |
| 525 |
break; |
| 526 |
case HORZ_FRONT_PORCH: |
| 527 |
bt->hfrontporch = update_bt->hfrontporch; |
| 528 |
break; |
| 529 |
case HORZ_SYNC: |
| 530 |
bt->hsync = update_bt->hsync; |
| 531 |
break; |
| 532 |
case HORZ_BACK_PORCH: |
| 533 |
bt->hbackporch = update_bt->hbackporch; |
| 534 |
break; |
| 535 |
case VERT_FRONT_PORCH: |
| 536 |
bt->vfrontporch = update_bt->vfrontporch; |
| 537 |
break; |
| 538 |
case VERT_SYNC: |
| 539 |
bt->vsync = update_bt->vsync; |
| 540 |
break; |
| 541 |
case VERT_BACK_PORCH: |
| 542 |
bt->vbackporch = update_bt->vbackporch; |
| 543 |
break; |
| 544 |
case IL_VERT_FRONT_PORCH: |
| 545 |
bt->il_vfrontporch = update_bt->il_vfrontporch; |
| 546 |
break; |
| 547 |
case IL_VERT_SYNC: |
| 548 |
bt->il_vsync = update_bt->il_vsync; |
| 549 |
break; |
| 550 |
case IL_VERT_BACK_PORCH: |
| 551 |
bt->il_vbackporch = update_bt->il_vbackporch; |
| 552 |
break; |
| 553 |
case REDUCED_FPS: |
| 554 |
bt->flags &= ~V4L2_DV_FL_REDUCED_FPS; |
| 555 |
bt->flags |= update_bt->flags & V4L2_DV_FL_REDUCED_FPS; |
| 556 |
break; |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
if (verbose) |
| 561 |
print_dv_timings(&new_dv_timings); |
| 562 |
if (doioctl(fd, VIDIOC_S_DV_TIMINGS, &new_dv_timings) >= 0) { |
| 563 |
printf("BT timings set\n"); |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
void stds_get(cv4l_fd &_fd) |
| 569 |
{ |
| 570 |
int fd = _fd.g_fd(); |
| 571 |
|
| 572 |
if (options[OptGetStandard]) { |
| 573 |
if (doioctl(fd, VIDIOC_G_STD, &standard) == 0) { |
| 574 |
printf("Video Standard = 0x%08llx\n", static_cast<unsigned long long>(standard)); |
| 575 |
printf("\t%s\n", std2s(standard, "\n\t").c_str()); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
if (options[OptGetDvTimings]) { |
| 580 |
if (doioctl(fd, VIDIOC_G_DV_TIMINGS, &dv_timings) >= 0) { |
| 581 |
printf("DV timings:\n"); |
| 582 |
print_dv_timings(&dv_timings); |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
if (options[OptGetDvTimingsCap]) { |
| 587 |
struct v4l2_dv_timings_cap dv_timings_cap = {}; |
| 588 |
|
| 589 |
dv_timings_cap.pad = dv_timings_cap_pad; |
| 590 |
if (doioctl(fd, VIDIOC_DV_TIMINGS_CAP, &dv_timings_cap) >= 0) { |
| 591 |
struct v4l2_bt_timings_cap *bt = &dv_timings_cap.bt; |
| 592 |
|
| 593 |
printf("DV timings capabilities:\n"); |
| 594 |
if (dv_timings_cap.type != V4L2_DV_BT_656_1120) |
| 595 |
printf("\tUnknown type\n"); |
| 596 |
else { |
| 597 |
printf("\tMinimum Width: %u\n", bt->min_width); |
| 598 |
printf("\tMaximum Width: %u\n", bt->max_width); |
| 599 |
printf("\tMinimum Height: %u\n", bt->min_height); |
| 600 |
printf("\tMaximum Height: %u\n", bt->max_height); |
| 601 |
printf("\tMinimum PClock: %llu\n", bt->min_pixelclock); |
| 602 |
printf("\tMaximum PClock: %llu\n", bt->max_pixelclock); |
| 603 |
printf("\tStandards: %s\n", |
| 604 |
dv_standards2s(bt->standards).c_str()); |
| 605 |
printf("\tCapabilities: %s\n", |
| 606 |
dv_caps2s(bt->capabilities).c_str()); |
| 607 |
} |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
if (options[OptQueryStandard]) { |
| 612 |
if (doioctl(fd, VIDIOC_QUERYSTD, &standard) == 0) { |
| 613 |
printf("Video Standard = 0x%08llx\n", static_cast<unsigned long long>(standard)); |
| 614 |
printf("\t%s\n", std2s(standard, "\n\t").c_str()); |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
if (options[OptQueryDvTimings]) { |
| 619 |
doioctl(fd, VIDIOC_QUERY_DV_TIMINGS, &dv_timings); |
| 620 |
print_dv_timings(&dv_timings); |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
void stds_list(cv4l_fd &_fd) |
| 625 |
{ |
| 626 |
int fd = _fd.g_fd(); |
| 627 |
|
| 628 |
if (options[OptListStandards]) { |
| 629 |
struct v4l2_standard vs; |
| 630 |
|
| 631 |
printf("ioctl: VIDIOC_ENUMSTD\n"); |
| 632 |
vs.index = 0; |
| 633 |
while (test_ioctl(fd, VIDIOC_ENUMSTD, &vs) >= 0) { |
| 634 |
if (options[OptConcise]) { |
| 635 |
printf("\t%2d: 0x%016llX %s\n", vs.index, |
| 636 |
static_cast<unsigned long long>(vs.id), vs.name); |
| 637 |
} else { |
| 638 |
if (vs.index) |
| 639 |
printf("\n"); |
| 640 |
printf("\tIndex : %d\n", vs.index); |
| 641 |
printf("\tID : 0x%016llX\n", static_cast<unsigned long long>(vs.id)); |
| 642 |
printf("\tName : %s\n", vs.name); |
| 643 |
printf("\tFrame period: %d/%d\n", |
| 644 |
vs.frameperiod.numerator, |
| 645 |
vs.frameperiod.denominator); |
| 646 |
printf("\tFrame lines : %d\n", vs.framelines); |
| 647 |
} |
| 648 |
vs.index++; |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
if (options[OptListDvTimings]) { |
| 653 |
struct v4l2_enum_dv_timings dv_enum_timings = {}; |
| 654 |
|
| 655 |
printf("ioctl: VIDIOC_ENUM_DV_TIMINGS\n"); |
| 656 |
dv_enum_timings.pad = list_dv_timings_pad; |
| 657 |
while (test_ioctl(fd, VIDIOC_ENUM_DV_TIMINGS, &dv_enum_timings) >= 0) { |
| 658 |
if (options[OptConcise]) { |
| 659 |
printf("\t%d:", dv_enum_timings.index); |
| 660 |
} else { |
| 661 |
if (dv_enum_timings.index) |
| 662 |
printf("\n"); |
| 663 |
printf("\tIndex: %d\n", dv_enum_timings.index); |
| 664 |
} |
| 665 |
print_dv_timings(&dv_enum_timings.timings); |
| 666 |
dv_enum_timings.index++; |
| 667 |
} |
| 668 |
} |
| 669 |
} |