diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2018-10-30 02:31:15 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2018-10-30 07:22:12 -0400 |
commit | 826b5de90c0bca4e9de6231da9e1730480621588 (patch) | |
tree | 504349d4e97ca62d7aa72a97a017b09b3d113742 | |
parent | ac237c28d5ac1b241d58b1b7b4b9fa10efb22fb5 (diff) |
ALSA: firewire-lib: fix insufficient PCM rule for period/buffer size
In a former commit, PCM constraint based on LCM of SYT_INTERVAL was
obsoleted with PCM rule. However, the new PCM rule brings -EINVAL in
some cases that max/min values of size of buffer/period is not
multiples of one of values of SYT_INTERVAL. For example, pulseaudio
always fail to configure PCM substream.
This commit changes strategy for the PCM rule. Although the buggy rules
had a single dependency (rate from period, period from rate, rate from
buffer, buffer from rate), a revised rule has double dependencies
(period from period/rate, buffer from buffer/rate). A step of value is
calculated with table of SYT_INTERVAL and list of available rates. This
prevents interval template which brings -EINVAL to a call of
snd_interval_refine().
Fixes: 5950229582bc('ALSA: firewire-lib: add PCM rules to obsolete PCM constraints based on LCM of SYT_INTERVAL')
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/firewire/amdtp-stream.c | 57 |
1 files changed, 9 insertions, 48 deletions
diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index fcd965f1d69e..9be76c808fcc 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c | |||
@@ -146,53 +146,22 @@ static int apply_constraint_to_size(struct snd_pcm_hw_params *params, | |||
146 | struct snd_interval *s = hw_param_interval(params, rule->var); | 146 | struct snd_interval *s = hw_param_interval(params, rule->var); |
147 | const struct snd_interval *r = | 147 | const struct snd_interval *r = |
148 | hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); | 148 | hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); |
149 | struct snd_interval t = { | 149 | struct snd_interval t = {0}; |
150 | .min = s->min, .max = s->max, .integer = 1, | 150 | unsigned int step = 0; |
151 | }; | ||
152 | int i; | 151 | int i; |
153 | 152 | ||
154 | for (i = 0; i < CIP_SFC_COUNT; ++i) { | 153 | for (i = 0; i < CIP_SFC_COUNT; ++i) { |
155 | unsigned int rate = amdtp_rate_table[i]; | 154 | if (snd_interval_test(r, amdtp_rate_table[i])) |
156 | unsigned int step = amdtp_syt_intervals[i]; | 155 | step = max(step, amdtp_syt_intervals[i]); |
157 | |||
158 | if (!snd_interval_test(r, rate)) | ||
159 | continue; | ||
160 | |||
161 | t.min = roundup(t.min, step); | ||
162 | t.max = rounddown(t.max, step); | ||
163 | } | 156 | } |
164 | 157 | ||
165 | if (snd_interval_checkempty(&t)) | 158 | t.min = roundup(s->min, step); |
166 | return -EINVAL; | 159 | t.max = rounddown(s->max, step); |
160 | t.integer = 1; | ||
167 | 161 | ||
168 | return snd_interval_refine(s, &t); | 162 | return snd_interval_refine(s, &t); |
169 | } | 163 | } |
170 | 164 | ||
171 | static int apply_constraint_to_rate(struct snd_pcm_hw_params *params, | ||
172 | struct snd_pcm_hw_rule *rule) | ||
173 | { | ||
174 | struct snd_interval *r = | ||
175 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); | ||
176 | const struct snd_interval *s = hw_param_interval_c(params, rule->deps[0]); | ||
177 | struct snd_interval t = { | ||
178 | .min = UINT_MAX, .max = 0, .integer = 1, | ||
179 | }; | ||
180 | int i; | ||
181 | |||
182 | for (i = 0; i < CIP_SFC_COUNT; ++i) { | ||
183 | unsigned int step = amdtp_syt_intervals[i]; | ||
184 | unsigned int rate = amdtp_rate_table[i]; | ||
185 | |||
186 | if (s->min % step || s->max % step) | ||
187 | continue; | ||
188 | |||
189 | t.min = min(t.min, rate); | ||
190 | t.max = max(t.max, rate); | ||
191 | } | ||
192 | |||
193 | return snd_interval_refine(r, &t); | ||
194 | } | ||
195 | |||
196 | /** | 165 | /** |
197 | * amdtp_stream_add_pcm_hw_constraints - add hw constraints for PCM substream | 166 | * amdtp_stream_add_pcm_hw_constraints - add hw constraints for PCM substream |
198 | * @s: the AMDTP stream, which must be initialized. | 167 | * @s: the AMDTP stream, which must be initialized. |
@@ -250,24 +219,16 @@ int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s, | |||
250 | */ | 219 | */ |
251 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | 220 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
252 | apply_constraint_to_size, NULL, | 221 | apply_constraint_to_size, NULL, |
222 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | ||
253 | SNDRV_PCM_HW_PARAM_RATE, -1); | 223 | SNDRV_PCM_HW_PARAM_RATE, -1); |
254 | if (err < 0) | 224 | if (err < 0) |
255 | goto end; | 225 | goto end; |
256 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, | ||
257 | apply_constraint_to_rate, NULL, | ||
258 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); | ||
259 | if (err < 0) | ||
260 | goto end; | ||
261 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, | 226 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
262 | apply_constraint_to_size, NULL, | 227 | apply_constraint_to_size, NULL, |
228 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, | ||
263 | SNDRV_PCM_HW_PARAM_RATE, -1); | 229 | SNDRV_PCM_HW_PARAM_RATE, -1); |
264 | if (err < 0) | 230 | if (err < 0) |
265 | goto end; | 231 | goto end; |
266 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, | ||
267 | apply_constraint_to_rate, NULL, | ||
268 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1); | ||
269 | if (err < 0) | ||
270 | goto end; | ||
271 | end: | 232 | end: |
272 | return err; | 233 | return err; |
273 | } | 234 | } |