diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-10-21 18:57:43 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2010-10-21 18:57:43 +0000 |
commit | 6ebe19ad940ba7f867c1080614a5943ce0f81597 (patch) | |
tree | 8e426ae1ad08415b87e4f44e9d6744b036dd48b5 /usr.bin | |
parent | 037c630a168e2dd796c6b34b17d366faf713cdb3 (diff) |
use MODE_xxx and XRUN_xxx macros everywhere, and zap corresponding
AMSG_xxx macros, which in turns simplifies the code
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/aucat/abuf.h | 10 | ||||
-rw-r--r-- | usr.bin/aucat/amsg.h | 14 | ||||
-rw-r--r-- | usr.bin/aucat/aproc.c | 41 | ||||
-rw-r--r-- | usr.bin/aucat/aucat.c | 8 | ||||
-rw-r--r-- | usr.bin/aucat/conf.h | 23 | ||||
-rw-r--r-- | usr.bin/aucat/dev.c | 13 | ||||
-rw-r--r-- | usr.bin/aucat/midi.c | 37 | ||||
-rw-r--r-- | usr.bin/aucat/opt.h | 13 | ||||
-rw-r--r-- | usr.bin/aucat/sock.c | 184 | ||||
-rw-r--r-- | usr.bin/aucat/sock.h | 4 |
10 files changed, 154 insertions, 193 deletions
diff --git a/usr.bin/aucat/abuf.h b/usr.bin/aucat/abuf.h index 6ce365dc085..e6180a54e2a 100644 --- a/usr.bin/aucat/abuf.h +++ b/usr.bin/aucat/abuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: abuf.h,v 1.22 2010/04/06 20:07:01 ratchov Exp $ */ +/* $OpenBSD: abuf.h,v 1.23 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -19,11 +19,6 @@ #include <sys/queue.h> -#define XRUN_IGNORE 0 /* on xrun silently insert/discard samples */ -#define XRUN_SYNC 1 /* catchup to sync to the mix/sub */ -#define XRUN_ERROR 2 /* xruns are errors, eof/hup buffer */ -#define MIDI_MSGMAX 16 /* max size of MIDI messaage */ - struct aproc; struct aparams; @@ -62,6 +57,7 @@ struct abuf { unsigned used; /* bytes used from ``msg'' */ unsigned idx; /* actual MIDI message size */ unsigned len; /* MIDI message length */ +#define MIDI_MSGMAX 16 /* max size of MIDI messaage */ unsigned char msg[MIDI_MSGMAX]; } midi; } r; @@ -75,7 +71,7 @@ struct abuf { } mix; struct { unsigned done; /* frames copied */ - unsigned xrun; /* overrun policy */ + unsigned xrun; /* overrun policy, one of XRUN_XXX */ int silence; /* silence to add on next write */ } sub; } w; diff --git a/usr.bin/aucat/amsg.h b/usr.bin/aucat/amsg.h index 552afa7f8d8..dca82864639 100644 --- a/usr.bin/aucat/amsg.h +++ b/usr.bin/aucat/amsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: amsg.h,v 1.17 2010/06/05 12:45:48 ratchov Exp $ */ +/* $OpenBSD: amsg.h,v 1.18 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -18,6 +18,7 @@ #define AMSG_H #include <stdint.h> +#include "conf.h" /* * WARNING: since the protocol may be simultaneously used by static @@ -46,9 +47,6 @@ struct amsg { union { struct amsg_par { uint8_t legacy_mode; /* compat for old libs */ -#define AMSG_IGNORE 0 /* loose sync */ -#define AMSG_SYNC 1 /* resync after xrun */ -#define AMSG_ERROR 2 /* kill the stream */ uint8_t xrun; /* one of above */ uint8_t bps; /* bytes per sample */ uint8_t bits; /* actually used bits */ @@ -84,13 +82,7 @@ struct amsg { uint32_t ctl; } vol; struct amsg_hello { -#define AMSG_PLAY 0x1 /* audio playback */ -#define AMSG_REC 0x2 /* audio recording */ -#define AMSG_MIDIIN 0x4 /* MIDI thru input */ -#define AMSG_MIDIOUT 0x8 /* MIDI thru output */ -#define AMSG_MON 0x10 /* audio monitoring */ -#define AMSG_RECMASK (AMSG_REC | AMSG_MON) /* can record ? */ - uint16_t proto; /* protocol type */ + uint16_t mode; /* bitmap of MODE_XXX */ #define AMSG_VERSION 3 uint8_t version; /* protocol version */ uint8_t reserved1[5]; /* for future use */ diff --git a/usr.bin/aucat/aproc.c b/usr.bin/aucat/aproc.c index be615b34277..c642088ed4c 100644 --- a/usr.bin/aucat/aproc.c +++ b/usr.bin/aucat/aproc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aproc.c,v 1.59 2010/05/07 07:15:50 ratchov Exp $ */ +/* $OpenBSD: aproc.c,v 1.60 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -1042,6 +1042,10 @@ mix_setmaster(struct aproc *p) * uses channels that have no intersection, they are * counted only once because they don't need to * share their volume + * + * XXX: this is wrong, this is not optimal if we have two + * buckets of N and N' clients, in which case we should + * get 1/N and 1/N' respectively */ n = 0; LIST_FOREACH(i, &p->ins, ient) { @@ -1083,41 +1087,6 @@ mix_clear(struct aproc *p) obuf->w.mix.todo = 0; } -void -mix_prime(struct aproc *p) -{ - struct abuf *obuf = LIST_FIRST(&p->outs); - unsigned todo, count; - - for (;;) { - if (!ABUF_WOK(obuf)) - break; - todo = p->u.mix.maxlat - p->u.mix.lat; - mix_bzero(obuf, todo); - count = obuf->w.mix.todo; - if (count > todo) - count = todo; - if (count == 0) - break; - obuf->w.mix.todo -= count; - p->u.mix.lat += count; - abuf_wcommit(obuf, count); - if (APROC_OK(p->u.mix.mon)) - mon_snoop(p->u.mix.mon, obuf, 0, count); - abuf_flush(obuf); - } -#ifdef DEBUG - if (debug_level >= 3) { - aproc_dbg(p); - dbg_puts(": prime: lat/maxlat="); - dbg_puti(p->u.mix.lat); - dbg_puts("/"); - dbg_puti(p->u.mix.maxlat); - dbg_puts("\n"); - } -#endif -} - /* * Gracefully terminate the mixer: raise the APROC_QUIT flag * and let the rest of the code do the job. If there are neither diff --git a/usr.bin/aucat/aucat.c b/usr.bin/aucat/aucat.c index 88d91d2534f..a2c9c90e345 100644 --- a/usr.bin/aucat/aucat.c +++ b/usr.bin/aucat/aucat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aucat.c,v 1.105 2010/09/08 22:07:26 deraadt Exp $ */ +/* $OpenBSD: aucat.c,v 1.106 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -691,7 +691,7 @@ aucat_main(int argc, char **argv) if (n_flag) { d = dev_new_loop(&cd->ipar, &cd->opar, cd->bufsz); } else { - d = dev_new_sio(cd->path, cd->mode, + d = dev_new_sio(cd->path, cd->mode | MODE_MIDIMASK, &cd->ipar, &cd->opar, cd->bufsz, cd->round, cd->hold); } @@ -744,7 +744,7 @@ aucat_main(int argc, char **argv) SLIST_REMOVE_HEAD(&cd->opts, entry); opt_new(cs->path, d, &cs->opar, &cs->ipar, MIDI_TO_ADATA(cs->vol), cs->mmc, - cs->join, cs->mode); + cs->join, cs->mode | MODE_MIDIMASK); free(cs); } free(cd); @@ -1018,7 +1018,7 @@ midicat_main(int argc, char **argv) while (!SLIST_EMPTY(&cd->opts)) { cs = SLIST_FIRST(&cd->opts); SLIST_REMOVE_HEAD(&cd->opts, entry); - opt_new(cs->path, d, NULL, NULL, 0, 0, 0, 0); + opt_new(cs->path, d, NULL, NULL, 0, 0, 0, MODE_MIDIMASK); free(cs); } free(cd); diff --git a/usr.bin/aucat/conf.h b/usr.bin/aucat/conf.h index 1923cd0279e..adbe17b12fe 100644 --- a/usr.bin/aucat/conf.h +++ b/usr.bin/aucat/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.15 2010/04/06 20:07:01 ratchov Exp $ */ +/* $OpenBSD: conf.h,v 1.16 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -47,4 +47,25 @@ extern int debug_level; */ #define MTC_SEC 2400 /* 1 second is 2400 ticks */ +/* + * device or sub-device mode, must be a superset of corresponding SIO_XXX + * and MIO_XXX constants + */ +#define MODE_PLAY 0x01 /* allowed to play */ +#define MODE_REC 0x02 /* allowed to rec */ +#define MODE_MIDIOUT 0x04 /* allowed to read midi */ +#define MODE_MIDIIN 0x08 /* allowed to write midi */ +#define MODE_MON 0x10 /* allowed to monitor */ +#define MODE_LOOP 0x20 /* deviceless mode */ +#define MODE_RECMASK (MODE_REC | MODE_MON) +#define MODE_AUDIOMASK (MODE_REC | MODE_MON | MODE_PLAY) +#define MODE_MIDIMASK (MODE_MIDIIN | MODE_MIDIOUT) + +/* + * underrun/overrun policies, must be the same as SIO_XXX + */ +#define XRUN_IGNORE 0 /* on xrun silently insert/discard samples */ +#define XRUN_SYNC 1 /* catchup to sync to the mix/sub */ +#define XRUN_ERROR 2 /* xruns are errors, eof/hup buffer */ + #endif /* !defined(CONF_H) */ diff --git a/usr.bin/aucat/dev.c b/usr.bin/aucat/dev.c index e56a465e7a7..b09808ce12b 100644 --- a/usr.bin/aucat/dev.c +++ b/usr.bin/aucat/dev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dev.c,v 1.63 2010/07/31 08:46:56 ratchov Exp $ */ +/* $OpenBSD: dev.c,v 1.64 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -166,7 +166,7 @@ dev_new_loop(struct aparams *dipar, struct aparams *dopar, unsigned bufsz) d->rate = rate; d->reqround = (bufsz + 1) / 2; d->reqbufsz = d->reqround * 2; - d->reqmode = MODE_PLAY | MODE_REC | MODE_LOOP; + d->reqmode = MODE_PLAY | MODE_REC | MODE_LOOP | MODE_MIDIMASK; d->pstate = DEV_CLOSED; d->hold = 0; d->path = "loop"; @@ -188,7 +188,7 @@ dev_new_thru(void) perror("malloc"); exit(1); } - d->reqmode = 0; + d->reqmode = MODE_MIDIMASK; d->pstate = DEV_CLOSED; d->hold = 0; d->path = "midithru"; @@ -289,8 +289,11 @@ dev_open(struct dev *d) * Create the midi control end, or a simple thru box * if there's no device */ - d->midi = (d->mode == 0) ? thru_new("thru") : ctl_new("ctl", d); - d->midi->refs++; + if (d->mode & MODE_MIDIMASK) { + d->midi = (d->mode & (MODE_PLAY | MODE_RECMASK)) ? + ctl_new("ctl", d) : thru_new("thru"); + d->midi->refs++; + } /* * Create mixer, demuxer and monitor diff --git a/usr.bin/aucat/midi.c b/usr.bin/aucat/midi.c index aa2b6884a3f..8001f118182 100644 --- a/usr.bin/aucat/midi.c +++ b/usr.bin/aucat/midi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.28 2010/07/06 01:12:45 ratchov Exp $ */ +/* $OpenBSD: midi.c,v 1.29 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -560,20 +560,19 @@ ctl_getidx(struct aproc *p, char *who) umap |= (1 << i); } for (unit = 0; ; unit++) { - if (unit == CTL_NSLOT) + if (unit == CTL_NSLOT) { +#ifdef DEBUG + if (debug_level >= 1) { + dbg_puts(name); + dbg_puts(": too many instances"); + } +#endif return -1; + } if ((umap & (1 << unit)) == 0) break; } -#ifdef DEBUG - if (debug_level >= 3) { - aproc_dbg(p); - dbg_puts(": new control name is "); - dbg_puts(name); - dbg_putu(unit); - dbg_puts("\n"); - } -#endif + /* * find a free controller slot with the same name/unit */ @@ -583,7 +582,8 @@ ctl_getidx(struct aproc *p, char *who) slot->unit == unit) { #ifdef DEBUG if (debug_level >= 3) { - aproc_dbg(p); + dbg_puts(name); + dbg_putu(unit); dbg_puts(": found slot "); dbg_putu(i); dbg_puts("\n"); @@ -608,8 +608,16 @@ ctl_getidx(struct aproc *p, char *who) bestidx = i; } } - if (bestidx == CTL_NSLOT) + if (bestidx == CTL_NSLOT) { +#ifdef DEBUG + if (debug_level >= 1) { + dbg_puts(name); + dbg_putu(unit); + dbg_puts(": out of mixer slots\n"); + } +#endif return -1; + } slot = p->u.ctl.slot + bestidx; if (slot->name[0] != '\0') slot->vol = MIDI_MAXCTL; @@ -618,7 +626,8 @@ ctl_getidx(struct aproc *p, char *who) slot->unit = unit; #ifdef DEBUG if (debug_level >= 3) { - aproc_dbg(p); + dbg_puts(name); + dbg_putu(unit); dbg_puts(": overwritten slot "); dbg_putu(bestidx); dbg_puts("\n"); diff --git a/usr.bin/aucat/opt.h b/usr.bin/aucat/opt.h index 79cb4164f45..8ef3fe1e40d 100644 --- a/usr.bin/aucat/opt.h +++ b/usr.bin/aucat/opt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: opt.h,v 1.8 2010/06/04 06:15:28 ratchov Exp $ */ +/* $OpenBSD: opt.h,v 1.9 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -31,16 +31,7 @@ struct opt { struct aparams rpar; /* template for clients read params */ int mmc; /* true if MMC control enabled */ int join; /* true if join/expand enabled */ -#define MODE_PLAY 0x1 /* allowed to play */ -#define MODE_REC 0x2 /* allowed to rec */ -#define MODE_MIDIIN 0x4 /* allowed to read midi */ -#define MODE_MIDIOUT 0x8 /* allowed to write midi */ -#define MODE_MON 0x10 /* allowed to monitor */ -#define MODE_LOOP 0x20 /* deviceless mode */ -#define MODE_RECMASK (MODE_REC | MODE_MON) -#define MODE_AUDIOMASK (MODE_REC | MODE_MON | MODE_PLAY) -#define MODE_MIDIMASK (MODE_MIDIIN | MODE_MIDIOUT) - unsigned mode; /* bitmap of above */ + unsigned mode; /* bitmap of MODE_XXX */ struct dev *dev; /* device to which we're attached */ }; diff --git a/usr.bin/aucat/sock.c b/usr.bin/aucat/sock.c index 4eec95f70e6..c6c9c59568a 100644 --- a/usr.bin/aucat/sock.c +++ b/usr.bin/aucat/sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.c,v 1.50 2010/06/05 16:00:52 ratchov Exp $ */ +/* $OpenBSD: sock.c,v 1.51 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -57,7 +57,9 @@ struct fileops sock_ops = { void sock_dbg(struct sock *f) { - static char *pstates[] = { "hel", "ini", "sta", "rdy", "run", "mid" }; + static char *pstates[] = { + "hel", "ini", "sta", "rdy", "run", "stp", "mid" + }; static char *rstates[] = { "rdat", "rmsg", "rret" }; static char *wstates[] = { "widl", "wmsg", "wdat" }; struct aproc *midi; @@ -180,7 +182,7 @@ rsock_opos(struct aproc *p, struct abuf *obuf, int delta) { struct sock *f = (struct sock *)p->u.io.file; - if (f->mode & AMSG_RECMASK) + if (f->mode & MODE_RECMASK) return; f->delta += delta; @@ -279,7 +281,7 @@ wsock_ipos(struct aproc *p, struct abuf *obuf, int delta) { struct sock *f = (struct sock *)p->u.io.file; - if (!(f->mode & AMSG_RECMASK)) + if (!(f->mode & MODE_RECMASK)) return; f->delta += delta; @@ -351,7 +353,7 @@ sock_new(struct fileops *ops, int fd) f->mode = 0; f->opt = NULL; f->dev = NULL; - f->xrun = AMSG_IGNORE; + f->xrun = XRUN_IGNORE; f->delta = 0; f->tickpending = 0; f->startpos = 0; @@ -413,14 +415,14 @@ sock_allocbuf(struct sock *f) bufsz = f->bufsz + f->dev->bufsz / f->dev->round * f->round; f->pstate = SOCK_START; - if (f->mode & AMSG_PLAY) { + if (f->mode & MODE_PLAY) { rbuf = abuf_new(bufsz, &f->rpar); aproc_setout(f->pipe.file.rproc, rbuf); if (!ABUF_WOK(rbuf) || (f->pipe.file.state & FILE_EOF)) f->pstate = SOCK_READY; f->rmax = bufsz * aparams_bpf(&f->rpar); } - if (f->mode & AMSG_RECMASK) { + if (f->mode & MODE_RECMASK) { wbuf = abuf_new(bufsz, &f->wpar); aproc_setin(f->pipe.file.wproc, wbuf); f->walign = f->round; @@ -442,7 +444,7 @@ sock_allocbuf(struct sock *f) dbg_puts("\n"); } #endif - if (f->mode & AMSG_PLAY) { + if (f->mode & MODE_PLAY) { f->pstate = SOCK_START; } else { f->pstate = SOCK_READY; @@ -490,9 +492,7 @@ sock_startreq(void *arg) } #endif (void)sock_attach(f, 0); -} - -/* +}/* * Callback invoked by MMC stop */ void @@ -542,7 +542,7 @@ sock_quitreq(void *arg) } /* - * Attach play and/or record buffers to dev->mix and/or dev->sub. + * Attach play and/or record buffers to the device */ void sock_attach(struct sock *f, int force) @@ -591,7 +591,7 @@ sock_attach(struct sock *f, int force) wbuf, &f->wpar, f->opt->join ? f->opt->wpar.cmax - f->opt->wpar.cmin + 1 : 0, f->xrun, f->opt->maxweight); - if (f->mode & AMSG_PLAY) + if (f->mode & MODE_PLAY) dev_setvol(f->dev, rbuf, MIDI_TO_ADATA(f->vol)); /* @@ -835,7 +835,7 @@ sock_setpar(struct sock *f) f->rpar.le = f->wpar.le = p->le ? 1 : 0; if (AMSG_ISSET(p->msb)) f->rpar.msb = f->wpar.msb = p->msb ? 1 : 0; - if (AMSG_ISSET(p->rchan) && (f->mode & AMSG_RECMASK)) { + if (AMSG_ISSET(p->rchan) && (f->mode & MODE_RECMASK)) { if (p->rchan < 1) p->rchan = 1; if (p->rchan > NCHAN_MAX) @@ -855,7 +855,7 @@ sock_setpar(struct sock *f) } #endif } - if (AMSG_ISSET(p->pchan) && (f->mode & AMSG_PLAY)) { + if (AMSG_ISSET(p->pchan) && (f->mode & MODE_PLAY)) { if (p->pchan < 1) p->pchan = 1; if (p->pchan > NCHAN_MAX) @@ -905,9 +905,9 @@ sock_setpar(struct sock *f) #endif } if (AMSG_ISSET(p->xrun)) { - if (p->xrun != AMSG_IGNORE && - p->xrun != AMSG_SYNC && - p->xrun != AMSG_ERROR) { + if (p->xrun != XRUN_IGNORE && + p->xrun != XRUN_SYNC && + p->xrun != XRUN_ERROR) { #ifdef DEBUG if (debug_level >= 1) { sock_dbg(f); @@ -919,8 +919,8 @@ sock_setpar(struct sock *f) return 0; } f->xrun = p->xrun; - if (f->opt->mmc && f->xrun == AMSG_IGNORE) - f->xrun = AMSG_SYNC; + if (f->opt->mmc && f->xrun == XRUN_IGNORE) + f->xrun = XRUN_SYNC; #ifdef DEBUG if (debug_level >= 3) { sock_dbg(f); @@ -931,7 +931,7 @@ sock_setpar(struct sock *f) #endif } if (AMSG_ISSET(p->appbufsz)) { - rate = (f->mode & AMSG_PLAY) ? f->rpar.rate : f->wpar.rate; + rate = (f->mode & MODE_PLAY) ? f->rpar.rate : f->wpar.rate; min = 1; max = 1 + rate / f->dev->round; min *= f->round; @@ -961,11 +961,11 @@ sock_setpar(struct sock *f) dbg_puts(f->pipe.file.name); dbg_puts(": buffer size = "); dbg_putu(f->bufsz); - if (f->mode & AMSG_PLAY) { + if (f->mode & MODE_PLAY) { dbg_puts(", play = "); aparams_dbg(&f->rpar); } - if (f->mode & AMSG_RECMASK) { + if (f->mode & MODE_RECMASK) { dbg_puts(", rec:"); aparams_dbg(&f->wpar); } @@ -979,18 +979,19 @@ sock_setpar(struct sock *f) * allocate buffers, so client can start filling write-end. */ void -sock_midiattach(struct sock *f, unsigned mode) +sock_midiattach(struct sock *f) { struct abuf *rbuf = NULL, *wbuf = NULL; - if (mode & AMSG_MIDIOUT) { + if (f->mode & MODE_MIDIOUT) { rbuf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setout(f->pipe.file.rproc, rbuf); } - if (mode & AMSG_MIDIIN) { + if (f->mode & MODE_MIDIIN) { wbuf = abuf_new(MIDI_BUFSZ, &aparams_none); aproc_setin(f->pipe.file.wproc, wbuf); } + f->pstate = SOCK_MIDI; dev_midiattach(f->dev, rbuf, wbuf); } @@ -1004,8 +1005,8 @@ sock_hello(struct sock *f) sock_dbg(f); dbg_puts(": hello from <"); dbg_puts(p->who); - dbg_puts(">, proto = "); - dbg_putx(p->proto); + dbg_puts(">, mode = "); + dbg_putx(p->mode); dbg_puts(", ver "); dbg_putu(p->version); dbg_puts("\n"); @@ -1017,7 +1018,26 @@ sock_hello(struct sock *f) sock_dbg(f); dbg_puts(": "); dbg_putu(p->version); - dbg_puts(": bad version\n"); + dbg_puts(": unsupported protocol version\n"); + } +#endif + return 0; + } + switch (p->mode) { + case MODE_MIDIIN: + case MODE_MIDIOUT: + case MODE_MIDIOUT | MODE_MIDIIN: + case MODE_REC: + case MODE_PLAY: + case MODE_PLAY | MODE_REC: + break; + default: +#ifdef DEBUG + if (debug_level >= 1) { + sock_dbg(f); + dbg_puts(": "); + dbg_putx(p->mode); + dbg_puts(": unsupported mode\n"); } #endif return 0; @@ -1027,85 +1047,45 @@ sock_hello(struct sock *f) return 0; if (!dev_ref(f->opt->dev)) return 0; + if ((p->mode & MODE_REC) && (f->opt->mode & MODE_MON)) { + p->mode &= ~MODE_REC; + p->mode |= MODE_MON; + } f->dev = f->opt->dev; - - if (APROC_OK(f->dev->midi) && (p->proto & (AMSG_MIDIIN | AMSG_MIDIOUT))) { - if (p->proto & ~(AMSG_MIDIIN | AMSG_MIDIOUT)) { + f->mode = (p->mode & f->opt->mode) & f->dev->mode; #ifdef DEBUG - if (debug_level >= 1) { - sock_dbg(f); - dbg_puts(": "); - dbg_putx(p->proto); - dbg_puts(": bad hello protocol\n"); - } -#endif - return 0; - } - f->mode = p->proto; - f->pstate = SOCK_MIDI; - sock_midiattach(f, p->proto); - return 1; + if (debug_level >= 3) { + sock_dbg(f); + dbg_puts(": using mode = "); + dbg_putx(f->mode); + dbg_puts("\n"); } - if (f->opt->mode & MODE_RECMASK) - f->wpar = f->opt->wpar; - if (f->opt->mode & MODE_PLAY) - f->rpar = f->opt->rpar; - if (f->opt->mmc) - f->xrun = AMSG_SYNC; - f->bufsz = f->dev->bufsz; - f->round = f->dev->round; - if ((p->proto & ~(AMSG_PLAY | AMSG_REC)) != 0 || - (p->proto & (AMSG_PLAY | AMSG_REC)) == 0) { +#endif + if (f->mode != p->mode) { #ifdef DEBUG if (debug_level >= 1) { sock_dbg(f); - dbg_puts(": "); - dbg_putx(p->proto); - dbg_puts(": unsupported hello protocol\n"); + dbg_puts(": requested mode not available\n"); } #endif return 0; } - f->mode = 0; - if (p->proto & AMSG_PLAY) { - if (!APROC_OK(f->dev->mix) || !(f->opt->mode & MODE_PLAY)) { -#ifdef DEBUG - if (debug_level >= 1) { - sock_dbg(f); - dbg_puts(": playback not available\n"); - } -#endif - return 0; - } - f->mode |= AMSG_PLAY; - } - if (p->proto & AMSG_REC) { - if (!(APROC_OK(f->dev->sub) && (f->opt->mode & MODE_REC)) && - !(APROC_OK(f->dev->submon) && (f->opt->mode & MODE_MON))) { -#ifdef DEBUG - if (debug_level >= 1) { - sock_dbg(f); - dbg_puts(": recording not available\n"); - } -#endif - return 0; - } - f->mode |= (f->opt->mode & MODE_MON) ? AMSG_MON : AMSG_REC; - } - if (APROC_OK(f->dev->midi)) { - f->slot = ctl_slotnew(f->dev->midi, - p->who, &ctl_sockops, f, - f->opt->mmc); - if (f->slot < 0) { -#ifdef DEBUG - if (debug_level >= 1) { - sock_dbg(f); - dbg_puts(": out of mixer slots\n"); - } -#endif - return 0; - } + if (f->mode & (MODE_MIDIOUT | MODE_MIDIIN)) { + sock_midiattach(f); + return 1; } + if (f->mode & MODE_PLAY) + f->rpar = f->opt->rpar; + if (f->mode & MODE_RECMASK) + f->wpar = f->opt->wpar; + f->xrun = (f->opt->mmc) ? XRUN_SYNC : XRUN_IGNORE; + f->bufsz = f->dev->bufsz; + f->round = f->dev->round; + f->slot = ctl_slotnew(f->dev->midi, p->who, + &ctl_sockops, f, + f->opt->mmc); + if (f->slot < 0) + return 0; f->pstate = SOCK_INIT; return 1; } @@ -1139,7 +1119,7 @@ sock_execmsg(struct sock *f) aproc_del(f->pipe.file.rproc); return 0; } - if (!(f->mode & AMSG_PLAY)) { + if (!(f->mode & MODE_PLAY)) { #ifdef DEBUG if (debug_level >= 1) { sock_dbg(f); @@ -1295,7 +1275,7 @@ sock_execmsg(struct sock *f) AMSG_INIT(m); m->cmd = AMSG_GETPAR; m->u.par.legacy_mode = f->mode; - if (f->mode & AMSG_PLAY) { + if (f->mode & MODE_PLAY) { m->u.par.bits = f->rpar.bits; m->u.par.bps = f->rpar.bps; m->u.par.sig = f->rpar.sig; @@ -1304,7 +1284,7 @@ sock_execmsg(struct sock *f) m->u.par.rate = f->rpar.rate; m->u.par.pchan = f->rpar.cmax - f->rpar.cmin + 1; } - if (f->mode & AMSG_RECMASK) { + if (f->mode & MODE_RECMASK) { m->u.par.bits = f->wpar.bits; m->u.par.bps = f->wpar.bps; m->u.par.sig = f->wpar.sig; @@ -1446,7 +1426,7 @@ sock_execmsg(struct sock *f) dbg_puts(": RRET done\n"); } #endif - if (f->pstate == SOCK_MIDI && (f->mode & AMSG_MIDIOUT)) { + if (f->pstate == SOCK_MIDI && (f->mode & MODE_MIDIOUT)) { f->rstate = SOCK_RDATA; f->rtodo = 0; } else { @@ -1660,7 +1640,7 @@ sock_return(struct sock *f) dbg_puts(": sent RRET message\n"); } #endif - if (f->pstate == SOCK_MIDI && (f->mode & AMSG_MIDIOUT)) { + if (f->pstate == SOCK_MIDI && (f->mode & MODE_MIDIOUT)) { f->rstate = SOCK_RDATA; f->rtodo = 0; } else { diff --git a/usr.bin/aucat/sock.h b/usr.bin/aucat/sock.h index 190b4a847cf..266ddc42530 100644 --- a/usr.bin/aucat/sock.h +++ b/usr.bin/aucat/sock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sock.h,v 1.17 2010/06/05 12:45:48 ratchov Exp $ */ +/* $OpenBSD: sock.h,v 1.18 2010/10/21 18:57:42 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -50,7 +50,7 @@ struct sock { #define SOCK_STOP 5 /* draining rec buffers */ #define SOCK_MIDI 6 /* raw byte stream (midi) */ unsigned pstate; /* one of the above */ - unsigned mode; /* a set of AMSG_PLAY, AMSG_REC */ + unsigned mode; /* bitmask of MODE_XXX */ struct aparams rpar; /* read (ie play) parameters */ struct aparams wpar; /* write (ie rec) parameters */ int delta; /* pos. change to send */ |