summaryrefslogtreecommitdiff
path: root/src/filter
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-12-27 11:42:14 +0100
committerMax Kellermann <max@musicpd.org>2017-12-27 11:56:05 +0100
commitedef62df86416a63efb936d5a5fd40ad1a49d171 (patch)
treecd93db6cf9bea01d01bc8474cc40fff540138b92 /src/filter
parente2621d5e44be0da281edd7d6906a085360959fde (diff)
filter/Internal: return std::unique_ptr<Filter>
Diffstat (limited to 'src/filter')
-rw-r--r--src/filter/FilterInternal.hxx5
-rw-r--r--src/filter/Observer.cxx18
-rw-r--r--src/filter/plugins/AutoConvertFilterPlugin.cxx10
-rw-r--r--src/filter/plugins/ChainFilterPlugin.cxx38
-rw-r--r--src/filter/plugins/ConvertFilterPlugin.cxx6
-rw-r--r--src/filter/plugins/NormalizeFilterPlugin.cxx6
-rw-r--r--src/filter/plugins/NullFilterPlugin.cxx4
-rw-r--r--src/filter/plugins/ReplayGainFilterPlugin.cxx6
-rw-r--r--src/filter/plugins/RouteFilterPlugin.cxx7
-rw-r--r--src/filter/plugins/VolumeFilterPlugin.cxx6
10 files changed, 49 insertions, 57 deletions
diff --git a/src/filter/FilterInternal.hxx b/src/filter/FilterInternal.hxx
index 0aa9b5c8e..3758f1de4 100644
--- a/src/filter/FilterInternal.hxx
+++ b/src/filter/FilterInternal.hxx
@@ -27,8 +27,9 @@
#include "AudioFormat.hxx"
+#include <memory>
+
#include <assert.h>
-#include <stddef.h>
struct AudioFormat;
template<typename T> struct ConstBuffer;
@@ -84,7 +85,7 @@ public:
* plugin may modify the object to enforce another input
* format
*/
- virtual Filter *Open(AudioFormat &af) = 0;
+ virtual std::unique_ptr<Filter> Open(AudioFormat &af) = 0;
};
#endif
diff --git a/src/filter/Observer.cxx b/src/filter/Observer.cxx
index 706abd8b7..8ca42c5b1 100644
--- a/src/filter/Observer.cxx
+++ b/src/filter/Observer.cxx
@@ -50,26 +50,25 @@ public:
Filter *Get();
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
class FilterObserver::Proxy final : public Filter {
PreparedProxy &parent;
- Filter *const filter;
+ std::unique_ptr<Filter> filter;
public:
- Proxy(PreparedProxy &_parent, Filter *_filter)
+ Proxy(PreparedProxy &_parent, std::unique_ptr<Filter> _filter)
:Filter(_filter->GetOutAudioFormat()),
- parent(_parent), filter(_filter) {}
+ parent(_parent), filter(std::move(_filter)) {}
~Proxy() {
parent.Clear(this);
- delete filter;
}
Filter *Get() {
- return filter;
+ return filter.get();
}
ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override {
@@ -85,13 +84,14 @@ FilterObserver::PreparedProxy::Get()
: nullptr;
}
-Filter *
+std::unique_ptr<Filter>
FilterObserver::PreparedProxy::Open(AudioFormat &af)
{
assert(child == nullptr);
- Filter *f = prepared_filter->Open(af);
- return child = new Proxy(*this, f);
+ auto c = std::make_unique<Proxy>(*this, prepared_filter->Open(af));
+ child = c.get();
+ return c;
}
std::unique_ptr<PreparedFilter>
diff --git a/src/filter/plugins/AutoConvertFilterPlugin.cxx b/src/filter/plugins/AutoConvertFilterPlugin.cxx
index f805b6183..125e488dd 100644
--- a/src/filter/plugins/AutoConvertFilterPlugin.cxx
+++ b/src/filter/plugins/AutoConvertFilterPlugin.cxx
@@ -68,10 +68,10 @@ public:
PreparedAutoConvertFilter(std::unique_ptr<PreparedFilter> _filter) noexcept
:filter(std::move(_filter)) {}
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
-Filter *
+std::unique_ptr<Filter>
PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format)
{
assert(in_audio_format.IsValid());
@@ -79,7 +79,7 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format)
/* open the "real" filter */
AudioFormat child_audio_format = in_audio_format;
- std::unique_ptr<Filter> new_filter(filter->Open(child_audio_format));
+ auto new_filter = filter->Open(child_audio_format);
/* need to convert? */
@@ -91,8 +91,8 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format)
child_audio_format));
}
- return new AutoConvertFilter(std::move(new_filter),
- std::move(convert));
+ return std::make_unique<AutoConvertFilter>(std::move(new_filter),
+ std::move(convert));
}
ConstBuffer<void>
diff --git a/src/filter/plugins/ChainFilterPlugin.cxx b/src/filter/plugins/ChainFilterPlugin.cxx
index 0349301b0..3be60463f 100644
--- a/src/filter/plugins/ChainFilterPlugin.cxx
+++ b/src/filter/plugins/ChainFilterPlugin.cxx
@@ -33,16 +33,10 @@
class ChainFilter final : public Filter {
struct Child {
const char *name;
- Filter *filter;
+ std::unique_ptr<Filter> filter;
- Child(const char *_name, Filter *_filter)
- :name(_name), filter(_filter) {}
- ~Child() {
- delete filter;
- }
-
- Child(const Child &) = delete;
- Child &operator=(const Child &) = delete;
+ Child(const char *_name, std::unique_ptr<Filter> _filter)
+ :name(_name), filter(std::move(_filter)) {}
};
std::list<Child> children;
@@ -51,12 +45,12 @@ public:
explicit ChainFilter(AudioFormat _audio_format)
:Filter(_audio_format) {}
- void Append(const char *name, Filter *filter) {
+ void Append(const char *name, std::unique_ptr<Filter> filter) {
assert(out_audio_format.IsValid());
out_audio_format = filter->GetOutAudioFormat();
assert(out_audio_format.IsValid());
- children.emplace_back(name, filter);
+ children.emplace_back(name, std::move(filter));
}
/* virtual methods from class Filter */
@@ -76,7 +70,7 @@ class PreparedChainFilter final : public PreparedFilter {
Child(const Child &) = delete;
Child &operator=(const Child &) = delete;
- Filter *Open(const AudioFormat &prev_audio_format);
+ std::unique_ptr<Filter> Open(const AudioFormat &prev_audio_format);
};
std::list<Child> children;
@@ -88,38 +82,34 @@ public:
}
/* virtual methods from class PreparedFilter */
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
-Filter *
+std::unique_ptr<Filter>
PreparedChainFilter::Child::Open(const AudioFormat &prev_audio_format)
{
AudioFormat conv_audio_format = prev_audio_format;
- Filter *new_filter = filter->Open(conv_audio_format);
-
- if (conv_audio_format != prev_audio_format) {
- delete new_filter;
+ auto new_filter = filter->Open(conv_audio_format);
+ if (conv_audio_format != prev_audio_format)
throw FormatRuntimeError("Audio format not supported by filter '%s': %s",
name,
ToString(prev_audio_format).c_str());
- }
return new_filter;
}
-Filter *
+std::unique_ptr<Filter>
PreparedChainFilter::Open(AudioFormat &in_audio_format)
{
- std::unique_ptr<ChainFilter> chain(new ChainFilter(in_audio_format));
+ auto chain = std::make_unique<ChainFilter>(in_audio_format);
for (auto &child : children) {
AudioFormat audio_format = chain->GetOutAudioFormat();
- auto *filter = child.Open(audio_format);
- chain->Append(child.name, filter);
+ chain->Append(child.name, child.Open(audio_format));
}
- return chain.release();
+ return chain;
}
void
diff --git a/src/filter/plugins/ConvertFilterPlugin.cxx b/src/filter/plugins/ConvertFilterPlugin.cxx
index 571f68e6e..8800d4b00 100644
--- a/src/filter/plugins/ConvertFilterPlugin.cxx
+++ b/src/filter/plugins/ConvertFilterPlugin.cxx
@@ -59,7 +59,7 @@ public:
class PreparedConvertFilter final : public PreparedFilter {
public:
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
void
@@ -91,12 +91,12 @@ ConvertFilter::ConvertFilter(const AudioFormat &audio_format)
{
}
-Filter *
+std::unique_ptr<Filter>
PreparedConvertFilter::Open(AudioFormat &audio_format)
{
assert(audio_format.IsValid());
- return new ConvertFilter(audio_format);
+ return std::make_unique<ConvertFilter>(audio_format);
}
ConvertFilter::~ConvertFilter()
diff --git a/src/filter/plugins/NormalizeFilterPlugin.cxx b/src/filter/plugins/NormalizeFilterPlugin.cxx
index 16119086b..99b2c205f 100644
--- a/src/filter/plugins/NormalizeFilterPlugin.cxx
+++ b/src/filter/plugins/NormalizeFilterPlugin.cxx
@@ -50,7 +50,7 @@ public:
class PreparedNormalizeFilter final : public PreparedFilter {
public:
/* virtual methods from class PreparedFilter */
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
static std::unique_ptr<PreparedFilter>
@@ -59,12 +59,12 @@ normalize_filter_init(gcc_unused const ConfigBlock &block)
return std::make_unique<PreparedNormalizeFilter>();
}
-Filter *
+std::unique_ptr<Filter>
PreparedNormalizeFilter::Open(AudioFormat &audio_format)
{
audio_format.format = SampleFormat::S16;
- return new NormalizeFilter(audio_format);
+ return std::make_unique<NormalizeFilter>(audio_format);
}
ConstBuffer<void>
diff --git a/src/filter/plugins/NullFilterPlugin.cxx b/src/filter/plugins/NullFilterPlugin.cxx
index 7856494bd..895402ae4 100644
--- a/src/filter/plugins/NullFilterPlugin.cxx
+++ b/src/filter/plugins/NullFilterPlugin.cxx
@@ -43,8 +43,8 @@ public:
class PreparedNullFilter final : public PreparedFilter {
public:
- virtual Filter *Open(AudioFormat &af) override {
- return new NullFilter(af);
+ virtual std::unique_ptr<Filter> Open(AudioFormat &af) override {
+ return std::make_unique<NullFilter>(af);
}
};
diff --git a/src/filter/plugins/ReplayGainFilterPlugin.cxx b/src/filter/plugins/ReplayGainFilterPlugin.cxx
index 0a74bb13c..84e2bcde5 100644
--- a/src/filter/plugins/ReplayGainFilterPlugin.cxx
+++ b/src/filter/plugins/ReplayGainFilterPlugin.cxx
@@ -138,7 +138,7 @@ public:
}
/* virtual methods from class Filter */
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
void
@@ -177,10 +177,10 @@ NewReplayGainFilter(const ReplayGainConfig &config) noexcept
return std::make_unique<PreparedReplayGainFilter>(config);
}
-Filter *
+std::unique_ptr<Filter>
PreparedReplayGainFilter::Open(AudioFormat &af)
{
- return new ReplayGainFilter(config, af, mixer, base);
+ return std::make_unique<ReplayGainFilter>(config, af, mixer, base);
}
ConstBuffer<void>
diff --git a/src/filter/plugins/RouteFilterPlugin.cxx b/src/filter/plugins/RouteFilterPlugin.cxx
index 98181800a..10a4045c0 100644
--- a/src/filter/plugins/RouteFilterPlugin.cxx
+++ b/src/filter/plugins/RouteFilterPlugin.cxx
@@ -134,7 +134,7 @@ public:
PreparedRouteFilter(const ConfigBlock &block);
/* virtual methods from class PreparedFilter */
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
PreparedRouteFilter::PreparedRouteFilter(const ConfigBlock &block)
@@ -216,10 +216,11 @@ RouteFilter::RouteFilter(const AudioFormat &audio_format,
output_frame_size = out_audio_format.GetFrameSize();
}
-Filter *
+std::unique_ptr<Filter>
PreparedRouteFilter::Open(AudioFormat &audio_format)
{
- return new RouteFilter(audio_format, min_output_channels, sources);
+ return std::make_unique<RouteFilter>(audio_format, min_output_channels,
+ sources);
}
ConstBuffer<void>
diff --git a/src/filter/plugins/VolumeFilterPlugin.cxx b/src/filter/plugins/VolumeFilterPlugin.cxx
index 2c7addbd1..2d113c820 100644
--- a/src/filter/plugins/VolumeFilterPlugin.cxx
+++ b/src/filter/plugins/VolumeFilterPlugin.cxx
@@ -50,13 +50,13 @@ public:
class PreparedVolumeFilter final : public PreparedFilter {
public:
/* virtual methods from class Filter */
- Filter *Open(AudioFormat &af) override;
+ std::unique_ptr<Filter> Open(AudioFormat &af) override;
};
-Filter *
+std::unique_ptr<Filter>
PreparedVolumeFilter::Open(AudioFormat &audio_format)
{
- return new VolumeFilter(audio_format);
+ return std::make_unique<VolumeFilter>(audio_format);
}
ConstBuffer<void>