More debugging support, cleaned up H.323 code.

git-svn-id: http://yate.null.ro/svn/yate/trunk@411 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2005-06-20 20:51:17 +00:00
parent a9b5d2c4e2
commit 9f66248239
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=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 = false

View File

@ -9,3 +9,6 @@
; header: string: Header string to display on connect
;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());
if (m_driver) {
debugName(m_driver->debugName());
debugChain(m_driver);
m_driver->lock();
if (m_id.null())
@ -203,7 +204,7 @@ void Channel::init()
m_driver->changed();
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()
@ -341,7 +342,7 @@ void Channel::callAccept(Message& msg)
m_billid = msg.getValue("billid");
m_targetid = msg.getValue("targetid");
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);
}
}
@ -361,14 +362,13 @@ bool Channel::setDebug(Message& msg)
}
else if (str == "reset")
debugChain(m_driver);
else {
bool dbg = debugEnabled();
str >> dbg;
debugEnabled(dbg);
}
else if (str == "engine")
debugCopy();
else if (str.isBoolean())
debugEnabled(str.toBoolean(debugEnabled()));
msg.retValue() << "Channel " << m_id
<< " debug " << (debugEnabled() ? "on" : "off")
<< " level " << debugLevel() << "\n";
<< " level " << debugLevel() << (debugChained() ? " chained" : "") << "\n";
return true;
}
@ -405,6 +405,12 @@ Module::Module(const char* name, const char* type)
: Plugin(name), Mutex(true),
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
@ -445,7 +451,7 @@ void Module::initialize()
void Module::setup()
{
Debug(DebugAll,"Module::setup()");
Debug(this,DebugAll,"Module::setup()");
if (m_init)
return;
m_init = true;
@ -522,7 +528,7 @@ bool Module::received(Message &msg, int id)
else if (id == Level)
return setDebug(msg,dest);
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());
return false;
@ -579,7 +585,7 @@ void Driver::initialize()
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();
if (m_init)
return;
@ -680,7 +686,7 @@ bool Driver::received(Message &msg, int id)
Lock lock(this);
Channel* chan = find(dest);
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;
}
@ -718,7 +724,7 @@ void Driver::dropAll(Message &msg)
while (l) {
Channel* c = static_cast<Channel*>(l->get());
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);
if (l->get() != c)
break;
@ -828,7 +834,7 @@ void Router::run()
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();
m_driver->lock();
@ -841,7 +847,7 @@ bool Router::route()
m_driver->unlock();
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;
}

View File

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

View File

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

View File

