| 1 |
#ifndef _V4L2_CTL_H |
| 2 |
#define _V4L2_CTL_H |
| 3 |
|
| 4 |
#include <cstdint> |
| 5 |
#include <linux/videodev2.h> |
| 6 |
#include <linux/v4l2-subdev.h> |
| 7 |
#include <v4l-getsubopt.h> |
| 8 |
|
| 9 |
#include <v4l2-info.h> |
| 10 |
|
| 11 |
#ifndef NO_LIBV4L2 |
| 12 |
#include <libv4l2.h> |
| 13 |
#else |
| 14 |
#define v4l2_open(file, oflag, ...) (-1) |
| 15 |
#define v4l2_close(fd) (-1) |
| 16 |
#define v4l2_ioctl(fd, request, ...) (-1) |
| 17 |
#define v4l2_mmap(start, length, prot, flags, fd, offset) (MAP_FAILED) |
| 18 |
#define v4l2_munmap(_start, length) (-1) |
| 19 |
#endif |
| 20 |
|
| 21 |
#include "cv4l-helpers.h" |
| 22 |
|
| 23 |
class cv4l_disable_trace { |
| 24 |
public: |
| 25 |
cv4l_disable_trace(cv4l_fd &fd) : _fd(fd) |
| 26 |
{ |
| 27 |
old_trace = _fd.g_trace(); |
| 28 |
_fd.s_trace(0); |
| 29 |
} |
| 30 |
~cv4l_disable_trace() |
| 31 |
{ |
| 32 |
_fd.s_trace(old_trace); |
| 33 |
} |
| 34 |
private: |
| 35 |
cv4l_fd &_fd; |
| 36 |
unsigned int old_trace; |
| 37 |
}; |
| 38 |
|
| 39 |
/* Available options. |
| 40 |
|
| 41 |
Please keep the first part (options < 128) in alphabetical order. |
| 42 |
That makes it easier to see which short options are still free. |
| 43 |
|
| 44 |
In general the lower case is used to set something and the upper |
| 45 |
case is used to retrieve a setting. */ |
| 46 |
enum Option { |
| 47 |
OptListDevices = 'A', |
| 48 |
OptGetSlicedVbiFormat = 'B', |
| 49 |
OptSetSlicedVbiFormat = 'b', |
| 50 |
OptGetCtrl = 'C', |
| 51 |
OptSetCtrl = 'c', |
| 52 |
OptSetDevice = 'd', |
| 53 |
OptGetDriverInfo = 'D', |
| 54 |
OptSetOutDevice = 'e', |
| 55 |
OptSetExportDevice = 'E', |
| 56 |
OptGetFreq = 'F', |
| 57 |
OptSetFreq = 'f', |
| 58 |
OptHelp = 'h', |
| 59 |
OptGetInput = 'I', |
| 60 |
OptSetInput = 'i', |
| 61 |
OptConcise = 'k', |
| 62 |
OptListCtrls = 'l', |
| 63 |
OptListCtrlsMenus = 'L', |
| 64 |
OptListOutputs = 'N', |
| 65 |
OptListInputs = 'n', |
| 66 |
OptGetOutput = 'O', |
| 67 |
OptSetOutput = 'o', |
| 68 |
OptGetParm = 'P', |
| 69 |
OptSetParm = 'p', |
| 70 |
OptSubset = 'r', |
| 71 |
OptGetStandard = 'S', |
| 72 |
OptSetStandard = 's', |
| 73 |
OptGetTuner = 'T', |
| 74 |
OptSetTuner = 't', |
| 75 |
OptGetVideoFormat = 'V', |
| 76 |
OptSetVideoFormat = 'v', |
| 77 |
OptUseWrapper = 'w', |
| 78 |
OptGetVideoOutFormat = 'X', |
| 79 |
OptSetVideoOutFormat = 'x', |
| 80 |
OptMediaBusInfo = 'z', |
| 81 |
|
| 82 |
OptGetSlicedVbiOutFormat = 128, |
| 83 |
OptGetOverlayFormat, |
| 84 |
OptGetVbiFormat, |
| 85 |
OptGetVbiOutFormat, |
| 86 |
OptGetSdrFormat, |
| 87 |
OptGetSdrOutFormat, |
| 88 |
OptGetMetaFormat, |
| 89 |
OptGetMetaOutFormat, |
| 90 |
OptGetSubDevFormat, |
| 91 |
OptSetSlicedVbiOutFormat, |
| 92 |
OptSetOverlayFormat, |
| 93 |
OptSetVbiFormat, |
| 94 |
OptSetVbiOutFormat, |
| 95 |
OptSetSdrFormat, |
| 96 |
OptSetSdrOutFormat, |
| 97 |
OptSetMetaFormat, |
| 98 |
OptSetMetaOutFormat, |
| 99 |
OptSetSubDevFormat, |
| 100 |
OptTryVideoOutFormat, |
| 101 |
OptTrySlicedVbiOutFormat, |
| 102 |
OptTrySlicedVbiFormat, |
| 103 |
OptTryVideoFormat, |
| 104 |
OptTryOverlayFormat, |
| 105 |
OptTryVbiFormat, |
| 106 |
OptTryVbiOutFormat, |
| 107 |
OptTrySdrFormat, |
| 108 |
OptTrySdrOutFormat, |
| 109 |
OptTryMetaFormat, |
| 110 |
OptTryMetaOutFormat, |
| 111 |
OptTrySubDevFormat, |
| 112 |
OptAll, |
| 113 |
OptListStandards, |
| 114 |
OptListFormats, |
| 115 |
OptListFormatsExt, |
| 116 |
OptListFields, |
| 117 |
OptListFrameSizes, |
| 118 |
OptListFrameIntervals, |
| 119 |
OptListOverlayFormats, |
| 120 |
OptListSdrFormats, |
| 121 |
OptListSdrOutFormats, |
| 122 |
OptListOutFormats, |
| 123 |
OptListOutFormatsExt, |
| 124 |
OptListMetaFormats, |
| 125 |
OptListMetaOutFormats, |
| 126 |
OptListSubDevMBusCodes, |
| 127 |
OptListSubDevFrameSizes, |
| 128 |
OptListSubDevFrameIntervals, |
| 129 |
OptListOutFields, |
| 130 |
OptClearClips, |
| 131 |
OptClearBitmap, |
| 132 |
OptAddClip, |
| 133 |
OptAddBitmap, |
| 134 |
OptFindFb, |
| 135 |
OptLogStatus, |
| 136 |
OptVerbose, |
| 137 |
OptSilent, |
| 138 |
OptGetSlicedVbiCap, |
| 139 |
OptGetSlicedVbiOutCap, |
| 140 |
OptGetFBuf, |
| 141 |
OptSetFBuf, |
| 142 |
OptGetCrop, |
| 143 |
OptSetCrop, |
| 144 |
OptGetOutputCrop, |
| 145 |
OptSetOutputCrop, |
| 146 |
OptGetOverlayCrop, |
| 147 |
OptSetOverlayCrop, |
| 148 |
OptGetOutputOverlayCrop, |
| 149 |
OptSetOutputOverlayCrop, |
| 150 |
OptGetSelection, |
| 151 |
OptSetSelection, |
| 152 |
OptGetOutputSelection, |
| 153 |
OptSetOutputSelection, |
| 154 |
OptGetSubDevSelection, |
| 155 |
OptSetSubDevSelection, |
| 156 |
OptTrySubDevSelection, |
| 157 |
OptGetSubDevFPS, |
| 158 |
OptSetSubDevFPS, |
| 159 |
OptGetAudioInput, |
| 160 |
OptSetAudioInput, |
| 161 |
OptGetAudioOutput, |
| 162 |
OptSetAudioOutput, |
| 163 |
OptListAudioOutputs, |
| 164 |
OptListAudioInputs, |
| 165 |
OptGetCropCap, |
| 166 |
OptGetOutputCropCap, |
| 167 |
OptGetOverlayCropCap, |
| 168 |
OptGetOutputOverlayCropCap, |
| 169 |
OptOverlay, |
| 170 |
OptSleep, |
| 171 |
OptGetJpegComp, |
| 172 |
OptSetJpegComp, |
| 173 |
OptGetModulator, |
| 174 |
OptSetModulator, |
| 175 |
OptListFreqBands, |
| 176 |
OptListDevicesInput, |
| 177 |
OptListDevicesOutput, |
| 178 |
OptGetOutputParm, |
| 179 |
OptSetOutputParm, |
| 180 |
OptQueryStandard, |
| 181 |
OptPollForEvent, |
| 182 |
OptEPollForEvent, |
| 183 |
OptWaitForEvent, |
| 184 |
OptGetPriority, |
| 185 |
OptSetPriority, |
| 186 |
OptListDvTimings, |
| 187 |
OptQueryDvTimings, |
| 188 |
OptGetDvTimings, |
| 189 |
OptSetDvBtTimings, |
| 190 |
OptGetDvTimingsCap, |
| 191 |
OptSetEdid, |
| 192 |
OptClearEdid, |
| 193 |
OptGetEdid, |
| 194 |
OptInfoEdid, |
| 195 |
OptShowEdid, |
| 196 |
OptKeepEdidChecksums, |
| 197 |
OptGetRouting, |
| 198 |
OptSetRouting, |
| 199 |
OptTryRouting, |
| 200 |
OptFreqSeek, |
| 201 |
OptEncoderCmd, |
| 202 |
OptTryEncoderCmd, |
| 203 |
OptDecoderCmd, |
| 204 |
OptTryDecoderCmd, |
| 205 |
OptTunerIndex, |
| 206 |
OptListBuffers, |
| 207 |
OptListBuffersOut, |
| 208 |
OptListBuffersVbi, |
| 209 |
OptListBuffersSlicedVbi, |
| 210 |
OptListBuffersVbiOut, |
| 211 |
OptListBuffersSlicedVbiOut, |
| 212 |
OptListBuffersSdr, |
| 213 |
OptListBuffersSdrOut, |
| 214 |
OptListBuffersMeta, |
| 215 |
OptListBuffersMetaOut, |
| 216 |
OptStreamCount, |
| 217 |
OptStreamSkip, |
| 218 |
OptStreamLoop, |
| 219 |
OptStreamSleep, |
| 220 |
OptStreamPoll, |
| 221 |
OptStreamNoQuery, |
| 222 |
OptStreamTo, |
| 223 |
OptStreamToHdr, |
| 224 |
OptStreamToHost, |
| 225 |
OptStreamLossless, |
| 226 |
OptStreamShowDeltaNow, |
| 227 |
OptStreamBufCaps, |
| 228 |
OptStreamMmap, |
| 229 |
OptStreamUser, |
| 230 |
OptStreamDmaBuf, |
| 231 |
OptStreamFrom, |
| 232 |
OptStreamFromHdr, |
| 233 |
OptStreamFromHost, |
| 234 |
OptStreamOutPattern, |
| 235 |
OptStreamOutSquare, |
| 236 |
OptStreamOutBorder, |
| 237 |
OptStreamOutInsertSAV, |
| 238 |
OptStreamOutInsertEAV, |
| 239 |
OptStreamOutHorSpeed, |
| 240 |
OptStreamOutVertSpeed, |
| 241 |
OptStreamOutPercFill, |
| 242 |
OptStreamOutAlphaComponent, |
| 243 |
OptStreamOutAlphaRedOnly, |
| 244 |
OptStreamOutRGBLimitedRange, |
| 245 |
OptStreamOutPixelAspect, |
| 246 |
OptStreamOutVideoAspect, |
| 247 |
OptStreamOutBufCaps, |
| 248 |
OptStreamOutMmap, |
| 249 |
OptStreamOutUser, |
| 250 |
OptStreamOutDmaBuf, |
| 251 |
OptListPatterns, |
| 252 |
OptHelpTuner, |
| 253 |
OptHelpIO, |
| 254 |
OptHelpStds, |
| 255 |
OptHelpVidCap, |
| 256 |
OptHelpVidOut, |
| 257 |
OptHelpOverlay, |
| 258 |
OptHelpVbi, |
| 259 |
OptHelpSdr, |
| 260 |
OptHelpMeta, |
| 261 |
OptHelpSubDev, |
| 262 |
OptHelpSelection, |
| 263 |
OptHelpMisc, |
| 264 |
OptHelpStreaming, |
| 265 |
OptHelpEdid, |
| 266 |
OptHelpAll, |
| 267 |
OptVersion, |
| 268 |
OptLast = 512 |
| 269 |
}; |
| 270 |
|
| 271 |
extern char options[OptLast]; |
| 272 |
extern unsigned capabilities; |
| 273 |
extern unsigned out_capabilities; |
| 274 |
extern unsigned priv_magic; |
| 275 |
extern unsigned out_priv_magic; |
| 276 |
extern bool is_multiplanar; |
| 277 |
extern __u32 vidcap_buftype; |
| 278 |
extern __u32 vidout_buftype; |
| 279 |
extern int verbose; |
| 280 |
|
| 281 |
/* fmts specified */ |
| 282 |
#define FmtWidth (1L<<0) |
| 283 |
#define FmtHeight (1L<<1) |
| 284 |
#define FmtChromaKey (1L<<2) |
| 285 |
#define FmtGlobalAlpha (1L<<3) |
| 286 |
#define FmtPixelFormat (1L<<4) |
| 287 |
#define FmtLeft (1L<<5) |
| 288 |
#define FmtTop (1L<<6) |
| 289 |
#define FmtField (1L<<7) |
| 290 |
#define FmtColorspace (1L<<8) |
| 291 |
#define FmtYCbCr (1L<<9) |
| 292 |
#define FmtQuantization (1L<<10) |
| 293 |
#define FmtFlags (1L<<11) |
| 294 |
#define FmtBytesPerLine (1L<<12) |
| 295 |
#define FmtXferFunc (1L<<13) |
| 296 |
#define FmtSizeImage (1L<<14) |
| 297 |
|
| 298 |
// v4l2-ctl.cpp |
| 299 |
int doioctl_name(int fd, unsigned long int request, void *parm, const char *name); |
| 300 |
int test_ioctl(int fd, unsigned long cmd, void *arg); |
| 301 |
int parse_subopt(char **subs, const char * const *subopts, char **value); |
| 302 |
__u32 parse_field(const char *s); |
| 303 |
__u32 parse_colorspace(const char *s); |
| 304 |
__u32 parse_xfer_func(const char *s); |
| 305 |
__u32 parse_ycbcr(const char *s); |
| 306 |
__u32 parse_hsv(const char *s); |
| 307 |
__u32 parse_quantization(const char *s); |
| 308 |
int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat, |
| 309 |
__u32 &field, __u32 &colorspace, __u32 &xfer, __u32 &ycbcr, |
| 310 |
__u32 &quantization, __u32 &flags, __u32 *bytesperline, |
| 311 |
__u32 *sizeimage); |
| 312 |
int parse_selection_target(const char *s, unsigned int &target); |
| 313 |
int parse_selection_flags(const char *s); |
| 314 |
void print_selection(const struct v4l2_selection &sel); |
| 315 |
__u32 find_pixel_format(int fd, unsigned index, bool output, bool mplane); |
| 316 |
bool valid_pixel_format(int fd, __u32 pixelformat, bool output, bool mplane); |
| 317 |
void print_frmsize(const struct v4l2_frmsizeenum &frmsize, const char *prefix); |
| 318 |
void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix); |
| 319 |
void printfmt(int fd, const struct v4l2_format &vfmt); |
| 320 |
void print_video_formats(cv4l_fd &fd, __u32 type, unsigned int mbus_code, bool enum_all); |
| 321 |
void print_video_formats_ext(cv4l_fd &fd, __u32 type, unsigned int mbus_code, bool enum_all); |
| 322 |
|
| 323 |
static inline bool subscribe_event(cv4l_fd &fd, __u32 type) |
| 324 |
{ |
| 325 |
struct v4l2_event_subscription sub; |
| 326 |
|
| 327 |
memset(&sub, 0, sizeof(sub)); |
| 328 |
sub.type = type; |
| 329 |
|
| 330 |
cv4l_disable_trace dt(fd); |
| 331 |
return !fd.subscribe_event(sub); |
| 332 |
} |
| 333 |
|
| 334 |
#define doioctl(n, r, p) doioctl_name(n, r, p, #r) |
| 335 |
|
| 336 |
#define info(fmt, args...) \ |
| 337 |
do { \ |
| 338 |
if (!options[OptSilent]) \ |
| 339 |
printf(fmt, ##args); \ |
| 340 |
} while (0) |
| 341 |
|
| 342 |
#define stderr_info(fmt, args...) \ |
| 343 |
do { \ |
| 344 |
if (!options[OptSilent]) \ |
| 345 |
fprintf(stderr, fmt, ##args); \ |
| 346 |
} while (0) |
| 347 |
|
| 348 |
// v4l2-ctl-common.cpp |
| 349 |
void common_usage(void); |
| 350 |
void common_cmd(int ch, char *optarg); |
| 351 |
void common_set(cv4l_fd &fd); |
| 352 |
void common_get(cv4l_fd &fd); |
| 353 |
bool common_list_devices(const std::string &media_bus_info, cv4l_fd &fd); |
| 354 |
void common_list(cv4l_fd &fd); |
| 355 |
void common_process_controls(cv4l_fd &fd); |
| 356 |
void common_control_event(int fd, const struct v4l2_event *ev); |
| 357 |
int common_find_ctrl_id(const char *name); |
| 358 |
|
| 359 |
// v4l2-ctl-tuner.cpp |
| 360 |
void tuner_usage(void); |
| 361 |
void tuner_cmd(int ch, char *optarg); |
| 362 |
void tuner_set(cv4l_fd &fd); |
| 363 |
void tuner_get(cv4l_fd &fd); |
| 364 |
|
| 365 |
// v4l2-ctl-io.cpp |
| 366 |
void io_usage(void); |
| 367 |
void io_cmd(int ch, char *optarg); |
| 368 |
void io_set(cv4l_fd &fd); |
| 369 |
void io_get(cv4l_fd &fd); |
| 370 |
void io_list(cv4l_fd &fd); |
| 371 |
|
| 372 |
// v4l2-ctl-stds.cpp |
| 373 |
void stds_usage(void); |
| 374 |
void stds_cmd(int ch, char *optarg); |
| 375 |
void stds_set(cv4l_fd &fd); |
| 376 |
void stds_get(cv4l_fd &fd); |
| 377 |
void stds_list(cv4l_fd &fd); |
| 378 |
|
| 379 |
// v4l2-ctl-vidcap.cpp |
| 380 |
void vidcap_usage(void); |
| 381 |
void vidcap_cmd(int ch, char *optarg); |
| 382 |
int vidcap_get_and_update_fmt(cv4l_fd &_fd, struct v4l2_format &vfmt); |
| 383 |
void vidcap_set(cv4l_fd &fd); |
| 384 |
void vidcap_get(cv4l_fd &fd); |
| 385 |
void vidcap_list(cv4l_fd &fd); |
| 386 |
void print_touch_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); |
| 387 |
|
| 388 |
// v4l2-ctl-vidout.cpp |
| 389 |
void vidout_usage(void); |
| 390 |
void vidout_cmd(int ch, char *optarg); |
| 391 |
void vidout_set(cv4l_fd &fd); |
| 392 |
void vidout_get(cv4l_fd &fd); |
| 393 |
void vidout_list(cv4l_fd &fd); |
| 394 |
|
| 395 |
// v4l2-ctl-overlay.cpp |
| 396 |
void overlay_usage(void); |
| 397 |
void overlay_cmd(int ch, char *optarg); |
| 398 |
void overlay_set(cv4l_fd &fd); |
| 399 |
void overlay_get(cv4l_fd &fd); |
| 400 |
void overlay_list(cv4l_fd &fd); |
| 401 |
|
| 402 |
// v4l2-ctl-vbi.cpp |
| 403 |
void vbi_usage(void); |
| 404 |
void vbi_cmd(int ch, char *optarg); |
| 405 |
void vbi_set(cv4l_fd &fd); |
| 406 |
void vbi_get(cv4l_fd &fd); |
| 407 |
void vbi_list(cv4l_fd &fd); |
| 408 |
|
| 409 |
// v4l2-ctl-sdr.cpp |
| 410 |
void sdr_usage(void); |
| 411 |
void sdr_cmd(int ch, char *optarg); |
| 412 |
void sdr_set(cv4l_fd &fd); |
| 413 |
void sdr_get(cv4l_fd &fd); |
| 414 |
void sdr_list(cv4l_fd &fd); |
| 415 |
|
| 416 |
// v4l2-ctl-meta.cpp |
| 417 |
void meta_usage(void); |
| 418 |
void meta_cmd(int ch, char *optarg); |
| 419 |
void meta_set(cv4l_fd &fd); |
| 420 |
void meta_get(cv4l_fd &fd); |
| 421 |
void meta_list(cv4l_fd &fd); |
| 422 |
void print_meta_buffer(FILE *f, cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); |
| 423 |
void meta_fillbuffer(cv4l_buffer &buf, cv4l_fmt &fmt, cv4l_queue &q); |
| 424 |
|
| 425 |
// v4l2-ctl-subdev.cpp |
| 426 |
void subdev_usage(void); |
| 427 |
void subdev_cmd(int ch, char *optarg); |
| 428 |
void subdev_set(cv4l_fd &fd); |
| 429 |
void subdev_get(cv4l_fd &fd); |
| 430 |
void subdev_list(cv4l_fd &fd); |
| 431 |
|
| 432 |
// v4l2-ctl-selection.cpp |
| 433 |
void selection_usage(void); |
| 434 |
void selection_cmd(int ch, char *optarg); |
| 435 |
void selection_set(cv4l_fd &fd); |
| 436 |
void selection_get(cv4l_fd &fd); |
| 437 |
|
| 438 |
// v4l2-ctl-misc.cpp |
| 439 |
// This one is also used by the streaming code. |
| 440 |
extern struct v4l2_decoder_cmd dec_cmd; |
| 441 |
void misc_usage(void); |
| 442 |
void misc_cmd(int ch, char *optarg); |
| 443 |
void misc_set(cv4l_fd &fd); |
| 444 |
void misc_get(cv4l_fd &fd); |
| 445 |
|
| 446 |
// v4l2-ctl-streaming.cpp |
| 447 |
void streaming_usage(void); |
| 448 |
void streaming_cmd(int ch, char *optarg); |
| 449 |
void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd, cv4l_fd &exp_fd); |
| 450 |
void streaming_list(cv4l_fd &fd, cv4l_fd &out_fd); |
| 451 |
|
| 452 |
// v4l2-ctl-edid.cpp |
| 453 |
void edid_usage(void); |
| 454 |
void edid_cmd(int ch, char *optarg); |
| 455 |
void edid_set(cv4l_fd &fd); |
| 456 |
void edid_get(cv4l_fd &fd); |
| 457 |
|
| 458 |
/* v4l2-ctl-modes.cpp */ |
| 459 |
bool calc_cvt_modeline(int image_width, int image_height, |
| 460 |
int refresh_rate, int reduced_blanking, |
| 461 |
bool interlaced, bool reduced_fps, |
| 462 |
struct v4l2_bt_timings *cvt); |
| 463 |
|
| 464 |
bool calc_gtf_modeline(int image_width, int image_height, |
| 465 |
int refresh_rate, bool reduced_blanking, |
| 466 |
bool interlaced, struct v4l2_bt_timings *gtf); |
| 467 |
#endif |