Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/videoctl add videoctl(1), a tool for displaying or s...
details: https://anonhg.NetBSD.org/src/rev/0e65129fd50a
branches: trunk
changeset: 760087:0e65129fd50a
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun Dec 26 10:37:14 2010 +0000
description:
add videoctl(1), a tool for displaying or setting parameters on video(4)
devices
diffstat:
usr.bin/videoctl/Makefile | 8 +
usr.bin/videoctl/videoctl.1 | 77 +++++
usr.bin/videoctl/videoctl.c | 627 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 712 insertions(+), 0 deletions(-)
diffs (truncated from 724 to 300 lines):
diff -r 1839abae3568 -r 0e65129fd50a usr.bin/videoctl/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/videoctl/Makefile Sun Dec 26 10:37:14 2010 +0000
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.1 2010/12/26 10:37:14 jmcneill Exp $
+
+PROG= videoctl
+SRCS= videoctl.c
+LDADD+= -lutil
+DPADD+= ${LIBUTIL}
+
+.include <bsd.prog.mk>
diff -r 1839abae3568 -r 0e65129fd50a usr.bin/videoctl/videoctl.1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/videoctl/videoctl.1 Sun Dec 26 10:37:14 2010 +0000
@@ -0,0 +1,77 @@
+.\" $NetBSD: videoctl.1,v 1.1 2010/12/26 10:37:15 jmcneill Exp $
+.\"
+.\" Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd December 26, 2010
+.Dt VIDEOCTL 1
+.Os
+.Sh NAME
+.Nm videoctl
+.Nd control video device
+.Sh SYNOPSIS
+.Nm
+.Op Fl d Ar device
+.Fl a
+.Nm
+.Op Fl d Ar device
+.Ar name ...
+.Nm
+.Op Fl d Ar device
+.Fl w
+.Ar name=value ...
+.Sh DESCRIPTION
+The
+.Nm
+command displays or sets various video system driver variables. If a list of
+variables is present on the command line, then
+.Nm
+prints the current value of those variables for the specified device.
+If the
+.Fl a
+flag is specified, all variables for the device are printed.
+If the
+.Fl w
+flag is specified
+.Nm
+attempts to set the specified variables to the given values.
+The
+.Fl d
+flag can be used to specify an alternate video device. If
+.Fl d
+is not specified,
+.Pa /dev/video0
+is used.
+.Sh FILES
+.Bl -tag -width /dev/video0 -compact
+.It Pa /dev/video0
+video device
+.El
+.Sh SEE ALSO
+.Xr video 4
+.Sh HISTORY
+The
+.Nm
+command first appeared in
+.Nx 6.0 .
diff -r 1839abae3568 -r 0e65129fd50a usr.bin/videoctl/videoctl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/videoctl/videoctl.c Sun Dec 26 10:37:14 2010 +0000
@@ -0,0 +1,627 @@
+/* $NetBSD: videoctl.c,v 1.1 2010/12/26 10:37:15 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2010\
+ Jared D. McNeill <jmcneill%invisible.ca@localhost>. All rights reserved.");
+__RCSID("$NetBSD: videoctl.c,v 1.1 2010/12/26 10:37:15 jmcneill Exp $");
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/videoio.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <util.h>
+
+static void usage(void);
+static void video_print(const char *);
+static void video_print_all(void);
+static bool video_print_caps(const char *);
+static bool video_print_formats(const char *);
+static bool video_print_inputs(const char *);
+static bool video_print_audios(const char *);
+static bool video_print_standards(const char *);
+static bool video_print_tuners(const char *);
+static bool video_print_ctrl(uint32_t);
+static void video_set(const char *);
+static bool video_set_ctrl(uint32_t, int32_t);
+static const char * video_cid2name(uint32_t);
+static uint32_t video_name2cid(const char *);
+
+static const char *video_dev = NULL;
+static int video_fd = -1;
+static bool aflag = false;
+static bool wflag = false;
+
+static const struct {
+ uint32_t id;
+ const char *name;
+} videoctl_cid_names[] = {
+ { V4L2_CID_BRIGHTNESS, "brightness" },
+ { V4L2_CID_CONTRAST, "contrast" },
+ { V4L2_CID_SATURATION, "saturation" },
+ { V4L2_CID_HUE, "hue" },
+ { V4L2_CID_AUDIO_VOLUME, "audio_volume" },
+ { V4L2_CID_AUDIO_BALANCE, "audio_balance" },
+ { V4L2_CID_AUDIO_BASS, "audio_bass" },
+ { V4L2_CID_AUDIO_TREBLE, "audio_treble" },
+ { V4L2_CID_AUDIO_MUTE, "audio_mute" },
+ { V4L2_CID_AUDIO_LOUDNESS, "audio_loudness" },
+ { V4L2_CID_BLACK_LEVEL, "black_level" },
+ { V4L2_CID_AUTO_WHITE_BALANCE, "auto_white_balance" },
+ { V4L2_CID_DO_WHITE_BALANCE, "do_white_balance" },
+ { V4L2_CID_RED_BALANCE, "red_balance" },
+ { V4L2_CID_BLUE_BALANCE, "blue_balance" },
+ { V4L2_CID_GAMMA, "gamma" },
+ { V4L2_CID_WHITENESS, "whiteness" },
+ { V4L2_CID_EXPOSURE, "exposure" },
+ { V4L2_CID_AUTOGAIN, "autogain" },
+ { V4L2_CID_GAIN, "gain" },
+ { V4L2_CID_HFLIP, "hflip" },
+ { V4L2_CID_VFLIP, "vflip" },
+ { V4L2_CID_HCENTER, "hcenter" },
+ { V4L2_CID_VCENTER, "vcenter" },
+ { V4L2_CID_POWER_LINE_FREQUENCY, "power_line_frequency" },
+ { V4L2_CID_HUE_AUTO, "hue_auto" },
+ { V4L2_CID_WHITE_BALANCE_TEMPERATURE, "white_balance_temperature" },
+ { V4L2_CID_SHARPNESS, "sharpness" },
+ { V4L2_CID_BACKLIGHT_COMPENSATION, "backlight_compensation" },
+};
+
+int
+main(int argc, char *argv[])
+{
+ int ch;
+
+ setprogname(argv[0]);
+
+ while ((ch = getopt(argc, argv, "ad:w")) != -1) {
+ switch (ch) {
+ case 'a':
+ aflag = true;
+ break;
+ case 'd':
+ video_dev = strdup(optarg);
+ break;
+ case 'w':
+ wflag = true;
+ break;
+ case 'h':
+ default:
+ usage();
+ /* NOTREACHED */
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (wflag && aflag)
+ usage();
+ /* NOTREACHED */
+ if (wflag && argc == 0)
+ usage();
+ /* NOTREACHED */
+ if (aflag && argc > 0)
+ usage();
+ /* NOTREACHED */
+ if (!wflag && !aflag && argc == 0)
+ usage();
+ /* NOTREACHED */
+
+ if (video_dev == NULL)
+ video_dev = _PATH_VIDEO0;
+
+ video_fd = open(video_dev, wflag ? O_RDWR : O_RDONLY);
+ if (video_fd == -1)
+ err(EXIT_FAILURE, "couldn't open '%s'", video_dev);
+
+ if (aflag) {
+ video_print_all();
+ } else if (wflag) {
+ while (argc > 0) {
+ video_set(argv[0]);
+ --argc;
+ ++argv;
+ }
+ } else {
+ while (argc > 0) {
+ video_print(argv[0]);
+ --argc;
+ ++argv;
+ }
+ }
+
+ close(video_fd);
+
+ return EXIT_SUCCESS;
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-d file] name ...\n", getprogname());
+ fprintf(stderr, "usage: %s [-d file] -w name=value ...\n",
+ getprogname());
+ fprintf(stderr, "usage: %s [-d file] -a\n", getprogname());
+ exit(EXIT_FAILURE);
+}
+
+static void
+video_print_all(void)
+{
+ video_print_caps(NULL);
+ video_print_formats(NULL);
+ video_print_inputs(NULL);
+ video_print_audios(NULL);
+ video_print_standards(NULL);
+ video_print_tuners(NULL);
+ video_print_ctrl(0);
+}
+
+static bool
+video_print_caps(const char *name)
+{
+ struct v4l2_capability cap;
+ char capbuf[128];
+ int error;
+ bool found = false;
+
+ if (strtok(NULL, ".") != NULL)
Home |
Main Index |
Thread Index |
Old Index