output/Multiple: use std::unique_ptr<FilteredAudioOutput>

This commit is contained in:
Max Kellermann 2018-01-04 10:14:26 +01:00
parent f52b3b4e04
commit ef71df60f6
5 changed files with 27 additions and 32 deletions

View File

@ -37,13 +37,21 @@ static constexpr PeriodClock::Duration REOPEN_AFTER = std::chrono::seconds(10);
struct notify audio_output_client_notify; struct notify audio_output_client_notify;
AudioOutputControl::AudioOutputControl(FilteredAudioOutput *_output, AudioOutputControl::AudioOutputControl(std::unique_ptr<FilteredAudioOutput> _output,
AudioOutputClient &_client) noexcept AudioOutputClient &_client) noexcept
:output(_output), client(_client), :output(std::move(_output)), client(_client),
thread(BIND_THIS_METHOD(Task)) thread(BIND_THIS_METHOD(Task))
{ {
} }
AudioOutputControl::~AudioOutputControl() noexcept
{
assert(!fail_timer.IsDefined());
assert(!thread.IsDefined());
assert(output == nullptr);
assert(!open);
}
void void
AudioOutputControl::Configure(const ConfigBlock &block) AudioOutputControl::Configure(const ConfigBlock &block)
{ {
@ -377,6 +385,5 @@ AudioOutputControl::FinishDestroy() noexcept
if (thread.IsDefined()) if (thread.IsDefined())
thread.Join(); thread.Join();
delete output; output.reset();
output = nullptr;
} }

View File

@ -30,6 +30,7 @@
#include <utility> #include <utility>
#include <exception> #include <exception>
#include <memory>
#include <string> #include <string>
#include <map> #include <map>
@ -52,7 +53,7 @@ class AudioOutputClient;
* Controller for an #AudioOutput and its output thread. * Controller for an #AudioOutput and its output thread.
*/ */
class AudioOutputControl { class AudioOutputControl {
FilteredAudioOutput *output; std::unique_ptr<FilteredAudioOutput> output;
/** /**
* The PlayerControl object which "owns" this output. This * The PlayerControl object which "owns" this output. This
@ -211,17 +212,10 @@ public:
*/ */
mutable Mutex mutex; mutable Mutex mutex;
AudioOutputControl(FilteredAudioOutput *_output, AudioOutputControl(std::unique_ptr<FilteredAudioOutput> _output,
AudioOutputClient &_client) noexcept; AudioOutputClient &_client) noexcept;
#ifndef NDEBUG ~AudioOutputControl() noexcept;
~AudioOutputControl() noexcept {
assert(!fail_timer.IsDefined());
assert(!thread.IsDefined());
assert(output == nullptr);
assert(!open);
}
#endif
AudioOutputControl(const AudioOutputControl &) = delete; AudioOutputControl(const AudioOutputControl &) = delete;
AudioOutputControl &operator=(const AudioOutputControl &) = delete; AudioOutputControl &operator=(const AudioOutputControl &) = delete;

View File

@ -239,7 +239,7 @@ extern struct notify audio_output_client_notify;
/** /**
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
FilteredAudioOutput * std::unique_ptr<FilteredAudioOutput>
audio_output_new(EventLoop &event_loop, audio_output_new(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config, const ReplayGainConfig &replay_gain_config,
const ConfigBlock &block, const ConfigBlock &block,

View File

@ -259,7 +259,7 @@ FilteredAudioOutput::Setup(EventLoop &event_loop,
convert_filter.Set(convert_filter_prepare())); convert_filter.Set(convert_filter_prepare()));
} }
FilteredAudioOutput * std::unique_ptr<FilteredAudioOutput>
audio_output_new(EventLoop &event_loop, audio_output_new(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config, const ReplayGainConfig &replay_gain_config,
const ConfigBlock &block, const ConfigBlock &block,
@ -292,16 +292,10 @@ audio_output_new(EventLoop &event_loop,
block)); block));
assert(ao != nullptr); assert(ao != nullptr);
auto *f = new FilteredAudioOutput(plugin->name, std::move(ao), block); auto f = std::make_unique<FilteredAudioOutput>(plugin->name,
std::move(ao), block);
try { f->Setup(event_loop, replay_gain_config,
f->Setup(event_loop, replay_gain_config, plugin->mixer_plugin,
plugin->mixer_plugin, mixer_listener, block);
mixer_listener, block);
} catch (...) {
delete f;
throw;
}
return f; return f;
} }

View File

@ -51,7 +51,7 @@ MultipleOutputs::~MultipleOutputs() noexcept
delete i; delete i;
} }
static FilteredAudioOutput * static std::unique_ptr<FilteredAudioOutput>
LoadOutput(EventLoop &event_loop, LoadOutput(EventLoop &event_loop,
const ReplayGainConfig &replay_gain_config, const ReplayGainConfig &replay_gain_config,
MixerListener &mixer_listener, MixerListener &mixer_listener,
@ -73,10 +73,10 @@ LoadOutputControl(EventLoop &event_loop,
MixerListener &mixer_listener, MixerListener &mixer_listener,
AudioOutputClient &client, const ConfigBlock &block) AudioOutputClient &client, const ConfigBlock &block)
{ {
auto *output = LoadOutput(event_loop, replay_gain_config, auto output = LoadOutput(event_loop, replay_gain_config,
mixer_listener, mixer_listener,
block); block);
auto *control = new AudioOutputControl(output, client); auto *control = new AudioOutputControl(std::move(output), client);
try { try {
control->Configure(block); control->Configure(block);