summaryrefslogtreecommitdiff
path: root/src/output/Thread.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/output/Thread.cxx')
-rw-r--r--src/output/Thread.cxx31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx
index ac382864a..bad9e0a73 100644
--- a/src/output/Thread.cxx
+++ b/src/output/Thread.cxx
@@ -362,11 +362,42 @@ AudioOutputControl::InternalPause() noexcept
skip_delay = true;
}
+static void
+PlayFull(FilteredAudioOutput &output, ConstBuffer<void> _buffer)
+{
+ auto buffer = ConstBuffer<uint8_t>::FromVoid(_buffer);
+
+ while (!buffer.empty()) {
+ size_t nbytes = output.Play(buffer.data, buffer.size);
+ assert(nbytes > 0);
+
+ buffer.skip_front(nbytes);
+ }
+
+}
+
inline void
AudioOutputControl::InternalDrain() noexcept
{
const ScopeUnlock unlock(mutex);
+ try {
+ /* flush the filter and play its remaining output */
+
+ while (true) {
+ auto buffer = source.Flush();
+ if (buffer.IsNull())
+ break;
+
+ PlayFull(*output, buffer);
+ }
+ } catch (...) {
+ FormatError(std::current_exception(),
+ "Failed to flush filter on %s", GetLogName());
+ InternalCloseError(std::current_exception());
+ return;
+ }
+
output->Drain();
}