Commit a72a02f0 authored by Max Kellermann's avatar Max Kellermann

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

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