sndiod: replace the gloal opt list with per-device lists.

This commit is contained in:
Alexandre Ratchov 2018-06-10 22:50:35 +02:00
parent ddf5e0dfa7
commit 37ee5aa871
6 changed files with 39 additions and 39 deletions

View File

@ -24,6 +24,7 @@
#include "dsp.h"
#include "siofile.h"
#include "midi.h"
#include "opt.h"
#include "sysex.h"
#include "utils.h"
@ -972,6 +973,7 @@ dev_new(char *path, struct aparams *par,
d = xmalloc(sizeof(struct dev));
d->path = xstrdup(path);
d->num = dev_sndnum++;
d->opt_list = NULL;
/*
* XXX: below, we allocate a midi input buffer, since we don't
@ -1239,6 +1241,8 @@ dev_del(struct dev *d)
log_puts(": deleting\n");
}
#endif
while (d->opt_list != NULL)
opt_del(d, d->opt_list);
if (d->pstate != DEV_CFG)
dev_close(d);
for (p = &dev_list; *p != d; p = &(*p)->next) {

View File

@ -95,12 +95,25 @@ struct slot {
unsigned int tstate; /* mmc state */
};
struct opt {
struct opt *next;
#define OPT_NAMEMAX 11
char name[OPT_NAMEMAX + 1];
int maxweight; /* max dynamic range for clients */
int pmin, pmax; /* play channels */
int rmin, rmax; /* recording channels */
int mmc; /* true if MMC control enabled */
int dup; /* true if join/expand enabled */
int mode; /* bitmap of MODE_XXX */
};
/*
* audio device with plenty of slots
*/
struct dev {
struct dev *next;
struct slot *slot_list; /* audio streams attached */
struct opt *opt_list;
struct midi *midi;
/*

View File

@ -20,13 +20,11 @@
#include "opt.h"
#include "utils.h"
struct opt *opt_list = NULL;
/*
* create a new audio sub-device "configuration"
*/
struct opt *
opt_new(char *name, struct dev *dev,
opt_new(struct dev *d, char *name,
int pmin, int pmax, int rmin, int rmax,
int maxweight, int mmc, int dup, unsigned int mode)
{
@ -34,7 +32,9 @@ opt_new(char *name, struct dev *dev,
unsigned int len;
char c;
if (opt_byname(name, dev->num)) {
if (opt_byname(d, name)) {
dev_log(d);
log_puts(".");
log_puts(name);
log_puts(": already defined\n");
return NULL;
@ -66,12 +66,11 @@ opt_new(char *name, struct dev *dev,
o->mmc = mmc;
o->dup = dup;
o->mode = mode;
o->dev = dev;
memcpy(o->name, name, len + 1);
o->next = opt_list;
opt_list = o;
o->next = d->opt_list;
d->opt_list = o;
if (log_level >= 2) {
dev_log(o->dev);
dev_log(d);
log_puts(".");
log_puts(o->name);
log_puts(":");
@ -107,13 +106,11 @@ opt_new(char *name, struct dev *dev,
}
struct opt *
opt_byname(char *name, unsigned int num)
opt_byname(struct dev *d, char *name)
{
struct opt *o;
for (o = opt_list; o != NULL; o = o->next) {
if (o->dev->num != num)
continue;
for (o = d->opt_list; o != NULL; o = o->next) {
if (strcmp(name, o->name) == 0)
return o;
}
@ -121,11 +118,11 @@ opt_byname(char *name, unsigned int num)
}
void
opt_del(struct opt *o)
opt_del(struct dev *d, struct opt *o)
{
struct opt **po;
for (po = &opt_list; *po != o; po = &(*po)->next) {
for (po = &d->opt_list; *po != o; po = &(*po)->next) {
#ifdef DEBUG
if (*po == NULL) {
log_puts("opt_del: not on list\n");

View File

@ -19,24 +19,9 @@
struct dev;
struct opt {
struct opt *next;
#define OPT_NAMEMAX 11
char name[OPT_NAMEMAX + 1];
int maxweight; /* max dynamic range for clients */
int pmin, pmax; /* play channels */
int rmin, rmax; /* recording channels */
int mmc; /* true if MMC control enabled */
int dup; /* true if join/expand enabled */
int mode; /* bitmap of MODE_XXX */
struct dev *dev; /* device to which we're attached */
};
extern struct opt *opt_list;
struct opt *opt_new(char *, struct dev *, int, int, int, int,
struct opt *opt_new(struct dev *, char *, int, int, int, int,
int, int, int, unsigned int);
void opt_del(struct opt *);
struct opt *opt_byname(char *, unsigned int);
void opt_del(struct dev *, struct opt *);
struct opt *opt_byname(struct dev *, char *);
#endif /* !defined(OPT_H) */

View File

@ -325,7 +325,7 @@ mkopt(char *path, struct dev *d,
{
struct opt *o;
o = opt_new(path, d, pmin, pmax, rmin, rmax,
o = opt_new(d, path, pmin, pmax, rmin, rmax,
MIDI_TO_ADATA(vol), mmc, dup, mode);
if (o == NULL)
return NULL;
@ -466,7 +466,7 @@ main(int argc, char **argv)
if (dev_list == NULL)
mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate, hold, autovol);
for (d = dev_list; d != NULL; d = d->next) {
if (opt_byname("default", d->num))
if (opt_byname(d, "default"))
continue;
if (mkopt("default", d, pmin, pmax, rmin, rmax,
mode, vol, mmc, dup) == NULL)
@ -534,8 +534,6 @@ main(int argc, char **argv)
; /* nothing */
midi_done();
while (opt_list != NULL)
opt_del(opt_list);
while (dev_list)
dev_del(dev_list);
while (port_list)

View File

@ -843,14 +843,17 @@ sock_hello(struct sock *f)
return 0;
return 1;
}
f->opt = opt_byname(p->opt, p->devnum);
d = dev_bynum(p->devnum);
if (d == NULL)
return 0;
f->opt = opt_byname(d, p->opt);
if (f->opt == NULL)
return 0;
#ifdef DEBUG
if (log_level >= 3) {
sock_log(f);
log_puts(": using ");
dev_log(f->opt->dev);
dev_log(d);
log_puts(".");
log_puts(f->opt->name);
log_puts(", mode = ");
@ -869,7 +872,7 @@ sock_hello(struct sock *f)
}
return 0;
}
s = slot_new(f->opt->dev, p->who, &sock_slotops, f, mode);
s = slot_new(d, p->who, &sock_slotops, f, mode);
if (s == NULL)
return 0;
f->midi = NULL;