filter/convert: add method IsActive()

This commit is contained in:
Max Kellermann 2018-01-29 22:33:54 +01:00
parent eb771eaf0d
commit 7ff5cf8372
1 changed files with 10 additions and 6 deletions

View File

@ -59,6 +59,11 @@ public:
ConstBuffer<void> Flush() override { ConstBuffer<void> Flush() override {
return state.Flush(); return state.Flush();
} }
private:
bool IsActive() const noexcept {
return out_audio_format != in_audio_format;
}
}; };
class PreparedConvertFilter final : public PreparedFilter { class PreparedConvertFilter final : public PreparedFilter {
@ -76,7 +81,7 @@ ConvertFilter::Set(const AudioFormat &_out_audio_format)
/* no change */ /* no change */
return; return;
if (out_audio_format != in_audio_format) { if (IsActive()) {
out_audio_format = in_audio_format; out_audio_format = in_audio_format;
state.Close(); state.Close();
} }
@ -107,7 +112,7 @@ ConvertFilter::~ConvertFilter()
{ {
assert(in_audio_format.IsValid()); assert(in_audio_format.IsValid());
if (out_audio_format != in_audio_format) if (IsActive())
state.Close(); state.Close();
} }
@ -116,11 +121,10 @@ ConvertFilter::FilterPCM(ConstBuffer<void> src)
{ {
assert(in_audio_format.IsValid()); assert(in_audio_format.IsValid());
if (out_audio_format == in_audio_format) return IsActive()
? state.Convert(src)
/* optimized special case: no-op */ /* optimized special case: no-op */
return src; : src;
return state.Convert(src);
} }
std::unique_ptr<PreparedFilter> std::unique_ptr<PreparedFilter>