Skip to content

Commit

Permalink
ALSA: fireworks: unify substream counter
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Takashi Sakamoto authored and Takashi Iwai committed Jun 12, 2019
1 parent 33e41a5 commit 1dc5921
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
3 changes: 1 addition & 2 deletions sound/firewire/fireworks/fireworks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions sound/firewire/fireworks/fireworks_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);

Expand All @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions sound/firewire/fireworks/fireworks_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
27 changes: 10 additions & 17 deletions sound/firewire/fireworks/fireworks_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 1dc5921

Please sign in to comment.