From d7ae512b5e3fb60128206a562b82aae233711a7c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 5 Nov 2024 12:24:26 +0100 Subject: [PATCH] filter/Filter: clarify that the FilterPCM() return value may be empty And adjust TwoFilter accordingly. --- src/filter/Filter.hxx | 2 +- src/filter/plugins/TwoFilters.cxx | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/filter/Filter.hxx b/src/filter/Filter.hxx index 9174076e1..7196cc2d8 100644 --- a/src/filter/Filter.hxx +++ b/src/filter/Filter.hxx @@ -43,7 +43,7 @@ public: * @param src the input buffer * @return the output buffer (will be invalidated by deleting * this object or any call to Reset(), FilterPCM() or - * Flush()) + * Flush()); may be empty if no output is currently available */ virtual std::span FilterPCM(std::span src) = 0; diff --git a/src/filter/plugins/TwoFilters.cxx b/src/filter/plugins/TwoFilters.cxx index 2ffcae1ad..ee67d9073 100644 --- a/src/filter/plugins/TwoFilters.cxx +++ b/src/filter/plugins/TwoFilters.cxx @@ -10,7 +10,14 @@ std::span TwoFilters::FilterPCM(std::span src) { - return second->FilterPCM(first->FilterPCM(src)); + if (const auto dest = first->FilterPCM(src); dest.empty()) [[unlikely]] + /* no output from the first filter; pass the empty + buffer on, do not call the second filter */ + return dest; + else + /* pass output from the first filter to the second + filter and return its result */ + return second->FilterPCM(dest); } std::span