callprocessor.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Inter Asterisk Exchange 2
00004  * 
00005  * The core routine which determines the processing of packets for one call.
00006  * 
00007  * Open Phone Abstraction Library (OPAL)
00008  *
00009  * Copyright (c) 2005 Indranet Technologies Ltd.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Open Phone Abstraction Library.
00022  *
00023  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
00024  *
00025  * The author of this code is Derek J Smithies
00026  *
00027  * $Revision: 24722 $
00028  * $Author: dereksmithies $
00029  * $Date: 2010-09-23 23:32:35 -0500 (Thu, 23 Sep 2010) $
00030  */
00031 
00032 #ifndef OPAL_IAX2_CALLPROCESSOR_H
00033 #define OPAL_IAX2_CALLPROCESSOR_H
00034 
00035 #ifndef _PTLIB_H
00036 #include <ptlib.h>
00037 #endif
00038 
00039 #include <opal/buildopts.h>
00040 
00041 #if OPAL_IAX2
00042 
00043 #include <opal/connection.h>
00044 
00045 #include <iax2/processor.h>
00046 #include <iax2/frame.h>
00047 #include <iax2/iedata.h>
00048 #include <iax2/remote.h>
00049 #include <iax2/safestrings.h>
00050 #include <iax2/sound.h>
00051 
00052 class IAX2Connection;
00053 
00057 class IAX2CallProcessor : public IAX2Processor
00058 {
00059   PCLASSINFO(IAX2CallProcessor, IAX2Processor);
00060   
00061  public:
00062   
00064   IAX2CallProcessor(IAX2EndPoint & ep);
00065 
00067   virtual ~IAX2CallProcessor(); 
00068 
00070   void AssignConnection(IAX2Connection * _con);
00071   
00074   void PutSoundPacketToNetwork(PBYTEArray *sund);
00075   
00077   IAX2Encryption & GetEncryptionInfo() { return encryption; }
00078 
00080   virtual void Release(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
00081 
00083   void ClearCall(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
00084 
00089   virtual void OnReleased();
00090   
00094   void SendDtmf(const PString & dtmfs);
00095 
00099   void SendText(const PString & text);
00100 
00107   virtual PBoolean SetUpConnection();
00108 
00111   PBoolean Matches(IAX2Frame *frame) { return remote == (frame->GetRemoteInfo()); }
00112   
00115   virtual void PrintOn(ostream & strm) const;
00116   
00119   void ReportStatistics();  
00120 
00122   PBoolean MatchingLocalCallNumber(PINDEX compare) { return (compare == remote.SourceCallNumber()); }  
00123   
00125   unsigned short GetSelectedCodec() { return (unsigned short) selectedCodec; }
00126   
00131   void AcceptIncomingCall();
00132 
00143   virtual PBoolean SetAlerting(
00144          const PString & calleeName,   
00145          PBoolean withMedia                
00146          ) ;
00147 
00151   void Hangup(PString messageToSend);
00152 
00155   PBoolean IsCallTerminating() { return callStatus & callTerminating; }
00156   
00158   void SendHold();
00159 
00161   void SendHoldRelease();
00162   
00169   void SetUserName(PString & inUserName) { userName = inUserName; };
00170   
00172   PString GetUserName() const;
00173   
00176   PString GetCallingName() const { return callingName; }
00177 
00184   void SetPassword(PString & inPassword) { password = inPassword; };
00185   
00187   PString GetPassword() const { return password; };
00188   
00191   void SendTransfer(
00192     const PString & calledNumber,
00193     const PString & calledContext = PString::Empty());  
00194 
00197   void StartStatusCheckTimer(PINDEX msToWait = 10000 );
00199   
00206   virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff);
00207 
00211   void SendAnswerMessageToRemoteNode();
00212 
00213  protected:
00214   
00216   IAX2Connection * con;
00217 
00222   PBoolean RemoteSelectedCodecOk();
00223  
00227   void CheckForHangupMessages();
00228  
00230   void ProcessNetworkFrame(IAX2Frame * src);
00231   
00234   void ProcessNetworkFrame(IAX2MiniFrame * src);
00235   
00238   void ProcessNetworkFrame(IAX2FullFrame * src);
00239   
00242   void ProcessNetworkFrame(IAX2FullFrameDtmf * src);
00243   
00246   void ProcessNetworkFrame(IAX2FullFrameVoice * src);
00247   
00250   void ProcessNetworkFrame(IAX2FullFrameVideo * src);
00251   
00254   void ProcessNetworkFrame(IAX2FullFrameSessionControl * src);
00255   
00258   void ProcessNetworkFrame(IAX2FullFrameNull * src);
00259   
00266   virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
00267   
00270   void ProcessNetworkFrame(IAX2FullFrameText * src);
00271   
00274   void ProcessNetworkFrame(IAX2FullFrameImage * src);
00275   
00278   void ProcessNetworkFrame(IAX2FullFrameHtml * src);
00279   
00282   void ProcessNetworkFrame(IAX2FullFrameCng * src);
00283   
00286   virtual void ProcessLists();
00287     
00289   void ConnectToRemoteNode(PString & destination);
00290   
00292   void SendDtmfMessage(char message);
00293   
00295   void SendTextMessage(PString & message);
00296 
00299   void SendSoundMessage(PBYTEArray *sound);
00300   
00302   void SendTransferMessage();
00303   
00305   void SendQuelchMessage();
00306   
00308   void SendUnQuelchMessage();
00309   
00311   void IncAudioFramesSent()   { ++audioFramesSent; }
00312   
00314   void IncAudioFramesRcvd()   { ++audioFramesRcvd; }
00315   
00317   void IncVideoFramesSent()   { ++videoFramesSent; }
00318   
00320   void IncVideoFramesRcvd()   { ++videoFramesRcvd; }
00321   
00324   void RemoteNodeHasAnswered();
00325   
00329   void CallStopSounds();
00330   
00333   void ReceivedHookFlash();
00334   
00337   void RemoteNodeIsBusy();
00338   
00341   void ProcessIncomingAudioFrame(IAX2Frame *newFrame);
00342   
00345   void ProcessIncomingVideoFrame(IAX2Frame *newFrame);
00346   
00349   void ProcessIaxCmdNew(IAX2FullFrameProtocol *src);
00350   
00353   void ProcessIaxCmdAck(IAX2FullFrameProtocol *src);
00354   
00357   void ProcessIaxCmdHangup(IAX2FullFrameProtocol *src);
00358   
00361   void ProcessIaxCmdReject(IAX2FullFrameProtocol *src);
00362   
00365   void ProcessIaxCmdAccept(IAX2FullFrameProtocol *src);
00366   
00369   void ProcessIaxCmdAuthReq(IAX2FullFrameProtocol *src);
00370   
00373   void ProcessIaxCmdAuthRep(IAX2FullFrameProtocol *src);
00374   
00377   void ProcessIaxCmdInval(IAX2FullFrameProtocol *src);
00378   
00381   void ProcessIaxCmdDpReq(IAX2FullFrameProtocol *src);
00382   
00385   void ProcessIaxCmdDpRep(IAX2FullFrameProtocol *src);
00386   
00389   void ProcessIaxCmdDial(IAX2FullFrameProtocol *src);
00390   
00393   void ProcessIaxCmdTxreq(IAX2FullFrameProtocol *src);
00394   
00397   void ProcessIaxCmdTxcnt(IAX2FullFrameProtocol *src);
00398   
00401   void ProcessIaxCmdTxacc(IAX2FullFrameProtocol *src);
00402   
00405   void ProcessIaxCmdTxready(IAX2FullFrameProtocol *src);
00406   
00409   void ProcessIaxCmdTxrel(IAX2FullFrameProtocol *src);
00410   
00413   void ProcessIaxCmdTxrej(IAX2FullFrameProtocol *src);
00414   
00417   void ProcessIaxCmdQuelch(IAX2FullFrameProtocol *src);
00418   
00421   void ProcessIaxCmdUnquelch(IAX2FullFrameProtocol *src);
00422   
00425   void ProcessIaxCmdPage(IAX2FullFrameProtocol *src);
00426   
00429   void ProcessIaxCmdMwi(IAX2FullFrameProtocol *src);
00430   
00433   void ProcessIaxCmdUnsupport(IAX2FullFrameProtocol *src);
00434   
00437   void ProcessIaxCmdTransfer(IAX2FullFrameProtocol *src);
00438   
00441   void ProcessIaxCmdProvision(IAX2FullFrameProtocol *src);
00442   
00445   void ProcessIaxCmdFwDownl(IAX2FullFrameProtocol *src);
00446   
00449   void ProcessIaxCmdFwData(IAX2FullFrameProtocol *src);
00450 
00457   void ProcessIaxCmdCallToken(IAX2FullFrameProtocol *src);
00458 
00464   IAX2FullFrameProtocol *BuildNewFrameForSending(IAX2FullFrameProtocol *inReplyTo = NULL);
00465   
00467   PAtomicInteger audioFramesSent;
00468   
00470   PAtomicInteger audioFramesRcvd;
00471   
00473   PAtomicInteger videoFramesSent;
00474   
00476   PAtomicInteger videoFramesRcvd;
00477   
00479   SafeString remotePhoneNumber;
00480   
00482   SafeStrings callList;
00483   
00487   SafeString dtmfText;
00488 
00491   SafeStrings textList;
00492 
00494   SafeStrings dtmfNetworkList;
00495 
00497   SafeStrings hangList;
00498   
00500   PBoolean holdCall;
00501   
00503   PBoolean holdReleaseCall;
00504   
00507   IAX2SoundList   soundWaitingForTransmission;
00508   
00514   enum SoundBufferState {
00515     BufferToSmall, 
00516     Normal, 
00517     BufferToBig 
00518   };
00519   
00521   SoundBufferState soundBufferState;
00522   
00525   PINDEX lastFullFrameTimeStamp;
00526     
00528   PBoolean audioCanFlow;
00529 
00532   unsigned int selectedCodec;
00533   
00535   enum CallStatus {
00536     callNewed      =  1 << 0,   
00537     callSentRinging = 1 << 1,   
00538     callRegistered =  1 << 2,   
00539     callAuthorised =  1 << 3,   
00540     callAccepted   =  1 << 4,   
00541     callRinging    =  1 << 5,   
00542     callAnswered   =  1 << 6,   
00543     callTerminating = 1 << 7    
00544   };
00545   
00547   unsigned short callStatus;
00548   
00550   void SetCallSentRinging(PBoolean newValue = true) 
00551     { if (newValue) callStatus |= callSentRinging; else callStatus &= ~callSentRinging; }
00552   
00554   void SetCallNewed(PBoolean newValue = true) 
00555     { if (newValue) callStatus |= callNewed; else callStatus &= ~callNewed; }
00556   
00558   void SetCallRegistered(PBoolean newValue = true) 
00559     { if (newValue) callStatus |= callRegistered; else callStatus &= ~callRegistered; }
00560   
00562   void SetCallAuthorised(PBoolean newValue = true) 
00563     { if (newValue) callStatus |= callAuthorised; else callStatus &= ~callAuthorised; }
00564   
00566   void SetCallAccepted(PBoolean newValue = true) 
00567     { if (newValue) callStatus |= callAccepted; else callStatus &= ~callAccepted; }
00568   
00570   void SetCallRinging(PBoolean newValue = true) 
00571     { if (newValue) callStatus |= callRinging; else callStatus &= ~callRinging; }
00572   
00574   void SetCallAnswered(PBoolean newValue = true) 
00575     { if (newValue) callStatus |= callAnswered; else callStatus &= ~callAnswered; }
00576 
00578   void SetCallTerminating(PBoolean newValue = true) 
00579     { if (newValue) callStatus |= callTerminating; else callStatus &= ~callTerminating; }
00580   
00582   PBoolean IsCallHappening() { return callStatus > 0; }
00583   
00586   PBoolean IsCallNewed() { return callStatus & callNewed; }
00587   
00590   PBoolean IsCallSentRinging() { return callStatus & callSentRinging; }
00591   
00593   PBoolean IsCallRegistered() { return callStatus & callRegistered; }
00594   
00596   PBoolean IsCallAuthorised() { return callStatus & callAuthorised; }
00597   
00599   PBoolean IsCallAccepted() { return callStatus & callAccepted; }
00600   
00602   PBoolean IsCallRinging() { return callStatus & callRinging; }
00603   
00605   PBoolean IsCallAnswered() { return callStatus & callAnswered; }
00606        
00607 #ifdef DOC_PLUS_PLUS
00608 
00614   void OnStatusCheck(PTimer &, INT);
00615 #else
00616   PDECLARE_NOTIFIER(PTimer, IAX2CallProcessor, OnStatusCheck);
00617 #endif
00618   
00620   void DoStatusCheck();
00621   
00624   void RemoteNodeIsRinging();
00625 
00629   void RingingWasAcked();
00630 
00635   void AnswerWasAcked();
00636 
00640   PBoolean firstMediaFrame;
00641 
00644   PBoolean answerCallNow;
00645 
00650   PBoolean statusCheckOtherEnd;
00651 
00653   PTimer statusCheckTimer;
00654 
00657   PINDEX audioFrameDuration;
00658 
00660   PINDEX audioCompressedBytes;
00661 
00665   PBoolean audioFramesNotStarted;
00666 
00669   void CheckForRemoteCapabilities(IAX2FullFrameProtocol *src);
00670   
00673   virtual void OnNoResponseTimeout();
00674   
00676   virtual void ProcessFullFrame(IAX2FullFrame & fullFrame);
00677   
00680   PString callingName;
00681 
00684   PString callingExtension;
00685 
00687   PString callingDnid;
00688 
00691   PString callingContext;
00692 
00696   PString userName;
00697   
00701   PString password;
00702   
00704   PMutex transferMutex;
00705   
00707   PBoolean doTransfer;
00708   
00710   PString transferCalledNumber;
00711   
00713   PString transferCalledContext;    
00714 
00719   PBoolean suppressHangupFrame;
00720 };
00721 
00723 
00724 /* The comment below is magic for those who use emacs to edit this file.
00725  * With the comment below, the tab key does auto indent to 2 spaces.    
00726  *
00727  * Local Variables:
00728  * mode:c
00729  * c-basic-offset:2
00730  * End:
00731  */
00732 
00733 
00734 #endif // OPAL_IAX2
00735 
00736 #endif // OPAL_IAX2_CALLPROCESSOR_H

Generated on Sun Nov 21 20:20:50 2010 for OPAL by  doxygen 1.4.7