aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xchannels/chan_h323.c180
-rwxr-xr-xchannels/h323/Makefile25
-rwxr-xr-xchannels/h323/ast_h323.cpp231
-rwxr-xr-xchannels/h323/ast_h323.h41
-rwxr-xr-xchannels/h323/chan_h323.h32
5 files changed, 155 insertions, 354 deletions
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
index 77b24d05b..d0d9d4cbb 100755
--- a/channels/chan_h323.c
+++ b/channels/chan_h323.c
@@ -72,10 +72,10 @@ extern "C" {
#include "h323/chan_h323.h"
send_digit_cb on_send_digit;
-on_connection_cb on_create_connection;
+on_rtp_cb on_external_rtp_create;
+start_rtp_cb on_start_rtp_channel;
setup_incoming_cb on_incoming_call;
setup_outbound_cb on_outgoing_call;
-start_logchan_cb on_start_logical_channel;
chan_ringing_cb on_chan_ringing;
con_established_cb on_connection_established;
clear_con_cb on_connection_cleared;
@@ -426,7 +426,6 @@ static int oh323_call(struct ast_channel *c, char *dest, int timeout)
int res = 0;
struct oh323_pvt *pvt = (struct oh323_pvt *)c->pvt->pvt;
char called_addr[256];
- char *cid, *cidname, oldcid[256];
char iabuf[INET_ADDRSTRLEN];
if ((c->_state != AST_STATE_DOWN) && (c->_state != AST_STATE_RESERVED)) {
@@ -448,49 +447,6 @@ static int oh323_call(struct ast_channel *c, char *dest, int timeout)
/* indicate that this is an outgoing call */
pvt->outgoing = 1;
ast_log(LOG_DEBUG, "Outgoing call to %s:%d\n", called_addr, pvt->options.port);
-
- /* Copy callerid, if there is any */
- if (!ast_strlen_zero(c->callerid)) {
- memset(oldcid, 0, sizeof(oldcid));
- memcpy(oldcid, c->callerid, strlen(c->callerid));
- oldcid[sizeof(oldcid)-1] = '\0';
- ast_callerid_parse(oldcid, &cidname, &cid);
- if (!ast_strlen_zero(pvt->options.callerid)) {
- free(pvt->options.callerid);
- pvt->options.callerid = NULL;
- }
- if (!ast_strlen_zero(pvt->options.callername)) {
- free(pvt->options.callername);
- pvt->options.callername = NULL;
- }
- pvt->options.callerid = (char*)malloc(256);
- if (!pvt->options.callerid) {
- ast_log(LOG_ERROR, "Not enough memory to allocate callerid\n");
- return(-1);
- }
- memset(pvt->options.callerid, 0, 256);
- if ((!ast_strlen_zero(cid)) && (!ast_strlen_zero(cid))) {
- strncpy(pvt->options.callerid, cid, sizeof(pvt->options.callerid) - 1);
- }
- pvt->options.callername = (char*)malloc(256);
- if (!pvt->options.callername) {
- ast_log(LOG_ERROR, "Not enough memory.\n");
- return(-1);
- }
- memset(pvt->options.callername, 0, 256);
- if ((!ast_strlen_zero(cidname)) && (!ast_strlen_zero(cidname))) {
- strncpy(pvt->options.callername, cidname, sizeof(pvt->options.callername) - 1);
- }
- } else {
- if (!ast_strlen_zero(pvt->options.callerid)) {
- free(pvt->options.callerid);
- pvt->options.callerid = NULL;
- }
- if (!ast_strlen_zero(pvt->options.callername)) {
- free(pvt->options.callername);
- pvt->options.callername = NULL;
- }
- }
res = h323_make_call(called_addr, &(pvt->cd), pvt->options);
if (res) {
ast_log(LOG_NOTICE, "h323_make_call failed(%s)\n", c->name);
@@ -752,8 +708,6 @@ static struct ast_channel *oh323_new(struct oh323_pvt *pvt, int state, const cha
strncpy(ch->context, pvt->context, sizeof(ch->context) - 1);
strncpy(ch->exten, pvt->exten, sizeof(ch->exten) - 1);
ch->priority = 1;
- if (!ast_strlen_zero(pvt->callerid))
- ch->callerid = strdup(pvt->callerid);
if (!ast_strlen_zero(pvt->accountcode))
strncpy(ch->accountcode, pvt->accountcode, sizeof(ch->accountcode) - 1);
if (pvt->amaflags)
@@ -1071,51 +1025,91 @@ int send_digit(unsigned call_reference, char digit, const char *token)
}
/**
- * Call-back function that gets called when any H.323 connection is made
+ * Callback function used to inform the H.323 stack of the local rtp ip/port details
*
* Returns the local RTP information
*/
-struct rtp_info *create_connection(unsigned call_reference, const char * token)
+struct rtp_info *external_rtp_create(unsigned call_reference, const char * token)
{
struct oh323_pvt *pvt;
struct sockaddr_in us;
- struct sockaddr_in them;
struct rtp_info *info;
-
- /* XXX This is sooooo bugus. inet_ntoa is not reentrant
- but this function wants to return a static variable so
- the only way to do this will be to declare iabuf within
- the oh323_pvt structure XXX */
- static char iabuf[INET_ADDRSTRLEN];
-
- info = (struct rtp_info *) malloc(sizeof(struct rtp_info));
+ static char iabuf[INET_ADDRSTRLEN];
+ info = (struct rtp_info *)malloc(sizeof(struct rtp_info));
+ if (!info) {
+ ast_log(LOG_ERROR, "Unable to allocated info structure, this is very bad\n");
+ return NULL;
+ }
pvt = find_call(call_reference, token);
-
if (!pvt) {
- ast_log(LOG_ERROR, "Unable to allocate private structure, this is very bad.\n");
+ ast_log(LOG_ERROR, "Unable to find call %s(%d)\n", token, call_reference);
return NULL;
}
-
/* figure out our local RTP port and tell the H.323 stack about it*/
ast_rtp_get_us(pvt->rtp, &us);
- ast_rtp_get_peer(pvt->rtp, &them);
-
info->addr = ast_inet_ntoa(iabuf, sizeof(iabuf), us.sin_addr);
info->port = ntohs(us.sin_port);
-
return info;
}
/**
+ * Call-back function passing remote ip/port information from H.323 to asterisk
+ *
+ * Returns nothing
+ */
+void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int remotePort, const char *token)
+{
+ struct oh323_pvt *pvt = NULL;
+ struct sockaddr_in them;
+
+ /* Find the call or allocate a private structure if call not found */
+ pvt = find_call(call_reference, token);
+ if (!pvt) {
+ ast_log(LOG_ERROR, "Something is wrong: rtp\n");
+ return;
+ }
+ them.sin_family = AF_INET;
+ them.sin_addr.s_addr = inet_addr(remoteIp); // only works for IPv4
+ them.sin_port = htons(remotePort);
+ ast_rtp_set_peer(pvt->rtp, &them);
+ return;
+}
+
+/**
+ * Call-back function to signal asterisk that the channel has been answered
+ * Returns nothing
+ */
+void connection_made(unsigned call_reference, const char *token)
+{
+ struct ast_channel *c = NULL;
+ struct oh323_pvt *pvt = NULL;
+
+ pvt = find_call(call_reference, token);
+
+ if (!pvt) {
+ ast_log(LOG_ERROR, "Something is wrong: connection\n");
+ return;
+ }
+
+ if (!pvt->owner) {
+ ast_log(LOG_ERROR, "Channel has no owner\n");
+ return;
+ }
+ c = pvt->owner;
+
+ ast_setstate(c, AST_STATE_UP);
+ ast_queue_control(c, AST_CONTROL_ANSWER);
+ return;
+}
+
+/**
* Call-back function for incoming calls
*
* Returns 1 on success
*/
-
int setup_incoming_call(call_details_t cd)
{
-
struct oh323_pvt *pvt = NULL;
struct oh323_user *user = NULL;
struct oh323_alias *alias = NULL;
@@ -1269,56 +1263,6 @@ int setup_outgoing_call(call_details_t cd)
}
/**
- * Call-back function that gets called for each rtp channel opened
- *
- * Returns nothing
- */
-void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int remotePort, const char *token)
-{
- struct oh323_pvt *pvt = NULL;
- struct sockaddr_in them;
-
- /* Find the call or allocate a private structure if call not found */
- pvt = find_call(call_reference, token);
- if (!pvt) {
- ast_log(LOG_ERROR, "Something is wrong: rtp\n");
- return;
- }
- them.sin_family = AF_INET;
- them.sin_addr.s_addr = inet_addr(remoteIp); // only works for IPv4
- them.sin_port = htons(remotePort);
- ast_rtp_set_peer(pvt->rtp, &them);
- return;
-}
-
-/**
- * Call-back function to signal asterisk that the channel has been answered
- * Returns nothing
- */
-void connection_made(unsigned call_reference, const char *token)
-{
- struct ast_channel *c = NULL;
- struct oh323_pvt *pvt = NULL;
-
- pvt = find_call(call_reference, token);
-
- if (!pvt) {
- ast_log(LOG_ERROR, "Something is wrong: connection\n");
- return;
- }
-
- if (!pvt->owner) {
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- c = pvt->owner;
-
- ast_setstate(c, AST_STATE_UP);
- ast_queue_control(c, AST_CONTROL_ANSWER);
- return;
-}
-
-/**
* Call-back function to signal asterisk that the channel is ringing
* Returns nothing
*/
@@ -1979,7 +1923,7 @@ int load_module()
/* Register our callback functions */
h323_callback_register(setup_incoming_call,
setup_outgoing_call,
- create_connection,
+ external_rtp_create,
setup_rtp_connection,
cleanup_connection,
chan_ringing,
diff --git a/channels/h323/Makefile b/channels/h323/Makefile
index ef52b4d8f..48e4c4e43 100755
--- a/channels/h323/Makefile
+++ b/channels/h323/Makefile
@@ -35,8 +35,6 @@ endif
#
# Only change below if you know WTF your doing
#
-#
-# Janus release directives, comment below if your brave enough for Janus
OSARCH=$(shell uname -s)
CFLAGS += -DNDEBUG -DDO_CRASH -DDEBUG_THREADS
CFLAGS += -pipe -Wall -fPIC -Wmissing-prototypes -Wmissing-declarations
@@ -45,25 +43,6 @@ CFLAGS += -I../../include
CFLAGS += -I$(PWLIBDIR)/include
CFLAGS += -I$(OPENH323DIR)/include -Wno-missing-prototypes -Wno-missing-declarations
-# Pre Janus release directives
-#CFLAGS += -DNDEBUG -DDO_CRASH -DDEBUG_THREADS
-#CFLAGS += -pipe -Wall -fPIC
-#ifeq (${OSARCH},Linux)
-#CFLAGS += -DP_LINUX
-#LIBS+=-lpthread
-#endif
-#ifeq ($(findstring BSD,${OSARCH}),BSD)
-#CFLAGS += -pthread
-#endif
-#CFLAGS += -D_REENTRANT -D_GNU_SOURCE
-#CFLAGS += -DP_HAS_SEMAPHORES -DP_SSL -DP_PTHREADS
-#CFLAGS += -DPHAS_TEMPLATES -DPTRACING -DP_USE_PRAGMA
-#CFLAGS += -I../../include
-#CFLAGS += -I$(PWLIBDIR)/include/ptlib/unix -I$(PWLIBDIR)/include
-#CFLAGS += -I$(OPENH323DIR)/include
-#CFLAGS += -Wno-missing-prototypes -Wno-missing-declarations
-#LIBS+= -lcrypto -lssl -lexpat
-
all: libchanh323.a
samples:
@@ -76,10 +55,6 @@ samples:
ast_h323.o: ast_h323.cpp
$(CXX) -g -c -o $@ $(CFLAGS) $<
-#ast_h323.o: ast_h323.cpp
-# $(CXX) -g -c -fno-rtti -o $@ $(CFLAGS) $<
-
-
libchanh323.a: ast_h323.o
ar cr libchanh323.a ast_h323.o
diff --git a/channels/h323/ast_h323.cpp b/channels/h323/ast_h323.cpp
index cfec7e5c6..74de8d62d 100755
--- a/channels/h323/ast_h323.cpp
+++ b/channels/h323/ast_h323.cpp
@@ -70,7 +70,6 @@ MyH323EndPoint *endPoint = NULL;
/** PWLib entry point */
MyProcess *localProcess = NULL;
-
MyProcess::MyProcess(): PProcess("The NuFone Network's", "H.323 Channel Driver for Asterisk",
MAJOR_VERSION, MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
{
@@ -84,11 +83,11 @@ void MyProcess::Main()
PTrace::Initialise(0, NULL, PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
}
-#define H323_NAME OPAL_G7231_6k3"{sw}"
+#define H323_G7231 OPAL_G7231_6k3"{sw}"
#define H323_G729 OPAL_G729 "{sw}"
#define H323_G729A OPAL_G729A"{sw}"
-H323_REGISTER_CAPABILITY(H323_G7231Capability, H323_NAME);
+H323_REGISTER_CAPABILITY(H323_G7231Capability, H323_G7231);
H323_REGISTER_CAPABILITY(AST_G729Capability, H323_G729);
H323_REGISTER_CAPABILITY(AST_G729ACapability, H323_G729A);
@@ -117,19 +116,16 @@ PObject * H323_G7231Capability::Clone() const
return new H323_G7231Capability(*this);
}
-
PString H323_G7231Capability::GetFormatName() const
{
- return H323_NAME;
+ return H323_G7231;
}
-
unsigned H323_G7231Capability::GetSubType() const
{
return H245_AudioCapability::e_g7231;
}
-
BOOL H323_G7231Capability::OnSendingPDU(H245_AudioCapability & cap,
unsigned packetSize) const
{
@@ -142,7 +138,6 @@ BOOL H323_G7231Capability::OnSendingPDU(H245_AudioCapability & cap,
return TRUE;
}
-
BOOL H323_G7231Capability::OnReceivedPDU(const H245_AudioCapability & cap,
unsigned & packetSize)
{
@@ -156,13 +151,11 @@ BOOL H323_G7231Capability::OnReceivedPDU(const H245_AudioCapability & cap,
return TRUE;
}
-
H323Codec * H323_G7231Capability::CreateCodec(H323Codec::Direction direction) const
{
return NULL;
}
-
/////////////////////////////////////////////////////////////////////////////
AST_G729Capability::AST_G729Capability()
@@ -170,29 +163,26 @@ AST_G729Capability::AST_G729Capability()
{
}
-
PObject * AST_G729Capability::Clone() const
{
return new AST_G729Capability(*this);
}
-
unsigned AST_G729Capability::GetSubType() const
{
return H245_AudioCapability::e_g729;
}
-
PString AST_G729Capability::GetFormatName() const
{
return H323_G729;
}
-
H323Codec * AST_G729Capability::CreateCodec(H323Codec::Direction direction) const
{
return NULL;
}
+
/////////////////////////////////////////////////////////////////////////////
AST_G729ACapability::AST_G729ACapability()
@@ -200,25 +190,21 @@ AST_G729ACapability::AST_G729ACapability()
{
}
-
PObject * AST_G729ACapability::Clone() const
{
return new AST_G729ACapability(*this);
}
-
unsigned AST_G729ACapability::GetSubType() const
{
return H245_AudioCapability::e_g729AnnexA;
}
-
PString AST_G729ACapability::GetFormatName() const
{
return H323_G729A;
}
-
H323Codec * AST_G729ACapability::CreateCodec(H323Codec::Direction direction) const
{
return NULL;
@@ -269,8 +255,6 @@ int MyH323EndPoint::MakeCall(const PString & dest, PString & token, unsigned int
localAliasNames.RemoveAll();
connection->SetLocalPartyName(PString(callerid));
}
- connection->AST_Outgoing = TRUE;
-
if (h323debug) {
cout << " -- " << GetLocalUserName() << " is calling host " << fullAddress << endl;
cout << " -- " << "Call token is " << (const char *)token << endl;
@@ -475,12 +459,12 @@ H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference, void *
unsigned options = 0;
call_options_t *opts = (call_options_t *)o;
- if (opts->noFastStart) {
+ if (opts && opts->noFastStart) {
options |= H323Connection::FastStartOptionDisable;
} else {
options |= H323Connection::FastStartOptionEnable;
}
- if (opts->noH245Tunneling) {
+ if (opts && opts->noH245Tunneling) {
options |= H323Connection::H245TunnelingOptionDisable;
} else {
options |= H323Connection::H245TunnelingOptionEnable;
@@ -503,8 +487,6 @@ MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned callReference,
if (h323debug) {
cout << " == New H.323 Connection created." << endl;
}
- AST_RTP_Connected = FALSE;
- AST_Outgoing = FALSE;
return;
}
@@ -534,43 +516,13 @@ H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString
BOOL MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const PString & username)
{
- PIPSocket::Address remoteIpAddress;
- WORD remotePort;
- H323_ExternalRTPChannel * channel;
-
- if (h323debug)
+ if (h323debug) {
cout << "\t =-= In OnAlerting for call " << GetCallReference()
<< ": sessionId=" << sessionId << endl;
-
- /* Connect RTP if logical channel has already been opened */
- if (Lock()) {
- if ( (channel = (H323_ExternalRTPChannel*) FindChannel(sessionId,TRUE)) ) {
- channel->GetRemoteAddress(remoteIpAddress, remotePort);
- if (h323debug) {
- cout << "\t\t--- found logical channel. Connecting RTP" << endl;
- cout << "\t\tRTP channel id " << sessionId << " parameters:" << endl;
- cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
- cout << "\t\t-- remotePort: " << remotePort << endl;
- cout << "\t\t-- ExternalIpAddress: " << externalIpAddress << endl;
- cout << "\t\t-- ExternalPort: " << externalPort << endl;
- }
- on_start_logical_channel(GetCallReference(),(const char *)remoteIpAddress.AsString(), remotePort,
- (const char *)GetCallToken() );
- AST_RTP_Connected=TRUE;
- } else
- if (h323debug)
- cout << "\t\t--- no logical channels" << endl;
-
- if (h323debug) {
- cout << " -- Ringing phone for \"" << username << "\"" << endl;
- }
-
- on_chan_ringing(GetCallReference(), (const char *)GetCallToken() );
- Unlock();
- return TRUE;
- }
- ast_log(LOG_ERROR,"chan_h323: OnAlerting: Could not obtain connection lock");
- return FALSE;
+ cout << " -- Ringing phone for \"" << username << "\"" << endl;
+ }
+ on_chan_ringing(GetCallReference(), (const char *)GetCallToken() );
+ return TRUE;
}
BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
@@ -753,31 +705,10 @@ void MyH323Connection::OnUserInputString(const PString &value)
H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capability & capability,
H323Channel::Directions dir,
unsigned sessionID,
- const H245_H2250LogicalChannelParameters * /*param*/)
+ const H245_H2250LogicalChannelParameters * /*param*/,
+ RTP_QOS * /*param*/ )
{
- struct rtp_info *info;
- WORD port;
-
- /* Determine the Local (A side) IP Address and port */
- info = on_create_connection(GetCallReference(), (const char *)GetCallToken());
-
- if (!info) {
- return NULL;
- }
-
- GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
- externalPort = info->port;
- sessionId = sessionID;
-
- if (h323debug) {
- cout << " =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
- cout << " -- externalIpAddress: " << externalIpAddress << endl;
- cout << " -- externalPort: " << externalPort << endl;
- cout << " -- SessionID: " << sessionID << endl;
- cout << " -- Direction: " << dir << endl;
- }
-
- return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID, externalIpAddress, externalPort);
+ return new MyH323_ExternalRTPChannel(*this, capability, dir, sessionID);
}
/** This callback function is invoked once upon creation of each
@@ -785,11 +716,8 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
*/
BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
{
- PIPSocket::Address remoteIpAddress;
- WORD remotePort;
-
if (h323debug) {
- cout << " -- Started logical channel: ";
+ cout << "\t-- Started logical channel: ";
cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" "));
cout << (const char *)(channel.GetCapability()).GetFormatName() << endl;
}
@@ -798,101 +726,72 @@ BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
channelsOpen++;
if (h323debug) {
- cout << " -- channelsOpen = " << channelsOpen << endl;
+ cout << "\t\t-- channelsOpen = " << channelsOpen << endl;
}
- if (!Lock()) {
- ast_log(LOG_ERROR,"chan_h323: OnStartLogicalChannel: Could not obtain connection lock");
- return FALSE;
- }
- /* Connect RTP for incoming calls */
- if (!AST_Outgoing) {
- H323_ExternalRTPChannel & external = (H323_ExternalRTPChannel &)channel;
- external.GetRemoteAddress(remoteIpAddress, remotePort);
- if (h323debug) {
- cout << "\t\tRTP channel id " << sessionId << " parameters:" << endl;
- cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
- cout << "\t\t-- remotePort: " << remotePort << endl;
- cout << "\t\t-- ExternalIpAddress: " << externalIpAddress << endl;
- cout << "\t\t-- ExternalPort: " << externalPort << endl;
- }
- /* Notify Asterisk of remote RTP information */
- on_start_logical_channel(GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
- (const char *)GetCallToken());
- AST_RTP_Connected = TRUE;
- }
- Unlock();
return TRUE;
}
/* MyH323_ExternalRTPChannel */
MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connection,
const H323Capability & capability,
- Directions direction,
- unsigned sessionID,
- const PIPSocket::Address & ip,
- WORD dataPort)
- : H323_ExternalRTPChannel(connection, capability, direction, sessionID, ip, dataPort)
-{
-}
-
-MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connection,
- const H323Capability & capability,
Directions direction,
unsigned id)
: H323_ExternalRTPChannel::H323_ExternalRTPChannel(connection, capability, direction, id)
{
-}
+ struct rtp_info *info;
-MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connection,
- const H323Capability & capability,
- Directions direction,
- unsigned id,
- const H323TransportAddress & data,
- const H323TransportAddress & control)
- : H323_ExternalRTPChannel::H323_ExternalRTPChannel(connection, capability, direction, id, data, control)
-{
+ /* Determine the Local (A side) IP Address and port */
+ info = on_external_rtp_create(connection.GetCallReference(), (const char *)connection.GetCallToken());
+ if (!info) {
+ cout << "\tERROR: on_external_rtp_create failure" << endl;
+ return;
+ } else {
+ localIpAddr = (PIPSocket::Address)info->addr;
+ localPort = (WORD)info->port;
+ /* tell the H.323 stack */
+ SetExternalAddress(H323TransportAddress(localIpAddr, localPort), H323TransportAddress(localIpAddr, localPort + 1));
+ /* clean up allocated memory */
+ free(info);
+ }
+
+ // Get the payload code
+ OpalMediaFormat format(capability.GetFormatName(), FALSE);
+ payloadCode = format.GetPayloadType();
}
-MyH323_ExternalRTPChannel::~MyH323_ExternalRTPChannel()
+MyH323_ExternalRTPChannel::~MyH323_ExternalRTPChannel()
{
+ if (h323debug) {
+ cout << "\tExternalRTPChannel Destroyed" << endl;
+ }
}
-BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
+BOOL MyH323_ExternalRTPChannel::Start(void)
{
- PIPSocket::Address remoteIpAddress;
- WORD remotePort;
- MyH323Connection* conn = (MyH323Connection*) &connection;
-
- if (h323debug)
- cout << "\t=-= In OnReceivedAckPDU for call " << connection.GetCallReference() << endl;
-
- if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
- if (!connection.Lock()) {
- ast_log(LOG_ERROR,"chan_h323: OnReceivedAckPDU: Could not obtain connection lock");
- return FALSE;
- }
- /* if RTP hasn't been connected yet */
- if (!conn->AST_RTP_Connected) {
- H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort);
- if (h323debug) {
- cout << "\t\tRTP channel id " << sessionID << " parameters:" << endl;
- cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
- cout << "\t\t-- remotePort: " << remotePort << endl;
- cout << "\t\t-- ExternalIpAddress: " << conn->externalIpAddress << endl;
- cout << "\t\t-- ExternalPort: " << conn->externalPort << endl;
- }
-
- /* Notify Asterisk of remote RTP information */
- on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
- (const char *)conn->GetCallToken());
- conn->AST_RTP_Connected = TRUE;
- }
- connection.Unlock();
- return TRUE;
- }
- return FALSE;
+ /* Call ancestor first */
+ if (!H323_ExternalRTPChannel::Start()) {
+ return FALSE;
+ }
+
+ /* Collect the remote information */
+ GetRemoteAddress(remoteIpAddr, remotePort);
+
+ if (h323debug) {
+ cout << "\t\tExternal RTP Session Starting" << endl;
+ cout << "\t\tRTP channel id " << sessionID << " parameters:" << endl;
+ cout << "\t\t-- remoteIpAddress: " << remoteIpAddr << endl;
+ cout << "\t\t-- remotePort: " << remotePort << endl;
+ cout << "\t\t-- ExternalIpAddress: " << localIpAddr << endl;
+ cout << "\t\t-- ExternalPort: " << localPort << endl;
+ }
+
+ /* Notify Asterisk of remote RTP information */
+ on_start_rtp_channel(connection.GetCallReference(), (const char *)remoteIpAddr.AsString(), remotePort,
+ (const char *)connection.GetCallToken());
+ return TRUE;
}
+
/** IMPLEMENTATION OF C FUNCTIONS */
/**
@@ -946,8 +845,8 @@ void h323_debug(int flag, unsigned level)
/** Installs the callback functions on behalf of the PBX application */
void h323_callback_register(setup_incoming_cb ifunc,
setup_outbound_cb sfunc,
- on_connection_cb confunc,
- start_logchan_cb lfunc,
+ on_rtp_cb rtpfunc,
+ start_rtp_cb lfunc,
clear_con_cb clfunc,
chan_ringing_cb rfunc,
con_established_cb efunc,
@@ -956,8 +855,8 @@ void h323_callback_register(setup_incoming_cb ifunc,
{
on_incoming_call = ifunc;
on_outgoing_call = sfunc;
- on_create_connection = confunc;
- on_start_logical_channel = lfunc;
+ on_external_rtp_create = rtpfunc;
+ on_start_rtp_channel = lfunc;
on_connection_cleared = clfunc;
on_chan_ringing = rfunc;
on_connection_established = efunc;
diff --git a/channels/h323/ast_h323.h b/channels/h323/ast_h323.h
index 2a034f7d9..b04f57c95 100755
--- a/channels/h323/ast_h323.h
+++ b/channels/h323/ast_h323.h
@@ -218,7 +218,8 @@ class MyH323Connection : public H323Connection {
H323Channel * CreateRealTimeLogicalChannel(const H323Capability &,
H323Channel::Directions,
unsigned,
- const H245_H2250LogicalChannelParameters *);
+ const H245_H2250LogicalChannelParameters *,
+ RTP_QOS *);
H323Connection::AnswerCallResponse OnAnswerCall(const PString &, const H323SignalPDU &, H323SignalPDU &);
void OnReceivedReleaseComplete(const H323SignalPDU &);
BOOL OnAlerting(const H323SignalPDU &, const PString &);
@@ -237,12 +238,8 @@ class MyH323Connection : public H323Connection {
PString sourceE164;
PString destE164;
- PIPSocket::Address externalIpAddress;
- WORD externalPort;
WORD sessionId;
BOOL bridging;
- BOOL AST_RTP_Connected;
- BOOL AST_Outgoing;
};
class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
@@ -251,35 +248,24 @@ class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
public:
MyH323_ExternalRTPChannel(
- MyH323Connection & connection,
+ MyH323Connection & connection,
const H323Capability & capability,
Directions direction,
unsigned sessionID);
- MyH323_ExternalRTPChannel(
- MyH323Connection & connection,
- const H323Capability & capability,
- Directions direction,
- unsigned sessionID,
- const H323TransportAddress & data,
- const H323TransportAddress & control);
-
- /* Create a new channel. */
- MyH323_ExternalRTPChannel(
- MyH323Connection & connection,
- const H323Capability & capability,
- Directions direction,
- unsigned sessionID,
- const PIPSocket::Address & ip,
- WORD dataPort);
-
/* Destructor */
~MyH323_ExternalRTPChannel();
- BOOL OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param);
+ /* Overrides */
+ BOOL Start(void);
+
+ protected:
+ BYTE payloadCode;
- PIPSocket::Address externalIpAddress;
- WORD externalPort;
+ PIPSocket::Address localIpAddr;
+ PIPSocket::Address remoteIpAddr;
+ WORD localPort;
+ WORD remotePort;
};
/**
@@ -292,10 +278,7 @@ class MyProcess : public PProcess {
public:
MyProcess();
-
void Main();
-
-
};
#endif /* !defined AST_H323_H */
diff --git a/channels/h323/chan_h323.h b/channels/h323/chan_h323.h
index 928301986..c53ee0c8c 100755
--- a/channels/h323/chan_h323.h
+++ b/channels/h323/chan_h323.h
@@ -116,45 +116,45 @@ typedef struct rtp_info {
/* This is a callback prototype function, called pass
DTMF down the RTP. */
typedef int (*send_digit_cb)(unsigned, char, const char *);
-extern send_digit_cb on_send_digit;
+extern send_digit_cb on_send_digit;
/* This is a callback prototype function, called to collect
the external RTP port from Asterisk. */
-typedef rtp_info_t *(*on_connection_cb)(unsigned, const char *);
-extern on_connection_cb on_create_connection;
+typedef rtp_info_t *(*on_rtp_cb)(unsigned, const char *);
+extern on_rtp_cb on_external_rtp_create;
+
+/* This is a callback prototype function, called to send
+ the remote IP and RTP port from H.323 to Asterisk */
+typedef void (*start_rtp_cb)(unsigned int, const char *, int, const char *);
+extern start_rtp_cb on_start_rtp_channel;
/* This is a callback prototype function, called upon
an incoming call happens. */
typedef int (*setup_incoming_cb)(call_details_t);
-extern setup_incoming_cb on_incoming_call;
+extern setup_incoming_cb on_incoming_call;
/* This is a callback prototype function, called upon
an outbound call. */
typedef int (*setup_outbound_cb)(call_details_t);
-extern setup_outbound_cb on_outgoing_call;
-
-/* This is a callback prototype function, called when the openh323
- OnStartLogicalChannel is invoked. */
-typedef void (*start_logchan_cb)(unsigned int, const char *, int, const char *);
-extern start_logchan_cb on_start_logical_channel;
+extern setup_outbound_cb on_outgoing_call;
/* This is a callback prototype function, called when openh323
OnAlerting is invoked */
typedef void (*chan_ringing_cb)(unsigned, const char *);
-extern chan_ringing_cb on_chan_ringing;
+extern chan_ringing_cb on_chan_ringing;
/* This is a callback protoype function, called when the openh323
OnConnectionEstablished is inovked */
typedef void (*con_established_cb)(unsigned, const char *);
-extern con_established_cb on_connection_established;
+extern con_established_cb on_connection_established;
/* This is a callback prototype function, called when the openH323
OnConnectionCleared callback is invoked */
typedef void (*clear_con_cb)(call_details_t);
-extern clear_con_cb on_connection_cleared;
+extern clear_con_cb on_connection_cleared;
typedef int (*answer_call_cb)(unsigned, const char *);
-extern answer_call_cb on_answer_call;
+extern answer_call_cb on_answer_call;
/* debug flag */
extern int h323debug;
@@ -176,8 +176,8 @@ extern "C" {
/* callback function handler*/
void h323_callback_register(setup_incoming_cb,
setup_outbound_cb,
- on_connection_cb,
- start_logchan_cb,
+ on_rtp_cb,
+ start_rtp_cb,
clear_con_cb,
chan_ringing_cb,
con_established_cb,