From 846f3814a3d51c0fe52a624389adfc0d569b0ade Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.net>
Date: Wed, 21 Oct 2009 17:03:00 -0400
Subject: [PATCH] [#2333] Update playback audiostream parameters

---
 .../src/audio/pulseaudio/audiostream.cpp      | 21 ++++++++++---------
 .../src/audio/pulseaudio/pulselayer.cpp       |  8 ++++---
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/sflphone-common/src/audio/pulseaudio/audiostream.cpp b/sflphone-common/src/audio/pulseaudio/audiostream.cpp
index 21cb6aa5cc..991815835c 100644
--- a/sflphone-common/src/audio/pulseaudio/audiostream.cpp
+++ b/sflphone-common/src/audio/pulseaudio/audiostream.cpp
@@ -184,11 +184,11 @@ AudioStream::createStream (pa_context* c)
     // parameters are defined as number of bytes
     // 2048 bytes (1024 int16) is 20 ms at 44100 Hz 
     if (_streamType == PLAYBACK_STREAM) {
-        attributes->maxlength = 32000;
-        attributes->tlength = 16000;
-        attributes->prebuf = 1024;
-        attributes->minreq = 512;
-        attributes->fragsize = (uint32_t) -1;
+        attributes->maxlength = 64000;
+        attributes->tlength = 32000;
+        attributes->prebuf = 4096;      // Pulseaudio will not start if prebuffering is not reached
+        attributes->minreq = 2048;      // The server side playback framesize
+        attributes->fragsize = 8192;    // Fragment size at wich we receive an interupt
         pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_INTERPOLATE_TIMING, &_volume, NULL);
         // pa_stream_connect_playback (s , NULL , attributes, PA_STREAM_START_CORKED, &_volume, NULL);
     } else if (_streamType == CAPTURE_STREAM) {
@@ -197,13 +197,14 @@ AudioStream::createStream (pa_context* c)
         // attributes->fragsize = (uint32_t)-1;
 
         attributes->maxlength = 32000;
-        attributes->tlength = 16000;
-        attributes->prebuf = 1024;
-        attributes->minreq = 512;
-        attributes->fragsize = (uint32_t) -1;
+        attributes->tlength = (uint32_t)-1;
+        attributes->prebuf = (uint32_t)-1;
+        attributes->minreq = (uint32_t)-1;
+        attributes->fragsize = (uint32_t)-1;
 
         // pa_stream_connect_record (s , NULL , attributes , PA_STREAM_START_CORKED);
-        pa_stream_connect_record( s , NULL , attributes , PA_STREAM_INTERPOLATE_TIMING );
+        // pa_stream_connect_record( s , NULL , attributes , PA_STREAM_INTERPOLATE_TIMING );
+	pa_stream_connect_record( s, NULL, NULL, PA_STREAM_INTERPOLATE_TIMING );
     } else if (_streamType == UPLOAD_STREAM) {
         pa_stream_connect_upload (s , 1024);
     } else {
diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
index f727c1a3d7..faa15f006f 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
@@ -58,10 +58,11 @@ static void playback_underflow_callback (pa_stream* s,  void* userdata UNUSED)
 {
     _debug ("PulseLayer::Buffer Underflow\n");
 
-    SFLDataFormat* out = (SFLDataFormat*) pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat));
-    bzero (out, framesPerBuffer*sizeof(SFLDataFormat));
+    // fill in audio buffer twice the prebuffering value to restart playback
+    SFLDataFormat* out = (SFLDataFormat*) pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat)*2);
+    bzero (out, framesPerBuffer*sizeof(SFLDataFormat)*2);
 
-    pa_stream_write (s, out, framesPerBuffer*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE); 
+    pa_stream_write (s, out, framesPerBuffer*sizeof(SFLDataFormat)*2, NULL, 0, PA_SEEK_RELATIVE); 
     pa_stream_trigger (s, NULL, NULL);
 
     pa_xfree (out);
@@ -561,6 +562,7 @@ void PulseLayer::writeToSpeaker (void)
 		}
             }
 
+	    
 	    _urgentRingBuffer.Discard(toGet);
 
             pa_xfree (out);
-- 
GitLab