mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
ALSA: fireworks: unify substream counter
This commit is a part of preparation to perform allocation/release of isochronous resources in pcm.hw_params/hw_free callbacks. It's inconvenient to handle two isochronous context separately each other. This commit unifies the counters to handle the two at the same time. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
33e41a5ce5
commit
1dc5921082
4 changed files with 19 additions and 27 deletions
|
@ -89,8 +89,7 @@ struct snd_efw {
|
|||
struct amdtp_stream rx_stream;
|
||||
struct cmp_connection out_conn;
|
||||
struct cmp_connection in_conn;
|
||||
unsigned int capture_substreams;
|
||||
unsigned int playback_substreams;
|
||||
unsigned int substreams_counter;
|
||||
|
||||
/* hardware metering parameters */
|
||||
unsigned int phys_out;
|
||||
|
|
|
@ -18,7 +18,7 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
|
|||
goto end;
|
||||
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->capture_substreams++;
|
||||
++efw->substreams_counter;
|
||||
err = snd_efw_stream_start_duplex(efw, 0);
|
||||
mutex_unlock(&efw->mutex);
|
||||
if (err < 0)
|
||||
|
@ -38,7 +38,7 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
|
|||
goto end;
|
||||
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->playback_substreams++;
|
||||
++efw->substreams_counter;
|
||||
err = snd_efw_stream_start_duplex(efw, 0);
|
||||
mutex_unlock(&efw->mutex);
|
||||
if (err < 0)
|
||||
|
@ -52,7 +52,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
|
|||
struct snd_efw *efw = substream->rmidi->private_data;
|
||||
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->capture_substreams--;
|
||||
--efw->substreams_counter;
|
||||
snd_efw_stream_stop_duplex(efw);
|
||||
mutex_unlock(&efw->mutex);
|
||||
|
||||
|
@ -65,7 +65,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
|
|||
struct snd_efw *efw = substream->rmidi->private_data;
|
||||
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->playback_substreams--;
|
||||
--efw->substreams_counter;
|
||||
snd_efw_stream_stop_duplex(efw);
|
||||
mutex_unlock(&efw->mutex);
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ static int pcm_capture_hw_params(struct snd_pcm_substream *substream,
|
|||
|
||||
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->capture_substreams++;
|
||||
++efw->substreams_counter;
|
||||
mutex_unlock(&efw->mutex);
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ static int pcm_playback_hw_params(struct snd_pcm_substream *substream,
|
|||
|
||||
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->playback_substreams++;
|
||||
++efw->substreams_counter;
|
||||
mutex_unlock(&efw->mutex);
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream)
|
|||
|
||||
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->capture_substreams--;
|
||||
--efw->substreams_counter;
|
||||
mutex_unlock(&efw->mutex);
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ static int pcm_playback_hw_free(struct snd_pcm_substream *substream)
|
|||
|
||||
if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
|
||||
mutex_lock(&efw->mutex);
|
||||
efw->playback_substreams--;
|
||||
--efw->substreams_counter;
|
||||
mutex_unlock(&efw->mutex);
|
||||
}
|
||||
|
||||
|
|
|
@ -194,9 +194,9 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
|
|||
unsigned int curr_rate;
|
||||
int err = 0;
|
||||
|
||||
/* Need no substreams */
|
||||
if (efw->playback_substreams == 0 && efw->capture_substreams == 0)
|
||||
goto end;
|
||||
// Need no substreams.
|
||||
if (efw->substreams_counter == 0)
|
||||
return -EIO;
|
||||
|
||||
/*
|
||||
* Considering JACK/FFADO streaming:
|
||||
|
@ -206,19 +206,15 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
|
|||
if (err < 0)
|
||||
goto end;
|
||||
|
||||
/* packet queueing error */
|
||||
if (amdtp_streaming_error(&efw->tx_stream))
|
||||
stop_stream(efw, &efw->tx_stream);
|
||||
if (amdtp_streaming_error(&efw->rx_stream))
|
||||
stop_stream(efw, &efw->rx_stream);
|
||||
|
||||
/* stop streams if rate is different */
|
||||
err = snd_efw_command_get_sampling_rate(efw, &curr_rate);
|
||||
if (err < 0)
|
||||
goto end;
|
||||
if (rate == 0)
|
||||
rate = curr_rate;
|
||||
if (rate != curr_rate) {
|
||||
if (rate != curr_rate ||
|
||||
amdtp_streaming_error(&efw->tx_stream) ||
|
||||
amdtp_streaming_error(&efw->rx_stream)) {
|
||||
stop_stream(efw, &efw->tx_stream);
|
||||
stop_stream(efw, &efw->rx_stream);
|
||||
}
|
||||
|
@ -237,13 +233,12 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
|
|||
}
|
||||
}
|
||||
|
||||
/* start slave if needed */
|
||||
if (efw->capture_substreams > 0 &&
|
||||
!amdtp_stream_running(&efw->tx_stream)) {
|
||||
if (!amdtp_stream_running(&efw->tx_stream)) {
|
||||
err = start_stream(efw, &efw->tx_stream, rate);
|
||||
if (err < 0) {
|
||||
dev_err(&efw->unit->device,
|
||||
"fail to start AMDTP slave stream:%d\n", err);
|
||||
stop_stream(efw, &efw->tx_stream);
|
||||
stop_stream(efw, &efw->rx_stream);
|
||||
}
|
||||
}
|
||||
|
@ -253,11 +248,9 @@ int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate)
|
|||
|
||||
void snd_efw_stream_stop_duplex(struct snd_efw *efw)
|
||||
{
|
||||
if (efw->capture_substreams == 0) {
|
||||
if (efw->substreams_counter == 0) {
|
||||
stop_stream(efw, &efw->tx_stream);
|
||||
|
||||
if (efw->playback_substreams == 0)
|
||||
stop_stream(efw, &efw->rx_stream);
|
||||
stop_stream(efw, &efw->rx_stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue