Commit a72a02f0 authored by Max Kellermann's avatar Max Kellermann

output/Thread: move Enable() call to InternalEnable()

parent 614df963
......@@ -362,6 +362,13 @@ public:
private:
/**
* Runs inside the OutputThread. Handles exceptions.
*
* @return true on success
*/
bool InternalEnable() noexcept;
/**
* Runs inside the OutputThread. Handles exceptions.
*/
void InternalDisable() noexcept;
......
......@@ -197,6 +197,22 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
}
}
inline bool
AudioOutputControl::InternalEnable() noexcept
{
last_error = nullptr;
try {
output->Enable();
return true;
} catch (const std::runtime_error &e) {
LogError(e);
fail_timer.Update();
last_error = std::current_exception();
return false;
}
}
inline void
AudioOutputControl::InternalDisable() noexcept
{
......@@ -210,14 +226,15 @@ inline void
AudioOutputControl::InternalOpen(const AudioFormat audio_format,
const MusicPipe &pipe) noexcept
{
/* enable the device (just in case the last enable has failed) */
if (!InternalEnable())
return;
last_error = nullptr;
fail_timer.Reset();
skip_delay = true;
try {
/* enable the device (just in case the last enable has failed) */
output->Enable();
output->Open(audio_format, pipe);
} catch (const std::runtime_error &e) {
LogError(e);
......@@ -459,16 +476,7 @@ AudioOutputControl::Task()
break;
case Command::ENABLE:
last_error = nullptr;
try {
output->Enable();
} catch (const std::runtime_error &e) {
LogError(e);
fail_timer.Update();
last_error = std::current_exception();
}
InternalEnable();
CommandFinished();
break;
......
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