Merge branch 'master' of ssh://caoua.org/~alex/git/sndio

This commit is contained in:
Alexandre Ratchov 2020-05-02 17:51:56 +02:00
commit 417e0d6bef
11 changed files with 89 additions and 38 deletions

11
configure vendored
View File

@ -24,6 +24,7 @@ Usage: configure [options]
--disable-umidi disable usb-midi backend --disable-umidi disable usb-midi backend
--with-libbsd use the libbsd rather than bsd-compat/* --with-libbsd use the libbsd rather than bsd-compat/*
--without-libbsd don't use libbsd --without-libbsd don't use libbsd
--default-dev=DEV set default device [$dev]
END END
} }
@ -49,6 +50,7 @@ unset includedir # path where to install header file
unset libdir # path where to install library unset libdir # path where to install library
unset defs # no extra #defines unset defs # no extra #defines
unset ldadd # no extra libraries (-l options) unset ldadd # no extra libraries (-l options)
unset dev
# #
# guess OS-specific parameters # guess OS-specific parameters
@ -170,6 +172,9 @@ for i; do
--without-libbsd) --without-libbsd)
libbsd=no libbsd=no
shift;; shift;;
--default-dev=*)
dev="${i#--default-dev=}"
shift;;
CC=*|CFLAGS=*|LDFLAGS=*) CC=*|CFLAGS=*|LDFLAGS=*)
vars="$vars$i$nl" vars="$vars$i$nl"
shift;; shift;;
@ -241,6 +246,11 @@ if [ $libbsd = yes ]; then
ldadd="$ldadd -lbsd" ldadd="$ldadd -lbsd"
fi fi
if [ -n "$dev" ]; then
defs="$defs -DDEFAULT_DEV='\"$dev\"'"
fi
for f in Makefile aucat/Makefile midicat/Makefile sndiod/Makefile \ for f in Makefile aucat/Makefile midicat/Makefile sndiod/Makefile \
libsndio/Makefile \ libsndio/Makefile \
sndioctl/Makefile \ sndioctl/Makefile \
@ -262,6 +272,7 @@ do
-e "s:@vars@:${vars}:" \ -e "s:@vars@:${vars}:" \
-e "s:@precision@:$precision:" \ -e "s:@precision@:$precision:" \
-e "s:@user@:$user:" \ -e "s:@user@:$user:" \
-e "s:@devs@:$devs:" \
< $f.in > $f < $f.in > $f
done done

View File

@ -62,7 +62,7 @@ sio_open(const char *str, unsigned int mode, int nbio)
if (hdl != NULL) if (hdl != NULL)
return hdl; return hdl;
#if defined(USE_SUN) #if defined(USE_SUN)
return _sio_sun_open("rsnd/default", mode, nbio); return _sio_sun_open("rsnd/0", mode, nbio);
#elif defined(USE_OSS) #elif defined(USE_OSS)
return _sio_oss_open("rsnd/default", mode, nbio); return _sio_oss_open("rsnd/default", mode, nbio);
#elif defined(USE_ALSA) #elif defined(USE_ALSA)

View File

@ -290,14 +290,10 @@ sio_sun_getfd(const char *str, unsigned int mode, int nbio)
DPRINTF("sio_sun_getfd: %s: '/' expected\n", str); DPRINTF("sio_sun_getfd: %s: '/' expected\n", str);
return -1; return -1;
} }
if (strcmp(p, "default") == 0) { p = _sndio_parsenum(p, &devnum, 255);
devnum = 0; if (p == NULL || *p != '\0') {
} else { DPRINTF("sio_sun_getfd: %s: number expected after '/'\n", str);
p = _sndio_parsenum(p, &devnum, 255); return -1;
if (p == NULL || *p != '\0') {
DPRINTF("sio_sun_getfd: %s: number expected after '/'\n", str);
return -1;
}
} }
snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum); snprintf(path, sizeof(path), DEVPATH_PREFIX "%u", devnum);
if (mode == (SIO_PLAY | SIO_REC)) if (mode == (SIO_PLAY | SIO_REC))

View File

@ -45,7 +45,7 @@ sioctl_open(const char *str, unsigned int mode, int nbio)
if (hdl != NULL) if (hdl != NULL)
return hdl; return hdl;
#if defined(USE_SUN_MIXER) #if defined(USE_SUN_MIXER)
return _sioctl_sun_open("rsnd/default", mode, nbio); return _sioctl_sun_open("rsnd/0", mode, nbio);
#else #else
return NULL; return NULL;
#endif #endif

View File

@ -84,14 +84,24 @@ static int
initmute(struct sioctl_sun_hdl *hdl, struct mixer_devinfo *info) initmute(struct sioctl_sun_hdl *hdl, struct mixer_devinfo *info)
{ {
struct mixer_devinfo mi; struct mixer_devinfo mi;
char name[MAX_AUDIO_DEV_LEN];
mi.index = info->next;
for (mi.index = info->next; mi.index != -1; mi.index = mi.next) { for (mi.index = info->next; mi.index != -1; mi.index = mi.next) {
if (ioctl(hdl->fd, AUDIO_MIXER_DEVINFO, &mi) < 0) if (ioctl(hdl->fd, AUDIO_MIXER_DEVINFO, &mi) < 0)
break; break;
if (strcmp(mi.label.name, AudioNmute) == 0) if (strcmp(mi.label.name, AudioNmute) == 0)
return mi.index; return mi.index;
} }
/* try "_mute" suffix */
snprintf(name, sizeof(name), "%s_mute", info->label.name);
for (mi.index = 0; ; mi.index++) {
if (ioctl(hdl->fd, AUDIO_MIXER_DEVINFO, &mi) < 0)
break;
if (info->mixer_class == mi.mixer_class &&
strcmp(mi.label.name, name) == 0)
return mi.index;
}
return -1; return -1;
} }

View File

@ -100,20 +100,22 @@ If
.Qq \&! .Qq \&!
is used instead of a number, then the switch is toggled. is used instead of a number, then the switch is toggled.
.Sh EXAMPLES .Sh EXAMPLES
The following will set all Increase the
.Ar output .Cm level
channels control affecting all
.Ar level .Cm output
control to zero: channels by 10% of the maximum:
.Pp .Pp
.Dl $ sndioctl output.level=0 .Dl $ sndioctl output.level=+0.1
.Pp .Pp
The following set all Mute all output channels:
.Ar output .Pp
channels .Dl $ sndioctl output.mute=1
.Ar mute .Pp
Toggle the above
.Cm mute
control: control:
.Pp .Pp
.Dl $ sndioctl output.mute=0 .Dl $ sndioctl output.mute=!
.Sh SEE ALSO .Sh SEE ALSO
.Xr sioctl_open 3 .Xr sioctl_open 3

View File

@ -374,7 +374,14 @@ print_val(struct info *p, int mono)
switch (p->desc.type) { switch (p->desc.type) {
case SIOCTL_NUM: case SIOCTL_NUM:
case SIOCTL_SW: case SIOCTL_SW:
printf("%.2g", p->curval / (float)p->desc.maxval); if (p->desc.maxval == 1)
printf("%d", p->curval);
else
/*
* For now, maxval is always 127 or 255,
* so three decimals is always ideal.
*/
printf("%.3f", p->curval / (float)p->desc.maxval);
break; break;
case SIOCTL_VEC: case SIOCTL_VEC:
case SIOCTL_LIST: case SIOCTL_LIST:
@ -389,7 +396,11 @@ print_val(struct info *p, int mono)
if (more) if (more)
printf(","); printf(",");
print_node(&e->desc.node1, mono); print_node(&e->desc.node1, mono);
printf(":%.2g", e->curval / (float)e->desc.maxval); if (e->desc.maxval == 1)
printf(":%d", e->curval);
else
printf(":%.3f",
e->curval / (float)e->desc.maxval);
more = 1; more = 1;
} }
} }

View File

@ -208,6 +208,14 @@ Sub-devices
that are applied after will be attached to this device. that are applied after will be attached to this device.
Device mode and parameters are determined from sub-devices Device mode and parameters are determined from sub-devices
attached to it. attached to it.
If no
.Fl f
option is used,
.Nm
will use
.Pa rsnd/0 , rsnd/1 ,
.No ... ,
.Pa rsnd/3 .
.It Fl j Ar flag .It Fl j Ar flag
Control whether program channels are joined or expanded if Control whether program channels are joined or expanded if
the number of channels requested by a program is not equal the number of channels requested by a program is not equal

View File

