Commit ae7fcf4c authored by Max Kellermann's avatar Max Kellermann

output/Thread: move common code to method Failure()

parent 16077547
...@@ -421,6 +421,17 @@ public: ...@@ -421,6 +421,17 @@ public:
private: private:
/** /**
* An error has occurred and this output is defunct.
*/
void Failure(std::exception_ptr e) noexcept {
last_error = e;
/* don't automatically reopen this device for 10
seconds */
fail_timer.Update();
}
/**
* Runs inside the OutputThread. * Runs inside the OutputThread.
* Caller must lock the mutex. * Caller must lock the mutex.
* Handles exceptions. * Handles exceptions.
......
...@@ -109,8 +109,7 @@ AudioOutputControl::InternalEnable() noexcept ...@@ -109,8 +109,7 @@ AudioOutputControl::InternalEnable() noexcept
return true; return true;
} catch (...) { } catch (...) {
LogError(std::current_exception()); LogError(std::current_exception());
fail_timer.Update(); Failure(std::current_exception());
last_error = std::current_exception();
return false; return false;
} }
} }
...@@ -162,8 +161,7 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format, ...@@ -162,8 +161,7 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
} }
} catch (...) { } catch (...) {
LogError(std::current_exception()); LogError(std::current_exception());
fail_timer.Update(); Failure(std::current_exception());
last_error = std::current_exception();
} }
if (f != in_audio_format || f != output->out_audio_format) if (f != in_audio_format || f != output->out_audio_format)
...@@ -234,13 +232,8 @@ try { ...@@ -234,13 +232,8 @@ try {
} catch (...) { } catch (...) {
FormatError(std::current_exception(), FormatError(std::current_exception(),
"Failed to filter for %s", GetLogName()); "Failed to filter for %s", GetLogName());
last_error = std::current_exception(); Failure(std::current_exception());
InternalClose(false); InternalClose(false);
/* don't automatically reopen this device for 10
seconds */
fail_timer.Update();
return false; return false;
} }
...@@ -280,15 +273,9 @@ AudioOutputControl::PlayChunk() noexcept ...@@ -280,15 +273,9 @@ AudioOutputControl::PlayChunk() noexcept
} catch (...) { } catch (...) {
FormatError(std::current_exception(), FormatError(std::current_exception(),
"Failed to play on %s", GetLogName()); "Failed to play on %s", GetLogName());
last_error = std::current_exception(); Failure(std::current_exception());
InternalClose(false); InternalClose(false);
/* don't automatically reopen this device for
10 seconds */
assert(!fail_timer.IsDefined());
fail_timer.Update();
return false; return false;
} }
......
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