From: ratchov Date: Fri, 29 Apr 2022 09:12:57 +0000 (+0000) Subject: Wait until the buffer is drained before closing the device X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0add871791821558a4c201885b630835a8a45ed0;p=openbsd Wait until the buffer is drained before closing the device Fixes last few samples not being played when very large buffers are used. --- 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 * @@ -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 * @@ -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 */