[Asterisk-cvs] asterisk/channels/h323 ast_h323.cpp, 1.58, 1.59 ast_h323.h, 1.25, 1.26 chan_h323.h, 1.26, 1.27

jeremy at lists.digium.com jeremy at lists.digium.com
Tue Sep 21 14:38:59 CDT 2004


Update of /usr/cvsroot/asterisk/channels/h323
In directory mongoose.digium.com:/tmp/cvs-serv14719/h323

Modified Files:
	ast_h323.cpp ast_h323.h chan_h323.h 
Log Message:
support early media/intercept Bug #562

Index: ast_h323.cpp
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- ast_h323.cpp	19 Sep 2004 16:53:01 -0000	1.58
+++ ast_h323.cpp	21 Sep 2004 18:42:37 -0000	1.59
@@ -272,6 +272,8 @@
                 localAliasNames.RemoveAll();
                 connection->SetLocalPartyName(PString(callerid));
         }
+        
+        connection->AST_Outgoing = TRUE;
 
 	connection->Unlock(); 	
 
@@ -357,7 +359,8 @@
 void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection, const PString & estCallToken)
 {
 	if (h323debug) {
-		cout << "	-- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
+		cout << "\t=-= In OnConnectionEstablished for call " << connection.GetCallReference() << endl;
+		cout << "\t\t-- Connection Established with \"" << connection.GetRemotePartyName() << "\"" << endl;
 	}
 	on_connection_established(connection.GetCallReference(), (const char *)connection.GetCallToken());
 }
@@ -478,9 +481,13 @@
 
 	if (noFastStart)
 		options |= H323Connection::FastStartOptionDisable;
+	else
+		options |= H323Connection::FastStartOptionEnable;
 
 	if (noH245Tunneling)
 		options |= H323Connection::H245TunnelingOptionDisable;
+	else
+		options |= H323Connection::H245TunnelingOptionEnable;
 
 	return new MyH323Connection(*this, callReference, options);
 }
@@ -493,7 +500,8 @@
 	if (h323debug) {
 		cout << "	== New H.323 Connection created." << endl;
 	}
-
+	AST_RTP_Connected = FALSE;
+	AST_Outgoing = FALSE;
 	return;
 }
 
@@ -506,10 +514,12 @@
 }
 
 H323Connection::AnswerCallResponse MyH323Connection::OnAnswerCall(const PString & caller,
-																   const H323SignalPDU & /*setupPDU*/,
-																   H323SignalPDU & /*connectPDU*/)
+								  const H323SignalPDU & /*setupPDU*/,
+								  H323SignalPDU & /*connectPDU*/)
 {
 
+       if (h323debug)
+               cout << "\t=-= In OnAnswerCall for call " << GetCallReference() << endl;
 	
 	if (!on_answer_call(GetCallReference(), (const char *)GetCallToken()))
 		return H323Connection::AnswerCallDenied;
@@ -521,12 +531,43 @@
 
 BOOL  MyH323Connection::OnAlerting(const H323SignalPDU & /*alertingPDU*/, const PString & username)
 {
+	PIPSocket::Address remoteIpAddress;
+	WORD remotePort;
+	H323_ExternalRTPChannel * channel;
 	
-	if (h323debug) {
-		cout << "	-- Ringing phone for \"" << username << "\"" << endl;
+	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;
 	}
-	on_chan_ringing(GetCallReference(), (const char *)GetCallToken());
-	return TRUE;
+	ast_log(LOG_ERROR,"chan_h323: OnAlerting: Could not obtain connection lock");
+	return FALSE;
 }
 
 BOOL MyH323Connection::OnReceivedSignalSetup(const H323SignalPDU & setupPDU)
@@ -723,6 +764,7 @@
 
 	GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
 	externalPort = info->port;
+	sessionId = sessionID;
 
 	if (h323debug) {
 		cout << "	=*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
@@ -740,6 +782,9 @@
   */
 BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
 {    
+	PIPSocket::Address remoteIpAddress;
+	WORD remotePort;
+	
 	if (h323debug) {
 		cout << "	 -- Started logical channel: ";	
 		cout << ((channel.GetDirection()==H323Channel::IsTransmitter)?"sending ":((channel.GetDirection()==H323Channel::IsReceiver)?"receiving ":" ")); 
@@ -753,6 +798,27 @@
 		cout <<  "		-- 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;	
 }
 
@@ -793,16 +859,36 @@
 {
        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)) {
-               H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort);
-               /* Notify Asterisk of remote RTP information */
-               on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort, 
-                                         (const char *)connection.GetCallToken() );
-                return TRUE;
-        }
-        return FALSE;
+       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;
 }
 /** IMPLEMENTATION OF C FUNCTIONS */
 
@@ -1145,6 +1231,9 @@
 
         connection = endPoint->FindConnectionWithLock(currentToken);
 
+        if (h323debug)
+        	ast_verbose("\tSending alerting\n");
+        
         if (!connection) {
                 cout << "No connection found for " << token << endl;
                 return -1;
@@ -1191,8 +1280,12 @@
 	}
 
 	if (!busy) {
+		if (h323debug)
+			ast_verbose("\tanswering call\n");
 		connection->AnsweringCall(H323Connection::AnswerCallNow);
 	} else {
+		if (h323debug)
+			ast_verbose("\tdenying call\n");
 		connection->AnsweringCall(H323Connection::AnswerCallDenied);
 	}
 	connection->Unlock();
@@ -1237,5 +1330,12 @@
 
 }
 
+/* set defalt h323 options */
+void h323_set_options(int nofs, int noh245tun) {
+       noFastStart = nofs;
+       noH245Tunneling = noh245tun;
+       return;
+}
+
 } /* extern "C" */
 

Index: ast_h323.h
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/ast_h323.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- ast_h323.h	19 Sep 2004 16:53:01 -0000	1.25
+++ ast_h323.h	21 Sep 2004 18:42:37 -0000	1.26
@@ -241,7 +241,8 @@
 	WORD externalPort;
 	WORD sessionId;
 	BOOL bridging;			
-        
+        BOOL AST_RTP_Connected;
+        BOOL AST_Outgoing;
 };
 
 class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {

Index: chan_h323.h
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/h323/chan_h323.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- chan_h323.h	19 Sep 2004 16:53:01 -0000	1.26
+++ chan_h323.h	21 Sep 2004 18:42:37 -0000	1.27
@@ -202,7 +202,8 @@
 	/* H323 create and destroy sessions */
 	int h323_make_call(char *host, call_details_t *cd, call_options_t);
 	int h323_clear_call(const char *);
-
+	void h323_set_options(int nofs, int noh245tun);	
+	
 	/* H.323 alerting and progress */
 	int h323_send_alerting(const char *token);
 	int h323_send_progress(const char *token);
@@ -210,7 +211,7 @@
 	int h323_answering_call(const char *token, int);
 	int h323_soft_hangup(const char *data);	
 	int h323_show_codec(int fd, int argc, char *argv[]);
-	
+
 
 #ifdef __cplusplus
 }




More information about the svn-commits mailing list