Commit 3010d182 authored by Max Kellermann's avatar Max Kellermann

output/Internal: move "really_enabled" flag to class AudioOutputControl

parent a72a02f0
...@@ -132,7 +132,7 @@ AudioOutputControl::EnableAsync() ...@@ -132,7 +132,7 @@ AudioOutputControl::EnableAsync()
/* don't bother to start the thread now if the /* don't bother to start the thread now if the
device doesn't even have a enable() method; device doesn't even have a enable() method;
just assign the variable and we're done */ just assign the variable and we're done */
output->really_enabled = true; really_enabled = true;
return; return;
} }
...@@ -147,11 +147,11 @@ AudioOutputControl::DisableAsync() noexcept ...@@ -147,11 +147,11 @@ AudioOutputControl::DisableAsync() noexcept
{ {
if (!thread.IsDefined()) { if (!thread.IsDefined()) {
if (output->plugin.disable == nullptr) if (output->plugin.disable == nullptr)
output->really_enabled = false; really_enabled = false;
else else
/* if there's no thread yet, the device cannot /* if there's no thread yet, the device cannot
be enabled */ be enabled */
assert(!output->really_enabled); assert(!really_enabled);
return; return;
} }
...@@ -162,7 +162,7 @@ AudioOutputControl::DisableAsync() noexcept ...@@ -162,7 +162,7 @@ AudioOutputControl::DisableAsync() noexcept
void void
AudioOutputControl::EnableDisableAsync() AudioOutputControl::EnableDisableAsync()
{ {
if (enabled == output->really_enabled) if (enabled == really_enabled)
return; return;
if (enabled) if (enabled)
...@@ -233,7 +233,7 @@ AudioOutputControl::LockUpdate(const AudioFormat audio_format, ...@@ -233,7 +233,7 @@ AudioOutputControl::LockUpdate(const AudioFormat audio_format,
{ {
const std::lock_guard<Mutex> protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (enabled && output->really_enabled) { if (enabled && really_enabled) {
if (force || !fail_timer.IsDefined() || if (force || !fail_timer.IsDefined() ||
fail_timer.Check(REOPEN_AFTER * 1000)) { fail_timer.Check(REOPEN_AFTER * 1000)) {
return Open(audio_format, mp); return Open(audio_format, mp);
......
...@@ -144,6 +144,12 @@ class AudioOutputControl { ...@@ -144,6 +144,12 @@ class AudioOutputControl {
bool enabled = true; bool enabled = true;
/** /**
* Is this device actually enabled, i.e. the "enable" method
* has succeeded?
*/
bool really_enabled = false;
/**
* Is the device paused? i.e. the output thread is in the * Is the device paused? i.e. the output thread is in the
* ao_pause() loop. * ao_pause() loop.
*/ */
......
...@@ -54,12 +54,6 @@ struct AudioOutput { ...@@ -54,12 +54,6 @@ struct AudioOutput {
Mixer *mixer = nullptr; Mixer *mixer = nullptr;
/** /**
* Is this device actually enabled, i.e. the "enable" method
* has succeeded?
*/
bool really_enabled = false;
/**
* Is the device (already) open and functional? * Is the device (already) open and functional?
* *
* This attribute may only be modified by the output thread. * This attribute may only be modified by the output thread.
......
...@@ -60,9 +60,6 @@ AudioOutputControl::CommandFinished() noexcept ...@@ -60,9 +60,6 @@ AudioOutputControl::CommandFinished() noexcept
inline void inline void
AudioOutput::Enable() AudioOutput::Enable()
{ {
if (really_enabled)
return;
try { try {
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
ao_plugin_enable(*this); ao_plugin_enable(*this);
...@@ -70,19 +67,13 @@ AudioOutput::Enable() ...@@ -70,19 +67,13 @@ AudioOutput::Enable()
std::throw_with_nested(FormatRuntimeError("Failed to enable output \"%s\" [%s]", std::throw_with_nested(FormatRuntimeError("Failed to enable output \"%s\" [%s]",
name, plugin.name)); name, plugin.name));
} }
really_enabled = true;
} }
inline void inline void
AudioOutput::Disable() noexcept AudioOutput::Disable() noexcept
{ {
if (really_enabled) { const ScopeUnlock unlock(mutex);
really_enabled = false; ao_plugin_disable(*this);
const ScopeUnlock unlock(mutex);
ao_plugin_disable(*this);
}
} }
void void
...@@ -200,10 +191,15 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format) ...@@ -200,10 +191,15 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
inline bool inline bool
AudioOutputControl::InternalEnable() noexcept AudioOutputControl::InternalEnable() noexcept
{ {
if (really_enabled)
/* already enabled */
return true;
last_error = nullptr; last_error = nullptr;
try { try {
output->Enable(); output->Enable();
really_enabled = true;
return true; return true;
} catch (const std::runtime_error &e) { } catch (const std::runtime_error &e) {
LogError(e); LogError(e);
...@@ -216,9 +212,13 @@ AudioOutputControl::InternalEnable() noexcept ...@@ -216,9 +212,13 @@ AudioOutputControl::InternalEnable() noexcept
inline void inline void
AudioOutputControl::InternalDisable() noexcept AudioOutputControl::InternalDisable() noexcept
{ {
if (!really_enabled)
return;
if (output->open) if (output->open)
output->Close(false); output->Close(false);
really_enabled = false;
output->Disable(); output->Disable();
} }
......
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