ALSA: oxfw: expand stop procedure for packet streaming
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 12 Jun 2019 08:44:18 +0000 (17:44 +0900)
committerTakashi Iwai <tiwai@suse.de>
Wed, 12 Jun 2019 13:26:56 +0000 (15:26 +0200)
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>
sound/firewire/oxfw/oxfw-stream.c

index 806a7fded99d414c3565d86849d1968168ab359a..561ceb09d9275c3a64594965474056f345004a4e 100644 (file)
@@ -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;
@@ -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,
@@ -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) {
@@ -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;
@@ -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);
+               }
        }
 }
 
@@ -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,