summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2019-09-19 05:04:34 +0000
committerratchov <ratchov@openbsd.org>2019-09-19 05:04:34 +0000
commit2d234d21aaddc277b7778c42c49ba4d603c14527 (patch)
tree1357afc39fa1d389b1405b4d0bb5e6084911e152
parentMove device buffer allocation to its own routines. (diff)
downloadwireguard-openbsd-2d234d21aaddc277b7778c42c49ba4d603c14527.tar.xz
wireguard-openbsd-2d234d21aaddc277b7778c42c49ba4d603c14527.zip
Move device slot convertions setup in its own routine.
No behabior change.
-rw-r--r--usr.bin/sndiod/dev.c67
1 files changed, 46 insertions, 21 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 773010500ca..e1745cfb7f4 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.59 2019/09/19 05:02:27 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.60 2019/09/19 05:04:34 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -82,6 +82,7 @@ void slot_attach(struct slot *);
void slot_ready(struct slot *);
void slot_allocbufs(struct slot *);
void slot_freebufs(struct slot *);
+void slot_initconv(struct slot *);
void slot_start(struct slot *);
void slot_detach(struct slot *);
void slot_stop(struct slot *);
@@ -1425,23 +1426,17 @@ dev_mmcloc(struct dev *d, unsigned int origin)
dev_mmcstart(d);
}
-
/*
* allocate buffers & conversion chain
*/
void
-slot_allocbufs(struct slot *s)
+slot_initconv(struct slot *s)
{
unsigned int dev_nch;
struct dev *d = s->dev;
if (s->mode & MODE_PLAY) {
- s->mix.bpf = s->par.bps * s->mix.nch;
- abuf_init(&s->mix.buf, s->appbufsz * s->mix.bpf);
-
dev_nch = s->opt->pmax - s->opt->pmin + 1;
- s->mix.decbuf = NULL;
- s->mix.resampbuf = NULL;
s->mix.join = 1;
s->mix.expand = 1;
if (s->opt->dup) {
@@ -1457,24 +1452,15 @@ slot_allocbufs(struct slot *s)
s->opt->pmin, s->opt->pmax);
if (!aparams_native(&s->par)) {
dec_init(&s->mix.dec, &s->par, s->mix.nch);
- s->mix.decbuf =
- xmalloc(s->round * s->mix.nch * sizeof(adata_t));
}
if (s->rate != d->rate) {
resamp_init(&s->mix.resamp, s->round, d->round,
s->mix.nch);
- s->mix.resampbuf =
- xmalloc(d->round * s->mix.nch * sizeof(adata_t));
}
}
if (s->mode & MODE_RECMASK) {
- s->sub.bpf = s->par.bps * s->sub.nch;
- abuf_init(&s->sub.buf, s->appbufsz * s->sub.bpf);
-
dev_nch = s->opt->rmax - s->opt->rmin + 1;
- s->sub.encbuf = NULL;
- s->sub.resampbuf = NULL;
s->sub.join = 1;
s->sub.expand = 1;
if (s->opt->dup) {
@@ -1491,13 +1477,9 @@ slot_allocbufs(struct slot *s)
if (s->rate != d->rate) {
resamp_init(&s->sub.resamp, d->round, s->round,
s->sub.nch);
- s->sub.resampbuf =
- xmalloc(d->round * s->sub.nch * sizeof(adata_t));
}
if (!aparams_native(&s->par)) {
enc_init(&s->sub.enc, &s->par, s->sub.nch);
- s->sub.encbuf =
- xmalloc(s->round * s->sub.nch * sizeof(adata_t));
}
/*
@@ -1517,6 +1499,49 @@ slot_allocbufs(struct slot *s)
s->appbufsz * s->sub.nch * sizeof(adata_t));
}
}
+}
+
+/*
+ * allocate buffers & conversion chain
+ */
+void
+slot_allocbufs(struct slot *s)
+{
+ struct dev *d = s->dev;
+
+ if (s->mode & MODE_PLAY) {
+ s->mix.bpf = s->par.bps * s->mix.nch;
+ abuf_init(&s->mix.buf, s->appbufsz * s->mix.bpf);
+
+ s->mix.decbuf = NULL;
+ s->mix.resampbuf = NULL;
+ if (!aparams_native(&s->par)) {
+ s->mix.decbuf =
+ xmalloc(s->round * s->mix.nch * sizeof(adata_t));
+ }
+ if (s->rate != d->rate) {
+ s->mix.resampbuf =
+ xmalloc(d->round * s->mix.nch * sizeof(adata_t));
+ }
+ }
+
+ if (s->mode & MODE_RECMASK) {
+ s->sub.bpf = s->par.bps * s->sub.nch;
+ abuf_init(&s->sub.buf, s->appbufsz * s->sub.bpf);
+
+ s->sub.encbuf = NULL;
+ s->sub.resampbuf = NULL;
+ if (s->rate != d->rate) {
+ s->sub.resampbuf =
+ xmalloc(d->round * s->sub.nch * sizeof(adata_t));
+ }
+ if (!aparams_native(&s->par)) {
+ s->sub.encbuf =
+ xmalloc(s->round * s->sub.nch * sizeof(adata_t));
+ }
+ }
+
+ slot_initconv(s);
#ifdef DEBUG
if (log_level >= 3) {