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;
AudioOutputControl::AudioOutputControl(FilteredAudioOutput *_output,
AudioOutputControl::AudioOutputControl(std::unique_ptr<FilteredAudioOutput> _output,
AudioOutputClient &_client) noexcept
:output(_output), client(_client),
:output(std::move(_output)), client(_client),
thread(BIND_THIS_METHOD(Task))
{
}
AudioOutputControl::~AudioOutputControl() noexcept
{
assert(!fail_timer.IsDefined());
assert(!thread.IsDefined());
assert(output == nullptr);
assert(!open);
}
void
AudioOutputControl::Configure(const ConfigBlock &block)
{
@ -377,6 +385,5 @@ AudioOutputControl::FinishDestroy() noexcept
if (thread.IsDefined())
thread.Join();
delete output;
output = nullptr;
output.reset();
}

View File

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

View File

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

View File

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