mirror of https://github.com/ericonr/sndio.git
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.
This commit is contained in:
parent
9edbee2bc1
commit
74ae9cda72
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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} */
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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} */
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
35
sndiod/dev.c
35
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) {
|
||||
|
|
|
@ -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 *);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue