lidep.h

Go to the documentation of this file.
00001 /*
00002  * lidep.h
00003  *
00004  * Line Interface Device EndPoint
00005  *
00006  * Open Phone Abstraction Library
00007  *
00008  * Copyright (c) 2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions of this code were written with the assisance of funding from 
00025  * Quicknet Technologies, Inc. http://www.quicknet.net.
00026  * 
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: lidep.h,v $
00030  * Revision 2.28  2007/03/29 05:15:48  csoutheren
00031  * Pass OpalConnection to OpalMediaSream constructor
00032  * Add ID to OpalMediaStreams so that transcoders can match incoming and outgoing codecs
00033  *
00034  * Revision 2.27  2007/03/13 00:32:16  csoutheren
00035  * Simple but messy changes to allow compile time removal of protocol
00036  * options such as H.450 and H.460
00037  * Fix MakeConnection overrides
00038  *
00039  * Revision 2.26  2007/03/01 05:51:03  rjongbloed
00040  * Fixed backward compatibility of OnIncomingConnection() virtual
00041  *   functions on various classes. If an old override returned FALSE
00042  *   then it will now abort the call as it used to.
00043  *
00044  * Revision 2.25  2007/01/24 04:00:56  csoutheren
00045  * Arrrghh. Changing OnIncomingConnection turned out to have a lot of side-effects
00046  * Added some pure viritual functions to prevent old code from breaking silently
00047  * New OpalEndpoint and OpalConnection descendants will need to re-implement
00048  * OnIncomingConnection. Sorry :)
00049  *
00050  * Revision 2.24  2006/12/18 03:18:41  csoutheren
00051  * Messy but simple fixes
00052  *   - Add access to SIP REGISTER timeout
00053  *   - Ensure OpalConnection options are correctly progagated
00054  *
00055  * Revision 2.23  2006/10/22 12:05:56  rjongbloed
00056  * Fixed correct usage of read/write buffer sizes in LID endpoints.
00057  *
00058  * Revision 2.22  2006/08/29 08:47:43  rjongbloed
00059  * Added functions to get average audio signal level from audio streams in
00060  *   suitable connection types.
00061  *
00062  * Revision 2.21  2006/08/17 23:09:03  rjongbloed
00063  * Added volume controls
00064  *
00065  * Revision 2.20  2006/06/27 13:50:24  csoutheren
00066  * Patch 1375137 - Voicetronix patches and lid enhancements
00067  * Thanks to Frederich Heem
00068  *
00069  * Revision 2.19  2006/03/08 10:38:01  csoutheren
00070  * Applied patch #1441139 - virtualise LID functions and kill monitorlines correctly
00071  * Thanks to Martin Yarwood
00072  *
00073  * Revision 2.18  2005/11/30 13:35:26  csoutheren
00074  * Changed tags for Doxygen
00075  *
00076  * Revision 2.17  2004/10/06 13:03:41  rjongbloed
00077  * Added "configure" support for known LIDs
00078  * Changed LID GetName() function to be normalised against the GetAllNames()
00079  *   return values and fixed the pre-factory registration system.
00080  * Added a GetDescription() function to do what the previous GetName() did.
00081  *
00082  * Revision 2.16  2004/08/14 07:56:29  rjongbloed
00083  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00084  *
00085  * Revision 2.15  2004/07/11 12:42:09  rjongbloed
00086  * Added function on endpoints to get the list of all media formats any
00087  *   connection the endpoint may create can support.
00088  *
00089  * Revision 2.14  2004/05/17 13:24:17  rjongbloed
00090  * Added silence suppression.
00091  *
00092  * Revision 2.13  2003/06/02 02:56:17  rjongbloed
00093  * Moved LID specific media stream class to LID source file.
00094  *
00095  * Revision 2.12  2003/03/24 07:18:29  robertj
00096  * Added registration system for LIDs so can work with various LID types by
00097  *   name instead of class instance.
00098  *
00099  * Revision 2.11  2003/03/17 10:26:59  robertj
00100  * Added video support.
00101  *
00102  * Revision 2.10  2003/03/06 03:57:46  robertj
00103  * IVR support (work in progress) requiring large changes everywhere.
00104  *
00105  * Revision 2.9  2002/09/16 02:52:34  robertj
00106  * Added #define so can select if #pragma interface/implementation is used on
00107  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00108  *
00109  * Revision 2.8  2002/09/04 05:27:55  robertj
00110  * Added ability to set default line name to be used when the destination
00111  *   does not match any lines configured.
00112  *
00113  * Revision 2.7  2002/01/22 05:00:54  robertj
00114  * Revamp of user input API triggered by RFC2833 support
00115  *
00116  * Revision 2.6  2001/11/13 06:25:56  robertj
00117  * Changed SetUpConnection() so returns BOOL as returning
00118  *   pointer to connection is not useful.
00119  *
00120  * Revision 2.5  2001/10/15 04:29:35  robertj
00121  * Removed answerCall signal and replaced with state based functions.
00122  *
00123  * Revision 2.4  2001/10/03 05:56:15  robertj
00124  * Changes abndwidth management API.
00125  *
00126  * Revision 2.3  2001/08/17 01:11:52  robertj
00127  * Added ability to add whole LID's to LID endpoint.
00128  * Added ability to change the prefix on POTS and PSTN endpoints.
00129  *
00130  * Revision 2.2  2001/08/01 06:23:55  robertj
00131  * Changed to use separate mutex for LIDs structure to avoid Unix nested mutex problem.
00132  *
00133  * Revision 2.1  2001/08/01 05:18:51  robertj
00134  * Made OpalMediaFormatList class global to help with documentation.
00135  *
00136  * Revision 2.0  2001/07/27 15:48:24  robertj
00137  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00138  *
00139  */
00140 
00141 #ifndef __LIDS_LIDEP_H
00142 #define __LIDS_LIDEP_H
00143 
00144 #ifdef P_USE_PRAGMA
00145 #pragma interface
00146 #endif
00147 
00148 
00149 #include <opal/endpoint.h>
00150 #include <lids/lid.h>
00151 #include <codec/silencedetect.h>
00152 
00153 
00154 class OpalLineConnection;
00155 
00156 
00161 class OpalLIDEndPoint : public OpalEndPoint
00162 {
00163   PCLASSINFO(OpalLIDEndPoint, OpalEndPoint);
00164 
00165   public:
00170     OpalLIDEndPoint(
00171       OpalManager & manager,  
00172       const PString & prefix, 
00173       unsigned attributes     
00174     );
00175 
00177     ~OpalLIDEndPoint();
00179 
00211     virtual BOOL MakeConnection(
00212       OpalCall & call,          
00213       const PString & party,    
00214       void * userData = NULL,   
00215       unsigned int options = 0,  
00216       OpalConnection::StringOptions * stringOptions  = NULL
00217     );
00218 
00222     virtual BOOL OnSetUpConnection(OpalLineConnection &connection);
00223     
00233     virtual OpalMediaFormatList GetMediaFormats() const;
00235 
00238     virtual OpalLineConnection * CreateConnection(
00239       OpalCall & call,        
00240       OpalLine & line,        
00241       void * userData,        
00242       const PString & number  
00243     );
00245 
00252     PSafePtr<OpalLineConnection> GetLIDConnectionWithLock(
00253       const PString & token,     
00254       PSafetyMode mode = PSafeReadWrite
00255     ) { return PSafePtrCast<OpalConnection, OpalLineConnection>(GetConnectionWithLock(token, mode)); }
00256 
00264     BOOL AddLine(
00265       OpalLine * line
00266     );
00267 
00271     void RemoveLine(
00272       OpalLine * line
00273     );
00274 
00275     
00280     const PList<OpalLine> & GetLines() const { return lines;};
00281     
00285     void RemoveLine(
00286       const PString & token
00287     );
00288 
00293     void RemoveAllLines();
00294 
00304     virtual BOOL AddLinesFromDevice(
00305       OpalLineInterfaceDevice & device  
00306     );
00307 
00311     void RemoveLinesFromDevice(
00312       OpalLineInterfaceDevice & device  
00313     );
00314 
00320     BOOL AddDeviceNames(
00321       const PStringArray & descriptors  
00322     );
00323 
00333     BOOL AddDeviceName(
00334       const PString & descriptor  
00335     );
00336 
00348     virtual BOOL AddDevice(
00349       OpalLineInterfaceDevice * device    
00350     );
00351 
00355     void RemoveDevice(
00356       OpalLineInterfaceDevice * device  
00357     );
00358 
00366     OpalLine * GetLine(
00367       const PString & lineName,  
00368       BOOL enableAudio = FALSE   
00369     ) const;
00370 
00374     void SetDefaultLine(
00375       const PString & lineName  
00376     );
00378 
00379 
00380   protected:
00381     PDECLARE_NOTIFIER(PThread, OpalLIDEndPoint, MonitorLines);
00382     virtual void MonitorLine(OpalLine & line);
00383 
00384     OpalLIDList  devices;
00385     OpalLineList lines;
00386     PString      defaultLine;
00387     PMutex       linesMutex;
00388     PThread    * monitorThread;
00389     PSyncPoint   exitFlag;
00390 };
00391 
00392 
00397 class OpalPSTNEndPoint : public OpalLIDEndPoint
00398 {
00399   PCLASSINFO(OpalLIDEndPoint, OpalLIDEndPoint);
00400 
00401   public:
00406     OpalPSTNEndPoint(
00407       OpalManager & manager,  
00408       const char * prefix = "pstn" 
00409     ) : OpalLIDEndPoint(manager, prefix, HasLineInterface) { }
00411 };
00412 
00413 
00418 class OpalPOTSEndPoint : public OpalLIDEndPoint
00419 {
00420   PCLASSINFO(OpalPOTSEndPoint, OpalLIDEndPoint);
00421 
00422   public:
00427     OpalPOTSEndPoint(
00428       OpalManager & manager,  
00429       const char * prefix = "pots" 
00430     ) : OpalLIDEndPoint(manager, prefix, CanTerminateCall) { }
00432 };
00433 
00434 
00437 class OpalLineConnection : public OpalConnection
00438 {
00439   PCLASSINFO(OpalLineConnection, OpalConnection);
00440 
00441   public:
00446     OpalLineConnection(
00447       OpalCall & call,              
00448       OpalLIDEndPoint & endpoint,   
00449       OpalLine & line,              
00450       const PString & number        
00451     );
00453 
00462     virtual BOOL SetUpConnection();
00466     virtual BOOL OnSetUpConnection();
00467 
00478     virtual BOOL SetAlerting(
00479       const PString & calleeName,   
00480       BOOL withMedia                
00481     );
00482 
00487     virtual BOOL SetConnected();
00488 
00507     virtual void OnReleased();
00508 
00515     virtual PString GetDestinationAddress();
00516 
00523     virtual OpalMediaFormatList GetMediaFormats() const;
00524 
00539     virtual OpalMediaStream * CreateMediaStream(
00540       const OpalMediaFormat & mediaFormat, 
00541       unsigned sessionID,                  
00542       BOOL isSource                        
00543     );
00544 
00557     virtual BOOL OnOpenMediaStream(
00558       OpalMediaStream & stream    
00559     );
00560 
00563     virtual BOOL SetAudioVolume(
00564       BOOL source,                  
00565       unsigned percentage           
00566     );
00567 
00571     virtual unsigned GetAudioSignalLevel(
00572       BOOL source                   
00573     );
00574 
00582     virtual BOOL SendUserInputString(
00583       const PString & value                   
00584     );
00585 
00592     virtual BOOL SendUserInputTone(
00593       char tone,    
00594       int duration  
00595     );
00596 
00603     virtual BOOL PromptUserInput(
00604       BOOL play   
00605     );
00607 
00612     void StartIncoming();
00613 
00616     virtual void Monitor(
00617       BOOL offHook
00618     );
00620 
00621 
00625     void setDialDelay(unsigned int uiDialDelay){ m_uiDialDelay = uiDialDelay;};
00626     
00630     unsigned int getDialDelay() const { return m_uiDialDelay;};
00631 
00632         
00633   protected:
00634     OpalLIDEndPoint & endpoint;
00635     OpalLine        & line;
00636     BOOL              wasOffHook;
00637     unsigned          answerRingCount;
00638     BOOL              requireTonesForDial;
00639     /* time in msec to wait between the dial tone detection and dialing the dtmf */
00640     unsigned          m_uiDialDelay; 
00641 
00642     PDECLARE_NOTIFIER(PThread, OpalLineConnection, HandleIncoming);
00643     PThread         * handlerThread;
00644 };
00645 
00646 
00650 class OpalLineMediaStream : public OpalMediaStream
00651 {
00652     PCLASSINFO(OpalLineMediaStream, OpalMediaStream);
00653   public:
00658     OpalLineMediaStream(
00659       OpalLineConnection & conn,
00660       const OpalMediaFormat & mediaFormat, 
00661       unsigned sessionID,                  
00662       BOOL isSource,                       
00663       OpalLine & line                      
00664     );
00666 
00674     virtual BOOL Open();
00675 
00680     virtual BOOL Close();
00681 
00685     virtual BOOL ReadData(
00686       BYTE * data,      
00687       PINDEX size,      
00688       PINDEX & length   
00689     );
00690 
00694     virtual BOOL WriteData(
00695       const BYTE * data,   
00696       PINDEX length,       
00697       PINDEX & written     
00698     );
00699 
00705     virtual BOOL SetDataSize(
00706       PINDEX dataSize  
00707     );
00708 
00712     virtual BOOL IsSynchronous() const;
00714 
00719     OpalLine & GetLine() { return line; }
00721 
00722   protected:
00723     OpalLine & line;
00724     BOOL       useDeblocking;
00725     unsigned   missedCount;
00726     BYTE       lastSID[4];
00727     BOOL       lastFrameWasSignal;
00728 };
00729 
00730 
00731 class OpalLineSilenceDetector : public OpalSilenceDetector
00732 {
00733     PCLASSINFO(OpalLineSilenceDetector, OpalSilenceDetector);
00734   public:
00739     OpalLineSilenceDetector(
00740       OpalLine & line
00741     );
00743 
00754     virtual unsigned GetAverageSignalLevel(
00755       const BYTE * buffer,  
00756       PINDEX size           
00757     );
00759 
00760   protected:
00761     OpalLine & line;
00762 };
00763 
00764 
00765 #endif // __LIDS_LIDEP_H
00766 
00767 
00768 // End of File ///////////////////////////////////////////////////////////////

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