From 74ae9cda725cd67a03b45dcdae1976b8ddbbf0e7 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Mon, 13 Jan 2020 09:27:06 +0100 Subject: [PATCH] Make the control group a simple string. To handle nested devices, just prefix the group with the "dev." prefix. To avoid namespace conflicts, put program controls in a new "app" group. The "master.level" control is renamed to "output.level" to match the hardware name. This way snd/0 and rsnd/0 end-up with the same control name. --- libsndio/amsg.h | 2 +- libsndio/sioctl_aucat.c | 3 +-- libsndio/sioctl_open.3 | 2 +- libsndio/sioctl_sun.c | 1 - libsndio/sndio.h | 2 +- sndioctl/sndioctl.c | 11 +++-------- sndiod/dev.c | 35 ++++++++--------------------------- sndiod/dev.h | 5 +++-- sndiod/dev_sioctl.c | 15 +++++++++++++-- sndiod/sock.c | 3 +-- 10 files changed, 32 insertions(+), 47 deletions(-) diff --git a/libsndio/amsg.h b/libsndio/amsg.h index 9938242..525ddb5 100644 --- a/libsndio/amsg.h +++ b/libsndio/amsg.h @@ -138,10 +138,10 @@ struct amsg_ctl_chan { * description of a control (index, value) pair */ struct amsg_ctl_desc { - struct amsg_ctl_chan group; /* group of the control */ struct amsg_ctl_chan chan0; /* affected channels */ struct amsg_ctl_chan chan1; /* dito for AMSG_CTL_{SEL,VEC,LIST} */ char func[AMSG_CTL_NAMEMAX]; /* parameter function name */ + char group[AMSG_CTL_NAMEMAX]; /* group of the control */ uint8_t type; /* see sioctl_desc structure */ uint8_t __pad1[1]; uint16_t addr; /* control address */ diff --git a/libsndio/sioctl_aucat.c b/libsndio/sioctl_aucat.c index e9b8b74..1f92a9f 100644 --- a/libsndio/sioctl_aucat.c +++ b/libsndio/sioctl_aucat.c @@ -82,8 +82,7 @@ sioctl_aucat_rdata(struct sioctl_aucat_hdl *hdl) c = hdl->buf; rpos = 0; while (rpos < hdl->buf_wpos) { - strlcpy(desc.group.str, c->group.str, SIOCTL_NAMEMAX); - desc.group.unit = (int16_t)ntohs(c->group.unit); + strlcpy(desc.group, c->group, SIOCTL_NAMEMAX); strlcpy(desc.chan0.str, c->chan0.str, SIOCTL_NAMEMAX); desc.chan0.unit = (int16_t)ntohs(c->chan0.unit); strlcpy(desc.chan1.str, c->chan1.str, SIOCTL_NAMEMAX); diff --git a/libsndio/sioctl_open.3 b/libsndio/sioctl_open.3 index 0c5d72b..464dfe7 100644 --- a/libsndio/sioctl_open.3 +++ b/libsndio/sioctl_open.3 @@ -129,7 +129,7 @@ struct sioctl_desc { #define SIOCTL_LIST 5 /* switch, element of a list */ unsigned int type; /* one of above */ char func[SIOCTL_NAMEMAX]; /* function name */ - struct sioctl_chan group; /* group this control belongs to */ + char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ struct sioctl_chan chan0; /* affected channels */ struct sioctl_chan chan1; /* dito for SIOCTL_{VEC,LIST} */ }; diff --git a/libsndio/sioctl_sun.c b/libsndio/sioctl_sun.c index 88e68cb..119aec8 100644 --- a/libsndio/sioctl_sun.c +++ b/libsndio/sioctl_sun.c @@ -224,7 +224,6 @@ scanvol(struct sioctl_sun_hdl *hdl, struct wskbd_vol *vol) int i, val; memset(&desc, 0, sizeof(struct sioctl_desc)); - desc.group.unit = -1; if (vol->level_idx >= 0) { ctrl.dev = vol->level_idx; ctrl.type = AUDIO_MIXER_VALUE; diff --git a/libsndio/sndio.h b/libsndio/sndio.h index 96434f0..b1cafd9 100644 --- a/libsndio/sndio.h +++ b/libsndio/sndio.h @@ -113,7 +113,7 @@ struct sioctl_desc { #define SIOCTL_LIST 5 /* switch, element of a list */ unsigned int type; /* one of above */ char func[SIOCTL_NAMEMAX]; /* function name */ - struct sioctl_chan group; /* group this control belongs to */ + char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ struct sioctl_chan chan0; /* affected channels */ struct sioctl_chan chan1; /* dito for SIOCTL_{VEC,LIST} */ }; diff --git a/sndioctl/sndioctl.c b/sndioctl/sndioctl.c index 9b18c7b..8f402c5 100644 --- a/sndioctl/sndioctl.c +++ b/sndioctl/sndioctl.c @@ -78,10 +78,7 @@ cmpdesc(struct sioctl_desc *d1, struct sioctl_desc *d2) { int res; - res = strcmp(d1->group.str, d2->group.str); - if (res != 0) - return res; - res = d1->group.unit - d2->group.unit; + res = strcmp(d1->group, d2->group); if (res != 0) return res; res = strcmp(d1->chan0.str, d2->chan0.str); @@ -397,10 +394,8 @@ print_val(struct info *p, int mono) void print_par(struct info *p, int mono, char *comment) { - if (p->desc.group.str[0] != 0) { - printf("%s", p->desc.group.str); - if (p->desc.group.unit >= 0) - printf("%d", p->desc.group.unit); + if (p->desc.group[0] != 0) { + printf("%s", p->desc.group); printf("/"); } print_chan(&p->desc.chan0, mono); diff --git a/sndiod/dev.c b/sndiod/dev.c index 7ff7ea7..00256ed 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -1112,7 +1112,7 @@ dev_allocbufs(struct dev *d) int dev_open(struct dev *d) { - int i, gunit; + int i; struct ctl *c; d->mode = d->reqmode; @@ -1136,32 +1136,14 @@ dev_open(struct dev *d) if (!dev_allocbufs(d)) return 0; - /* - * we use the "sndiod" group name. find a unused - * unit number for it - */ - gunit = 0; - c = d->ctl_list; - while (1) { - if (c == NULL) - break; - if (strcmp(c->group.str, "sndiod") == 0 && - c->group.unit == gunit) { - gunit++; - c = d->ctl_list; - continue; - } - c = c->next; - } - for (i = 0; i < DEV_NSLOT; i++) { - dev_addctl(d, "app", -1, CTL_NUM, + dev_addctl(d, "app", CTL_NUM, CTLADDR_SLOT_LEVEL(i), d->slot[i].name, d->slot[i].unit, "level", NULL, -1, d->slot[i].vol); } - dev_addctl(d, "sndiod", gunit, CTL_NUM, - CTLADDR_MASTER, "master", -1, "level", NULL, -1, d->master); + dev_addctl(d, "", CTL_NUM, + CTLADDR_MASTER, "output", -1, "level", NULL, -1, d->master); d->pstate = DEV_INIT; return 1; @@ -2242,8 +2224,8 @@ ctl_chan_log(struct ctl_chan *c) void ctl_log(struct ctl *c) { - if (c->group.str[0] != 0) { - ctl_chan_log(&c->group); + if (c->group[0] != 0) { + log_puts(c->group); log_puts("/"); } ctl_chan_log(&c->chan0); @@ -2269,7 +2251,7 @@ ctl_log(struct ctl *c) * add a ctl */ struct ctl * -dev_addctl(struct dev *d, char *gstr, int gunit, int type, int addr, +dev_addctl(struct dev *d, char *gstr, int type, int addr, char *str0, int unit0, char *func, char *str1, int unit1, int val) { struct ctl *c, **pc; @@ -2278,8 +2260,7 @@ dev_addctl(struct dev *d, char *gstr, int gunit, int type, int addr, c = xmalloc(sizeof(struct ctl)); c->type = type; strlcpy(c->func, func, CTL_NAMEMAX); - strlcpy(c->group.str, gstr, CTL_NAMEMAX); - c->group.unit = gunit; + strlcpy(c->group, gstr, CTL_NAMEMAX); strlcpy(c->chan0.str, str0, CTL_NAMEMAX); c->chan0.unit = unit0; if (c->type == CTL_VEC || c->type == CTL_LIST) { diff --git a/sndiod/dev.h b/sndiod/dev.h index 2f61bef..23a79f2 100644 --- a/sndiod/dev.h +++ b/sndiod/dev.h @@ -129,10 +129,11 @@ struct ctl { unsigned int addr; /* control address */ #define CTL_NAMEMAX 16 /* max name lenght */ char func[CTL_NAMEMAX]; /* parameter function name */ + char group[CTL_NAMEMAX]; /* group aka namespace */ struct ctl_chan { char str[CTL_NAMEMAX]; /* stream name */ int unit; - } group, chan0, chan1; /* affected channels */ + } chan0, chan1; /* affected channels */ unsigned int val_mask; unsigned int desc_mask; unsigned int refs_mask; @@ -305,7 +306,7 @@ int dev_setctl(struct dev *, int, int); int dev_onval(struct dev *, int, int); int dev_nctl(struct dev *); void dev_label(struct dev *, int); -struct ctl *dev_addctl(struct dev *, char *, int, int, int, +struct ctl *dev_addctl(struct dev *, char *, int, int, char *, int, char *, char *, int, int); void dev_rmctl(struct dev *, int); int dev_makeunit(struct dev *, char *); diff --git a/sndiod/dev_sioctl.c b/sndiod/dev_sioctl.c index 5122d15..b4d1e65 100644 --- a/sndiod/dev_sioctl.c +++ b/sndiod/dev_sioctl.c @@ -51,15 +51,26 @@ struct fileops dev_sioctl_ops = { void dev_sioctl_ondesc(void *arg, struct sioctl_desc *desc, int val) { +#define GROUP_PREFIX "dev" +#define GROUP_PREFIX_LEN (sizeof(GROUP_PREFIX)) + char group[CTL_NAMEMAX]; struct dev *d = arg; + size_t len; int addr; if (desc == NULL) return; addr = CTLADDR_END + desc->addr; dev_rmctl(d, addr); - dev_addctl(d, - desc->group.str, desc->group.unit, desc->type, addr, + if (desc->group[0] != 0) { + len = snprintf(group, CTL_NAMEMAX, + GROUP_PREFIX ".%s", desc->group); + if (len >= CTL_NAMEMAX) + return; + } else + strlcpy(group, GROUP_PREFIX, CTL_NAMEMAX); + + dev_addctl(d, group, desc->type, addr, desc->chan0.str, desc->chan0.unit, desc->func, desc->chan1.str, desc->chan1.unit, val); } diff --git a/sndiod/sock.c b/sndiod/sock.c index faacdc0..b1b0f20 100644 --- a/sndiod/sock.c +++ b/sndiod/sock.c @@ -1532,9 +1532,8 @@ sock_buildmsg(struct sock *f) break; c->desc_mask &= ~mask; c->val_mask &= ~mask; - strlcpy(desc->group.str, c->group.str, + strlcpy(desc->group, c->group, AMSG_CTL_NAMEMAX); - desc->group.unit = ntohs(c->group.unit); strlcpy(desc->chan0.str, c->chan0.str, AMSG_CTL_NAMEMAX); desc->chan0.unit = ntohs(c->chan0.unit);