[alsa-devel] [PATCH 3/6] topology: Parse flags for PCM

Takashi Iwai tiwai at suse.de
Sat Nov 5 16:45:46 CET 2016


On Fri, 04 Nov 2016 00:07:06 +0100,
mengdong.lin at linux.intel.com wrote:
> 
> From: Mengdong Lin <mengdong.lin at linux.intel.com>
> 
> Users can define flags by both text conf file and C API.
> Add flags and flag_mask to C API template of PCM object.
> 
> Signed-off-by: Mengdong Lin <mengdong.lin at linux.intel.com>
> 
> diff --git a/include/topology.h b/include/topology.h
> index ccd8401..b6a6f19 100644
> --- a/include/topology.h
> +++ b/include/topology.h
> @@ -606,6 +606,11 @@ extern "C" {
>   *			"config3"
>   *		]
>   *	}
> + *
> + *	# Optional boolean flags
> + *	symmetric_rates			"true"
> + *	symmetric_channels		"true"
> + *	symmetric_sample_bits		"false"
>   * }
>   * </pre>
>   *
> @@ -863,6 +868,8 @@ struct snd_tplg_pcm_template {
>  	unsigned int capture;	/*!< supports capture mode */
>  	unsigned int compress;	/*!< 1 = compressed; 0 = PCM */
>  	struct snd_tplg_stream_caps_template *caps[2]; /*!< playback & capture for DAI */
> +	unsigned int flag_mask; /*!< bitmask of flags to configure */
> +	unsigned int flags;     /*!< flag value SND_SOC_TPLG_LNK_FLGBIT_* */
>  	int num_streams;	/*!< number of supported configs */
>  	struct snd_tplg_stream_template stream[0]; /*!< supported configs */
>  };
> diff --git a/src/topology/pcm.c b/src/topology/pcm.c
> index 6fdf047..bd70dc9 100644
> --- a/src/topology/pcm.c
> +++ b/src/topology/pcm.c
> @@ -364,6 +364,24 @@ static int tplg_parse_fe_dai(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
>  	return 0;
>  }
>  
> +/* parse a flag bit of the given mask */
> +static int parse_flag(snd_config_t *n, unsigned int mask_in,
> +		      unsigned int *mask, unsigned int *flags)
> +{
> +	const char *val = NULL;
> +
> +	if (snd_config_get_string(n, &val) < 0)
> +		return -EINVAL;
> +
> +	*mask |= mask_in;
> +	if (strcmp(val, "true") == 0)
> +		*flags |= mask_in;
> +	else
> +		*flags &= ~mask_in;

This can be simplified with snd_config_get_bool().


thanks,

Takashi

> +
> +	return 0;
> +}
> +
>  /* Parse pcm (for front end DAI & DAI link) */
>  int tplg_parse_pcm(snd_tplg_t *tplg,
>  	snd_config_t *cfg, void *private ATTRIBUTE_UNUSED)
> @@ -430,6 +448,34 @@ int tplg_parse_pcm(snd_tplg_t *tplg,
>  				return err;
>  			continue;
>  		}
> +
> +		/* flags */
> +		if (strcmp(id, "symmetric_rates") == 0) {
> +			err = parse_flag(n,
> +				SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES,
> +				&pcm->flag_mask, &pcm->flags);
> +			if (err < 0)
> +				return err;
> +			continue;
> +		}
> +
> +		if (strcmp(id, "symmetric_channels") == 0) {
> +			err = parse_flag(n,
> +				SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS,
> +				&pcm->flag_mask, &pcm->flags);
> +			if (err < 0)
> +				return err;
> +			continue;
> +		}
> +
> +		if (strcmp(id, "symmetric_sample_bits") == 0) {
> +			err = parse_flag(n,
> +				SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS,
> +				&pcm->flag_mask, &pcm->flags);
> +			if (err < 0)
> +				return err;
> +			continue;
> +		}
>  	}
>  
>  	return 0;
> @@ -610,6 +656,9 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
>  			tplg_add_stream_caps(&pcm->caps[i], pcm_tpl->caps[i]);
>  	}
>  
> +	pcm->flag_mask = pcm_tpl->flag_mask;
> +	pcm->flags = pcm_tpl->flags;
> +
>  	pcm->num_streams = pcm_tpl->num_streams;
>  	for (i = 0; i < pcm_tpl->num_streams; i++)
>  		tplg_add_stream_object(&pcm->stream[i], &pcm_tpl->stream[i]);
> -- 
> 2.7.4
> 


More information about the Alsa-devel mailing list