Filter*: move to filter/
This commit is contained in:
108
src/filter/FilterConfig.cxx
Normal file
108
src/filter/FilterConfig.cxx
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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 "config.h"
|
||||
#include "FilterConfig.hxx"
|
||||
#include "plugins/ChainFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "config/ConfigData.hxx"
|
||||
#include "config/ConfigOption.hxx"
|
||||
#include "config/ConfigGlobal.hxx"
|
||||
#include "config/ConfigError.hxx"
|
||||
#include "util/Error.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Find the "filter" configuration block for the specified name.
|
||||
*
|
||||
* @param filter_template_name the name of the filter template
|
||||
* @param error space to return an error description
|
||||
* @return the configuration block, or nullptr if none was configured
|
||||
*/
|
||||
static const struct config_param *
|
||||
filter_plugin_config(const char *filter_template_name, Error &error)
|
||||
{
|
||||
const struct config_param *param = nullptr;
|
||||
|
||||
while ((param = config_get_next_param(CONF_AUDIO_FILTER, param)) != nullptr) {
|
||||
const char *name = param->GetBlockValue("name");
|
||||
if (name == nullptr) {
|
||||
error.Format(config_domain,
|
||||
"filter configuration without 'name' name in line %d",
|
||||
param->line);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (strcmp(name, filter_template_name) == 0)
|
||||
return param;
|
||||
}
|
||||
|
||||
error.Format(config_domain,
|
||||
"filter template not found: %s",
|
||||
filter_template_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool
|
||||
filter_chain_append_new(Filter &chain, const char *template_name, Error &error)
|
||||
{
|
||||
const struct config_param *cfg =
|
||||
filter_plugin_config(template_name, error);
|
||||
if (cfg == nullptr)
|
||||
// The error has already been set, just stop.
|
||||
return false;
|
||||
|
||||
// Instantiate one of those filter plugins with the template name as a hint
|
||||
Filter *f = filter_configured_new(*cfg, error);
|
||||
if (f == nullptr)
|
||||
// The error has already been set, just stop.
|
||||
return false;
|
||||
|
||||
const char *plugin_name = cfg->GetBlockValue("plugin",
|
||||
"unknown");
|
||||
filter_chain_append(chain, plugin_name, f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
filter_chain_parse(Filter &chain, const char *spec, Error &error)
|
||||
{
|
||||
const char *const end = spec + strlen(spec);
|
||||
|
||||
while (true) {
|
||||
const char *comma = std::find(spec, end, ',');
|
||||
if (comma > spec) {
|
||||
const std::string name(spec, comma);
|
||||
if (!filter_chain_append_new(chain, name.c_str(),
|
||||
error))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (comma == end)
|
||||
break;
|
||||
|
||||
spec = comma + 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
43
src/filter/FilterConfig.hxx
Normal file
43
src/filter/FilterConfig.hxx
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Utility functions for filter configuration
|
||||
*/
|
||||
|
||||
#ifndef MPD_FILTER_CONFIG_HXX
|
||||
#define MPD_FILTER_CONFIG_HXX
|
||||
|
||||
class Filter;
|
||||
class Error;
|
||||
|
||||
/**
|
||||
* Builds a filter chain from a configuration string on the form
|
||||
* "name1, name2, name3, ..." by looking up each name among the
|
||||
* configured filter sections.
|
||||
* @param chain the chain to append filters on
|
||||
* @param spec the filter chain specification
|
||||
* @param error_r space to return an error description
|
||||
* @return true on success
|
||||
*/
|
||||
bool
|
||||
filter_chain_parse(Filter &chain, const char *spec, Error &error);
|
||||
|
||||
#endif
|
74
src/filter/FilterInternal.hxx
Normal file
74
src/filter/FilterInternal.hxx
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Internal stuff for the filter core and filter plugins.
|
||||
*/
|
||||
|
||||
#ifndef MPD_FILTER_INTERNAL_HXX
|
||||
#define MPD_FILTER_INTERNAL_HXX
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct AudioFormat;
|
||||
class Error;
|
||||
|
||||
class Filter {
|
||||
public:
|
||||
virtual ~Filter() {}
|
||||
|
||||
/**
|
||||
* Opens the filter, preparing it for FilterPCM().
|
||||
*
|
||||
* @param filter the filter object
|
||||
* @param audio_format the audio format of incoming data; the
|
||||
* plugin may modify the object to enforce another input
|
||||
* format
|
||||
* @param error location to store the error occurring, or nullptr
|
||||
* to ignore errors.
|
||||
* @return the format of outgoing data or
|
||||
* AudioFormat::Undefined() on error
|
||||
*/
|
||||
virtual AudioFormat Open(AudioFormat &af, Error &error) = 0;
|
||||
|
||||
/**
|
||||
* Closes the filter. After that, you may call Open() again.
|
||||
*/
|
||||
virtual void Close() = 0;
|
||||
|
||||
/**
|
||||
* Filters a block of PCM data.
|
||||
*
|
||||
* @param filter the filter object
|
||||
* @param src the input buffer
|
||||
* @param src_size the size of #src_buffer in bytes
|
||||
* @param dest_size_r the size of the returned buffer
|
||||
* @param error location to store the error occurring, or nullptr
|
||||
* to ignore errors.
|
||||
* @return the destination buffer on success (will be
|
||||
* invalidated by filter_close() or filter_filter()), nullptr on
|
||||
* error
|
||||
*/
|
||||
virtual const void *FilterPCM(const void *src, size_t src_size,
|
||||
size_t *dest_size_r,
|
||||
Error &error) = 0;
|
||||
};
|
||||
|
||||
#endif
|
58
src/filter/FilterPlugin.cxx
Normal file
58
src/filter/FilterPlugin.cxx
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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 "config.h"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "config/ConfigData.hxx"
|
||||
#include "config/ConfigError.hxx"
|
||||
#include "util/Error.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
Filter *
|
||||
filter_new(const struct filter_plugin *plugin,
|
||||
const config_param ¶m, Error &error)
|
||||
{
|
||||
assert(plugin != nullptr);
|
||||
assert(!error.IsDefined());
|
||||
|
||||
return plugin->init(param, error);
|
||||
}
|
||||
|
||||
Filter *
|
||||
filter_configured_new(const config_param ¶m, Error &error)
|
||||
{
|
||||
assert(!error.IsDefined());
|
||||
|
||||
const char *plugin_name = param.GetBlockValue("plugin");
|
||||
if (plugin_name == nullptr) {
|
||||
error.Set(config_domain, "No filter plugin specified");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const filter_plugin *plugin = filter_plugin_by_name(plugin_name);
|
||||
if (plugin == nullptr) {
|
||||
error.Format(config_domain,
|
||||
"No such filter plugin: %s", plugin_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return filter_new(plugin, param, error);
|
||||
}
|
67
src/filter/FilterPlugin.hxx
Normal file
67
src/filter/FilterPlugin.hxx
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* This header declares the filter_plugin class. It describes a
|
||||
* plugin API for objects which filter raw PCM data.
|
||||
*/
|
||||
|
||||
#ifndef MPD_FILTER_PLUGIN_HXX
|
||||
#define MPD_FILTER_PLUGIN_HXX
|
||||
|
||||
struct config_param;
|
||||
class Filter;
|
||||
class Error;
|
||||
|
||||
struct filter_plugin {
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
* Allocates and configures a filter.
|
||||
*/
|
||||
Filter *(*init)(const config_param ¶m, Error &error);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new instance of the specified filter plugin.
|
||||
*
|
||||
* @param plugin the filter plugin
|
||||
* @param param optional configuration section
|
||||
* @param error location to store the error occurring, or nullptr to
|
||||
* ignore errors.
|
||||
* @return a new filter object, or nullptr on error
|
||||
*/
|
||||
Filter *
|
||||
filter_new(const struct filter_plugin *plugin,
|
||||
const config_param ¶m, Error &error);
|
||||
|
||||
/**
|
||||
* Creates a new filter, loads configuration and the plugin name from
|
||||
* the specified configuration section.
|
||||
*
|
||||
* @param param the configuration section
|
||||
* @param error location to store the error occurring, or nullptr to
|
||||
* ignore errors.
|
||||
* @return a new filter object, or nullptr on error
|
||||
*/
|
||||
Filter *
|
||||
filter_configured_new(const config_param ¶m, Error &error);
|
||||
|
||||
#endif
|
43
src/filter/FilterRegistry.cxx
Normal file
43
src/filter/FilterRegistry.cxx
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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 "config.h"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
const struct filter_plugin *const filter_plugins[] = {
|
||||
&null_filter_plugin,
|
||||
&route_filter_plugin,
|
||||
&normalize_filter_plugin,
|
||||
&volume_filter_plugin,
|
||||
&replay_gain_filter_plugin,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
const struct filter_plugin *
|
||||
filter_plugin_by_name(const char *name)
|
||||
{
|
||||
for (unsigned i = 0; filter_plugins[i] != nullptr; ++i)
|
||||
if (strcmp(filter_plugins[i]->name, name) == 0)
|
||||
return filter_plugins[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
43
src/filter/FilterRegistry.hxx
Normal file
43
src/filter/FilterRegistry.hxx
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2014 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.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* This library manages all filter plugins which are enabled at
|
||||
* compile time.
|
||||
*/
|
||||
|
||||
#ifndef MPD_FILTER_REGISTRY_HXX
|
||||
#define MPD_FILTER_REGISTRY_HXX
|
||||
|
||||
#include "Compiler.h"
|
||||
|
||||
extern const struct filter_plugin null_filter_plugin;
|
||||
extern const struct filter_plugin chain_filter_plugin;
|
||||
extern const struct filter_plugin convert_filter_plugin;
|
||||
extern const struct filter_plugin route_filter_plugin;
|
||||
extern const struct filter_plugin normalize_filter_plugin;
|
||||
extern const struct filter_plugin volume_filter_plugin;
|
||||
extern const struct filter_plugin replay_gain_filter_plugin;
|
||||
|
||||
gcc_pure
|
||||
const struct filter_plugin *
|
||||
filter_plugin_by_name(const char *name);
|
||||
|
||||
#endif
|
@@ -20,9 +20,9 @@
|
||||
#include "config.h"
|
||||
#include "AutoConvertFilterPlugin.hxx"
|
||||
#include "ConvertFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "config/ConfigData.hxx"
|
||||
|
@@ -19,9 +19,9 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "ChainFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "util/Domain.hxx"
|
@@ -19,9 +19,9 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "ConvertFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "pcm/PcmConvert.hxx"
|
||||
#include "util/Manual.hxx"
|
||||
#include "AudioFormat.hxx"
|
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "pcm/PcmBuffer.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "AudioCompress/compress.h"
|
@@ -25,9 +25,9 @@
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "Compiler.h"
|
||||
|
@@ -19,9 +19,9 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "ReplayGainFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "ReplayGainInfo.hxx"
|
||||
#include "ReplayGainConfig.hxx"
|
@@ -43,9 +43,9 @@
|
||||
#include "config/ConfigError.hxx"
|
||||
#include "config/ConfigData.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "pcm/PcmBuffer.hxx"
|
||||
#include "util/StringUtil.hxx"
|
||||
#include "util/Error.hxx"
|
@@ -19,9 +19,9 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "VolumeFilterPlugin.hxx"
|
||||
#include "FilterPlugin.hxx"
|
||||
#include "FilterInternal.hxx"
|
||||
#include "FilterRegistry.hxx"
|
||||
#include "filter/FilterPlugin.hxx"
|
||||
#include "filter/FilterInternal.hxx"
|
||||
#include "filter/FilterRegistry.hxx"
|
||||
#include "pcm/Volume.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
Reference in New Issue
Block a user