diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index f797900a2b013775c7eccc4a47f1477ac7196790..0317a081546c6eb3401eee92e0a3ff516e0c51b2 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -43,8 +43,7 @@ #include <dlfcn.h> IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : - evThread_(new EventThread(this)) - , regSession_(NULL) + regSession_(NULL) , nextRefreshStamp_(0) , mutexIAX_() , decData_() @@ -53,6 +52,7 @@ IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : , converter_(44100) , initDone_(false) , accountID_(accountID) + , evThread_(this) { srand(time(NULL)); // to get random number for RANDOM_PORT } @@ -61,8 +61,6 @@ IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : IAXVoIPLink::~IAXVoIPLink() { handlingEvents_ = false; - delete evThread_; - regSession_ = NULL; // shall not delete it // XXX: but why? terminate(); } @@ -75,8 +73,8 @@ IAXVoIPLink::init() for (int port = IAX_DEFAULT_PORTNO, nbTry = 0; nbTry < 3 ; port = rand() % 64000 + 1024, nbTry++) { if (iax_init(port) >= 0) { - handlingEvents_ = false; - evThread_->start(); + handlingEvents_ = true; + evThread_.start(); initDone_ = true; break; } @@ -113,6 +111,7 @@ IAXVoIPLink::getEvent() iax_event *event; while ((event = iax_get_event(0)) != NULL) { + // If we received an 'ACK', libiax2 tells apps to ignore them. if (event->etype == IAX_EVENT_NULL) { iax_event_free(event); @@ -121,10 +120,12 @@ IAXVoIPLink::getEvent() IAXCall *call = iaxFindCallBySession(event->session); - if (call) + if (call) { iaxHandleCallEvent(event, call); - else if (event->session && event->session == regSession_) + } + else if (event->session && event->session == regSession_) { iaxHandleRegReply(event); // This is a registration session, deal with it + } else // We've got an event before it's associated with any call iaxHandlePrecallEvent(event); @@ -208,6 +209,8 @@ IAXVoIPLink::getIAXCall(const std::string& id) void IAXVoIPLink::sendRegister(Account *a) { + DEBUG("========================================= Send register"); + IAXAccount *account = dynamic_cast<IAXAccount*>(a); if (account->getHostname().empty()) @@ -584,6 +587,8 @@ void IAXVoIPLink::iaxHandleVoiceEvent(iax_event* event, IAXCall* call) */ void IAXVoIPLink::iaxHandleRegReply(iax_event* event) { + DEBUG("================== IAX REG REPLY"); + IAXAccount *account = dynamic_cast<IAXAccount *>(Manager::instance().getAccount(accountID_)); if (event->etype != IAX_EVENT_REGREJ && event->etype != IAX_EVENT_REGACK) @@ -605,6 +610,8 @@ void IAXVoIPLink::iaxHandlePrecallEvent(iax_event* event) std::string id; int format; + DEBUG("================ HANDLE IAX PRECALL EVENT"); + switch (event->etype) { case IAX_EVENT_CONNECT: id = Manager::instance().getNewCallID(); diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index 07606c730045bb71724c4305b0507265fedbf811..99d3a8f724bb0841cbb62defc24fd803237edaea 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -33,20 +33,20 @@ #define IAXVOIPLINK_H #include "voiplink.h" -#include <iax-client.h> #include "audio/codecs/audiocodec.h" // for DEC_BUFFER_SIZE #include "sfl_types.h" #include "noncopyable.h" #include "audio/samplerateconverter.h" +#include "eventthread.h" + +#include <iax-client.h> -class EventThread; class IAXCall; +class IAXAccount; class AudioCodec; class AudioLayer; -class IAXAccount; - /** * @file iaxvoiplink.h * @brief VoIPLink contains a thread that listen to external events @@ -234,9 +234,6 @@ class IAXVoIPLink : public VoIPLink { */ void iaxOutgoingInvite(IAXCall* call); - /** Threading object */ - EventThread* evThread_; - /** registration session : 0 if not register */ iax_session* regSession_; @@ -264,6 +261,11 @@ class IAXVoIPLink : public VoIPLink { bool initDone_; const std::string accountID_; + + /** + * Threading object + */ + EventThread evThread_; }; #endif diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 51e443583e4dc63370c1be02b9b7bd194891162b..433001153dca61356c0f56ffa59950963e758df2 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -38,15 +38,13 @@ #include <map> -////////////////////////////// -/* PJSIP imports */ #include <pjsip.h> #include <pjlib.h> #include <pjsip_ua.h> #include <pjlib-util.h> #include <pjnath.h> #include <pjnath/stun_config.h> -/////////////////////////////// + #include "sipaccount.h" #include "voiplink.h" #include "siptransport.h"