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: 21293 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-10-12 23:24:41 +0000 (Sun, 12 Oct 2008) $
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   
00180   void SetPassword(PString & inPassword) { password = inPassword; };
00181   
00183   PString GetPassword() const { return password; };
00184   
00187   void SendTransfer(
00188     const PString & calledNumber,
00189     const PString & calledContext = PString::Empty());  
00190 
00193   void StartStatusCheckTimer(PINDEX msToWait = 10000 );
00195   
00202   virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff);
00203 
00207   void SendAnswerMessageToRemoteNode();
00208 
00209  protected:
00210   
00212   IAX2Connection * con;
00213 
00218   PBoolean RemoteSelectedCodecOk();
00219  
00223   void CheckForHangupMessages();
00224  
00226   void ProcessNetworkFrame(IAX2Frame * src);
00227   
00230   void ProcessNetworkFrame(IAX2MiniFrame * src);
00231   
00234   void ProcessNetworkFrame(IAX2FullFrame * src);
00235   
00238   void ProcessNetworkFrame(IAX2FullFrameDtmf * src);
00239   
00242   void ProcessNetworkFrame(IAX2FullFrameVoice * src);
00243   
00246   void ProcessNetworkFrame(IAX2FullFrameVideo * src);
00247   
00250   void ProcessNetworkFrame(IAX2FullFrameSessionControl * src);
00251   
00254   void ProcessNetworkFrame(IAX2FullFrameNull * src);
00255   
00261   virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
00262   
00265   void ProcessNetworkFrame(IAX2FullFrameText * src);
00266   
00269   void ProcessNetworkFrame(IAX2FullFrameImage * src);
00270   
00273   void ProcessNetworkFrame(IAX2FullFrameHtml * src);
00274   
00277   void ProcessNetworkFrame(IAX2FullFrameCng * src);
00278   
00281   virtual void ProcessLists();
00282     
00284   void ConnectToRemoteNode(PString & destination);
00285   
00287   void SendDtmfMessage(char message);
00288   
00290   void SendTextMessage(PString & message);
00291 
00294   void SendSoundMessage(PBYTEArray *sound);
00295   
00297   void SendTransferMessage();
00298   
00300   void SendQuelchMessage();
00301   
00303   void SendUnQuelchMessage();
00304   
00306   void IncAudioFramesSent()   { ++audioFramesSent; }
00307   
00309   void IncAudioFramesRcvd()   { ++audioFramesRcvd; }
00310   
00312   void IncVideoFramesSent()   { ++videoFramesSent; }
00313   
00315   void IncVideoFramesRcvd()   { ++videoFramesRcvd; }
00316   
00319   void RemoteNodeHasAnswered();
00320   
00324   void CallStopSounds();
00325   
00328   void ReceivedHookFlash();
00329   
00332   void RemoteNodeIsBusy();
00333   
00336   void ProcessIncomingAudioFrame(IAX2Frame *newFrame);
00337   
00340   void ProcessIncomingVideoFrame(IAX2Frame *newFrame);
00341   
00344   void ProcessIaxCmdNew(IAX2FullFrameProtocol *src);
00345   
00348   void ProcessIaxCmdAck(IAX2FullFrameProtocol *src);
00349   
00352   void ProcessIaxCmdHangup(IAX2FullFrameProtocol *src);
00353   
00356   void ProcessIaxCmdReject(IAX2FullFrameProtocol *src);
00357   
00360   void ProcessIaxCmdAccept(IAX2FullFrameProtocol *src);
00361   
00364   void ProcessIaxCmdAuthReq(IAX2FullFrameProtocol *src);
00365   
00368   void ProcessIaxCmdAuthRep(IAX2FullFrameProtocol *src);
00369   
00372   void ProcessIaxCmdInval(IAX2FullFrameProtocol *src);
00373   
00376   void ProcessIaxCmdDpReq(IAX2FullFrameProtocol *src);
00377   
00380   void ProcessIaxCmdDpRep(IAX2FullFrameProtocol *src);
00381   
00384   void ProcessIaxCmdDial(IAX2FullFrameProtocol *src);
00385   
00388   void ProcessIaxCmdTxreq(IAX2FullFrameProtocol *src);
00389   
00392   void ProcessIaxCmdTxcnt(IAX2FullFrameProtocol *src);
00393   
00396   void ProcessIaxCmdTxacc(IAX2FullFrameProtocol *src);
00397   
00400   void ProcessIaxCmdTxready(IAX2FullFrameProtocol *src);
00401   
00404   void ProcessIaxCmdTxrel(IAX2FullFrameProtocol *src);
00405   
00408   void ProcessIaxCmdTxrej(IAX2FullFrameProtocol *src);
00409   
00412   void ProcessIaxCmdQuelch(IAX2FullFrameProtocol *src);
00413   
00416   void ProcessIaxCmdUnquelch(IAX2FullFrameProtocol *src);
00417   
00420   void ProcessIaxCmdPage(IAX2FullFrameProtocol *src);
00421   
00424   void ProcessIaxCmdMwi(IAX2FullFrameProtocol *src);
00425   
00428   void ProcessIaxCmdUnsupport(IAX2FullFrameProtocol *src);
00429   
00432   void ProcessIaxCmdTransfer(IAX2FullFrameProtocol *src);
00433   
00436   void ProcessIaxCmdProvision(IAX2FullFrameProtocol *src);
00437   
00440   void ProcessIaxCmdFwDownl(IAX2FullFrameProtocol *src);
00441   
00444   void ProcessIaxCmdFwData(IAX2FullFrameProtocol *src);
00445   
00447   PAtomicInteger audioFramesSent;
00448   
00450   PAtomicInteger audioFramesRcvd;
00451   
00453   PAtomicInteger videoFramesSent;
00454   
00456   PAtomicInteger videoFramesRcvd;
00457   
00459   SafeString remotePhoneNumber;
00460   
00462   SafeStrings callList;
00463   
00467   SafeString dtmfText;
00468 
00471   SafeStrings textList;
00472 
00474   SafeStrings dtmfNetworkList;
00475 
00477   SafeStrings hangList;
00478   
00480   PBoolean holdCall;
00481   
00483   PBoolean holdReleaseCall;
00484   
00487   IAX2SoundList   soundWaitingForTransmission;
00488   
00494   enum SoundBufferState {
00495     BufferToSmall, 
00496     Normal, 
00497     BufferToBig 
00498   };
00499   
00501   SoundBufferState soundBufferState;
00502   
00505   PINDEX lastFullFrameTimeStamp;
00506     
00508   PBoolean audioCanFlow;
00509 
00512   unsigned int selectedCodec;
00513   
00515   enum CallStatus {
00516     callNewed      =  1 << 0,   
00517     callSentRinging = 1 << 1,   
00518     callRegistered =  1 << 2,   
00519     callAuthorised =  1 << 3,   
00520     callAccepted   =  1 << 4,   
00521     callRinging    =  1 << 5,   
00522     callAnswered   =  1 << 6,   
00523     callTerminating = 1 << 7    
00524   };
00525   
00527   unsigned short callStatus;
00528   
00530   void SetCallSentRinging(PBoolean newValue = PTrue) 
00531     { if (newValue) callStatus |= callSentRinging; else callStatus &= ~callSentRinging; }
00532   
00534   void SetCallNewed(PBoolean newValue = PTrue) 
00535     { if (newValue) callStatus |= callNewed; else callStatus &= ~callNewed; }
00536   
00538   void SetCallRegistered(PBoolean newValue = PTrue) 
00539     { if (newValue) callStatus |= callRegistered; else callStatus &= ~callRegistered; }
00540   
00542   void SetCallAuthorised(PBoolean newValue = PTrue) 
00543     { if (newValue) callStatus |= callAuthorised; else callStatus &= ~callAuthorised; }
00544   
00546   void SetCallAccepted(PBoolean newValue = PTrue) 
00547     { if (newValue) callStatus |= callAccepted; else callStatus &= ~callAccepted; }
00548   
00550   void SetCallRinging(PBoolean newValue = PTrue) 
00551     { if (newValue) callStatus |= callRinging; else callStatus &= ~callRinging; }
00552   
00554   void SetCallAnswered(PBoolean newValue = PTrue) 
00555     { if (newValue) callStatus |= callAnswered; else callStatus &= ~callAnswered; }
00556 
00558   void SetCallTerminating(PBoolean newValue = PTrue) 
00559     { if (newValue) callStatus |= callTerminating; else callStatus &= ~callTerminating; }
00560   
00562   PBoolean IsCallHappening() { return callStatus > 0; }
00563   
00566   PBoolean IsCallNewed() { return callStatus & callNewed; }
00567   
00570   PBoolean IsCallSentRinging() { return callStatus & callSentRinging; }
00571   
00573   PBoolean IsCallRegistered() { return callStatus & callRegistered; }
00574   
00576   PBoolean IsCallAuthorised() { return callStatus & callAuthorised; }
00577   
00579   PBoolean IsCallAccepted() { return callStatus & callAccepted; }
00580   
00582   PBoolean IsCallRinging() { return callStatus & callRinging; }
00583   
00585   PBoolean IsCallAnswered() { return callStatus & callAnswered; }
00586        
00587 #ifdef DOC_PLUS_PLUS
00588 
00594   void OnStatusCheck(PTimer &, INT);
00595 #else
00596   PDECLARE_NOTIFIER(PTimer, IAX2CallProcessor, OnStatusCheck);
00597 #endif
00598   
00600   void DoStatusCheck();
00601   
00604   void RemoteNodeIsRinging();
00605 
00609   void RingingWasAcked();
00610 
00615   void AnswerWasAcked();
00616 
00620   PBoolean firstMediaFrame;
00621 
00624   PBoolean answerCallNow;
00625 
00630   PBoolean statusCheckOtherEnd;
00631 
00633   PTimer statusCheckTimer;
00634 
00637   PINDEX audioFrameDuration;
00638 
00640   PINDEX audioCompressedBytes;
00641 
00645   PBoolean audioFramesNotStarted;
00646 
00649   void CheckForRemoteCapabilities(IAX2FullFrameProtocol *src);
00650   
00653   virtual void OnNoResponseTimeout();
00654   
00656   virtual void ProcessFullFrame(IAX2FullFrame & fullFrame);
00657   
00661   PString userName;
00662   
00666   PString password;
00667   
00669   PMutex transferMutex;
00670   
00672   PBoolean doTransfer;
00673   
00675   PString transferCalledNumber;
00676   
00678   PString transferCalledContext;    
00679 };
00680 
00682 
00683 /* The comment below is magic for those who use emacs to edit this file. */
00684 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00685 
00686 /*
00687  * Local Variables:
00688  * mode:c
00689  * c-basic-offset:2
00690  * End:
00691  */
00692 
00693 
00694 #endif // OPAL_IAX2
00695 
00696 #endif // OPAL_IAX2_CALLPROCESSOR_H

Generated on Mon Feb 1 00:25:19 2010 for OPAL by  doxygen 1.5.1