From f2c5f7bebd988aec00cabb38cea210b70be248fe Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 8 May 2008 16:20:15 +0000 Subject: [PATCH] ok this has to fix the issue with crappy sound cards 100% soft timer git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8305 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../endpoints/mod_portaudio/pa_ringbuffer.c | 2 +- src/mod/endpoints/mod_portaudio/pablio.c | 35 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c b/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c index 41342f2e2d..b632c06084 100644 --- a/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c +++ b/src/mod/endpoints/mod_portaudio/pa_ringbuffer.c @@ -70,7 +70,7 @@ * PaUtil_WriteMemoryBarrier() * ****************/ - +#define __VIA_HACK__ #if defined(__VIA_HACK__) #define NO_BARRIER #endif diff --git a/src/mod/endpoints/mod_portaudio/pablio.c b/src/mod/endpoints/mod_portaudio/pablio.c index c4be4bc77f..a38ca925ba 100644 --- a/src/mod/endpoints/mod_portaudio/pablio.c +++ b/src/mod/endpoints/mod_portaudio/pablio.c @@ -145,36 +145,35 @@ long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch { long bytesRead = 0; char *p = (char *) data; - long avail, readBytes = 0, numBytes = aStream->bytesPerFrame * numFrames; + long avail, totalBytes = 0, neededBytes = aStream->bytesPerFrame * numFrames; - while (numBytes > 0) { + for(;;) { avail = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO); - - if (avail >= numBytes * 10) { + + if (switch_core_timer_check(timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { + break; + } + + if (avail >= neededBytes * 6) { PaUtil_FlushRingBuffer(&aStream->inFIFO); avail = 0; } - if (avail >= numBytes * 2) { - bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, numBytes); - numBytes -= bytesRead; - readBytes += bytesRead; + bytesRead = 0; + + if (totalBytes < neededBytes && avail >= neededBytes) { + bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, neededBytes); + totalBytes += bytesRead; } - if (numBytes > 0) { - if (switch_core_timer_check(timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) { - break; - } - switch_yield(1000); + if (bytesRead) { p += bytesRead; + } else { + switch_yield(1000); } } - if (readBytes) { - switch_core_timer_sync(timer); - } - - return readBytes / aStream->bytesPerFrame; + return totalBytes / aStream->bytesPerFrame; } /************************************************************