From edfe125d74c06dcc8ad35b1138bac214a4244a1c Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.net>
Date: Thu, 22 Oct 2009 11:10:14 -0400
Subject: [PATCH] [#2333] Adjust pulseaudio fragment size to 4096 (max
 sflphone's frames per buffer)

---
 sflphone-common/src/audio/pulseaudio/audiostream.cpp | 2 +-
 sflphone-common/src/audio/pulseaudio/pulselayer.cpp  | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/sflphone-common/src/audio/pulseaudio/audiostream.cpp b/sflphone-common/src/audio/pulseaudio/audiostream.cpp
index ae4ae6775b..54309276ec 100644
--- a/sflphone-common/src/audio/pulseaudio/audiostream.cpp
+++ b/sflphone-common/src/audio/pulseaudio/audiostream.cpp
@@ -200,7 +200,7 @@ AudioStream::createStream (pa_context* c)
         attributes->tlength = (uint32_t)-1;
         attributes->prebuf = (uint32_t)-1;
         attributes->minreq = (uint32_t)-1;
-        attributes->fragsize = (uint32_t)-1;
+        attributes->fragsize = 4096;
 
         // pa_stream_connect_record (s , NULL , attributes , PA_STREAM_START_CORKED);
         // pa_stream_connect_record( s , NULL , attributes , PA_STREAM_INTERPOLATE_TIMING );
diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
index 1c7db92d30..e46e1e9524 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
@@ -524,10 +524,14 @@ void PulseLayer::writeToSpeaker (void)
 	    int maxNbSamplesToGet = 0;
 	    int maxNbBytesToGet = 0;
 
+	    // test if audio resampling is needed
 	    if (_mainBufferSampleRate && ((int)_audioSampleRate != _mainBufferSampleRate)) {
  
+		// upsamplefactor is used to compute the number of bytes to get in the ring buffer 
 		double upsampleFactor = (double) _mainBufferSampleRate / _audioSampleRate;
 
+		// maxNbSamplesToGet is the number of sample to get in the ring buffer which, 
+                // once resampled, will not be over the framesPerBuffer
 		maxNbSamplesToGet = (int) ((double) framesPerBuffer * upsampleFactor);
 
 	    } else {
@@ -595,7 +599,7 @@ void PulseLayer::writeToSpeaker (void)
 
 void PulseLayer::readFromMic (void)
 {
-    const char* data;
+    const char* data = NULL;
     size_t r;
 
     if (pa_stream_peek (record->pulseStream() , (const void**) &data , &r) < 0 || !data) {
-- 
GitLab