filter/AutoConvert: move the Filter class to TwoFilters.cxx
This commit is contained in:
parent
77c14692c9
commit
0c965d0573
@ -19,6 +19,7 @@
|
||||
|
||||
#include "AutoConvertFilterPlugin.hxx"
|
||||
#include "ConvertFilterPlugin.hxx"
|
||||
#include "TwoFilters.hxx"
|
||||
#include "filter/Filter.hxx"
|
||||
#include "filter/Prepared.hxx"
|
||||
#include "pcm/AudioFormat.hxx"
|
||||
@ -27,33 +28,6 @@
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
class AutoConvertFilter final : public Filter {
|
||||
/**
|
||||
* The underlying filter.
|
||||
*/
|
||||
std::unique_ptr<Filter> filter;
|
||||
|
||||
/**
|
||||
* A convert_filter, just in case conversion is needed. nullptr
|
||||
* if unused.
|
||||
*/
|
||||
std::unique_ptr<Filter> convert;
|
||||
|
||||
public:
|
||||
AutoConvertFilter(std::unique_ptr<Filter> &&_filter,
|
||||
std::unique_ptr<Filter> &&_convert)
|
||||
:Filter(_filter->GetOutAudioFormat()),
|
||||
filter(std::move(_filter)), convert(std::move(_convert)) {}
|
||||
|
||||
void Reset() noexcept override {
|
||||
filter->Reset();
|
||||
convert->Reset();
|
||||
}
|
||||
|
||||
ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override;
|
||||
ConstBuffer<void> Flush() override;
|
||||
};
|
||||
|
||||
class PreparedAutoConvertFilter final : public PreparedFilter {
|
||||
/**
|
||||
* The underlying filter.
|
||||
@ -88,25 +62,8 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format)
|
||||
auto convert = convert_filter_new(in_audio_format,
|
||||
child_audio_format);
|
||||
|
||||
return std::make_unique<AutoConvertFilter>(std::move(new_filter),
|
||||
std::move(convert));
|
||||
}
|
||||
|
||||
ConstBuffer<void>
|
||||
AutoConvertFilter::FilterPCM(ConstBuffer<void> src)
|
||||
{
|
||||
src = convert->FilterPCM(src);
|
||||
return filter->FilterPCM(src);
|
||||
}
|
||||
|
||||
ConstBuffer<void>
|
||||
AutoConvertFilter::Flush()
|
||||
{
|
||||
auto result = convert->Flush();
|
||||
if (!result.IsNull())
|
||||
return filter->FilterPCM(result);
|
||||
|
||||
return filter->Flush();
|
||||
return std::make_unique<TwoFilters>(std::move(convert),
|
||||
std::move(new_filter));
|
||||
}
|
||||
|
||||
std::unique_ptr<PreparedFilter>
|
||||
|
39
src/filter/plugins/TwoFilters.cxx
Normal file
39
src/filter/plugins/TwoFilters.cxx
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2003-2020 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "TwoFilters.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
|
||||
ConstBuffer<void>
|
||||
TwoFilters::FilterPCM(ConstBuffer<void> src)
|
||||
{
|
||||
return second->FilterPCM(first->FilterPCM(src));
|
||||
}
|
||||
|
||||
ConstBuffer<void>
|
||||
TwoFilters::Flush()
|
||||
{
|
||||
auto result = first->Flush();
|
||||
if (!result.IsNull())
|
||||
/* Flush() output from the first Filter must be
|
||||
filtered by the second Filter */
|
||||
return second->FilterPCM(result);
|
||||
|
||||
return second->Flush();
|
||||
}
|
49
src/filter/plugins/TwoFilters.hxx
Normal file
49
src/filter/plugins/TwoFilters.hxx
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2003-2020 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_WITH_CONVERT_FILTER_HXX
|
||||
#define MPD_WITH_CONVERT_FILTER_HXX
|
||||
|
||||
#include "filter/Filter.hxx"
|
||||
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* A #Filter implementation which chains two other filters.
|
||||
*/
|
||||
class TwoFilters final : public Filter {
|
||||
std::unique_ptr<Filter> first, second;
|
||||
|
||||
public:
|
||||
template<typename F, typename S>
|
||||
TwoFilters(F &&_first, S &&_second) noexcept
|
||||
:Filter(_second->GetOutAudioFormat()),
|
||||
first(std::forward<F>(_first)),
|
||||
second(std::forward<S>(_second)) {}
|
||||
|
||||
void Reset() noexcept override {
|
||||
first->Reset();
|
||||
second->Reset();
|
||||
}
|
||||
|
||||
ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override;
|
||||
ConstBuffer<void> Flush() override;
|
||||
};
|
||||
|
||||
#endif
|
@ -14,6 +14,7 @@ filter_plugins = static_library(
|
||||
'filter_plugins',
|
||||
'../../AudioCompress/compress.c',
|
||||
'NullFilterPlugin.cxx',
|
||||
'TwoFilters.cxx',
|
||||
'ChainFilterPlugin.cxx',
|
||||
'AutoConvertFilterPlugin.cxx',
|
||||
'ConvertFilterPlugin.cxx',
|
||||
|
Loading…
Reference in New Issue
Block a user