[PATCH v3 4/6] conf-parser: Add pa_config_parse_volume()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 2015-04-27 13:34, Tanu Kaskinen wrote:
> This will be used to parse the path default volume in the alsa mixer
> configuration files. For now, percentages are the only supported
> format, because I don't have need for anything else, but we can of
> course add more volume formats later as needed.

My preference for allowing all volume formats is quite strong; 
specifically considering that volume percentages are frowned upon as 
meaning different things in different contexts (so newcomers to 
PulseAudio don't have to figure out what *we* mean with it before being 
able to write the config).

> ---
>   src/pulsecore/conf-parser.c | 23 +++++++++++++++++++++++
>   src/pulsecore/conf-parser.h |  3 ++-
>   2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/src/pulsecore/conf-parser.c b/src/pulsecore/conf-parser.c
> index 2dcd45a..7ec50fc 100644
> --- a/src/pulsecore/conf-parser.c
> +++ b/src/pulsecore/conf-parser.c
> @@ -312,3 +312,26 @@ int pa_config_parse_string(pa_config_parser_state *state) {
>       *s = *state->rvalue ? pa_xstrdup(state->rvalue) : NULL;
>       return 0;
>   }
> +
> +int pa_config_parse_volume(pa_config_parser_state *state) {
> +    size_t len;
> +
> +    pa_assert(state);
> +
> +    len = strlen(state->rvalue);
> +
> +    /* Only allow volumes in percentage format. This limitation can be lifted
> +     * if necessary, it's currently done this way to make documentation
> +     * easier for the users of pa_config_parse_volume(). */
> +    if (len == 0 || state->rvalue[len - 1] != '%')
> +        goto fail;
> +
> +    if (pa_parse_volume(state->rvalue, state->data) < 0)
> +        goto fail;
> +
> +    return 0;
> +
> +fail:
> +    pa_log("[%s:%u] Failed to parse volume value: \"%s\"", state->filename, state->lineno, state->rvalue);
> +    return -1;
> +}
> diff --git a/src/pulsecore/conf-parser.h b/src/pulsecore/conf-parser.h
> index dbb6f5c..62d7046 100644
> --- a/src/pulsecore/conf-parser.h
> +++ b/src/pulsecore/conf-parser.h
> @@ -70,12 +70,13 @@ struct pa_config_parser_state {
>    * are not allowed at all in the configuration file. */
>   int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, pa_proplist *proplist, void *userdata);
>
> -/* Generic parsers for integers, size_t, booleans and strings */
> +/* Generic parsers for integers, size_t, booleans, strings and pa_volume_t */
>   int pa_config_parse_int(pa_config_parser_state *state);
>   int pa_config_parse_unsigned(pa_config_parser_state *state);
>   int pa_config_parse_size(pa_config_parser_state *state);
>   int pa_config_parse_bool(pa_config_parser_state *state);
>   int pa_config_parse_not_bool(pa_config_parser_state *state);
>   int pa_config_parse_string(pa_config_parser_state *state);
> +int pa_config_parse_volume(pa_config_parser_state *state);
>
>   #endif
>

-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux