diff options
author | jeremy <jeremy@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-10-10 12:20:18 +0000 |
---|---|---|
committer | jeremy <jeremy@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-10-10 12:20:18 +0000 |
commit | 25157bbe77ed41c8d34ea922d3d6bb7f78d5dbed (patch) | |
tree | d7339e000cef4f33c3d85825e821f82cf602c257 /channels/h323 | |
parent | 7d314f3632d9ce618963251ae12e469d678b636d (diff) |
finish implementing type=peer, implement setting of FastStart and H.245 Tunneling per user/peer, update External RTP implemenation, fixed compile process/other buglets to operate with Open H.323 v1.14.4 and PWLib v1.7.5, and massive code clean up. All of the above is untested, please test and report
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3970 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/h323')
-rwxr-xr-x | channels/h323/Makefile | 25 | ||||
-rwxr-xr-x | channels/h323/ast_h323.cpp | 231 | ||||
-rwxr-xr-x | channels/h323/ast_h323.h | 41 | ||||
-rwxr-xr-x | channels/h323/chan_h323.h | 32 |
4 files changed, 93 insertions, 236 deletions
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, |