output/Thread: move code to InternalOpen()

This commit is contained in:
Max Kellermann 2017-05-23 00:08:36 +02:00
parent 5eef146871
commit e616be0a42
2 changed files with 23 additions and 12 deletions

View File

@ -339,6 +339,12 @@ public:
void LockAllowPlay();
private:
/**
* Runs inside the OutputThread. Handles exceptions.
*/
void InternalOpen(AudioFormat audio_format,
const MusicPipe &pipe) noexcept;
/**
* Wait until the output's delay reaches zero.
*

View File

@ -203,6 +203,22 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
}
}
inline void
AudioOutputControl::InternalOpen(const AudioFormat audio_format,
const MusicPipe &pipe) noexcept
{
last_error = nullptr;
fail_timer.Reset();
try {
output->Open(audio_format, pipe);
} catch (const std::runtime_error &e) {
LogError(e);
fail_timer.Update();
last_error = std::current_exception();
}
}
void
AudioOutput::Close(bool drain)
{
@ -452,18 +468,7 @@ AudioOutputControl::Task()
break;
case Command::OPEN:
last_error = nullptr;
fail_timer.Reset();
try {
output->Open(request.audio_format,
*request.pipe);
} catch (const std::runtime_error &e) {
LogError(e);
fail_timer.Update();
last_error = std::current_exception();
}
InternalOpen(request.audio_format, *request.pipe);
CommandFinished();
break;