]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
support early media/intercept Bug #562
authorJeremy McNamara <jj@nufone.net>
Tue, 21 Sep 2004 18:42:37 +0000 (18:42 +0000)
committerJeremy McNamara <jj@nufone.net>
Tue, 21 Sep 2004 18:42:37 +0000 (18:42 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3815 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_h323.c
channels/h323/ast_h323.cpp
channels/h323/ast_h323.h
channels/h323/chan_h323.h

index fa8ebd21264af377894e4f2b03ddd5b1782d80db..c64a6e254b153dd3a0f7a37573d631510cd4e84a 100755 (executable)
@@ -1766,6 +1766,9 @@ int reload_config(void)
        }
        ast_mutex_unlock(&caplock);
 
+       /* set default options */
+       h323_set_options(noFastStart,noH245Tunneling);
+
        return 0;
 }
 
@@ -1985,7 +1988,6 @@ int load_module()
                                       send_digit,
                                       answer_call);
        
-
                /* start the h.323 listener */
                if (h323_start_listener(port, bindaddr)) {
                        ast_log(LOG_ERROR, "Unable to create H323 listener.\n");
index 480da4e73a5b9edd4e6e432f800654401264a8bc..afeee365e18c749b20326d7e9360f66d6d872329 100755 (executable)
@@ -272,6 +272,8 @@ int MyH323EndPoint::MakeCall(const PString & dest, PString & token, unsigned int
                 localAliasNames.RemoveAll();
                 connection->SetLocalPartyName(PString(callerid));
         }
+        
+        connection->AST_Outgoing = TRUE;
 
        connection->Unlock();   
 
@@ -357,7 +359,8 @@ BOOL MyH323EndPoint::ForwardConnection(H323Connection & connection,
 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 @@ H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference, void *
 
        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 @@ MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned callReference,
        if (h323debug) {
                cout << "       == New H.323 Connection created." << endl;
        }
-
+       AST_RTP_Connected = FALSE;
+       AST_Outgoing = FALSE;
        return;
 }
 
@@ -506,10 +514,12 @@ MyH323Connection::~MyH323Connection()
 }
 
 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 @@ 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) {
-               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 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
 
        GetControlChannel().GetLocalAddress().GetIpAndPort(externalIpAddress, port);
        externalPort = info->port;
+       sessionId = sessionID;
 
        if (h323debug) {
                cout << "       =*= In CreateRealTimeLogicalChannel for call " << GetCallReference() << endl;
@@ -740,6 +782,9 @@ H323Channel * MyH323Connection::CreateRealTimeLogicalChannel(const H323Capabilit
   */
 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 @@ BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
                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 @@ BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelA
 {
        PIPSocket::Address remoteIpAddress;
        WORD remotePort;
-
-        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;
-
+       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;
 }
 /** IMPLEMENTATION OF C FUNCTIONS */
 
@@ -1145,6 +1231,9 @@ int h323_send_alerting(const char *token)
 
         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 @@ int h323_answering_call(const char *token, int busy)
        }
 
        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 @@ void h323_native_bridge(const char *token, const char *them, char *capability)
 
 }
 
+/* set defalt h323 options */
+void h323_set_options(int nofs, int noh245tun) {
+       noFastStart = nofs;
+       noH245Tunneling = noh245tun;
+       return;
+}
+
 } /* extern "C" */
 
index a0c710194ebbf9e68ee2a2906d5e1fdaf57abdd7..2a034f7d9bd752770b0eb4e289e942f46f5cc325 100755 (executable)
@@ -241,7 +241,8 @@ class MyH323Connection : public H323Connection {
        WORD externalPort;
        WORD sessionId;
        BOOL bridging;                  
-        
+        BOOL AST_RTP_Connected;
+        BOOL AST_Outgoing;
 };
 
 class MyH323_ExternalRTPChannel : public H323_ExternalRTPChannel {
index 691fec63500841ea2574a206e5ba63f32cfd1ea6..1b277c4993b2d2166effab5c3ae030547710ed01 100755 (executable)
@@ -202,7 +202,8 @@ extern "C" {
        /* 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 @@ extern "C" {
        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
 }