@ -226,6 +226,24 @@ public:
class YateH323EndPoint;
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
{
PCLASSINFO(YateGatekeeperCall, H323GatekeeperCall);
@ -266,7 +284,7 @@ class YateH323AudioSource : public DataSource, public PIndirectChannel
public:
YateH323AudioSource()
: m_exit(false)
{ Debug(DebugAll,"h.323 source [%p] created",this); }
{ Debug(&hplugin,DebugAll,"h.323 source [%p] created",this); }
~YateH323AudioSource();
virtual BOOL Close();
virtual BOOL IsOpen() const;
@ -284,7 +302,7 @@ class YateH323AudioConsumer : public DataConsumer, public PIndirectChannel
public:
YateH323AudioConsumer()
: m_exit(false)
{ Debug(DebugAll,"h.323 consumer [%p] created",this); }
{ Debug(&hplugin,DebugAll,"h.323 consumer [%p] created",this); }
~YateH323AudioConsumer();
virtual BOOL Close();
virtual BOOL IsOpen() const;
@ -335,19 +353,21 @@ public:
#endif
virtual BOOL OnStartLogicalChannel(H323Channel& channel);
virtual BOOL OnCreateLogicalChannel(const H323Capability& capability, H323Channel::Directions dir, unsigned& errorCode ) ;
BOOL StartExternalRTP(const char* remoteIP, WORD remotePort, H323Channel::Directions dir, YateH323_ExternalRTPChannel* chan);
void OnStoppedExternal(H323Channel::Directions dir);
void SetRemoteAddress(const char* remoteIP, WORD remotePort);
BOOL startExternalRTP(const char* remoteIP, WORD remotePort, H323Channel::Directions dir, YateH323_ExternalRTPChannel* chan);
void stoppedExternal(H323Channel::Directions dir);
void setRemoteAddress(const char* remoteIP, WORD remotePort);
void cleanups();
bool sendTone(Message& msg, const char* tone);
void setCallerID(const char* number, const char* name);
void rtpExecuted(Message& msg);
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);
inline bool HasRemoteAddress() const
{ return s_passtrough && (m_remotePort > 0); }
inline bool hasRemoteAddress() const
{ return m_passtrough && (m_remotePort > 0); }
private:
YateH323Chan* m_chan;
bool m_externalRtp;
bool m_nativeRtp;
bool m_passtrough;
String m_formats;
@ -405,29 +425,11 @@ private:
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)
: H323GatekeeperServer(ep),
endpoint(ep)
{
Debug(DebugAll,"YateGatekeeperServer::YateGatekeeperServer() [%p]",this);
Debug(&hplugin,DebugAll,"YateGatekeeperServer::YateGatekeeperServer() [%p]",this);
}
BOOL YateGatekeeperServer::Init()
@ -446,7 +448,7 @@ BOOL YateGatekeeperServer::Init()
YateH323EndPoint::YateH323EndPoint(const char* name)
: String(name), gkServer(0)
{
Debug(DebugAll,"YateH323EndPoint::YateH323EndPoint(\"%s\") [%p]",name,this);
Debug(&hplugin,DebugAll,"YateH323EndPoint::YateH323EndPoint(\"%s\") [%p]",name,this);
String sect("ep");
if (name)
sect << " " << name;
@ -457,7 +459,7 @@ YateH323EndPoint::YateH323EndPoint(const char* name)
YateH323EndPoint::~YateH323EndPoint()
{
Debug(DebugAll,"YateH323EndPoint::~YateH323EndPoint() [%p]",this);
Debug(&hplugin,DebugAll,"YateH323EndPoint::~YateH323EndPoint() [%p]",this);
hplugin.m_endpoints.remove(this,false);
RemoveListener(0);
ClearAllCalls(H323Connection::EndedByTemporaryFailure, true);
@ -563,10 +565,10 @@ bool YateH323EndPoint::Init(void)
num = GetCapabilities().GetSize() - init;
}
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
// 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));
DisableFastStart(!s_cfg.getBoolValue(sect,"faststart",false));
DisableH245Tunneling(!s_cfg.getBoolValue(sect,"h245tunneling",false));
DisableH245inSetup(!s_cfg.getBoolValue(sect,"h245insetup",false));
SetSilenceDetectionMode(static_cast<H323AudioCodec::SilenceDetectionMode>
(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");
if (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* a = s_cfg.getValue(sect,"gkname");
@ -601,7 +604,7 @@ bool YateH323EndPoint::Init(void)
PString gkName = d;
H323TransportUDP* rasChannel = new H323TransportUDP(*this);
if (SetGatekeeper(gkName, rasChannel))
Debug(DebugInfo,"Connect to gatekeeper ip = %s",d);
Debug(&hplugin,DebugInfo,"Connect to gatekeeper ip = %s",d);
else {
Debug(DebugGoOn,"Unable to connect to gatekeeper ip = %s",d);
if (listener)
@ -611,7 +614,7 @@ bool YateH323EndPoint::Init(void)
else if (a) {
PString gkIdentifier = a;
if (LocateGatekeeper(gkIdentifier))
Debug(DebugInfo,"Connect to gatekeeper name = %s",a);
Debug(&hplugin,DebugInfo,"Connect to gatekeeper name = %s",a);
else {
Debug(DebugGoOn,"Unable to connect to gatekeeper name = %s",a);
if (listener)
@ -620,7 +623,7 @@ bool YateH323EndPoint::Init(void)
}
else {
if (DiscoverGatekeeper(new H323TransportUDP(*this)))
Debug(DebugInfo,"Find a gatekeeper");
Debug(&hplugin,DebugInfo,"Find a gatekeeper");
else {
Debug(DebugGoOn,"Unable to connect to any gatekeeper");
if (listener)
@ -642,16 +645,20 @@ bool YateH323EndPoint::Init(void)
YateH323Connection::YateH323Connection(YateH323EndPoint& endpoint,
H323Transport* transport, unsigned callReference, void* userdata)
: 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);
// outgoing calls get the "call.execute" message as user data
Message* msg = static_cast<Message*>(userdata);
m_chan = new YateH323Chan(this,userdata,
((transport && !userdata) ? (const char*)transport->GetRemoteAddress() : 0));
if (!msg)
if (!msg) {
m_passtrough = s_passtrough;
return;
}
setCallerID(msg->getValue("caller"),msg->getValue("callername"));
rtpForward(*msg,s_passtrough);
@ -667,7 +674,7 @@ YateH323Connection::YateH323Connection(YateH323EndPoint& endpoint,
YateH323Connection::~YateH323Connection()
{
Debug(DebugAll,"YateH323Connection::~YateH323Connection() [%p]",this);
Debug(&hplugin,DebugAll,"YateH323Connection::~YateH323Connection() [%p]",this);
YateH323Chan* tmp = m_chan;
m_chan = 0;
if (tmp) {
@ -687,7 +694,7 @@ void YateH323Connection::cleanups()
H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PString &caller,
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);
if (!m_chan)
return H323Connection::AnswerCallDenied;
@ -703,32 +710,31 @@ H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PStrin
m->setParam("callername",caller);
s = GetRemotePartyNumber();
Debug(DebugInfo,"GetRemotePartyNumber()='%s'",s);
Debug(m_chan,DebugInfo,"GetRemotePartyNumber()='%s'",s);
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_ArrayOf_AliasAddress &adr = setup.m_destinationAddress;
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;
if (adr.GetSize() > 0)
called = (const char *)H323GetAliasAddressString(adr[0]);
if (called.null())
called = s_cfg.getValue("incoming","called");
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);
}
else
Debug(DebugWarn,"No called number present!");
Debug(m_chan,DebugMild,"No called number present!");
#if 0
s = GetRemotePartyAddress();
Debug(DebugInfo,"GetRemotePartyAddress()='%s'",s);
Debug(m_chan,DebugInfo,"GetRemotePartyAddress()='%s'",s);
if (s)
m->setParam("calledname",s);
#endif
if (s_passtrough && m_remotePort) {
m_passtrough = true;
if (hasRemoteAddress()) {
m->addParam("rtp_forward","possible");
m->addParam("rtp_addr",m_remoteAddr);
m->addParam("rtp_port",String(m_remotePort));
@ -737,25 +743,25 @@ H323Connection::AnswerCallResponse YateH323Connection::OnAnswerCall(const PStrin
if (m_chan->startRouter(m))
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;
}
void YateH323Connection::rtpExecuted(Message& msg)
{
Debug(DebugAll,"YateH323Connection::rtpExecuted(%p) [%p]",
Debug(m_chan,DebugAll,"YateH323Connection::rtpExecuted(%p) [%p]",
&msg,this);
if (!m_passtrough)
return;
String tmp = msg.getValue("rtp_forward");
m_passtrough = (tmp == "accepted");
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)
{
Debug(DebugAll,"YateH323Connection::rtpForward(%p,%d) [%p]",
Debug(m_chan,DebugAll,"YateH323Connection::rtpForward(%p,%d) [%p]",
&msg,init,this);
String tmp = msg.getValue("rtp_forward");
if (!((init || m_passtrough) && tmp))
@ -770,16 +776,41 @@ void YateH323Connection::rtpForward(Message& msg, bool init)
m_rtpPort = port;
m_formats = msg.getValue("formats");
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());
}
else
else {
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()
{
Debug(DebugInfo,"YateH323Connection::OnEstablished() [%p]",this);
Debug(m_chan,DebugInfo,"YateH323Connection::OnEstablished() [%p]",this);
if (!m_chan)
return;
if (HadAnsweredCall()) {
@ -796,7 +827,7 @@ void YateH323Connection::OnEstablished()
m->addParam("formats",m_remoteFormats);
}
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);
}
@ -805,7 +836,7 @@ void YateH323Connection::OnCleared()
{
int reason = GetCallEndReason();
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);
if (m_chan)
m_chan->disconnect(rtext);
@ -813,12 +844,12 @@ void YateH323Connection::OnCleared()
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)
return FALSE;
m_chan->status("ringing");
Message *m = m_chan->message("call.ringing",false,true);
if (m_passtrough && m_remotePort) {
if (hasRemoteAddress()) {
m->addParam("rtp_forward","yes");
m->addParam("rtp_addr",m_remoteAddr);
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)
{
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)
return;
char buf[2];
@ -844,7 +875,7 @@ void YateH323Connection::OnUserInputTone(char tone, unsigned duration, unsigned
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)
return;
String text((const char *)value);
@ -857,9 +888,9 @@ void YateH323Connection::OnUserInputString(const PString &value)
BOOL YateH323Connection::OpenAudioChannel(BOOL isEncoding, unsigned bufferSize,
H323AudioCodec &codec)
{
Debug(DebugInfo,"YateH323Connection::OpenAudioChannel [%p]",this);
Debug(m_chan,DebugInfo,"YateH323Connection::OpenAudioChannel [%p]",this);
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 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)
#endif
{
Debug(DebugAll,"H323Connection::CreateRealTimeLogicalChannel [%p]",this);
if (s_externalRtp || s_passtrough) {
Debug(m_chan,DebugAll,"H323Connection::CreateRealTimeLogicalChannel%s%s [%p]",
m_externalRtp ? " external" : "",m_passtrough ? " passtrough" : "",this);
if (m_externalRtp || m_passtrough) {
const char* sdir = lookup(dir,dict_h323_dir);
const char *format = 0;
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);
// disallow codecs not supported by remote receiver
if (s_passtrough && !(m_formats.null() || (m_formats.find(format) >= 0))) {
Debug(DebugWarn,"Refusing '%s' not in remote '%s'",format,m_formats.c_str());
if (m_passtrough && !(m_formats.null() || (m_formats.find(format) >= 0))) {
Debug(m_chan,DebugMild,"Refusing to create '%s' not in remote '%s'",format,m_formats.c_str());
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 (m_remoteFormats)
m_remoteFormats << ",";
@ -894,9 +926,9 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
}
PIPSocket::Address 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;
if (s_externalRtp) {
if (!m_passtrough) {
Message m("chan.rtp");
m.addParam("localip",externalIpAddress.AsString());
m.userData(m_chan);
@ -907,7 +939,7 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
externalPort = m.getIntValue("localport");
}
}
if (externalPort || s_passtrough) {
if (externalPort || m_passtrough) {
m_nativeRtp = false;
if (!externalPort) {
externalPort = m_rtpPort;
@ -915,7 +947,7 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
}
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;
@ -928,7 +960,8 @@ H323Channel* YateH323Connection::CreateRealTimeLogicalChannel(const H323Capabili
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();
if (m_formats.null())
return;
@ -940,7 +973,7 @@ void YateH323Connection::OnSetLocalCapabilities()
decodeCapability(localCapabilities[i],&format,0,&fname);
if (format) {
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());
localCapabilities.Remove(fname.c_str());
i--;
@ -955,13 +988,13 @@ void YateH323Connection::OnSetLocalCapabilities()
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;
}
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);
}
@ -983,7 +1016,7 @@ BOOL YateH323Connection::decodeCapability(const H323Capability& capability, cons
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 (capabName)
*capabName = fname;
@ -996,37 +1029,36 @@ BOOL YateH323Connection::decodeCapability(const H323Capability& capability, cons
return FALSE;
}
void YateH323Connection::SetRemoteAddress(const char* remoteIP, WORD remotePort)
void YateH323Connection::setRemoteAddress(const char* remoteIP, WORD 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_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);
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);
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());
WORD dataPort = m_rtpPort;
chan->SetExternalAddress(H323TransportAddress(ip, dataPort), H323TransportAddress(ip, dataPort+1));
OnStoppedExternal(dir);
stoppedExternal(dir);
return TRUE;
}
if (!s_externalRtp)
if (!m_externalRtp)
return FALSE;
Message m("chan.rtp");
m.userData(m_chan);
if (m_rtpid)
m.setParam("rtpid",m_rtpid);
// Debug(DebugAll,"userData=%p this=%p",m.userData(),this);
if (sdir)
m.addParam("direction",sdir);
m.addParam("remoteip",remoteIP);
@ -1046,9 +1078,9 @@ BOOL YateH323Connection::StartExternalRTP(const char* remoteIP, WORD remotePort,
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)
return;
switch (dir) {
@ -1087,62 +1119,62 @@ YateH323_ExternalRTPChannel::YateH323_ExternalRTPChannel(
: H323_ExternalRTPChannel(connection, capability, direction, sessionID, ip, dataPort),
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);
SetExternalAddress(H323TransportAddress(ip, dataPort), H323TransportAddress(ip, dataPort+1));
}
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);
if (isRunning) {
isRunning = FALSE;
if (m_conn)
m_conn->OnStoppedExternal(GetDirection());
m_conn->stoppedExternal(GetDirection());
}
}
BOOL YateH323_ExternalRTPChannel::Start()
{
Debug(DebugAll,"YateH323_ExternalRTPChannel::Start() [%p]",this);
Debug(&hplugin,DebugAll,"YateH323_ExternalRTPChannel::Start() [%p]",this);
if (!m_conn)
return FALSE;
PIPSocket::Address remoteIpAddress;
WORD 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(
const H245_H2250LogicalChannelParameters& param,
unsigned& errorCode)
{
Debug(DebugInfo,"OnReceivedPDU [%p]",this);
Debug(&hplugin,DebugInfo,"OnReceivedPDU [%p]",this);
if (!H323_ExternalRTPChannel::OnReceivedPDU(param,errorCode))
return FALSE;
if (!m_conn || m_conn->HasRemoteAddress())
if (!m_conn || m_conn->hasRemoteAddress())
return TRUE;
PIPSocket::Address remoteIpAddress;
WORD remotePort;
GetRemoteAddress(remoteIpAddress,remotePort);
Debug(DebugInfo,"external rtp ip address %s:%u",(const char *)remoteIpAddress.AsString(),remotePort);
m_conn->SetRemoteAddress((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);
return TRUE;
}
BOOL YateH323_ExternalRTPChannel::OnSendingPDU(H245_H2250LogicalChannelParameters& param)
{
Debug(DebugInfo,"OnSendingPDU [%p]",this);
Debug(&hplugin,DebugInfo,"OnSendingPDU [%p]",this);
return H323_ExternalRTPChannel::OnSendingPDU(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);
}
@ -1399,7 +1431,7 @@ void YateH323Connection::setCallerID(const char* number, const char* name)
display << number << " [" << name << "]";
else
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);
localAliasNames.AppendString(display.c_str());
}
@ -1411,7 +1443,7 @@ void YateH323Connection::setCallerID(const char* number, const char* name)
display = number;
else
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());
}
}
@ -1419,7 +1451,7 @@ void YateH323Connection::setCallerID(const char* number, const char* name)
YateH323Chan::YateH323Chan(YateH323Connection* conn,bool outgoing,const char* addr)
: 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);
m_address = addr;
Engine::enqueue(message("chan.startup"));
@ -1427,7 +1459,7 @@ YateH323Chan::YateH323Chan(YateH323Connection* conn,bool outgoing,const char* ad
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);
Message *m = message("chan.hangup");
drop();
@ -1515,7 +1547,7 @@ void YateH323Chan::callAccept(Message& msg)
Channel::callAccept(msg);
if (m_conn) {
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;
if (msg.getParam("rtp_forward"))
m_conn->rtpForward(msg);
// FIXME: with or without media?
m_conn->AnsweringCall(H323Connection::AnswerCallAlertWithMedia);
m_conn->answerCall(H323Connection::AnswerCallPending);
return true;
}
@ -1541,7 +1572,7 @@ bool YateH323Chan::msgAnswered(Message& msg)
if (!m_conn)
return false;
m_conn->rtpForward(msg);
m_conn->AnsweringCall(H323Connection::AnswerCallNow);
m_conn->answerCall(H323Connection::AnswerCallNow);
return true;
}
@ -1553,7 +1584,7 @@ bool YateH323Chan::msgTone(Message& msg, const char* tone)
bool YateH323Chan::msgText(Message& msg, const char* text)
{
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);
return true;
}
@ -1600,10 +1631,10 @@ bool H323Driver::msgExecute(Message& msg, String& dest)
if (dest.null())
return false;
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;
}
Debug(DebugInfo,"Found call to H.323 target='%s'",
Debug(this,DebugInfo,"Found call to H.323 target='%s'",
dest.c_str());
PString p;
YateH323EndPoint* ep = hplugin.findEndpoint(msg.getValue("line"));

View File

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

View File

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

View File

@ -157,12 +157,13 @@ public:
virtual bool received(Message &msg);
};
class YRTPPlugin : public Plugin
class YRTPPlugin : public Module
{
public:
YRTPPlugin();
virtual ~YRTPPlugin();
virtual void initialize();
virtual void statusParams(String& str);
private:
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_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);
m_id = "yrtp/";
m_id << (unsigned int)::random();
@ -187,7 +188,7 @@ YRTPWrapper::YRTPWrapper(const char* localip, CallEndpoint* conn, RTPSession::Di
YRTPWrapper::~YRTPWrapper()
{
Debug(DebugAll,"YRTPWrapper::~YRTPWrapper() %s [%p]",
Debug(&splugin,DebugAll,"YRTPWrapper::~YRTPWrapper() %s [%p]",
lookup(m_dir,dict_yrtp_dir),this);
s_mutex.lock();
s_calls.remove(this,false);
@ -198,12 +199,12 @@ YRTPWrapper::~YRTPWrapper()
delete tmp;
}
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 = 0;
}
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 = 0;
}
@ -236,7 +237,7 @@ YRTPWrapper* YRTPWrapper::find(const String& id)
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->initTransport();
int minport = s_cfg.getIntValue("rtp","minport",16384);
@ -253,7 +254,7 @@ void YRTPWrapper::setupRTP(const char* localip)
}
SocketAddr addr(AF_INET);
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;
}
for (; attempt; attempt--) {
@ -261,50 +262,50 @@ void YRTPWrapper::setupRTP(const char* localip)
addr.port(lport);
if (m_rtp->localAddr(addr)) {
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;
}
}
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)
{
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) {
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;
}
if (m_bufsize) {
Debug(DebugMild,"YRTPWrapper [%p] attempted to restart RTP!",this);
Debug(&splugin,DebugMild,"YRTPWrapper [%p] attempted to restart RTP!",this);
return true;
}
if (!format)
format = lookup(payload, dict_payloads);
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;
}
if (payload == -1)
payload = lookup(format, dict_payloads, -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;
}
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;
}
Debug(DebugAll,"RTP format '%s' payload %d",format,payload);
Debug(&splugin,DebugAll,"RTP format '%s' payload %d",format,payload);
SocketAddr addr(AF_INET);
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;
}
// Change format of source and/or consumer,
@ -346,7 +347,7 @@ bool YRTPWrapper::sendDTMF(char dtmf, int duration)
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())
return;
char buf[2];
@ -364,16 +365,16 @@ void YRTPWrapper::guessLocal(const char* remoteip, String& localip)
localip.clear();
SocketAddr r(AF_INET);
if (!r.host(remoteip)) {
Debug(DebugInfo,"Guess - Could not parse remote '%s'",remoteip);
Debug(&splugin,DebugInfo,"Guess - Could not parse remote '%s'",remoteip);
return;
}
SocketAddr l;
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;
}
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)
@ -407,7 +408,7 @@ bool YRTPSession::rtpRecvEvent(int event, char key, int duration,
void YRTPSession::rtpNewPayload(int payload, unsigned int timestamp)
{
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);
}
}
@ -415,7 +416,7 @@ void YRTPSession::rtpNewPayload(int payload, unsigned int timestamp)
YRTPAudioSource::YRTPAudioSource(YRTPWrapper* wrap)
: m_wrap(wrap)
{
Debug(DebugAll,"YRTPAudioSource::YRTPAudioSource(%p) [%p]",wrap,this);
Debug(&splugin,DebugAll,"YRTPAudioSource::YRTPAudioSource(%p) [%p]",wrap,this);
m_format.clear();
if (m_wrap) {
m_wrap->ref();
@ -425,7 +426,7 @@ YRTPAudioSource::YRTPAudioSource(YRTPWrapper* wrap)
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();
if (m_wrap) {
YRTPWrapper* tmp = m_wrap;
@ -440,7 +441,7 @@ YRTPAudioSource::~YRTPAudioSource()
YRTPAudioConsumer::YRTPAudioConsumer(YRTPWrapper *wrap)
: 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();
if (m_wrap) {
m_wrap->ref();
@ -450,7 +451,7 @@ YRTPAudioConsumer::YRTPAudioConsumer(YRTPWrapper *wrap)
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) {
YRTPWrapper* tmp = m_wrap;
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()))
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);
unsigned int buf = m_wrap->bufSize();
const char* ptr = (const char*)data.data();
@ -522,9 +523,9 @@ bool AttachHandler::received(Message &msg)
CallEndpoint *ch = static_cast<CallEndpoint*>(msg.userData());
if (!ch) {
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())
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;
}
@ -564,7 +565,7 @@ bool AttachHandler::received(Message &msg)
bool RtpHandler::received(Message &msg)
{
Debug(DebugAll,"RTP message received");
Debug(&splugin,DebugAll,"RTP message received");
String dir(msg.getValue("direction"));
RTPSession::Direction direction = RTPSession::SendRecv;
bool d_recv = false;
@ -588,9 +589,9 @@ bool RtpHandler::received(Message &msg)
CallEndpoint *ch = static_cast<CallEndpoint*>(msg.userData());
if (!ch) {
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)
Debug(DebugWarn,"RTP send request with no call channel!");
Debug(&splugin,DebugWarn,"RTP send request with no call channel!");
return false;
}
@ -599,18 +600,18 @@ bool RtpHandler::received(Message &msg)
YRTPWrapper *w = YRTPWrapper::find(ch);
if (w)
Debug(DebugAll,"YRTPWrapper %p found by CallEndpoint",w);
Debug(&splugin,DebugAll,"YRTPWrapper %p found by CallEndpoint",w);
if (!w) {
w = YRTPWrapper::find(msg.getValue("rtpid"));
if (w)
Debug(DebugAll,"YRTPWrapper %p found by ID",w);
Debug(&splugin,DebugAll,"YRTPWrapper %p found by ID",w);
}
if (!w) {
String lip(msg.getValue("localip"));
if (lip.null())
YRTPWrapper::guessLocal(rip,lip);
if (lip.null()) {
Debug(DebugWarn,"RTP request with no local address!");
Debug(&splugin,DebugWarn,"RTP request with no local address!");
return false;
}
msg.setParam("localip",lip);
@ -660,7 +661,7 @@ bool DTMFHandler::received(Message &msg)
return false;
YRTPWrapper* wrap = YRTPWrapper::find(targetid);
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");
for (unsigned int i=0;i<text.length();i++)
wrap->sendDTMF(text.at(i),duration);
@ -670,7 +671,7 @@ bool DTMFHandler::received(Message &msg)
}
YRTPPlugin::YRTPPlugin()
: m_first(true)
: Module("yrtp","misc"), m_first(true)
{
Output("Loaded module YRTP");
}
@ -681,11 +682,17 @@ YRTPPlugin::~YRTPPlugin()
s_calls.clear();
}
void YRTPPlugin::statusParams(String& str)
{
str.append("chans=",",") << s_calls.count();
}
void YRTPPlugin::initialize()
{
Output("Initializing module YRTP");
s_cfg = Engine::configFile("yrtpchan");
s_cfg.load();
setup();
if (m_first) {
m_first = false;
Engine::install(new AttachHandler);

View File

@ -211,9 +211,12 @@ public:
* @param level The initial local debug level
*/
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); }
inline ~DebugEnabler()
{ m_name = 0; m_chain = 0; }
/**
* Retrive the current local debug level
* @return The current local debug level
@ -242,6 +245,13 @@ public:
inline void debugEnabled(bool enable)
{ 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
* @param level The debug level we are testing
@ -249,6 +259,13 @@ public:
*/
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
* @param chain Pointer to parent debug level, NULL to detach
@ -262,10 +279,19 @@ public:
*/
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:
int m_level;
bool m_enabled;
const DebugEnabler* m_chain;
const char* m_name;
};
#if 0
@ -436,13 +462,13 @@ public:
* Set the output callback
* @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
* @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

View File

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