mixer

FreeBSD OSS mixer library implementation and a complete rewrite of mixer(8)
git clone git://git.margiolis.net/mixer.git
Log | Files | Refs | README | LICENSE

commit 6199e1478a15504748d72bb3d59ba59d24d3987a
parent 775771ba1907073f938215549b27efa3b3733d8e
Author: Christos Margiolis <christos@margiolis.net>
Date:   Fri,  1 Oct 2021 13:22:40 +0300

add symbol versioning and change dunit to default_unit

Diffstat:
Mlib/libmixer/Makefile | 24++++++++++++++++++++++++
Alib/libmixer/Symbol.map | 28++++++++++++++++++++++++++++
Mlib/libmixer/mixer.3 | 14+++++++-------
Mlib/libmixer/mixer.c | 24+++++++++---------------
Mlib/libmixer/mixer.h | 4++--
Musr.sbin/mixer/mixer.c | 24++++++++++++------------
6 files changed, 82 insertions(+), 36 deletions(-)

diff --git a/lib/libmixer/Makefile b/lib/libmixer/Makefile @@ -4,5 +4,29 @@ LIB= mixer SRCS= ${LIB}.c INCS= ${LIB}.h MAN= ${LIB}.3 +SYMBOL_MAPS= Symbol.map + +MLINKS+= mixer.3 mixer_open.3 +MLINKS+= mixer.3 mixer_close.3 +MLINKS+= mixer.3 mixer_get_dev.3 +MLINKS+= mixer.3 mixer_get_dev_byname.3 +MLINKS+= mixer.3 mixer_add_ctl.3 +MLINKS+= mixer.3 mixer_add_ctl_s.3 +MLINKS+= mixer.3 mixer_remove_ctl.3 +MLINKS+= mixer.3 mixer_get_ctl.3 +MLINKS+= mixer.3 mixer_get_ctl_byname.3 +MLINKS+= mixer.3 mixer_set_vol.3 +MLINKS+= mixer.3 mixer_set_mute.3 +MLINKS+= mixer.3 mixer_mod_recsrc.3 +MLINKS+= mixer.3 mixer_get_default_unit.3 +MLINKS+= mixer.3 mixer_set_default_unit.3 +MLINKS+= mixer.3 mixer_get_mode.3 +MLINKS+= mixer.3 mixer_get_nmixers.3 +MLINKS+= mixer.3 MIX_ISDEV.3 +MLINKS+= mixer.3 MIX_ISMUTE.3 +MLINKS+= mixer.3 MIX_ISREC.3 +MLINKS+= mixer.3 MIX_ISRECSRC.3 +MLINKS+= mixer.3 MIX_VOLNORM.3 +MLINKS+= mixer.3 MIX_VOLDENORM.3 .include <bsd.lib.mk> diff --git a/lib/libmixer/Symbol.map b/lib/libmixer/Symbol.map @@ -0,0 +1,28 @@ +/* + * $FreeBSD$ + */ + +LIBMIXER_1.0 { + mixer_open; + mixer_close; + mixer_get_dev; + mixer_get_dev_byname; + mixer_add_ctl; + mixer_add_ctl_s; + mixer_remove_ctl; + mixer_get_ctl; + mixer_get_ctl_byname; + mixer_set_vol; + mixer_set_mute; + mixer_mod_recsrc; + mixer_get_default_unit; + mixer_set_default_unit; + mixer_get_mode; + mixer_get_nmixers; + MIX_ISDEV; + MIX_ISMUTE; + MIX_ISREC; + MIX_ISRECSRC; + MIX_VOLNORM; + MIX_VOLDENORM; +}; diff --git a/lib/libmixer/mixer.3 b/lib/libmixer/mixer.3 @@ -38,8 +38,8 @@ .Nm mixer_set_vol , .Nm mixer_set_mute , .Nm mixer_mod_recsrc , -.Nm mixer_get_dunit , -.Nm mixer_set_dunit , +.Nm mixer_get_default_unit , +.Nm mixer_set_default_unit , .Nm mixer_get_mode, .Nm mixer_get_nmixers , .Nm MIX_ISDEV , @@ -80,9 +80,9 @@ Mixer library (libmixer, -lmixer) .Ft int .Fn mixer_mod_recsrc "struct mixer *m" "int opt" .Ft int -.Fn mixer_get_dunit "void" +.Fn mixer_get_default_unit "void" .Ft int -.Fn mixer_set_dunit "struct mixer *m" "int unit" +.Fn mixer_set_default_unit "struct mixer *m" "int unit" .Ft int .Fn mixer_get_mode "int unit" .Ft int @@ -358,9 +358,9 @@ Toggle device from the recording sources. .El .Pp The -.Fn mixer_get_dunit +.Fn mixer_get_default_unit and -.Fn mixer_set_dunit +.Fn mixer_set_default_unit functions get and set the default audio card in the system. Although this is not really a mixer feature, it's useful to have instead of having to use the @@ -457,7 +457,7 @@ The .Fn mixer_set_mute , .Fn mixer_mod_recsrc , .Fn mixer_get_dunut , -.Fn mixer_set_dunit +.Fn mixer_set_default_unit and .Fn mixer_get_nmixers functions return 0 or positive values on success and -1 on failure. diff --git a/lib/libmixer/mixer.c b/lib/libmixer/mixer.c @@ -36,8 +36,6 @@ #include "mixer.h" -#define BASEPATH "/dev/mixer" - static int _mixer_readvol(struct mixer *, struct mix_dev *); /* @@ -70,23 +68,21 @@ mixer_open(const char *name) struct mixer *m = NULL; struct mix_dev *dp; const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; - char *p = NULL; + char *p; int i; if ((m = calloc(1, sizeof(struct mixer))) == NULL) goto fail; if (name != NULL) { - /* XXX: should we remove `const` altogether? */ - if ((p = strdup(basename((char *)name))) == NULL) - goto fail; + p = basename((char *)name); if (strncmp(p, "mixer", 5) == 0 && p[5] == '\0') - goto dunit; + goto default_unit; (void)sscanf(p, "%*[^0123456789]%d", &m->unit); (void)strlcpy(m->name, name, sizeof(m->name)); } else { -dunit: - if ((m->unit = mixer_get_dunit()) < 0) +default_unit: + if ((m->unit = mixer_get_default_unit()) < 0) goto fail; (void)snprintf(m->name, sizeof(m->name), "/dev/mixer%d", m->unit); } @@ -95,7 +91,7 @@ dunit: goto fail; m->devmask = m->recmask = m->recsrc = 0; - m->f_default = m->unit == mixer_get_dunit(); + m->f_default = m->unit == mixer_get_default_unit(); m->mode = mixer_get_mode(m->unit); /* The unit number _must_ be set before the ioctl. */ m->mi.dev = m->unit; @@ -106,7 +102,7 @@ dunit: } if (ioctl(m->fd, SNDCTL_CARDINFO, &m->ci) < 0) memset(&m->ci, 0, sizeof(m->ci)); - if(ioctl(m->fd, SOUND_MIXER_READ_DEVMASK, &m->devmask) < 0 || + if (ioctl(m->fd, SOUND_MIXER_READ_DEVMASK, &m->devmask) < 0 || ioctl(m->fd, SOUND_MIXER_READ_MUTE, &m->mutemask) < 0 || ioctl(m->fd, SOUND_MIXER_READ_RECMASK, &m->recmask) < 0 || ioctl(m->fd, SOUND_MIXER_READ_RECSRC, &m->recsrc) < 0) @@ -132,8 +128,6 @@ dunit: return (m); fail: - if (p != NULL) - free(p); /* XXX: do we need this? */ /*if (m != NULL)*/ /*(void)mixer_close(m);*/ @@ -420,7 +414,7 @@ mixer_mod_recsrc(struct mixer *m, int opt) * and set the mixer structure's `f_default` flag. */ int -mixer_get_dunit(void) +mixer_get_default_unit(void) { size_t size; int unit; @@ -440,7 +434,7 @@ mixer_get_dunit(void) * @param unit the audio card number (e.g pcm0, pcm1, ...). */ int -mixer_set_dunit(struct mixer *m, int unit) +mixer_set_default_unit(struct mixer *m, int unit) { size_t size; diff --git a/lib/libmixer/mixer.h b/lib/libmixer/mixer.h @@ -113,8 +113,8 @@ mix_ctl_t *mixer_get_ctl_byname(struct mix_dev *, const char *); int mixer_set_vol(struct mixer *, mix_volume_t); int mixer_set_mute(struct mixer *, int); int mixer_mod_recsrc(struct mixer *, int); -int mixer_get_dunit(void); -int mixer_set_dunit(struct mixer *, int); +int mixer_get_default_unit(void); +int mixer_set_default_unit(struct mixer *, int); int mixer_get_mode(int); int mixer_get_nmixers(void); diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c @@ -38,7 +38,7 @@ static void printminfo(struct mixer *, int); static void printdev(struct mixer *, int); static void printrecsrc(struct mixer *, int); /* XXX: change name */ /* Control handlers */ -static int mod_dunit(struct mix_dev *, void *); +static int mod_default_unit(struct mix_dev *, void *); static int mod_volume(struct mix_dev *, void *); static int mod_mute(struct mix_dev *, void *); static int mod_recsrc(struct mix_dev *, void *); @@ -46,11 +46,11 @@ static int print_volume(struct mix_dev *, void *); static int print_mute(struct mix_dev *, void *); static int print_recsrc(struct mix_dev *, void *); -static const mix_ctl_t ctl_dunit = { +static const mix_ctl_t ctl_default_unit = { .parent_dev = NULL, .id = -1, .name = "default_unit", - .mod = mod_dunit, + .mod = mod_default_unit, .print = NULL }; @@ -61,7 +61,7 @@ main(int argc, char *argv[]) mix_ctl_t *cp; char *name = NULL, buf[NAME_MAX]; char *p, *bufp, *devstr, *ctlstr, *valstr = NULL; - int dunit, i, n, pall = 1; + int du, i, n, pall = 1; int aflag = 0, dflag = 0, oflag = 0, sflag = 0; int ch; @@ -71,7 +71,7 @@ main(int argc, char *argv[]) aflag = 1; break; case 'd': - dunit = strtol(optarg, NULL, 10); + du = strtol(optarg, NULL, 10); if (errno == EINVAL || errno == ERANGE) err(1, "strtol"); dflag = 1; @@ -119,7 +119,7 @@ main(int argc, char *argv[]) initctls(m); - if (dflag && ctl_dunit.mod(m->dev, &dunit) < 0) + if (dflag && ctl_default_unit.mod(m->dev, &du) < 0) goto parse; if (sflag) { printrecsrc(m, oflag); @@ -287,20 +287,20 @@ printrecsrc(struct mixer *m, int oflag) } static int -mod_dunit(struct mix_dev *d, void *p) +mod_default_unit(struct mix_dev *d, void *p) { - int dunit = *((int *)p); + int du = *((int *)p); int n; - if ((n = mixer_get_dunit()) < 0) { + if ((n = mixer_get_default_unit()) < 0) { warn("cannot get default unit"); return (-1); } - if (mixer_set_dunit(d->parent_mixer, dunit) < 0) { - warn("cannot set default unit to: %d", dunit); + if (mixer_set_default_unit(d->parent_mixer, du) < 0) { + warn("cannot set default unit to: %d", du); return (-1); } - printf("%s: %d -> %d\n", ctl_dunit.name, n, dunit); + printf("%s: %d -> %d\n", ctl_default_unit.name, n, du); return (0); }