filter/TwoFilters: add class PreparedTwoFilters
This commit is contained in:
parent
38a4b0d8d5
commit
49dcac5c21
@ -18,7 +18,10 @@
|
||||
*/
|
||||
|
||||
#include "TwoFilters.hxx"
|
||||
#include "pcm/AudioFormat.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/StringBuffer.hxx"
|
||||
|
||||
ConstBuffer<void>
|
||||
TwoFilters::FilterPCM(ConstBuffer<void> src)
|
||||
@ -37,3 +40,21 @@ TwoFilters::Flush()
|
||||
|
||||
return second->Flush();
|
||||
}
|
||||
|
||||
std::unique_ptr<Filter>
|
||||
PreparedTwoFilters::Open(AudioFormat &audio_format)
|
||||
{
|
||||
auto a = first->Open(audio_format);
|
||||
|
||||
const auto &a_out_format = a->GetOutAudioFormat();
|
||||
auto b_in_format = a_out_format;
|
||||
auto b = second->Open(b_in_format);
|
||||
|
||||
if (b_in_format != a_out_format)
|
||||
throw FormatRuntimeError("Audio format not supported by filter '%s': %s",
|
||||
second_name.c_str(),
|
||||
ToString(a_out_format).c_str());
|
||||
|
||||
return std::make_unique<TwoFilters>(std::move(a),
|
||||
std::move(b));
|
||||
}
|
||||
|
@ -21,8 +21,10 @@
|
||||
#define MPD_TWO_FILTERS_HXX
|
||||
|
||||
#include "filter/Filter.hxx"
|
||||
#include "filter/Prepared.hxx"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* A #Filter implementation which chains two other filters.
|
||||
@ -46,4 +48,21 @@ public:
|
||||
ConstBuffer<void> Flush() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* Like #TwoFilters, but implements the #PreparedFilter interface.
|
||||
*/
|
||||
class PreparedTwoFilters final : public PreparedFilter {
|
||||
std::unique_ptr<PreparedFilter> first, second;
|
||||
std::string second_name;
|
||||
|
||||
public:
|
||||
template<typename F, typename S, typename N>
|
||||
PreparedTwoFilters(F &&_first, S &&_second, N &&_second_name) noexcept
|
||||
:first(std::forward<F>(_first)),
|
||||
second(std::forward<S>(_second)),
|
||||
second_name(std::forward<N>(_second_name)) {}
|
||||
|
||||
std::unique_ptr<Filter> Open(AudioFormat &audio_format) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user