diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 7eeac7441d29a7a2b9e126919808d0feac9ce553..f7caef81adef27a2e7ad7ec33f6aae49c3c694e1 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -69,7 +69,7 @@ AudioRtp::closeRtpSession () { // AudioRtpRTX Class // //////////////////////////////////////////////////////////////////////////////// AudioRtpRTX::AudioRtpRTX (SipCall *sipcall, AudioLayer* driver, bool sym) : _codecBuilder(0) { - + setCancel(cancelDeferred); time = new ost::Time(); _ca = sipcall; _sym = sym; diff --git a/src/audio/tone.cpp b/src/audio/tone.cpp index fba483d5dc8f1b47614038c9aaa16b206f7483d4..8b96ca9fe703139edae04b820b4e66c31b981c35 100644 --- a/src/audio/tone.cpp +++ b/src/audio/tone.cpp @@ -156,14 +156,3 @@ Tone::getNext(int16* output, int nb, short volume) return copied; } -int -Tone::contains (const std::string& str, char c) -{ - int nb = 0; - unsigned int pos = str.find(c); - while (pos != std::string::npos ) { - nb++; - pos = str.find(c, pos+1); - } - return nb; -} diff --git a/src/audio/tone.h b/src/audio/tone.h index 9f8c26da100603cb476e93acfbefb09f033cb20f..3cf6cc948de8ef0e560f02d114304b94165955ab 100644 --- a/src/audio/tone.h +++ b/src/audio/tone.h @@ -64,7 +64,6 @@ private: */ void genBuffer(const std::string& definition); - int contains (const std::string& str, char c); int16* _buffer; int _size; // number of int16 inside the buffer, not the delay int _pos; // current position, set to 0, when initialize diff --git a/src/audio/tonelist.cpp b/src/audio/tonelist.cpp index 2c24f345f9749747dce596379e04f70a1b5ae8e5..cbf6620702ad507781d9cafa6cf71c6c387e5080 100644 --- a/src/audio/tonelist.cpp +++ b/src/audio/tonelist.cpp @@ -122,10 +122,10 @@ TelephoneTone::~TelephoneTone() void TelephoneTone::setCurrentTone(Tone::TONEID toneId) { - _currentTone = toneId; - if ( _currentTone != Tone::TONE_NULL ) { - _tone[_currentTone]->reset(); + if ( toneId != Tone::TONE_NULL && _currentTone != toneId ) { + _tone[toneId]->reset(); } + _currentTone = toneId; } Tone* diff --git a/src/call.cpp b/src/call.cpp index 67873bac709c2a194c56e7ab981d253c74155a83..b316c760f0e62565a9c8f0716df6f8ae239ba870 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -29,7 +29,7 @@ Call::Call (CALLID id, CallType type, VoIPLink* voiplink) _id = id; _type = type; _voIPLink = voiplink; - _flagNotAnswered = false; + _flagNotAnswered = true; switch (_type) { case Outgoing: @@ -37,7 +37,6 @@ Call::Call (CALLID id, CallType type, VoIPLink* voiplink) break; case Incoming: _voIPLink->newIncomingCall(_id); - _flagNotAnswered = true; break; default: break; @@ -233,6 +232,7 @@ Call::cancel (void) int Call::answer (void) { + _flagNotAnswered = false; int i = _voIPLink->answer(_id); setState(Answered); return i; diff --git a/src/gui/server/tcpstreampool.h b/src/gui/server/tcpstreampool.h index 75145ff466232d2adeb601b652b54cd808be696d..3c7420ee0f8b008988b117fd5b3b701991d0b8c8 100644 --- a/src/gui/server/tcpstreampool.h +++ b/src/gui/server/tcpstreampool.h @@ -41,7 +41,7 @@ class TCPStreamPool : public ost::TCPSession public: TCPStreamPool(ost::TCPSocket& server) : ost::TCPSession(server) { - setCancel(cancelImmediate); + setCancel(cancelDeferred); } TCPStreamPool::~TCPStreamPool(); diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 4f17fdbad072907ae7887054abe2e4086a4eebb4..704f633c1901bcfde9ee515e45aebe75c27de60b 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -232,9 +232,8 @@ ManagerImpl::deleteCall (CALLID id) while(iter!=_callVector.end()) { Call *call = *iter; if (call != NULL && call->getId() == id) { - if (call->getFlagNotAnswered()) { + if (call->getFlagNotAnswered() || call->isIncomingType()) { decWaitingCall(); - call->setFlagNotAnswered(false); } delete (*iter); *iter = NULL; call = NULL; @@ -661,9 +660,23 @@ ManagerImpl::callCanBeAnswered(CALLID id) { bool returnValue = false; ost::MutexLock m(_mutex); Call* call = getCall(id); - if (call != NULL && - call->getState() != Call::OnHold && - call->getState() != Call::OffHold) { + if (call != NULL && ( call->getFlagNotAnswered() || + (call->getState()!=Call::OnHold && call->getState()!=Call::OffHold) )) { + returnValue = true; + } + return returnValue; +} + +/** + * SipEvent Thread + * ask if it can start the sound thread + */ +bool +ManagerImpl::callIsOnHold(CALLID id) { + bool returnValue = false; + ost::MutexLock m(_mutex); + Call* call = getCall(id); + if (call != NULL && (call->getState()==Call::OnHold)) { returnValue = true; } return returnValue; @@ -713,8 +726,9 @@ ManagerImpl::peerAnsweredCall (CALLID id) ost::MutexLock m(_mutex); Call* call = getCall(id); if (call != 0) { + call->setFlagNotAnswered(false); call->setState(Call::Answered); - + stopTone(); // switch current call switchCall(id); diff --git a/src/managerimpl.h b/src/managerimpl.h index 7cab468ecbe6a92d7e6f1c167993f483e572ecb6..bda3c92b65d2c709c796c681e4ae23b71e826d1f 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -126,6 +126,7 @@ public: void callSetInfo(CALLID id, const std::string& name, const std::string& number); bool callCanBeAnswered(CALLID id); bool callCanBeClosed(CALLID id); + bool callIsOnHold(CALLID id); /* * Functions which occur with a user's action diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 25e53f2f5203720234d03a731b22762fa5027a10..5ccc5631e18c0d5b76b6730ea062cfabb39e47ee 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -705,20 +705,25 @@ SipVoIPLink::getEvent (void) // Answer if (Manager::instance().callCanBeAnswered(id)) { sipcall->setStandBy(false); + _debug("Answering call first time\n"); if (sipcall->answeredCall(event) != -1) { sipcall->answeredCall_without_hold(event); Manager::instance().peerAnsweredCall(id); - // Outgoing call is answered, start the sound channel. - if (_audiortp.createNewSession (sipcall) < 0) { - _debug("FATAL: Unable to start sound (%s:%d)\n", - __FILE__, __LINE__); - returnValue = -1; - break; + if(!Manager::instance().callIsOnHold(id)) { + // Outgoing call is answered, start the sound channel. + _debug("Starting AudioRTP\n"); + if (_audiortp.createNewSession (sipcall) < 0) { + _debug("FATAL: Unable to start sound (%s:%d)\n", + __FILE__, __LINE__); + returnValue = -1; + break; + } } } } else { // Answer to on/off hold to send ACK + _debug("Answering call\n"); sipcall->answeredCall(event); } break;