@ -78,13 +78,6 @@
#define DEFAULT_BUFSZ 7680 #define DEFAULT_BUFSZ 7680
#endif #endif
/*
* default device in server mode
*/
#ifndef DEFAULT_DEV
#define DEFAULT_DEV "rsnd/default"
#endif
void sigint(int); void sigint(int);
void sighup(int); void sighup(int);
void opt_ch(int *, int *); void opt_ch(int *, int *);
@ -111,6 +104,18 @@ char usagestr[] = "usage: sndiod [-d] [-a flag] [-b nframes] "
"[-Q port] [-q port] [-r rate] [-s name] [-t mode] [-U unit]\n\t" "[-Q port] [-q port] [-r rate] [-s name] [-t mode] [-U unit]\n\t"
"[-v volume] [-w flag] [-z nframes]\n"; "[-v volume] [-w flag] [-z nframes]\n";
/*
* default audio devices
*/
static char *default_devs[] = {
#ifdef DEFAULT_DEV
DEFAULT_DEV,
#else
"rsnd/0", "rsnd/1", "rsnd/2", "rsnd/3",
#endif
NULL
};
/* /*
* default MIDI ports * default MIDI ports
*/ */
@ -361,7 +366,7 @@ mkopt(char *path, struct dev *d,
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int c, i, background, unit; int c, i, background, unit, devindex;
int pmin, pmax, rmin, rmax; int pmin, pmax, rmin, rmax;
char base[SOCKPATH_MAX], path[SOCKPATH_MAX]; char base[SOCKPATH_MAX], path[SOCKPATH_MAX];
unsigned int mode, dup, mmc, vol; unsigned int mode, dup, mmc, vol;
@ -399,6 +404,7 @@ main(int argc, char **argv)
aparams_init(&par); aparams_init(&par);
mode = MODE_PLAY | MODE_REC; mode = MODE_PLAY | MODE_REC;
tcpaddr_list = NULL; tcpaddr_list = NULL;
devindex = 0;
while ((c = getopt(argc, argv, while ((c = getopt(argc, argv,
"a:b:c:C:de:F:f:j:L:m:Q:q:r:s:t:U:v:w:x:z:")) != -1) { "a:b:c:C:de:F:f:j:L:m:Q:q:r:s:t:U:v:w:x:z:")) != -1) {
@ -448,8 +454,8 @@ main(int argc, char **argv)
break; break;
case 's': case 's':
if ((d = dev_list) == NULL) { if ((d = dev_list) == NULL) {
d = mkdev(DEFAULT_DEV, &par, 0, bufsz, round, d = mkdev(default_devs[devindex++], &par, 0,
rate, hold, autovol); bufsz, round, rate, hold, autovol);
} }
if (mkopt(optarg, d, pmin, pmax, rmin, rmax, if (mkopt(optarg, d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup) == NULL) mode, vol, mmc, dup) == NULL)
@ -482,6 +488,7 @@ main(int argc, char **argv)
case 'f': case 'f':
mkdev(optarg, &par, 0, bufsz, round, mkdev(optarg, &par, 0, bufsz, round,
rate, hold, autovol); rate, hold, autovol);
devindex = -1;
break; break;
case 'F': case 'F':
if (dev_list == NULL) if (dev_list == NULL)
@ -503,8 +510,12 @@ main(int argc, char **argv)
for (i = 0; default_ports[i] != NULL; i++) for (i = 0; default_ports[i] != NULL; i++)
mkport(default_ports[i], 0); mkport(default_ports[i], 0);
} }
if (dev_list == NULL) if (devindex != -1) {
mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate, hold, autovol); for (i = devindex; default_devs[i] != NULL; i++) {
mkdev(default_devs[i], &par, 0,
bufsz, round, rate, 0, autovol);
}
}
for (d = dev_list; d != NULL; d = d->next) { for (d = dev_list; d != NULL; d = d->next) {
if (opt_byname(d, "default")) if (opt_byname(d, "default"))
continue; continue;

View File

@ -151,7 +151,7 @@ sock_close(struct sock *f)
} }
#endif #endif
if (f->pstate > SOCK_AUTH) if (f->pstate > SOCK_AUTH)
sock_sesrefs--; sock_sesrefs -= f->sesrefs;
if (f->slot) { if (f->slot) {
slot_del(f->slot); slot_del(f->slot);
f->slot = NULL; f->slot = NULL;
@ -792,11 +792,12 @@ sock_auth(struct sock *f)
if (sock_sesrefs == 0) { if (sock_sesrefs == 0) {
/* start a new session */ /* start a new session */
memcpy(sock_sescookie, p->cookie, AMSG_COOKIELEN); memcpy(sock_sescookie, p->cookie, AMSG_COOKIELEN);
f->sesrefs = 1;
} else if (memcmp(sock_sescookie, p->cookie, AMSG_COOKIELEN) != 0) { } else if (memcmp(sock_sescookie, p->cookie, AMSG_COOKIELEN) != 0) {
/* another session is active, drop connection */ /* another session is active, drop connection */
return 0; return 0;
} }
sock_sesrefs++; sock_sesrefs += f->sesrefs;
f->pstate = SOCK_HELLO; f->pstate = SOCK_HELLO;
return 1; return 1;
} }

View File

@ -64,6 +64,7 @@ struct sock {
#define SOCK_CTLVAL 2 /* send value changes */ #define SOCK_CTLVAL 2 /* send value changes */
unsigned int ctlops; /* bitmap of above */ unsigned int ctlops; /* bitmap of above */
int ctlsyncpending; /* CTLSYNC waiting to be transmitted */ int ctlsyncpending; /* CTLSYNC waiting to be transmitted */
unsigned int sesrefs; /* 1 if socket belongs to a session */
}; };
struct sock *sock_new(int fd); struct sock *sock_new(int fd);