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: 27079 $
00028  * $Author: rjongbloed $
00029  * $Date: 2012-02-29 23:12:01 -0600 (Wed, 29 Feb 2012) $
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   void ClearCall(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
00081 
00086   virtual void OnReleased();
00087   
00091   void SendDtmf(const PString & dtmfs);
00092 
00096   void SendText(const PString & text);
00097 
00104   virtual PBoolean SetUpConnection();
00105 
00108   PBoolean Matches(IAX2Frame *frame) { return remote == (frame->GetRemoteInfo()); }
00109   
00112   virtual void PrintOn(ostream & strm) const;
00113   
00116   void ReportStatistics();  
00117 
00119   PBoolean MatchingLocalCallNumber(PINDEX compare) { return (compare == remote.SourceCallNumber()); }  
00120   
00122   unsigned short GetSelectedCodec() { return (unsigned short) selectedCodec; }
00123   
00128   void AcceptIncomingCall();
00129 
00140   virtual PBoolean SetAlerting(
00141          const PString & calleeName,   
00142          PBoolean withMedia                
00143          ) ;
00144 
00148   void Hangup(PString messageToSend);
00149 
00152   PBoolean IsCallTerminating() { return callStatus & callTerminating; }
00153   
00155   void SendHold();
00156 
00158   void SendHoldRelease();
00159   
00166   void SetUserName(PString & inUserName) { userName = inUserName; };
00167   
00169   PString GetUserName() const;
00170   
00173   PString GetCallingName() const { return callingName; }
00174 
00181   void SetPassword(PString & inPassword) { password = inPassword; };
00182   
00184   PString GetPassword() const { return password; };
00185   
00188   void SendTransfer(
00189     const PString & calledNumber,
00190     const PString & calledContext = PString::Empty());  
00191 
00194   void StartStatusCheckTimer(PINDEX msToWait = 10000 );
00196   
00203   virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff);
00204 
00208   void SendAnswerMessageToRemoteNode();
00209 
00210  protected:
00211   
00213   IAX2Connection * con;
00214 
00219   PBoolean RemoteSelectedCodecOk();
00220  
00224   void CheckForHangupMessages();
00225  
00227   void ProcessNetworkFrame(IAX2Frame * src);
00228   
00231   void ProcessNetworkFrame(IAX2MiniFrame * src);
00232   
00235   void ProcessNetworkFrame(IAX2FullFrame * src);
00236   
00239   void ProcessNetworkFrame(IAX2FullFrameDtmf * src);
00240   
00243   void ProcessNetworkFrame(IAX2FullFrameVoice * src);
00244   
00247   void ProcessNetworkFrame(IAX2FullFrameVideo * src);
00248   
00251   void ProcessNetworkFrame(IAX2FullFrameSessionControl * src);
00252   
00255   void ProcessNetworkFrame(IAX2FullFrameNull * src);
00256   
00263   virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
00264   
00267   void ProcessNetworkFrame(IAX2FullFrameText * src);
00268   
00271   void ProcessNetworkFrame(IAX2FullFrameImage * src);
00272   
00275   void ProcessNetworkFrame(IAX2FullFrameHtml * src);
00276   
00279   void ProcessNetworkFrame(IAX2FullFrameCng * src);
00280   
00283   virtual void ProcessLists();
00284     
00286   void ConnectToRemoteNode(PString & destination);
00287   
00289   void SendDtmfMessage(char message);
00290   
00292   void SendTextMessage(PString & message);
00293 
00296   void SendSoundMessage(PBYTEArray *sound);
00297   
00299   void SendTransferMessage();
00300   
00302   void SendQuelchMessage();
00303   
00305   void SendUnQuelchMessage();
00306   
00308   void IncAudioFramesSent()   { ++audioFramesSent; }
00309   
00311   void IncAudioFramesRcvd()   { ++audioFramesRcvd; }
00312   
00314   void IncVideoFramesSent()   { ++videoFramesSent; }
00315   
00317   void IncVideoFramesRcvd()   { ++videoFramesRcvd; }
00318   
00321   void RemoteNodeHasAnswered();
00322   
00326   void CallStopSounds();
00327   
00330   void ReceivedHookFlash();
00331   
00334   void RemoteNodeIsBusy();
00335   
00338   void ProcessIncomingAudioFrame(IAX2Frame *newFrame);
00339   
00342   void ProcessIncomingVideoFrame(IAX2Frame *newFrame);
00343   
00346   void ProcessIaxCmdNew(IAX2FullFrameProtocol *src);
00347   
00350   void ProcessIaxCmdAck(IAX2FullFrameProtocol *src);
00351   
00354   void ProcessIaxCmdHangup(IAX2FullFrameProtocol *src);
00355   
00358   void ProcessIaxCmdReject(IAX2FullFrameProtocol *src);
00359   
00362   void ProcessIaxCmdAccept(IAX2FullFrameProtocol *src);
00363   
00366   void ProcessIaxCmdAuthReq(IAX2FullFrameProtocol *src);
00367   
00370   void ProcessIaxCmdAuthRep(IAX2FullFrameProtocol *src);
00371   
00374   void ProcessIaxCmdInval(IAX2FullFrameProtocol *src);
00375   
00378   void ProcessIaxCmdDpReq(IAX2FullFrameProtocol *src);
00379   
00382   void ProcessIaxCmdDpRep(IAX2FullFrameProtocol *src);
00383   
00386   void ProcessIaxCmdDial(IAX2FullFrameProtocol *src);
00387   
00390   void ProcessIaxCmdTxreq(IAX2FullFrameProtocol *src);
00391   
00394   void ProcessIaxCmdTxcnt(IAX2FullFrameProtocol *src);
00395   
00398   void ProcessIaxCmdTxacc(IAX2FullFrameProtocol *src);
00399   
00402   void ProcessIaxCmdTxready(IAX2FullFrameProtocol *src);
00403   
00406   void ProcessIaxCmdTxrel(IAX2FullFrameProtocol *src);
00407   
00410   void ProcessIaxCmdTxrej(IAX2FullFrameProtocol *src);
00411   
00414   void ProcessIaxCmdQuelch(IAX2FullFrameProtocol *src);
00415   
00418   void ProcessIaxCmdUnquelch(IAX2FullFrameProtocol *src);
00419   
00422   void ProcessIaxCmdPage(IAX2FullFrameProtocol *src);
00423   
00426   void ProcessIaxCmdMwi(IAX2FullFrameProtocol *src);
00427   
00430   void ProcessIaxCmdUnsupport(IAX2FullFrameProtocol *src);
00431   
00434   void ProcessIaxCmdTransfer(IAX2FullFrameProtocol *src);
00435   
00438   void ProcessIaxCmdProvision(IAX2FullFrameProtocol *src);
00439   
00442   void ProcessIaxCmdFwDownl(IAX2FullFrameProtocol *src);
00443   
00446   void ProcessIaxCmdFwData(IAX2FullFrameProtocol *src);
00447 
00454   void ProcessIaxCmdCallToken(IAX2FullFrameProtocol *src);
00455 
00461   IAX2FullFrameProtocol *BuildNewFrameForSending(IAX2FullFrameProtocol *inReplyTo = NULL);
00462   
00464   PAtomicInteger audioFramesSent;
00465   
00467   PAtomicInteger audioFramesRcvd;
00468   
00470   PAtomicInteger videoFramesSent;
00471   
00473   PAtomicInteger videoFramesRcvd;
00474   
00476   SafeString remotePhoneNumber;
00477   
00479   SafeStrings callList;
00480   
00484   SafeString dtmfText;
00485 
00488   SafeStrings textList;
00489 
00491   SafeStrings dtmfNetworkList;
00492 
00494   SafeStrings hangList;
00495   
00497   PBoolean holdCall;
00498   
00500   PBoolean holdReleaseCall;
00501   
00504   IAX2SoundList   soundWaitingForTransmission;
00505   
00511   enum SoundBufferState {
00512     BufferToSmall, 
00513     Normal, 
00514     BufferToBig 
00515   };
00516   
00518   SoundBufferState soundBufferState;
00519   
00522   PINDEX lastFullFrameTimeStamp;
00523     
00525   PBoolean audioCanFlow;
00526 
00529   unsigned int selectedCodec;
00530   
00532   enum CallStatus {
00533     callNewed      =  1 << 0,   
00534     callSentRinging = 1 << 1,   
00535     callRegistered =  1 << 2,   
00536     callAuthorised =  1 << 3,   
00537     callAccepted   =  1 << 4,   
00538     callRinging    =  1 << 5,   
00539     callAnswered   =  1 << 6,   
00540     callTerminating = 1 << 7    
00541   };
00542   
00544   unsigned short callStatus;
00545   
00547   void SetCallSentRinging(PBoolean newValue = true) 
00548     { if (newValue) callStatus |= callSentRinging; else callStatus &= ~callSentRinging; }
00549   
00551   void SetCallNewed(PBoolean newValue = true) 
00552     { if (newValue) callStatus |= callNewed; else callStatus &= ~callNewed; }
00553   
00555   void SetCallRegistered(PBoolean newValue = true) 
00556     { if (newValue) callStatus |= callRegistered; else callStatus &= ~callRegistered; }
00557   
00559   void SetCallAuthorised(PBoolean newValue = true) 
00560     { if (newValue) callStatus |= callAuthorised; else callStatus &= ~callAuthorised; }
00561   
00563   void SetCallAccepted(PBoolean newValue = true) 
00564     { if (newValue) callStatus |= callAccepted; else callStatus &= ~callAccepted; }
00565   
00567   void SetCallRinging(PBoolean newValue = true) 
00568     { if (newValue) callStatus |= callRinging; else callStatus &= ~callRinging; }
00569   
00571   void SetCallAnswered(PBoolean newValue = true) 
00572     { if (newValue) callStatus |= callAnswered; else callStatus &= ~callAnswered; }
00573 
00575   void SetCallTerminating(PBoolean newValue = true) 
00576     { if (newValue) callStatus |= callTerminating; else callStatus &= ~callTerminating; }
00577   
00579   PBoolean IsCallHappening() { return callStatus > 0; }
00580   
00583   PBoolean IsCallNewed() { return callStatus & callNewed; }
00584   
00587   PBoolean IsCallSentRinging() { return callStatus & callSentRinging; }
00588   
00590   PBoolean IsCallRegistered() { return callStatus & callRegistered; }
00591   
00593   PBoolean IsCallAuthorised() { return callStatus & callAuthorised; }
00594   
00596   PBoolean IsCallAccepted() { return callStatus & callAccepted; }
00597   
00599   PBoolean IsCallRinging() { return callStatus & callRinging; }
00600   
00602   PBoolean IsCallAnswered() { return callStatus & callAnswered; }
00603        
00604 #ifdef DOC_PLUS_PLUS
00605 
00611   void OnStatusCheck(PTimer &, INT);
00612 #else
00613   PDECLARE_NOTIFIER(PTimer, IAX2CallProcessor, OnStatusCheck);
00614 #endif
00615   
00617   void DoStatusCheck();
00618   
00621   void RemoteNodeIsRinging();
00622 
00626   void RingingWasAcked();
00627 
00632   void AnswerWasAcked();
00633 
00637   PBoolean firstMediaFrame;
00638 
00641   PBoolean answerCallNow;
00642 
00647   PBoolean statusCheckOtherEnd;
00648 
00650   PTimer statusCheckTimer;
00651 
00654   PINDEX audioFrameDuration;
00655 
00657   PINDEX audioCompressedBytes;
00658 
00662   PBoolean audioFramesNotStarted;
00663 
00666   void CheckForRemoteCapabilities(IAX2FullFrameProtocol *src);
00667   
00670   virtual void OnNoResponseTimeout();
00671   
00673   virtual void ProcessFullFrame(IAX2FullFrame & fullFrame);
00674   
00677   PString callingName;
00678 
00681   PString callingExtension;
00682 
00684   PString callingDnid;
00685 
00688   PString callingContext;
00689 
00693   PString userName;
00694   
00698   PString password;
00699   
00701   PMutex transferMutex;
00702   
00704   PBoolean doTransfer;
00705   
00707   PString transferCalledNumber;
00708   
00710   PString transferCalledContext;    
00711 
00716   PBoolean suppressHangupFrame;
00717 };
00718 
00720 
00721 /* The comment below is magic for those who use emacs to edit this file.
00722  * With the comment below, the tab key does auto indent to 2 spaces.    
00723  *
00724  * Local Variables:
00725  * mode:c
00726  * c-basic-offset:2
00727  * End:
00728  */
00729 
00730 
00731 #endif // OPAL_IAX2
00732 
00733 #endif // OPAL_IAX2_CALLPROCESSOR_H

Generated on 21 Jun 2013 for OPAL by  doxygen 1.4.7