From 37ee5aa8710b94499ce2d8cff67d8471e79fa9e1 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Sun, 10 Jun 2018 22:50:35 +0200 Subject: [PATCH] sndiod: replace the gloal opt list with per-device lists. --- sndiod/dev.c | 4 ++++ sndiod/dev.h | 13 +++++++++++++ sndiod/opt.c | 25 +++++++++++-------------- sndiod/opt.h | 21 +++------------------ sndiod/sndiod.c | 6 ++---- sndiod/sock.c | 9 ++++++--- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/sndiod/dev.c b/sndiod/dev.c index 236ac1f..0af1089 100644 --- a/sndiod/dev.c +++ b/sndiod/dev.c @@ -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) { diff --git a/sndiod/dev.h b/sndiod/dev.h index 2e35838..036c0e3 100644 --- a/sndiod/dev.h +++ b/sndiod/dev.h @@ -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; /* diff --git a/sndiod/opt.c b/sndiod/opt.c index bf25d12..53554d8 100644 --- a/sndiod/opt.c +++ b/sndiod/opt.c @@ -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"); diff --git a/sndiod/opt.h b/sndiod/opt.h index 4380f7a..b4ae622 100644 --- a/sndiod/opt.h +++ b/sndiod/opt.h @@ -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) */ diff --git a/sndiod/sndiod.c b/sndiod/sndiod.c index 8158966..c6acc7c 100644 --- a/sndiod/sndiod.c +++ b/sndiod/sndiod.c @@ -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) diff --git a/sndiod/sock.c b/sndiod/sock.c index d8d631b..7fcaf56 100644 --- a/sndiod/sock.c +++ b/sndiod/sock.c @@ -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;