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

This commit is contained in:
Max Kellermann 2018-01-02 17:15:59 +01:00
parent 1607754771
commit ae7fcf4c6b
2 changed files with 15 additions and 17 deletions

View File

@ -420,6 +420,17 @@ public:
void LockAllowPlay() noexcept;
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.
* Caller must lock the mutex.

View File

@ -109,8 +109,7 @@ AudioOutputControl::InternalEnable() noexcept
return true;
} catch (...) {
LogError(std::current_exception());
fail_timer.Update();
last_error = std::current_exception();
Failure(std::current_exception());
return false;
}
}
@ -162,8 +161,7 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
}
} catch (...) {
LogError(std::current_exception());
fail_timer.Update();
last_error = std::current_exception();
Failure(std::current_exception());
}
if (f != in_audio_format || f != output->out_audio_format)
@ -234,13 +232,8 @@ try {
} catch (...) {
FormatError(std::current_exception(),
"Failed to filter for %s", GetLogName());
last_error = std::current_exception();
Failure(std::current_exception());
InternalClose(false);
/* don't automatically reopen this device for 10
seconds */
fail_timer.Update();
return false;
}
@ -280,15 +273,9 @@ AudioOutputControl::PlayChunk() noexcept
} catch (...) {
FormatError(std::current_exception(),
"Failed to play on %s", GetLogName());
last_error = std::current_exception();
Failure(std::current_exception());
InternalClose(false);
/* don't automatically reopen this device for
10 seconds */
assert(!fail_timer.IsDefined());
fail_timer.Update();
return false;
}