filter/Plugin: return std::unique_ptr<PreparedFilter>
This commit is contained in:
parent
0e3ff12dd3
commit
e2621d5e44
|
@ -19,8 +19,9 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "FilterConfig.hxx"
|
||||
#include "plugins/ChainFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "plugins/ChainFilterPlugin.hxx"
|
||||
#include "config/Param.hxx"
|
||||
#include "config/ConfigOption.hxx"
|
||||
#include "config/ConfigGlobal.hxx"
|
||||
|
@ -42,11 +43,11 @@ filter_chain_append_new(PreparedFilter &chain, const char *template_name)
|
|||
template_name);
|
||||
|
||||
// Instantiate one of those filter plugins with the template name as a hint
|
||||
PreparedFilter *f = filter_configured_new(*cfg);
|
||||
auto f = filter_configured_new(*cfg);
|
||||
|
||||
const char *plugin_name = cfg->GetBlockValue("plugin",
|
||||
"unknown");
|
||||
filter_chain_append(chain, plugin_name, f);
|
||||
filter_chain_append(chain, plugin_name, std::move(f));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -20,13 +20,14 @@
|
|||
#include "config.h"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "config/Block.hxx"
|
||||
#include "config/ConfigError.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
filter_new(const FilterPlugin *plugin, const ConfigBlock &block)
|
||||
{
|
||||
assert(plugin != nullptr);
|
||||
|
@ -34,7 +35,7 @@ filter_new(const FilterPlugin *plugin, const ConfigBlock &block)
|
|||
return plugin->init(block);
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
filter_configured_new(const ConfigBlock &block)
|
||||
{
|
||||
const char *plugin_name = block.GetBlockValue("plugin");
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#ifndef MPD_FILTER_PLUGIN_HXX
|
||||
#define MPD_FILTER_PLUGIN_HXX
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct ConfigBlock;
|
||||
class PreparedFilter;
|
||||
|
||||
|
@ -35,7 +37,7 @@ struct FilterPlugin {
|
|||
/**
|
||||
* Allocates and configures a filter.
|
||||
*/
|
||||
PreparedFilter *(*init)(const ConfigBlock &block);
|
||||
std::unique_ptr<PreparedFilter> (*init)(const ConfigBlock &block);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -46,7 +48,7 @@ struct FilterPlugin {
|
|||
* @param plugin the filter plugin
|
||||
* @param block configuration section
|
||||
*/
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
filter_new(const FilterPlugin *plugin,
|
||||
const ConfigBlock &block);
|
||||
|
||||
|
@ -58,7 +60,7 @@ filter_new(const FilterPlugin *plugin,
|
|||
*
|
||||
* @param block the configuration section
|
||||
*/
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
filter_configured_new(const ConfigBlock &block);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,21 +27,20 @@
|
|||
class FilterObserver::PreparedProxy final : public PreparedFilter {
|
||||
FilterObserver &observer;
|
||||
|
||||
PreparedFilter *const prepared_filter;
|
||||
std::unique_ptr<PreparedFilter> prepared_filter;
|
||||
Proxy *child = nullptr;
|
||||
|
||||
public:
|
||||
PreparedProxy(FilterObserver &_observer,
|
||||
PreparedFilter *_prepared_filter)
|
||||
std::unique_ptr<PreparedFilter> _prepared_filter)
|
||||
:observer(_observer),
|
||||
prepared_filter(_prepared_filter) {}
|
||||
prepared_filter(std::move(_prepared_filter)) {}
|
||||
|
||||
~PreparedProxy() {
|
||||
assert(child == nullptr);
|
||||
assert(observer.proxy == this);
|
||||
|
||||
observer.proxy = nullptr;
|
||||
delete prepared_filter;
|
||||
}
|
||||
|
||||
void Clear(gcc_unused Proxy *_child) {
|
||||
|
@ -95,12 +94,14 @@ FilterObserver::PreparedProxy::Open(AudioFormat &af)
|
|||
return child = new Proxy(*this, f);
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
FilterObserver::Set(PreparedFilter *pf)
|
||||
std::unique_ptr<PreparedFilter>
|
||||
FilterObserver::Set(std::unique_ptr<PreparedFilter> pf)
|
||||
{
|
||||
assert(proxy == nullptr);
|
||||
|
||||
return proxy = new PreparedProxy(*this, pf);
|
||||
auto p = std::make_unique<PreparedProxy>(*this, std::move(pf));
|
||||
proxy = p.get();
|
||||
return p;
|
||||
}
|
||||
|
||||
Filter *
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "check.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PreparedFilter;
|
||||
class Filter;
|
||||
|
||||
|
@ -39,7 +41,7 @@ public:
|
|||
/**
|
||||
* @return a proxy object
|
||||
*/
|
||||
PreparedFilter *Set(PreparedFilter *pf);
|
||||
std::unique_ptr<PreparedFilter> Set(std::unique_ptr<PreparedFilter> pf);
|
||||
|
||||
Filter *Get();
|
||||
};
|
||||
|
|
|
@ -62,13 +62,11 @@ class PreparedAutoConvertFilter final : public PreparedFilter {
|
|||
/**
|
||||
* The underlying filter.
|
||||
*/
|
||||
PreparedFilter *const filter;
|
||||
std::unique_ptr<PreparedFilter> filter;
|
||||
|
||||
public:
|
||||
PreparedAutoConvertFilter(PreparedFilter *_filter):filter(_filter) {}
|
||||
~PreparedAutoConvertFilter() {
|
||||
delete filter;
|
||||
}
|
||||
PreparedAutoConvertFilter(std::unique_ptr<PreparedFilter> _filter) noexcept
|
||||
:filter(std::move(_filter)) {}
|
||||
|
||||
Filter *Open(AudioFormat &af) override;
|
||||
};
|
||||
|
@ -106,8 +104,8 @@ AutoConvertFilter::FilterPCM(ConstBuffer<void> src)
|
|||
return filter->FilterPCM(src);
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
autoconvert_filter_new(PreparedFilter *filter)
|
||||
std::unique_ptr<PreparedFilter>
|
||||
autoconvert_filter_new(std::unique_ptr<PreparedFilter> filter) noexcept
|
||||
{
|
||||
return new PreparedAutoConvertFilter(filter);
|
||||
return std::make_unique<PreparedAutoConvertFilter>(std::move(filter));
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#ifndef MPD_AUTOCONVERT_FILTER_PLUGIN_HXX
|
||||
#define MPD_AUTOCONVERT_FILTER_PLUGIN_HXX
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PreparedFilter;
|
||||
|
||||
/**
|
||||
|
@ -28,7 +30,7 @@ class PreparedFilter;
|
|||
* requests a different format, it automatically creates a
|
||||
* convert_filter.
|
||||
*/
|
||||
PreparedFilter *
|
||||
autoconvert_filter_new(PreparedFilter *filter);
|
||||
std::unique_ptr<PreparedFilter>
|
||||
autoconvert_filter_new(std::unique_ptr<PreparedFilter> filter) noexcept;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -67,13 +67,11 @@ public:
|
|||
class PreparedChainFilter final : public PreparedFilter {
|
||||
struct Child {
|
||||
const char *name;
|
||||
PreparedFilter *filter;
|
||||
std::unique_ptr<PreparedFilter> filter;
|
||||
|
||||
Child(const char *_name, PreparedFilter *_filter)
|
||||
:name(_name), filter(_filter) {}
|
||||
~Child() {
|
||||
delete filter;
|
||||
}
|
||||
Child(const char *_name,
|
||||
std::unique_ptr<PreparedFilter> _filter)
|
||||
:name(_name), filter(std::move(_filter)) {}
|
||||
|
||||
Child(const Child &) = delete;
|
||||
Child &operator=(const Child &) = delete;
|
||||
|
@ -84,8 +82,9 @@ class PreparedChainFilter final : public PreparedFilter {
|
|||
std::list<Child> children;
|
||||
|
||||
public:
|
||||
void Append(const char *name, PreparedFilter *filter) {
|
||||
children.emplace_back(name, filter);
|
||||
void Append(const char *name,
|
||||
std::unique_ptr<PreparedFilter> filter) noexcept {
|
||||
children.emplace_back(name, std::move(filter));
|
||||
}
|
||||
|
||||
/* virtual methods from class PreparedFilter */
|
||||
|
@ -143,17 +142,17 @@ ChainFilter::FilterPCM(ConstBuffer<void> src)
|
|||
return src;
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
filter_chain_new(void)
|
||||
std::unique_ptr<PreparedFilter>
|
||||
filter_chain_new() noexcept
|
||||
{
|
||||
return new PreparedChainFilter();
|
||||
return std::make_unique<PreparedChainFilter>();
|
||||
}
|
||||
|
||||
void
|
||||
filter_chain_append(PreparedFilter &_chain, const char *name,
|
||||
PreparedFilter *filter)
|
||||
std::unique_ptr<PreparedFilter> filter) noexcept
|
||||
{
|
||||
PreparedChainFilter &chain = (PreparedChainFilter &)_chain;
|
||||
|
||||
chain.Append(name, filter);
|
||||
chain.Append(name, std::move(filter));
|
||||
}
|
||||
|
|
|
@ -27,13 +27,15 @@
|
|||
#ifndef MPD_FILTER_CHAIN_HXX
|
||||
#define MPD_FILTER_CHAIN_HXX
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PreparedFilter;
|
||||
|
||||
/**
|
||||
* Creates a new filter chain.
|
||||
*/
|
||||
PreparedFilter *
|
||||
filter_chain_new();
|
||||
std::unique_ptr<PreparedFilter>
|
||||
filter_chain_new() noexcept;
|
||||
|
||||
/**
|
||||
* Appends a new filter at the end of the filter chain. You must call
|
||||
|
@ -44,6 +46,6 @@ filter_chain_new();
|
|||
*/
|
||||
void
|
||||
filter_chain_append(PreparedFilter &chain, const char *name,
|
||||
PreparedFilter *filter);
|
||||
std::unique_ptr<PreparedFilter> filter) noexcept;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -119,10 +119,10 @@ ConvertFilter::FilterPCM(ConstBuffer<void> src)
|
|||
return state.Convert(src);
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
convert_filter_prepare() noexcept
|
||||
{
|
||||
return new PreparedConvertFilter();
|
||||
return std::make_unique<PreparedConvertFilter>();
|
||||
}
|
||||
|
||||
Filter *
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#ifndef MPD_CONVERT_FILTER_PLUGIN_HXX
|
||||
#define MPD_CONVERT_FILTER_PLUGIN_HXX
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PreparedFilter;
|
||||
class Filter;
|
||||
struct AudioFormat;
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
convert_filter_prepare() noexcept;
|
||||
|
||||
Filter *
|
||||
|
|
|
@ -53,10 +53,10 @@ public:
|
|||
Filter *Open(AudioFormat &af) override;
|
||||
};
|
||||
|
||||
static PreparedFilter *
|
||||
static std::unique_ptr<PreparedFilter>
|
||||
normalize_filter_init(gcc_unused const ConfigBlock &block)
|
||||
{
|
||||
return new PreparedNormalizeFilter();
|
||||
return std::make_unique<PreparedNormalizeFilter>();
|
||||
}
|
||||
|
||||
Filter *
|
||||
|
@ -82,8 +82,8 @@ const FilterPlugin normalize_filter_plugin = {
|
|||
normalize_filter_init,
|
||||
};
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
normalize_filter_prepare() noexcept
|
||||
{
|
||||
return new PreparedNormalizeFilter();
|
||||
return std::make_unique<PreparedNormalizeFilter>();
|
||||
}
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#ifndef MPD_NORMALIZE_FILTER_PLUGIN_HXX
|
||||
#define MPD_NORMALIZE_FILTER_PLUGIN_HXX
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PreparedFilter;
|
||||
class Filter;
|
||||
struct AudioFormat;
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
normalize_filter_prepare() noexcept;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,10 +48,10 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
static PreparedFilter *
|
||||
static std::unique_ptr<PreparedFilter>
|
||||
null_filter_init(gcc_unused const ConfigBlock &block)
|
||||
{
|
||||
return new PreparedNullFilter();
|
||||
return std::make_unique<PreparedNullFilter>();
|
||||
}
|
||||
|
||||
const FilterPlugin null_filter_plugin = {
|
||||
|
|
|
@ -171,10 +171,10 @@ ReplayGainFilter::Update()
|
|||
pv.SetVolume(volume);
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
NewReplayGainFilter(const ReplayGainConfig &config)
|
||||
std::unique_ptr<PreparedFilter>
|
||||
NewReplayGainFilter(const ReplayGainConfig &config) noexcept
|
||||
{
|
||||
return new PreparedReplayGainFilter(config);
|
||||
return std::make_unique<PreparedReplayGainFilter>(config);
|
||||
}
|
||||
|
||||
Filter *
|
||||
|
|
|
@ -22,14 +22,16 @@
|
|||
|
||||
#include "ReplayGainMode.hxx"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Filter;
|
||||
class PreparedFilter;
|
||||
class Mixer;
|
||||
struct ReplayGainConfig;
|
||||
struct ReplayGainInfo;
|
||||
|
||||
PreparedFilter *
|
||||
NewReplayGainFilter(const ReplayGainConfig &config);
|
||||
std::unique_ptr<PreparedFilter>
|
||||
NewReplayGainFilter(const ReplayGainConfig &config) noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables the hardware mixer for applying replay gain.
|
||||
|
|
|
@ -196,10 +196,10 @@ PreparedRouteFilter::PreparedRouteFilter(const ConfigBlock &block)
|
|||
}
|
||||
}
|
||||
|
||||
static PreparedFilter *
|
||||
static std::unique_ptr<PreparedFilter>
|
||||
route_filter_init(const ConfigBlock &block)
|
||||
{
|
||||
return new PreparedRouteFilter(block);
|
||||
return std::make_unique<PreparedRouteFilter>(block);
|
||||
}
|
||||
|
||||
RouteFilter::RouteFilter(const AudioFormat &audio_format,
|
||||
|
|
|
@ -65,10 +65,10 @@ VolumeFilter::FilterPCM(ConstBuffer<void> src)
|
|||
return pv.Apply(src);
|
||||
}
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
volume_filter_prepare() noexcept
|
||||
{
|
||||
return new PreparedVolumeFilter();
|
||||
return std::make_unique<PreparedVolumeFilter>();
|
||||
}
|
||||
|
||||
unsigned
|
||||
|
|
|
@ -20,10 +20,12 @@
|
|||
#ifndef MPD_VOLUME_FILTER_PLUGIN_HXX
|
||||
#define MPD_VOLUME_FILTER_PLUGIN_HXX
|
||||
|
||||
#include <memory>
|
||||
|
||||
class PreparedFilter;
|
||||
class Filter;
|
||||
|
||||
PreparedFilter *
|
||||
std::unique_ptr<PreparedFilter>
|
||||
volume_filter_prepare() noexcept;
|
||||
|
||||
unsigned
|
||||
|
|
|
@ -93,7 +93,7 @@ public:
|
|||
* The filter object of this audio output. This is an
|
||||
* instance of chain_filter_plugin.
|
||||
*/
|
||||
PreparedFilter *prepared_filter = nullptr;
|
||||
std::unique_ptr<PreparedFilter> prepared_filter;
|
||||
|
||||
/**
|
||||
* The #VolumeFilter instance of this audio output. It is
|
||||
|
@ -105,14 +105,14 @@ public:
|
|||
* The replay_gain_filter_plugin instance of this audio
|
||||
* output.
|
||||
*/
|
||||
PreparedFilter *prepared_replay_gain_filter = nullptr;
|
||||
std::unique_ptr<PreparedFilter> prepared_replay_gain_filter;
|
||||
|
||||
/**
|
||||
* The replay_gain_filter_plugin instance of this audio
|
||||
* output, to be applied to the second chunk during
|
||||
* cross-fading.
|
||||
*/
|
||||
PreparedFilter *prepared_other_replay_gain_filter = nullptr;
|
||||
std::unique_ptr<PreparedFilter> prepared_other_replay_gain_filter;
|
||||
|
||||
/**
|
||||
* The convert_filter_plugin instance of this audio output.
|
||||
|
|
|
@ -27,10 +27,6 @@ FilteredAudioOutput::~FilteredAudioOutput()
|
|||
{
|
||||
if (mixer != nullptr)
|
||||
mixer_free(mixer);
|
||||
|
||||
delete prepared_replay_gain_filter;
|
||||
delete prepared_other_replay_gain_filter;
|
||||
delete prepared_filter;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -22,12 +22,13 @@
|
|||
#include "Registry.hxx"
|
||||
#include "Domain.hxx"
|
||||
#include "OutputAPI.hxx"
|
||||
#include "filter/FilterConfig.hxx"
|
||||
#include "AudioParser.hxx"
|
||||
#include "mixer/MixerList.hxx"
|
||||
#include "mixer/MixerType.hxx"
|
||||
#include "mixer/MixerControl.hxx"
|
||||
#include "mixer/plugins/SoftwareMixerPlugin.hxx"
|
||||
#include "filter/FilterConfig.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/plugins/AutoConvertFilterPlugin.hxx"
|
||||
#include "filter/plugins/ConvertFilterPlugin.hxx"
|
||||
#include "filter/plugins/ReplayGainFilterPlugin.hxx"
|
||||
|
|
|
@ -146,8 +146,8 @@ AudioOutputControl::InternalOpen(const AudioFormat in_audio_format,
|
|||
try {
|
||||
try {
|
||||
f = source.Open(in_audio_format, pipe,
|
||||
output->prepared_replay_gain_filter,
|
||||
output->prepared_other_replay_gain_filter,
|
||||
output->prepared_replay_gain_filter.get(),
|
||||
output->prepared_other_replay_gain_filter.get(),
|
||||
*output->prepared_filter);
|
||||
} catch (...) {
|
||||
std::throw_with_nested(FormatRuntimeError("Failed to open filter for %s",
|
||||
|
|
|
@ -48,7 +48,7 @@ mixer_set_volume(gcc_unused Mixer *mixer,
|
|||
{
|
||||
}
|
||||
|
||||
static PreparedFilter *
|
||||
static std::unique_ptr<PreparedFilter>
|
||||
load_filter(const char *name)
|
||||
{
|
||||
const auto *param = config_find_block(ConfigBlockOption::AUDIO_FILTER,
|
||||
|
@ -86,7 +86,7 @@ try {
|
|||
|
||||
/* initialize the filter */
|
||||
|
||||
std::unique_ptr<PreparedFilter> prepared_filter(load_filter(argv[2]));
|
||||
auto prepared_filter = load_filter(argv[2]);
|
||||
if (!prepared_filter)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue