Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
To: lgirdwood@gmail.com, broonie@kernel.org
Cc: alsa-devel@alsa-project.org,
	pierre-louis.bossart@linux.intel.com,
	ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com,
	yung-chuan.liao@linux.intel.com
Subject: [PATCH 5/9] ASoC: SOF: ipc4-topology: Handle output format special case
Date: Mon, 15 May 2023 13:33:32 +0300	[thread overview]
Message-ID: <20230515103336.16132-6-peter.ujfalusi@linux.intel.com> (raw)
In-Reply-To: <20230515103336.16132-1-peter.ujfalusi@linux.intel.com>

From: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>

The current topologies have input/output formats in pairs and even
though there are multiple output formats, they are all the same. Handle
this case as if there were only one format in topology. Also, add a check
for the number of output formats and reports errors where applicable.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
 sound/soc/sof/ipc4-topology.c | 55 +++++++++++++++++++++++++++++++----
 1 file changed, 50 insertions(+), 5 deletions(-)

diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index a079dd8eb7e1..f3a6e739e800 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -1033,10 +1033,37 @@ static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
 					  struct sof_ipc4_available_audio_format *available_fmt,
 					  int input_audio_format_index)
 {
+	struct sof_ipc4_audio_format *out_fmt;
+	u32 out_rate, out_channels, out_valid_bits;
+	bool single_format = true;
 	int i;
 
-	/* pick the only available output format */
-	if (available_fmt->num_output_formats == 1)
+	if (!available_fmt->num_output_formats)
+		return -EINVAL;
+
+	out_fmt = &available_fmt->output_pin_fmts[0].audio_fmt;
+	out_rate = out_fmt->sampling_frequency;
+	out_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(out_fmt->fmt_cfg);
+	out_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(out_fmt->fmt_cfg);
+
+	/* check if all output formats in topology are the same */
+	for (i = 1; i < available_fmt->num_output_formats; i++) {
+		u32 _out_rate, _out_channels, _out_valid_bits;
+
+		out_fmt = &available_fmt->output_pin_fmts[i].audio_fmt;
+		_out_rate = out_fmt->sampling_frequency;
+		_out_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(out_fmt->fmt_cfg);
+		_out_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(out_fmt->fmt_cfg);
+
+		if (_out_rate != out_rate || _out_channels != out_channels ||
+		    _out_valid_bits != out_valid_bits) {
+			single_format = false;
+			break;
+		}
+	}
+
+	/* pick the first format if there's only one available or if all formats are the same */
+	if (single_format)
 		i = 0;
 	else
 		i = input_audio_format_index;
@@ -1522,6 +1549,11 @@ sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
 
 	output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, &copier_data->base_config,
 							  available_fmt, ret);
+	if (output_fmt_index < 0) {
+		dev_err(sdev->dev, "No output formats in topology for copier %s",
+			swidget->widget->name);
+		return output_fmt_index;
+	}
 
 	/*
 	 * Set the output format. Current topology defines pin 0 input and output formats in pairs.
@@ -1700,7 +1732,11 @@ static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
 	if (ret < 0)
 		return ret;
 
-	sof_ipc4_init_output_audio_fmt(sdev, &gain->base_config, available_fmt, ret);
+	ret = sof_ipc4_init_output_audio_fmt(sdev, &gain->base_config, available_fmt, ret);
+	if (ret < 0) {
+		dev_err(sdev->dev, "No output formats for %s", swidget->widget->name);
+		return ret;
+	}
 
 	/* update pipeline memory usage */
 	sof_ipc4_update_pipeline_mem_usage(sdev, swidget, &gain->base_config);
@@ -1726,7 +1762,11 @@ static int sof_ipc4_prepare_mixer_module(struct snd_sof_widget *swidget,
 	if (ret < 0)
 		return ret;
 
-	sof_ipc4_init_output_audio_fmt(sdev, &mixer->base_config, available_fmt, ret);
+	ret = sof_ipc4_init_output_audio_fmt(sdev, &mixer->base_config, available_fmt, ret);
+	if (ret < 0) {
+		dev_err(sdev->dev, "No output formats for %s", swidget->widget->name);
+		return ret;
+	}
 
 	/* update pipeline memory usage */
 	sof_ipc4_update_pipeline_mem_usage(sdev, swidget, &mixer->base_config);
@@ -1753,7 +1793,11 @@ static int sof_ipc4_prepare_src_module(struct snd_sof_widget *swidget,
 	if (ret < 0)
 		return ret;
 
-	sof_ipc4_init_output_audio_fmt(sdev, &src->base_config, available_fmt, ret);
+	ret = sof_ipc4_init_output_audio_fmt(sdev, &src->base_config, available_fmt, ret);
+	if (ret < 0) {
+		dev_err(sdev->dev, "No output formats for %s", swidget->widget->name);
+		return ret;
+	}
 
 	/* update pipeline memory usage */
 	sof_ipc4_update_pipeline_mem_usage(sdev, swidget, &src->base_config);
@@ -1864,6 +1908,7 @@ static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
 	if (ret < 0)
 		return ret;
 
+	/* No need to check the return value. Some processing modules do not have output pins */
 	output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, &process->base_config,
 							  available_fmt, ret);
 
-- 
2.40.1


  parent reply	other threads:[~2023-05-15 10:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 10:33 [PATCH 0/9] ASoC: SOF: ipc4-topology: Improve the audio format selection logic Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 1/9] ASoC: SOF: ipc4-topology: Handle input/output audio format special case Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 2/9] ASoC: SOF: ipc4-topology: Add a helper function for output format selection Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 3/9] ASoC: SOF: ipc4-topology: Move the call to init output format Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 4/9] ASoC: SOF: ipc4-topology: Rename sof_ipc4_init_audio_fmt() Peter Ujfalusi
2023-05-15 10:33 ` Peter Ujfalusi [this message]
2023-05-15 10:33 ` [PATCH 6/9] ASoC: SOF: ipc4-topology: Add a new helper function to get the valid bits Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 7/9] ASoC: SOF: ipc4-topology: Modify the output format selection logic Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 8/9] ASoC: SOF: ipc4-topology: New helper to check if all output formats are the same Peter Ujfalusi
2023-05-15 10:33 ` [PATCH 9/9] ASoC: SOF: ipc4-topology: Modify input audio format selection logic Peter Ujfalusi
2023-05-15 15:31 ` [PATCH 0/9] ASoC: SOF: ipc4-topology: Improve the " Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230515103336.16132-6-peter.ujfalusi@linux.intel.com \
    --to=peter.ujfalusi@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox