iax2con.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Inter Asterisk Exchange 2
00004  * 
00005  * Open Phone Abstraction Library (OPAL)
00006  *
00007  * Describes the IAX2 extension of the OpalConnection class.
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  *  $Log: iax2con.h,v $
00028  *  Revision 1.19  2007/08/13 04:24:26  csoutheren
00029  *  Normalise IAX2 answer logic
00030  *
00031  *  Revision 1.18  2007/08/02 23:25:07  dereksmithies
00032  *  Rework iax2 handling of incoming calls. This should ensure that woomera/simpleopal etc
00033  *  will correctly advise on receiving an incoming call.
00034  *
00035  *  Revision 1.17  2007/08/01 02:20:24  dereksmithies
00036  *  Change the way we accept/reject incoming iax2 calls. This change makes us
00037  *  more compliant to the OPAL standard. Thanks Craig for pointing this out.
00038  *
00039  *  Revision 1.16  2007/04/19 06:17:21  csoutheren
00040  *  Fixes for precompiled headers with gcc
00041  *
00042  *  Revision 1.15  2007/01/24 04:00:55  csoutheren
00043  *  Arrrghh. Changing OnIncomingConnection turned out to have a lot of side-effects
00044  *  Added some pure viritual functions to prevent old code from breaking silently
00045  *  New OpalEndpoint and OpalConnection descendants will need to re-implement
00046  *  OnIncomingConnection. Sorry :)
00047  *
00048  *  Revision 1.14  2007/01/18 04:45:16  csoutheren
00049  *  Messy, but simple change to add additional options argument to OpalConnection constructor
00050  *  This allows the provision of non-trivial arguments for connections
00051  *
00052  *  Revision 1.13  2007/01/17 03:48:13  dereksmithies
00053  *  Tidy up comments, remove leaks, improve reporting of packet types.
00054  *
00055  *  Revision 1.12  2007/01/12 02:48:11  dereksmithies
00056  *  Make the iax2callprocessor a more permanent variable in the iax2connection.
00057  *
00058  *  Revision 1.11  2007/01/12 02:39:00  dereksmithies
00059  *  Remove the notion of srcProcessors and dstProcessor lists from the ep.
00060  *  Ensure that the connection looks after the callProcessor.
00061  *
00062  *  Revision 1.10  2007/01/11 03:02:15  dereksmithies
00063  *  Remove the previous audio buffering code, and switch to using the jitter
00064  *  buffer provided in Opal. Reduce the verbosity of the log mesasges.
00065  *
00066  *  Revision 1.9  2006/09/11 03:08:51  dereksmithies
00067  *  Add fixes from Stephen Cook (sitiveni@gmail.com) for new patches to
00068  *  improve call handling. Notably, IAX2 call transfer. Many thanks.
00069  *  Thanks also to the Google summer of code for sponsoring this work.
00070  *
00071  *  Revision 1.8  2006/08/09 03:46:39  dereksmithies
00072  *  Add ability to register to a remote Asterisk box. The iaxProcessor class is split
00073  *  into a callProcessor and a regProcessor class.
00074  *  Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
00075  * 
00076  *  Revision 1.7  2006/06/16 01:47:08  dereksmithies
00077  *  Get the OnHold features of IAX2 to work correctly.
00078  *  Thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
00079  *
00080  *  Revision 1.6  2005/09/05 01:19:43  dereksmithies
00081  *  add patches from Adrian Sietsma to avoid multiple hangup packets at call end,
00082  *  and stop the sending of ping/lagrq packets at call end. Many thanks.
00083  *
00084  *  Revision 1.5  2005/08/26 03:07:38  dereksmithies
00085  *  Change naming convention, so all class names contain the string "IAX2"
00086  *
00087  *  Revision 1.4  2005/08/25 03:26:06  dereksmithies
00088  *  Add patch from Adrian Sietsma to correctly set the packet timestamps under windows.
00089  *  Many thanks.
00090  *
00091  *  Revision 1.3  2005/08/24 04:56:25  dereksmithies
00092  *  Add code from Adrian Sietsma to send FullFrameTexts and FullFrameDtmfs to
00093  *  the remote end.  Many Thanks.
00094  *
00095  *  Revision 1.2  2005/08/04 08:14:17  rjongbloed
00096  *  Fixed Windows build under DevStudio 2003 of IAX2 code
00097  *
00098  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
00099  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
00100  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
00101  *  writing and contributing this code
00102  *
00103  *
00104  *
00105  *
00106  *
00107  */
00108 
00109 #ifndef IAX_CONNECTION_H
00110 #define IAX_CONNECTION_H
00111 
00112 #ifndef _PTLIB_H
00113 #include <ptlib.h>
00114 #endif
00115 
00116 #include <opal/connection.h>
00117 
00118 #include <iax2/frame.h>
00119 #include <iax2/iax2jitter.h>
00120 #include <iax2/iedata.h>
00121 #include <iax2/processor.h>
00122 #include <iax2/callprocessor.h>
00123 #include <iax2/safestrings.h>
00124 #include <iax2/sound.h>
00125 
00126 class IAX2EndPoint;
00127 
00128 
00130 
00136 class IAX2Connection : public OpalConnection
00137 { 
00138   PCLASSINFO(IAX2Connection, OpalConnection);
00139   
00140  public:  
00143   
00146   IAX2Connection(
00147     OpalCall & call,             
00148     IAX2EndPoint & endpoint,     
00149     const PString & token,       
00150     void *userData,              
00151     const PString & remoteParty, 
00152     const PString & remotePartyName = PString::Empty() 
00153   );
00154   
00158   ~IAX2Connection();
00160 
00163   
00167   void IncomingEthernetFrame (IAX2Frame *frame);
00168   
00171   //static BOOL IsStatusQueryEthernetFrame(IAX2Frame *frame);
00172     
00174   IAX2EndPoint & GetEndPoint() { return endpoint; }
00175   
00178   void ReportStatistics();
00179   
00192   void Release( CallEndReason reason = EndedByLocalUser 
00193                 );
00194   
00199   void ClearCall(
00200       CallEndReason reason = EndedByLocalUser 
00201     );
00202 
00204   void EndCallNow(
00205       CallEndReason reason = EndedByLocalUser 
00206       );
00207 
00208   OpalConnection::SendUserInputModes GetRealSendUserInputMode() const;
00209 
00211   void SendDtmf(const PString & dtmf);
00212 
00214   virtual BOOL SendUserInputString(const PString & value );
00215   
00217   virtual BOOL SendUserInputTone(char tone, unsigned duration );
00218 
00219 
00222   void AcceptIncomingCall();
00223   
00224 
00231   virtual void AnsweringCall(AnswerCallResponse response);
00232 
00233 
00235   BOOL IsCallTerminating() { return iax2Processor.IsCallTerminating(); }
00236   
00247   BOOL SetAlerting(
00248                            const PString & calleeName,   
00249                            BOOL withMedia                
00250                            ); 
00251   
00256   BOOL SetConnected();       
00257   
00264   OpalMediaFormatList GetMediaFormats() const { return remoteMediaFormats; }
00265   
00266   
00278   OpalMediaStream * CreateMediaStream(
00279                                       const OpalMediaFormat & mediaFormat, 
00280                                       unsigned sessionID,                  
00281                                       BOOL isSource                        
00282                                       );
00283 
00294   void SetCallToken(PString newToken);
00295 
00297   PString GetCallToken() { return iax2Processor.GetCallToken(); }
00298 
00301   void TransmitFrameToRemoteEndpoint(IAX2Frame *src);
00302  
00306   void PutSoundPacketToNetwork(PBYTEArray *sund);
00307 
00310   void ReceivedSoundPacketFromNetwork(IAX2Frame *soundFrame);
00311 
00316   BOOL ReadSoundPacket(DWORD timestamp, RTP_DataFrame & packet);
00317 
00319   IAX2Remote & GetRemoteInfo() { return iax2Processor.GetRemoteInfo(); }
00320 
00322   IAX2SequenceNumbers & GetSequenceInfo() { return iax2Processor.GetSequenceInfo(); }
00323   
00325   const PTimeInterval & GetCallStartTick() { return iax2Processor.GetCallStartTick(); } 
00326 
00331     virtual void OnSetUp();
00332 
00348   virtual void OnAlerting();
00349 
00350   virtual BOOL OnIncomingCall(
00351     unsigned int options, 
00352     OpalConnection::StringOptions * stringOptions
00353   );
00354 
00364   virtual void OnConnected();
00365   
00377   virtual void OnEstablished();
00378 
00379 
00380 
00399   void OnReleased();
00400 
00401 
00402 
00409   BOOL SetUpConnection();
00410 
00411 
00415   PINDEX GetSupportedCodecs();
00416   
00420   PINDEX GetPreferredCodec();
00421 
00424   void BuildRemoteCapabilityTable(unsigned int remoteCapability, unsigned int format);
00425 
00426      
00434   unsigned int ChooseCodec();
00435   
00437   virtual BOOL IsConnectionOnHold();
00438   
00440   virtual void RetrieveConnection();
00441   
00443   virtual void HoldConnection();
00444   
00446   void RemoteHoldConnection();
00447   
00449   void RemoteRetrieveConnection();
00450 
00457   void SetUserName(PString & inUserName) { userName = inUserName; };
00458   
00460   PString GetUserName() const { return userName; };
00461   
00468   void SetPassword(PString & inPassword) { password = inPassword; };
00469   
00471   PString GetPassword() const { return password; };
00472   
00476   virtual void TransferConnection(
00477     const PString & remoteParty,   
00478     const PString & callIdentity = PString::Empty() 
00479     );
00480     
00490   virtual BOOL ForwardCall(
00491     const PString & forwardParty   
00492   );
00493 
00494  protected:
00495   
00497   PString userName;
00498   
00500   PString password;
00501   
00505 
00507   IAX2EndPoint    &endpoint;
00508 
00511   OpalMediaFormatList remoteMediaFormats;
00512 
00515   OpalMediaFormatList localMediaFormats;
00516     
00518   IAX2CallProcessor & iax2Processor;
00519   
00521   BOOL            local_hold;
00522   
00524   BOOL            remote_hold;
00525 
00527 
00530   IAX2JitterBuffer jitterBuffer;
00531   
00539   RTP_DataFrame::PayloadTypes opalPayloadType;
00540 };
00541 
00542 
00544 
00545 
00546 
00547 #endif // IAX_CONNECTION_H
00548 /* The comment below is magic for those who use emacs to edit this file. */
00549 /* With the comment below, the tab key does auto indent to 2 spaces.     */
00550 
00551 /*
00552  * Local Variables:
00553  * mode:c
00554  * c-file-style:linux
00555  * c-basic-offset:2
00556  * End:
00557  */
00558 
00559 
00560 

Generated on Fri Mar 7 06:33:37 2008 for OPAL by  doxygen 1.5.1