diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index a93f5c961..903429fb5 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -29,6 +29,8 @@ #include "thread/Thread.hxx" #include "system/PeriodClock.hxx" +#include + class PreparedFilter; class MusicPipe; class EventLoop; @@ -255,6 +257,14 @@ struct AudioOutput { */ AudioOutputSource source; + /** + * The error that occurred in the output thread. It is + * cleared whenever the output is opened successfully. + * + * Protected by #mutex. + */ + std::exception_ptr last_error; + /** * Throws #std::runtime_error on error. */ diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index d2749a2ad..f0b2ab085 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -405,11 +405,14 @@ AudioOutput::Task() break; case Command::ENABLE: + last_error = nullptr; + try { Enable(); } catch (const std::runtime_error &e) { LogError(e); fail_timer.Update(); + last_error = std::current_exception(); } CommandFinished(); @@ -421,11 +424,14 @@ AudioOutput::Task() break; case Command::OPEN: + last_error = nullptr; + try { Open(); } catch (const std::runtime_error &e) { LogError(e); fail_timer.Update(); + last_error = std::current_exception(); } CommandFinished();