diff --git a/sflphone-common/src/audio/mainbuffer.cpp b/sflphone-common/src/audio/mainbuffer.cpp index 0232fbad4c0d6dfb6cb3b9cf3489e9cebda93e1b..8e74c5dc4f2e861a548367a3a7072b2e32985465 100644 --- a/sflphone-common/src/audio/mainbuffer.cpp +++ b/sflphone-common/src/audio/mainbuffer.cpp @@ -35,81 +35,49 @@ MainBuffer::MainBuffer() : _internalSamplingRate (8000) { - mixBuffer = new SFLDataFormat[STATIC_BUFSIZE]; } MainBuffer::~MainBuffer() { - - delete [] mixBuffer; - mixBuffer = NULL; } void MainBuffer::setInternalSamplingRate (int sr) { - _debug("MainBuffer: Set internal sampling rate"); - if (sr > _internalSamplingRate) { - - _debug ("MainBuffer: Internal sampling rate changed %d", sr); - - // This call takes the mutex flushAllBuffers(); - - // ost::MutexLock guard (_mutex); - _internalSamplingRate = sr; - - // Manager::instance().audioSamplingRateChanged(sr); - } } CallIDSet* MainBuffer::getCallIDSet (std::string call_id) { - CallIDMap::iterator iter = _callIDMap.find (call_id); - - if (iter != _callIDMap.end()) - return iter->second; - else - return NULL; - + return (iter != _callIDMap.end()) ? iter->second : NULL; } -bool MainBuffer::createCallIDSet (std::string set_id) +void MainBuffer::createCallIDSet (std::string set_id) { - - CallIDSet* newCallIDSet = new CallIDSet; - - _callIDMap.insert (std::pair<std::string, CallIDSet*> (set_id, newCallIDSet)); - - return true; - + _callIDMap.insert (std::pair<std::string, CallIDSet*> (set_id, new CallIDSet)); } bool MainBuffer::removeCallIDSet (std::string set_id) { - - CallIDSet* callid_set = getCallIDSet (set_id); - if (callid_set != NULL) { - if (_callIDMap.erase (set_id) != 0) { - delete callid_set; - callid_set = NULL; - return true; - } else { - _debug ("removeCallIDSet error while removing callid set %s!", set_id.c_str()); - return false; - } - } else { + if (!callid_set) { _debug ("removeCallIDSet error callid set %s does not exist!", set_id.c_str()); return false; } + if (_callIDMap.erase (set_id) == 0) { + _debug ("removeCallIDSet error while removing callid set %s!", set_id.c_str()); + return false; + } + delete callid_set; + callid_set = NULL; + return true; } void MainBuffer::addCallIDtoSet (std::string set_id, std::string call_id) @@ -148,9 +116,7 @@ RingBuffer* MainBuffer::getRingBuffer (std::string call_id) RingBuffer* MainBuffer::createRingBuffer (std::string call_id) { RingBuffer* newRingBuffer = new RingBuffer (SIZEBUF, call_id); - _ringBufferMap.insert (std::pair<std::string, RingBuffer*> (call_id, newRingBuffer)); - return newRingBuffer; } @@ -378,12 +344,7 @@ int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, std::s CallIDSet* callid_set = getCallIDSet (call_id); - int nbSmplToCopy = toCopy / sizeof (SFLDataFormat); - - if (callid_set == NULL) - return 0; - - if (callid_set->empty()) { + if (!callid_set || callid_set->empty()) { return 0; } @@ -396,18 +357,17 @@ int MainBuffer::getData (void *buffer, int toCopy, unsigned short volume, std::s } else return 0; } else { - - memset (buffer, 0, nbSmplToCopy*sizeof (SFLDataFormat)); + memset (buffer, 0, toCopy); int size = 0; CallIDSet::iterator iter_id = callid_set->begin(); while (iter_id != callid_set->end()) { - + int nbSmplToCopy = toCopy / sizeof (SFLDataFormat); + SFLDataFormat mixBuffer[nbSmplToCopy]; memset (mixBuffer, 0, toCopy); - - size = getDataByID (mixBuffer, toCopy, volume, (std::string) (*iter_id), call_id); + size = getDataByID (mixBuffer, toCopy, volume, *iter_id, call_id); if (size > 0) { for (int k = 0; k < nbSmplToCopy; k++) { diff --git a/sflphone-common/src/audio/mainbuffer.h b/sflphone-common/src/audio/mainbuffer.h index 973039fc2b51e1398191b858c02351cfefeaca6c..b84e110263b5d20ddcb2f7ebbb7994c65629ad76 100644 --- a/sflphone-common/src/audio/mainbuffer.h +++ b/sflphone-common/src/audio/mainbuffer.h @@ -113,7 +113,7 @@ class MainBuffer CallIDSet* getCallIDSet (std::string call_id); - bool createCallIDSet (std::string set_id); + void createCallIDSet (std::string set_id); bool removeCallIDSet (std::string set_id); @@ -145,8 +145,6 @@ class MainBuffer CallIDMap _callIDMap; - SFLDataFormat* mixBuffer; - ost::Mutex _mutex; int _internalSamplingRate; diff --git a/sflphone-common/src/global.h b/sflphone-common/src/global.h index d244ece14fff906ff1b7111b5f1de6b4a459c871..504713b89ca223616f3b0189973c11a268fdd91d 100644 --- a/sflphone-common/src/global.h +++ b/sflphone-common/src/global.h @@ -83,7 +83,6 @@ static const SOUND_FORMAT INT32 = 0x8; #define CODECDIR "codecs" /** Codecs directory */ #define SIZEBUF 400000 /** About 12 sec of buffering at 8000 Hz*/ -#define STATIC_BUFSIZE 5000 #define ALSA_DFT_CARD_ID 0 /** Index of the default soundcard */