diff options
author | Max Kellermann <max@musicpd.org> | 2018-01-02 12:11:02 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-01-02 12:13:51 +0100 |
commit | 46406d6cca25c2e5a84bb45c75ee4ad4c7fcc42e (patch) | |
tree | fc4c12ceb28db027dda728b45d86826a21fd4039 | |
parent | 196df1ccd5ab747a82c0d4519cd285226e6ada6d (diff) |
output/ao: use class SafeSingleton for libao initialization
-rw-r--r-- | src/output/plugins/AoOutputPlugin.cxx | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/output/plugins/AoOutputPlugin.cxx b/src/output/plugins/AoOutputPlugin.cxx index 30de2ead6..cd40df30b 100644 --- a/src/output/plugins/AoOutputPlugin.cxx +++ b/src/output/plugins/AoOutputPlugin.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "AoOutputPlugin.hxx" #include "../OutputAPI.hxx" +#include "thread/SafeSingleton.hxx" #include "system/Error.hxx" #include "util/DivideString.hxx" #include "util/SplitString.hxx" @@ -34,9 +35,18 @@ /* An ao_sample_format, with all fields set to zero: */ static ao_sample_format OUR_AO_FORMAT_INITIALIZER; -static unsigned ao_output_ref; +class AoInit { +public: + AoInit() { + ao_initialize(); + } + + ~AoInit() noexcept { + ao_shutdown(); + } +}; -class AoOutput final : AudioOutput { +class AoOutput final : AudioOutput, SafeSingleton<AoInit> { const size_t write_size; int driver; ao_option *options = nullptr; @@ -93,11 +103,6 @@ AoOutput::AoOutput(const ConfigBlock &block) :AudioOutput(0), write_size(block.GetBlockValue("write_size", 1024u)) { - if (ao_output_ref == 0) { - ao_initialize(); - } - ao_output_ref++; - const char *value = block.GetBlockValue("driver", "default"); if (0 == strcmp(value, "default")) driver = ao_default_driver_id(); @@ -132,11 +137,6 @@ AoOutput::AoOutput(const ConfigBlock &block) AoOutput::~AoOutput() { ao_free_options(options); - - ao_output_ref--; - - if (ao_output_ref == 0) - ao_shutdown(); } void |