diff options
author | Max Kellermann <max@musicpd.org> | 2019-04-04 20:55:39 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-04-04 21:01:08 +0200 |
commit | e78d8250598e4a12bfe3fac4111927598aecdef4 (patch) | |
tree | 9343165ef8c96625e1859fdec514459f1e033f5b /src/filter | |
parent | 00b04468dc2281a09857e1b1d8fea92462568fb2 (diff) |
pcm/PcmConvert: eliminate Open() and Close()
Let the constructor and destructor do this. This means that all users
have to be converted to allocate PcmConvert dynamically.
Diffstat (limited to 'src/filter')
-rw-r--r-- | src/filter/plugins/ConvertFilterPlugin.cxx | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/src/filter/plugins/ConvertFilterPlugin.cxx b/src/filter/plugins/ConvertFilterPlugin.cxx index a5e501afd..8a0a8c7d8 100644 --- a/src/filter/plugins/ConvertFilterPlugin.cxx +++ b/src/filter/plugins/ConvertFilterPlugin.cxx @@ -41,31 +41,25 @@ class ConvertFilter final : public Filter { * This object is only "open" if #in_audio_format != * #out_audio_format. */ - PcmConvert state; + std::unique_ptr<PcmConvert> state; public: ConvertFilter(const AudioFormat &audio_format); - ~ConvertFilter(); void Set(const AudioFormat &_out_audio_format); void Reset() noexcept override { - if (IsActive()) - state.Reset(); + if (state) + state->Reset(); } ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override; ConstBuffer<void> Flush() override { - return IsActive() - ? state.Flush() + return state + ? state->Flush() : nullptr; } - -private: - bool IsActive() const noexcept { - return out_audio_format != in_audio_format; - } }; class PreparedConvertFilter final : public PreparedFilter { @@ -82,16 +76,17 @@ ConvertFilter::Set(const AudioFormat &_out_audio_format) /* no change */ return; - if (IsActive()) { + if (state) { out_audio_format = in_audio_format; - state.Close(); + state.reset(); } if (_out_audio_format == in_audio_format) /* optimized special case: no-op */ return; - state.Open(in_audio_format, _out_audio_format); + state = std::make_unique<PcmConvert>(in_audio_format, + _out_audio_format); out_audio_format = _out_audio_format; } @@ -110,17 +105,11 @@ PreparedConvertFilter::Open(AudioFormat &audio_format) return std::make_unique<ConvertFilter>(audio_format); } -ConvertFilter::~ConvertFilter() -{ - if (IsActive()) - state.Close(); -} - ConstBuffer<void> ConvertFilter::FilterPCM(ConstBuffer<void> src) { - return IsActive() - ? state.Convert(src) + return state + ? state->Convert(src) /* optimized special case: no-op */ : src; } |