diff --git a/src/filter/FilterInternal.hxx b/src/filter/FilterInternal.hxx index 110920d48..0aa9b5c8e 100644 --- a/src/filter/FilterInternal.hxx +++ b/src/filter/FilterInternal.hxx @@ -52,6 +52,12 @@ public: return out_audio_format; } + /** + * Reset the filter's state, e.g. drop/flush buffers. + */ + virtual void Reset() { + } + /** * Filters a block of PCM data. * @@ -60,7 +66,7 @@ public: * @param src the input buffer * @return the destination buffer on success (will be * invalidated by deleting this object or the next FilterPCM() - * call) + * or Reset() call) */ virtual ConstBuffer FilterPCM(ConstBuffer src) = 0; }; diff --git a/src/filter/plugins/AutoConvertFilterPlugin.cxx b/src/filter/plugins/AutoConvertFilterPlugin.cxx index 7da31a00b..890018243 100644 --- a/src/filter/plugins/AutoConvertFilterPlugin.cxx +++ b/src/filter/plugins/AutoConvertFilterPlugin.cxx @@ -48,6 +48,13 @@ public: :Filter(_filter->GetOutAudioFormat()), filter(std::move(_filter)), convert(std::move(_convert)) {} + void Reset() override { + filter->Reset(); + + if (convert) + convert->Reset(); + } + ConstBuffer FilterPCM(ConstBuffer src) override; }; diff --git a/src/filter/plugins/ChainFilterPlugin.cxx b/src/filter/plugins/ChainFilterPlugin.cxx index ad3d7ddf8..db62c70b1 100644 --- a/src/filter/plugins/ChainFilterPlugin.cxx +++ b/src/filter/plugins/ChainFilterPlugin.cxx @@ -61,6 +61,7 @@ public: } /* virtual methods from class Filter */ + void Reset() override; ConstBuffer FilterPCM(ConstBuffer src) override; }; @@ -130,6 +131,13 @@ PreparedChainFilter::Open(AudioFormat &in_audio_format) return chain.release(); } +void +ChainFilter::Reset() +{ + for (auto &child : children) + child.filter->Reset(); +} + ConstBuffer ChainFilter::FilterPCM(ConstBuffer src) { diff --git a/src/filter/plugins/ConvertFilterPlugin.cxx b/src/filter/plugins/ConvertFilterPlugin.cxx index f42a55be2..1ede2c03e 100644 --- a/src/filter/plugins/ConvertFilterPlugin.cxx +++ b/src/filter/plugins/ConvertFilterPlugin.cxx @@ -52,6 +52,10 @@ public: void Set(const AudioFormat &_out_audio_format); + void Reset() override { + state.Reset(); + } + ConstBuffer FilterPCM(ConstBuffer src) override; };