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

mainbuffer: simplify

parent 731d46cb
No related branches found
No related tags found
No related merge requests found
...@@ -93,14 +93,10 @@ void MainBuffer::removeCallIDfromSet (const std::string & set_id, const std::str ...@@ -93,14 +93,10 @@ void MainBuffer::removeCallIDfromSet (const std::string & set_id, const std::str
{ {
CallIDSet* callid_set = getCallIDSet (set_id); CallIDSet* callid_set = getCallIDSet (set_id);
if (callid_set != NULL) { if (callid_set == NULL)
if (callid_set->erase (call_id) != 0) { _error("removeCallIDfromSet error callid set %s does not exist!", set_id.c_str());
} else { else if (callid_set->erase (call_id) == 0)
_debug ("removeCallIDfromSet error while removing callid %s from set %s!", call_id.c_str(), set_id.c_str()); _error("removeCallIDfromSet error while removing callid %s from set %s!", call_id.c_str(), set_id.c_str());
}
} else {
_debug ("removeCallIDfromSet error callid set %s does not exist!", set_id.c_str());
}
} }
...@@ -108,11 +104,7 @@ RingBuffer* MainBuffer::getRingBuffer (const std::string & call_id) ...@@ -108,11 +104,7 @@ RingBuffer* MainBuffer::getRingBuffer (const std::string & call_id)
{ {
RingBufferMap::iterator iter = _ringBufferMap.find (call_id); RingBufferMap::iterator iter = _ringBufferMap.find (call_id);
if (iter == _ringBufferMap.end()) { return (iter != _ringBufferMap.end()) ? iter->second : NULL;
// _debug("ringBuffer with ID: \"%s\" doesn't exist! ", call_id.c_str());
return NULL;
} else
return iter->second;
} }
...@@ -278,29 +270,6 @@ void MainBuffer::unBindAll (const std::string & call_id) ...@@ -278,29 +270,6 @@ void MainBuffer::unBindAll (const std::string & call_id)
} }
void MainBuffer::unBindAllHalfDuplexOut (const std::string & process_id)
{
CallIDSet* callid_set = getCallIDSet (process_id);
if (!callid_set)
return;
if (callid_set->empty())
return;
CallIDSet temp_set = *callid_set;
CallIDSet::iterator iter_set = temp_set.begin();
while (iter_set != temp_set.end()) {
std::string call_id_in_set = *iter_set;
unBindCallID (process_id, call_id_in_set);
iter_set++;
}
}
void MainBuffer::putData (void *buffer, int toCopy, const std::string & call_id) void MainBuffer::putData (void *buffer, int toCopy, const std::string & call_id)
{ {
ost::MutexLock guard (_mutex); ost::MutexLock guard (_mutex);
...@@ -359,11 +328,7 @@ int MainBuffer::getDataByID (void *buffer, int toCopy, const std::string & call_ ...@@ -359,11 +328,7 @@ int MainBuffer::getDataByID (void *buffer, int toCopy, const std::string & call_
{ {
RingBuffer* ring_buffer = getRingBuffer (call_id); RingBuffer* ring_buffer = getRingBuffer (call_id);
if (!ring_buffer) { return ring_buffer ? ring_buffer->Get(buffer, toCopy, reader_id) : 0;
return 0;
}
return ring_buffer->Get (buffer, toCopy, reader_id);
} }
...@@ -433,42 +398,21 @@ int MainBuffer::discard (int toDiscard, const std::string & call_id) ...@@ -433,42 +398,21 @@ int MainBuffer::discard (int toDiscard, const std::string & call_id)
CallIDSet* callid_set = getCallIDSet (call_id); CallIDSet* callid_set = getCallIDSet (call_id);
if (callid_set == NULL) if (!callid_set || callid_set->empty())
return 0;
if (callid_set->empty()) {
return 0; return 0;
}
if (callid_set->size() == 1) {
CallIDSet::iterator iter_id = callid_set->begin();
return discardByID (toDiscard, *iter_id, call_id);
} else {
for (CallIDSet::iterator iter = callid_set->begin(); iter != callid_set->end(); iter++)
CallIDSet::iterator iter_id; discardByID (toDiscard, *iter, call_id);
for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) {
discardByID (toDiscard, *iter_id, call_id);
}
return toDiscard; return toDiscard;
} }
}
int MainBuffer::discardByID (int toDiscard, const std::string & call_id, const std::string & reader_id) void MainBuffer::discardByID (int toDiscard, const std::string & call_id, const std::string & reader_id)
{ {
RingBuffer* ringbuffer = getRingBuffer (call_id); RingBuffer* ringbuffer = getRingBuffer (call_id);
if (ringbuffer)
if (ringbuffer == NULL) ringbuffer->Discard (toDiscard, reader_id);
return 0;
else
return ringbuffer->Discard (toDiscard, reader_id);
} }
...@@ -478,35 +422,14 @@ void MainBuffer::flush (const std::string & call_id) ...@@ -478,35 +422,14 @@ void MainBuffer::flush (const std::string & call_id)
ost::MutexLock guard (_mutex); ost::MutexLock guard (_mutex);
CallIDSet* callid_set = getCallIDSet (call_id); CallIDSet* callid_set = getCallIDSet (call_id);
if (callid_set == NULL) if (callid_set == NULL)
return; return;
if (callid_set->empty()) { for (CallIDSet::iterator iter = callid_set->begin(); iter != callid_set->end(); iter++)
} flushByID (*iter, call_id);
if (callid_set->size() == 1) {
CallIDSet::iterator iter_id = callid_set->begin();
flushByID (*iter_id, call_id);
} else {
CallIDSet::iterator iter_id;
for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) {
flushByID (*iter_id, call_id);
}
}
}
void MainBuffer::flushDefault()
{
ost::MutexLock guard (_mutex);
flushByID (Call::DEFAULT_ID, Call::DEFAULT_ID);
} }
void MainBuffer::flushByID (const std::string & call_id, const std::string & reader_id) void MainBuffer::flushByID (const std::string & call_id, const std::string & reader_id)
{ {
RingBuffer* ringbuffer = getRingBuffer (call_id); RingBuffer* ringbuffer = getRingBuffer (call_id);
...@@ -518,118 +441,73 @@ void MainBuffer::flushByID (const std::string & call_id, const std::string & rea ...@@ -518,118 +441,73 @@ void MainBuffer::flushByID (const std::string & call_id, const std::string & rea
void MainBuffer::flushAllBuffers() void MainBuffer::flushAllBuffers()
{ {
RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); for (RingBufferMap::iterator iter = _ringBufferMap.begin(); iter != _ringBufferMap.end(); ++iter)
iter->second->flushAll();
while (iter_buffer != _ringBufferMap.end()) {
iter_buffer->second->flushAll();
iter_buffer++;
}
} }
void MainBuffer::syncBuffers (const std::string & call_id) void MainBuffer::syncBuffers (const std::string & call_id)
{ {
CallIDSet* callid_set = getCallIDSet (call_id); CallIDSet* callid_set = getCallIDSet (call_id);
if (callid_set == NULL) if (callid_set || callid_set->empty())
return;
if (callid_set->empty()) {
return; return;
}
if (callid_set->size() == 1) { if (callid_set->size() == 1) // no need to resync, only one session
// no need to resync, only one session
return; return;
}
int nbBuffers = 0;
float mean_nbBytes = 0.0; float mean_nbBytes = 0.0;
CallIDSet::iterator iter_id = callid_set->begin(); CallIDSet::iterator iter;
// compute mean nb byte in buffers // compute mean nb byte in buffers
for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) { for (iter = callid_set->begin(); iter != callid_set->end(); iter++)
nbBuffers++; mean_nbBytes += availForGetByID (*iter, call_id);
mean_nbBytes += availForGetByID (*iter_id, call_id);
}
mean_nbBytes = mean_nbBytes / (float) nbBuffers; mean_nbBytes /= (float) callid_set->size();
// resync buffers in this conference according to the computed mean // resync buffers in this conference according to the computed mean
for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) { for (iter = callid_set->begin(); iter != callid_set->end(); iter++)
if (availForGetByID (*iter, call_id) > (mean_nbBytes + 640))
if (availForGetByID (*iter_id, call_id) > (mean_nbBytes + 640)) discardByID (640, *iter, call_id);
discardByID (640, *iter_id, call_id);
}
} }
void MainBuffer::stateInfo() void MainBuffer::stateInfo()
{ {
_debug ("MainBuffer: State info");
CallIDMap::iterator iter_call = _callIDMap.begin();
// print each call and bound call ids // print each call and bound call ids
for (CallIDMap::iterator iter_call = _callIDMap.begin(); iter_call != _callIDMap.end(); ++iter_call) {
while (iter_call != _callIDMap.end()) { std::string dbg_str (" Call: \t");
std::string dbg_str (" Call: ");
dbg_str.append (iter_call->first); dbg_str.append (iter_call->first);
dbg_str.append (" is bound to: "); dbg_str.append (" is bound to: \t");
CallIDSet* call_id_set = (CallIDSet*) iter_call->second;
CallIDSet::iterator iter_call_id = call_id_set->begin(); CallIDSet *call_id_set = iter_call->second;
for (CallIDSet::iterator iter = call_id_set->begin(); iter != call_id_set->end(); ++iter) {
while (iter_call_id != call_id_set->end()) { dbg_str.append (*iter);
dbg_str.append (*iter_call_id);
dbg_str.append (", "); dbg_str.append (", ");
iter_call_id++;
} }
_debug("%s", dbg_str.c_str()); _debug("%s", dbg_str.c_str());
iter_call++;
} }
// Print ringbuffers ids and readpointers // Print ringbuffers ids and readpointers
RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); for (RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); iter_buffer != _ringBufferMap.end(); ++iter_buffer) {
RingBuffer* rbuffer = iter_buffer->second;
while (iter_buffer != _ringBufferMap.end()) {
RingBuffer* rbuffer = (RingBuffer*) iter_buffer->second;
ReadPointer* rpointer = NULL; ReadPointer* rpointer = NULL;
std::string dbg_str (" Buffer: "); std::string dbg_str (" Buffer: \t");
dbg_str.append (iter_buffer->first); dbg_str.append (iter_buffer->first);
dbg_str.append (" as read pointer: "); dbg_str.append (" as read pointer: \t");
if (rbuffer) if (rbuffer)
rpointer = rbuffer->getReadPointerList(); rpointer = rbuffer->getReadPointerList();
if (rpointer) { if (rpointer) {
for (ReadPointer::iterator iter = rpointer->begin(); iter != rpointer->end(); ++iter) {
ReadPointer::iterator iter_pointer = rpointer->begin(); dbg_str.append (iter->first);
while (iter_pointer != rpointer->end()) {
dbg_str.append (iter_pointer->first);
dbg_str.append (", "); dbg_str.append (", ");
iter_pointer++;
} }
} }
_debug("%s", dbg_str.c_str()); _debug("%s", dbg_str.c_str());
iter_buffer++;
} }
} }
...@@ -87,8 +87,6 @@ class MainBuffer ...@@ -87,8 +87,6 @@ class MainBuffer
void unBindAll (const std::string & call_id); void unBindAll (const std::string & call_id);
void unBindAllHalfDuplexOut (const std::string & process_id);
void putData (void *buffer, int toCopy, const std::string & call_id = Call::DEFAULT_ID); void putData (void *buffer, int toCopy, const std::string & call_id = Call::DEFAULT_ID);
int getData (void *buffer, int toCopy, const std::string & call_id = Call::DEFAULT_ID); int getData (void *buffer, int toCopy, const std::string & call_id = Call::DEFAULT_ID);
...@@ -101,8 +99,6 @@ class MainBuffer ...@@ -101,8 +99,6 @@ class MainBuffer
void flushAllBuffers(); void flushAllBuffers();
void flushDefault();
void syncBuffers (const std::string & call_id); void syncBuffers (const std::string & call_id);
void stateInfo(); void stateInfo();
...@@ -135,7 +131,7 @@ class MainBuffer ...@@ -135,7 +131,7 @@ class MainBuffer
int availForGetByID (const std::string & call_id, const std::string & reader_id); int availForGetByID (const std::string & call_id, const std::string & reader_id);
int discardByID (int toDiscard, const std::string & call_id, const std::string & reader_id); void discardByID (int toDiscard, const std::string & call_id, const std::string & reader_id);
void flushByID (const std::string & call_id, const std::string & reader_id); void flushByID (const std::string & call_id, const std::string & reader_id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment