Commit 57c0747d authored by Tristan Matthews's avatar Tristan Matthews
Browse files
parents 41402c75 653a8a3b
......@@ -88,7 +88,6 @@ void AudioRtpRecordHandler::setRtpMedia (AudioCodec* audioCodec)
void AudioRtpRecordHandler::initBuffers()
{
// Set sampling rate, main buffer choose the highest one
// Manager::instance().getMainBuffer()->setInternalSamplingRate (codecSampleRate);
Manager::instance().audioSamplingRateChanged(_audioRtpRecord._codecSampleRate);
// initialize SampleRate converter using AudioLayer's sampling rate
......
......@@ -93,14 +93,10 @@ void MainBuffer::removeCallIDfromSet (const std::string & set_id, const std::str
{
CallIDSet* callid_set = getCallIDSet (set_id);
if (callid_set != NULL) {
if (callid_set->erase (call_id) != 0) {
} else {
_debug ("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());
}
if (callid_set == NULL)
_error("removeCallIDfromSet error callid set %s does not exist!", set_id.c_str());
else if (callid_set->erase (call_id) == 0)
_error("removeCallIDfromSet error while removing callid %s from set %s!", call_id.c_str(), set_id.c_str());
}
......@@ -108,11 +104,7 @@ RingBuffer* MainBuffer::getRingBuffer (const std::string & call_id)
{
RingBufferMap::iterator iter = _ringBufferMap.find (call_id);
if (iter == _ringBufferMap.end()) {
// _debug("ringBuffer with ID: \"%s\" doesn't exist! ", call_id.c_str());
return NULL;
} else
return iter->second;
return (iter != _ringBufferMap.end()) ? iter->second : NULL;
}
......@@ -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)
{
ost::MutexLock guard (_mutex);
......@@ -359,11 +328,7 @@ int MainBuffer::getDataByID (void *buffer, int toCopy, const std::string & call_
{
RingBuffer* ring_buffer = getRingBuffer (call_id);
if (!ring_buffer) {
return 0;
}
return ring_buffer->Get (buffer, toCopy, reader_id);
return ring_buffer ? ring_buffer->Get(buffer, toCopy, reader_id) : 0;
}
......@@ -433,42 +398,21 @@ int MainBuffer::discard (int toDiscard, const std::string & 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;
}
for (CallIDSet::iterator iter = callid_set->begin(); iter != callid_set->end(); iter++)
discardByID (toDiscard, *iter, call_id);
if (callid_set->size() == 1) {
CallIDSet::iterator iter_id = callid_set->begin();
return discardByID (toDiscard, *iter_id, call_id);
} else {
CallIDSet::iterator iter_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);
if (ringbuffer == NULL)
return 0;
else
return ringbuffer->Discard (toDiscard, reader_id);
if (ringbuffer)
ringbuffer->Discard (toDiscard, reader_id);
}
......@@ -478,35 +422,14 @@ void MainBuffer::flush (const std::string & call_id)
ost::MutexLock guard (_mutex);
CallIDSet* callid_set = getCallIDSet (call_id);
if (callid_set == NULL)
return;
if (callid_set->empty()) {
}
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);
}
}
for (CallIDSet::iterator iter = callid_set->begin(); iter != callid_set->end(); iter++)
flushByID (*iter, 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)
{
RingBuffer* ringbuffer = getRingBuffer (call_id);
......@@ -518,118 +441,73 @@ void MainBuffer::flushByID (const std::string & call_id, const std::string & rea
void MainBuffer::flushAllBuffers()
{
RingBufferMap::iterator iter_buffer = _ringBufferMap.begin();
while (iter_buffer != _ringBufferMap.end()) {
iter_buffer->second->flushAll();
iter_buffer++;
}
for (RingBufferMap::iterator iter = _ringBufferMap.begin(); iter != _ringBufferMap.end(); ++iter)
iter->second->flushAll();
}
void MainBuffer:: syncBuffers (const std::string & call_id)
void MainBuffer::syncBuffers (const std::string & call_id)
{
CallIDSet* callid_set = getCallIDSet (call_id);
if (callid_set == NULL)
return;
if (callid_set->empty()) {
if (callid_set || callid_set->empty())
return;
}
if (callid_set->size() == 1) {
// no need to resync, only one session
if (callid_set->size() == 1) // no need to resync, only one session
return;
}
int nbBuffers = 0;
float mean_nbBytes = 0.0;
CallIDSet::iterator iter_id = callid_set->begin();
CallIDSet::iterator iter;
// compute mean nb byte in buffers
for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) {
nbBuffers++;
mean_nbBytes += availForGetByID (*iter_id, call_id);
}
for (iter = callid_set->begin(); iter != callid_set->end(); iter++)
mean_nbBytes += availForGetByID (*iter, call_id);
mean_nbBytes = mean_nbBytes / (float) nbBuffers;
mean_nbBytes /= (float) callid_set->size();
// resync buffers in this conference according to the computed mean
for (iter_id = callid_set->begin(); iter_id != callid_set->end(); iter_id++) {
if (availForGetByID (*iter_id, call_id) > (mean_nbBytes + 640))
discardByID (640, *iter_id, call_id);
}
for (iter = callid_set->begin(); iter != callid_set->end(); iter++)
if (availForGetByID (*iter, call_id) > (mean_nbBytes + 640))
discardByID (640, *iter, call_id);
}
void MainBuffer::stateInfo()
{
_debug ("MainBuffer: State info");
CallIDMap::iterator iter_call = _callIDMap.begin();
// 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: ");
std::string dbg_str (" Call: \t");
dbg_str.append (iter_call->first);
dbg_str.append (" is bound to: ");
CallIDSet* call_id_set = (CallIDSet*) iter_call->second;
CallIDSet::iterator iter_call_id = call_id_set->begin();
dbg_str.append (" is bound to: \t");
while (iter_call_id != call_id_set->end()) {
dbg_str.append (*iter_call_id);
CallIDSet *call_id_set = iter_call->second;
for (CallIDSet::iterator iter = call_id_set->begin(); iter != call_id_set->end(); ++iter) {
dbg_str.append (*iter);
dbg_str.append (", ");
iter_call_id++;
}
_debug ("%s", dbg_str.c_str());
iter_call++;
_debug("%s", dbg_str.c_str());
}
// Print ringbuffers ids and readpointers
RingBufferMap::iterator iter_buffer = _ringBufferMap.begin();
while (iter_buffer != _ringBufferMap.end()) {
RingBuffer* rbuffer = (RingBuffer*) iter_buffer->second;
for (RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); iter_buffer != _ringBufferMap.end(); ++iter_buffer) {
RingBuffer* rbuffer = iter_buffer->second;
ReadPointer* rpointer = NULL;
std::string dbg_str (" Buffer: ");
std::string dbg_str (" Buffer: \t");
dbg_str.append (iter_buffer->first);
dbg_str.append (" as read pointer: ");
dbg_str.append (" as read pointer: \t");
if (rbuffer)
rpointer = rbuffer->getReadPointerList();
if (rpointer) {
ReadPointer::iterator iter_pointer = rpointer->begin();
while (iter_pointer != rpointer->end()) {
dbg_str.append (iter_pointer->first);
for (ReadPointer::iterator iter = rpointer->begin(); iter != rpointer->end(); ++iter) {
dbg_str.append (iter->first);
dbg_str.append (", ");
iter_pointer++;
}
}
_debug ("%s", dbg_str.c_str());
iter_buffer++;
_debug("%s", dbg_str.c_str());
}
}
......@@ -87,8 +87,6 @@ class MainBuffer
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);
int getData (void *buffer, int toCopy, const std::string & call_id = Call::DEFAULT_ID);
......@@ -101,8 +99,6 @@ class MainBuffer
void flushAllBuffers();
void flushDefault();
void syncBuffers (const std::string & call_id);
void stateInfo();
......@@ -135,7 +131,7 @@ class MainBuffer
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);
......
......@@ -185,7 +185,7 @@ void context_changed_callback (pa_context* c, pa_subscription_event_type_t t, ui
_debug ("Audio: PA_SUBSCRIPTION_EVENT_TYPE_MASK");
break;
default:
_debug ("Audio: Unknown event type");
_debug ("Audio: Unknown event type %d", t);
}
}
......
......@@ -36,19 +36,16 @@
#include "audio/audiolayer.h"
#include "audio/mainbuffer.h"
Conference::Conference() : _id (""), _confState (ACTIVE_ATTACHED), _nbParticipant (0)
Conference::Conference()
: _id (Manager::instance().getNewCallID())
, _confState (ACTIVE_ATTACHED)
{
_id = Manager::instance().getNewCallID();
Recordable::initRecFileName (_id);
}
Conference::~Conference()
{
}
......@@ -66,87 +63,41 @@ void Conference::setState (ConferenceState state)
void Conference::add (std::string participant_id)
{
_debug ("Conference:: add participant %s", participant_id.c_str());
_participants.insert (participant_id);
_nbParticipant++;
}
void Conference::remove (std::string participant_id)
{
_debug ("Conference::remove participant %s", participant_id.c_str());
_participants.erase (participant_id);
_nbParticipant--;
}
void Conference::bindParticipant (std::string participant_id)
{
if (_nbParticipant >= 1) {
_debug("************************************************ Conference: bindParticipant");
ParticipantSet::iterator iter = _participants.begin();
while (iter != _participants.end()) {
if (participant_id != (*iter)) {
Manager::instance().getMainBuffer()->bindCallID (participant_id, *iter);
}
iter++;
}
}
ParticipantSet::iterator iter;
for (iter = _participants.begin(); iter != _participants.end(); ++iter)
if (participant_id != *iter)
Manager::instance().getMainBuffer()->bindCallID (participant_id, *iter);
Manager::instance().getMainBuffer()->bindCallID (participant_id);
}
std::string Conference::getStateStr()
{
std::string state_str;
switch (_confState) {
case ACTIVE_ATTACHED:
state_str = "ACTIVE_ATACHED";
break;
case ACTIVE_DETACHED:
state_str = "ACTIVE_DETACHED";
break;
case ACTIVE_ATTACHED_REC:
state_str = "ACTIVE_ATTACHED_REC";
break;
case ACTIVE_DETACHED_REC:
state_str = "ACTIVE_DETACHED_REC";
break;
case HOLD:
state_str = "HOLD";
break;
case HOLD_REC:
state_str = "HOLD_REC";
break;
default:
break;
case ACTIVE_ATTACHED: return "ACTIVE_ATACHED";
case ACTIVE_DETACHED: return "ACTIVE_DETACHED";
case ACTIVE_ATTACHED_REC: return "ACTIVE_ATTACHED_REC";
case ACTIVE_DETACHED_REC: return "ACTIVE_DETACHED_REC";
case HOLD: return "HOLD";
case HOLD_REC: return "HOLD_REC";
default: return "";
}
return state_str;
}
ParticipantSet Conference::getParticipantList()
const ParticipantSet &Conference::getParticipantList()
{
return _participants;
}
......@@ -155,48 +106,27 @@ ParticipantSet Conference::getParticipantList()
bool Conference::setRecording()
{
bool recordStatus = Recordable::recAudio.isRecording();
Recordable::recAudio.setRecording();
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
ParticipantSet::iterator iter;
std::string process_id = Recordable::recorder.getRecorderID();
// start recording
if (!recordStatus) {
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
ParticipantSet::iterator iter = _participants.begin();
std::string process_id = Recordable::recorder.getRecorderID();
while (iter != _participants.end()) {
for (iter = _participants.begin(); iter != _participants.end(); ++iter)
mbuffer->bindHalfDuplexOut (process_id, *iter);
iter++;
}
mbuffer->bindHalfDuplexOut (process_id);
Recordable::recorder.start();
}
// stop recording
else {
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
ParticipantSet::iterator iter = _participants.begin();
std::string process_id = Recordable::recorder.getRecorderID();
while (iter != _participants.end()) {
} else {
for (iter = _participants.begin(); iter != _participants.end(); ++iter)
mbuffer->unBindHalfDuplexOut (process_id, *iter);
iter++;
}
mbuffer->unBindHalfDuplexOut (process_id);
// Recordable::recorder.start();
}
return recordStatus;
......
......@@ -80,13 +80,6 @@ class Conference: public Recordable
*/
std::string getStateStr();
/**
* Return the number of participant for this conference
*/
int getNbParticipants() {
return _nbParticipant;
}
/**
* Add a new participant to the conference
*/
......@@ -105,7 +98,7 @@ class Conference: public Recordable
/**
* Get the participant list for this conference
*/
ParticipantSet getParticipantList();
const ParticipantSet &getParticipantList();
/**
* Get recording file ID
......
......@@ -416,16 +416,10 @@ bool ManagerImpl::hangupConference (const std::string& id)
if (iter_conf != _conferencemap.end()) {
Conference *conf = iter_conf->second;
ParticipantSet participants = conf->getParticipantList();
ParticipantSet::iterator iter_participant = participants.begin();
while (iter_participant != participants.end()) {
_debug ("Manager: Hangup conference participant %s", (*iter_participant).c_str());
hangupCall (*iter_participant);
iter_participant++;
}
const ParticipantSet &participants = conf->getParticipantList();
ParticipantSet::const_iterator iter;
for (iter = participants.begin(); iter != participants.end(); ++iter)
hangupCall (*iter);
}
switchCall ("");
......@@ -730,7 +724,7 @@ void ManagerImpl::removeConference (const std::string& conference_id)
// Unbind main participant audio from conference
getMainBuffer()->unBindAll (Call::DEFAULT_ID);
ParticipantSet participants = conf->getParticipantList();
const ParticipantSet &participants = conf->getParticipantList();
// bind main participant audio to remaining conference call
ParticipantSet::iterator iter_p = participants.begin();
......@@ -765,64 +759,42 @@ ManagerImpl::getConferenceFromCallID (const std::string& call_id)
void ManagerImpl::holdConference (const std::string& id)
{
_debug ("Manager: Hold conference()");
ConferenceMap::iterator iter_conf = _conferencemap.find (id);
bool isRec = false;
std::string currentAccountId;
if (iter_conf == _conferencemap.end())
return;
if (iter_conf != _conferencemap.end()) {
Conference *conf = iter_conf->second;
if(conf->getState() == Conference::ACTIVE_ATTACHED_REC) {
isRec = true;
} else if (conf->getState() == Conference::ACTIVE_DETACHED_REC) {
isRec = true;
} else if (conf->getState() == Conference::HOLD_REC) {
isRec = true;
}
ParticipantSet participants = conf->getParticipantList();
ParticipantSet::iterator iter_participant = participants.begin();
while (iter_participant != participants.end()) {
_debug (" holdConference: participant %s", (*iter_participant).c_str());
currentAccountId = getAccountFromCall (*iter_participant);
switchCall (*iter_participant);
onHoldCall (*iter_participant);