Proper error reporting from filter_config
This commit is contained in:
parent
ff3393ebf1
commit
69391dadda
@ -27,28 +27,43 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
static GQuark
|
||||||
|
filter_quark(void)
|
||||||
|
{
|
||||||
|
return g_quark_from_static_string("filter");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the "filter" configuration block for the specified name.
|
* Find the "filter" configuration block for the specified name.
|
||||||
*
|
*
|
||||||
* @param filter_template_name the name of the filter template
|
* @param filter_template_name the name of the filter template
|
||||||
|
* @param error_r space to return an error description
|
||||||
* @return the configuration block, or NULL if none was configured
|
* @return the configuration block, or NULL if none was configured
|
||||||
*/
|
*/
|
||||||
static const struct config_param *
|
static const struct config_param *
|
||||||
filter_plugin_config(const char *filter_template_name)
|
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 =
|
||||||
config_get_block_string(param, "name", NULL);
|
config_get_block_string(param, "name", NULL);
|
||||||
if (name == NULL)
|
if (name == NULL) {
|
||||||
g_error("filter configuration without 'name' name in line %d",
|
g_set_error(error_r, filter_quark(), 1,
|
||||||
|
"filter configuration without 'name' name in line %d",
|
||||||
param->line);
|
param->line);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(name, filter_template_name) == 0)
|
if (strcmp(name, filter_template_name) == 0)
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_set_error(error_r, filter_quark(), 1,
|
||||||
|
"filter template not found: %s",
|
||||||
|
filter_template_name);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,10 +73,11 @@ filter_plugin_config(const char *filter_template_name)
|
|||||||
* configured filter sections.
|
* configured filter sections.
|
||||||
* @param chain the chain to append filters on
|
* @param chain the chain to append filters on
|
||||||
* @param spec the filter chain specification
|
* @param spec the filter chain specification
|
||||||
|
* @param error_r space to return an error description
|
||||||
* @return the number of filters which were successfully added
|
* @return the number of filters which were successfully added
|
||||||
*/
|
*/
|
||||||
unsigned int
|
unsigned int
|
||||||
filter_chain_parse(struct filter *chain, const char *spec)
|
filter_chain_parse(struct filter *chain, const char *spec, GError **error_r)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Split on comma
|
// Split on comma
|
||||||
@ -80,38 +96,36 @@ filter_chain_parse(struct filter *chain, const char *spec)
|
|||||||
// Squeeze whitespace
|
// Squeeze whitespace
|
||||||
g_strstrip(*template_names);
|
g_strstrip(*template_names);
|
||||||
|
|
||||||
cfg = filter_plugin_config(*template_names);
|
cfg = filter_plugin_config(*template_names, error_r);
|
||||||
if (cfg == NULL) {
|
if (cfg == NULL) {
|
||||||
g_error("Unable to locate filter template %s",
|
// The error has already been set, just stop.
|
||||||
*template_names);
|
break;
|
||||||
++template_names;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out what kind of a plugin that is
|
// Figure out what kind of a plugin that is
|
||||||
plugin_name = config_get_block_string(cfg, "plugin", NULL);
|
plugin_name = config_get_block_string(cfg, "plugin", NULL);
|
||||||
if (plugin_name == NULL) {
|
if (plugin_name == NULL) {
|
||||||
g_error("filter configuration without 'plugin' at line %d",
|
g_set_error(error_r, filter_quark(), 1,
|
||||||
|
"filter configuration without 'plugin' at line %d",
|
||||||
cfg->line);
|
cfg->line);
|
||||||
++template_names;
|
break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
fp = filter_plugin_by_name(plugin_name);
|
fp = filter_plugin_by_name(plugin_name);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
g_error("filter plugin not found: %s",
|
g_set_error(error_r, filter_quark(), 2,
|
||||||
|
"filter plugin not found: %s",
|
||||||
plugin_name);
|
plugin_name);
|
||||||
++template_names;
|
break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f = filter_new(fp, cfg, NULL);
|
f = filter_new(fp, cfg, NULL);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
g_error("filter plugin initialization failed: %s",
|
g_set_error(error_r, filter_quark(), 3,
|
||||||
|
"filter plugin initialization failed: %s",
|
||||||
plugin_name);
|
plugin_name);
|
||||||
++template_names;
|
break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filter_chain_append(chain, f);
|
filter_chain_append(chain, f);
|
||||||
|
@ -38,9 +38,10 @@
|
|||||||
* configured filter sections.
|
* configured filter sections.
|
||||||
* @param chain the chain to append filters on
|
* @param chain the chain to append filters on
|
||||||
* @param spec the filter chain specification
|
* @param spec the filter chain specification
|
||||||
|
* @param error_r space to return an error description
|
||||||
* @return the number of filters which were successfully added
|
* @return the number of filters which were successfully added
|
||||||
*/
|
*/
|
||||||
unsigned int
|
unsigned int
|
||||||
filter_chain_parse(struct filter *chain, const char *spec);
|
filter_chain_parse(struct filter *chain, const char *spec, GError **error_r);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -193,9 +193,18 @@ audio_output_init(struct audio_output *ao, const struct config_param *param,
|
|||||||
ao->filter = filter_chain_new();
|
ao->filter = filter_chain_new();
|
||||||
assert(ao->filter != NULL);
|
assert(ao->filter != NULL);
|
||||||
filter_chain_parse(ao->filter,
|
filter_chain_parse(ao->filter,
|
||||||
config_get_block_string(param, AUDIO_FILTERS, "")
|
config_get_block_string(param, AUDIO_FILTERS, ""),
|
||||||
|
&error
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// It's not really fatal - Part of the filter chain has been set up already
|
||||||
|
// and even an empty one will work (if only with unexpected behaviour)
|
||||||
|
if (error != NULL) {
|
||||||
|
g_warning("Failed to initialize filter chain for '%s': %s",
|
||||||
|
ao->name, error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
|
|
||||||
ao->thread = NULL;
|
ao->thread = NULL;
|
||||||
ao->command = AO_COMMAND_NONE;
|
ao->command = AO_COMMAND_NONE;
|
||||||
ao->mutex = g_mutex_new();
|
ao->mutex = g_mutex_new();
|
||||||
|
Loading…
Reference in New Issue
Block a user