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/buildopts.h>
00117 
00118 #include <opal/connection.h>
00119 
00120 #include <iax2/frame.h>
00121 #include <iax2/iax2jitter.h>
00122 #include <iax2/iedata.h>
00123 #include <iax2/processor.h>
00124 #include <iax2/callprocessor.h>
00125 #include <iax2/safestrings.h>
00126 #include <iax2/sound.h>
00127 
00128 class IAX2EndPoint;
00129 
00130 
00132 
00138 class IAX2Connection : public OpalConnection
00139 { 
00140   PCLASSINFO(IAX2Connection, OpalConnection);
00141   
00142  public:  
00145   
00148   IAX2Connection(
00149     OpalCall & call,             
00150     IAX2EndPoint & endpoint,     
00151     const PString & token,       
00152     void *userData,              
00153     const PString & remoteParty, 
00154     const PString & remotePartyName = PString::Empty() 
00155   );
00156   
00160   ~IAX2Connection();
00162 
00171     virtual bool IsNetworkConnection() const { return true; }
00172 
00180     virtual bool TransferConnection(
00181       const PString & remoteParty 
00182     );
00183 
00202   virtual void OnReleased();
00203 
00214   OpalMediaFormatList GetMediaFormats() const { return remoteMediaFormats; }
00215 
00217   void EndCallNow(
00218       CallEndReason reason = EndedByLocalUser 
00219       );
00220 
00221   OpalConnection::SendUserInputModes GetRealSendUserInputMode() const;
00222 
00224   void SendDtmf(const PString & dtmf);
00225 
00227   virtual PBoolean SendUserInputString(const PString & value );
00228   
00230   virtual PBoolean SendUserInputTone(char tone, unsigned duration );
00231 
00233   PBoolean IsCallTerminating() { return iax2Processor.IsCallTerminating(); }
00234   
00243   virtual void AnsweringCall(
00244                              AnswerCallResponse response 
00245                              );
00246 
00254   void OnConnected();   
00255     
00267   virtual PBoolean SetConnected();
00268 
00283   void OnEstablished();
00284 
00299   virtual void Release( CallEndReason reason = EndedByLocalUser 
00300                 );
00301 
00313   PBoolean SetAlerting(   
00314                        const PString & calleeName,
00315                        PBoolean withMedia  
00316                           ); 
00317      
00325   OpalMediaStream * CreateMediaStream(
00326                                       const OpalMediaFormat & mediaFormat, 
00327                                       unsigned sessionID,
00328                                       PBoolean isSource  
00329                                       );
00330 
00341   void SetCallToken(PString newToken);
00342 
00344   PString GetCallToken() { return iax2Processor.GetCallToken(); }
00345 
00348   void TransmitFrameToRemoteEndpoint(IAX2Frame *src);
00349  
00353   void PutSoundPacketToNetwork(PBYTEArray *sund);
00354 
00357   void ReceivedSoundPacketFromNetwork(IAX2Frame *soundFrame);
00358 
00363   PBoolean ReadSoundPacket(RTP_DataFrame & packet);
00364 
00366   IAX2Remote & GetRemoteInfo() { return iax2Processor.GetRemoteInfo(); }
00367 
00369   IAX2SequenceNumbers & GetSequenceInfo() { return iax2Processor.GetSequenceInfo(); }
00370   
00372   const PTimeInterval & GetCallStartTick() { return iax2Processor.GetCallStartTick(); } 
00373 
00378   void OnSetUp();
00379 
00380   PBoolean OnIncomingCall(
00381     unsigned int options, 
00382     OpalConnection::StringOptions * stringOptions
00383   );
00384 
00385 
00393   PBoolean SetUpConnection();
00394 
00395 
00399   PINDEX GetSupportedCodecs();
00400   
00404   PINDEX GetPreferredCodec();
00405 
00408   void BuildRemoteCapabilityTable(unsigned int remoteCapability, unsigned int format);
00409 
00410      
00418   unsigned int ChooseCodec();
00419   
00421   virtual PBoolean IsConnectionOnHold();
00422   
00424   virtual bool RetrieveConnection();
00425   
00427   virtual bool HoldConnection();
00428   
00430   void RemoteHoldConnection();
00431   
00433   void RemoteRetrieveConnection();
00434 
00441   void SetUserName(PString & inUserName) { userName = inUserName; };
00442   
00444   PString GetUserName() const { return userName; };
00445   
00452   void SetPassword(PString & inPassword) { password = inPassword; };
00453   
00455   PString GetPassword() const { return password; };
00456   
00457     
00467   virtual PBoolean ForwardCall(
00468                                const PString & forwardParty   
00469                                );
00470   
00474   void IncomingEthernetFrame (IAX2Frame *frame);
00475   
00479   //static PBoolean IsStatusQueryEthernetFrame(IAX2Frame *frame);
00480     
00482   IAX2EndPoint & GetEndPoint() { return endpoint; }
00483   
00486   void ReportStatistics();
00487     
00488 
00489  protected:
00490   
00492   PString userName;
00493   
00495   PString password;
00496   
00500 
00502   IAX2EndPoint    &endpoint;
00503 
00506   OpalMediaFormatList remoteMediaFormats;
00507 
00510   OpalMediaFormatList localMediaFormats;
00511     
00513   IAX2CallProcessor & iax2Processor;
00514   
00516   PBoolean            local_hold;
00517   
00519   PBoolean            remote_hold;
00520 
00522 
00525   IAX2JitterBuffer jitterBuffer;
00526   
00534   RTP_DataFrame::PayloadTypes opalPayloadType;
00535 
00536   friend class IAX2CallProcessor;
00537 };
00538 
00539 
00541 
00542 
00543 
00544 #endif // IAX_CONNECTION_H
00545 /* The comment below is magic for those who use emacs to edit this file. */
00546 /* With the comment below, the tab key does auto indent to 2 spaces.     */
00547 
00548 /*
00549  * Local Variables:
00550  * mode:c
00551  * c-basic-offset:2
00552  * End:
00553  */
00554 
00555 
00556 

Generated on Mon Sep 22 12:24:50 2008 for OPAL by  doxygen 1.5.1