/v4l-utils-0.8.8/utils/v4l2-ctl/v4l2-ctl.cpp
# · C++ · 3756 lines · 3407 code · 306 blank · 43 comment · 772 complexity · 9ca7652ddfa5370be759efe6852865bd MD5 · raw file
Large files are truncated click here to view the full file
- /*
- Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo dot com>
- Cleanup and VBI and audio in/out options, introduction in v4l-dvb,
- support for most new APIs since 2006.
- Copyright (C) 2004, 2006, 2007 Hans Verkuil <hverkuil@xs4all.nl>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
- */
- #include <unistd.h>
- #include <features.h> /* Uses _GNU_SOURCE to define getsubopt in stdlib.h */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <inttypes.h>
- #include <getopt.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <ctype.h>
- #include <errno.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #include <dirent.h>
- #include <math.h>
- #include <sys/klog.h>
- #include <linux/videodev2.h>
- #include <libv4l2.h>
- #include <list>
- #include <vector>
- #include <map>
- #include <string>
- #include <algorithm>
- /* Short option list
- Please keep in alphabetical order.
- That makes it easier to see which short options are still free.
- In general the lower case is used to set something and the upper
- case is used to retrieve a setting. */
- enum Option {
- OptGetSlicedVbiFormat = 'B',
- OptSetSlicedVbiFormat = 'b',
- OptGetCtrl = 'C',
- OptSetCtrl = 'c',
- OptSetDevice = 'd',
- OptGetDriverInfo = 'D',
- OptGetFreq = 'F',
- OptSetFreq = 'f',
- OptHelp = 'h',
- OptGetInput = 'I',
- OptSetInput = 'i',
- OptListCtrls = 'l',
- OptListCtrlsMenus = 'L',
- OptListOutputs = 'N',
- OptListInputs = 'n',
- OptGetOutput = 'O',
- OptSetOutput = 'o',
- OptGetParm = 'P',
- OptSetParm = 'p',
- OptGetStandard = 'S',
- OptSetStandard = 's',
- OptGetTuner = 'T',
- OptSetTuner = 't',
- OptGetVideoFormat = 'V',
- OptSetVideoFormat = 'v',
- OptUseWrapper = 'w',
- OptGetVideoMplaneFormat = 128,
- OptSetVideoMplaneFormat,
- OptGetSlicedVbiOutFormat,
- OptGetOverlayFormat,
- OptGetOutputOverlayFormat,
- OptGetVbiFormat,
- OptGetVbiOutFormat,
- OptGetVideoOutFormat,
- OptGetVideoOutMplaneFormat,
- OptSetSlicedVbiOutFormat,
- OptSetOutputOverlayFormat,
- OptSetOverlayFormat,
- //OptSetVbiFormat, TODO
- //OptSetVbiOutFormat, TODO
- OptSetVideoOutFormat,
- OptSetVideoOutMplaneFormat,
- OptTryVideoOutFormat,
- OptTryVideoOutMplaneFormat,
- OptTrySlicedVbiOutFormat,
- OptTrySlicedVbiFormat,
- OptTryVideoFormat,
- OptTryVideoMplaneFormat,
- OptTryOutputOverlayFormat,
- OptTryOverlayFormat,
- //OptTryVbiFormat, TODO
- //OptTryVbiOutFormat, TODO
- OptAll,
- OptStreamOff,
- OptStreamOn,
- OptListStandards,
- OptListFormats,
- OptListMplaneFormats,
- OptListFormatsExt,
- OptListMplaneFormatsExt,
- OptListFrameSizes,
- OptListFrameIntervals,
- OptListOverlayFormats,
- OptListOutFormats,
- OptListOutMplaneFormats,
- OptLogStatus,
- OptVerbose,
- OptSilent,
- OptGetSlicedVbiCap,
- OptGetSlicedVbiOutCap,
- OptGetFBuf,
- OptSetFBuf,
- OptGetCrop,
- OptSetCrop,
- OptGetOutputCrop,
- OptSetOutputCrop,
- OptGetOverlayCrop,
- OptSetOverlayCrop,
- OptGetOutputOverlayCrop,
- OptSetOutputOverlayCrop,
- OptGetAudioInput,
- OptSetAudioInput,
- OptGetAudioOutput,
- OptSetAudioOutput,
- OptListAudioOutputs,
- OptListAudioInputs,
- OptGetCropCap,
- OptGetOutputCropCap,
- OptGetOverlayCropCap,
- OptGetOutputOverlayCropCap,
- OptOverlay,
- OptSleep,
- OptGetJpegComp,
- OptSetJpegComp,
- OptGetModulator,
- OptSetModulator,
- OptListDevices,
- OptGetOutputParm,
- OptSetOutputParm,
- OptQueryStandard,
- OptPollForEvent,
- OptWaitForEvent,
- OptGetPriority,
- OptSetPriority,
- OptListDvPresets,
- OptSetDvPreset,
- OptGetDvPreset,
- OptQueryDvPreset,
- OptGetDvBtTimings,
- OptSetDvBtTimings,
- OptLast = 256
- };
- static char options[OptLast];
- static int app_result;
- static int verbose;
- static unsigned capabilities;
- typedef std::map<unsigned, std::vector<struct v4l2_ext_control> > class2ctrls_map;
- typedef std::map<std::string, struct v4l2_queryctrl> ctrl_qmap;
- static ctrl_qmap ctrl_str2q;
- typedef std::map<unsigned, std::string> ctrl_idmap;
- static ctrl_idmap ctrl_id2str;
- typedef std::list<std::string> ctrl_get_list;
- static ctrl_get_list get_ctrls;
- typedef std::map<std::string, std::string> ctrl_set_map;
- static ctrl_set_map set_ctrls;
- typedef std::vector<std::string> dev_vec;
- typedef std::map<std::string, std::string> dev_map;
- typedef struct {
- unsigned flag;
- const char *str;
- } flag_def;
- static const flag_def service_def[] = {
- { V4L2_SLICED_TELETEXT_B, "teletext" },
- { V4L2_SLICED_VPS, "vps" },
- { V4L2_SLICED_CAPTION_525, "cc" },
- { V4L2_SLICED_WSS_625, "wss" },
- { 0, NULL }
- };
- /* fmts specified */
- #define FmtWidth (1L<<0)
- #define FmtHeight (1L<<1)
- #define FmtChromaKey (1L<<2)
- #define FmtGlobalAlpha (1L<<3)
- #define FmtPixelFormat (1L<<4)
- #define FmtLeft (1L<<5)
- #define FmtTop (1L<<6)
- #define FmtField (1L<<7)
- /* crop specified */
- #define CropWidth (1L<<0)
- #define CropHeight (1L<<1)
- #define CropLeft (1L<<2)
- #define CropTop (1L<<3)
- static struct option long_options[] = {
- {"list-audio-inputs", no_argument, 0, OptListAudioInputs},
- {"list-audio-outputs", no_argument, 0, OptListAudioOutputs},
- {"all", no_argument, 0, OptAll},
- {"device", required_argument, 0, OptSetDevice},
- {"get-fmt-video", no_argument, 0, OptGetVideoFormat},
- {"set-fmt-video", required_argument, 0, OptSetVideoFormat},
- {"try-fmt-video", required_argument, 0, OptTryVideoFormat},
- {"get-fmt-video-mplane", no_argument, 0, OptGetVideoMplaneFormat},
- {"set-fmt-video-mplane", required_argument, 0, OptSetVideoMplaneFormat},
- {"try-fmt-video-mplane", required_argument, 0, OptTryVideoMplaneFormat},
- {"get-fmt-video-out", no_argument, 0, OptGetVideoOutFormat},
- {"set-fmt-video-out", required_argument, 0, OptSetVideoOutFormat},
- {"try-fmt-video-out", required_argument, 0, OptTryVideoOutFormat},
- {"get-fmt-video-out-mplane", no_argument, 0, OptGetVideoOutMplaneFormat},
- {"set-fmt-video-out-mplane", required_argument, 0, OptSetVideoOutMplaneFormat},
- {"try-fmt-video-out-mplane", required_argument, 0, OptTryVideoOutMplaneFormat},
- {"help", no_argument, 0, OptHelp},
- {"wrapper", no_argument, 0, OptUseWrapper},
- {"get-output", no_argument, 0, OptGetOutput},
- {"set-output", required_argument, 0, OptSetOutput},
- {"list-outputs", no_argument, 0, OptListOutputs},
- {"list-inputs", no_argument, 0, OptListInputs},
- {"get-input", no_argument, 0, OptGetInput},
- {"set-input", required_argument, 0, OptSetInput},
- {"get-audio-input", no_argument, 0, OptGetAudioInput},
- {"set-audio-input", required_argument, 0, OptSetAudioInput},
- {"get-audio-output", no_argument, 0, OptGetAudioOutput},
- {"set-audio-output", required_argument, 0, OptSetAudioOutput},
- {"get-freq", no_argument, 0, OptGetFreq},
- {"set-freq", required_argument, 0, OptSetFreq},
- {"streamoff", no_argument, 0, OptStreamOff},
- {"streamon", no_argument, 0, OptStreamOn},
- {"list-standards", no_argument, 0, OptListStandards},
- {"list-formats", no_argument, 0, OptListFormats},
- {"list-formats-mplane", no_argument, 0, OptListMplaneFormats},
- {"list-formats-ext", no_argument, 0, OptListFormatsExt},
- {"list-formats-ext-mplane", no_argument, 0, OptListMplaneFormatsExt},
- {"list-framesizes", required_argument, 0, OptListFrameSizes},
- {"list-frameintervals", required_argument, 0, OptListFrameIntervals},
- {"list-formats-overlay", no_argument, 0, OptListOverlayFormats},
- {"list-formats-out", no_argument, 0, OptListOutFormats},
- {"list-formats-out-mplane", no_argument, 0, OptListOutMplaneFormats},
- {"get-standard", no_argument, 0, OptGetStandard},
- {"set-standard", required_argument, 0, OptSetStandard},
- {"get-detected-standard", no_argument, 0, OptQueryStandard},
- {"get-parm", no_argument, 0, OptGetParm},
- {"set-parm", required_argument, 0, OptSetParm},
- {"get-output-parm", no_argument, 0, OptGetOutputParm},
- {"set-output-parm", required_argument, 0, OptSetOutputParm},
- {"info", no_argument, 0, OptGetDriverInfo},
- {"list-ctrls", no_argument, 0, OptListCtrls},
- {"list-ctrls-menus", no_argument, 0, OptListCtrlsMenus},
- {"set-ctrl", required_argument, 0, OptSetCtrl},
- {"get-ctrl", required_argument, 0, OptGetCtrl},
- {"get-tuner", no_argument, 0, OptGetTuner},
- {"set-tuner", required_argument, 0, OptSetTuner},
- {"verbose", no_argument, 0, OptVerbose},
- {"log-status", no_argument, 0, OptLogStatus},
- {"get-fmt-overlay", no_argument, 0, OptGetOverlayFormat},
- {"set-fmt-overlay", required_argument, 0, OptSetOverlayFormat},
- {"try-fmt-overlay", required_argument, 0, OptTryOverlayFormat},
- {"get-fmt-output-overlay", no_argument, 0, OptGetOutputOverlayFormat},
- {"set-fmt-output-overlay", required_argument, 0, OptSetOutputOverlayFormat},
- {"try-fmt-output-overlay", required_argument, 0, OptTryOutputOverlayFormat},
- {"get-fmt-sliced-vbi", no_argument, 0, OptGetSlicedVbiFormat},
- {"set-fmt-sliced-vbi", required_argument, 0, OptSetSlicedVbiFormat},
- {"try-fmt-sliced-vbi", required_argument, 0, OptTrySlicedVbiFormat},
- {"get-fmt-sliced-vbi-out", no_argument, 0, OptGetSlicedVbiOutFormat},
- {"set-fmt-sliced-vbi-out", required_argument, 0, OptSetSlicedVbiOutFormat},
- {"try-fmt-sliced-vbi-out", required_argument, 0, OptTrySlicedVbiOutFormat},
- {"get-fmt-vbi", no_argument, 0, OptGetVbiFormat},
- {"get-fmt-vbi-out", no_argument, 0, OptGetVbiOutFormat},
- {"get-sliced-vbi-cap", no_argument, 0, OptGetSlicedVbiCap},
- {"get-sliced-vbi-out-cap", no_argument, 0, OptGetSlicedVbiOutCap},
- {"get-fbuf", no_argument, 0, OptGetFBuf},
- {"set-fbuf", required_argument, 0, OptSetFBuf},
- {"get-cropcap", no_argument, 0, OptGetCropCap},
- {"get-crop", no_argument, 0, OptGetCrop},
- {"set-crop", required_argument, 0, OptSetCrop},
- {"get-cropcap-output", no_argument, 0, OptGetOutputCropCap},
- {"get-crop-output", no_argument, 0, OptGetOutputCrop},
- {"set-crop-output", required_argument, 0, OptSetOutputCrop},
- {"get-cropcap-overlay", no_argument, 0, OptGetOverlayCropCap},
- {"get-crop-overlay", no_argument, 0, OptGetOverlayCrop},
- {"set-crop-overlay", required_argument, 0, OptSetOverlayCrop},
- {"get-cropcap-output-overlay", no_argument, 0, OptGetOutputOverlayCropCap},
- {"get-crop-output-overlay", no_argument, 0, OptGetOutputOverlayCrop},
- {"set-crop-output-overlay", required_argument, 0, OptSetOutputOverlayCrop},
- {"get-jpeg-comp", no_argument, 0, OptGetJpegComp},
- {"set-jpeg-comp", required_argument, 0, OptSetJpegComp},
- {"get-modulator", no_argument, 0, OptGetModulator},
- {"set-modulator", required_argument, 0, OptSetModulator},
- {"get-priority", no_argument, 0, OptGetPriority},
- {"set-priority", required_argument, 0, OptSetPriority},
- {"wait-for-event", required_argument, 0, OptWaitForEvent},
- {"poll-for-event", required_argument, 0, OptPollForEvent},
- {"overlay", required_argument, 0, OptOverlay},
- {"sleep", required_argument, 0, OptSleep},
- {"list-devices", no_argument, 0, OptListDevices},
- {"list-dv-presets", no_argument, 0, OptListDvPresets},
- {"set-dv-presets", required_argument, 0, OptSetDvPreset},
- {"get-dv-presets", no_argument, 0, OptGetDvPreset},
- {"query-dv-presets", no_argument, 0, OptQueryDvPreset},
- {"get-dv-bt-timings", no_argument, 0, OptGetDvBtTimings},
- {"set-dv-bt-timings", required_argument, 0, OptSetDvBtTimings},
- {0, 0, 0, 0}
- };
- static void usage(void)
- {
- printf("Usage:\n");
- printf("Common options:\n"
- " --all display all information available\n"
- " -C, --get-ctrl=<ctrl>[,<ctrl>...]\n"
- " get the value of the controls [VIDIOC_G_EXT_CTRLS]\n"
- " -c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]\n"
- " set the controls to the values specified [VIDIOC_S_EXT_CTRLS]\n"
- " -D, --info show driver info [VIDIOC_QUERYCAP]\n"
- " -d, --device=<dev> use device <dev> instead of /dev/video0\n"
- " if <dev> is a single digit, then /dev/video<dev> is used\n"
- " -F, --get-freq query the frequency [VIDIOC_G_FREQUENCY]\n"
- " -f, --set-freq=<freq>\n"
- " set the frequency to <freq> MHz [VIDIOC_S_FREQUENCY]\n"
- " -h, --help display this help message\n"
- " -I, --get-input query the video input [VIDIOC_G_INPUT]\n"
- " -i, --set-input=<num>\n"
- " set the video input to <num> [VIDIOC_S_INPUT]\n"
- " -l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]\n"
- " -L, --list-ctrls-menus\n"
- " display all controls, their values and the menus [VIDIOC_QUERYMENU]\n"
- " -N, --list-outputs display video outputs [VIDIOC_ENUMOUTPUT]\n"
- " -n, --list-inputs display video inputs [VIDIOC_ENUMINPUT]\n"
- " -O, --get-output query the video output [VIDIOC_G_OUTPUT]\n"
- " -o, --set-output=<num>\n"
- " set the video output to <num> [VIDIOC_S_OUTPUT]\n"
- " --list-standards display supported video standards [VIDIOC_ENUMSTD]\n"
- " -S, --get-standard\n"
- " query the video standard [VIDIOC_G_STD]\n"
- " -s, --set-standard=<num>\n"
- " set the video standard to <num> [VIDIOC_S_STD]\n"
- " <num> can be a numerical v4l2_std value, or it can be one of:\n"
- " pal-X (X = B/G/H/N/Nc/I/D/K/M/60) or just 'pal' (V4L2_STD_PAL)\n"
- " ntsc-X (X = M/J/K) or just 'ntsc' (V4L2_STD_NTSC)\n"
- " secam-X (X = B/G/H/D/K/L/Lc) or just 'secam' (V4L2_STD_SECAM)\n"
- " --get-detected-standard\n"
- " display detected input video standard [VIDIOC_QUERYSTD]\n"
- " -P, --get-parm display video parameters [VIDIOC_G_PARM]\n"
- " -p, --set-parm=<fps>\n"
- " set video framerate in <fps> [VIDIOC_S_PARM]\n"
- " -T, --get-tuner query the tuner settings [VIDIOC_G_TUNER]\n"
- " -t, --set-tuner=<mode>\n"
- " set the audio mode of the tuner [VIDIOC_S_TUNER]\n"
- " Possible values: mono, stereo, lang2, lang1, bilingual\n"
- " --list-formats display supported video formats [VIDIOC_ENUM_FMT]\n"
- " --list-formats-mplane\n"
- " display supported video multi-planar formats [VIDIOC_ENUM_FMT]\n"
- " --list-formats-ext display supported video formats including frame sizes\n"
- " and intervals\n"
- " --list-formats-ext-mplane\n"
- " display supported video multi-planar formats including\n"
- " frame sizes and intervals\n"
- " --list-framesizes=<f>\n"
- " list supported framesizes for pixelformat <f>\n"
- " [VIDIOC_ENUM_FRAMESIZES]\n"
- " pixelformat is the fourcc value as a string\n"
- " --list-frameintervals=width=<w>,height=<h>,pixelformat=<f>\n"
- " list supported frame intervals for pixelformat <f> and\n"
- " the given width and height [VIDIOC_ENUM_FRAMEINTERVALS]\n"
- " pixelformat is the fourcc value as a string\n"
- " -V, --get-fmt-video\n"
- " query the video capture format [VIDIOC_G_FMT]\n"
- " -v, --set-fmt-video=width=<w>,height=<h>,pixelformat=<f>\n"
- " set the video capture format [VIDIOC_S_FMT]\n"
- " pixelformat is either the format index as reported by\n"
- " --list-formats, or the fourcc value as a string\n"
- " -w, --wrapper use the libv4l2 wrapper library.\n"
- " --list-devices list all v4l devices\n"
- " --silent only set the result code, do not print any messages\n"
- " --verbose turn on verbose ioctl status reporting\n"
- "\n");
- printf("Uncommon options:\n"
- " --try-fmt-video=width=<w>,height=<h>,pixelformat=<f>\n"
- " try the video capture format [VIDIOC_TRY_FMT]\n"
- " pixelformat is either the format index as reported by\n"
- " --list-formats, or the fourcc value as a string\n"
- " --get-fmt-video-mplane\n"
- " query the video capture format through the multi-planar API [VIDIOC_G_FMT]\n"
- " --set-fmt-video-mplane\n"
- " --try-fmt-video-mplane=width=<w>,height=<h>,pixelformat=<f>\n"
- " set/try the video capture format using the multi-planar API [VIDIOC_S/TRY_FMT]\n"
- " pixelformat is either the format index as reported by\n"
- " --list-formats-mplane, or the fourcc value as a string\n"
- " --list-formats-out display supported video output formats [VIDIOC_ENUM_FMT]\n"
- " --get-fmt-video-out\n"
- " query the video output format [VIDIOC_G_FMT]\n"
- " --set-fmt-video-out\n"
- " --try-fmt-video-out=width=<w>,height=<h>,pixelformat=<f>\n"
- " set/try the video output format [VIDIOC_TRY_FMT]\n"
- " pixelformat is either the format index as reported by\n"
- " --list-formats-out, or the fourcc value as a string\n"
- " --list-formats-out-mplane\n"
- " display supported video output multi-planar formats [VIDIOC_ENUM_FMT]\n"
- " --get-fmt-video-out-mplane\n"
- " query the video output format using the multi-planar API [VIDIOC_G_FMT]\n"
- " --set-fmt-video-out-mplane\n"
- " --try-fmt-video-out-mplane=width=<w>,height=<h>,pixelformat=<f>\n"
- " set/try the video output format with the multi-planar API [VIDIOC_S/TRY_FMT]\n"
- " pixelformat is either the format index as reported by\n"
- " --list-formats-out-mplane, or the fourcc value as a string\n"
- " --list-formats-overlay\n"
- " display supported overlay formats [VIDIOC_ENUM_FMT]\n"
- " --get-fmt-overlay query the video overlay format [VIDIOC_G_FMT]\n"
- " --get-fmt-output-overlay\n"
- " query the video output overlay format [VIDIOC_G_FMT]\n"
- " --set-fmt-overlay\n"
- " --try-fmt-overlay\n"
- " --set-fmt-output-overlay\n"
- " --try-fmt-output-overlay=chromakey=<key>,global_alpha=<alpha>,\n"
- " top=<t>,left=<l>,width=<w>,height=<h>,field=<f>\n"
- " set/try the video or video output overlay format [VIDIOC_S/TRY_FMT]\n"
- " <f> can be one of:\n"
- " any, none, top, bottom, interlaced, seq_tb, seq_bt, alternate,\n"
- " interlaced_tb, interlaced_bt\n"
- " --get-sliced-vbi-cap\n"
- " query the sliced VBI capture capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"
- " --get-sliced-vbi-out-cap\n"
- " query the sliced VBI output capabilities [VIDIOC_G_SLICED_VBI_CAP]\n"
- " -B, --get-fmt-sliced-vbi\n"
- " query the sliced VBI capture format [VIDIOC_G_FMT]\n"
- " --get-fmt-sliced-vbi-out\n"
- " query the sliced VBI output format [VIDIOC_G_FMT]\n"
- " -b, --set-fmt-sliced-vbi\n"
- " --try-fmt-sliced-vbi\n"
- " --set-fmt-sliced-vbi-out\n"
- " --try-fmt-sliced-vbi-out=<mode>\n"
- " set/try the sliced VBI capture/output format to <mode> [VIDIOC_S/TRY_FMT]\n"
- " <mode> is a comma separated list of:\n"
- " off: turn off sliced VBI (cannot be combined with other modes)\n"
- " teletext: teletext (PAL/SECAM)\n"
- " cc: closed caption (NTSC)\n"
- " wss: widescreen signal (PAL/SECAM)\n"
- " vps: VPS (PAL/SECAM)\n"
- " --get-fmt-vbi query the VBI capture format [VIDIOC_G_FMT]\n"
- " --get-fmt-vbi-out query the VBI output format [VIDIOC_G_FMT]\n"
- " --overlay=<on> turn overlay on (1) or off (0) (VIDIOC_OVERLAY)\n"
- " --get-fbuf query the overlay framebuffer data [VIDIOC_G_FBUF]\n"
- " --set-fbuf=chromakey=<0/1>,global_alpha=<0/1>,local_alpha=<0/1>,local_inv_alpha=<0/1>\n"
- " set the overlay framebuffer [VIDIOC_S_FBUF]\n"
- " --get-cropcap query the crop capabilities [VIDIOC_CROPCAP]\n"
- " --get-crop query the video capture crop window [VIDIOC_G_CROP]\n"
- " --set-crop=top=<x>,left=<y>,width=<w>,height=<h>\n"
- " set the video capture crop window [VIDIOC_S_CROP]\n"
- " --get-cropcap-output\n"
- " query the crop capabilities for video output [VIDIOC_CROPCAP]\n"
- " --get-crop-output query the video output crop window [VIDIOC_G_CROP]\n"
- " --set-crop-output=top=<x>,left=<y>,width=<w>,height=<h>\n"
- " set the video output crop window [VIDIOC_S_CROP]\n"
- " --get-cropcap-overlay\n"
- " query the crop capabilities for video overlay [VIDIOC_CROPCAP]\n"
- " --get-crop-overlay query the video overlay crop window [VIDIOC_G_CROP]\n"
- " --set-crop-overlay=top=<x>,left=<y>,width=<w>,height=<h>\n"
- " set the video overlay crop window [VIDIOC_S_CROP]\n"
- " --get-cropcap-output-overlay\n"
- " query the crop capabilities for video output overlays [VIDIOC_CROPCAP]\n"
- " --get-crop-output-overlay\n"
- " query the video output overlay crop window [VIDIOC_G_CROP]\n"
- " --set-crop-output-overlay=top=<x>,left=<y>,width=<w>,height=<h>\n"
- " set the video output overlay crop window [VIDIOC_S_CROP]\n"
- " --get-jpeg-comp query the JPEG compression [VIDIOC_G_JPEGCOMP]\n"
- " --set-jpeg-comp=quality=<q>,markers=<markers>,comment=<c>,app<n>=<a>\n"
- " set the JPEG compression [VIDIOC_S_JPEGCOMP]\n"
- " <n> is the app segment: 0-9 or a-f, <a> is the actual string.\n"
- " <markers> is a colon separated list of:\n"
- " dht: Define Huffman Tables\n"
- " dqt: Define Quantization Tables\n"
- " dri: Define Restart Interval\n"
- " --set-audio-output=<num>\n"
- " set the audio output to <num> [VIDIOC_S_AUDOUT]\n"
- " --get-audio-input query the audio input [VIDIOC_G_AUDIO]\n"
- " --set-audio-input=<num>\n"
- " set the audio input to <num> [VIDIOC_S_AUDIO]\n"
- " --get-audio-output query the audio output [VIDIOC_G_AUDOUT]\n"
- " --set-audio-output=<num>\n"
- " set the audio output to <num> [VIDIOC_S_AUDOUT]\n"
- " --list-audio-outputs\n"
- " display audio outputs [VIDIOC_ENUMAUDOUT]\n"
- " --list-audio-inputs\n"
- " display audio inputs [VIDIOC_ENUMAUDIO]\n"
- " --get-modulator query the modulator settings [VIDIOC_G_MODULATOR]\n"
- " --set-modulator=<txsubchans>\n"
- " set the sub-carrier modulation [VIDIOC_S_MODULATOR]\n"
- " <txsubchans> is one of:\n"
- " mono: Modulate as mono\n"
- " mono-rds: Modulate as mono with RDS (radio only)\n"
- " stereo: Modulate as stereo\n"
- " stereo-rds: Modulate as stereo with RDS (radio only)\n"
- " bilingual: Modulate as bilingual\n"
- " mono-sap: Modulate as mono with Second Audio Program\n"
- " stereo-sap: Modulate as stereo with Second Audio Program\n"
- " --get-priority query the current access priority [VIDIOC_G_PRIORITY]\n"
- " --set-priority=<prio>\n"
- " set the new access priority [VIDIOC_S_PRIORITY]\n"
- " <prio> is 1 (background), 2 (interactive) or 3 (record)\n"
- " --get-output-parm display output video parameters [VIDIOC_G_PARM]\n"
- " --set-output-parm=<fps>\n"
- " set output video framerate in <fps> [VIDIOC_S_PARM]\n"
- " --wait-for-event=<event>\n"
- " wait for an event [VIDIOC_DQEVENT]\n"
- " <event> is the event number or one of:\n"
- " eos, vsync, ctrl=<id>\n"
- " where <id> is the name of the control\n"
- " --poll-for-event=<event>\n"
- " poll for an event [VIDIOC_DQEVENT]\n"
- " see --wait-for-event for possible events\n"
- " --list-dv-presets list supported digital video presets [VIDIOC_ENUM_DV_PRESETS]\n"
- " --set-dv-preset=<num>\n"
- " set the digital video preset to <num> [VIDIOC_S_DV_PRESET]\n"
- " --get-dv-preset query the digital video preset in use [VIDIOC_G_DV_PRESET]\n"
- " --query-dv-preset query the detected digital video preset [VIDIOC_QUERY_DV_PRESET]\n"
- " --set-dv-bt-timings=width=<width>,height=<height>,interlaced=<0/1>,\n"
- " polarities=<polarities mask>,pixelclock=<pixelclock Hz>,\n"
- " hfp=<horizontal front porch>,hs=<horizontal sync>,\n"
- " hbp=<horizontal back porch>,vfporch=<vertical front porch>,\n"
- " vs=<vertical sync>,vbp=<vertical back porch>,\n"
- " il_vfp=<vertical front porch for bottom field>,\n"
- " il_vs=<vertical sync for bottom field>,\n"
- " il_vbp=<vertical back porch for bottom field>,\n"
- " set the digital video timings according to the BT 656/1120 standard [VIDIOC_S_DV_TIMINGS]\n"
- " --get-dv-bt-timings\n"
- " get the digital video timings in use [VIDIOC_G_DV_TIMINGS]\n"
- " --sleep=<secs> sleep for <secs> seconds, call QUERYCAP and close the file handle\n"
- " --streamoff turn the stream off [VIDIOC_STREAMOFF]\n"
- " --streamon turn the stream on [VIDIOC_STREAMON]\n"
- " --log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]\n");
- exit(0);
- }
- static int test_open(const char *file, int oflag)
- {
- return options[OptUseWrapper] ? v4l2_open(file, oflag) : open(file, oflag);
- }
- static int test_close(int fd)
- {
- return options[OptUseWrapper] ? v4l2_close(fd) : close(fd);
- }
- static int test_ioctl(int fd, int cmd, void *arg)
- {
- return options[OptUseWrapper] ? v4l2_ioctl(fd, cmd, arg) : ioctl(fd, cmd, arg);
- }
- static int doioctl_name(int fd, unsigned long int request, void *parm, const char *name)
- {
- int retval = test_ioctl(fd, request, parm);
- if (retval < 0) {
- app_result = -1;
- }
- if (options[OptSilent]) return retval;
- if (retval < 0)
- printf("%s: failed: %s\n", name, strerror(errno));
- else if (verbose)
- printf("%s: ok\n", name);
- return retval;
- }
- #define doioctl(n, r, p) doioctl_name(n, r, p, #r)
- static std::string num2s(unsigned num)
- {
- char buf[10];
- sprintf(buf, "%08x", num);
- return buf;
- }
- static std::string buftype2s(int type)
- {
- switch (type) {
- case 0:
- return "Invalid";
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- return "Video Capture";
- case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
- return "Video Capture Multiplanar";
- case V4L2_BUF_TYPE_VIDEO_OUTPUT:
- return "Video Output";
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
- return "Video Output Multiplanar";
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- return "Video Overlay";
- case V4L2_BUF_TYPE_VBI_CAPTURE:
- return "VBI Capture";
- case V4L2_BUF_TYPE_VBI_OUTPUT:
- return "VBI Output";
- case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
- return "Sliced VBI Capture";
- case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
- return "Sliced VBI Output";
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
- return "Video Output Overlay";
- case V4L2_BUF_TYPE_PRIVATE:
- return "Private";
- default:
- return "Unknown (" + num2s(type) + ")";
- }
- }
- static std::string fcc2s(unsigned int val)
- {
- std::string s;
- s += val & 0xff;
- s += (val >> 8) & 0xff;
- s += (val >> 16) & 0xff;
- s += (val >> 24) & 0xff;
- return s;
- }
- static std::string field2s(int val)
- {
- switch (val) {
- case V4L2_FIELD_ANY:
- return "Any";
- case V4L2_FIELD_NONE:
- return "None";
- case V4L2_FIELD_TOP:
- return "Top";
- case V4L2_FIELD_BOTTOM:
- return "Bottom";
- case V4L2_FIELD_INTERLACED:
- return "Interlaced";
- case V4L2_FIELD_SEQ_TB:
- return "Sequential Top-Bottom";
- case V4L2_FIELD_SEQ_BT:
- return "Sequential Bottom-Top";
- case V4L2_FIELD_ALTERNATE:
- return "Alternating";
- case V4L2_FIELD_INTERLACED_TB:
- return "Interlaced Top-Bottom";
- case V4L2_FIELD_INTERLACED_BT:
- return "Interlaced Bottom-Top";
- default:
- return "Unknown (" + num2s(val) + ")";
- }
- }
- static std::string colorspace2s(int val)
- {
- switch (val) {
- case V4L2_COLORSPACE_SMPTE170M:
- return "Broadcast NTSC/PAL (SMPTE170M/ITU601)";
- case V4L2_COLORSPACE_SMPTE240M:
- return "1125-Line (US) HDTV (SMPTE240M)";
- case V4L2_COLORSPACE_REC709:
- return "HDTV and modern devices (ITU709)";
- case V4L2_COLORSPACE_BT878:
- return "Broken Bt878";
- case V4L2_COLORSPACE_470_SYSTEM_M:
- return "NTSC/M (ITU470/ITU601)";
- case V4L2_COLORSPACE_470_SYSTEM_BG:
- return "PAL/SECAM BG (ITU470/ITU601)";
- case V4L2_COLORSPACE_JPEG:
- return "JPEG (JFIF/ITU601)";
- case V4L2_COLORSPACE_SRGB:
- return "SRGB";
- default:
- return "Unknown (" + num2s(val) + ")";
- }
- }
- static std::string flags2s(unsigned val, const flag_def *def)
- {
- std::string s;
- while (def->flag) {
- if (val & def->flag) {
- if (s.length()) s += ", ";
- s += def->str;
- val &= ~def->flag;
- }
- def++;
- }
- if (val) {
- if (s.length()) s += ", ";
- s += num2s(val);
- }
- return s;
- }
- static const flag_def in_status_def[] = {
- { V4L2_IN_ST_NO_POWER, "no power" },
- { V4L2_IN_ST_NO_SIGNAL, "no signal" },
- { V4L2_IN_ST_NO_COLOR, "no color" },
- { V4L2_IN_ST_HFLIP, "hflip" },
- { V4L2_IN_ST_VFLIP, "vflip" },
- { V4L2_IN_ST_NO_H_LOCK, "no hsync lock." },
- { V4L2_IN_ST_COLOR_KILL, "color kill" },
- { V4L2_IN_ST_NO_SYNC, "no sync lock" },
- { V4L2_IN_ST_NO_EQU, "no equalizer lock" },
- { V4L2_IN_ST_NO_CARRIER, "no carrier" },
- { V4L2_IN_ST_MACROVISION, "macrovision" },
- { V4L2_IN_ST_NO_ACCESS, "no conditional access" },
- { V4L2_IN_ST_VTR, "VTR time constant" },
- { 0, NULL }
- };
- static std::string status2s(__u32 status)
- {
- return status ? flags2s(status, in_status_def) : "ok";
- }
- static const flag_def input_cap_def[] = {
- {V4L2_IN_CAP_PRESETS, "DV presets" },
- {V4L2_IN_CAP_CUSTOM_TIMINGS, "custom DV timings" },
- {V4L2_IN_CAP_STD, "SD presets" },
- { 0, NULL }
- };
- static std::string input_cap2s(__u32 capabilities)
- {
- return capabilities ? flags2s(capabilities, input_cap_def) : "not defined";
- }
- static const flag_def output_cap_def[] = {
- {V4L2_OUT_CAP_PRESETS, "DV presets" },
- {V4L2_OUT_CAP_CUSTOM_TIMINGS, "custom DV timings" },
- {V4L2_OUT_CAP_STD, "SD presets" },
- { 0, NULL }
- };
- static std::string output_cap2s(__u32 capabilities)
- {
- return capabilities ? flags2s(capabilities, output_cap_def) : "not defined";
- }
- static void print_sliced_vbi_cap(struct v4l2_sliced_vbi_cap &cap)
- {
- printf("\tType : %s\n", buftype2s(cap.type).c_str());
- printf("\tService Set : %s\n",
- flags2s(cap.service_set, service_def).c_str());
- for (int i = 0; i < 24; i++) {
- printf("\tService Line %2d: %8s / %-8s\n", i,
- flags2s(cap.service_lines[0][i], service_def).c_str(),
- flags2s(cap.service_lines[1][i], service_def).c_str());
- }
- }
- static std::string name2var(unsigned char *name)
- {
- std::string s;
- int add_underscore = 0;
- while (*name) {
- if (isalnum(*name)) {
- if (add_underscore)
- s += '_';
- add_underscore = 0;
- s += std::string(1, tolower(*name));
- }
- else if (s.length()) add_underscore = 1;
- name++;
- }
- return s;
- }
- static std::string safename(const unsigned char *name)
- {
- std::string s;
- while (*name) {
- if (*name == '\n') {
- s += "\\n";
- }
- else if (*name == '\r') {
- s += "\\r";
- }
- else if (*name == '\f') {
- s += "\\f";
- }
- else if (*name == '\\') {
- s += "\\\\";
- }
- else if ((*name & 0x7f) < 0x20) {
- char buf[3];
- sprintf(buf, "%02x", *name);
- s += "\\x";
- s += buf;
- }
- else {
- s += *name;
- }
- name++;
- }
- return s;
- }
- static std::string safename(const char *name)
- {
- return safename((const unsigned char *)name);
- }
- static std::string ctrlflags2s(__u32 flags)
- {
- static const flag_def def[] = {
- { V4L2_CTRL_FLAG_GRABBED, "grabbed" },
- { V4L2_CTRL_FLAG_DISABLED, "disabled" },
- { V4L2_CTRL_FLAG_READ_ONLY, "read-only" },
- { V4L2_CTRL_FLAG_UPDATE, "update" },
- { V4L2_CTRL_FLAG_INACTIVE, "inactive" },
- { V4L2_CTRL_FLAG_SLIDER, "slider" },
- { V4L2_CTRL_FLAG_WRITE_ONLY, "write-only" },
- { 0, NULL }
- };
- return flags2s(flags, def);
- }
- static void print_qctrl(int fd, struct v4l2_queryctrl *queryctrl,
- struct v4l2_ext_control *ctrl, int show_menus)
- {
- struct v4l2_querymenu qmenu;
- std::string s = name2var(queryctrl->name);
- int i;
- memset(&qmenu, 0, sizeof(qmenu));
- qmenu.id = queryctrl->id;
- switch (queryctrl->type) {
- case V4L2_CTRL_TYPE_INTEGER:
- printf("%31s (int) : min=%d max=%d step=%d default=%d value=%d",
- s.c_str(),
- queryctrl->minimum, queryctrl->maximum,
- queryctrl->step, queryctrl->default_value,
- ctrl->value);
- break;
- case V4L2_CTRL_TYPE_INTEGER64:
- printf("%31s (int64) : value=%lld", s.c_str(), ctrl->value64);
- break;
- case V4L2_CTRL_TYPE_STRING:
- printf("%31s (str) : min=%d max=%d step=%d value='%s'",
- s.c_str(),
- queryctrl->minimum, queryctrl->maximum,
- queryctrl->step, safename(ctrl->string).c_str());
- break;
- case V4L2_CTRL_TYPE_BOOLEAN:
- printf("%31s (bool) : default=%d value=%d",
- s.c_str(),
- queryctrl->default_value, ctrl->value);
- break;
- case V4L2_CTRL_TYPE_MENU:
- printf("%31s (menu) : min=%d max=%d default=%d value=%d",
- s.c_str(),
- queryctrl->minimum, queryctrl->maximum,
- queryctrl->default_value, ctrl->value);
- break;
- case V4L2_CTRL_TYPE_BUTTON:
- printf("%31s (button) :", s.c_str());
- break;
- case V4L2_CTRL_TYPE_BITMASK:
- printf("%31s (bitmask): max=0x%08x default=0x%08x value=0x%08x",
- s.c_str(), queryctrl->maximum,
- queryctrl->default_value, ctrl->value);
- break;
- default: break;
- }
- if (queryctrl->flags)
- printf(" flags=%s", ctrlflags2s(queryctrl->flags).c_str());
- printf("\n");
- if (queryctrl->type == V4L2_CTRL_TYPE_MENU && show_menus) {
- for (i = queryctrl->minimum; i <= queryctrl->maximum; i++) {
- qmenu.index = i;
- if (test_ioctl(fd, VIDIOC_QUERYMENU, &qmenu))
- continue;
- printf("\t\t\t\t%d: %s\n", i, qmenu.name);
- }
- }
- }
- static int print_control(int fd, struct v4l2_queryctrl &qctrl, int show_menus)
- {
- struct v4l2_control ctrl;
- struct v4l2_ext_control ext_ctrl;
- struct v4l2_ext_controls ctrls;
- memset(&ctrl, 0, sizeof(ctrl));
- memset(&ext_ctrl, 0, sizeof(ext_ctrl));
- memset(&ctrls, 0, sizeof(ctrls));
- if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED)
- return 1;
- if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) {
- printf("\n%s\n\n", qctrl.name);
- return 1;
- }
- ext_ctrl.id = qctrl.id;
- if ((qctrl.flags & V4L2_CTRL_FLAG_WRITE_ONLY) ||
- qctrl.type == V4L2_CTRL_TYPE_BUTTON) {
- print_qctrl(fd, &qctrl, &ext_ctrl, show_menus);
- return 1;
- }
- ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(qctrl.id);
- ctrls.count = 1;
- ctrls.controls = &ext_ctrl;
- if (qctrl.type == V4L2_CTRL_TYPE_INTEGER64 ||
- qctrl.type == V4L2_CTRL_TYPE_STRING ||
- (V4L2_CTRL_ID2CLASS(qctrl.id) != V4L2_CTRL_CLASS_USER &&
- qctrl.id < V4L2_CID_PRIVATE_BASE)) {
- if (qctrl.type == V4L2_CTRL_TYPE_STRING) {
- ext_ctrl.size = qctrl.maximum + 1;
- ext_ctrl.string = (char *)malloc(ext_ctrl.size);
- ext_ctrl.string[0] = 0;
- }
- if (test_ioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls)) {
- printf("error %d getting ext_ctrl %s\n",
- errno, qctrl.name);
- return 0;
- }
- }
- else {
- ctrl.id = qctrl.id;
- if (test_ioctl(fd, VIDIOC_G_CTRL, &ctrl)) {
- printf("error %d getting ctrl %s\n",
- errno, qctrl.name);
- return 0;
- }
- ext_ctrl.value = ctrl.value;
- }
- print_qctrl(fd, &qctrl, &ext_ctrl, show_menus);
- if (qctrl.type == V4L2_CTRL_TYPE_STRING)
- free(ext_ctrl.string);
- return 1;
- }
- static void list_controls(int fd, int show_menus)
- {
- struct v4l2_queryctrl qctrl;
- int id;
- memset(&qctrl, 0, sizeof(qctrl));
- qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
- while (test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) {
- print_control(fd, qctrl, show_menus);
- qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
- }
- if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL)
- return;
- for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) {
- qctrl.id = id;
- if (test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0)
- print_control(fd, qctrl, show_menus);
- }
- for (qctrl.id = V4L2_CID_PRIVATE_BASE;
- test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) {
- print_control(fd, qctrl, show_menus);
- }
- }
- static void find_controls(int fd)
- {
- struct v4l2_queryctrl qctrl;
- int id;
- memset(&qctrl, 0, sizeof(qctrl));
- qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
- while (test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) {
- if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS &&
- !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
- ctrl_str2q[name2var(qctrl.name)] = qctrl;
- ctrl_id2str[qctrl.id] = name2var(qctrl.name);
- }
- qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
- }
- if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL)
- return;
- for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) {
- qctrl.id = id;
- if (test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0 &&
- !(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
- ctrl_str2q[name2var(qctrl.name)] = qctrl;
- ctrl_id2str[qctrl.id] = name2var(qctrl.name);
- }
- }
- for (qctrl.id = V4L2_CID_PRIVATE_BASE;
- test_ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) {
- if (!(qctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
- ctrl_str2q[name2var(qctrl.name)] = qctrl;
- ctrl_id2str[qctrl.id] = name2var(qctrl.name);
- }
- }
- }
- static std::string fbufcap2s(unsigned cap)
- {
- std::string s;
- if (cap & V4L2_FBUF_CAP_EXTERNOVERLAY)
- s += "\t\t\tExtern Overlay\n";
- if (cap & V4L2_FBUF_CAP_CHROMAKEY)
- s += "\t\t\tChromakey\n";
- if (cap & V4L2_FBUF_CAP_GLOBAL_ALPHA)
- s += "\t\t\tGlobal Alpha\n";
- if (cap & V4L2_FBUF_CAP_LOCAL_ALPHA)
- s += "\t\t\tLocal Alpha\n";
- if (cap & V4L2_FBUF_CAP_LOCAL_INV_ALPHA)
- s += "\t\t\tLocal Inverted Alpha\n";
- if (cap & V4L2_FBUF_CAP_LIST_CLIPPING)
- s += "\t\t\tClipping List\n";
- if (cap & V4L2_FBUF_CAP_BITMAP_CLIPPING)
- s += "\t\t\tClipping Bitmap\n";
- if (s.empty()) s += "\t\t\t\n";
- return s;
- }
- static std::string fbufflags2s(unsigned fl)
- {
- std::string s;
- if (fl & V4L2_FBUF_FLAG_PRIMARY)
- s += "\t\t\tPrimary Graphics Surface\n";
- if (fl & V4L2_FBUF_FLAG_OVERLAY)
- s += "\t\t\tOverlay Matches Capture/Output Size\n";
- if (fl & V4L2_FBUF_FLAG_CHROMAKEY)
- s += "\t\t\tChromakey\n";
- if (fl & V4L2_FBUF_FLAG_GLOBAL_ALPHA)
- s += "\t\t\tGlobal Alpha\n";
- if (fl & V4L2_FBUF_FLAG_LOCAL_ALPHA)
- s += "\t\t\tLocal Alpha\n";
- if (fl & V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)
- s += "\t\t\tLocal Inverted Alpha\n";
- if (s.empty()) s += "\t\t\t\n";
- return s;
- }
- static void printfbuf(const struct v4l2_framebuffer &fb)
- {
- int is_ext = fb.capability & V4L2_FBUF_CAP_EXTERNOVERLAY;
- printf("Framebuffer Format:\n");
- printf("\tCapability : %s", fbufcap2s(fb.capability).c_str() + 3);
- printf("\tFlags : %s", fbufflags2s(fb.flags).c_str() + 3);
- if (fb.base)
- printf("\tBase : 0x%p\n", fb.base);
- printf("\tWidth : %d\n", fb.fmt.width);
- printf("\tHeight : %d\n", fb.fmt.height);
- printf("\tPixel Format : '%s'\n", fcc2s(fb.fmt.pixelformat).c_str());
- if (!is_ext) {
- printf("\tBytes per Line: %d\n", fb.fmt.bytesperline);
- printf("\tSize image : %d\n", fb.fmt.sizeimage);
- printf("\tColorspace : %s\n", colorspace2s(fb.fmt.colorspace).c_str());
- if (fb.fmt.priv)
- printf("\tCustom Info : %08x\n", fb.fmt.priv);
- }
- }
- static std::string markers2s(unsigned markers)
- {
- std::string s;
- if (markers & V4L2_JPEG_MARKER_DHT)
- s += "\t\tDefine Huffman Tables\n";
- if (markers & V4L2_JPEG_MARKER_DQT)
- s += "\t\tDefine Quantization Tables\n";
- if (markers & V4L2_JPEG_MARKER_DRI)
- s += "\t\tDefine Restart Interval\n";
- if (markers & V4L2_JPEG_MARKER_COM)
- s += "\t\tDefine Comment\n";
- if (markers & V4L2_JPEG_MARKER_APP)
- s += "\t\tDefine APP segment\n";
- return s;
- }
- static void printjpegcomp(const struct v4l2_jpegcompression &jc)
- {
- printf("JPEG compression:\n");
- printf("\tQuality: %d\n", jc.quality);
- if (jc.COM_len)
- printf("\tComment: '%s'\n", jc.COM_data);
- if (jc.APP_len)
- printf("\tAPP%x : '%s'\n", jc.APPn, jc.APP_data);
- printf("\tMarkers: 0x%08x\n", jc.jpeg_markers);
- printf("%s", markers2s(jc.jpeg_markers).c_str());
- }
- static void printcrop(const struct v4l2_crop &crop)
- {
- printf("Crop: Left %d, Top %d, Width %d, Height %d\n",
- crop.c.left, crop.c.top, crop.c.width, crop.c.height);
- }
- static void printcropcap(const struct v4l2_cropcap &cropcap)
- {
- printf("Crop Capability %s:\n", buftype2s(cropcap.type).c_str());
- printf("\tBounds : Left %d, Top %d, Width %d, Height %d\n",
- cropcap.bounds.left, cropcap.bounds.top, cropcap.bounds.width, cropcap.bounds.height);
- printf("\tDefault : Left %d, Top %d, Width %d, Height %d\n",
- cropcap.defrect.left, cropcap.defrect.top, cropcap.defrect.width, cropcap.defrect.height);
- printf("\tPixel Aspect: %u/%u\n", cropcap.pixelaspect.numerator, cropcap.pixelaspect.denominator);
- }
- static void printfmt(const struct v4l2_format &vfmt)
- {
- const flag_def vbi_def[] = {
- { V4L2_VBI_UNSYNC, "unsynchronized" },
- { V4L2_VBI_INTERLACED, "interlaced" },
- { 0, NULL }
- };
- printf("Format %s:\n", buftype2s(vfmt.type).c_str());
- switch (vfmt.type) {
- case V4L2_BUF_TYPE_VIDEO_CAPTURE:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT:
- printf("\tWidth/Height : %u/%u\n", vfmt.fmt.pix.width, vfmt.fmt.pix.height);
- printf("\tPixel Format : '%s'\n", fcc2s(vfmt.fmt.pix.pixelformat).c_str());
- printf("\tField : %s\n", field2s(vfmt.fmt.pix.field).c_str());
- printf("\tBytes per Line: %u\n", vfmt.fmt.pix.bytesperline);
- printf("\tSize Image : %u\n", vfmt.fmt.pix.sizeimage);
- printf("\tColorspace : %s\n", colorspace2s(vfmt.fmt.pix.colorspace).c_str());
- if (vfmt.fmt.pix.priv)
- printf("\tCustom Info : %08x\n", vfmt.fmt.pix.priv);
- break;
- case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
- printf("\tWidth/Height : %u/%u\n", vfmt.fmt.pix_mp.width, vfmt.fmt.pix_mp.height);
- printf("\tPixel Format : '%s'\n", fcc2s(vfmt.fmt.pix_mp.pixelformat).c_str());
- printf("\tField : %s\n", field2s(vfmt.fmt.pix_mp.field).c_str());
- printf("\tNumber of planes : %u\n", vfmt.fmt.pix_mp.num_planes);
- printf("\tColorspace : %s\n", colorspace2s(vfmt.fmt.pix_mp.colorspace).c_str());
- for (int i = 0; i < vfmt.fmt.pix_mp.num_planes; i++) {
- printf("\tPlane %d :\n", i);
- printf("\t Bytes per Line : %u\n", vfmt.fmt.pix_mp.plane_fmt[i].bytesperline);
- printf("\t Size Image : %u\n", vfmt.fmt.pix_mp.plane_fmt[i].sizeimage);
- if (i >= VIDEO_MAX_PLANES)
- break;
- }
- break;
- case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
- case V4L2_BUF_TYPE_VIDEO_OVERLAY:
- printf("\tLeft/Top : %d/%d\n",
- vfmt.fmt.win.w.left, vfmt.fmt.win.w.top);
- printf("\tWidth/Height: %d/%d\n",
- vfmt.fmt.win.w.width, vfmt.fmt.win.w.height);
- printf("\tField : %s\n", field2s(vfmt.fmt.win.field).c_str());
- printf("\tChroma Key : 0x%08x\n", vfmt.fmt.win.chromakey);
- printf("\tGlobal Alpha: 0x%02x\n", vfmt.fmt.win.global_alpha);
- printf("\tClip Count : %u\n", vfmt.fmt.win.clipcount);
- printf("\tClip Bitmap : %s\n", vfmt.fmt.win.bitmap ? "Yes" : "No");
- break;
- case V4L2_BUF_TYPE_VBI_CAPTURE:
- case V4L2_BUF_TYPE_VBI_OUTPUT:
- printf("\tSampling Rate : %u Hz\n", vfmt.fmt.vbi.sampling_rate);
- printf("\tOffset : %u samples (%g secs after leading edge)\n",
- vfmt.fmt.vbi.offset,
- (double)vfmt.fmt.vbi.offset / (double)vfmt.fmt.vbi.sampling_rate);
- printf("\tSamples per Line: %u\n", vfmt.fmt.vbi.samples_per_line);
- printf("\tSample Format : %s\n", fcc2s(vfmt.fmt.vbi.sample_format).c_str());
- printf("\tStart 1st Field : %u\n", vfmt.fmt.vbi.start[0]);
- printf("\tCount 1st Field : %u\n", vfmt.fmt.vbi.count[0]);
- printf("\tStart 2nd Field : %u\n", vfmt.fmt.vbi.start[1]);
- printf("\tCount 2nd Field : %u\n", vfmt.fmt.vbi.count[1]);
- if (vfmt.fmt.vbi.flags)
- printf("\tFlags : %s\n", flags2s(vfmt.fmt.vbi.flags, vbi_def).c_str());
- break;
- case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
- case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
- printf("\tService Set : %s\n",
- flags2s(vfmt.fmt.sliced.service_set, service_def).c_str());
- for (int i = 0; i < 24; i++) {
- printf("\tService Line %2d: %8s / %-8s\n", i,
- flags2s(vfmt.fmt.sliced.service_lines[0][i], service_def).c_str(),
- flags2s(vfmt.fmt.sliced.service_lines[1][i], service_def).c_str());
- }
- printf("\tI/O Size : %u\n", vfmt.fmt.sliced.io_size);
- break;
- case V4L2_BUF_TYPE_PRIVATE:
- break;
- }
- }
- static std::string frmtype2s(unsigned type)
- {
- static const char *types[] = {
- "Unknown",
- "Discrete",
- "Continuous",
- "Stepwise"
- };
- if (type > 3)
- type = 0;
- return types[type];
- }
- static std::string fract2sec(const struct v4l2_fract &f)
- {
- char buf[100];
- sprintf(buf, "%.3f s", (1.0 * f.numerator) / f.denominator);
- return buf;
- }
- static std::string fract2fps(const struct v4l2_fract &f)
- {
- char buf[100];
- sprintf(buf, "%.3f fps", (1.0 * f.denominator) / f.numerator);
- return buf;
- }
- static void print_frmsize(const struct v4l2_frmsizeenum &frmsize, const char *prefix)
- {
- printf("%s\tSize: %s ", prefix, frmtype2s(frmsize.type).c_str());
- if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
- printf("%dx%d", frmsize.discrete.width, frmsize.discrete.height);
- } else if (frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
- printf("%dx%d - %dx%d with step %d/%d",
- frmsize.stepwise.min_width,
- frmsize.stepwise.min_height,
- frmsize.stepwise.max_width,
- frmsize.stepwise.max_height,
- frmsize.stepwise.step_width,
- frmsize.stepwise.step_height);
- }
- printf("\n");
- }
- static void print_frmival(const struct v4l2_frmivalenum &frmival, const char *prefix)
- {
- printf("%s\tInterval: %s ", prefix, frmtype2s(frmival.type).c_str());
- if (frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
- printf("%s (%s)\n", fract2sec(frmival.discrete).c_str(),
- fract2fps(frmival.discrete).c_str());
- } else if (frmival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
- printf("%s - %s with step %s\n",
- fract2sec(frmival.stepwise.min).c_str(),
- fract2sec(frmival.stepwise.max).c_str(),
- fract2sec(frmival.stepwise.step).c_str());
- printf("%s\t : ", prefix);
- printf("(%s - %s with step %s)\n",
- fract2fps(frmival.stepwise.min).c_str(),
- fract2fps(frmival.stepwise.max).c_str(),
- fract2fps(frmival.stepwise.step).c_str());
- }
- }
- static const flag_def fmtdesc_def[] = {
- { V4L2_FMT_FLAG_COMPRESSED, "compressed" },
- { V4L2_FMT_FLAG_EMULATED, "emulated" },
- { 0, NULL }
- };
- static void print_video_formats(int fd, enum v4l2_buf_type type)
- {
- struct v4l2_fmtdesc fmt;
- memset(&fmt, 0, sizeof(fmt));
- fmt.type = type;
- while (test_ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) {
- printf("\tIndex : %d\n", fmt.index);
- printf("\tType : %s\n", buftype2s(type).c_str());
- printf("\tPixel Format: '%s'", fcc2s(fmt.pixelformat).c_str());
- if (fmt.flags)
- printf(" (%s)", flags2s(fmt.flags, fmtdesc_def).c_str());
- printf("\n");
- printf("\tName : %s\n", fmt.description);
- printf("\n");
- fmt.index++;
- }
- }
- static void print_video_formats_ext(int fd, enum v4l2_buf_type type)
- {
- struct v4l2_fmtdesc fmt;
- struct v4l2_frmsizeenum frmsize;
- struct v4l2_frmivalenum frmival;
- fmt.index = 0;
- fmt.type = type;
- while (test_ioctl(fd, VIDIOC_ENUM_FMT, &fmt) >= 0) {
- printf("\tIndex : %d\n", fmt.index);
- printf("\tType : %s\n", buftype2s(type).c_str());
- printf("\tPixel Format: '%s'", fcc2s(fmt.pixelformat).c_str());
- if (fmt.flags)
- printf(" (%s)", flags2s(fmt.flags, fmtdesc_def).c_str());
- printf("\n");
- printf("\tName : %s\n", fmt.description);
- frmsize.pixel_format = fmt.pixelformat;
- frmsize.index = 0;
- while (test_ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0) {
- print_frmsize(frmsize, "\t");
- if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
- frmival.index = 0;
- frmival.pixel_format = fmt.pixelformat;
- frmival.width = frmsize.discrete.width;
- frmival.height = frmsize.discrete.height;
- while (test_ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) >= 0) {
- print_frmival(frmival, "\t\t");
- frmival.index++;
- }
- }
- frmsize.index++;
- }
- printf("\n");
- fmt.index++;
- }
- }
- static const char *audmode2s(int audmode)
- {
- switch (audmode) {
- case V4L2_TUNER_MODE_STEREO: return "stereo";
- case V4L2_TUNER_MODE_LANG1: return "lang1";
- case V4L2_TUNER_MODE_LANG2: return "lang2";
- case V4L2…