Skip to content
Snippets Groups Projects
Commit 2a9f1bd3 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

MainBuffer: simplify

Do not export buffer size, it's internal only
parent fa70e0e9
No related branches found
No related tags found
No related merge requests found
......@@ -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, new CallIDSet));
return true;
}
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++) {
......
......@@ -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;
......
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment