[igt-dev] [PATCH i-g-t 2/5] lib/igt_alsa: add format argument to alsa_test_output_configuration

Martin Peres martin.peres at linux.intel.com
Mon May 20 12:08:07 UTC 2019


On 17/05/2019 19:02, Simon Ser wrote:
> This allows us to test whether HW supports a PCM format, and only run the test
> if it's the case.

Reviewed-by: Martin Peres <martin.peres at linux.intel.com>
> 
> Signed-off-by: Simon Ser <simon.ser at intel.com>
> ---
>  lib/igt_alsa.c        | 18 +++++++++++++-----
>  lib/igt_alsa.h        |  4 ++--
>  tests/kms_chamelium.c | 31 ++++++++++++++++++++-----------
>  3 files changed, 35 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/igt_alsa.c b/lib/igt_alsa.c
> index 2dfb8ccd3ad9..5b5980a94888 100644
> --- a/lib/igt_alsa.c
> +++ b/lib/igt_alsa.c
> @@ -266,8 +266,8 @@ void alsa_close_output(struct alsa *alsa)
>  	alsa->output_callback = NULL;
>  }
>  
> -static bool alsa_test_configuration(snd_pcm_t *handle, int channels,
> -			     int sampling_rate)
> +static bool alsa_test_configuration(snd_pcm_t *handle, snd_pcm_format_t fmt,
> +				    int channels, int sampling_rate)
>  {
>  	snd_pcm_hw_params_t *params;
>  	int ret;
> @@ -281,6 +281,13 @@ static bool alsa_test_configuration(snd_pcm_t *handle, int channels,
>  	if (ret < 0)
>  		return false;
>  
> +	ret = snd_pcm_hw_params_test_format(handle, params, fmt);
> +	if (ret < 0) {
> +		igt_debug("Output device doesn't support the format %s\n",
> +			  snd_pcm_format_name(fmt));
> +		return false;
> +	}
> +
>  	ret = snd_pcm_hw_params_test_rate(handle, params, sampling_rate, 0);
>  	if (ret < 0) {
>  		snd_pcm_hw_params_get_rate_min(params, &min_rate, &min_rate_dir);
> @@ -307,6 +314,7 @@ static bool alsa_test_configuration(snd_pcm_t *handle, int channels,
>  /**
>   * alsa_test_output_configuration:
>   * @alsa: The target alsa structure
> + * @fmt: The format to test
>   * @channels: The number of channels to test
>   * @sampling_rate: The sampling rate to test
>   *
> @@ -315,8 +323,8 @@ static bool alsa_test_configuration(snd_pcm_t *handle, int channels,
>   *
>   * Returns: A boolean indicating whether the test succeeded
>   */
> -bool alsa_test_output_configuration(struct alsa *alsa, int channels,
> -				    int sampling_rate)
> +bool alsa_test_output_configuration(struct alsa *alsa, snd_pcm_format_t fmt,
> +				    int channels, int sampling_rate)
>  {
>  	snd_pcm_t *handle;
>  	bool ret;
> @@ -325,7 +333,7 @@ bool alsa_test_output_configuration(struct alsa *alsa, int channels,
>  	for (i = 0; i < alsa->output_handles_count; i++) {
>  		handle = alsa->output_handles[i];
>  
> -		ret = alsa_test_configuration(handle, channels, sampling_rate);
> +		ret = alsa_test_configuration(handle, fmt, channels, sampling_rate);
>  		if (!ret)
>  			return false;
>  	}
> diff --git a/lib/igt_alsa.h b/lib/igt_alsa.h
> index 46b3568d26fd..1ece9f5255d8 100644
> --- a/lib/igt_alsa.h
> +++ b/lib/igt_alsa.h
> @@ -38,8 +38,8 @@ bool alsa_has_exclusive_access(void);
>  struct alsa *alsa_init(void);
>  int alsa_open_output(struct alsa *alsa, const char *device_name);
>  void alsa_close_output(struct alsa *alsa);
> -bool alsa_test_output_configuration(struct alsa *alsa, int channels,
> -				    int sampling_rate);
> +bool alsa_test_output_configuration(struct alsa *alsa, snd_pcm_format_t dmt,
> +				    int channels, int sampling_rate);
>  void alsa_configure_output(struct alsa *alsa, snd_pcm_format_t fmt,
>  			   int channels, int sampling_rate);
>  void alsa_register_output_callback(struct alsa *alsa,
> diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
> index 2b465565418d..af9f54d1f4c7 100644
> --- a/tests/kms_chamelium.c
> +++ b/tests/kms_chamelium.c
> @@ -821,8 +821,8 @@ run_audio_thread(void *data)
>  
>  static bool
>  do_test_display_audio(data_t *data, struct chamelium_port *port,
> -		      struct alsa *alsa, int playback_channels,
> -		      int playback_rate)
> +		      struct alsa *alsa, snd_pcm_format_t playback_format,
> +		      int playback_channels, int playback_rate)
>  {
>  	int ret, capture_rate, capture_channels, msec, freq, step;
>  	struct chamelium_audio_file *audio_file;
> @@ -841,9 +841,11 @@ do_test_display_audio(data_t *data, struct chamelium_port *port,
>  	struct audio_state state = {};
>  	int channel_mapping[8], capture_chan;
>  
> -	igt_debug("Testing with playback sampling rate %d Hz and %d channels\n",
> +	igt_debug("Testing with playback format %s, sampling rate %d Hz and "
> +		  "%d channels\n",
> +		  snd_pcm_format_name(playback_format),
>  		  playback_rate, playback_channels);
> -	alsa_configure_output(alsa, SND_PCM_FORMAT_S16_LE,
> +	alsa_configure_output(alsa, playback_format,
>  			      playback_channels, playback_rate);
>  
>  	chamelium_start_capturing_audio(data->chamelium, port, false);
> @@ -913,7 +915,9 @@ do_test_display_audio(data_t *data, struct chamelium_port *port,
>  	}
>  
>  	if (igt_frame_dump_is_enabled()) {
> -		snprintf(dump_suffix, sizeof(dump_suffix), "capture-%dch-%d",
> +		snprintf(dump_suffix, sizeof(dump_suffix),
> +			 "capture-%s-%dch-%dHz",
> +			 snd_pcm_format_name(playback_format),
>  			 playback_channels, playback_rate);
>  
>  		dump_fd = audio_create_wav_file_s32_le(dump_suffix,
> @@ -1037,6 +1041,7 @@ test_display_audio(data_t *data, struct chamelium_port *port,
>  	drmModeConnector *connector;
>  	int fb_id, i;
>  	int channels, sampling_rate;
> +	snd_pcm_format_t format;
>  
>  	igt_require(alsa_has_exclusive_access());
>  
> @@ -1074,23 +1079,27 @@ test_display_audio(data_t *data, struct chamelium_port *port,
>  		ret = alsa_open_output(alsa, audio_device);
>  		igt_assert(ret >= 0);
>  
> +		/* TODO: playback with different formats */
>  		/* TODO: playback on all 8 available channels */
> +		format = SND_PCM_FORMAT_S16_LE;
>  		channels = PLAYBACK_CHANNELS;
>  		sampling_rate = test_sampling_rates[i];
>  
> -		if (!alsa_test_output_configuration(alsa, channels,
> +		if (!alsa_test_output_configuration(alsa, format, channels,
>  						    sampling_rate)) {
> -			igt_debug("Skipping test with sample rate %d Hz and %d channels "
> -				  "because at least one of the selected output devices "
> -				  "doesn't support this configuration\n",
> +			igt_debug("Skipping test with format %s, sample rate "
> +				  "%d Hz and %d channels because at least one "
> +				  "of the selected output devices doesn't "
> +				  "support this configuration\n",
> +				  snd_pcm_format_name(format),
>  				  channels, sampling_rate);
>  			continue;
>  		}
>  
>  		run = true;
>  
> -		success &= do_test_display_audio(data, port, alsa, channels,
> -						 sampling_rate);
> +		success &= do_test_display_audio(data, port, alsa, format,
> +						 channels, sampling_rate);
>  
>  		alsa_close_output(alsa);
>  	}
> 


More information about the igt-dev mailing list