diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-27 09:17:15 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-12-27 11:39:01 +0100 |
commit | e2621d5e44be0da281edd7d6906a085360959fde (patch) | |
tree | 6c4a5fae2488b31f70b01c04809c2e1ab18b9028 /src/filter | |
parent | 0e3ff12dd35bce20bc1ed1fba4a148de572e0c8c (diff) |
filter/Plugin: return std::unique_ptr<PreparedFilter>
Diffstat (limited to 'src/filter')
-rw-r--r-- | src/filter/FilterConfig.cxx | 7 | ||||
-rw-r--r-- | src/filter/FilterPlugin.cxx | 5 | ||||
-rw-r--r-- | src/filter/FilterPlugin.hxx | 8 | ||||
-rw-r--r-- | src/filter/Observer.cxx | 15 | ||||
-rw-r--r-- | src/filter/Observer.hxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/AutoConvertFilterPlugin.cxx | 14 | ||||
-rw-r--r-- | src/filter/plugins/AutoConvertFilterPlugin.hxx | 6 | ||||
-rw-r--r-- | src/filter/plugins/ChainFilterPlugin.cxx | 25 | ||||
-rw-r--r-- | src/filter/plugins/ChainFilterPlugin.hxx | 8 | ||||
-rw-r--r-- | src/filter/plugins/ConvertFilterPlugin.cxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/ConvertFilterPlugin.hxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/NormalizeFilterPlugin.cxx | 8 | ||||
-rw-r--r-- | src/filter/plugins/NormalizeFilterPlugin.hxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/NullFilterPlugin.cxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/ReplayGainFilterPlugin.cxx | 6 | ||||
-rw-r--r-- | src/filter/plugins/ReplayGainFilterPlugin.hxx | 6 | ||||
-rw-r--r-- | src/filter/plugins/RouteFilterPlugin.cxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/VolumeFilterPlugin.cxx | 4 | ||||
-rw-r--r-- | src/filter/plugins/VolumeFilterPlugin.hxx | 4 |
19 files changed, 78 insertions, 62 deletions
diff --git a/src/filter/FilterConfig.cxx b/src/filter/FilterConfig.cxx index 61a23797a..380a65020 100644 --- a/src/filter/FilterConfig.cxx +++ b/src/filter/FilterConfig.cxx @@ -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 diff --git a/src/filter/FilterPlugin.cxx b/src/filter/FilterPlugin.cxx index 11326e09f..5f5ad5d8c 100644 --- a/src/filter/FilterPlugin.cxx +++ b/src/filter/FilterPlugin.cxx @@ -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"); diff --git a/src/filter/FilterPlugin.hxx b/src/filter/FilterPlugin.hxx index 37d45f3ef..cb7f82476 100644 --- a/src/filter/FilterPlugin.hxx +++ b/src/filter/FilterPlugin.hxx @@ -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 diff --git a/src/filter/Observer.cxx b/src/filter/Observer.cxx index 5d6602d46..706abd8b7 100644 --- a/src/filter/Observer.cxx +++ b/src/filter/Observer.cxx @@ -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 * diff --git a/src/filter/Observer.hxx b/src/filter/Observer.hxx index 276012bd8..b2114d1d0 100644 --- a/src/filter/Observer.hxx +++ b/src/filter/Observer.hxx @@ -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(); }; diff --git a/src/filter/plugins/AutoConvertFilterPlugin.cxx b/src/filter/plugins/AutoConvertFilterPlugin.cxx index 890018243..f805b6183 100644 --- a/src/filter/plugins/AutoConvertFilterPlugin.cxx +++ b/src/filter/plugins/AutoConvertFilterPlugin.cxx @@ -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)); } diff --git a/src/filter/plugins/AutoConvertFilterPlugin.hxx b/src/filter/plugins/AutoConvertFilterPlugin.hxx index e2bd6917e..de8e87509 100644 --- a/src/filter/plugins/AutoConvertFilterPlugin.hxx +++ b/src/filter/plugins/AutoConvertFilterPlugin.hxx @@ -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 diff --git a/src/filter/plugins/ChainFilterPlugin.cxx b/src/filter/plugins/ChainFilterPlugin.cxx index b3ac2fdbf..0349301b0 100644 --- a/src/filter/plugins/ChainFilterPlugin.cxx +++ b/src/filter/plugins/ChainFilterPlugin.cxx @@ -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)); } diff --git a/src/filter/plugins/ChainFilterPlugin.hxx b/src/filter/plugins/ChainFilterPlugin.hxx index 15814281d..c5b4c810d 100644 --- a/src/filter/plugins/ChainFilterPlugin.hxx +++ b/src/filter/plugins/ChainFilterPlugin.hxx @@ -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 diff --git a/src/filter/plugins/ConvertFilterPlugin.cxx b/src/filter/plugins/ConvertFilterPlugin.cxx index dc6fedf82..571f68e6e 100644 --- a/src/filter/plugins/ConvertFilterPlugin.cxx +++ b/src/filter/plugins/ConvertFilterPlugin.cxx @@ -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 * diff --git a/src/filter/plugins/ConvertFilterPlugin.hxx b/src/filter/plugins/ConvertFilterPlugin.hxx index 469271c93..26e472099 100644 --- a/src/filter/plugins/ConvertFilterPlugin.hxx +++ b/src/filter/plugins/ConvertFilterPlugin.hxx @@ -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 * diff --git a/src/filter/plugins/NormalizeFilterPlugin.cxx b/src/filter/plugins/NormalizeFilterPlugin.cxx index 4cd68b074..16119086b 100644 --- a/src/filter/plugins/NormalizeFilterPlugin.cxx +++ b/src/filter/plugins/NormalizeFilterPlugin.cxx @@ -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>(); } diff --git a/src/filter/plugins/NormalizeFilterPlugin.hxx b/src/filter/plugins/NormalizeFilterPlugin.hxx index fb62575d8..3c9101341 100644 --- a/src/filter/plugins/NormalizeFilterPlugin.hxx +++ b/src/filter/plugins/NormalizeFilterPlugin.hxx @@ -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 diff --git a/src/filter/plugins/NullFilterPlugin.cxx b/src/filter/plugins/NullFilterPlugin.cxx index 09599d156..7856494bd 100644 --- a/src/filter/plugins/NullFilterPlugin.cxx +++ b/src/filter/plugins/NullFilterPlugin.cxx @@ -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 = { diff --git a/src/filter/plugins/ReplayGainFilterPlugin.cxx b/src/filter/plugins/ReplayGainFilterPlugin.cxx index 1a77d44dc..0a74bb13c 100644 --- a/src/filter/plugins/ReplayGainFilterPlugin.cxx +++ b/src/filter/plugins/ReplayGainFilterPlugin.cxx @@ -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 * diff --git a/src/filter/plugins/ReplayGainFilterPlugin.hxx b/src/filter/plugins/ReplayGainFilterPlugin.hxx index 5a295491d..2177537b3 100644 --- a/src/filter/plugins/ReplayGainFilterPlugin.hxx +++ b/src/filter/plugins/ReplayGainFilterPlugin.hxx @@ -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. diff --git a/src/filter/plugins/RouteFilterPlugin.cxx b/src/filter/plugins/RouteFilterPlugin.cxx index 682dd06a3..98181800a 100644 --- a/src/filter/plugins/RouteFilterPlugin.cxx +++ b/src/filter/plugins/RouteFilterPlugin.cxx @@ -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, diff --git a/src/filter/plugins/VolumeFilterPlugin.cxx b/src/filter/plugins/VolumeFilterPlugin.cxx index 81282dcc1..2c7addbd1 100644 --- a/src/filter/plugins/VolumeFilterPlugin.cxx +++ b/src/filter/plugins/VolumeFilterPlugin.cxx @@ -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 diff --git a/src/filter/plugins/VolumeFilterPlugin.hxx b/src/filter/plugins/VolumeFilterPlugin.hxx index 1f7280ab9..6091663f7 100644 --- a/src/filter/plugins/VolumeFilterPlugin.hxx +++ b/src/filter/plugins/VolumeFilterPlugin.hxx @@ -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 |