[Sofaswitch-svn] [commit] r434 - sofaswitch/trunk/mcu
Author: derek Date: Sun Jul 27 01:11:44 2008 New Revision: 434 Modified: sofaswitch/trunk/mcu/member.cxx sofaswitch/trunk/mcu/member.h Log: use a read write lock on the internal audio buffer, so it is more efficient in handling audio. This will allow concurrent reads of the member's audio buffer. Modified: sofaswitch/trunk/mcu/member.cxx ============================================================================== --- sofaswitch/trunk/mcu/member.cxx (original) +++ sofaswitch/trunk/mcu/member.cxx Sun Jul 27 01:11:44 2008 @@ -44,18 +44,6 @@ #ifdef _MSC_VER #pragma warning(disable:4355) #endif -// size of a PCM data packet, in samples -#define PCM_PACKET_LEN 240 - -// size of a PCM data buffer, in bytes -#define PCM_BUFFER_LEN (PCM_PACKET_LEN * 2) - -// number of PCM buffers to keep -#define PCM_BUFFER_COUNT 2 - -#define PCM_BUFFER_SIZE (10 * PCM_BUFFER_LEN * PCM_BUFFER_COUNT) - - /////////////////////////////////////////////////////////////// void MemberDict::DeleteObject(PObject * object) const @@ -81,7 +69,6 @@ keepGoing = true; bufferSize = PCM_BUFFER_SIZE; - buffer = new BYTE[bufferSize]; memset(buffer, 0, bufferSize); currentWriteIndex = 0; @@ -92,14 +79,6 @@ { PTRACE(2, "Member\t" << *this << " destroyed dead and gone"); - { - PWaitAndSignal m(audioBufferMutex); - if (buffer != NULL) { - delete [] buffer; - buffer = NULL; - } - } - DecCountMembers(); } @@ -172,25 +151,20 @@ if (amount == 0) return; - PWaitAndSignal mutex(audioBufferMutex); - - if (buffer == NULL) { - PTRACE(3, "Audio buffer is null - abort ReadAndMixAudio"); - return; - } - + audioBufferMutex.StartWrite(); if ((currentWriteIndex + amount) > bufferSize) { - PINDEX bytesLeftOver; - bytesLeftOver = (currentWriteIndex + amount) - bufferSize; - - memcpy(buffer + currentWriteIndex, dataPtr, amount - bytesLeftOver); - memcpy(buffer, dataPtr + amount - bytesLeftOver, bytesLeftOver); - - currentWriteIndex = bytesLeftOver; + PINDEX bytesLeftOver; + bytesLeftOver = (currentWriteIndex + amount) - bufferSize; + + memcpy(buffer + currentWriteIndex, dataPtr, amount - bytesLeftOver); + memcpy(buffer, dataPtr + amount - bytesLeftOver, bytesLeftOver); + + currentWriteIndex = bytesLeftOver; } else { - memcpy(buffer + currentWriteIndex, dataPtr, amount); - currentWriteIndex += amount; + memcpy(buffer + currentWriteIndex, dataPtr, amount); + currentWriteIndex += amount; } + audioBufferMutex.EndWrite(); } void Member::ReadAudio(BYTE *dataPtr, PINDEX readSize) @@ -208,13 +182,7 @@ return keepGoing; } - PWaitAndSignal mutex(audioBufferMutex); - - if (buffer == NULL) { - PTRACE(3, "Audio buffer is null - abort ReadAndMixAudio"); - return keepGoing; - } - + audioBufferMutex.StartRead(); PINDEX availableBytes; if (currentReadIndex > currentWriteIndex) availableBytes = (bufferSize + currentWriteIndex) - currentReadIndex; @@ -239,6 +207,7 @@ Mix(data, buffer + currentReadIndex, amount); currentReadIndex += amount; } + audioBufferMutex.EndRead(); return keepGoing; } Modified: sofaswitch/trunk/mcu/member.h ============================================================================== --- sofaswitch/trunk/mcu/member.h (original) +++ sofaswitch/trunk/mcu/member.h Sun Jul 27 01:11:44 2008 @@ -34,7 +34,17 @@ #ifdef P_USE_PRAGMA #pragma interface #endif +// size of a PCM data packet, in samples +#define PCM_PACKET_LEN 240 +// size of a PCM data buffer, in bytes +#define PCM_BUFFER_LEN (PCM_PACKET_LEN * 2) + +// number of PCM buffers to keep +#define PCM_BUFFER_COUNT 2 + +#define PCM_BUFFER_SIZE (10 * PCM_BUFFER_LEN * PCM_BUFFER_COUNT) + #include <ptlib/safecoll.h> class ConferenceRoom; @@ -186,7 +196,7 @@ This buffer is circular, in that once data has been written to the end, data will then be written to the start */ - BYTE * buffer; + BYTE buffer[PCM_BUFFER_SIZE]; /** The position that we next put data to */ PINDEX currentWriteIndex; @@ -194,8 +204,10 @@ /** Total number of bytes in buffer. Never gets changed.*/ PINDEX bufferSize; - /**Lock on the audio buffer & assocated variables */ - PMutex audioBufferMutex; + /**Lock on the audio buffer & assocated variables. This is a + read/write lock, so we can have concurent reads of the audio in + this buffer */ + PReadWriteMutex audioBufferMutex; //@} /**The time at which this structure was created, which is the time this call
participants (1)
-
SofaSWITCH SVN