summaryrefslogtreecommitdiff
path: root/usr.bin/sndiod
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2022-04-29 09:12:58 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2022-04-29 09:12:58 +0000
commit73af0d822d2468503bcbd2d573b9737d5af42729 (patch)
tree01853d880dc4a23266d2c986438b916643ecfaa8 /usr.bin/sndiod
parent584034c420f8b87f27e1835da6d68f8d8d979391 (diff)
Wait until the buffer is drained before closing the device
Fixes last few samples not being played when very large buffers are used.
Diffstat (limited to 'usr.bin/sndiod')
-rw-r--r--usr.bin/sndiod/dev.c12
-rw-r--r--usr.bin/sndiod/dev.h3
2 files changed, 11 insertions, 4 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index b9f244be7bb..db10649c233 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.104 2022/03/15 05:53:37 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.105 2022/04/29 09:12:57 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -680,8 +680,8 @@ dev_cycle(struct dev *d)
* check if the device is actually used. If it isn't,
* then close it
*/
- if (d->slot_list == NULL && (mtc_array[0].dev != d ||
- mtc_array[0].tstate != MTC_RUN)) {
+ if (d->slot_list == NULL && d->idle >= d->bufsz &&
+ (mtc_array[0].dev != d || mtc_array[0].tstate != MTC_RUN)) {
if (log_level >= 2) {
dev_log(d);
log_puts(": device stopped\n");
@@ -744,6 +744,8 @@ dev_cycle(struct dev *d)
log_puts("\n");
}
#endif
+ d->idle = 0;
+
/*
* skip cycles for XRUN_SYNC correction
*/
@@ -858,6 +860,9 @@ dev_onmove(struct dev *d, int delta)
d->delta += delta;
+ if (d->slot_list == NULL)
+ d->idle += delta;
+
for (s = d->slot_list; s != NULL; s = snext) {
/*
* s->ops->onmove() may remove the slot
@@ -1284,6 +1289,7 @@ dev_wakeup(struct dev *d)
} else {
d->prime = 0;
}
+ d->idle = 0;
d->poffs = 0;
/*
diff --git a/usr.bin/sndiod/dev.h b/usr.bin/sndiod/dev.h
index 45ae71f47b9..3a666cf68e3 100644
--- a/usr.bin/sndiod/dev.h
+++ b/usr.bin/sndiod/dev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.h,v 1.41 2021/11/01 14:43:25 ratchov Exp $ */
+/* $OpenBSD: dev.h,v 1.42 2022/04/29 09:12:57 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -273,6 +273,7 @@ struct dev {
unsigned int mode; /* bitmap of MODE_xxx */
unsigned int bufsz, round, rate;
unsigned int prime;
+ unsigned int idle; /* cycles with no client */
unsigned int master; /* software vol. knob */
unsigned int master_enabled; /* 1 if h/w has no vo. knob */