Skip to content

Commit ecb40fd

Browse files
takaswietiwai
authored andcommitted
ALSA: dice: share PCM buffer size for both direction
This commit allows ALSA dice driver to share PCM buffer size for both capture and playback PCM substream. When AMDTP domain starts for one of the PCM substream, buffer size of the PCM substream is stores to AMDTP domain structure. Some AMDTP streams have already run with the buffer size when another PCM substream starts, therefore the PCM substream has a constraint to its buffer size. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Link: https://lore.kernel.org/r/20191017155424.885-6-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 3299d2a commit ecb40fd

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

sound/firewire/dice/dice-midi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int midi_open(struct snd_rawmidi_substream *substream)
1717

1818
mutex_lock(&dice->mutex);
1919

20-
err = snd_dice_stream_reserve_duplex(dice, 0, 0);
20+
err = snd_dice_stream_reserve_duplex(dice, 0, 0, 0);
2121
if (err >= 0) {
2222
++dice->substreams_counter;
2323
err = snd_dice_stream_start_duplex(dice);

sound/firewire/dice/dice-pcm.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
204204
if (!internal ||
205205
(dice->substreams_counter > 0 && d->events_per_period > 0)) {
206206
unsigned int frames_per_period = d->events_per_period;
207+
unsigned int frames_per_buffer = d->events_per_buffer;
207208
unsigned int rate;
208209

209210
err = snd_dice_transaction_get_rate(dice, &rate);
@@ -217,8 +218,10 @@ static int pcm_open(struct snd_pcm_substream *substream)
217218

218219
if (frames_per_period > 0) {
219220
// For double_pcm_frame quirk.
220-
if (rate > 96000)
221+
if (rate > 96000) {
221222
frames_per_period *= 2;
223+
frames_per_buffer *= 2;
224+
}
222225

223226
err = snd_pcm_hw_constraint_minmax(substream->runtime,
224227
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
@@ -227,6 +230,14 @@ static int pcm_open(struct snd_pcm_substream *substream)
227230
mutex_unlock(&dice->mutex);
228231
goto err_locked;
229232
}
233+
234+
err = snd_pcm_hw_constraint_minmax(substream->runtime,
235+
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
236+
frames_per_buffer, frames_per_buffer);
237+
if (err < 0) {
238+
mutex_unlock(&dice->mutex);
239+
goto err_locked;
240+
}
230241
}
231242
}
232243

@@ -263,13 +274,16 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
263274
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
264275
unsigned int rate = params_rate(hw_params);
265276
unsigned int events_per_period = params_period_size(hw_params);
277+
unsigned int events_per_buffer = params_buffer_size(hw_params);
266278

267279
mutex_lock(&dice->mutex);
268280
// For double_pcm_frame quirk.
269-
if (rate > 96000)
281+
if (rate > 96000) {
270282
events_per_period /= 2;
283+
events_per_buffer /= 2;
284+
}
271285
err = snd_dice_stream_reserve_duplex(dice, rate,
272-
events_per_period);
286+
events_per_period, events_per_buffer);
273287
if (err >= 0)
274288
++dice->substreams_counter;
275289
mutex_unlock(&dice->mutex);

sound/firewire/dice/dice-stream.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ static void finish_session(struct snd_dice *dice, struct reg_params *tx_params,
279279
}
280280

281281
int snd_dice_stream_reserve_duplex(struct snd_dice *dice, unsigned int rate,
282-
unsigned int events_per_period)
282+
unsigned int events_per_period,
283+
unsigned int events_per_buffer)
283284
{
284285
unsigned int curr_rate;
285286
int err;
@@ -327,7 +328,7 @@ int snd_dice_stream_reserve_duplex(struct snd_dice *dice, unsigned int rate,
327328
goto error;
328329

329330
err = amdtp_domain_set_events_per_period(&dice->domain,
330-
events_per_period, 0);
331+
events_per_period, events_per_buffer);
331332
if (err < 0)
332333
goto error;
333334
}

sound/firewire/dice/dice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ void snd_dice_stream_stop_duplex(struct snd_dice *dice);
211211
int snd_dice_stream_init_duplex(struct snd_dice *dice);
212212
void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
213213
int snd_dice_stream_reserve_duplex(struct snd_dice *dice, unsigned int rate,
214-
unsigned int events_per_period);
214+
unsigned int events_per_period,
215+
unsigned int events_per_buffer);
215216
void snd_dice_stream_update_duplex(struct snd_dice *dice);
216217
int snd_dice_stream_detect_current_formats(struct snd_dice *dice);
217218

0 commit comments

Comments
 (0)