Skip to content

Commit

Permalink
ALSA: oxfw: expand stop procedure for packet streaming
Browse files Browse the repository at this point in the history
The helper function stop packet streaming is not enough useful. This
commit obsoletes it and expands its code.

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 7efa19a commit e34244d
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions sound/firewire/oxfw/oxfw-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ static int set_stream_format(struct snd_oxfw *oxfw, struct amdtp_stream *s,
return 0;
}

static void stop_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
{
amdtp_stream_pcm_abort(stream);
amdtp_stream_stop(stream);

if (stream == &oxfw->tx_stream)
cmp_connection_break(&oxfw->out_conn);
else
cmp_connection_break(&oxfw->in_conn);
}

static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
{
u8 **formats;
Expand Down Expand Up @@ -158,28 +147,27 @@ static int start_stream(struct snd_oxfw *oxfw, struct amdtp_stream *stream)
err = amdtp_am824_set_parameters(stream, formation.rate, formation.pcm,
formation.midi * 8, false);
if (err < 0)
goto end;
return err;

err = cmp_connection_establish(conn,
amdtp_stream_get_max_payload(stream));
if (err < 0)
goto end;
return err;

err = amdtp_stream_start(stream,
conn->resources.channel,
conn->speed);
err = amdtp_stream_start(stream, conn->resources.channel, conn->speed);
if (err < 0) {
cmp_connection_break(conn);
goto end;
return err;
}

/* Wait first packet */
// Wait first packet.
if (!amdtp_stream_wait_callback(stream, CALLBACK_TIMEOUT)) {
stop_stream(oxfw, stream);
err = -ETIMEDOUT;
amdtp_stream_stop(stream);
cmp_connection_break(conn);
return -ETIMEDOUT;
}
end:
return err;

return 0;
}

static int check_connection_used_by_others(struct snd_oxfw *oxfw,
Expand Down Expand Up @@ -288,9 +276,13 @@ int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,
if (formation.rate != rate || formation.pcm != pcm_channels ||
amdtp_streaming_error(&oxfw->rx_stream) ||
amdtp_streaming_error(&oxfw->tx_stream)) {
stop_stream(oxfw, &oxfw->rx_stream);
if (oxfw->has_output)
stop_stream(oxfw, &oxfw->tx_stream);
amdtp_stream_stop(&oxfw->rx_stream);
cmp_connection_break(&oxfw->in_conn);

if (oxfw->has_output) {
amdtp_stream_stop(&oxfw->tx_stream);
cmp_connection_break(&oxfw->out_conn);
}

err = set_stream_format(oxfw, stream, rate, pcm_channels);
if (err < 0) {
Expand Down Expand Up @@ -322,10 +314,10 @@ int snd_oxfw_stream_start_simplex(struct snd_oxfw *oxfw,

return 0;
error:
stop_stream(oxfw, &oxfw->rx_stream);
amdtp_stream_stop(&oxfw->rx_stream);
cmp_connection_break(&oxfw->in_conn);
if (oxfw->has_output) {
stop_stream(oxfw, &oxfw->tx_stream);
amdtp_stream_stop(&oxfw->tx_stream);
cmp_connection_break(&oxfw->out_conn);
}
return err;
Expand All @@ -335,10 +327,13 @@ void snd_oxfw_stream_stop_simplex(struct snd_oxfw *oxfw,
struct amdtp_stream *stream)
{
if (oxfw->capture_substreams == 0 && oxfw->playback_substreams == 0) {
stop_stream(oxfw, &oxfw->rx_stream);
amdtp_stream_stop(&oxfw->rx_stream);
cmp_connection_break(&oxfw->in_conn);

if (oxfw->has_output)
stop_stream(oxfw, &oxfw->tx_stream);
if (oxfw->has_output) {
amdtp_stream_stop(&oxfw->tx_stream);
cmp_connection_break(&oxfw->out_conn);
}
}
}

Expand All @@ -363,10 +358,17 @@ void snd_oxfw_stream_destroy_simplex(struct snd_oxfw *oxfw,
void snd_oxfw_stream_update_simplex(struct snd_oxfw *oxfw,
struct amdtp_stream *stream)
{
stop_stream(oxfw, &oxfw->rx_stream);
amdtp_stream_stop(&oxfw->rx_stream);
cmp_connection_break(&oxfw->in_conn);

if (oxfw->has_output)
stop_stream(oxfw, &oxfw->tx_stream);
amdtp_stream_pcm_abort(&oxfw->rx_stream);

if (oxfw->has_output) {
amdtp_stream_stop(&oxfw->tx_stream);
cmp_connection_break(&oxfw->out_conn);

amdtp_stream_pcm_abort(&oxfw->tx_stream);
}
}

int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
Expand Down

0 comments on commit e34244d

Please sign in to comment.