Commit acf77af8 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#1883] Fix issues in ringbuffer reader pointers

parent 0b6b7688
......@@ -185,8 +185,9 @@ AudioRtpRTX::~AudioRtpRTX ()
throw;
}
_debug("unbind call id %s\n", _ca->getCallId().c_str());
_audiolayer->getMainBuffer()->unBindCallID(_ca->getCallId());
_debug("Unbind call id %s from all participants\n", _ca->getCallId().c_str());
// _audiolayer->getMainBuffer()->unBindCallID(_ca->getCallId());
// _audiolayer->getMainBuffer()->unBindAll(_ca->getCallID());
_ca = 0;
......@@ -474,8 +475,8 @@ AudioRtpRTX::sendSessionFromMic (int timestamp)
int compSize = processDataEncode();
// putData put the data on RTP queue, sendImmediate bypass this queue
if(compSize != 0)
_session->putData (timestamp, micDataEncoded, compSize);
// if(compSize != 0)
_session->putData (timestamp, micDataEncoded, compSize);
// _session->sendImmediate(timestamp, micDataEncoded, compSize);
......@@ -502,12 +503,12 @@ AudioRtpRTX::receiveSessionForSpkr (int& countTime)
const ost::AppDataUnit* adu = NULL;
int is_waiting = _session->isWaiting();
// int is_waiting = _session->isWaiting();
if (is_waiting != 0)
adu = _session->getData (_session->getFirstTimestamp());
else
return;
// if (is_waiting != 0)
adu = _session->getData (_session->getFirstTimestamp());
// else
// return;
......@@ -595,9 +596,11 @@ AudioRtpRTX::run ()
// Let's wait for the next transmit cycle
Thread::sleep (TimerPort::getTimer());
// TimerPort::incTimer(20); // 'frameSize' ms
TimerPort::incTimer (threadSleep);
}
// _audiolayer->stopStream();
......
......@@ -22,9 +22,6 @@
MainBuffer::MainBuffer()
{
createRingBuffer(default_id);
createCallIDSet(default_id);
mixBuffer = new SFLDataFormat[5000];
}
......@@ -237,6 +234,16 @@ void MainBuffer::unBindCallID(CallID call_id1, CallID call_id2)
}
}
}
void MainBuffer::unBindAll(CallID call_id)
{
// CallIDSet* callid_set = getCallIDSet(call_id);
// CallIDSet::iterator iter_set = callid_set->begin
}
......@@ -275,7 +282,7 @@ int MainBuffer::availForPut(CallID call_id)
ost::MutexLock guard (_mutex);
return getRingBuffer(call_id)->AvailForPut();
}
......@@ -311,7 +318,7 @@ int MainBuffer::getData(void *buffer, int toCopy, unsigned short volume, CallID
int size;
// _debug("CallIDSet with ID: \"%s\" is a conference!\n", call_id.c_str());
CallIDSet::iterator iter_id = callid_set->begin();
CallIDSet::iterator iter_id;
for(iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++)
{
// _debug("MainBuffer::getData in buffer %s by %s \n", (*iter_id).c_str(), call_id.c_str());
......@@ -431,7 +438,7 @@ int MainBuffer::discard(int toDiscard, CallID call_id)
else
{
// _debug("CallIDSet with ID: \"%s\" is a conference!\n", call_id.c_str());
CallIDSet::iterator iter_id = callid_set->begin();
CallIDSet::iterator iter_id;
for(iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++)
{
discardByID(toDiscard, *iter_id, call_id);
......@@ -472,7 +479,7 @@ void MainBuffer::flush(CallID call_id)
else
{
// _debug("CallIDSet with ID: \"%s\" is a conference!\n", call_id.c_str());
CallIDSet::iterator iter_id = callid_set->begin();
CallIDSet::iterator iter_id;
for(iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++)
{
flushByID(*iter_id, call_id);
......
......@@ -37,11 +37,9 @@ typedef std::set<CallID> CallIDSet;
typedef std::map<CallID, CallIDSet*> CallIDMap;
#define default_id "default_id"
class MainBuffer {
public:
public:
MainBuffer();
......@@ -65,6 +63,8 @@ class MainBuffer {
void unBindCallID(CallID call_id1, CallID call_id2 = default_id);
void unBindAll(CallID call_id);
int putData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);
int getData(void *buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);
......
......@@ -38,8 +38,8 @@ RingBuffer::RingBuffer (int size) : mStart (0), mEnd (0)
mBuffer = new unsigned char[mBufferSize];
assert (mBuffer != NULL);
createReadPointer();
storeReadPointer(mStart);
}
// Free memory on object deletion
......@@ -115,7 +115,7 @@ RingBuffer::getSmallestReadPointer()
ReadPointer::iterator iter;
for( iter = _readpointer.begin(); iter != _readpointer.end(); iter++)
{
if((iter->first != "default_id") && (iter->second < smallest))
if((iter->first != default_id) && (iter->second < smallest))
smallest = iter->second;
}
......@@ -130,8 +130,10 @@ RingBuffer::storeReadPointer(int pointer_value, CallID call_id)
if(iter != _readpointer.end())
{
iter->second = pointer_value;
_debug("store read pointer call_id %s, size: %i \n",call_id.c_str(), _readpointer.size());
}
else{
else
{
_debug("Cannot find \"%s\" readPointer\n", call_id.c_str());
}
......@@ -142,9 +144,10 @@ void
RingBuffer::createReadPointer(CallID call_id)
{
_debug("createReadPointer call_id %s\n", call_id);
_debug("---- createReadPointer call_id %s\n", call_id.c_str());
_readpointer.insert(pair<CallID, int>(call_id,0));
_readpointer.insert(pair<CallID, int>(call_id, 0));
_debug("---- createReadPointer size: %i\n", _readpointer.size());
}
......@@ -153,9 +156,10 @@ void
RingBuffer::removeReadPointer(CallID call_id)
{
_debug("removeReadPointer call_id %s\n", call_id);
_debug("---- removeReadPointer call_id %s\n", call_id.c_str());
_readpointer.erase(call_id);
_debug("---- removeReadPointer size: %i\n", _readpointer.size());
}
......
......@@ -48,18 +48,18 @@ class RingBuffer {
/**
* Reset the counters to 0
*/
void flush (CallID call_id = "default_id");
void flush (CallID call_id = default_id);
int getReadPointer(CallID call_id = "default_id");
int getReadPointer(CallID call_id = default_id);
int getSmallestReadPointer();
void storeReadPointer(int pointer_value, CallID call_id = "default_id");
void storeReadPointer(int pointer_value, CallID call_id = default_id);
void createReadPointer(CallID call_id = "default_id");
void createReadPointer(CallID call_id = default_id);
void removeReadPointer(CallID call_id = "default_id");
void removeReadPointer(CallID call_id = default_id);
int getNbReadPointer();
......@@ -82,7 +82,7 @@ class RingBuffer {
* To get how much space is available in the buffer to read in
* @return int The available size
*/
int AvailForGet (CallID call_id = "default_id");
int AvailForGet (CallID call_id = default_id);
/**
* Get data in the ring buffer
......@@ -91,14 +91,14 @@ class RingBuffer {
* @param volume The volume
* @return int Number of bytes copied
*/
int Get (void* buffer, int toCopy, unsigned short volume = 100, CallID call_id = "default_id");
int Get (void* buffer, int toCopy, unsigned short volume = 100, CallID call_id = default_id);
/**
* Discard data from the buffer
* @param toDiscard Number of bytes to discard
* @return int Number of bytes discarded
*/
int Discard(int toDiscard, CallID call_id = "default_id");
int Discard(int toDiscard, CallID call_id = default_id);
/**
* Total length of the ring buffer
......@@ -106,7 +106,7 @@ class RingBuffer {
*/
int putLen();
int getLen(CallID call_id = "default_id");
int getLen(CallID call_id = default_id);
/**
* Debug function print mEnd, mStart, mBufferSize
......
......@@ -36,6 +36,8 @@
typedef std::string CallID;
static CallID default_id = "default_id";
class AudioRecord;
class Call{
......
......@@ -645,7 +645,7 @@ ManagerImpl::createConference(const CallID& id)
Conference* conf = new Conference();
_conferencecall.insert(pair<CallID, Conference*>(id, conf));
_conferencemap.insert(pair<CallID, Conference*>("conf", conf));
_conferencemap.insert(pair<CallID, Conference*>(default_conf, conf));
conf->add(getCurrentCallId());
conf->add(id);
......@@ -674,7 +674,7 @@ ManagerImpl::removeConference(const CallID& conference_id)
}
}
_conferencemap.erase("conf");
_conferencemap.erase(default_conf);
}
......@@ -699,7 +699,7 @@ ManagerImpl::addParticipant(const CallID& call_id)
_debug(" Current call ID %s\n", getCurrentCallId().c_str());
// TODO: add conference_id as a second parameter
ConferenceMap::iterator iter = _conferencemap.find("conf");
ConferenceMap::iterator iter = _conferencemap.find(default_conf);
if(iter == _conferencemap.end())
{
......@@ -727,7 +727,7 @@ ManagerImpl::removeParticipant(const CallID& call_id)
// TODO: add conference_id as a second parameter
Conference* conf;
ConferenceMap::iterator iter = _conferencemap.find("conf");
ConferenceMap::iterator iter = _conferencemap.find(default_conf);
if(iter == _conferencemap.end())
{
......@@ -743,7 +743,7 @@ ManagerImpl::removeParticipant(const CallID& call_id)
_conferencecall.erase(iter);
if (conf->getNbParticipants() <= 1)
removeConference("conf");
removeConference(default_conf);
}
}
......
......@@ -74,7 +74,10 @@ typedef std::list<std::string> TokenList;
typedef std::map<CallID, Conference*> ConferenceCallMap;
/** To store conference objects by conference ids */
typedef std::map<CallID, Conference*> ConferenceMap;
typedef std::map<CallID, Conference*> ConferenceMap;
static CallID default_conf = "conf";
/** Manager (controller) of sflphone daemon */
class ManagerImpl {
......
......@@ -206,10 +206,13 @@ void MainBufferTest::testRingBufferInt()
CPPUNIT_ASSERT(test_ring_buffer->getReadPointer() == 0);
int testget;
int size;
CPPUNIT_ASSERT(test_ring_buffer->AvailForGet() == 2*sizeof(int));
CPPUNIT_ASSERT(test_ring_buffer->getLen() == 2*sizeof(int));
CPPUNIT_ASSERT(test_ring_buffer->Get(&testget, sizeof(int)) == sizeof(int));
size = test_ring_buffer->Get(&testget, (int)sizeof(int));
_debug("Error: %i\n", size);
CPPUNIT_ASSERT(size == sizeof(int));
CPPUNIT_ASSERT(test_ring_buffer->AvailForGet() == sizeof(int));
CPPUNIT_ASSERT(test_ring_buffer->getLen() == sizeof(int));
CPPUNIT_ASSERT(testget == testint1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment