Commit b6004b68 authored by Max Kellermann's avatar Max Kellermann

output/Source: release the mutex while the filter runs

The filter can take some time to finish, even more so on a weak machine with a saturated CPU. By not holding the mutex during that time, we can reduce PlayerThread latency a lot, because that thread needs to synchronize a lot with all outputs.
parent 86d3b25a
......@@ -264,7 +264,7 @@ AudioOutput::WaitForDelay()
bool
AudioOutput::FillSourceOrClose()
try {
return source.Fill();
return source.Fill(mutex);
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to filter for output \"%s\" [%s]",
name, plugin.name);
......
......@@ -23,6 +23,7 @@
#include "filter/FilterInternal.hxx"
#include "filter/plugins/ReplayGainFilterPlugin.hxx"
#include "pcm/PcmMix.hxx"
#include "thread/Mutex.hxx"
#include "util/ConstBuffer.hxx"
#include "util/RuntimeError.hxx"
......@@ -187,7 +188,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
}
bool
AudioOutputSource::Fill()
AudioOutputSource::Fill(Mutex &mutex)
{
if (current_chunk != nullptr && pending_tag == nullptr &&
pending_data.IsEmpty())
......@@ -203,6 +204,10 @@ AudioOutputSource::Fill()
pending_tag = current_chunk->tag;
try {
/* release the mutex while the filter runs, because
that may take a while */
const ScopeUnlock unlock(mutex);
pending_data = pending_data.FromVoid(FilterChunk(*current_chunk));
} catch (...) {
current_chunk = nullptr;
......
......@@ -36,6 +36,7 @@
struct MusicChunk;
struct Tag;
class Mutex;
class Filter;
class PreparedFilter;
......@@ -147,10 +148,13 @@ public:
*
* Throws std::runtime_error on error
*
* @param mutex the #Mutex which protects the
* #SharedPipeConsumer; it is locked by the caller, and may be
* unlocked temporarily by this method
* @return true if any input is available, false if the source
* has (temporarily?) run empty
*/
bool Fill();
bool Fill(Mutex &mutex);
/**
* Reads the #Tag to be processed. Be sure to call Fill()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment