ALSA: fireface: reserve/release isochronous resources in pcm.hw_params/hw_free callbacks

Once allocated, isochronous resources are available for packet
streaming, even if the streaming is cancelled. For this reason,
current implementation handles allocation of the resources and
starting packet streaming at the same time. However, this brings
complicated procedure to start packet streaming.

This commit separates the allocation and starting. The allocation is
done in pcm.hw_params callback and available till pcm.hw_free callback.
Even if any XRUN occurs, pcm.prepare callback is done to restart
packet streaming for allocated the resources.

There are two points to stop packet streaming; in pcm.hw_params and
pcm.prepare callbacks.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto
2019-06-02 16:12:56 +09:00
committed by Takashi Iwai
parent 60aec494b3
commit 55162d2bb0
3 changed files with 57 additions and 30 deletions

View File

@@ -211,8 +211,12 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream,
return err;
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
unsigned int rate = params_rate(hw_params);
mutex_lock(&ff->mutex);
ff->substreams_counter++;
err = snd_ff_stream_reserve_duplex(ff, rate);
if (err >= 0)
++ff->substreams_counter;
mutex_unlock(&ff->mutex);
}
@@ -231,8 +235,12 @@ static int pcm_playback_hw_params(struct snd_pcm_substream *substream,
return err;
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
unsigned int rate = params_rate(hw_params);
mutex_lock(&ff->mutex);
ff->substreams_counter++;
err = snd_ff_stream_reserve_duplex(ff, rate);
if (err >= 0)
++ff->substreams_counter;
mutex_unlock(&ff->mutex);
}
@@ -246,9 +254,10 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream)
mutex_lock(&ff->mutex);
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
ff->substreams_counter--;
--ff->substreams_counter;
snd_ff_stream_stop_duplex(ff);
snd_ff_stream_release_duplex(ff);
mutex_unlock(&ff->mutex);
@@ -262,9 +271,10 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream)
mutex_lock(&ff->mutex);
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
ff->substreams_counter--;
--ff->substreams_counter;
snd_ff_stream_stop_duplex(ff);
snd_ff_stream_release_duplex(ff);
mutex_unlock(&ff->mutex);