output/Control: pass "force" flag to LockUpdate()

Reduce overhead by eliminating MultipleOutputs::ResetReopen().
This commit is contained in:
Max Kellermann 2016-12-29 23:20:26 +01:00
parent 982d1bf662
commit db95aa250d
4 changed files with 12 additions and 32 deletions

View File

@ -383,10 +383,12 @@ public:
* Opens or closes the device, depending on the "enabled" * Opens or closes the device, depending on the "enabled"
* flag. * flag.
* *
* @param force true to ignore the #fail_timer
* @return true if the device is open * @return true if the device is open
*/ */
bool LockUpdate(const AudioFormat audio_format, bool LockUpdate(const AudioFormat audio_format,
const MusicPipe &mp); const MusicPipe &mp,
bool force);
void LockPlay(); void LockPlay();

View File

@ -145,23 +145,8 @@ MultipleOutputs::AllowPlay()
ao->LockAllowPlay(); ao->LockAllowPlay();
} }
static void
audio_output_reset_reopen(AudioOutput *ao)
{
const ScopeLock protect(ao->mutex);
ao->fail_timer.Reset();
}
void
MultipleOutputs::ResetReopen()
{
for (auto ao : outputs)
audio_output_reset_reopen(ao);
}
bool bool
MultipleOutputs::Update() MultipleOutputs::Update(bool force)
{ {
bool ret = false; bool ret = false;
@ -169,7 +154,7 @@ MultipleOutputs::Update()
return false; return false;
for (auto ao : outputs) for (auto ao : outputs)
ret = ao->LockUpdate(input_audio_format, *pipe) ret = ao->LockUpdate(input_audio_format, *pipe, force)
|| ret; || ret;
return ret; return ret;
@ -190,7 +175,7 @@ MultipleOutputs::Play(MusicChunk *chunk)
assert(chunk != nullptr); assert(chunk != nullptr);
assert(chunk->CheckFormat(input_audio_format)); assert(chunk->CheckFormat(input_audio_format));
if (!Update()) if (!Update(false))
/* TODO: obtain real error */ /* TODO: obtain real error */
throw std::runtime_error("Failed to open audio output"); throw std::runtime_error("Failed to open audio output");
@ -224,9 +209,8 @@ MultipleOutputs::Open(const AudioFormat audio_format,
input_audio_format = audio_format; input_audio_format = audio_format;
ResetReopen();
EnableDisable(); EnableDisable();
Update(); Update(true);
std::exception_ptr first_error; std::exception_ptr first_error;
@ -341,7 +325,7 @@ MultipleOutputs::Check()
void void
MultipleOutputs::Pause() MultipleOutputs::Pause()
{ {
Update(); Update(false);
for (auto ao : outputs) for (auto ao : outputs)
ao->LockPauseAsync(); ao->LockPauseAsync();

View File

@ -236,20 +236,13 @@ private:
*/ */
void AllowPlay(); void AllowPlay();
/**
* Resets the "reopen" flag on all audio devices. MPD should
* immediately retry to open the device instead of waiting for
* the timeout when the user wants to start playback.
*/
void ResetReopen();
/** /**
* Opens all output devices which are enabled, but closed. * Opens all output devices which are enabled, but closed.
* *
* @return true if there is at least open output device which * @return true if there is at least open output device which
* is open * is open
*/ */
bool Update(); bool Update(bool force);
/** /**
* Has this chunk been consumed by all audio outputs? * Has this chunk been consumed by all audio outputs?

View File

@ -159,12 +159,13 @@ AudioOutput::CloseWait()
bool bool
AudioOutput::LockUpdate(const AudioFormat audio_format, AudioOutput::LockUpdate(const AudioFormat audio_format,
const MusicPipe &mp) const MusicPipe &mp,
bool force)
{ {
const ScopeLock protect(mutex); const ScopeLock protect(mutex);
if (enabled && really_enabled) { if (enabled && really_enabled) {
if (!fail_timer.IsDefined() || if (force || !fail_timer.IsDefined() ||
fail_timer.Check(REOPEN_AFTER * 1000)) { fail_timer.Check(REOPEN_AFTER * 1000)) {
return Open(audio_format, mp); return Open(audio_format, mp);
} }