FilterPlugin: pass config_param reference

This commit is contained in:
Max Kellermann 2013-08-04 13:38:13 +02:00
parent ca0d09c50f
commit f54bcc1f16
14 changed files with 36 additions and 35 deletions

View File

@ -48,8 +48,7 @@ filter_plugin_config(const char *filter_template_name, GError **error_r)
const struct config_param *param = NULL; const struct config_param *param = NULL;
while ((param = config_get_next_param(CONF_AUDIO_FILTER, param)) != NULL) { while ((param = config_get_next_param(CONF_AUDIO_FILTER, param)) != NULL) {
const char *name = const char *name = param->GetBlockValue("name");
config_get_block_string(param, "name", NULL);
if (name == NULL) { if (name == NULL) {
g_set_error(error_r, filter_quark(), 1, g_set_error(error_r, filter_quark(), 1,
"filter configuration without 'name' name in line %d", "filter configuration without 'name' name in line %d",
@ -100,14 +99,14 @@ filter_chain_parse(Filter &chain, const char *spec, GError **error_r)
} }
// Instantiate one of those filter plugins with the template name as a hint // Instantiate one of those filter plugins with the template name as a hint
Filter *f = filter_configured_new(cfg, error_r); Filter *f = filter_configured_new(*cfg, error_r);
if (f == NULL) { if (f == NULL) {
// The error has already been set, just stop. // The error has already been set, just stop.
break; break;
} }
const char *plugin_name = const char *plugin_name = cfg->GetBlockValue("plugin",
config_get_block_string(cfg, "plugin", "unknown"); "unknown");
filter_chain_append(chain, plugin_name, f); filter_chain_append(chain, plugin_name, f);
++added_filters; ++added_filters;

View File

@ -28,7 +28,7 @@
Filter * Filter *
filter_new(const struct filter_plugin *plugin, filter_new(const struct filter_plugin *plugin,
const struct config_param *param, GError **error_r) const config_param &param, GError **error_r)
{ {
assert(plugin != NULL); assert(plugin != NULL);
assert(error_r == NULL || *error_r == NULL); assert(error_r == NULL || *error_r == NULL);
@ -37,15 +37,13 @@ filter_new(const struct filter_plugin *plugin,
} }
Filter * Filter *
filter_configured_new(const struct config_param *param, GError **error_r) filter_configured_new(const config_param &param, GError **error_r)
{ {
const char *plugin_name;
const struct filter_plugin *plugin; const struct filter_plugin *plugin;
assert(param != NULL);
assert(error_r == NULL || *error_r == NULL); assert(error_r == NULL || *error_r == NULL);
plugin_name = config_get_block_string(param, "plugin", NULL); const char *plugin_name = param.GetBlockValue("plugin");
if (plugin_name == NULL) { if (plugin_name == NULL) {
g_set_error(error_r, config_quark(), 0, g_set_error(error_r, config_quark(), 0,
"No filter plugin specified"); "No filter plugin specified");

View File

@ -39,7 +39,7 @@ struct filter_plugin {
/** /**
* Allocates and configures a filter. * Allocates and configures a filter.
*/ */
Filter *(*init)(const struct config_param *param, GError **error_r); Filter *(*init)(const config_param &param, GError **error_r);
}; };
/** /**
@ -53,7 +53,7 @@ struct filter_plugin {
*/ */
Filter * Filter *
filter_new(const struct filter_plugin *plugin, filter_new(const struct filter_plugin *plugin,
const struct config_param *param, GError **error_r); const config_param &param, GError **error_r);
/** /**
* Creates a new filter, loads configuration and the plugin name from * Creates a new filter, loads configuration and the plugin name from
@ -65,6 +65,6 @@ filter_new(const struct filter_plugin *plugin,
* @return a new filter object, or NULL on error * @return a new filter object, or NULL on error
*/ */
Filter * Filter *
filter_configured_new(const struct config_param *param, GError **error_r); filter_configured_new(const config_param &param, GError **error_r);
#endif #endif

View File

@ -183,7 +183,8 @@ ao_base_init(struct audio_output *ao,
if (config_get_bool(CONF_VOLUME_NORMALIZATION, false)) { if (config_get_bool(CONF_VOLUME_NORMALIZATION, false)) {
Filter *normalize_filter = Filter *normalize_filter =
filter_new(&normalize_filter_plugin, NULL, NULL); filter_new(&normalize_filter_plugin, config_param(),
nullptr);
assert(normalize_filter != NULL); assert(normalize_filter != NULL);
filter_chain_append(*ao->filter, "normalize", filter_chain_append(*ao->filter, "normalize",
@ -227,13 +228,13 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
if (strcmp(replay_gain_handler, "none") != 0) { if (strcmp(replay_gain_handler, "none") != 0) {
ao->replay_gain_filter = filter_new(&replay_gain_filter_plugin, ao->replay_gain_filter = filter_new(&replay_gain_filter_plugin,
&param, NULL); param, NULL);
assert(ao->replay_gain_filter != NULL); assert(ao->replay_gain_filter != NULL);
ao->replay_gain_serial = 0; ao->replay_gain_serial = 0;
ao->other_replay_gain_filter = filter_new(&replay_gain_filter_plugin, ao->other_replay_gain_filter = filter_new(&replay_gain_filter_plugin,
&param, NULL); param, NULL);
assert(ao->other_replay_gain_filter != NULL); assert(ao->other_replay_gain_filter != NULL);
ao->other_replay_gain_serial = 0; ao->other_replay_gain_serial = 0;
@ -271,7 +272,8 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
/* the "convert" filter must be the last one in the chain */ /* the "convert" filter must be the last one in the chain */
ao->convert_filter = filter_new(&convert_filter_plugin, NULL, NULL); ao->convert_filter = filter_new(&convert_filter_plugin, config_param(),
nullptr);
assert(ao->convert_filter != NULL); assert(ao->convert_filter != NULL);
filter_chain_append(*ao->filter, "convert", ao->convert_filter); filter_chain_append(*ao->filter, "convert", ao->convert_filter);

View File

@ -24,6 +24,7 @@
#include "FilterInternal.hxx" #include "FilterInternal.hxx"
#include "FilterRegistry.hxx" #include "FilterRegistry.hxx"
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "ConfigData.hxx"
#include <assert.h> #include <assert.h>
@ -68,7 +69,8 @@ AutoConvertFilter::Open(AudioFormat &in_audio_format, GError **error_r)
if (in_audio_format != child_audio_format) { if (in_audio_format != child_audio_format) {
/* yes - create a convert_filter */ /* yes - create a convert_filter */
convert = filter_new(&convert_filter_plugin, nullptr, error_r); const config_param empty;
convert = filter_new(&convert_filter_plugin, empty, error_r);
if (convert == nullptr) { if (convert == nullptr) {
filter->Close(); filter->Close();
return AudioFormat::Undefined(); return AudioFormat::Undefined();

View File

@ -73,7 +73,7 @@ filter_quark(void)
} }
static Filter * static Filter *
chain_filter_init(gcc_unused const struct config_param *param, chain_filter_init(gcc_unused const config_param &param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
return new ChainFilter(); return new ChainFilter();

View File

@ -63,7 +63,7 @@ public:
}; };
static Filter * static Filter *
convert_filter_init(gcc_unused const struct config_param *param, convert_filter_init(gcc_unused const config_param &param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
return new ConvertFilter(); return new ConvertFilter();

View File

@ -41,7 +41,7 @@ public:
}; };
static Filter * static Filter *
normalize_filter_init(gcc_unused const struct config_param *param, normalize_filter_init(gcc_unused const config_param &param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
return new NormalizeFilter(); return new NormalizeFilter();

View File

@ -49,7 +49,7 @@ public:
}; };
static Filter * static Filter *
null_filter_init(gcc_unused const struct config_param *param, null_filter_init(gcc_unused const config_param &param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
return new NullFilter(); return new NullFilter();

View File

@ -153,7 +153,7 @@ ReplayGainFilter::Update()
} }
static Filter * static Filter *
replay_gain_filter_init(gcc_unused const struct config_param *param, replay_gain_filter_init(gcc_unused const config_param &param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
return new ReplayGainFilter(); return new ReplayGainFilter();

View File

@ -118,7 +118,7 @@ public:
* @param filter a route_filter whose min_channels and sources[] to set * @param filter a route_filter whose min_channels and sources[] to set
* @return true on success, false on error * @return true on success, false on error
*/ */
bool Configure(const config_param *param, GError **error_r); bool Configure(const config_param &param, GError **error_r);
virtual AudioFormat Open(AudioFormat &af, GError **error_r) override; virtual AudioFormat Open(AudioFormat &af, GError **error_r) override;
virtual void Close(); virtual void Close();
@ -127,7 +127,7 @@ public:
}; };
bool bool
RouteFilter::Configure(const config_param *param, GError **error_r) { RouteFilter::Configure(const config_param &param, GError **error_r) {
/* TODO: /* TODO:
* With a more clever way of marking "don't copy to output N", * With a more clever way of marking "don't copy to output N",
@ -139,8 +139,7 @@ RouteFilter::Configure(const config_param *param, GError **error_r) {
int number_of_copies; int number_of_copies;
// A cowardly default, just passthrough stereo // A cowardly default, just passthrough stereo
const char *routes = const char *const routes = param.GetBlockValue("routes", "0>0, 1>1");
config_get_block_string(param, "routes", "0>0, 1>1");
min_input_channels = 0; min_input_channels = 0;
min_output_channels = 0; min_output_channels = 0;
@ -163,7 +162,7 @@ RouteFilter::Configure(const config_param *param, GError **error_r) {
if (g_strv_length(sd) != 2) { if (g_strv_length(sd) != 2) {
g_set_error(error_r, config_quark(), 1, g_set_error(error_r, config_quark(), 1,
"Invalid copy around %d in routes spec: %s", "Invalid copy around %d in routes spec: %s",
param->line, tokens[c]); param.line, tokens[c]);
g_strfreev(sd); g_strfreev(sd);
g_strfreev(tokens); g_strfreev(tokens);
return false; return false;
@ -210,7 +209,7 @@ RouteFilter::Configure(const config_param *param, GError **error_r) {
if (g_strv_length(sd) != 2) { if (g_strv_length(sd) != 2) {
g_set_error(error_r, config_quark(), 1, g_set_error(error_r, config_quark(), 1,
"Invalid copy around %d in routes spec: %s", "Invalid copy around %d in routes spec: %s",
param->line, tokens[c]); param.line, tokens[c]);
g_strfreev(sd); g_strfreev(sd);
g_strfreev(tokens); g_strfreev(tokens);
return false; return false;
@ -230,7 +229,7 @@ RouteFilter::Configure(const config_param *param, GError **error_r) {
} }
static Filter * static Filter *
route_filter_init(const config_param *param, GError **error_r) route_filter_init(const config_param &param, GError **error_r)
{ {
RouteFilter *filter = new RouteFilter(); RouteFilter *filter = new RouteFilter();
if (!filter->Configure(param, error_r)) { if (!filter->Configure(param, error_r)) {

View File

@ -69,7 +69,7 @@ volume_quark(void)
} }
static Filter * static Filter *
volume_filter_init(gcc_unused const struct config_param *param, volume_filter_init(gcc_unused const config_param &param,
gcc_unused GError **error_r) gcc_unused GError **error_r)
{ {
return new VolumeFilter(); return new VolumeFilter();

View File

@ -25,6 +25,7 @@
#include "FilterInternal.hxx" #include "FilterInternal.hxx"
#include "filter/VolumeFilterPlugin.hxx" #include "filter/VolumeFilterPlugin.hxx"
#include "pcm/PcmVolume.hxx" #include "pcm/PcmVolume.hxx"
#include "ConfigData.hxx"
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
@ -36,7 +37,8 @@ struct SoftwareMixer final : public Mixer {
SoftwareMixer() SoftwareMixer()
:Mixer(software_mixer_plugin), :Mixer(software_mixer_plugin),
filter(filter_new(&volume_filter_plugin, nullptr, nullptr)), filter(filter_new(&volume_filter_plugin, config_param(),
nullptr)),
volume(100) volume(100)
{ {
assert(filter != nullptr); assert(filter != nullptr);

View File

@ -58,8 +58,7 @@ find_named_config_block(ConfigOption option, const char *name)
const struct config_param *param = NULL; const struct config_param *param = NULL;
while ((param = config_get_next_param(option, param)) != NULL) { while ((param = config_get_next_param(option, param)) != NULL) {
const char *current_name = const char *current_name = param->GetBlockValue("name");
config_get_block_string(param, "name", NULL);
if (current_name != NULL && strcmp(current_name, name) == 0) if (current_name != NULL && strcmp(current_name, name) == 0)
return param; return param;
} }
@ -79,7 +78,7 @@ load_filter(const char *name)
return nullptr; return nullptr;
} }
Filter *filter = filter_configured_new(param, &error); Filter *filter = filter_configured_new(*param, &error);
if (filter == NULL) { if (filter == NULL) {
g_printerr("Failed to load filter: %s\n", error->message); g_printerr("Failed to load filter: %s\n", error->message);
g_error_free(error); g_error_free(error);