#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;
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 {
if (ioctl(fd, VIRTUAL_OSS_ADD_OPTIONS, options) < 0)
errx(EX_SOFTWARE, "One or more invalid options");
if (options[0] != '\0')
errx(EX_SOFTWARE, "%s", options);
}
close(fd);
return (0);
}