filter/Filter: add method ReadMore()

This allows FilterPCM() to return more data, which some
implementations may need to do (e.g. FFmpeg).
This commit is contained in:
Max Kellermann
2021-08-26 14:20:36 +02:00
committed by Max Kellermann
parent d8bb833ba3
commit 849c4012c0
8 changed files with 84 additions and 10 deletions

View File

@@ -84,6 +84,12 @@ FfmpegFilter::FilterPCM(std::span<const std::byte> src)
return ReadOutput();
}
std::span<const std::byte>
FfmpegFilter::ReadMore()
{
return ReadOutput();
}
std::span<const std::byte>
FfmpegFilter::Flush()
{

View File

@@ -54,6 +54,7 @@ public:
/* virtual methods from class Filter */
std::span<const std::byte> FilterPCM(std::span<const std::byte> src) override;
std::span<const std::byte> ReadMore() override;
std::span<const std::byte> Flush() override;
private:

View File

@@ -21,13 +21,47 @@ TwoFilters::FilterPCM(std::span<const std::byte> src)
}
std::span<const std::byte>
TwoFilters::Flush()
TwoFilters::ReadMore()
{
if (auto result = first->Flush(); !result.empty())
/* Flush() output from the first Filter must be
filtered by the second Filter */
assert(first);
assert(second);
/* first read all remaining data from the second filter */
if (auto result = second->ReadMore(); !result.empty())
return result;
/* now read more data from the first filter and process it
with the second filter */
if (auto result = first->ReadMore(); !result.empty())
/* output from the first Filter must be filtered by
the second Filter */
return second->FilterPCM(result);
/* both filters have been queried and there's no more data */
return {};
}
std::span<const std::byte>
TwoFilters::Flush()
{
assert(second);
/* first read all remaining data from the second filter */
if (auto result = second->ReadMore(); !result.empty())
return result;
/* now flush the first filter and process it with the second
filter */
if (first) {
if (auto result = first->Flush(); !result.empty())
/* output from the first Filter must be
filtered by the second Filter */
return second->FilterPCM(result);
first.reset();
}
/* finally flush the second filter */
return second->Flush();
}

View File

@@ -29,6 +29,7 @@ public:
}
std::span<const std::byte> FilterPCM(std::span<const std::byte> src) override;
std::span<const std::byte> ReadMore() override;
std::span<const std::byte> Flush() override;
};