[PATCH 2/4] Avoid instability in A3 voice routing code

Neil Jerram neil at ossau.homelinux.net
Thu Nov 29 01:39:17 CET 2012


---
 gsm-voice-routing.c |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/gsm-voice-routing.c b/gsm-voice-routing.c
index f607dbc..904d4c5 100644
--- a/gsm-voice-routing.c
+++ b/gsm-voice-routing.c
@@ -281,10 +281,11 @@ static void open_route_stream_repeated(struct route_stream *s)
     for (;;) {
         rc = open_route_stream(s);
         if (rc == 0) {
+	    fprintf(logfile, "opened %s stream\n", s->id);
             return;
         }
         close_route_stream(s);
-        fprintf(logfile, "retrying in 100 ms\n");
+        fprintf(logfile, "%s: retrying in 100 ms\n", s->id);
         usleep(1000 * 100);
     }
 }
@@ -297,6 +298,7 @@ static int route_stream_read(struct route_stream *s)
         return ERR_TERMINATING;
     }
 
+ reread:
     rc = snd_pcm_readi(s->handle, s->period_buffer, s->period_size);
     if (rc == s->period_size) {
         return 0;
@@ -306,6 +308,15 @@ static int route_stream_read(struct route_stream *s)
     if (rc == -EPIPE) {
         err("overrun occured", rc, s, ERR_READ_OVERRUN);
         snd_pcm_prepare(s->handle);
+
+	/* It's nice of ALSA to tell us that we were a bit slow with
+	   the reading, but we still want to capture the most recent
+	   available data, if it's there. */
+	rc = snd_pcm_avail_update(s->handle);
+	fprintf(logfile, "%d frames available\n", rc);
+	if (rc >= s->period_size) {
+	    goto reread;
+	}
         return ERR_READ_OVERRUN;
     }
 
@@ -324,6 +335,7 @@ static int route_stream_write(struct route_stream *s)
         return ERR_TERMINATING;
     }
 
+ rewrite:
     rc = snd_pcm_writei(s->handle, s->period_buffer, s->period_size);
     if (rc == s->period_size) {
         return 0;
@@ -333,7 +345,11 @@ static int route_stream_write(struct route_stream *s)
     if (rc == -EPIPE) {
         err("underrun occured", rc, s, ERR_WRITE_UNDERRUN);
         snd_pcm_prepare(s->handle);
-        return ERR_WRITE_UNDERRUN;
+
+	/* It's nice of ALSA to tell us that we were a bit slow with
+	   the writing, but we still want to write the playback data
+	   that we have in hand. */
+	goto rewrite;
     }
 
     if (rc < 0) {
-- 
1.7.10.4


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0003-Hand-applied-change-from-Neil-Brown.patch



More information about the community mailing list