All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de, lars@metafoo.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH RFC 03/21] ALSA: pcm: add a helper function to apply parameter rules
Date: Sun, 14 May 2017 17:57:38 +0900	[thread overview]
Message-ID: <20170514085756.22382-4-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20170514085756.22382-1-o-takashi@sakamocchi.jp>

Application of rules to parameters of PCM substream is done in a call of
snd_pcm_hw_refine(), while the function includes much codes and is not
enough friendly to readers.

This commit splits the codes to a separated function so that readers can
get it easily. I leave desicion into compilers to merge the function into
its callee.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/core/pcm_native.c | 62 +++++++++++++++++++++++++++++++------------------
 1 file changed, 40 insertions(+), 22 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index b828e94..78afdf1 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -349,35 +349,19 @@ static int constrain_interval_params(struct snd_pcm_hw_constraints *constrs,
 	return 0;
 }
 
-int snd_pcm_hw_refine(struct snd_pcm_substream *substream, 
-		      struct snd_pcm_hw_params *params)
+static int constrain_params_by_rules(struct snd_pcm_hw_constraints *constrs,
+				     struct snd_pcm_hw_params *params)
 {
 	unsigned int k;
-	struct snd_pcm_hardware *hw;
-	struct snd_mask *m = NULL;
-	struct snd_interval *i = NULL;
-	struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints;
 	unsigned int rstamps[constrs->rules_num];
 	unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1];
 	unsigned int stamp = 2;
 	int changed, again;
 
-	params->info = 0;
-	params->fifo_size = 0;
-	if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS))
-		params->msbits = 0;
-	if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_RATE)) {
-		params->rate_num = 0;
-		params->rate_den = 0;
-	}
-
-	changed = constrain_mask_params(constrs, params);
-	if (changed < 0)
-		return changed;
-
-	changed = constrain_interval_params(constrs, params);
-	if (changed < 0)
-		return changed;
+#ifdef RULES_DEBUG
+	struct snd_mask *m = NULL;
+	struct snd_interval *i = NULL;
+#endif
 
 	for (k = 0; k < constrs->rules_num; k++)
 		rstamps[k] = 0;
@@ -445,6 +429,40 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
 			stamp++;
 		}
 	} while (again);
+
+	return 0;
+}
+
+int snd_pcm_hw_refine(struct snd_pcm_substream *substream, 
+		      struct snd_pcm_hw_params *params)
+{
+	struct snd_pcm_hardware *hw;
+	struct snd_mask *m = NULL;
+	struct snd_interval *i = NULL;
+	struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints;
+	int changed;
+
+	params->info = 0;
+	params->fifo_size = 0;
+	if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS))
+		params->msbits = 0;
+	if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_RATE)) {
+		params->rate_num = 0;
+		params->rate_den = 0;
+	}
+
+	changed = constrain_mask_params(constrs, params);
+	if (changed < 0)
+		return changed;
+
+	changed = constrain_interval_params(constrs, params);
+	if (changed < 0)
+		return changed;
+
+	changed = constrain_params_by_rules(constrs, params);
+	if (changed < 0)
+		return changed;
+
 	if (!params->msbits) {
 		i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
 		if (snd_interval_single(i))
-- 
2.9.3

  parent reply	other threads:[~2017-05-14  8:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-14  8:57 [PATCH RFC 00/21] ALSA: pcm: add tracepoints for PCM params operation Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 01/21] ALSA: pcm: add a helper function to constrain mask-type parameters Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 02/21] ALSA: pcm: add a helper function to constrain interval-type parameters Takashi Sakamoto
2017-05-14  8:57 ` Takashi Sakamoto [this message]
2017-05-14  8:57 ` [PATCH RFC 04/21] ALSA: pcm: tracepoints for refining PCM parameters Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 05/21] ALSA: pcm: enable parameter tracepoints at CONFIG_SND_DEBUG only Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 06/21] ALSA: pcm: use goto statement instead of while statement to reduce indentation Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 07/21] ALSA: pcm: remove function local variable with alternative evaluation Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 08/21] ALSA: pcm: adaption of code formatting Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 09/21] ALSA: pcm: add comment about application of rule to PCM parameters Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 10/21] ALSA: pcm: constify function local and read-only table Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 11/21] ALSA: pcm: localize snd_pcm_hw_params_choose() Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 12/21] ALSA: pcm: add tracepoints for selection process of hardware parameters at SNDRV_PCM_IOCTL_HW_PARAMS Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 13/21] ALSA: pcm: use helper functions to check whether parameters are determined Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 14/21] ALSA: pcm: use helper function to refer parameter as read-only Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 15/21] ALSA: pcm: add const qualifier for read-only table for sampling rate Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 16/21] ALSA: pcm/oss: refer to parameters instead of copying to reduce usage of kernel stack Takashi Sakamoto
2017-05-15  9:10   ` Takashi Iwai
2017-05-15  9:15     ` Takashi Iwai
2017-05-14  8:57 ` [PATCH RFC 17/21] ALSA: pcm: check type of parameter in added rule Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 18/21] ALSA: pcm: calculate non-mask/non-interval parameters always when possible Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 19/21] ALSA: pcm: move fixup of info flag after selecting single parameters Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 20/21] ALSA: pcm: return error immediately for parameters refinement Takashi Sakamoto
2017-05-14  8:57 ` [PATCH RFC 21/21] ALSA: pcm: return error immediately at refine ioctl Takashi Sakamoto
2017-05-15  8:42 ` [PATCH RFC 00/21] ALSA: pcm: add tracepoints for PCM params operation Takashi Iwai
2017-05-15 14:29   ` Takashi Sakamoto
2017-05-15 14:34     ` Takashi Iwai
2017-05-16 11:54       ` Takashi Sakamoto

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=20170514085756.22382-4-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=lars@metafoo.de \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.