summaryrefslogtreecommitdiff
path: root/v4l2-apps
diff options
context:
space:
mode:
authorJean-Francois Moine <moinejf@free.fr>2008-06-09 11:55:06 +0200
committerJean-Francois Moine <moinejf@free.fr>2008-06-09 11:55:06 +0200
commita76f49b7ffe277c032fab5226bc092da0b324799 (patch)
tree47dcbd1db7c6c3f9493092a643c9ee5cfb578def /v4l2-apps
parent80fb482585b549df0669ef539d101369fae7a40a (diff)
parent18e4796addabb3886c9346e035ee30bb96bbcd74 (diff)
downloadmediapointer-dvb-s2-a76f49b7ffe277c032fab5226bc092da0b324799.tar.gz
mediapointer-dvb-s2-a76f49b7ffe277c032fab5226bc092da0b324799.tar.bz2
From: Jean-Francois Moine <moinejf@free.fr>
Update from main repository. Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
Diffstat (limited to 'v4l2-apps')
-rw-r--r--v4l2-apps/util/Makefile11
-rw-r--r--v4l2-apps/util/cx18-ctl.c496
-rw-r--r--v4l2-apps/util/ivtv-ctl.c687
-rw-r--r--v4l2-apps/util/v4l2-ctl.cpp111
-rw-r--r--v4l2-apps/util/v4l2-dbg.cpp3
5 files changed, 1235 insertions, 73 deletions
diff --git a/v4l2-apps/util/Makefile b/v4l2-apps/util/Makefile
index 34fc9a103..cc0547c32 100644
--- a/v4l2-apps/util/Makefile
+++ b/v4l2-apps/util/Makefile
@@ -1,8 +1,13 @@
# Makefile for linuxtv.org v4l2-apps/util
-CPPFLAGS += -I../../linux/include
+CPPFLAGS += -I../../linux/include -D_GNU_SOURCE
+LDFLAGS += -lm
-binaries = v4l2-ctl v4l2-dbg
+binaries = v4l2-ctl v4l2-dbg ivtv-ctl cx18-ctl
+
+ifeq ($(prefix),)
+prefix = /usr
+endif
.PHONY: all clean install qv4l2
@@ -22,6 +27,8 @@ v4l2-dbg: v4l2-dbg.o v4l2-driverids.o v4l2-chipids.o
$(CXX) $^ -o $@
install:
+ mkdir -p $(prefix)/bin
+ cp $(binaries) $(prefix)/bin
include ../Make.rules
diff --git a/v4l2-apps/util/cx18-ctl.c b/v4l2-apps/util/cx18-ctl.c
new file mode 100644
index 000000000..755b9437f
--- /dev/null
+++ b/v4l2-apps/util/cx18-ctl.c
@@ -0,0 +1,496 @@
+/*
+ Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo dot com>
+
+ Cleanup and VBI and audio in/out options:
+ Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <math.h>
+#include <linux/types.h>
+#include <sys/klog.h>
+
+#include <linux/videodev2.h>
+
+/* copied from cx18-driver.h */
+#define CX18_DBGFLG_WARN (1 << 0)
+#define CX18_DBGFLG_INFO (1 << 1)
+#define CX18_DBGFLG_API (1 << 2)
+#define CX18_DBGFLG_DMA (1 << 3)
+#define CX18_DBGFLG_IOCTL (1 << 4)
+#define CX18_DBGFLG_FILE (1 << 5)
+#define CX18_DBGFLG_I2C (1 << 6)
+#define CX18_DBGFLG_IRQ (1 << 7)
+/* Flag to turn on high volume debugging */
+#define CX18_DBGFLG_HIGHVOL (1 << 8)
+
+/* Internals copied from media/v4l2-common.h */
+struct v4l2_routing {
+ __u32 input;
+ __u32 output;
+};
+#define VIDIOC_INT_S_AUDIO_ROUTING _IOW('d', 109, struct v4l2_routing)
+
+#define VIDIOC_INT_RESET _IOW('d', 102, __u32)
+
+#define __stringify_1(x) #x
+#define __stringify(x) __stringify_1(x)
+
+#include "../../linux/drivers/media/video/cx18/cx18-version.h"
+
+/* GPIO */
+#define CX18_REG_GPIO_IN 0x02c72010
+#define CX18_REG_GPIO_OUT1 0x02c78100
+#define CX18_REG_GPIO_DIR1 0x02c78108
+#define CX18_REG_GPIO_OUT2 0x02c78104
+#define CX18_REG_GPIO_DIR2 0x02c7810c
+
+/* Options */
+enum Option {
+ OptSetDebugLevel = 'D',
+ OptSetDevice = 'd',
+ OptGetDebugLevel = 'e',
+ OptHelp = 'h',
+ OptSetGPIO = 'i',
+ OptListGPIO = 'I',
+ OptSetAudioRoute = 'v',
+ OptReset = 128,
+ OptVersion,
+ OptLast = 256
+};
+
+static char options[OptLast];
+
+static struct option long_options[] = {
+ /* Please keep in alphabetical order of the short option.
+ That makes it easier to see which options are still free. */
+ {"set-debug", required_argument, 0, OptSetDebugLevel},
+ {"device", required_argument, 0, OptSetDevice},
+ {"get-debug", no_argument, 0, OptGetDebugLevel},
+ {"help", no_argument, 0, OptHelp},
+ {"set-gpio", required_argument, 0, OptSetGPIO},
+ {"list-gpio", no_argument, 0, OptListGPIO},
+ {"audio-route", required_argument, 0, OptSetAudioRoute},
+ {"reset", required_argument, 0, OptReset},
+ {"version", no_argument, 0, OptVersion},
+ {0, 0, 0, 0}
+};
+
+static void usage(void)
+{
+ printf("Usage:\n");
+ printf(" -d, --device <dev> use device <dev> instead of /dev/video0\n");
+ printf(" -h, --help display this help message\n");
+ printf(" --reset <mask> reset the infrared receiver (1) or digitizer (2) [VIDIOC_INT_RESET]\n");
+ printf(" --version shows the version number of this utility.\n");
+ printf(" It should match the driver version.\n");
+ printf("\n");
+ printf("Expert options:\n");
+ printf(" -D, --set-debug <level>\n");
+ printf(" set the module debug variable\n");
+ printf(" 1/0x0001: warning\n");
+ printf(" 2/0x0002: info\n");
+ printf(" 4/0x0004: mailbox\n");
+ printf(" 8/0x0008: dma\n");
+ printf(" 16/0x0010: ioctl\n");
+ printf(" 32/0x0020: file\n");
+ printf(" 64/0x0040: i2c\n");
+ printf(" 128/0x0080: irq\n");
+ printf(" 256/0x0100: high volume\n");
+ printf(" -e, --get-debug query the module debug variable\n");
+ printf(" -I, --list-gpio\n");
+ printf(" show GPIO input/direction/output bits\n");
+ printf(" -i, --set-gpio [dir=<dir>,]val=<val>\n");
+ printf(" set GPIO direction bits to <dir> and set output to <val>\n");
+ printf(" -v, --audio-route=input=<in>,output=<out>\n");
+ printf(" set the audio input/output routing [VIDIOC_INT_S_AUDIO_ROUTING]\n");
+ exit(0);
+}
+
+static char *pts_to_string(char *str, unsigned long pts, float fps)
+{
+ static char buf[256];
+ int hours, minutes, seconds, fracsec;
+ int frame;
+ char *p = (str) ? str : buf;
+
+ static const int MPEG_CLOCK_FREQ = 90000;
+ seconds = pts / MPEG_CLOCK_FREQ;
+ fracsec = pts % MPEG_CLOCK_FREQ;
+
+ minutes = seconds / 60;
+ seconds = seconds % 60;
+
+ hours = minutes / 60;
+ minutes = minutes % 60;
+
+ frame = (int)ceilf(((float)fracsec / (float)MPEG_CLOCK_FREQ) * fps);
+
+ snprintf(p, sizeof(buf), "%d:%02d:%02d:%d", hours, minutes, seconds, frame);
+ return p;
+}
+
+static void print_debug_mask(int mask)
+{
+#define MASK_OR_NOTHING (mask ? " | " : "")
+ if (mask & CX18_DBGFLG_WARN) {
+ mask &= ~CX18_DBGFLG_WARN;
+ printf("CX18_DBGFLG_WARN%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_INFO) {
+ mask &= ~CX18_DBGFLG_INFO;
+ printf("CX18_DBGFLG_INFO%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_API) {
+ mask &= ~CX18_DBGFLG_API;
+ printf("CX18_DBGFLG_API%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_DMA) {
+ mask &= ~CX18_DBGFLG_DMA;
+ printf("CX18_DBGFLG_DMA%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_IOCTL) {
+ mask &= ~CX18_DBGFLG_IOCTL;
+ printf("CX18_DBGFLG_IOCTL%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_FILE) {
+ mask &= ~CX18_DBGFLG_FILE;
+ printf("CX18_DBGFLG_FILE%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_I2C) {
+ mask &= ~CX18_DBGFLG_I2C;
+ printf("CX18_DBGFLG_I2C%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_IRQ) {
+ mask &= ~CX18_DBGFLG_IRQ;
+ printf("CX18_DBGFLG_IRQ%s", MASK_OR_NOTHING);
+ }
+ if (mask & CX18_DBGFLG_HIGHVOL) {
+ mask &= ~CX18_DBGFLG_HIGHVOL;
+ printf("CX18_DBGFLG_HIGHVOL%s", MASK_OR_NOTHING);
+ }
+ if (mask)
+ printf("0x%08x", mask);
+ printf("\n");
+}
+
+static int dowrite(const char *buf, const char *fn)
+{
+ FILE *f = fopen(fn, "w");
+ if (f == NULL) {
+ printf("failed: %s\n", strerror(errno));
+ return errno;
+ }
+ fprintf(f, buf);
+ fclose(f);
+ return 0;
+}
+
+static char *doread(const char *fn)
+{
+ static char buf[1000];
+ FILE *f = fopen(fn, "r");
+ int s;
+
+ if (f == NULL) {
+ printf("failed: %s\n", strerror(errno));
+ return NULL;
+ }
+ s = fread(buf, 1, sizeof(buf) - 1, f);
+ buf[s] = 0;
+ fclose(f);
+ return buf;
+}
+
+static int doioctl(int fd, int request, void *parm, const char *name)
+{
+ int retVal;
+
+ printf("ioctl %s ", name);
+ retVal = ioctl(fd, request, parm);
+ if (retVal < 0)
+ printf("failed: %s\n", strerror(errno));
+ else
+ printf("ok\n");
+
+ return retVal;
+}
+
+int main(int argc, char **argv)
+{
+ char *value, *subs;
+ int i;
+ char *subopts[] = {
+#define SUB_VAL 0
+ "val",
+#define SUB_YUV_MODE 1
+ "mode",
+#define SUB_DIR 2
+ "dir",
+#define SUB_INPUT 3
+ "input",
+#define SUB_OUTPUT 4
+ "output",
+
+ NULL
+ };
+
+ int fd = -1;
+
+ /* bitfield for OptSetCodec */
+
+ /* command args */
+ char *device = strdup("/dev/video0"); /* -d device */
+ int ch;
+ int yuv_mode = 0;
+ struct v4l2_routing route; /* audio_route */
+ unsigned int gpio_out = 0x0; /* GPIO output data */
+ unsigned int gpio_dir = 0x0; /* GPIO direction bits */
+ int gpio_set_dir = 0;
+ int debug_level = 0;
+ __u32 reset = 0;
+ int new_debug_level, gdebug_level;
+ double timestamp;
+ char ptsstr[64];
+ char short_options[26 * 2 * 2 + 1];
+
+ if (argc == 1) {
+ usage();
+ return 0;
+ }
+ while (1) {
+ int option_index = 0;
+ int idx = 0;
+
+ for (i = 0; long_options[i].name; i++) {
+ if (!isalpha(long_options[i].val))
+ continue;
+ short_options[idx++] = long_options[i].val;
+ if (long_options[i].has_arg == required_argument)
+ short_options[idx++] = ':';
+ }
+ short_options[idx] = 0;
+ ch = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (ch == -1)
+ break;
+
+ options[(int)ch] = 1;
+ switch (ch) {
+ case OptHelp:
+ usage();
+ return 0;
+ case OptSetDebugLevel:{
+ debug_level = strtol(optarg, 0L, 0);
+ break;
+ }
+ case OptSetDevice:
+ device = strdup(optarg);
+ if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) {
+ char dev = device[0];
+
+ sprintf(device, "/dev/video%c", dev);
+ }
+ break;
+ case OptSetAudioRoute:
+ subs = optarg;
+ while (*subs != '\0') {
+ switch (getsubopt(&subs, subopts, &value)) {
+ case SUB_INPUT:
+ if (value == NULL) {
+ printf
+ ("No value given to suboption <input>\n");
+ usage();
+ }
+ route.input = strtol(value, 0L, 0);
+ break;
+ case SUB_OUTPUT:
+ if (value == NULL) {
+ printf
+ ("No value given to suboption <output>\n");
+ usage();
+ }
+ route.output = strtol(value, 0L, 0);
+ break;
+ default:
+ printf
+ ("Invalid suboptions specified\n");
+ usage();
+ break;
+ }
+ }
+ break;
+ case OptReset:
+ reset = strtol(optarg, 0L, 0);
+ break;
+ case OptSetGPIO:
+ subs = optarg;
+ while (*subs != '\0') {
+ switch (getsubopt(&subs, subopts, &value)) {
+ case SUB_DIR:
+ if (value == NULL) {
+ fprintf(stderr,
+ "No value given to suboption <dir>\n");
+ usage();
+ exit(1);
+ }
+ gpio_dir = strtoul(value, 0L, 0);
+ gpio_set_dir = 1;
+ break;
+ case SUB_VAL:
+ if (value == NULL) {
+ fprintf(stderr,
+ "No value given to suboption <val>\n");
+ usage();
+ exit(1);
+ }
+ gpio_out =
+ (unsigned short)strtoul(value, 0L, 0);
+ break;
+ default:
+ fprintf(stderr,
+ "Invalid suboptions specified\n");
+ usage();
+ exit(1);
+ break;
+ }
+ }
+ break;
+ case ':':
+ fprintf(stderr, "Option `%s' requires a value\n",
+ argv[optind]);
+ usage();
+ return 1;
+ case '?':
+ fprintf(stderr, "Unknown argument `%s'\n",
+ argv[optind]);
+ usage();
+ return 1;
+ }
+ }
+ if (optind < argc) {
+ printf("unknown arguments: ");
+ while (optind < argc)
+ printf("%s ", argv[optind++]);
+ printf("\n");
+ usage();
+ return 1;
+ }
+
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n", device,
+ strerror(errno));
+ exit(1);
+ }
+ free(device);
+
+ /* Setting Opts */
+
+ if (options[OptSetAudioRoute])
+ doioctl(fd, VIDIOC_INT_S_AUDIO_ROUTING, &route, "VIDIOC_INT_S_AUDIO_ROUTING");
+
+ if (options[OptSetGPIO]) {
+ struct v4l2_register reg;
+
+ reg.match_type = V4L2_CHIP_MATCH_HOST;
+ reg.match_chip = 0;
+ reg.reg = CX18_REG_GPIO_DIR1;
+ reg.val = (unsigned)((gpio_dir & 0xffff) << 16);
+ if (gpio_set_dir && doioctl(fd, VIDIOC_DBG_S_REGISTER, &reg,
+ "VIDIOC_DBG_S_REGISTER") == 0)
+ printf("GPIO dir 1 set to 0x%08llx\n", reg.val);
+ reg.reg = CX18_REG_GPIO_DIR2;
+ reg.val = (unsigned)(gpio_dir & 0xffff0000);
+ if (gpio_set_dir && doioctl(fd, VIDIOC_DBG_S_REGISTER, &reg,
+ "VIDIOC_DBG_S_REGISTER") == 0)
+ printf("GPIO dir 2 set to 0x%08llx\n", reg.val);
+ reg.reg = CX18_REG_GPIO_OUT1;
+ reg.val = (unsigned)((gpio_dir & 0xffff) << 16) | (gpio_out & 0xffff);
+ if (doioctl(fd, VIDIOC_DBG_S_REGISTER, &reg,
+ "VIDIOC_DBG_S_REGISTER") == 0)
+ printf("GPIO out 1 set to 0x%08llx\n", reg.val);
+ reg.reg = CX18_REG_GPIO_OUT2;
+ reg.val = (unsigned)(gpio_dir & 0xffff0000) | (gpio_out >> 16);
+ if (doioctl(fd, VIDIOC_DBG_S_REGISTER, &reg,
+ "VIDIOC_DBG_S_REGISTER") == 0)
+ printf("GPIO out 2 set to 0x%08llx\n", reg.val);
+ }
+
+ if (options[OptListGPIO]) {
+ struct v4l2_register reg;
+
+ reg.match_type = V4L2_CHIP_MATCH_HOST;
+ reg.match_chip = 0;
+ reg.reg = CX18_REG_GPIO_IN;
+ if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &reg) == 0)
+ printf("GPIO in: 0x%04llx\n", reg.val);
+ reg.reg = CX18_REG_GPIO_DIR1;
+ if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &reg) == 0)
+ printf("GPIO dir: 0x%04llx\n", reg.val);
+ reg.reg = CX18_REG_GPIO_OUT1;
+ if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &reg) == 0)
+ printf("GPIO out: 0x%04llx\n", reg.val);
+ }
+
+ if (options[OptSetDebugLevel]) {
+ char buf[20];
+ new_debug_level = debug_level;
+
+ sprintf(buf, "%d", debug_level);
+ if (dowrite(buf, "/sys/module/cx18/parameters/debug") == 0) {
+ printf(" set debug level: ");
+ print_debug_mask(new_debug_level);
+ printf("\n");
+ }
+ }
+
+ if (options[OptGetDebugLevel]) {
+ char *buf;
+
+ gdebug_level = 0;
+ buf = doread("/sys/module/cx18/parameters/debug");
+ if (buf) {
+ gdebug_level = atol(buf);
+ printf(" debug level: ");
+ print_debug_mask(gdebug_level);
+ printf("\n");
+ }
+ }
+
+ if (options[OptReset])
+ doioctl(fd, VIDIOC_INT_RESET, &reset, "VIDIOC_INT_RESET");
+
+ if (options[OptVersion])
+ printf("cx18ctl version " CX18_VERSION "\n");
+
+ close(fd);
+ exit(0);
+}
diff --git a/v4l2-apps/util/ivtv-ctl.c b/v4l2-apps/util/ivtv-ctl.c
new file mode 100644
index 000000000..9d3170785
--- /dev/null
+++ b/v4l2-apps/util/ivtv-ctl.c
@@ -0,0 +1,687 @@
+/*
+ Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo dot com>
+
+ Cleanup and VBI and audio in/out options:
+ Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <math.h>
+#include <linux/types.h>
+#include <sys/klog.h>
+
+#include <linux/videodev2.h>
+#include <linux/dvb/video.h>
+#include <linux/dvb/audio.h>
+
+/* copied from ivtv-driver.h */
+#define IVTV_DBGFLG_WARN (1 << 0)
+#define IVTV_DBGFLG_INFO (1 << 1)
+#define IVTV_DBGFLG_MB (1 << 2)
+#define IVTV_DBGFLG_IOCTL (1 << 3)
+#define IVTV_DBGFLG_FILE (1 << 4)
+#define IVTV_DBGFLG_DMA (1 << 5)
+#define IVTV_DBGFLG_IRQ (1 << 6)
+#define IVTV_DBGFLG_DEC (1 << 7)
+#define IVTV_DBGFLG_YUV (1 << 8)
+#define IVTV_DBGFLG_I2C (1 << 9)
+/* Flag to turn on high volume debugging */
+#define IVTV_DBGFLG_HIGHVOL (1 << 10)
+
+/* Internals copied from media/v4l2-common.h */
+struct v4l2_routing {
+ __u32 input;
+ __u32 output;
+};
+#define VIDIOC_INT_S_AUDIO_ROUTING _IOW('d', 109, struct v4l2_routing)
+
+#define VIDIOC_INT_RESET _IOW('d', 102, __u32)
+
+#include <linux/ivtv.h>
+
+/* GPIO */
+#define IVTV_REG_GPIO_IN_OFFSET (0x9008 + 0x02000000)
+#define IVTV_REG_GPIO_OUT_OFFSET (0x900c + 0x02000000)
+#define IVTV_REG_GPIO_DIR_OFFSET (0x9020 + 0x02000000)
+
+/* Options */
+enum Option {
+ OptSetDebugLevel = 'D',
+ OptSetDevice = 'd',
+ OptGetDebugLevel = 'e',
+ OptHelp = 'h',
+ OptSetGPIO = 'i',
+ OptListGPIO = 'I',
+ OptPassThrough = 'K',
+ OptFrameSync = 'k',
+ OptSetAudioRoute = 'v',
+ OptReset = 128,
+ OptSetYuvMode,
+ OptGetYuvMode,
+ OptSetAudioMute,
+ OptSetStereoMode,
+ OptSetBilingualMode,
+ OptLast = 256
+};
+
+static char options[OptLast];
+
+static int app_result;
+
+static struct option long_options[] = {
+ /* Please keep in alphabetical order of the short option.
+ That makes it easier to see which options are still free. */
+ {"set-debug", required_argument, 0, OptSetDebugLevel},
+ {"device", required_argument, 0, OptSetDevice},
+ {"get-debug", no_argument, 0, OptGetDebugLevel},
+ {"help", no_argument, 0, OptHelp},
+ {"set-gpio", required_argument, 0, OptSetGPIO},
+ {"list-gpio", no_argument, 0, OptListGPIO},
+ {"passthrough", required_argument, 0, OptPassThrough},
+ {"sync", no_argument, 0, OptFrameSync},
+ {"audio-route", required_argument, 0, OptSetAudioRoute},
+ {"reset", required_argument, 0, OptReset},
+ {"get-yuv-mode", no_argument, 0, OptGetYuvMode},
+ {"set-yuv-mode", required_argument, 0, OptSetYuvMode},
+ {"set-audio-mute", required_argument, 0, OptSetAudioMute},
+ {"set-stereo-mode", required_argument, 0, OptSetStereoMode},
+ {"set-bilingual-mode", required_argument, 0, OptSetBilingualMode},
+ {0, 0, 0, 0}
+};
+
+static void usage(void)
+{
+ printf("Usage:\n");
+ printf(" -d, --device <dev> use device <dev> instead of /dev/video0\n");
+ printf(" -h, --help display this help message\n");
+ printf(" -K, --passthrough <mode>\n");
+ printf(" set passthrough mode: 1 = on, 0 = off [IVTV_IOC_PASSTHROUGH]\n");
+ printf(" --get-yuv-mode display the current yuv mode\n");
+ printf(" --set-yuv-mode mode=<mode>\n");
+ printf(" set the current yuv mode:\n");
+ printf(" mode 0: interlaced (top transmitted first)\n");
+ printf(" mode 1: interlaced (bottom transmitted first)\n");
+ printf(" mode 2: progressive\n");
+ printf(" mode 3: auto\n");
+ printf(" --set-audio-mute <mute>\n");
+ printf(" 0=enable audio during 1.5x and 0.5x playback\n");
+ printf(" 1=mute audio during 1.5x and 0.5x playback\n");
+ printf(" --set-stereo-mode <mode>\n");
+ printf(" mode 0: playback stereo as stereo\n");
+ printf(" mode 1: playback left stereo channel as mono\n");
+ printf(" mode 2: playback right stereo channel as mono\n");
+ printf(" mode 3: playback stereo as mono\n");
+ printf(" mode 4: playback stereo as swapped stereo\n");
+ printf(" --set-bilingual-mode <mode>\n");
+ printf(" mode 0: playback bilingual as stereo\n");
+ printf(" mode 1: playback left bilingual channel as mono\n");
+ printf(" mode 2: playback right bilingual channel as mono\n");
+ printf(" mode 3: playback bilingual as mono\n");
+ printf(" mode 4: playback bilingual as swapped stereo\n");
+ printf(" --reset <mask> reset the infrared receiver (1) or digitizer (2) [VIDIOC_INT_RESET]\n");
+ printf("\n");
+ printf("Expert options:\n");
+ printf(" -D, --set-debug <level>\n");
+ printf(" set the module debug variable\n");
+ printf(" 1/0x0001: warning\n");
+ printf(" 2/0x0002: info\n");
+ printf(" 4/0x0004: mailbox\n");
+ printf(" 8/0x0008: ioctl\n");
+ printf(" 16/0x0010: file\n");
+ printf(" 32/0x0020: dma\n");
+ printf(" 64/0x0040: irq\n");
+ printf(" 128/0x0080: decoder\n");
+ printf(" 256/0x0100: yuv\n");
+ printf(" 512/0x0200: i2c\n");
+ printf(" 1024/0x0400: high volume\n");
+ printf(" -e, --get-debug query the module debug variable\n");
+ printf(" -I, --list-gpio\n");
+ printf(" show GPIO input/direction/output bits\n");
+ printf(" -i, --set-gpio [dir=<dir>,]val=<val>\n");
+ printf(" set GPIO direction bits to <dir> and set output to <val>\n");
+ printf(" -k, --sync test vsync's capabilities [VIDEO_GET_EVENT]\n");
+ printf(" -v, --audio-route=input=<in>,output=<out>\n");
+ printf(" set the audio input/output routing [VIDIOC_INT_S_AUDIO_ROUTING]\n");
+ exit(0);
+}
+
+static char *pts_to_string(char *str, unsigned long pts, float fps)
+{
+ static char buf[256];
+ int hours, minutes, seconds, fracsec;
+ int frame;
+ char *p = (str) ? str : buf;
+
+ static const int MPEG_CLOCK_FREQ = 90000;
+ seconds = pts / MPEG_CLOCK_FREQ;
+ fracsec = pts % MPEG_CLOCK_FREQ;
+
+ minutes = seconds / 60;
+ seconds = seconds % 60;
+
+ hours = minutes / 60;
+ minutes = minutes % 60;
+
+ frame = (int)ceilf(((float)fracsec / (float)MPEG_CLOCK_FREQ) * fps);
+
+ snprintf(p, sizeof(buf), "%d:%02d:%02d:%d", hours, minutes, seconds, frame);
+ return p;
+}
+
+static void print_debug_mask(int mask)
+{
+#define MASK_OR_NOTHING (mask ? " | " : "")
+ if (mask & IVTV_DBGFLG_WARN) {
+ mask &= ~IVTV_DBGFLG_WARN;
+ printf("IVTV_DBGFLG_WARN%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_INFO) {
+ mask &= ~IVTV_DBGFLG_INFO;
+ printf("IVTV_DBGFLG_INFO%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_MB) {
+ mask &= ~IVTV_DBGFLG_MB;
+ printf("IVTV_DBGFLG_MB%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_DMA) {
+ mask &= ~IVTV_DBGFLG_DMA;
+ printf("IVTV_DBGFLG_DMA%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_IOCTL) {
+ mask &= ~IVTV_DBGFLG_IOCTL;
+ printf("IVTV_DBGFLG_IOCTL%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_FILE) {
+ mask &= ~IVTV_DBGFLG_FILE;
+ printf("IVTV_DBGFLG_FILE%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_I2C) {
+ mask &= ~IVTV_DBGFLG_I2C;
+ printf("IVTV_DBGFLG_I2C%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_IRQ) {
+ mask &= ~IVTV_DBGFLG_IRQ;
+ printf("IVTV_DBGFLG_IRQ%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_DEC) {
+ mask &= ~IVTV_DBGFLG_DEC;
+ printf("IVTV_DBGFLG_DEC%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_YUV) {
+ mask &= ~IVTV_DBGFLG_YUV;
+ printf("IVTV_DBGFLG_YUV%s", MASK_OR_NOTHING);
+ }
+ if (mask & IVTV_DBGFLG_HIGHVOL) {
+ mask &= ~IVTV_DBGFLG_HIGHVOL;
+ printf("IVTV_DBGFLG_HIGHVOL%s", MASK_OR_NOTHING);
+ }
+ if (mask)
+ printf("0x%08x", mask);
+ printf("\n");
+}
+
+static int dowrite(const char *buf, const char *fn)
+{
+ FILE *f = fopen(fn, "w");
+ if (f == NULL) {
+ printf("failed: %s\n", strerror(errno));
+ return errno;
+ }
+ fprintf(f, buf);
+ fclose(f);
+ return 0;
+}
+
+static char *doread(const char *fn)
+{
+ static char buf[1000];
+ FILE *f = fopen(fn, "r");
+ int s;
+
+ if (f == NULL) {
+ printf("failed: %s\n", strerror(errno));
+ return NULL;
+ }
+ s = fread(buf, 1, sizeof(buf) - 1, f);
+ buf[s] = 0;
+ fclose(f);
+ return buf;
+}
+
+static const char *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";
+ }
+}
+
+static int doioctl(int fd, int request, void *parm, const char *name)
+{
+ int retVal;
+
+ printf("ioctl %s ", name);
+ retVal = ioctl(fd, request, parm);
+ if (retVal < 0) {
+ app_result = -1;
+ printf("failed: %s\n", strerror(errno));
+ }
+ else
+ printf("ok\n");
+
+ return retVal;
+}
+
+int main(int argc, char **argv)
+{
+ char *value, *subs;
+ int i;
+ char *subopts[] = {
+#define SUB_VAL 0
+ "val",
+#define SUB_YUV_MODE 1
+ "mode",
+#define SUB_DIR 2
+ "dir",
+#define SUB_INPUT 3
+ "input",
+#define SUB_OUTPUT 4
+ "output",
+
+ NULL
+ };
+
+ int fd = -1;
+
+ /* bitfield for OptSetCodec */
+
+ /* command args */
+ char *device = strdup("/dev/video0"); /* -d device */
+ int ch;
+ int yuv_mode = 0;
+ struct v4l2_routing route; /* audio_route */
+ unsigned short gpio_out = 0x0; /* GPIO output data */
+ unsigned short gpio_dir = 0x0; /* GPIO direction bits */
+ int gpio_set_dir = 0;
+ int passthrough = 0;
+ int audio_mute = 0;
+ int stereo_mode = 0;
+ int bilingual_mode = 0;
+ int debug_level = 0;
+ __u32 reset = 0;
+ int new_debug_level, gdebug_level;
+ double timestamp;
+ char ptsstr[64];
+ char short_options[26 * 2 * 2 + 1];
+
+ if (argc == 1) {
+ usage();
+ return 0;
+ }
+ while (1) {
+ int option_index = 0;
+ int idx = 0;
+
+ for (i = 0; long_options[i].name; i++) {
+ if (!isalpha(long_options[i].val))
+ continue;
+ short_options[idx++] = long_options[i].val;
+ if (long_options[i].has_arg == required_argument)
+ short_options[idx++] = ':';
+ }
+ short_options[idx] = 0;
+ ch = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (ch == -1)
+ break;
+
+ options[(int)ch] = 1;
+ switch (ch) {
+ case OptSetYuvMode:
+ {
+ subs = optarg;
+ while (*subs != '\0') {
+ switch (getsubopt(&subs, subopts, &value)) {
+ case SUB_YUV_MODE:
+ if (value == NULL) {
+ fprintf(stderr,
+ "No value given to suboption <mode>\n");
+ usage();
+ return 1;
+
+ }
+ yuv_mode = strtol(value, 0L, 0);
+ if (yuv_mode < 0 || yuv_mode > 3) {
+ fprintf(stderr, "invalid yuv mode\n");
+ return 1;
+ }
+ break;
+ }
+ }
+ }
+ break;
+ case OptHelp:
+ usage();
+ return 0;
+ case OptSetDebugLevel:{
+ debug_level = strtol(optarg, 0L, 0);
+ break;
+ }
+ case OptSetDevice:
+ device = strdup(optarg);
+ if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) {
+ char dev = device[0];
+
+ sprintf(device, "/dev/video%c", dev);
+ }
+ break;
+ case OptSetAudioRoute:
+ subs = optarg;
+ while (*subs != '\0') {
+ switch (getsubopt(&subs, subopts, &value)) {
+ case SUB_INPUT:
+ if (value == NULL) {
+ printf
+ ("No value given to suboption <input>\n");
+ usage();
+ }
+ route.input = strtol(value, 0L, 0);
+ break;
+ case SUB_OUTPUT:
+ if (value == NULL) {
+ printf
+ ("No value given to suboption <output>\n");
+ usage();
+ }
+ route.output = strtol(value, 0L, 0);
+ break;
+ default:
+ printf
+ ("Invalid suboptions specified\n");
+ usage();
+ break;
+ }
+ }
+ break;
+ case OptReset:
+ reset = strtol(optarg, 0L, 0);
+ break;
+ case OptPassThrough:
+ passthrough = strtol(optarg, 0L, 0);
+ break;
+ case OptSetAudioMute:
+ audio_mute = strtol(optarg, 0L, 0);
+ break;
+ case OptSetStereoMode:
+ stereo_mode = strtol(optarg, 0L, 0);
+ break;
+ case OptSetBilingualMode:
+ bilingual_mode = strtol(optarg, 0L, 0);
+ break;
+ case OptSetGPIO:
+ subs = optarg;
+ while (*subs != '\0') {
+ switch (getsubopt(&subs, subopts, &value)) {
+ case SUB_DIR:
+ if (value == NULL) {
+ fprintf(stderr,
+ "No value given to suboption <dir>\n");
+ usage();
+ exit(1);
+ }
+ gpio_dir = strtol(value, 0L, 0);
+ gpio_set_dir = 1;
+ break;
+ case SUB_VAL:
+ if (value == NULL) {
+ fprintf(stderr,
+ "No value given to suboption <val>\n");
+ usage();
+ exit(1);
+ }
+ gpio_out = (unsigned short)strtol(value, 0L, 0);
+ break;
+ default:
+ fprintf(stderr,
+ "Invalid suboptions specified\n");
+ usage();
+ exit(1);
+ break;
+ }
+ }
+ break;
+ case ':':
+ fprintf(stderr, "Option `%s' requires a value\n",
+ argv[optind]);
+ usage();
+ return 1;
+ case '?':
+ fprintf(stderr, "Unknown argument `%s'\n",
+ argv[optind]);
+ usage();
+ return 1;
+ }
+ }
+ if (optind < argc) {
+ printf("unknown arguments: ");
+ while (optind < argc)
+ printf("%s ", argv[optind++]);
+ printf("\n");
+ usage();
+ return 1;
+ }
+
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n", device,
+ strerror(errno));
+ exit(1);
+ }
+ free(device);
+
+ /* Setting Opts */
+
+ if (options[OptSetAudioRoute])
+ doioctl(fd, VIDIOC_INT_S_AUDIO_ROUTING, &route,
+ "VIDIOC_INT_S_AUDIO_ROUTING");
+
+ if (options[OptFrameSync]) {
+ printf("ioctl: VIDEO_GET_EVENT\n");
+
+ for (;;) {
+ struct video_event ev;
+ int fps = 30;
+ v4l2_std_id std;
+
+ if (ioctl(fd, VIDIOC_G_STD, &std) == 0)
+ fps = (std & V4L2_STD_525_60) ? 30 : 25;
+ if (ioctl(fd, VIDEO_GET_EVENT, &ev) < 0) {
+ fprintf(stderr, "ioctl: VIDEO_GET_EVENT failed\n");
+ break;
+ } else if (ev.timestamp == 0) {
+ unsigned long long pts = 0, frame = 0;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ timestamp =
+ (double)tv.tv_sec +
+ ((double)tv.tv_usec / 1000000.0);
+
+ ioctl(fd, VIDEO_GET_PTS, &pts);
+ ioctl(fd, VIDEO_GET_FRAME_COUNT, &frame);
+ pts_to_string(ptsstr, pts, fps);
+ printf("%10.6f: pts %-20s, %lld frames\n",
+ timestamp, ptsstr, frame);
+ }
+ }
+ }
+
+ if (options[OptSetGPIO]) {
+ struct v4l2_register reg;
+
+ reg.match_type = V4L2_CHIP_MATCH_HOST;
+ reg.match_chip = 0;
+ reg.reg = IVTV_REG_GPIO_DIR_OFFSET;
+ reg.val = gpio_dir;
+ if (gpio_set_dir && doioctl(fd, VIDIOC_DBG_S_REGISTER, &reg,
+ "VIDIOC_DBG_S_REGISTER") == 0)
+ printf("GPIO dir set to 0x%04llx\n", reg.val);
+ reg.reg = IVTV_REG_GPIO_OUT_OFFSET;
+ reg.val = gpio_out;
+ if (doioctl(fd, VIDIOC_DBG_S_REGISTER, &reg,
+ "VIDIOC_DBG_S_REGISTER") == 0)
+ printf("GPIO out set to 0x%04llx\n", reg.val);
+ }
+
+ if (options[OptListGPIO]) {
+ struct v4l2_register reg;
+
+ reg.match_type = V4L2_CHIP_MATCH_HOST;
+ reg.match_chip = 0;
+ reg.reg = IVTV_REG_GPIO_IN_OFFSET;
+ if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &reg) == 0)
+ printf("GPIO in: 0x%04llx\n", reg.val);
+ reg.reg = IVTV_REG_GPIO_DIR_OFFSET;
+ if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &reg) == 0)
+ printf("GPIO dir: 0x%04llx\n", reg.val);
+ reg.reg = IVTV_REG_GPIO_OUT_OFFSET;
+ if (ioctl(fd, VIDIOC_DBG_G_REGISTER, &reg) == 0)
+ printf("GPIO out: 0x%04llx\n", reg.val);
+ }
+
+ if (options[OptSetDebugLevel]) {
+ char buf[20];
+ new_debug_level = debug_level;
+
+ sprintf(buf, "%d", debug_level);
+ if (dowrite(buf, "/sys/module/ivtv/parameters/debug") == 0) {
+ printf(" set debug level: ");
+ print_debug_mask(new_debug_level);
+ printf("\n");
+ }
+ }
+
+ if (options[OptGetDebugLevel]) {
+ char *buf = doread("/sys/module/ivtv/parameters/debug");
+
+ gdebug_level = 0;
+ if (buf) {
+ gdebug_level = atol(buf);
+ printf(" debug level: ");
+ print_debug_mask(gdebug_level);
+ printf("\n");
+ }
+ }
+
+ if (options[OptPassThrough]) {
+ int source = passthrough ? VIDEO_SOURCE_DEMUX : VIDEO_SOURCE_MEMORY;
+
+ doioctl(fd, VIDEO_SELECT_SOURCE, (void *)source,
+ "IVTV_IOC_PASSTHROUGH");
+ }
+
+ if (options[OptSetAudioMute]) {
+ doioctl(fd, AUDIO_SET_MUTE, (void *)audio_mute, "AUDIO_SET_MUTE");
+ }
+
+ if (options[OptSetStereoMode]) {
+ doioctl(fd, AUDIO_CHANNEL_SELECT,
+ (void *)stereo_mode, "AUDIO_CHANNEL_SELECT");
+ }
+
+ if (options[OptSetBilingualMode]) {
+ doioctl(fd, AUDIO_BILINGUAL_CHANNEL_SELECT,
+ (void *)bilingual_mode, "AUDIO_BILINGUAL_CHANNEL_SELECT");
+ }
+
+ if (options[OptReset])
+ doioctl(fd, VIDIOC_INT_RESET, &reset, "VIDIOC_INT_RESET");
+
+ if (options[OptSetYuvMode]) {
+ struct ivtv_dma_frame frame;
+ struct v4l2_format fmt;
+ const enum v4l2_field map[4] = {
+ V4L2_FIELD_INTERLACED_TB,
+ V4L2_FIELD_INTERLACED_BT,
+ V4L2_FIELD_NONE,
+ V4L2_FIELD_ANY,
+ };
+
+ printf("set yuv mode\n");
+ memset(&frame, 0, sizeof(frame));
+ frame.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ if (ioctl(fd, IVTV_IOC_DMA_FRAME, &frame) < 0) {
+ fprintf(stderr, "Unable to switch to user DMA YUV mode\n");
+ exit(1);
+ }
+ fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ ioctl(fd, VIDIOC_G_FMT, &fmt);
+ fmt.fmt.pix.field = map[yuv_mode];
+ doioctl(fd, VIDIOC_S_FMT, &fmt, "VIDIOC_S_FMT");
+ }
+
+ if (options[OptGetYuvMode]) {
+ struct ivtv_dma_frame frame;
+ struct v4l2_format fmt;
+
+ memset(&frame, 0, sizeof(frame));
+ frame.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ if (ioctl(fd, IVTV_IOC_DMA_FRAME, &frame) < 0) {
+ fprintf(stderr, "Unable to switch to user DMA YUV mode\n");
+ exit(1);
+ }
+ fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT");
+ printf("Current yuv_mode %d %s\n", fmt.fmt.pix.field,
+ field2s(fmt.fmt.pix.field));
+ }
+
+ close(fd);
+ exit(app_result);
+}
diff --git a/v4l2-apps/util/v4l2-ctl.cpp b/v4l2-apps/util/v4l2-ctl.cpp
index 198118ac6..d637e34d7 100644
--- a/v4l2-apps/util/v4l2-ctl.cpp
+++ b/v4l2-apps/util/v4l2-ctl.cpp
@@ -123,6 +123,8 @@ enum Option {
static char options[OptLast];
+static int app_result;
+
static unsigned capabilities;
typedef std::vector<struct v4l2_ext_control> ctrl_list;
@@ -715,7 +717,7 @@ static void printcropcap(const struct v4l2_cropcap &cropcap)
printf("\tPixel Aspect: %u/%u\n", cropcap.pixelaspect.numerator, cropcap.pixelaspect.denominator);
}
-static int printfmt(struct v4l2_format vfmt)
+static void printfmt(struct v4l2_format vfmt)
{
const flag_def vbi_def[] = {
{ V4L2_VBI_UNSYNC, "unsynchronized" },
@@ -776,10 +778,7 @@ static int printfmt(struct v4l2_format vfmt)
break;
case V4L2_BUF_TYPE_PRIVATE:
break;
- default:
- return -1;
}
- return 0;
}
static void print_video_formats(int fd, enum v4l2_buf_type type)
@@ -999,10 +998,12 @@ static v4l2_std_id parse_ntsc(const char *ntsc)
static int doioctl(int fd, int request, void *parm, const char *name)
{
- int retVal;
+ int retVal = ioctl(fd, request, parm);
- if (!options[OptVerbose]) return ioctl(fd, request, parm);
- retVal = ioctl(fd, request, parm);
+ if (retVal < 0) {
+ app_result = -1;
+ }
+ if (!options[OptVerbose]) return retVal;
printf("%s: ", name);
if (retVal < 0)
printf("failed: %s\n", strerror(errno));
@@ -1068,9 +1069,7 @@ static void do_crop(int fd, unsigned int set_crop, struct v4l2_rect &vcrop, v4l2
struct v4l2_crop in_crop;
in_crop.type = type;
- if (ioctl(fd, VIDIOC_G_CROP, &in_crop) < 0)
- fprintf(stderr, "ioctl: VIDIOC_G_CROP failed\n");
- else {
+ if (doioctl(fd, VIDIOC_G_CROP, &in_crop, "VIDIOC_G_CROP") == 0) {
if (set_crop & CropWidth)
in_crop.c.width = vcrop.width;
if (set_crop & CropHeight)
@@ -1079,8 +1078,7 @@ static void do_crop(int fd, unsigned int set_crop, struct v4l2_rect &vcrop, v4l2
in_crop.c.left = vcrop.left;
if (set_crop & CropTop)
in_crop.c.top = vcrop.top;
- if (ioctl(fd, VIDIOC_S_CROP, &in_crop) < 0)
- fprintf(stderr, "ioctl: VIDIOC_S_CROP failed\n");
+ doioctl(fd, VIDIOC_S_CROP, &in_crop, "VIDIOC_S_CROP");
}
}
@@ -1603,43 +1601,35 @@ int main(int argc, char **argv)
struct v4l2_tuner vt;
memset(&vt, 0, sizeof(struct v4l2_tuner));
- if (ioctl(fd, VIDIOC_G_TUNER, &vt) < 0) {
- fprintf(stderr, "ioctl: VIDIOC_G_TUNER failed\n");
- exit(1);
+ if (doioctl(fd, VIDIOC_G_TUNER, &vt, "VIDIOC_G_TUNER") == 0) {
+ vt.audmode = mode;
+ doioctl(fd, VIDIOC_S_TUNER, &vt, "VIDIOC_S_TUNER");
}
- vt.audmode = mode;
- doioctl(fd, VIDIOC_S_TUNER, &vt, "VIDIOC_S_TUNER");
}
if (options[OptSetVideoFormat]) {
struct v4l2_format in_vfmt;
- printf("ioctl: VIDIOC_S_FMT\n");
+
in_vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (ioctl(fd, VIDIOC_G_FMT, &in_vfmt) < 0)
- fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n");
- else {
+ if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt, "VIDIOC_G_FMT") == 0) {
if (set_fmts & FmtWidth)
in_vfmt.fmt.pix.width = vfmt.fmt.pix.width;
if (set_fmts & FmtHeight)
in_vfmt.fmt.pix.height = vfmt.fmt.pix.height;
- if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0)
- fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n");
+ doioctl(fd, VIDIOC_S_FMT, &in_vfmt, "VIDIOC_S_FMT");
}
}
if (options[OptSetVideoOutFormat]) {
struct v4l2_format in_vfmt;
- printf("ioctl: VIDIOC_S_FMT\n");
+
in_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
- if (ioctl(fd, VIDIOC_G_FMT, &in_vfmt) < 0)
- fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n");
- else {
+ if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt, "VIDIOC_G_FMT") == 0) {
if (set_fmts_out & FmtWidth)
in_vfmt.fmt.pix.width = vfmt_out.fmt.pix.width;
if (set_fmts_out & FmtHeight)
in_vfmt.fmt.pix.height = vfmt_out.fmt.pix.height;
- if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0)
- fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n");
+ doioctl(fd, VIDIOC_S_FMT, &in_vfmt, "VIDIOC_S_FMT");
}
}
@@ -1669,29 +1659,24 @@ int main(int argc, char **argv)
if (options[OptSetOutputOverlayFormat]) {
struct v4l2_format fmt;
- memset(&fmt, 0, sizeof(fmt));
+
fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY;
- if (ioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") < 0)
- fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n");
- else {
+ if (doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") == 0) {
if (set_overlay_fmt_out & FmtChromaKey)
fmt.fmt.win.chromakey = overlay_fmt_out.fmt.win.chromakey;
if (set_overlay_fmt_out & FmtGlobalAlpha)
fmt.fmt.win.global_alpha = overlay_fmt_out.fmt.win.global_alpha;
- if (ioctl(fd, VIDIOC_S_FMT, &fmt, "VIDIOC_S_FMT") < 0)
- fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n");
+ doioctl(fd, VIDIOC_S_FMT, &fmt, "VIDIOC_S_FMT");
}
}
if (options[OptSetFBuf]) {
struct v4l2_framebuffer fb;
- if (ioctl(fd, VIDIOC_G_FBUF, &fb, "VIDIOC_G_FBUF") < 0)
- fprintf(stderr, "ioctl: VIDIOC_G_FBUF failed\n");
- else {
+
+ if (doioctl(fd, VIDIOC_G_FBUF, &fb, "VIDIOC_G_FBUF") == 0) {
fb.flags &= ~set_fbuf;
fb.flags |= fbuf.flags;
- if (ioctl(fd, VIDIOC_S_FBUF, &fb) < 0)
- fprintf(stderr, "ioctl: VIDIOC_S_FBUF failed\n");
+ doioctl(fd, VIDIOC_S_FBUF, &fb, "VIDIOC_S_FBUF");
}
}
@@ -1763,69 +1748,53 @@ int main(int argc, char **argv)
if (options[OptGetVideoFormat]) {
vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (doioctl(fd, VIDIOC_G_FMT, &vfmt, "VIDIOC_G_FMT") == 0)
- if (printfmt(vfmt) != 0)
- fprintf(stderr, "error printing result\n");
+ printfmt(vfmt);
}
if (options[OptGetVideoOutFormat]) {
vfmt_out.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
if (doioctl(fd, VIDIOC_G_FMT, &vfmt_out, "VIDIOC_G_FMT") == 0)
- if (printfmt(vfmt_out) != 0)
- fprintf(stderr, "error printing result\n");
+ printfmt(vfmt_out);
}
if (options[OptGetOverlayFormat]) {
struct v4l2_format fmt;
- memset(&fmt, 0, sizeof(fmt));
+
fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
if (doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") == 0)
- if (printfmt(fmt) != 0)
- fprintf(stderr, "error printing result\n");
+ printfmt(fmt);
}
if (options[OptGetOutputOverlayFormat]) {
struct v4l2_format fmt;
- memset(&fmt, 0, sizeof(fmt));
+
fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY;
if (doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") == 0)
- if (printfmt(fmt) != 0)
- fprintf(stderr, "error printing result\n");
+ printfmt(fmt);
}
if (options[OptGetSlicedVbiFormat]) {
vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
- if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt,
- "VIDIOC_G_FMT") == 0)
- if (printfmt(vbi_fmt) != 0)
- fprintf(stderr,
- "error printing result\n");
+ if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt, "VIDIOC_G_FMT") == 0)
+ printfmt(vbi_fmt);
}
if (options[OptGetSlicedVbiOutFormat]) {
vbi_fmt_out.type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
- if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out,
- "VIDIOC_G_FMT") == 0)
- if (printfmt(vbi_fmt_out) != 0)
- fprintf(stderr,
- "error printing result\n");
+ if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out, "VIDIOC_G_FMT") == 0)
+ printfmt(vbi_fmt_out);
}
if (options[OptGetVbiFormat]) {
raw_fmt.type = V4L2_BUF_TYPE_VBI_CAPTURE;
- if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt,
- "VIDIOC_G_FMT") == 0)
- if (printfmt(raw_fmt) != 0)
- fprintf(stderr,
- "error printing result\n");
+ if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt, "VIDIOC_G_FMT") == 0)
+ printfmt(raw_fmt);
}
if (options[OptGetVbiOutFormat]) {
raw_fmt_out.type = V4L2_BUF_TYPE_VBI_OUTPUT;
- if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt_out,
- "VIDIOC_G_FMT") == 0)
- if (printfmt(raw_fmt_out) != 0)
- fprintf(stderr,
- "error printing result\n");
+ if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt_out, "VIDIOC_G_FMT") == 0)
+ printfmt(raw_fmt_out);
}
if (options[OptGetFBuf]) {
@@ -2188,5 +2157,5 @@ int main(int argc, char **argv)
}
close(fd);
- exit(0);
+ exit(app_result);
}
diff --git a/v4l2-apps/util/v4l2-dbg.cpp b/v4l2-apps/util/v4l2-dbg.cpp
index e55cbb2a8..e24ae7140 100644
--- a/v4l2-apps/util/v4l2-dbg.cpp
+++ b/v4l2-apps/util/v4l2-dbg.cpp
@@ -533,6 +533,9 @@ int main(int argc, char **argv)
case V4L2_IDENT_CX23416:
print_regs(fd, &get_reg, 0x02000000, 0x020000ff, stride);
break;
+ case V4L2_IDENT_CX23418:
+ print_regs(fd, &get_reg, 0x02c40000, 0x02c409c7, stride);
+ break;
default:
/* By default print range 0-0xff */
print_regs(fd, &get_reg, 0, 0xff, stride);