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 
00169     virtual bool IsNetworkConnection() const { return true; }
00170 
00178     virtual bool TransferConnection(
00179       const PString & remoteParty 
00180     );
00181 
00200   virtual void OnReleased();
00201 
00212   OpalMediaFormatList GetMediaFormats() const { return remoteMediaFormats; }
00213 
00215   void EndCallNow(
00216       CallEndReason reason = EndedByLocalUser 
00217       );
00218 
00219   OpalConnection::SendUserInputModes GetRealSendUserInputMode() const;
00220 
00222   void SendDtmf(const PString & dtmf);
00223 
00225   virtual PBoolean SendUserInputString(const PString & value );
00226   
00228   virtual PBoolean SendUserInputTone(char tone, unsigned duration );
00229 
00231   PBoolean IsCallTerminating() { return iax2Processor.IsCallTerminating(); }
00232   
00241   virtual void AnsweringCall(
00242                              AnswerCallResponse response 
00243                              );
00244 
00252   void OnConnected();   
00253     
00265   virtual PBoolean SetConnected();
00266 
00281   void OnEstablished();
00282 
00297   virtual void Release( CallEndReason reason = EndedByLocalUser 
00298                 );
00299 
00311   PBoolean SetAlerting(   
00312                        const PString & calleeName,
00313                        PBoolean withMedia  
00314                           ); 
00315      
00323   OpalMediaStream * CreateMediaStream(
00324                                       const OpalMediaFormat & mediaFormat, 
00325                                       unsigned sessionID,
00326                                       PBoolean isSource  
00327                                       );
00328 
00339   void SetCallToken(PString newToken);
00340 
00342   PString GetCallToken() { return iax2Processor.GetCallToken(); }
00343 
00346   void TransmitFrameToRemoteEndpoint(IAX2Frame *src);
00347  
00351   void PutSoundPacketToNetwork(PBYTEArray *sund);
00352 
00355   void ReceivedSoundPacketFromNetwork(IAX2Frame *soundFrame);
00356 
00361   PBoolean ReadSoundPacket(RTP_DataFrame & packet);
00362 
00364   IAX2Remote & GetRemoteInfo() { return iax2Processor.GetRemoteInfo(); }
00365 
00367   IAX2SequenceNumbers & GetSequenceInfo() { return iax2Processor.GetSequenceInfo(); }
00368   
00370   const PTimeInterval & GetCallStartTick() { return iax2Processor.GetCallStartTick(); } 
00371 
00376   void OnSetUp();
00377 
00378   PBoolean OnIncomingCall(
00379     unsigned int options, 
00380     OpalConnection::StringOptions * stringOptions
00381   );
00382 
00383 
00391   PBoolean SetUpConnection();
00392 
00393 
00397   PINDEX GetSupportedCodecs();
00398   
00402   PINDEX GetPreferredCodec();
00403 
00406   void BuildRemoteCapabilityTable(unsigned int remoteCapability, unsigned int format);
00407 
00408      
00416   unsigned int ChooseCodec();
00417   
00419   virtual PBoolean IsConnectionOnHold();
00420   
00422   virtual bool RetrieveConnection();
00423   
00425   virtual bool HoldConnection();
00426   
00428   void RemoteHoldConnection();
00429   
00431   void RemoteRetrieveConnection();
00432 
00439   void SetUserName(PString & inUserName) { userName = inUserName; };
00440   
00442   PString GetUserName() const { return userName; };
00443   
00450   void SetPassword(PString & inPassword) { password = inPassword; };
00451   
00453   PString GetPassword() const { return password; };
00454   
00455     
00465   virtual PBoolean ForwardCall(
00466                                const PString & forwardParty   
00467                                );
00468   
00472   void IncomingEthernetFrame (IAX2Frame *frame);
00473   
00477   //static PBoolean IsStatusQueryEthernetFrame(IAX2Frame *frame);
00478     
00480   IAX2EndPoint & GetEndPoint() { return endpoint; }
00481   
00484   void ReportStatistics();
00485     
00486 
00487  protected:
00488   
00490   PString userName;
00491   
00493   PString password;
00494   
00498 
00500   IAX2EndPoint    &endpoint;
00501 
00504   OpalMediaFormatList remoteMediaFormats;
00505 
00508   OpalMediaFormatList localMediaFormats;
00509     
00511   IAX2CallProcessor & iax2Processor;
00512   
00514   PBoolean            local_hold;
00515   
00517   PBoolean            remote_hold;
00518 
00520 
00523   IAX2JitterBuffer jitterBuffer;
00524   
00532   RTP_DataFrame::PayloadTypes opalPayloadType;
00533 
00534   friend class IAX2CallProcessor;
00535 };
00536 
00537 
00539 
00540 
00541 
00542 #endif // IAX_CONNECTION_H
00543 /* The comment below is magic for those who use emacs to edit this file. */
00544 /* With the comment below, the tab key does auto indent to 2 spaces.     */
00545 
00546 /*
00547  * Local Variables:
00548  * mode:c
00549  * c-basic-offset:2
00550  * End:
00551  */
00552 
00553 
00554 

Generated on Mon Sep 15 11:49:11 2008 for OPAL by  doxygen 1.5.1