More debugging support, cleaned up H.323 code.

git-svn-id: http://voip.null.ro/svn/yate@411 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2005-06-20 20:51:17 +00:00
parent afe4264a80
commit 33973da02f
11 changed files with 282 additions and 193 deletions

View File

@ -102,6 +102,10 @@ ident = yate
; h245tunneling: bool: Enable H.245 tunneling mode ; h245tunneling: bool: Enable H.245 tunneling mode
;h245tunneling=false ;h245tunneling=false
; h245insetup: bool: Enable H.245 establishment early in call setup message
; Note that this setting may conflict with faststart so don't enable both
;h245insetup=false
; dtmfinband: bool: Wheter to decode inband DTMF (CPU intensive) ; dtmfinband: bool: Wheter to decode inband DTMF (CPU intensive)
;dtmfinband = false ;dtmfinband = false

View File

@ -9,3 +9,6 @@
; header: string: Header string to display on connect ; header: string: Header string to display on connect
;header=YATE (http://YATE.null.ro) ready. ;header=YATE (http://YATE.null.ro) ready.
; password: string: Password required to authenticate, default empty!
;password=

View File

@ -194,6 +194,7 @@ void Channel::init()
{ {
status(direction()); status(direction());
if (m_driver) { if (m_driver) {
debugName(m_driver->debugName());
debugChain(m_driver); debugChain(m_driver);
m_driver->lock(); m_driver->lock();
if (m_id.null()) if (m_id.null())
@ -203,7 +204,7 @@ void Channel::init()
m_driver->changed(); m_driver->changed();
m_driver->unlock(); m_driver->unlock();
} }
DDebug(DebugInfo,"Channel::init() '%s' [%p]",m_id.c_str(),this); DDebug(this,DebugInfo,"Channel::init() '%s' [%p]",m_id.c_str(),this);
} }
void Channel::drop() void Channel::drop()
@ -341,7 +342,7 @@ void Channel::callAccept(Message& msg)
m_billid = msg.getValue("billid"); m_billid = msg.getValue("billid");
m_targetid = msg.getValue("targetid"); m_targetid = msg.getValue("targetid");
if (m_targetid.null()) { if (m_targetid.null()) {
Debug(DebugInfo,"Answering now call %s because we have no targetid [%p]",m_id.c_str(),this); Debug(this,DebugInfo,"Answering now call %s because we have no targetid [%p]",m_id.c_str(),this);
msgAnswered(msg); msgAnswered(msg);
} }
} }
@ -361,14 +362,13 @@ bool Channel::setDebug(Message& msg)
} }
else if (str == "reset") else if (str == "reset")
debugChain(m_driver); debugChain(m_driver);
else { else if (str == "engine")
bool dbg = debugEnabled(); debugCopy();
str >> dbg; else if (str.isBoolean())
debugEnabled(dbg); debugEnabled(str.toBoolean(debugEnabled()));
}
msg.retValue() << "Channel " << m_id msg.retValue() << "Channel " << m_id
<< " debug " << (debugEnabled() ? "on" : "off") << " debug " << (debugEnabled() ? "on" : "off")
<< " level " << debugLevel() << "\n"; << " level " << debugLevel() << (debugChained() ? " chained" : "") << "\n";
return true; return true;
} }
@ -405,6 +405,12 @@ Module::Module(const char* name, const char* type)
: Plugin(name), Mutex(true), : Plugin(name), Mutex(true),
m_init(false), m_relays(0), m_name(name), m_type(type), m_changed(0) m_init(false), m_relays(0), m_name(name), m_type(type), m_changed(0)
{ {
debugName(m_name);
}
Module::~Module()
{
debugName(0);
} }
void* Module::getObject(const String& name) const void* Module::getObject(const String& name) const
@ -445,7 +451,7 @@ void Module::initialize()
void Module::setup() void Module::setup()
{ {
Debug(DebugAll,"Module::setup()"); Debug(this,DebugAll,"Module::setup()");
if (m_init) if (m_init)
return; return;
m_init = true; m_init = true;
@ -522,7 +528,7 @@ bool Module::received(Message &msg, int id)
else if (id == Level) else if (id == Level)
return setDebug(msg,dest); return setDebug(msg,dest);
else else
Debug(DebugGoOn,"Invalid relay id %d in module '%s', message '%s'", Debug(this,DebugGoOn,"Invalid relay id %d in module '%s', message '%s'",
id,m_name.c_str(),msg.c_str()); id,m_name.c_str(),msg.c_str());
return false; return false;
@ -579,7 +585,7 @@ void Driver::initialize()
void Driver::setup(const char* prefix, bool minimal) void Driver::setup(const char* prefix, bool minimal)
{ {
DDebug(DebugAll,"Driver::setup('%s',%d)",prefix,minimal); DDebug(this,DebugAll,"Driver::setup('%s',%d)",prefix,minimal);
Module::setup(); Module::setup();
if (m_init) if (m_init)
return; return;
@ -680,7 +686,7 @@ bool Driver::received(Message &msg, int id)
Lock lock(this); Lock lock(this);
Channel* chan = find(dest); Channel* chan = find(dest);
if (!chan) { if (!chan) {
DDebug(DebugMild,"Could not find channel '%s'",dest.c_str()); DDebug(this,DebugMild,"Could not find channel '%s'",dest.c_str());
return false; return false;
} }
@ -718,7 +724,7 @@ void Driver::dropAll(Message &msg)
while (l) { while (l) {
Channel* c = static_cast<Channel*>(l->get()); Channel* c = static_cast<Channel*>(l->get());
if (c) { if (c) {
DDebug(DebugAll,"Dropping %s channel %p [%p]",name().c_str(),c,this); DDebug(this,DebugAll,"Dropping %s channel %p [%p]",name().c_str(),c,this);
c->msgDrop(msg,reason); c->msgDrop(msg,reason);
if (l->get() != c) if (l->get() != c)
break; break;
@ -828,7 +834,7 @@ void Router::run()
bool Router::route() bool Router::route()
{ {
Debug(DebugAll,"Routing thread for '%s' [%p]",m_id.c_str(),this); Debug(m_driver,DebugAll,"Routing thread for '%s' [%p]",m_id.c_str(),this);
bool ok = Engine::dispatch(m_msg) && !m_msg->retValue().null(); bool ok = Engine::dispatch(m_msg) && !m_msg->retValue().null();
m_driver->lock(); m_driver->lock();
@ -841,7 +847,7 @@ bool Router::route()
m_driver->unlock(); m_driver->unlock();
if (!chan) { if (!chan) {
Debug(DebugMild,"Connection '%s' vanished while routing!",m_id.c_str()); Debug(m_driver,DebugMild,"Connection '%s' vanished while routing!",m_id.c_str());
return false; return false;
} }

View File

@ -688,17 +688,14 @@ void Engine::loadPlugins()
void Engine::initPlugins() void Engine::initPlugins()
{ {
#ifdef DEBUG Output("Initializing plugins");
Debugger debug("Engine::initPlugins()");
#else
Debug(DebugInfo,"Engine::initPlugins()");
#endif
dispatch("engine.init"); dispatch("engine.init");
ObjList *l = plugins.skipNull(); ObjList *l = plugins.skipNull();
for (; l; l = l->skipNext()) { for (; l; l = l->skipNext()) {
Plugin *p = static_cast<Plugin *>(l->get()); Plugin *p = static_cast<Plugin *>(l->get());
p->initialize(); p->initialize();
} }
Output("Initialization complete");
} }
int Engine::usedPlugins() int Engine::usedPlugins()

View File

@ -40,19 +40,23 @@ static bool s_debugging = true;
static bool s_abort = false; static bool s_abort = false;
static u_int64_t s_timestamp = 0; static u_int64_t s_timestamp = 0;
static void dbg_stderr_func(const char* buf) static void dbg_stderr_func(const char* buf, int level)
{ {
::write(2,buf,::strlen(buf)); ::write(2,buf,::strlen(buf));
} }
static void (*s_output)(const char*) = dbg_stderr_func; static void (*s_output)(const char*,int) = dbg_stderr_func;
static void (*s_intout)(const char*) = 0; static void (*s_intout)(const char*,int) = 0;
static Mutex out_mux; static Mutex out_mux;
static Mutex ind_mux; static Mutex ind_mux;
static void common_output(char* buf) static void common_output(int level,char* buf)
{ {
if (level < -1)
level = -1;
if (level > DebugMax)
level = DebugMax;
int n = ::strlen(buf); int n = ::strlen(buf);
if (n && (buf[n-1] == '\n')) if (n && (buf[n-1] == '\n'))
n--; n--;
@ -61,13 +65,13 @@ static void common_output(char* buf)
// serialize the output strings // serialize the output strings
out_mux.lock(); out_mux.lock();
if (s_output) if (s_output)
s_output(buf); s_output(buf,level);
if (s_intout) if (s_intout)
s_intout(buf); s_intout(buf,level);
out_mux.unlock(); out_mux.unlock();
} }
static void dbg_output(const char* prefix, const char* format, va_list ap) static void dbg_output(int level,const char* prefix, const char* format, va_list ap)
{ {
if (!(s_output || s_intout)) if (!(s_output || s_intout))
return; return;
@ -94,7 +98,7 @@ static void dbg_output(const char* prefix, const char* format, va_list ap)
if (format) { if (format) {
::vsnprintf(buf+n,l,format,ap); ::vsnprintf(buf+n,l,format,ap);
} }
common_output(buf); common_output(level,buf);
} }
void Output(const char* format, ...) void Output(const char* format, ...)
@ -106,7 +110,7 @@ void Output(const char* format, ...)
va_start(va,format); va_start(va,format);
::vsnprintf(buf,sizeof(buf)-2,format,va); ::vsnprintf(buf,sizeof(buf)-2,format,va);
va_end(va); va_end(va);
common_output(buf); common_output(-1,buf);
} }
void Debug(int level, const char* format, ...) void Debug(int level, const char* format, ...)
@ -122,7 +126,7 @@ void Debug(int level, const char* format, ...)
va_list va; va_list va;
va_start(va,format); va_start(va,format);
ind_mux.lock(); ind_mux.lock();
dbg_output(buf,format,va); dbg_output(level,buf,format,va);
ind_mux.unlock(); ind_mux.unlock();
va_end(va); va_end(va);
if (s_abort && (level == DebugFail)) if (s_abort && (level == DebugFail))
@ -142,7 +146,7 @@ void Debug(const char* facility, int level, const char* format, ...)
va_list va; va_list va;
va_start(va,format); va_start(va,format);
ind_mux.lock(); ind_mux.lock();
dbg_output(buf,format,va); dbg_output(level,buf,format,va);
ind_mux.unlock(); ind_mux.unlock();
va_end(va); va_end(va);
if (s_abort && (level == DebugFail)) if (s_abort && (level == DebugFail))
@ -153,6 +157,7 @@ void Debug(const DebugEnabler* local, int level, const char* format, ...)
{ {
if (!s_debugging) if (!s_debugging)
return; return;
const char* facility = 0;
if (!local) { if (!local) {
if (level > s_debug) if (level > s_debug)
return; return;
@ -160,15 +165,19 @@ void Debug(const DebugEnabler* local, int level, const char* format, ...)
else { else {
if (!local->debugAt(level)) if (!local->debugAt(level))
return; return;
facility = local->debugName();
} }
if (!format) if (!format)
format = ""; format = "";
char buf[32]; char buf[64];
::sprintf(buf,"<%d> ",level); if (facility)
::snprintf(buf,sizeof(buf),"<%s:%d> ",facility,level);
else
::sprintf(buf,"<%d> ",level);
va_list va; va_list va;
va_start(va,format); va_start(va,format);
ind_mux.lock(); ind_mux.lock();
dbg_output(buf,format,va); dbg_output(level,buf,format,va);
ind_mux.unlock(); ind_mux.unlock();
va_end(va); va_end(va);
if (s_abort && (level == DebugFail)) if (s_abort && (level == DebugFail))
@ -251,7 +260,7 @@ Debugger::Debugger(const char* name, const char* format, ...)
va_list va; va_list va;
va_start(va,format); va_start(va,format);
ind_mux.lock(); ind_mux.lock();
dbg_output(buf,format,va); dbg_output(DebugAll,buf,format,va);
va_end(va); va_end(va);
s_indent++; s_indent++;
ind_mux.unlock(); ind_mux.unlock();
@ -269,7 +278,7 @@ Debugger::Debugger(int level, const char* name, const char* format, ...)
va_list va; va_list va;
va_start(va,format); va_start(va,format);
ind_mux.lock(); ind_mux.lock();
dbg_output(buf,format,va); dbg_output(DebugAll,buf,format,va);
va_end(va); va_end(va);
s_indent++; s_indent++;
ind_mux.unlock(); ind_mux.unlock();
@ -282,7 +291,7 @@ static void dbg_dist_helper(const char* buf, const char* fmt, ...)
{ {
va_list va; va_list va;
va_start(va,fmt); va_start(va,fmt);
dbg_output(buf,fmt,va); dbg_output(DebugAll,buf,fmt,va);
va_end(va); va_end(va);
} }
@ -300,14 +309,14 @@ Debugger::~Debugger()
} }
} }
void Debugger::setOutput(void (*outFunc)(const char*)) void Debugger::setOutput(void (*outFunc)(const char*,int))
{ {
out_mux.lock(); out_mux.lock();
s_output = outFunc ? outFunc : dbg_stderr_func; s_output = outFunc ? outFunc : dbg_stderr_func;
out_mux.unlock(); out_mux.unlock();
} }
void Debugger::setIntOut(void (*outFunc)(const char*)) void Debugger::setIntOut(void (*outFunc)(const char*,int))
{ {
out_mux.lock(); out_mux.lock();
s_intout = outFunc; s_intout = outFunc;

View File

@ -226,6 +226,24 @@ public:
class YateH323EndPoint; class YateH323EndPoint;
class YateGatekeeperServer; class YateGatekeeperServer;
class H323Driver : public Driver
{
friend class YateH323EndPoint;
public:
H323Driver();
virtual ~H323Driver();
virtual void initialize();
virtual bool msgExecute(Message& msg, String& dest);
virtual bool received(Message &msg, int id);
void cleanup();
YateH323EndPoint* findEndpoint(const String& ep) const;
private:
ObjList m_endpoints;
};
H323Process* s_process = 0;
static H323Driver hplugin;
class YateGatekeeperCall : public H323GatekeeperCall class YateGatekeeperCall : public H323GatekeeperCall
{ {
PCLASSINFO(YateGatekeeperCall, H323GatekeeperCall); PCLASSINFO(YateGatekeeperCall, H323GatekeeperCall);
@ -266,7 +284,7 @@ class YateH323AudioSource : public DataSource, public PIndirectChannel
public: public:
YateH323AudioSource() YateH323AudioSource()
: m_exit(false) : m_exit(false)
{ Debug(DebugAll,"h.323 source [%p] created",this); } { Debug(&hplugin,DebugAll,"h.323 source [%p] created",this); }
~YateH323AudioSource(); ~YateH323AudioSource();
virtual BOOL Close(); virtual BOOL Close();
virtual BOOL IsOpen() const; virtual BOOL IsOpen() const;
@ -284,7 +302,7 @@ class YateH323AudioConsumer : public DataConsumer, public PIndirectChannel
public: public:
YateH323AudioConsumer() YateH323AudioConsumer()
: m_exit(false) : m_exit(false)
{ Debug(DebugAll,"h.323 consumer [%p] created",this); } { Debug(&hplugin,DebugAll,"h.323 consumer [%p] created",this); }
~YateH323AudioConsumer(); ~YateH323AudioConsumer();
virtual BOOL Close(); virtual BOOL Close();
virtual BOOL IsOpen() const; virtual BOOL IsOpen() const;
@ -335,19 +353,21 @@ public:
#endif #endif
virtual BOOL OnStartLogicalChannel(H323Channel& channel); virtual BOOL OnStartLogicalChannel(H323Channel& channel);
virtual BOOL OnCreateLogicalChannel(const H323Capability& capability, H323Channel::Directions dir, unsigned& errorCode ) ; virtual BOOL OnCreateLogicalChannel(const H323Capability& capability, H323Channel::Directions dir, unsigned& errorCode ) ;
BOOL StartExternalRTP(const char* remoteIP, WORD remotePort, H323Channel::Directions dir, YateH323_ExternalRTPChannel* chan); BOOL startExternalRTP(const char* remoteIP, WORD remotePort, H323Channel::Directions dir, YateH323_ExternalRTPChannel* chan);
void OnStoppedExternal(H323Channel::Directions dir); void stoppedExternal(H323Channel::Directions dir);
void SetRemoteAddress(const char* remoteIP, WORD remotePort); void setRemoteAddress(const char* remoteIP, WORD remotePort);
void cleanups(); void cleanups();
bool sendTone(Message& msg, const char* tone); bool sendTone(Message& msg, const char* tone);
void setCallerID(const char* number, const char* name); void setCallerID(const char* number, const char* name);
void rtpExecuted(Message& msg); void rtpExecuted(Message& msg);
void rtpForward(Message& msg, bool init = false); void rtpForward(Message& msg, bool init = false);
void answerCall(AnswerCallResponse response);
static BOOL decodeCapability(const H323Capability& capability, const char** dataFormat, int* payload = 0, String* capabName = 0); static BOOL decodeCapability(const H323Capability& capability, const char** dataFormat, int* payload = 0, String* capabName = 0);
inline bool HasRemoteAddress() const inline bool hasRemoteAddress() const
{ return s_passtrough && (m_remotePort > 0); } { return m_passtrough && (m_remotePort > 0); }
private: private:
YateH323Chan* m_chan; YateH323Chan* m_chan;
bool m_externalRtp;
bool m_nativeRtp; bool m_nativeRtp;
bool m_passtrough; bool m_passtrough;
String m_formats; String m_formats;
@ -405,29 +425,11 @@ private:
YateH323Connection* m_conn; YateH323Connection* m_conn;
}; };
class H323Driver : public Driver
{
friend class YateH323EndPoint;
public:
H323Driver();
virtual ~H323Driver();
virtual void initialize();
virtual bool msgExecute(Message& msg, String& dest);
virtual bool received(Message &msg, int id);
void cleanup();
YateH323EndPoint* findEndpoint(const String& ep) const;
private:
ObjList m_endpoints;
};
H323Process* s_process = 0;
static H323Driver hplugin;
YateGatekeeperServer::YateGatekeeperServer(YateH323EndPoint& ep) YateGatekeeperServer::YateGatekeeperServer(YateH323EndPoint& ep)
: H323GatekeeperServer(ep), : H323GatekeeperServer(ep),
endpoint(ep) endpoint(ep)
{ {
Debug(DebugAll,"YateGatekeeperServer::YateGatekeeperServer() [%p]",this); Debug(&hplugin,DebugAll,"YateGatekeeperServer::YateGatekeeperServer() [%p]",this);
} }
BOOL YateGatekeeperServer::Init() BOOL YateGatekeeperServer::Init()
@ -446,7 +448,7 @@ BOOL YateGatekeeperServer::Init()
YateH323EndPoint::YateH323EndPoint(const char* name) YateH323EndPoint::YateH323EndPoint(const char* name)
: String(name), gkServer(0) : String(name), gkServer(0)
{ {
Debug(DebugAll,"YateH323EndPoint::YateH323EndPoint(\"%s\") [%p]",name,this); Debug(&hplugin,DebugAll,"YateH323EndPoint::YateH323EndPoint(\"%s\") [%p]",name,this);
String sect("ep"); String sect("ep");
if (name) if (name)
sect << " " << name; sect << " " << name;
@ -457,7 +459,7 @@ YateH323EndPoint::YateH323EndPoint(const char* name)
YateH323EndPoint::~YateH323EndPoint() YateH323EndPoint::~YateH323EndPoint()
{ {
Debug(DebugAll,"YateH323EndPoint::~YateH323EndPoint() [%p]",this); Debug(&hplugin,DebugAll,"YateH323EndPoint::~YateH323EndPoint() [%p]",this);
hplugin.m_endpoints.remove(this,false); hplugin.m_endpoints.remove(this,false);
RemoveListener(0); RemoveListener(0);
ClearAllCalls(H323Connection::EndedByTemporaryFailure, true); ClearAllCalls(H323Connection::EndedByTemporaryFailure, true);
@ -563,10 +565,10 @@ bool YateH323EndPoint::Init(void)
num = GetCapabilities().GetSize() - init; num = GetCapabilities().GetSize() - init;
} }
if (num) if (num)
Debug(DebugAll,"H.323 added %d capabilities '%s'",num,tmp.c_str()); Debug(&hplugin,DebugAll,"H.323 added %d capabilities '%s'",num,tmp.c_str());
else else
// warn if codecs were disabled by default // warn if codecs were disabled by default
Debug(defcodecs ? DebugInfo : DebugWarn,"H323 failed to add capability '%s'",tmp.c_str()); Debug(&hplugin,defcodecs ? DebugInfo : DebugWarn,"H323 failed to add capability '%s'",tmp.c_str());
} }
} }
@ -574,6 +576,7 @@ bool YateH323EndPoint::Init(void)
DisableDetectInBandDTMF(!s_cfg.getBoolValue(sect,"dtmfinband",false)); DisableDetectInBandDTMF(!s_cfg.getBoolValue(sect,"dtmfinband",false));
DisableFastStart(!s_cfg.getBoolValue(sect,"faststart",false)); DisableFastStart(!s_cfg.getBoolValue(sect,"faststart",false));
DisableH245Tunneling(!s_cfg.getBoolValue(sect,"h245tunneling",false)); DisableH245Tunneling(!s_cfg.getBoolValue(sect,"h245tunneling",false));
DisableH245inSetup(!s_cfg.getBoolValue(sect,"h245insetup",false));
SetSilenceDetectionMode(static_cast<H323AudioCodec::SilenceDetectionMode> SetSilenceDetectionMode(static_cast<H323AudioCodec::SilenceDetectionMode>
(s_cfg.getIntValue(sect,"silencedetect",dict_silence,H323AudioCodec::NoSilenceDetection))); (s_cfg.getIntValue(sect,"silencedetect",dict_silence,H323AudioCodec::NoSilenceDetection)));
@ -593,7 +596,7 @@ bool YateH323EndPoint::Init(void)
const char *p = s_cfg.getValue(sect,"password"); const char *p = s_cfg.getValue(sect,"password");
if (p) { if (p) {
SetGatekeeperPassword(p); SetGatekeeperPassword(p);
Debug(DebugInfo,"Enabling H.235 security access to gatekeeper %s",p); Debug(&hplugin,DebugInfo,"Enabling H.235 security access to gatekeeper %s",p);
} }
const char* d = s_cfg.getValue(sect,"gkip"); const char* d = s_cfg.getValue(sect,"gkip");
const char* a = s_cfg.getValue(sect,"gkname"); const char* a = s_cfg.getValue(sect,"gkname");
@ -601,7 +604,7 @@ bool YateH323EndPoint::Init(void)
PString gkName = d; PString gkName = d;
H323TransportUDP* rasChannel = new H323TransportUDP(*this); H323TransportUDP* rasChannel = new H323TransportUDP(*this);
if (SetGatekeeper(gkName, rasChannel)) if (SetGatekeeper(gkName, rasChannel))
Debug(DebugInfo,"Connect to gatekeeper ip = %s",d); Debug(&hplugin,DebugInfo,"Connect to gatekeeper ip = %s",d);
else { else {
Debug(DebugGoOn,"Unable to connect to gatekeeper ip = %s",d); Debug(DebugGoOn,"Unable to connect to gatekeeper ip = %s",d);
if (listener) if (listener)
@ -611,7 +614,7 @@ bool YateH323EndPoint::Init(void)
else if (a) { else if (a) {
PString gkIdentifier = a; PString gkIdentifier = a;
if (LocateGatekeeper(gkIdentifier)) if (LocateGatekeeper(gkIdentifier))
Debug(DebugInfo,"Connect to gatekeeper name = %s",a); Debug(&hplugin,DebugInfo,"Connect to gatekeeper name = %s",a);
else { else {
Debug(DebugGoOn,"Unable to connect to gatekeeper name = %s",a); Debug(DebugGoOn,"Unable to connect to gatekeeper name = %s",a);
if (listener) if (listener)
@ -620,7 +623,7 @@ bool YateH323EndPoint::Init(void)
} }
else { else {
if (DiscoverGatekeeper(new H323TransportUDP(*this))) if (DiscoverGatekeeper(new H323TransportUDP(*this)))
Debug(DebugInfo,"Find a gatekeeper"); Debug(&hplugin,DebugInfo,"Find a gatekeeper");
else { else {
Debug(DebugGoOn,"Unable to connect to any gatekeeper"); Debug(DebugGoOn,"Unable to connect to any gatekeeper");
if (listener) if (listener)
@ -642,16 +645,20 @@ bool YateH323EndPoint::Init(void)
YateH323Connection::YateH323Connection(YateH323EndPoint& endpoint, YateH323Connection::YateH323Connection(YateH323EndPoint& endpoint,
H323Transport* transport, unsigned callReference, void* userdata) H323Transport* transport, unsigned callReference, void* userdata)
: H323Connection(endpoint,callReference), m_chan(0), : H323Connection(endpoint,callReference), m_chan(0),
m_nativeRtp(false), m_passtrough(false), m_rtpPort(0), m_remotePort(0) m_externalRtp(s_externalRtp), m_nativeRtp(false), m_passtrough(false),
m_rtpPort(0), m_remotePort(0)
{ {
Debug(DebugAll,"YateH323Connection::YateH323Connection(%p,%u,%p) [%p]", Debug(&hplugin,DebugAll,"YateH323Connection::YateH323Connection(%p,%u,%p) [%p]",
&endpoint,callReference,userdata,this); &endpoint,callReference,userdata,this);
// outgoing calls get the "call.execute" message as user data
Message* msg = static_cast<Message*>(userdata); Message* msg = static_cast<Message*>(userdata);
m_chan = new YateH323Chan(this,userdata, m_chan = new YateH323Chan(this,userdata,
((transport && !userdata) ? (const char*)transport->GetRemoteAddress() : 0)); ((transport && !userdata) ? (const char*)transport->GetRemoteAddress() : 0));
if (!msg) if (!msg) {
m_passtrough = s_passtrough;
return; return;
}
setCallerID(msg->getValue("caller"),msg->getValue("callername")); setCallerID(msg->getValue("caller"),msg->getValue("callername"));
rtpForward(*msg,s_passtrough); rtpForward(*msg,s_passtrough);
@ -667,7 +674,7 @@ YateH323Connection::YateH323Connection(YateH323EndPoint& endpoint,
YateH323Connection::~YateH323Connection() YateH323Connection::~YateH323Connection()
{ {
Debug(DebugAll,"YateH323Connection::~YateH323Connection() [%p]",this); Debug(&hplugin,DebugAll,"YateH323Connection::~YateH323Connection() [%p]",this);
YateH323Chan* tmp = m_chan; YateH323Chan* tmp = m_chan;
m_chan = 0; m_chan = 0;
if (tmp) { if (tmp) {
@ -687,7 +694,7 @@ void YateH323Connection::cleanups()
H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PString &caller, H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PString &caller,
const H323SignalPDU &setupPDU, H323SignalPDU &connectPDU) const H323SignalPDU &setupPDU, H323SignalPDU &connectPDU)
{ {
Debug(DebugInfo,"YateH323Connection::OnAnswerCall caller='%s' chan=%p [%p]", Debug(m_chan,DebugInfo,"YateH323Connection::OnAnswerCall caller='%s' chan=%p [%p]",
(const char *)caller,m_chan,this); (const char *)caller,m_chan,this);
if (!m_chan) if (!m_chan)
return H323Connection::AnswerCallDenied; return H323Connection::AnswerCallDenied;
@ -703,32 +710,31 @@ H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PStrin
m->setParam("callername",caller); m->setParam("callername",caller);
s = GetRemotePartyNumber(); s = GetRemotePartyNumber();
Debug(DebugInfo,"GetRemotePartyNumber()='%s'",s); Debug(m_chan,DebugInfo,"GetRemotePartyNumber()='%s'",s);
m->setParam("caller",s ? s : (const char *)("h323/"+caller)); m->setParam("caller",s ? s : (const char *)("h323/"+caller));
const H225_Setup_UUIE &setup = setupPDU.m_h323_uu_pdu.m_h323_message_body; const H225_Setup_UUIE &setup = setupPDU.m_h323_uu_pdu.m_h323_message_body;
const H225_ArrayOf_AliasAddress &adr = setup.m_destinationAddress; const H225_ArrayOf_AliasAddress &adr = setup.m_destinationAddress;
for (int i = 0; i<adr.GetSize(); i++) for (int i = 0; i<adr.GetSize(); i++)
Debug(DebugAll,"adr[%d]='%s'",i,(const char *)H323GetAliasAddressString(adr[i])); Debug(m_chan,DebugAll,"adr[%d]='%s'",i,(const char *)H323GetAliasAddressString(adr[i]));
String called; String called;
if (adr.GetSize() > 0) if (adr.GetSize() > 0)
called = (const char *)H323GetAliasAddressString(adr[0]); called = (const char *)H323GetAliasAddressString(adr[0]);
if (called.null()) if (called.null())
called = s_cfg.getValue("incoming","called"); called = s_cfg.getValue("incoming","called");
if (!called.null()) { if (!called.null()) {
Debug(DebugInfo,"Called number is '%s'",called.c_str()); Debug(m_chan,DebugInfo,"Called number is '%s'",called.c_str());
m->setParam("called",called); m->setParam("called",called);
} }
else else
Debug(DebugWarn,"No called number present!"); Debug(m_chan,DebugMild,"No called number present!");
#if 0 #if 0
s = GetRemotePartyAddress(); s = GetRemotePartyAddress();
Debug(DebugInfo,"GetRemotePartyAddress()='%s'",s); Debug(m_chan,DebugInfo,"GetRemotePartyAddress()='%s'",s);
if (s) if (s)
m->setParam("calledname",s); m->setParam("calledname",s);
#endif #endif
if (s_passtrough && m_remotePort) { if (hasRemoteAddress()) {
m_passtrough = true;
m->addParam("rtp_forward","possible"); m->addParam("rtp_forward","possible");
m->addParam("rtp_addr",m_remoteAddr); m->addParam("rtp_addr",m_remoteAddr);
m->addParam("rtp_port",String(m_remotePort)); m->addParam("rtp_port",String(m_remotePort));
@ -737,25 +743,25 @@ H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PStrin
if (m_chan->startRouter(m)) if (m_chan->startRouter(m))
return H323Connection::AnswerCallDeferred; return H323Connection::AnswerCallDeferred;
Debug(DebugWarn,"Error starting H.323 routing thread! [%p]",this); Debug(&hplugin,DebugWarn,"Error starting H.323 routing thread! [%p]",this);
return H323Connection::AnswerCallDenied; return H323Connection::AnswerCallDenied;
} }
void YateH323Connection::rtpExecuted(Message& msg) void YateH323Connection::rtpExecuted(Message& msg)
{ {
Debug(DebugAll,"YateH323Connection::rtpExecuted(%p) [%p]", Debug(m_chan,DebugAll,"YateH323Connection::rtpExecuted(%p) [%p]",
&msg,this); &msg,this);
if (!m_passtrough) if (!m_passtrough)
return; return;
String tmp = msg.getValue("rtp_forward"); String tmp = msg.getValue("rtp_forward");
m_passtrough = (tmp == "accepted"); m_passtrough = (tmp == "accepted");
if (m_passtrough) if (m_passtrough)
Debug(DebugInfo,"H323 Peer accepted RTP forward"); Debug(m_chan,DebugInfo,"H323 Peer accepted RTP forward");
} }
void YateH323Connection::rtpForward(Message& msg, bool init) void YateH323Connection::rtpForward(Message& msg, bool init)
{ {
Debug(DebugAll,"YateH323Connection::rtpForward(%p,%d) [%p]", Debug(m_chan,DebugAll,"YateH323Connection::rtpForward(%p,%d) [%p]",
&msg,init,this); &msg,init,this);
String tmp = msg.getValue("rtp_forward"); String tmp = msg.getValue("rtp_forward");
if (!((init || m_passtrough) && tmp)) if (!((init || m_passtrough) && tmp))
@ -770,16 +776,41 @@ void YateH323Connection::rtpForward(Message& msg, bool init)
m_rtpPort = port; m_rtpPort = port;
m_formats = msg.getValue("formats"); m_formats = msg.getValue("formats");
msg.setParam("rtp_forward","accepted"); msg.setParam("rtp_forward","accepted");
Debug(DebugInfo,"H323 Accepted RTP forward %s:%d formats '%s'", Debug(m_chan,DebugInfo,"Accepted RTP forward %s:%d formats '%s'",
addr.c_str(),port,m_formats.safe()); addr.c_str(),port,m_formats.safe());
} }
else else {
m_passtrough = false; m_passtrough = false;
Debug(m_chan,DebugInfo,"Disabling RTP forward [%p]",this);
}
}
void YateH323Connection::answerCall(AnswerCallResponse response)
{
bool media = false;
if (hasRemoteAddress() && m_rtpPort)
media = true;
else if (m_chan && m_chan->getConsumer() && m_chan->getConsumer()->getConnSource())
media = true;
// modify responses to indicate we have early media (remote ringing)
if (media) {
switch (response) {
case AnswerCallPending:
response = AnswerCallAlertWithMedia;
break;
case AnswerCallDeferred:
response = AnswerCallDeferredWithMedia;
break;
default:
break;
}
}
AnsweringCall(response);
} }
void YateH323Connection::OnEstablished() void YateH323Connection::OnEstablished()
{ {
Debug(DebugInfo,"YateH323Connection::OnEstablished() [%p]",this); Debug(m_chan,DebugInfo,"YateH323Connection::OnEstablished() [%p]",this);
if (!m_chan) if (!m_chan)
return; return;
if (HadAnsweredCall()) { if (HadAnsweredCall()) {
@ -796,7 +827,7 @@ void YateH323Connection::OnEstablished()
m->addParam("formats",m_remoteFormats); m->addParam("formats",m_remoteFormats);
} }
else else
Debug(DebugWarn,"H323 RTP passtrough with no remote address! [%p]",this); Debug(m_chan,DebugWarn,"H323 RTP passtrough with no remote address! [%p]",this);
} }
Engine::enqueue(m); Engine::enqueue(m);
} }
@ -805,7 +836,7 @@ void YateH323Connection::OnCleared()
{ {
int reason = GetCallEndReason(); int reason = GetCallEndReason();
const char* rtext = CallEndReasonText(reason); const char* rtext = CallEndReasonText(reason);
Debug(DebugInfo,"YateH323Connection::OnCleared() reason: %s (%d) [%p]", Debug(m_chan,DebugInfo,"YateH323Connection::OnCleared() reason: %s (%d) [%p]",
rtext,reason,this); rtext,reason,this);
if (m_chan) if (m_chan)
m_chan->disconnect(rtext); m_chan->disconnect(rtext);
@ -813,12 +844,12 @@ void YateH323Connection::OnCleared()
BOOL YateH323Connection::OnAlerting(const H323SignalPDU &alertingPDU, const PString &user) BOOL YateH323Connection::OnAlerting(const H323SignalPDU &alertingPDU, const PString &user)
{ {
Debug(DebugInfo,"YateH323Connection::OnAlerting '%s' [%p]",(const char *)user,this); Debug(m_chan,DebugInfo,"YateH323Connection::OnAlerting '%s' [%p]",(const char *)user,this);
if (!m_chan) if (!m_chan)
return FALSE; return FALSE;
m_chan->status("ringing"); m_chan->status("ringing");
Message *m = m_chan->message("call.ringing",false,true); Message *m = m_chan->message("call.ringing",false,true);
if (m_passtrough && m_remotePort) { if (hasRemoteAddress()) {
m->addParam("rtp_forward","yes"); m->addParam("rtp_forward","yes");
m->addParam("rtp_addr",m_remoteAddr); m->addParam("rtp_addr",m_remoteAddr);
m->addParam("rtp_port",String(m_remotePort)); m->addParam("rtp_port",String(m_remotePort));
@ -830,7 +861,7 @@ BOOL YateH323Connection::OnAlerting(const H323SignalPDU &alertingPDU, const PStr
void YateH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned logicalChannel, unsigned rtpTimestamp) void YateH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned logicalChannel, unsigned rtpTimestamp)
{ {
Debug(DebugInfo,"YateH323Connection::OnUserInputTone '%c' duration=%u [%p]",tone,duration,this); Debug(m_chan,DebugInfo,"YateH323Connection::OnUserInputTone '%c' duration=%u [%p]",tone,duration,this);
if (!m_chan) if (!m_chan)
return; return;
char buf[2]; char buf[2];
@ -844,7 +875,7 @@ void YateH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned
void YateH323Connection::OnUserInputString(const PString &value) void YateH323Connection::OnUserInputString(const PString &value)
{ {
Debug(DebugInfo,"YateH323Connection::OnUserInputString '%s' [%p]",(const char *)value,this); Debug(m_chan,DebugInfo,"YateH323Connection::OnUserInputString '%s' [%p]",(const char *)value,this);
if (!m_chan) if (!m_chan)
return; return;
String text((const char *)value); String text((const char *)value);
@ -857,9 +888,9 @@ void YateH323Connection::OnUserInputString(const PString &value)
BOOL YateH323Connection::OpenAudioChannel(BOOL isEncoding, unsigned bufferSize, BOOL YateH323Connection::OpenAudioChannel(BOOL isEncoding, unsigned bufferSize,
H323AudioCodec &codec) H323AudioCodec &codec)
{ {
Debug(DebugInfo,"YateH323Connection::OpenAudioChannel [%p]",this); Debug(m_chan,DebugInfo,"YateH323Connection::OpenAudioChannel [%p]",this);
if (!m_nativeRtp) { if (!m_nativeRtp) {
Debug(DebugGoOn,"YateH323Connection::OpenAudioChannel for external RTP in [%p]",this); Debug(DebugGoOn,"YateH323Connection::OpenAudioChannel for non-native RTP in [%p]",this);
return FALSE; return FALSE;
} }
return m_chan && m_chan->OpenAudioChannel(isEncoding,codec); return m_chan && m_chan->OpenAudioChannel(isEncoding,codec);
@ -871,21 +902,22 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capability& capability,H323Channel::Directions dir,unsigned sessionID,const H245_H2250LogicalChannelParameters* param) H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capability& capability,H323Channel::Directions dir,unsigned sessionID,const H245_H2250LogicalChannelParameters* param)
#endif #endif
{ {
Debug(DebugAll,"H323Connection::CreateRealTimeLogicalChannel [%p]",this); Debug(m_chan,DebugAll,"H323Connection::CreateRealTimeLogicalChannel%s%s [%p]",
if (s_externalRtp || s_passtrough) { m_externalRtp ? " external" : "",m_passtrough ? " passtrough" : "",this);
if (m_externalRtp || m_passtrough) {
const char* sdir = lookup(dir,dict_h323_dir); const char* sdir = lookup(dir,dict_h323_dir);
const char *format = 0; const char *format = 0;
decodeCapability(capability,&format); decodeCapability(capability,&format);
Debug(DebugAll,"capability '%s' format '%s' session %u %s", Debug(m_chan,DebugAll,"Capability '%s' format '%s' session %u %s",
(const char *)capability.GetFormatName(),format,sessionID,sdir); (const char *)capability.GetFormatName(),format,sessionID,sdir);
// disallow codecs not supported by remote receiver // disallow codecs not supported by remote receiver
if (s_passtrough && !(m_formats.null() || (m_formats.find(format) >= 0))) { if (m_passtrough && !(m_formats.null() || (m_formats.find(format) >= 0))) {
Debug(DebugWarn,"Refusing '%s' not in remote '%s'",format,m_formats.c_str()); Debug(m_chan,DebugMild,"Refusing to create '%s' not in remote '%s'",format,m_formats.c_str());
return 0; return 0;
} }
if (s_passtrough && (dir == H323Channel::IsReceiver)) { if (m_passtrough && (dir == H323Channel::IsReceiver)) {
if (format && (m_remoteFormats.find(format) < 0) && s_cfg.getBoolValue("codecs",format,true)) { if (format && (m_remoteFormats.find(format) < 0) && s_cfg.getBoolValue("codecs",format,true)) {
if (m_remoteFormats) if (m_remoteFormats)
m_remoteFormats << ","; m_remoteFormats << ",";
@ -894,9 +926,9 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
} }
PIPSocket::Address externalIpAddress; PIPSocket::Address externalIpAddress;
GetControlChannel().GetLocalAddress().GetIpAddress(externalIpAddress); GetControlChannel().GetLocalAddress().GetIpAddress(externalIpAddress);
Debug(DebugInfo,"address '%s'",(const char *)externalIpAddress.AsString()); Debug(m_chan,DebugInfo,"address '%s'",(const char *)externalIpAddress.AsString());
WORD externalPort = 0; WORD externalPort = 0;
if (s_externalRtp) { if (!m_passtrough) {
Message m("chan.rtp"); Message m("chan.rtp");
m.addParam("localip",externalIpAddress.AsString()); m.addParam("localip",externalIpAddress.AsString());
m.userData(m_chan); m.userData(m_chan);
@ -907,7 +939,7 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
externalPort = m.getIntValue("localport"); externalPort = m.getIntValue("localport");
} }
} }
if (externalPort || s_passtrough) { if (externalPort || m_passtrough) {
m_nativeRtp = false; m_nativeRtp = false;
if (!externalPort) { if (!externalPort) {
externalPort = m_rtpPort; externalPort = m_rtpPort;
@ -915,7 +947,7 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
} }
return new YateH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort); return new YateH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort);
} }
Debug(DebugWarn,"YateH323Connection failed to create external RTP, using native"); Debug(m_chan,DebugWarn,"YateH323Connection falling back to native RTP [%p]",this);
} }
m_nativeRtp = true; m_nativeRtp = true;
@ -928,7 +960,8 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
void YateH323Connection::OnSetLocalCapabilities() void YateH323Connection::OnSetLocalCapabilities()
{ {
Debug(DebugAll,"YateH323Connection::OnSetLocalCapabilities() [%p]",this); Debug(m_chan,DebugAll,"YateH323Connection::OnSetLocalCapabilities()%s%s [%p]",
m_externalRtp ? " external" : "",m_passtrough ? " passtrough" : "",this);
H323Connection::OnSetLocalCapabilities(); H323Connection::OnSetLocalCapabilities();
if (m_formats.null()) if (m_formats.null())
return; return;
@ -940,7 +973,7 @@ void YateH323Connection::OnSetLocalCapabilities()
decodeCapability(localCapabilities[i],&format,0,&fname); decodeCapability(localCapabilities[i],&format,0,&fname);
if (format) { if (format) {
if (m_formats.find(format) < 0) { if (m_formats.find(format) < 0) {
Debug(DebugAll,"Removing capability '%s' (%s) not in remote '%s'", Debug(m_chan,DebugAll,"Removing capability '%s' (%s) not in remote '%s'",
fname.c_str(),format,m_formats.c_str()); fname.c_str(),format,m_formats.c_str());
localCapabilities.Remove(fname.c_str()); localCapabilities.Remove(fname.c_str());
i--; i--;
@ -955,13 +988,13 @@ void YateH323Connection::OnSetLocalCapabilities()
BOOL YateH323Connection::OnStartLogicalChannel(H323Channel & channel) BOOL YateH323Connection::OnStartLogicalChannel(H323Channel & channel)
{ {
Debug(DebugInfo,"YateH323Connection::OnStartLogicalChannel(%p) [%p]",&channel,this); Debug(m_chan,DebugInfo,"YateH323Connection::OnStartLogicalChannel(%p) [%p]",&channel,this);
return m_nativeRtp ? H323Connection::OnStartLogicalChannel(channel) : TRUE; return m_nativeRtp ? H323Connection::OnStartLogicalChannel(channel) : TRUE;
} }
BOOL YateH323Connection::OnCreateLogicalChannel(const H323Capability & capability, H323Channel::Directions dir, unsigned & errorCode ) BOOL YateH323Connection::OnCreateLogicalChannel(const H323Capability & capability, H323Channel::Directions dir, unsigned & errorCode )
{ {
Debug(DebugInfo,"YateH323Connection::OnCreateLogicalChannel('%s',%s) [%p]",(const char *)capability.GetFormatName(),lookup(dir,dict_h323_dir),this); Debug(m_chan,DebugInfo,"YateH323Connection::OnCreateLogicalChannel('%s',%s) [%p]",(const char *)capability.GetFormatName(),lookup(dir,dict_h323_dir),this);
return H323Connection::OnCreateLogicalChannel(capability,dir,errorCode); return H323Connection::OnCreateLogicalChannel(capability,dir,errorCode);
} }
@ -983,7 +1016,7 @@ BOOL YateH323Connection::decodeCapability(const H323Capability& capability, cons
break; break;
} }
} }
DDebug(DebugAll,"capability '%s' format '%s' payload %d",fname.c_str(),format,pload); DDebug(m_chan,DebugAll,"capability '%s' format '%s' payload %d",fname.c_str(),format,pload);
if (format) { if (format) {
if (capabName) if (capabName)
*capabName = fname; *capabName = fname;
@ -996,37 +1029,36 @@ BOOL YateH323Connection::decodeCapability(const H323Capability& capability, cons
return FALSE; return FALSE;
} }
void YateH323Connection::SetRemoteAddress(const char* remoteIP, WORD remotePort) void YateH323Connection::setRemoteAddress(const char* remoteIP, WORD remotePort)
{ {
if (!m_remotePort) { if (!m_remotePort) {
Debug(DebugInfo,"Copying remote RTP address [%p]",this); Debug(m_chan,DebugInfo,"Copying remote RTP address [%p]",this);
m_remotePort = remotePort; m_remotePort = remotePort;
m_remoteAddr = remoteIP; m_remoteAddr = remoteIP;
} }
} }
BOOL YateH323Connection::StartExternalRTP(const char* remoteIP, WORD remotePort, H323Channel::Directions dir, YateH323_ExternalRTPChannel* chan) BOOL YateH323Connection::startExternalRTP(const char* remoteIP, WORD remotePort, H323Channel::Directions dir, YateH323_ExternalRTPChannel* chan)
{ {
const char* sdir = lookup(dir,dict_h323_dir); const char* sdir = lookup(dir,dict_h323_dir);
Debug(DebugAll,"YateH323Connection::StartExternalRTP(\"%s\",%u,%s,%p) [%p]", Debug(m_chan,DebugAll,"YateH323Connection::startExternalRTP(\"%s\",%u,%s,%p) [%p]",
remoteIP,remotePort,sdir,chan,this); remoteIP,remotePort,sdir,chan,this);
if (m_passtrough && m_rtpPort) { if (m_passtrough && m_rtpPort) {
SetRemoteAddress(remoteIP,remotePort); setRemoteAddress(remoteIP,remotePort);
Debug(DebugInfo,"Passing RTP to %s:%d",m_rtpAddr.c_str(),m_rtpPort); Debug(m_chan,DebugInfo,"Passing RTP to %s:%d",m_rtpAddr.c_str(),m_rtpPort);
const PIPSocket::Address ip(m_rtpAddr.safe()); const PIPSocket::Address ip(m_rtpAddr.safe());
WORD dataPort = m_rtpPort; WORD dataPort = m_rtpPort;
chan->SetExternalAddress(H323TransportAddress(ip, dataPort), H323TransportAddress(ip, dataPort+1)); chan->SetExternalAddress(H323TransportAddress(ip, dataPort), H323TransportAddress(ip, dataPort+1));
OnStoppedExternal(dir); stoppedExternal(dir);
return TRUE; return TRUE;
} }
if (!s_externalRtp) if (!m_externalRtp)
return FALSE; return FALSE;
Message m("chan.rtp"); Message m("chan.rtp");
m.userData(m_chan); m.userData(m_chan);
if (m_rtpid) if (m_rtpid)
m.setParam("rtpid",m_rtpid); m.setParam("rtpid",m_rtpid);
// Debug(DebugAll,"userData=%p this=%p",m.userData(),this);
if (sdir) if (sdir)
m.addParam("direction",sdir); m.addParam("direction",sdir);
m.addParam("remoteip",remoteIP); m.addParam("remoteip",remoteIP);
@ -1046,9 +1078,9 @@ BOOL YateH323Connection::StartExternalRTP(const char* remoteIP, WORD remotePort,
return FALSE; return FALSE;
} }
void YateH323Connection::OnStoppedExternal(H323Channel::Directions dir) void YateH323Connection::stoppedExternal(H323Channel::Directions dir)
{ {
Debug(DebugInfo,"YateH323Connection::OnStoppedExternal(%s) [%p]",lookup(dir,dict_h323_dir),this); Debug(m_chan,DebugInfo,"YateH323Connection::stoppedExternal(%s) [%p]",lookup(dir,dict_h323_dir),this);
if (!m_chan) if (!m_chan)
return; return;
switch (dir) { switch (dir) {
@ -1087,62 +1119,62 @@ YateH323_ExternalRTPChannel::YateH323_ExternalRTPChannel(
: H323_ExternalRTPChannel(connection, capability, direction, sessionID, ip, dataPort), : H323_ExternalRTPChannel(connection, capability, direction, sessionID, ip, dataPort),
m_conn(&connection) m_conn(&connection)
{ {
Debug(DebugAll,"YateH323_ExternalRTPChannel::YateH323_ExternalRTPChannel %s addr=%s:%u [%p]", Debug(&hplugin,DebugAll,"YateH323_ExternalRTPChannel::YateH323_ExternalRTPChannel %s addr=%s:%u [%p]",
lookup(GetDirection(),dict_h323_dir), (const char *)ip.AsString(), dataPort,this); lookup(GetDirection(),dict_h323_dir), (const char *)ip.AsString(), dataPort,this);
SetExternalAddress(H323TransportAddress(ip, dataPort), H323TransportAddress(ip, dataPort+1)); SetExternalAddress(H323TransportAddress(ip, dataPort), H323TransportAddress(ip, dataPort+1));
} }
YateH323_ExternalRTPChannel::~YateH323_ExternalRTPChannel() YateH323_ExternalRTPChannel::~YateH323_ExternalRTPChannel()
{ {
Debug(DebugInfo,"YateH323_ExternalRTPChannel::~YateH323_ExternalRTPChannel %s%s [%p]", Debug(&hplugin,DebugInfo,"YateH323_ExternalRTPChannel::~YateH323_ExternalRTPChannel %s%s [%p]",
lookup(GetDirection(),dict_h323_dir),(isRunning ? " running" : ""),this); lookup(GetDirection(),dict_h323_dir),(isRunning ? " running" : ""),this);
if (isRunning) { if (isRunning) {
isRunning = FALSE; isRunning = FALSE;
if (m_conn) if (m_conn)
m_conn->OnStoppedExternal(GetDirection()); m_conn->stoppedExternal(GetDirection());
} }
} }
BOOL YateH323_ExternalRTPChannel::Start() BOOL YateH323_ExternalRTPChannel::Start()
{ {
Debug(DebugAll,"YateH323_ExternalRTPChannel::Start() [%p]",this); Debug(&hplugin,DebugAll,"YateH323_ExternalRTPChannel::Start() [%p]",this);
if (!m_conn) if (!m_conn)
return FALSE; return FALSE;
PIPSocket::Address remoteIpAddress; PIPSocket::Address remoteIpAddress;
WORD remotePort; WORD remotePort;
GetRemoteAddress(remoteIpAddress,remotePort); GetRemoteAddress(remoteIpAddress,remotePort);
Debug(DebugInfo,"external rtp ip address %s:%u",(const char *)remoteIpAddress.AsString(),remotePort); Debug(&hplugin,DebugInfo,"external rtp ip address %s:%u",(const char *)remoteIpAddress.AsString(),remotePort);
return isRunning = m_conn->StartExternalRTP((const char *)remoteIpAddress.AsString(), remotePort, GetDirection(), this); return isRunning = m_conn->startExternalRTP((const char *)remoteIpAddress.AsString(), remotePort, GetDirection(), this);
} }
BOOL YateH323_ExternalRTPChannel::OnReceivedPDU( BOOL YateH323_ExternalRTPChannel::OnReceivedPDU(
const H245_H2250LogicalChannelParameters& param, const H245_H2250LogicalChannelParameters& param,
unsigned& errorCode) unsigned& errorCode)
{ {
Debug(DebugInfo,"OnReceivedPDU [%p]",this); Debug(&hplugin,DebugInfo,"OnReceivedPDU [%p]",this);
if (!H323_ExternalRTPChannel::OnReceivedPDU(param,errorCode)) if (!H323_ExternalRTPChannel::OnReceivedPDU(param,errorCode))
return FALSE; return FALSE;
if (!m_conn || m_conn->HasRemoteAddress()) if (!m_conn || m_conn->hasRemoteAddress())
return TRUE; return TRUE;
PIPSocket::Address remoteIpAddress; PIPSocket::Address remoteIpAddress;
WORD remotePort; WORD remotePort;
GetRemoteAddress(remoteIpAddress,remotePort); GetRemoteAddress(remoteIpAddress,remotePort);
Debug(DebugInfo,"external rtp ip address %s:%u",(const char *)remoteIpAddress.AsString(),remotePort); Debug(&hplugin,DebugInfo,"external rtp ip address %s:%u",(const char *)remoteIpAddress.AsString(),remotePort);
m_conn->SetRemoteAddress((const char *)remoteIpAddress.AsString(), remotePort); m_conn->setRemoteAddress((const char *)remoteIpAddress.AsString(), remotePort);
return TRUE; return TRUE;
} }
BOOL YateH323_ExternalRTPChannel::OnSendingPDU(H245_H2250LogicalChannelParameters& param) BOOL YateH323_ExternalRTPChannel::OnSendingPDU(H245_H2250LogicalChannelParameters& param)
{ {
Debug(DebugInfo,"OnSendingPDU [%p]",this); Debug(&hplugin,DebugInfo,"OnSendingPDU [%p]",this);
return H323_ExternalRTPChannel::OnSendingPDU(param); return H323_ExternalRTPChannel::OnSendingPDU(param);
} }
BOOL YateH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters& param) BOOL YateH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters& param)
{ {
Debug(DebugInfo,"OnReceivedAckPDU [%p]",this); Debug(&hplugin,DebugInfo,"OnReceivedAckPDU [%p]",this);
return H323_ExternalRTPChannel::OnReceivedAckPDU(param); return H323_ExternalRTPChannel::OnReceivedAckPDU(param);
} }
@ -1399,7 +1431,7 @@ void YateH323Connection::setCallerID(const char* number, const char* name)
display << number << " [" << name << "]"; display << number << " [" << name << "]";
else else
display = name; display = name;
Debug(DebugInfo,"Setting H.323 caller: number='%s' name='%s'",number,display.c_str()); Debug(m_chan,DebugInfo,"Setting H.323 caller: number='%s' name='%s'",number,display.c_str());
SetLocalPartyName(number); SetLocalPartyName(number);
localAliasNames.AppendString(display.c_str()); localAliasNames.AppendString(display.c_str());
} }
@ -1411,7 +1443,7 @@ void YateH323Connection::setCallerID(const char* number, const char* name)
display = number; display = number;
else else
display = name; display = name;
Debug(DebugInfo,"Setting H.323 caller: name='%s'",display.c_str()); Debug(m_chan,DebugInfo,"Setting H.323 caller: name='%s'",display.c_str());
SetLocalPartyName(display.c_str()); SetLocalPartyName(display.c_str());
} }
} }
@ -1419,7 +1451,7 @@ void YateH323Connection::setCallerID(const char* number, const char* name)
YateH323Chan::YateH323Chan(YateH323Connection* conn,bool outgoing,const char* addr) YateH323Chan::YateH323Chan(YateH323Connection* conn,bool outgoing,const char* addr)
: Channel(hplugin,0,outgoing), m_conn(conn) : Channel(hplugin,0,outgoing), m_conn(conn)
{ {
Debug(DebugAll,"YateH323Chan::YateH323Chan(%p,%s) %s [%p]", Debug(this,DebugAll,"YateH323Chan::YateH323Chan(%p,%s) %s [%p]",
conn,addr,direction(),this); conn,addr,direction(),this);
m_address = addr; m_address = addr;
Engine::enqueue(message("chan.startup")); Engine::enqueue(message("chan.startup"));
@ -1427,7 +1459,7 @@ YateH323Chan::YateH323Chan(YateH323Connection* conn,bool outgoing,const char* ad
YateH323Chan::~YateH323Chan() YateH323Chan::~YateH323Chan()
{ {
Debug(DebugAll,"YateH323Chan::~YateH323Chan() %s %s [%p]", Debug(this,DebugAll,"YateH323Chan::~YateH323Chan() %s %s [%p]",
m_status.c_str(),m_id.c_str(),this); m_status.c_str(),m_id.c_str(),this);
Message *m = message("chan.hangup"); Message *m = message("chan.hangup");
drop(); drop();
@ -1515,7 +1547,7 @@ void YateH323Chan::callAccept(Message& msg)
Channel::callAccept(msg); Channel::callAccept(msg);
if (m_conn) { if (m_conn) {
m_conn->rtpExecuted(msg); m_conn->rtpExecuted(msg);
m_conn->AnsweringCall(H323Connection::AnswerCallPending); m_conn->answerCall(H323Connection::AnswerCallPending);
} }
} }
@ -1531,8 +1563,7 @@ bool YateH323Chan::msgRinging(Message& msg)
return false; return false;
if (msg.getParam("rtp_forward")) if (msg.getParam("rtp_forward"))
m_conn->rtpForward(msg); m_conn->rtpForward(msg);
// FIXME: with or without media? m_conn->answerCall(H323Connection::AnswerCallPending);
m_conn->AnsweringCall(H323Connection::AnswerCallAlertWithMedia);
return true; return true;
} }
@ -1541,7 +1572,7 @@ bool YateH323Chan::msgAnswered(Message& msg)
if (!m_conn) if (!m_conn)
return false; return false;
m_conn->rtpForward(msg); m_conn->rtpForward(msg);
m_conn->AnsweringCall(H323Connection::AnswerCallNow); m_conn->answerCall(H323Connection::AnswerCallNow);
return true; return true;
} }
@ -1553,7 +1584,7 @@ bool YateH323Chan::msgTone(Message& msg, const char* tone)
bool YateH323Chan::msgText(Message& msg, const char* text) bool YateH323Chan::msgText(Message& msg, const char* text)
{ {
if (text && m_conn) { if (text && m_conn) {
Debug("H323",DebugInfo,"Text '%s' for %s [%p]",text,id().c_str(),this); Debug(this,DebugInfo,"Text '%s' for %s [%p]",text,id().c_str(),this);
m_conn->SendUserInputIndicationString(text); m_conn->SendUserInputIndicationString(text);
return true; return true;
} }
@ -1600,10 +1631,10 @@ bool H323Driver::msgExecute(Message& msg, String& dest)
if (dest.null()) if (dest.null())
return false; return false;
if (!msg.userData()) { if (!msg.userData()) {
Debug(DebugWarn,"H.323 call found but no data channel!"); Debug(this,DebugWarn,"H.323 call found but no data channel!");
return false; return false;
} }
Debug(DebugInfo,"Found call to H.323 target='%s'", Debug(this,DebugInfo,"Found call to H.323 target='%s'",
dest.c_str()); dest.c_str());
PString p; PString p;
YateH323EndPoint* ep = hplugin.findEndpoint(msg.getValue("line")); YateH323EndPoint* ep = hplugin.findEndpoint(msg.getValue("line"));

View File

@ -73,7 +73,7 @@ public:
virtual void run(); virtual void run();
bool processLine(const char *line); bool processLine(const char *line);
void writeStr(const char *str, int len = -1); void writeStr(const char *str, int len = -1);
void writeDebug(const char *str); void writeDebug(const char *str, int level);
void writeStr(Message &msg,bool received); void writeStr(Message &msg,bool received);
inline void writeStr(const String &s) inline void writeStr(const String &s)
{ writeStr(s.safe(),s.length()); } { writeStr(s.safe(),s.length()); }
@ -99,14 +99,14 @@ private:
bool m_first; bool m_first;
}; };
static void dbg_remote_func(const char *buf) static void dbg_remote_func(const char *buf, int level)
{ {
s_mutex.lock(); s_mutex.lock();
ObjList *p = &connectionlist; ObjList *p = &connectionlist;
for (; p; p=p->next()) { for (; p; p=p->next()) {
Connection *con = static_cast<Connection *>(p->get()); Connection *con = static_cast<Connection *>(p->get());
if (con) if (con)
con->writeDebug(buf); con->writeDebug(buf,level);
} }
s_mutex.unlock(); s_mutex.unlock();
} }
@ -436,7 +436,7 @@ void Connection::writeStr(Message &msg,bool received)
writeStr(s.c_str()); writeStr(s.c_str());
} }
void Connection::writeDebug(const char *str) void Connection::writeDebug(const char *str, int level)
{ {
if (m_debug && !null(str)) if (m_debug && !null(str))
writeStr(str,::strlen(str)); writeStr(str,::strlen(str));

View File

@ -227,6 +227,7 @@ ToneChan::ToneChan(const String &tone)
ToneSource *t = ToneSource::getTone(tone); ToneSource *t = ToneSource::getTone(tone);
if (t) { if (t) {
setSource(t); setSource(t);
m_address = t->name();
t->deref(); t->deref();
} }
else else

View File

@ -157,12 +157,13 @@ public:
virtual bool received(Message &msg); virtual bool received(Message &msg);
}; };
class YRTPPlugin : public Plugin class YRTPPlugin : public Module
{ {
public: public:
YRTPPlugin(); YRTPPlugin();
virtual ~YRTPPlugin(); virtual ~YRTPPlugin();
virtual void initialize(); virtual void initialize();
virtual void statusParams(String& str);
private: private:
bool m_first; bool m_first;
}; };
@ -175,7 +176,7 @@ YRTPWrapper::YRTPWrapper(const char* localip, CallEndpoint* conn, RTPSession::Di
: m_rtp(0), m_dir(direction), m_conn(conn), : m_rtp(0), m_dir(direction), m_conn(conn),
m_source(0), m_consumer(0), m_bufsize(0), m_port(0) m_source(0), m_consumer(0), m_bufsize(0), m_port(0)
{ {
Debug(DebugAll,"YRTPWrapper::YRTPWrapper(\"%s\",%p,%s) [%p]", Debug(&splugin,DebugAll,"YRTPWrapper::YRTPWrapper(\"%s\",%p,%s) [%p]",
localip,conn,lookup(direction,dict_yrtp_dir),this); localip,conn,lookup(direction,dict_yrtp_dir),this);
m_id = "yrtp/"; m_id = "yrtp/";
m_id << (unsigned int)::random(); m_id << (unsigned int)::random();
@ -187,7 +188,7 @@ YRTPWrapper::YRTPWrapper(const char* localip, CallEndpoint* conn, RTPSession::Di
YRTPWrapper::~YRTPWrapper() YRTPWrapper::~YRTPWrapper()
{ {
Debug(DebugAll,"YRTPWrapper::~YRTPWrapper() %s [%p]", Debug(&splugin,DebugAll,"YRTPWrapper::~YRTPWrapper() %s [%p]",
lookup(m_dir,dict_yrtp_dir),this); lookup(m_dir,dict_yrtp_dir),this);
s_mutex.lock(); s_mutex.lock();
s_calls.remove(this,false); s_calls.remove(this,false);
@ -198,12 +199,12 @@ YRTPWrapper::~YRTPWrapper()
delete tmp; delete tmp;
} }
if (m_source) { if (m_source) {
Debug(DebugGoOn,"There is still a RTP source %p [%p]",m_source,this); Debug(&splugin,DebugGoOn,"There is still a RTP source %p [%p]",m_source,this);
m_source->destruct(); m_source->destruct();
m_source = 0; m_source = 0;
} }
if (m_consumer) { if (m_consumer) {
Debug(DebugGoOn,"There is still a RTP consumer %p [%p]",m_consumer,this); Debug(&splugin,DebugGoOn,"There is still a RTP consumer %p [%p]",m_consumer,this);
m_consumer->destruct(); m_consumer->destruct();
m_consumer = 0; m_consumer = 0;
} }
@ -236,7 +237,7 @@ YRTPWrapper* YRTPWrapper::find(const String& id)
void YRTPWrapper::setupRTP(const char* localip) void YRTPWrapper::setupRTP(const char* localip)
{ {
Debug(DebugAll,"YRTPWrapper::setupRTP(\"%s\") [%p]",localip,this); Debug(&splugin,DebugAll,"YRTPWrapper::setupRTP(\"%s\") [%p]",localip,this);
m_rtp = new YRTPSession(this); m_rtp = new YRTPSession(this);
m_rtp->initTransport(); m_rtp->initTransport();
int minport = s_cfg.getIntValue("rtp","minport",16384); int minport = s_cfg.getIntValue("rtp","minport",16384);
@ -253,7 +254,7 @@ void YRTPWrapper::setupRTP(const char* localip)
} }
SocketAddr addr(AF_INET); SocketAddr addr(AF_INET);
if (!addr.host(localip)) { if (!addr.host(localip)) {
Debug(DebugWarn,"YRTPWrapper [%p] could not parse address '%s'",this,localip); Debug(&splugin,DebugWarn,"YRTPWrapper [%p] could not parse address '%s'",this,localip);
return; return;
} }
for (; attempt; attempt--) { for (; attempt; attempt--) {
@ -261,50 +262,50 @@ void YRTPWrapper::setupRTP(const char* localip)
addr.port(lport); addr.port(lport);
if (m_rtp->localAddr(addr)) { if (m_rtp->localAddr(addr)) {
m_port = lport; m_port = lport;
Debug(DebugAll,"YRTPWrapper [%p] RTP %p bound to %s:%u",this,m_rtp,localip,m_port); Debug(&splugin,DebugAll,"YRTPWrapper [%p] RTP %p bound to %s:%u",this,m_rtp,localip,m_port);
return; return;
} }
} }
Debug(DebugWarn,"YRTPWrapper [%p] RTP bind failed in range %d-%d",this,minport,maxport); Debug(&splugin,DebugWarn,"YRTPWrapper [%p] RTP bind failed in range %d-%d",this,minport,maxport);
} }
bool YRTPWrapper::startRTP(const char* raddr, unsigned int rport, int payload, int evpayload, const char* format) bool YRTPWrapper::startRTP(const char* raddr, unsigned int rport, int payload, int evpayload, const char* format)
{ {
Debug(DebugAll,"YRTPWrapper::startRTP(\"%s\",%u,%d) [%p]",raddr,rport,payload,this); Debug(&splugin,DebugAll,"YRTPWrapper::startRTP(\"%s\",%u,%d) [%p]",raddr,rport,payload,this);
if (!m_rtp) { if (!m_rtp) {
Debug(DebugWarn,"YRTPWrapper [%p] attempted to start RTP before setup!",this); Debug(&splugin,DebugWarn,"YRTPWrapper [%p] attempted to start RTP before setup!",this);
return false; return false;
} }
if (m_bufsize) { if (m_bufsize) {
Debug(DebugMild,"YRTPWrapper [%p] attempted to restart RTP!",this); Debug(&splugin,DebugMild,"YRTPWrapper [%p] attempted to restart RTP!",this);
return true; return true;
} }
if (!format) if (!format)
format = lookup(payload, dict_payloads); format = lookup(payload, dict_payloads);
if (!format) { if (!format) {
Debug(DebugWarn,"YRTPWrapper [%p] can't find name for payload %d",this,payload); Debug(&splugin,DebugWarn,"YRTPWrapper [%p] can't find name for payload %d",this,payload);
return false; return false;
} }
if (payload == -1) if (payload == -1)
payload = lookup(format, dict_payloads, -1); payload = lookup(format, dict_payloads, -1);
if (payload == -1) { if (payload == -1) {
Debug(DebugWarn,"YRTPWrapper [%p] can't find payload for format %s",this,format); Debug(&splugin,DebugWarn,"YRTPWrapper [%p] can't find payload for format %s",this,format);
return false; return false;
} }
if ((payload < 0) || (payload >= 127)) { if ((payload < 0) || (payload >= 127)) {
Debug(DebugWarn,"YRTPWrapper [%p] received invalid payload %d",this,payload); Debug(&splugin,DebugWarn,"YRTPWrapper [%p] received invalid payload %d",this,payload);
return false; return false;
} }
Debug(DebugAll,"RTP format '%s' payload %d",format,payload); Debug(&splugin,DebugAll,"RTP format '%s' payload %d",format,payload);
SocketAddr addr(AF_INET); SocketAddr addr(AF_INET);
if (!(addr.host(raddr) && addr.port(rport) && m_rtp->remoteAddr(addr))) { if (!(addr.host(raddr) && addr.port(rport) && m_rtp->remoteAddr(addr))) {
Debug(DebugWarn,"RTP failed to set remote address %s:%d [%p]",raddr,rport,this); Debug(&splugin,DebugWarn,"RTP failed to set remote address %s:%d [%p]",raddr,rport,this);
return false; return false;
} }
// Change format of source and/or consumer, // Change format of source and/or consumer,
@ -346,7 +347,7 @@ bool YRTPWrapper::sendDTMF(char dtmf, int duration)
void YRTPWrapper::gotDTMF(char tone) void YRTPWrapper::gotDTMF(char tone)
{ {
Debug(DebugInfo,"YRTPWrapper::gotDTMF('%c') [%p]",tone,this); Debug(&splugin,DebugInfo,"YRTPWrapper::gotDTMF('%c') [%p]",tone,this);
if (m_master.null()) if (m_master.null())
return; return;
char buf[2]; char buf[2];
@ -364,16 +365,16 @@ void YRTPWrapper::guessLocal(const char* remoteip, String& localip)
localip.clear(); localip.clear();
SocketAddr r(AF_INET); SocketAddr r(AF_INET);
if (!r.host(remoteip)) { if (!r.host(remoteip)) {
Debug(DebugInfo,"Guess - Could not parse remote '%s'",remoteip); Debug(&splugin,DebugInfo,"Guess - Could not parse remote '%s'",remoteip);
return; return;
} }
SocketAddr l; SocketAddr l;
if (!l.local(r)) { if (!l.local(r)) {
Debug(DebugInfo,"Guess - Could not guess local for remote '%s'",remoteip); Debug(&splugin,DebugInfo,"Guess - Could not guess local for remote '%s'",remoteip);
return; return;
} }
localip = l.host(); localip = l.host();
Debug(DebugInfo,"Guessed local IP '%s' for remote '%s'",localip.c_str(),remoteip); Debug(&splugin,DebugInfo,"Guessed local IP '%s' for remote '%s'",localip.c_str(),remoteip);
} }
void YRTPWrapper::addDirection(RTPSession::Direction direction) void YRTPWrapper::addDirection(RTPSession::Direction direction)
@ -407,7 +408,7 @@ bool YRTPSession::rtpRecvEvent(int event, char key, int duration,
void YRTPSession::rtpNewPayload(int payload, unsigned int timestamp) void YRTPSession::rtpNewPayload(int payload, unsigned int timestamp)
{ {
if (payload == 13) { if (payload == 13) {
Debug(DebugInfo,"Activating RTP silence payload %d in wrapper %p",payload,m_wrap); Debug(&splugin,DebugInfo,"Activating RTP silence payload %d in wrapper %p",payload,m_wrap);
m_wrap->rtp()->silencePayload(payload); m_wrap->rtp()->silencePayload(payload);
} }
} }
@ -415,7 +416,7 @@ void YRTPSession::rtpNewPayload(int payload, unsigned int timestamp)
YRTPAudioSource::YRTPAudioSource(YRTPWrapper* wrap) YRTPAudioSource::YRTPAudioSource(YRTPWrapper* wrap)
: m_wrap(wrap) : m_wrap(wrap)
{ {
Debug(DebugAll,"YRTPAudioSource::YRTPAudioSource(%p) [%p]",wrap,this); Debug(&splugin,DebugAll,"YRTPAudioSource::YRTPAudioSource(%p) [%p]",wrap,this);
m_format.clear(); m_format.clear();
if (m_wrap) { if (m_wrap) {
m_wrap->ref(); m_wrap->ref();
@ -425,7 +426,7 @@ YRTPAudioSource::YRTPAudioSource(YRTPWrapper* wrap)
YRTPAudioSource::~YRTPAudioSource() YRTPAudioSource::~YRTPAudioSource()
{ {
Debug(DebugAll,"YRTPAudioSource::~YRTPAudioSource() [%p] wrapper=%p",this,m_wrap); Debug(&splugin,DebugAll,"YRTPAudioSource::~YRTPAudioSource() [%p] wrapper=%p",this,m_wrap);
m_mutex.lock(); m_mutex.lock();
if (m_wrap) { if (m_wrap) {
YRTPWrapper* tmp = m_wrap; YRTPWrapper* tmp = m_wrap;
@ -440,7 +441,7 @@ YRTPAudioSource::~YRTPAudioSource()
YRTPAudioConsumer::YRTPAudioConsumer(YRTPWrapper *wrap) YRTPAudioConsumer::YRTPAudioConsumer(YRTPWrapper *wrap)
: m_wrap(wrap), m_timestamp(0) : m_wrap(wrap), m_timestamp(0)
{ {
Debug(DebugAll,"YRTPAudioConsumer::YRTPAudioConsumer(%p) [%p]",wrap,this); Debug(&splugin,DebugAll,"YRTPAudioConsumer::YRTPAudioConsumer(%p) [%p]",wrap,this);
m_format.clear(); m_format.clear();
if (m_wrap) { if (m_wrap) {
m_wrap->ref(); m_wrap->ref();
@ -450,7 +451,7 @@ YRTPAudioConsumer::YRTPAudioConsumer(YRTPWrapper *wrap)
YRTPAudioConsumer::~YRTPAudioConsumer() YRTPAudioConsumer::~YRTPAudioConsumer()
{ {
Debug(DebugAll,"YRTPAudioConsumer::~YRTPAudioConsumer() [%p] wrapper=%p ts=%d",this,m_wrap,m_timestamp); Debug(&splugin,DebugAll,"YRTPAudioConsumer::~YRTPAudioConsumer() [%p] wrapper=%p ts=%d",this,m_wrap,m_timestamp);
if (m_wrap) { if (m_wrap) {
YRTPWrapper* tmp = m_wrap; YRTPWrapper* tmp = m_wrap;
m_wrap = 0; m_wrap = 0;
@ -463,7 +464,7 @@ void YRTPAudioConsumer::Consume(const DataBlock &data, unsigned long timeDelta)
{ {
if (!(m_wrap && m_wrap->bufSize() && m_wrap->rtp())) if (!(m_wrap && m_wrap->bufSize() && m_wrap->rtp()))
return; return;
XDebug(DebugAll,"YRTPAudioConsumer writing %d bytes, delta=%lu ts=%d [%p]", XDebug(&splugin,DebugAll,"YRTPAudioConsumer writing %d bytes, delta=%lu ts=%d [%p]",
data.length(),timeDelta,m_timestamp,this); data.length(),timeDelta,m_timestamp,this);
unsigned int buf = m_wrap->bufSize(); unsigned int buf = m_wrap->bufSize();
const char* ptr = (const char*)data.data(); const char* ptr = (const char*)data.data();
@ -522,9 +523,9 @@ bool AttachHandler::received(Message &msg)
CallEndpoint *ch = static_cast<CallEndpoint*>(msg.userData()); CallEndpoint *ch = static_cast<CallEndpoint*>(msg.userData());
if (!ch) { if (!ch) {
if (!src.null()) if (!src.null())
Debug(DebugWarn,"RTP source '%s' attach request with no call channel!",src.c_str()); Debug(&splugin,DebugWarn,"RTP source '%s' attach request with no call channel!",src.c_str());
if (!cons.null()) if (!cons.null())
Debug(DebugWarn,"RTP consumer '%s' attach request with no call channel!",cons.c_str()); Debug(&splugin,DebugWarn,"RTP consumer '%s' attach request with no call channel!",cons.c_str());
return false; return false;
} }
@ -564,7 +565,7 @@ bool AttachHandler::received(Message &msg)
bool RtpHandler::received(Message &msg) bool RtpHandler::received(Message &msg)
{ {
Debug(DebugAll,"RTP message received"); Debug(&splugin,DebugAll,"RTP message received");
String dir(msg.getValue("direction")); String dir(msg.getValue("direction"));
RTPSession::Direction direction = RTPSession::SendRecv; RTPSession::Direction direction = RTPSession::SendRecv;
bool d_recv = false; bool d_recv = false;
@ -588,9 +589,9 @@ bool RtpHandler::received(Message &msg)
CallEndpoint *ch = static_cast<CallEndpoint*>(msg.userData()); CallEndpoint *ch = static_cast<CallEndpoint*>(msg.userData());
if (!ch) { if (!ch) {
if (d_recv) if (d_recv)
Debug(DebugWarn,"RTP recv request with no call channel!"); Debug(&splugin,DebugWarn,"RTP recv request with no call channel!");
if (d_send) if (d_send)
Debug(DebugWarn,"RTP send request with no call channel!"); Debug(&splugin,DebugWarn,"RTP send request with no call channel!");
return false; return false;
} }
@ -599,18 +600,18 @@ bool RtpHandler::received(Message &msg)
YRTPWrapper *w = YRTPWrapper::find(ch); YRTPWrapper *w = YRTPWrapper::find(ch);
if (w) if (w)
Debug(DebugAll,"YRTPWrapper %p found by CallEndpoint",w); Debug(&splugin,DebugAll,"YRTPWrapper %p found by CallEndpoint",w);
if (!w) { if (!w) {
w = YRTPWrapper::find(msg.getValue("rtpid")); w = YRTPWrapper::find(msg.getValue("rtpid"));
if (w) if (w)
Debug(DebugAll,"YRTPWrapper %p found by ID",w); Debug(&splugin,DebugAll,"YRTPWrapper %p found by ID",w);
} }
if (!w) { if (!w) {
String lip(msg.getValue("localip")); String lip(msg.getValue("localip"));
if (lip.null()) if (lip.null())
YRTPWrapper::guessLocal(rip,lip); YRTPWrapper::guessLocal(rip,lip);
if (lip.null()) { if (lip.null()) {
Debug(DebugWarn,"RTP request with no local address!"); Debug(&splugin,DebugWarn,"RTP request with no local address!");
return false; return false;
} }
msg.setParam("localip",lip); msg.setParam("localip",lip);
@ -660,7 +661,7 @@ bool DTMFHandler::received(Message &msg)
return false; return false;
YRTPWrapper* wrap = YRTPWrapper::find(targetid); YRTPWrapper* wrap = YRTPWrapper::find(targetid);
if (wrap && wrap->rtp()) { if (wrap && wrap->rtp()) {
Debug(DebugInfo,"RTP DTMF '%s' targetid '%s'",text.c_str(),targetid.c_str()); Debug(&splugin,DebugInfo,"RTP DTMF '%s' targetid '%s'",text.c_str(),targetid.c_str());
int duration = msg.getIntValue("duration"); int duration = msg.getIntValue("duration");
for (unsigned int i=0;i<text.length();i++) for (unsigned int i=0;i<text.length();i++)
wrap->sendDTMF(text.at(i),duration); wrap->sendDTMF(text.at(i),duration);
@ -670,7 +671,7 @@ bool DTMFHandler::received(Message &msg)
} }
YRTPPlugin::YRTPPlugin() YRTPPlugin::YRTPPlugin()
: m_first(true) : Module("yrtp","misc"), m_first(true)
{ {
Output("Loaded module YRTP"); Output("Loaded module YRTP");
} }
@ -681,11 +682,17 @@ YRTPPlugin::~YRTPPlugin()
s_calls.clear(); s_calls.clear();
} }
void YRTPPlugin::statusParams(String& str)
{
str.append("chans=",",") << s_calls.count();
}
void YRTPPlugin::initialize() void YRTPPlugin::initialize()
{ {
Output("Initializing module YRTP"); Output("Initializing module YRTP");
s_cfg = Engine::configFile("yrtpchan"); s_cfg = Engine::configFile("yrtpchan");
s_cfg.load(); s_cfg.load();
setup();
if (m_first) { if (m_first) {
m_first = false; m_first = false;
Engine::install(new AttachHandler); Engine::install(new AttachHandler);

View File

@ -211,9 +211,12 @@ public:
* @param level The initial local debug level * @param level The initial local debug level
*/ */
inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true) inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
: m_level(DebugFail), m_enabled(enabled), m_chain(0) : m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
{ debugLevel(level); } { debugLevel(level); }
inline ~DebugEnabler()
{ m_name = 0; m_chain = 0; }
/** /**
* Retrive the current local debug level * Retrive the current local debug level
* @return The current local debug level * @return The current local debug level
@ -242,6 +245,13 @@ public:
inline void debugEnabled(bool enable) inline void debugEnabled(bool enable)
{ m_enabled = enable; m_chain = 0; } { m_enabled = enable; m_chain = 0; }
/**
* Get the current debug name
* @return Name of the debug activation if set or NULL
*/
inline const char* debugName() const
{ return m_name; }
/** /**
* Check if debugging output should be generated * Check if debugging output should be generated
* @param level The debug level we are testing * @param level The debug level we are testing
@ -249,6 +259,13 @@ public:
*/ */
bool debugAt(int level) const; bool debugAt(int level) const;
/**
* Check if this enabler is chained to another one
* @return True if local debugging is chained to other enabler
*/
inline bool debugChained() const
{ return m_chain != 0; }
/** /**
* Chain this debug holder to a parent or detach from existing one * Chain this debug holder to a parent or detach from existing one
* @param chain Pointer to parent debug level, NULL to detach * @param chain Pointer to parent debug level, NULL to detach
@ -262,10 +279,19 @@ public:
*/ */
void debugCopy(const DebugEnabler* original = 0); void debugCopy(const DebugEnabler* original = 0);
protected:
/**
* Set the current debug name
* @param name Static debug name or NULL
*/
inline void debugName(const char* name)
{ m_name = name; }
private: private:
int m_level; int m_level;
bool m_enabled; bool m_enabled;
const DebugEnabler* m_chain; const DebugEnabler* m_chain;
const char* m_name;
}; };
#if 0 #if 0
@ -436,13 +462,13 @@ public:
* Set the output callback * Set the output callback
* @param outFunc Pointer to the output function, NULL to use stderr * @param outFunc Pointer to the output function, NULL to use stderr
*/ */
static void setOutput(void (*outFunc)(const char*) = 0); static void setOutput(void (*outFunc)(const char*,int) = 0);
/** /**
* Set the interactive output callback * Set the interactive output callback
* @param outFunc Pointer to the output function, NULL to disable * @param outFunc Pointer to the output function, NULL to disable
*/ */
static void setIntOut(void (*outFunc)(const char*) = 0); static void setIntOut(void (*outFunc)(const char*,int) = 0);
/** /**
* Enable or disable the debug output * Enable or disable the debug output

View File

@ -992,6 +992,11 @@ protected:
*/ */
Module(const char* name, const char* type = 0); Module(const char* name, const char* type = 0);
/**
* Destructor
*/
virtual ~Module();
/** /**
* This method is called to initialize the loaded module * This method is called to initialize the loaded module
*/ */