]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Cork output if underflow is detected.
authorMike Brady <mikebrady@eircom.net>
Wed, 17 May 2017 14:07:55 +0000 (15:07 +0100)
committerMike Brady <mikebrady@eircom.net>
Wed, 17 May 2017 14:07:55 +0000 (15:07 +0100)
audio_pa.c

index c49f0128b0f3b8b384e30ed07def002a9b6a5d90..f243244aad834eb93f72a9ff64e21bf91a5750e3 100644 (file)
@@ -155,7 +155,7 @@ static void play(short buf[], int samples) {
     audio_eoq = audio_lmb + bytes_to_transfer - space_to_end_of_buffer;
   }
   if ((audio_occupancy >= 11025 * 2 * 2) && (pa_stream_is_corked(stream))) {
-    // debug(1,"Uncorked");
+    debug(1,"Uncorked");
     pa_stream_cork(stream, 0, stream_success_cb, mainloop);
   }
 }
@@ -182,8 +182,11 @@ int pa_delay(long *the_delay) {
 
 void flush(void) {
   // Cork the stream so it will stop playing
-  pa_stream_cork(stream, 1, stream_success_cb, mainloop);
-  pa_stream_flush(stream, stream_success_cb, NULL);
+  if (pa_stream_is_corked(stream)==0) {
+    debug(1,"Flush for flush.");
+    pa_stream_flush(stream, stream_success_cb, NULL);
+//    pa_stream_cork(stream, 1, stream_success_cb, mainloop);
+  }
   audio_toq = audio_eoq = audio_lmb;
   audio_umb = audio_lmb + audio_size;
   audio_occupancy = 0;
@@ -191,8 +194,11 @@ void flush(void) {
 
 static void stop(void) {
   // Cork the stream so it will stop playing
-  pa_stream_cork(stream, 1, stream_success_cb, mainloop);
-  pa_stream_flush(stream, stream_success_cb, NULL);
+  if (pa_stream_is_corked(stream)==0) {
+    debug(1,"Flush and cork for stop.");
+    pa_stream_flush(stream, stream_success_cb, NULL);
+    pa_stream_cork(stream, 1, stream_success_cb, mainloop);
+  }
   audio_toq = audio_eoq = audio_lmb;
   audio_umb = audio_lmb + audio_size;
   audio_occupancy = 0;
@@ -265,8 +271,10 @@ void stream_write_cb(pa_stream *stream, size_t requested_bytes, void *userdata)
   while ((bytes_to_transfer > 0) && (audio_occupancy > 0)) {
     size_t bytes_we_can_transfer = bytes_to_transfer;
     if (audio_occupancy < bytes_we_can_transfer) {
-      debug(2, "Underflow? We have %d bytes but we are asked for %d bytes", audio_occupancy,
+      debug(1, "Underflow? We have %d bytes but we are asked for %d bytes", audio_occupancy,
             bytes_we_can_transfer);
+      pa_stream_cork(stream,1, stream_success_cb, mainloop);
+      debug(1, "Corked");
       bytes_we_can_transfer = audio_occupancy;
     }