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 8/9] ASoC: SOF: ipc4-topology: New helper to check if all output formats are the same
Date: Mon, 15 May 2023 13:33:35 +0300 [thread overview]
Message-ID: <20230515103336.16132-9-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>
Add a helper function to check if all formats are identical.
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 | 53 ++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 22 deletions(-)
diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index 7f5400612bf8..723e72d2d325 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -1028,6 +1028,34 @@ static int sof_ipc4_update_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_hw
return 0;
}
+static bool sof_ipc4_is_single_format(struct snd_sof_dev *sdev,
+ struct sof_ipc4_pin_format *pin_fmts, u32 pin_fmts_size)
+{
+ struct sof_ipc4_audio_format *fmt;
+ u32 rate, channels, valid_bits;
+ int i;
+
+ fmt = &pin_fmts[0].audio_fmt;
+ rate = fmt->sampling_frequency;
+ channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
+ valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
+
+ /* check if all output formats in topology are the same */
+ for (i = 1; i < pin_fmts_size; i++) {
+ u32 _rate, _channels, _valid_bits;
+
+ fmt = &pin_fmts[i].audio_fmt;
+ _rate = fmt->sampling_frequency;
+ _channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
+ _valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
+
+ if (_rate != rate || _channels != channels || _valid_bits != valid_bits)
+ return false;
+ }
+
+ return true;
+}
+
static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
struct sof_ipc4_base_module_cfg *base_config,
struct sof_ipc4_available_audio_format *available_fmt,
@@ -1035,33 +1063,14 @@ static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
u32 out_ref_valid_bits)
{
struct sof_ipc4_audio_format *out_fmt;
- u32 out_rate, out_channels, out_valid_bits;
- bool single_format = true;
+ bool single_format;
int i;
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;
- }
- }
+ single_format = sof_ipc4_is_single_format(sdev, available_fmt->output_pin_fmts,
+ available_fmt->num_output_formats);
/* pick the first format if there's only one available or if all formats are the same */
if (single_format) {
--
2.40.1
next prev 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 ` [PATCH 5/9] ASoC: SOF: ipc4-topology: Handle output format special case Peter Ujfalusi
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 ` Peter Ujfalusi [this message]
2023-05-15 10:33 ` [PATCH 9/9] ASoC: SOF: ipc4-topology: Modify input audio " 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-9-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