All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Ossman <ossman@cendio.se>
To: alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] Properly terminate stream in polypaudio plugin
Date: Tue, 07 Mar 2006 17:43:52 +0100	[thread overview]
Message-ID: <440DB848.5020200@cendio.se> (raw)

[-- Attachment #1: Type: text/plain, Size: 260 bytes --]

Some applications like to call prepare over and over again, recreating 
the stream each time. Previously we just cleaned up the local end each 
time, but this makes sure the server also releases its resources.

Signed-off-by: Pierre Ossman <ossman@cendio.se>


[-- Attachment #2: alsa-plugins-polyp-kill-stream.patch --]
[-- Type: text/x-patch, Size: 3417 bytes --]

Index: polyp/pcm_polyp.c
===================================================================
RCS file: /cvsroot/alsa/alsa-plugins/polyp/pcm_polyp.c,v
retrieving revision 1.2
diff -u -r1.2 pcm_polyp.c
--- polyp/pcm_polyp.c	22 Feb 2006 15:38:52 -0000	1.2
+++ polyp/pcm_polyp.c	7 Mar 2006 16:41:39 -0000
@@ -335,6 +335,8 @@
         return err;
 
     if (pcm->stream) {
+        pa_stream_disconnect(pcm->stream);
+        polyp_wait_stream_state(pcm->p, pcm->stream, PA_STREAM_TERMINATED);
         pa_stream_unref(pcm->stream);
         pcm->stream = NULL;
     }
@@ -356,18 +358,12 @@
     else
         pa_stream_connect_record(pcm->stream, pcm->device, &pcm->buffer_attr, 0);
 
-    while (1) {
-        state = pa_stream_get_state(pcm->stream);
-
-        if (state == PA_STREAM_FAILED)
-            goto error;
-
-        if (state == PA_STREAM_READY)
-            break;
-
-        err = pa_mainloop_iterate(pcm->p->mainloop, 1, NULL);
-        if (err < 0)
-            return -EIO;
+    err = polyp_wait_stream_state(pcm->p, pcm->stream, PA_STREAM_READY);
+    if (err < 0) {
+        fprintf(stderr, "*** POLYPAUDIO: Unable to create stream.\n");
+        pa_stream_unref(pcm->stream);
+        pcm->stream = NULL;
+        return err;
     }
 
     pcm->last_size = 0;
@@ -375,12 +371,6 @@
     pcm->offset = 0;
 
     return 0;
-
-error:
-    fprintf(stderr, "*** POLYPAUDIO: Unable to create stream.\n");
-    pa_stream_unref(pcm->stream);
-    pcm->stream = NULL;
-    return -EIO;
 }
 
 static int polyp_hw_params(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params)
@@ -437,8 +427,11 @@
 
     assert(pcm);
 
-    if (pcm->stream)
+    if (pcm->stream) {
+        pa_stream_disconnect(pcm->stream);
+        polyp_wait_stream_state(pcm->p, pcm->stream, PA_STREAM_TERMINATED);
         pa_stream_unref(pcm->stream);
+    }
 
     if (pcm->p)
         polyp_free(pcm->p);
Index: polyp/polyp.c
===================================================================
RCS file: /cvsroot/alsa/alsa-plugins/polyp/polyp.c,v
retrieving revision 1.2
diff -u -r1.2 polyp.c
--- polyp/polyp.c	22 Feb 2006 15:38:52 -0000	1.2
+++ polyp/polyp.c	7 Mar 2006 16:41:39 -0000
@@ -182,6 +182,32 @@
     return 0;
 }
 
+int polyp_wait_stream_state(snd_polyp_t *p, pa_stream *stream, pa_stream_state_t target)
+{
+    int err;
+    pa_stream_state_t state;
+
+    assert(p && stream && (p->state == POLYP_STATE_READY));
+
+    while (1) {
+        state = pa_stream_get_state(stream);
+
+        if (state == PA_STREAM_FAILED)
+            return -EIO;
+
+        if (state == target)
+            break;
+
+        p->state = POLYP_STATE_POLLING;
+        err = pa_mainloop_iterate(p->mainloop, 1, NULL);
+        p->state = POLYP_STATE_READY;
+        if (err < 0)
+            return -EIO;
+    }
+
+    return 0;
+}
+
 snd_polyp_t *polyp_new()
 {
     snd_polyp_t *p;
Index: polyp/polyp.h
===================================================================
RCS file: /cvsroot/alsa/alsa-plugins/polyp/polyp.h,v
retrieving revision 1.1
diff -u -r1.1 polyp.h
--- polyp/polyp.h	21 Feb 2006 16:14:00 -0000	1.1
+++ polyp/polyp.h	7 Mar 2006 16:41:39 -0000
@@ -48,6 +48,7 @@
 int polyp_check_connection(snd_polyp_t *p);
 
 int polyp_wait_operation(snd_polyp_t *p, pa_operation *o);
+int polyp_wait_stream_state(snd_polyp_t *p, pa_stream *stream, pa_stream_state_t target);
 
 snd_polyp_t *polyp_new();
 void polyp_free(snd_polyp_t *p);

             reply	other threads:[~2006-03-07 16:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-07 16:43 Pierre Ossman [this message]
2006-03-08 12:18 ` [PATCH] Properly terminate stream in polypaudio plugin Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=440DB848.5020200@cendio.se \
    --to=ossman@cendio.se \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.