Skip to content

Commit

Permalink
filter/Filter: clarify that the FilterPCM() return value may be empty
Browse files Browse the repository at this point in the history
And adjust TwoFilter accordingly.
  • Loading branch information
MaxKellermann committed Nov 5, 2024
1 parent b7b4c6b commit d7ae512
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/filter/Filter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<const std::byte> FilterPCM(std::span<const std::byte> src) = 0;

Expand Down
9 changes: 8 additions & 1 deletion src/filter/plugins/TwoFilters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
std::span<const std::byte>
TwoFilters::FilterPCM(std::span<const std::byte> 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<const std::byte>
Expand Down

0 comments on commit d7ae512

Please sign in to comment.