Skip to content

Commit 128307d

Browse files
takaswietiwai
authored andcommitted
ALSA: firewire-tascam: share PCM buffer size for both direction
This commit allows ALSA firewire-tascam 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-8-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 76c4ecb commit 128307d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

sound/firewire/tascam/tascam-pcm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
6666
// at current one.
6767
if (clock != SND_TSCM_CLOCK_INTERNAL || tscm->substreams_counter > 0) {
6868
unsigned int frames_per_period = d->events_per_period;
69+
unsigned int frames_per_buffer = d->events_per_buffer;
6970
unsigned int rate;
7071

7172
err = snd_tscm_stream_get_rate(tscm, &rate);
@@ -83,6 +84,14 @@ static int pcm_open(struct snd_pcm_substream *substream)
8384
mutex_unlock(&tscm->mutex);
8485
goto err_locked;
8586
}
87+
88+
err = snd_pcm_hw_constraint_minmax(substream->runtime,
89+
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
90+
frames_per_buffer, frames_per_buffer);
91+
if (err < 0) {
92+
mutex_unlock(&tscm->mutex);
93+
goto err_locked;
94+
}
8695
}
8796

8897
mutex_unlock(&tscm->mutex);
@@ -118,10 +127,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
118127
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
119128
unsigned int rate = params_rate(hw_params);
120129
unsigned int frames_per_period = params_period_size(hw_params);
130+
unsigned int frames_per_buffer = params_buffer_size(hw_params);
121131

122132
mutex_lock(&tscm->mutex);
123133
err = snd_tscm_stream_reserve_duplex(tscm, rate,
124-
frames_per_period);
134+
frames_per_period, frames_per_buffer);
125135
if (err >= 0)
126136
++tscm->substreams_counter;
127137
mutex_unlock(&tscm->mutex);

sound/firewire/tascam/tascam-stream.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm)
384384
}
385385

386386
int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
387-
unsigned int frames_per_period)
387+
unsigned int frames_per_period,
388+
unsigned int frames_per_buffer)
388389
{
389390
unsigned int curr_rate;
390391
int err;
@@ -416,7 +417,7 @@ int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
416417
}
417418

418419
err = amdtp_domain_set_events_per_period(&tscm->domain,
419-
frames_per_period, 0);
420+
frames_per_period, frames_per_buffer);
420421
if (err < 0) {
421422
fw_iso_resources_free(&tscm->tx_resources);
422423
fw_iso_resources_free(&tscm->rx_resources);

sound/firewire/tascam/tascam.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
169169
void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
170170
void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
171171
int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
172-
unsigned int frames_per_period);
172+
unsigned int frames_per_period,
173+
unsigned int frames_per_buffer);
173174
int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
174175
void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);
175176

0 commit comments

Comments
 (0)