From: ratchov Date: Fri, 29 Jan 2021 11:38:23 +0000 (+0000) Subject: Make audio clients use struct opt to reach the device X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c67d5b9a6f94fa69d8e6e5a602c13ae764bf75b9;p=openbsd Make audio clients use struct opt to reach the device No behavior change. This decreases the number of explicit references to the dev structure --- diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c index 154eb6ba8c3..176e8b17e79 100644 --- a/usr.bin/sndiod/dev.c +++ b/usr.bin/sndiod/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.88 2021/01/29 11:36:44 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.89 2021/01/29 11:38:23 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -122,7 +122,7 @@ slot_array_init(void) slot_array[i].unit = i; slot_array[i].ops = NULL; slot_array[i].vol = MIDI_MAXCTL; - slot_array[i].dev = NULL; + slot_array[i].opt = NULL; slot_array[i].serial = slot_serial++; memset(slot_array[i].name, 0, SLOT_NAMEMAX); } @@ -408,7 +408,7 @@ dev_midi_slotdesc(struct dev *d, struct slot *s) x.dev = SYSEX_DEV_ANY; x.id0 = SYSEX_AUCAT; x.id1 = SYSEX_AUCAT_SLOTDESC; - if (*s->name != '\0') + if (s->opt != NULL && s->opt->dev == d) slot_ctlname(s, (char *)x.u.slotdesc.name, SYSEX_NAMELEN); x.u.slotdesc.chan = (s - slot_array); x.u.slotdesc.end = SYSEX_END; @@ -424,7 +424,7 @@ dev_midi_dump(struct dev *d) dev_midi_master(d); for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) { - if (s->dev != d) + if (s->opt != NULL && s->opt->dev != d) continue; dev_midi_slotdesc(d, s); dev_midi_vol(d, s); @@ -461,7 +461,8 @@ dev_midi_omsg(void *arg, unsigned char *msg, int len) chan = msg[0] & MIDI_CHANMASK; if (chan >= DEV_NSLOT) return; - if (slot_array[chan].dev != d) + if (slot_array[chan].opt == NULL || + slot_array[chan].opt->dev != d) return; slot_setvol(slot_array + chan, msg[2]); dev_onval(d, CTLADDR_SLOT_LEVEL(chan), msg[2]); @@ -1235,7 +1236,7 @@ dev_open(struct dev *d) return 0; for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) { - if (s->dev != d || s->name[0] == 0) + if (s->opt == NULL || s->opt->dev != d || s->name[0] == 0) continue; slot_ctlname(s, name, CTL_NAMEMAX); dev_addctl(d, "app", CTL_NUM, @@ -1270,20 +1271,22 @@ dev_abort(struct dev *d) struct ctlslot *c; for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) { - if (s->dev != d) + if (s->opt == NULL || s->opt->dev != d) continue; - if (s->ops) + if (s->ops) { s->ops->exit(s->arg); - s->ops = NULL; + s->ops = NULL; + } } d->slot_list = NULL; for (c = ctlslot_array, i = DEV_NCTLSLOT; i > 0; i--, c++) { if (c->opt->dev != d) continue; - if (c->ops) + if (c->ops) { c->ops->exit(c->arg); - c->ops = NULL; + c->ops = NULL; + } } midi_abort(d->midi); @@ -1574,7 +1577,7 @@ dev_sync_attach(struct dev *d) } for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) { - if (s->dev != d || !s->ops || !s->opt->mmc) + if (s->opt == NULL || s->opt->dev != d || !s->ops || !s->opt->mmc) continue; if (s->pstate != SLOT_READY) { #ifdef DEBUG @@ -1590,7 +1593,7 @@ dev_sync_attach(struct dev *d) return; for (i = 0, s = slot_array; i < DEV_NSLOT; i++, s++) { - if (s->dev != d || !s->ops || !s->opt->mmc) + if (s->opt == NULL || s->opt->dev != d || !s->ops || !s->opt->mmc) continue; slot_attach(s); s->pstate = SLOT_RUN; @@ -1670,7 +1673,7 @@ void slot_initconv(struct slot *s) { unsigned int dev_nch; - struct dev *d = s->dev; + struct dev *d = s->opt->dev; if (s->mode & MODE_PLAY) { cmap_init(&s->mix.cmap, @@ -1751,7 +1754,7 @@ slot_initconv(struct slot *s) void slot_allocbufs(struct slot *s) { - struct dev *d = s->dev; + struct dev *d = s->opt->dev; if (s->mode & MODE_PLAY) { s->mix.bpf = s->par.bps * s->mix.nch; @@ -1826,7 +1829,7 @@ slot_freebufs(struct slot *s) * allocate a new slot and register the given call-backs */ struct slot * -slot_new(struct dev *d, struct opt *opt, unsigned int id, char *who, +slot_new(struct opt *opt, unsigned int id, char *who, struct slotops *ops, void *arg, int mode) { char *p; @@ -1923,20 +1926,18 @@ found: slot_log(s); log_puts(": requested mode not allowed\n"); } - return 0; + return NULL; } - if (!dev_ref(d)) + if (!dev_ref(opt->dev)) return NULL; - dev_label(d, s - slot_array); - if ((mode & d->mode) != mode) { + if ((mode & opt->dev->mode) != mode) { if (log_level >= 1) { slot_log(s); log_puts(": requested mode not supported\n"); } - dev_unref(d); + dev_unref(opt->dev); return NULL; } - s->dev = d; s->opt = opt; s->ops = ops; s->arg = arg; @@ -1948,18 +1949,19 @@ found: if (s->mode & MODE_RECMASK) s->sub.nch = s->opt->rmax - s->opt->rmin + 1; s->xrun = s->opt->mmc ? XRUN_SYNC : XRUN_IGNORE; - s->appbufsz = d->bufsz; - s->round = d->round; - s->rate = d->rate; - dev_midi_slotdesc(d, s); - dev_midi_vol(d, s); + s->appbufsz = s->opt->dev->bufsz; + s->round = s->opt->dev->round; + s->rate = s->opt->dev->rate; + dev_label(s->opt->dev, s - slot_array); + dev_midi_slotdesc(s->opt->dev, s); + dev_midi_vol(s->opt->dev, s); #ifdef DEBUG if (log_level >= 3) { slot_log(s); log_puts(": using "); - dev_log(d); + dev_log(s->opt->dev); log_puts("."); - log_puts(opt->name); + log_puts(s->opt->name); log_puts(", mode = "); log_putx(mode); log_puts("\n"); @@ -1987,8 +1989,7 @@ slot_del(struct slot *s) slot_stop(s, 0); break; } - dev_unref(s->dev); - s->dev = NULL; + dev_unref(s->opt->dev); } /* @@ -2015,7 +2016,7 @@ slot_setvol(struct slot *s, unsigned int vol) void slot_attach(struct slot *s) { - struct dev *d = s->dev; + struct dev *d = s->opt->dev; long long pos; /* @@ -2080,13 +2081,13 @@ slot_ready(struct slot *s) * device may be disconnected, and if so we're called from * slot->ops->exit() on a closed device */ - if (s->dev->pstate == DEV_CFG) + if (s->opt->dev->pstate == DEV_CFG) return; if (!s->opt->mmc) { slot_attach(s); s->pstate = SLOT_RUN; } else - dev_sync_attach(s->dev); + dev_sync_attach(s->opt->dev); } /* @@ -2096,7 +2097,7 @@ slot_ready(struct slot *s) void slot_start(struct slot *s) { - struct dev *d = s->dev; + struct dev *d = s->opt->dev; #ifdef DEBUG if (s->pstate != SLOT_INIT) { slot_log(s); @@ -2156,7 +2157,7 @@ void slot_detach(struct slot *s) { struct slot **ps; - struct dev *d = s->dev; + struct dev *d = s->opt->dev; long long pos; for (ps = &d->slot_list; *ps != s; ps = &(*ps)->next) { @@ -2570,7 +2571,7 @@ dev_setctl(struct dev *d, int addr, int val) } else { num = addr - CTLADDR_SLOT_LEVEL(0); s = slot_array + num; - if (s->dev != d) + if (s->opt->dev != d) return 1; slot_setvol(s, val); dev_midi_vol(d, s); diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h index 019691ab673..57ed8c88972 100644 --- a/usr.bin/sndiod/dev.h +++ b/usr.bin/sndiod/dev.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.h,v 1.36 2021/01/29 11:36:44 ratchov Exp $ */ +/* $OpenBSD: dev.h,v 1.37 2021/01/29 11:38:23 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -60,7 +60,6 @@ struct ctlops struct slot { struct slotops *ops; /* client callbacks */ struct slot *next; /* next on the play list */ - struct dev *dev; /* device this belongs to */ struct opt *opt; /* config used */ void *arg; /* user data for callbacks */ struct aparams par; /* socket side params */ @@ -92,7 +91,7 @@ struct slot { int xrun; /* underrun policy */ int skip; /* cycles to skip (for xrun) */ #define SLOT_BUFSZ(s) \ - ((s)->appbufsz + (s)->dev->bufsz / (s)->dev->round * (s)->round) + ((s)->appbufsz + (s)->opt->dev->bufsz / (s)->opt->dev->round * (s)->round) int appbufsz; /* slot-side buffer size */ int round; /* slot-side block size */ int rate; /* slot-side sample rate */ @@ -293,7 +292,7 @@ void dev_midi_vol(struct dev *, struct slot *); * sio_open(3) like interface for clients */ void slot_log(struct slot *); -struct slot *slot_new(struct dev *, struct opt *, unsigned int, char *, +struct slot *slot_new(struct opt *, unsigned int, char *, struct slotops *, void *, int); void slot_del(struct slot *); void slot_setvol(struct slot *, unsigned int); diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c index 6e276f96e4e..83f8ad08bb2 100644 --- a/usr.bin/sndiod/sock.c +++ b/usr.bin/sndiod/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.40 2021/01/29 11:36:44 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.41 2021/01/29 11:38:23 ratchov Exp $ */ /* * Copyright (c) 2008-2012 Alexandre Ratchov * @@ -616,7 +616,7 @@ int sock_setpar(struct sock *f) { struct slot *s = f->slot; - struct dev *d = s->dev; + struct dev *d = s->opt->dev; struct amsg_par *p = &f->rmsg.u.par; unsigned int min, max; uint32_t rate, appbufsz; @@ -929,7 +929,7 @@ sock_hello(struct sock *f) opt = opt_byname(d, p->opt); if (opt == NULL) return 0; - f->slot = slot_new(d, opt, id, p->who, &sock_slotops, f, mode); + f->slot = slot_new(opt, id, p->who, &sock_slotops, f, mode); if (f->slot == NULL) return 0; f->midi = NULL; @@ -1239,8 +1239,8 @@ sock_execmsg(struct sock *f) f->rstate = SOCK_RMSG; f->lastvol = ctl; /* dont trigger feedback message */ slot_setvol(s, ctl); - dev_midi_vol(s->dev, s); - dev_onval(s->dev, + dev_midi_vol(s->opt->dev, s); + dev_onval(s->opt->dev, CTLADDR_SLOT_LEVEL(f->slot - slot_array), ctl); break; case AMSG_CTLSUB: