summaryrefslogtreecommitdiff
path: root/sound/core/pcm_native.c
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2017-06-09 06:37:00 +0900
committerTakashi Iwai <tiwai@suse.de>2017-06-08 23:40:29 +0200
commit3432fa040211660989844209b67b414185003004 (patch)
treefd52f3b105c5bcf25cbfb037e470799b871a32e5 /sound/core/pcm_native.c
parent561e1cadb4dca3783de82cfa453a142129953e4d (diff)
ALSA: pcm: add a helper function to constrain interval-type parameters
Application of constraints to interval-type parameters for 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> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/pcm_native.c')
-rw-r--r--sound/core/pcm_native.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 1dee5f960fbe..7e811ace6bf2 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -286,6 +286,39 @@ static int constrain_mask_params(struct snd_pcm_substream *substream,
return 0;
}
+static int constrain_interval_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params)
+{
+ struct snd_pcm_hw_constraints *constrs =
+ &substream->runtime->hw_constraints;
+ struct snd_interval *i;
+ unsigned int k;
+ struct snd_interval old_interval;
+ int changed;
+
+ for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) {
+ i = hw_param_interval(params, k);
+ if (snd_interval_empty(i))
+ return -EINVAL;
+ if (!(params->rmask & (1 << k)))
+ continue;
+
+ if (trace_hw_interval_param_enabled())
+ old_interval = *i;
+
+ changed = snd_interval_refine(i, constrs_interval(constrs, k));
+
+ trace_hw_interval_param(substream, k, 0, &old_interval, i);
+
+ if (changed)
+ params->cmask |= 1 << k;
+ if (changed < 0)
+ return changed;
+ }
+
+ return 0;
+}
+
int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
@@ -316,25 +349,9 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
if (err < 0)
return err;
- for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) {
- i = hw_param_interval(params, k);
- if (snd_interval_empty(i))
- return -EINVAL;
- if (!(params->rmask & (1 << k)))
- continue;
-
- if (trace_hw_interval_param_enabled())
- old_interval = *i;
-
- changed = snd_interval_refine(i, constrs_interval(constrs, k));
-
- trace_hw_interval_param(substream, k, 0, &old_interval, i);
-
- if (changed)
- params->cmask |= 1 << k;
- if (changed < 0)
- return changed;
- }
+ err = constrain_interval_params(substream, params);
+ if (err < 0)
+ return err;
for (k = 0; k < constrs->rules_num; k++)
rstamps[k] = 0;