aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/virtual_oss/virtual_oss_cmd
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/virtual_oss/virtual_oss_cmd')
-rw-r--r--usr.sbin/virtual_oss/virtual_oss_cmd/Makefile8
-rw-r--r--usr.sbin/virtual_oss/virtual_oss_cmd/command.c113
-rw-r--r--usr.sbin/virtual_oss/virtual_oss_cmd/virtual_oss_cmd.8103
3 files changed, 224 insertions, 0 deletions
diff --git a/usr.sbin/virtual_oss/virtual_oss_cmd/Makefile b/usr.sbin/virtual_oss/virtual_oss_cmd/Makefile
new file mode 100644
index 000000000000..b209d3dca068
--- /dev/null
+++ b/usr.sbin/virtual_oss/virtual_oss_cmd/Makefile
@@ -0,0 +1,8 @@
+PROG= virtual_oss_cmd
+MAN= ${PROG}.8
+
+SRCS= command.c
+
+CFLAGS+= -I${SRCTOP}/usr.sbin/virtual_oss/virtual_oss
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/virtual_oss/virtual_oss_cmd/command.c b/usr.sbin/virtual_oss/virtual_oss_cmd/command.c
new file mode 100644
index 000000000000..64781992ddfd
--- /dev/null
+++ b/usr.sbin/virtual_oss/virtual_oss_cmd/command.c
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2021-2022 Hans Petter Selasky
+ *
+ * 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 AUTHOR 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 AUTHOR 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 <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <err.h>
+#include <sysexits.h>
+#include <stdarg.h>
+#include <fcntl.h>
+
+#include "virtual_oss.h"
+
+static void
+message(const char *fmt, ...)
+{
+ va_list list;
+
+ va_start(list, fmt);
+ vfprintf(stderr, fmt, list);
+ va_end(list);
+}
+
+static void
+usage(void)
+{
+ message("Usage: virtual_oss_cmd /dev/vdsp.ctl [command line arguments to pass to virtual_oss]\n");
+ exit(EX_USAGE);
+}
+
+int
+main(int argc, char **argv)
+{
+ char options[VIRTUAL_OSS_OPTIONS_MAX] = {};
+ size_t offset = 0;
+ size_t len = VIRTUAL_OSS_OPTIONS_MAX - 1;
+ int fd;
+
+ /* check if no options */
+ if (argc < 2)
+ usage();
+
+ fd = open(argv[1], O_RDWR);
+ if (fd < 0)
+ errx(EX_SOFTWARE, "Could not open '%s'", argv[1]);
+
+ for (int x = 2; x != argc; x++) {
+ size_t tmp = strlen(argv[x]) + 1;
+ if (tmp > len)
+ errx(EX_SOFTWARE, "Too many options passed");
+ memcpy(options + offset, argv[x], tmp);
+ options[offset + tmp - 1] = ' ';
+ offset += tmp;
+ len -= tmp;
+ }
+
+ if (options[0] == 0) {
+ struct virtual_oss_system_info info;
+ if (ioctl(fd, VIRTUAL_OSS_GET_SYSTEM_INFO, &info) < 0)
+ errx(EX_SOFTWARE, "Cannot get system information");
+
+ info.rx_device_name[sizeof(info.rx_device_name) - 1] = 0;
+ info.tx_device_name[sizeof(info.tx_device_name) - 1] = 0;
+
+ printf("Sample rate: %u Hz\n"
+ "Sample width: %u bits\n"
+ "Sample channels: %u\n"
+ "Output jitter: %u / %u\n"
+ "Input device name: %s\n"
+ "Output device name: %s\n",
+ info.sample_rate,
+ info.sample_bits,
+ info.sample_channels,
+ info.tx_jitter_down,
+ info.tx_jitter_up,
+ info.rx_device_name,
+ info.tx_device_name);
+ } else {
+ /* execute options */
+ if (ioctl(fd, VIRTUAL_OSS_ADD_OPTIONS, options) < 0)
+ errx(EX_SOFTWARE, "One or more invalid options");
+ /* show error, if any */
+ if (options[0] != '\0')
+ errx(EX_SOFTWARE, "%s", options);
+ }
+
+ close(fd);
+ return (0);
+}
diff --git a/usr.sbin/virtual_oss/virtual_oss_cmd/virtual_oss_cmd.8 b/usr.sbin/virtual_oss/virtual_oss_cmd/virtual_oss_cmd.8
new file mode 100644
index 000000000000..a200d88a4a32
--- /dev/null
+++ b/usr.sbin/virtual_oss/virtual_oss_cmd/virtual_oss_cmd.8
@@ -0,0 +1,103 @@
+.\"
+.\" Copyright (c) 2021-2022 Hans Petter Selasky <hselasky@freebsd.org>
+.\"
+.\" 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 AUTHOR 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 AUTHOR 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 February 12, 2025
+.Dt VIRTUAL_OSS_CMD 8
+.Os
+.Sh NAME
+.Nm virtual_oss_cmd
+.Nd modify a running
+.Xr virtual_oss 8
+instance's options
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+.Nm
+pass additional command line arguments to a running
+.Xr virtual_oss 8
+instance via its control device.
+Supported command line arguments:
+.Bl -tag -width indent
+.It Fl E Ar xxx
+.It Fl F Ar xxx
+.It Fl G Ar xxx
+.It Fl L Ar xxx
+.It Fl M Ar xxx
+.It Fl O Ar xxx
+.It Fl P Ar xxx
+.It Fl R Ar xxx
+.It Fl a Ar xxx
+.It Fl b Ar xxx
+.It Fl c Ar xxx
+.It Fl d Ar xxx
+.It Fl e Ar xxx
+.It Fl f Ar xxx
+.It Fl l Ar xxx
+.It Fl m Ar xxx
+.It Fl p Ar xxx
+.It Fl s Ar xxx
+.It Fl w Ar xxx
+.El
+.Pp
+Refer to
+.Xr virtual_oss 8
+for a detailed description of the command line arguments.
+.Sh EXAMPLES
+To change the recording device:
+.Bd -literal -offset indent
+virtual_oss_cmd /dev/vdsp.ctl -R /dev/dsp4
+
+.Ed
+To change the playback device:
+.Bd -literal -offset indent
+virtual_oss_cmd /dev/vdsp.ctl -P /dev/dsp4
+
+.Ed
+To enable recording:
+.Bd -literal -offset indent
+virtual_oss_cmd /dev/vdsp.ctl -E 1
+
+.Ed
+To disable recording:
+.Bd -literal -offset indent
+virtual_oss_cmd /dev/vdsp.ctl -E 0
+
+.Ed
+To create a new DSP device on the fly:
+.Bd -literal -offset indent
+virtual_oss_cmd /dev/vdsp.ctl -b 16 -c 2 -d dsp.new
+
+.Ed
+To show system information:
+.Bd -literal -offset indent
+virtual_oss_cmd /dev/vdsp.ctl
+
+.Ed
+.Sh SEE ALSO
+.Xr virtual_oss 8
+.Sh AUTHORS
+.Nm
+was written by
+.An Hans Petter Selasky hselasky@freebsd.org .