OpenH323 1.18.0
ixjlid.h
Go to the documentation of this file.
00001 /*
00002  * ixjlid.h
00003  *
00004  * QuickNet Internet Phone/Line JACK codec interface
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1999-2000 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: ixjlid.h,v $
00030  * Revision 1.68.2.1  2006/03/02 11:12:52  csoutheren
00031  * Backport gcc 4.1.0 fix from CVS head
00032  *
00033  * Revision 1.69  2006/03/02 05:49:44  csoutheren
00034  * Fix for gcc 4.1.0
00035  *
00036  * Revision 1.68  2005/11/30 13:05:01  csoutheren
00037  * Changed tags for Doxygen
00038  *
00039  * Revision 1.67  2004/08/22 04:21:06  csoutheren
00040  * Added compiler.h for new glibc
00041  * Thanks to Klaus Kaempf
00042  *
00043  * Revision 1.66  2004/04/25 09:08:25  rjongbloed
00044  * Fixed being able to link of system does not have IxJ LID configured.
00045  *
00046  * Revision 1.65  2004/01/31 13:13:22  csoutheren
00047  * Fixed problem with HAS_IXJ being tested but not included
00048  *
00049  * Revision 1.64  2003/10/27 20:27:37  dereksmithies
00050  * Add log scale methods for audio.
00051  *
00052  * Revision 1.63  2003/04/29 08:27:47  robertj
00053  * Cleaned up documentation for new wink duration functions.
00054  *
00055  * Revision 1.62  2003/04/28 01:47:53  dereks
00056  * Add ability to set/get wink duration for ixj device.
00057  *
00058  * Revision 1.61  2002/11/06 04:03:38  dereks
00059  * Improve docs for  SetToneFilterParameters().
00060  *
00061  * Revision 1.60  2002/11/05 04:26:21  robertj
00062  * Imported RingLine() by array from OPAL.
00063  *
00064  * Revision 1.59  2002/09/16 01:14:15  robertj
00065  * Added #define so can select if #pragma interface/implementation is used on
00066  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00067  *
00068  * Revision 1.58  2002/09/03 06:19:37  robertj
00069  * Normalised the multi-include header prevention ifdef/define symbol.
00070  *
00071  * Revision 1.57  2002/08/05 10:03:47  robertj
00072  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00073  *
00074  * Revision 1.56  2002/05/09 06:26:30  robertj
00075  * Added fuction to get the current audio enable state for line in device.
00076  * Changed IxJ EnableAudio() semantics so is exclusive, no direct switching
00077  *   from PSTN to POTS and vice versa without disabling the old one first.
00078  *
00079  * Revision 1.55  2001/09/24 12:31:35  robertj
00080  * Added backward compatibility with old drivers.
00081  *
00082  * Revision 1.54  2001/07/19 05:54:27  robertj
00083  * Updated interface to xJACK drivers to utilise cadence and filter functions
00084  *   for dial tone, busy tone and ringback tone detection.
00085  *
00086  * Revision 1.53  2001/05/21 06:36:46  craigs
00087  * Changed to allow optional wink detection for line disconnect
00088  *
00089  * Revision 1.52  2001/03/29 23:38:48  robertj
00090  * Added ability to get average signal level for both receive and transmit.
00091  *
00092  * Revision 1.51  2001/02/09 05:16:24  robertj
00093  * Added #pragma interface for GNU C++.
00094  *
00095  * Revision 1.50  2001/01/25 07:27:14  robertj
00096  * Major changes to add more flexible OpalMediaFormat class to normalise
00097  *   all information about media types, especially codecs.
00098  *
00099  * Revision 1.49  2001/01/24 05:34:49  robertj
00100  * Altered volume control range to be percentage, ie 100 is max volume.
00101  *
00102  * Revision 1.48  2000/12/19 06:38:57  robertj
00103  * Fixed missing virtual on IsTonePlaying() function.
00104  *
00105  * Revision 1.47  2000/12/11 01:47:28  robertj
00106  * Changed to use built PWLib class for overlapped I/O.
00107  *
00108  * Revision 1.46  2000/12/11 00:16:51  robertj
00109  * Removed unused filter/cadence function.
00110  *
00111  * Revision 1.45  2000/12/05 11:29:31  craigs
00112  * Fixed problem with DTMF signal by adding queue for DTMF digits
00113  *
00114  * Revision 1.44  2000/12/04 23:30:02  craigs
00115  * Added better initialisation of Quicknet devices
00116  *
00117  * Revision 1.43  2000/11/30 21:28:47  eokerson
00118  * Fixed DTMF signal handling to stop polling ixj driver.
00119  *
00120  * Revision 1.42  2000/11/30 08:48:35  robertj
00121  * Added functions to enable/disable Voice Activity Detection in LID's
00122  *
00123  * Revision 1.41  2000/11/27 10:30:01  craigs
00124  * Added SetRawCodec function
00125  *
00126  * Revision 1.40  2000/11/27 00:12:17  robertj
00127  * Added WIN32 version of hook flash detection function.
00128  *
00129  * Revision 1.39  2000/11/26 23:12:18  craigs
00130  * Added hook flash detection API
00131  *
00132  * Revision 1.38  2000/11/24 11:18:36  robertj
00133  * Don't need special raw modes for Linux drivers ... yet.
00134  *
00135  * Revision 1.37  2000/11/24 10:50:13  robertj
00136  * Added a raw PCM dta mode for generating/detecting standard tones.
00137  * Modified the ReadFrame/WriteFrame functions to allow for variable length codecs.
00138  * Fixed hook state debouncing.
00139  * Added codec to explicitly set LineJACK mixer settings to avoid funny modes
00140  *    the driver/hardware gets into sometimes.
00141  *
00142  * Revision 1.36  2000/11/20 03:15:13  craigs
00143  * Changed tone detection API slightly to allow detection of multiple
00144  * simultaneous tones
00145  * Added fax CNG tone to tone list
00146  *
00147  * Revision 1.35  2000/11/12 22:34:32  craigs
00148  * Changed Linux driver interface code to use signals
00149  *
00150  * Revision 1.34  2000/11/06 06:33:20  robertj
00151  * Changed hook state debounce so does not block for 200ms.
00152  *
00153  * Revision 1.33  2000/11/03 06:22:48  robertj
00154  * Added flag to IsLinePresent() to force slow test, guarenteeing correct value.
00155  *
00156  * Revision 1.32  2000/10/23 05:39:07  craigs
00157  * Added access to exception detection on Unix
00158  * Fixed problem with detecting available devices when
00159  * devices with lower ordinals were used
00160  *
00161  * Revision 1.31  2000/10/19 04:12:13  robertj
00162  * Added enum for xJACK card types.
00163  *
00164  * Revision 1.30  2000/10/19 04:00:35  robertj
00165  * Added functions to get xJACK card type and serial number.
00166  *
00167  * Revision 1.29  2000/10/13 02:21:40  robertj
00168  * Changed volume control code to set more mixer values on LineJACK.
00169  *
00170  * Revision 1.28  2000/09/25 23:59:42  craigs
00171  * Finally got G.728 working on boards which use the 8021
00172  * Added better handling for wink exceptions
00173  *
00174  * Revision 1.27  2000/09/22 01:35:03  robertj
00175  * Added support for handling LID's that only do symmetric codecs.
00176  *
00177  * Revision 1.26  2000/09/13 09:26:28  rogerh
00178  * Add location of FreeBSD header files
00179  *
00180  * Revision 1.25  2000/09/08 06:43:42  craigs
00181  * Added additional ioctl debugging
00182  * Added attempt to reduce ioctl count for hookstate monitoring
00183  *
00184  * Revision 1.24  2000/08/31 13:14:39  craigs
00185  * Added functions to LID
00186  * More bulletproofing to Linux driver
00187  *
00188  * Revision 1.23  2000/07/28 06:29:20  robertj
00189  * Fixed AEC under Win32 so can be changed from other processes.
00190  *
00191  * Revision 1.22  2000/06/22 02:47:12  craigs
00192  * Improved PSTN ring detection
00193  *
00194  * Revision 1.21  2000/06/17 09:34:45  robertj
00195  * Put back variables mistakenly thought to be Linux specific.
00196  *
00197  * Revision 1.20  2000/06/17 04:11:13  craigs
00198  * Fixed problem with potential codec startup problem in Linux IXJ driver
00199  * Moved Linux specific variables to Linux specific section
00200  *
00201  * Revision 1.19  2000/05/24 06:42:18  craigs
00202  * Added calls to get volume settings
00203  *
00204  * Revision 1.18  2000/05/02 04:32:24  robertj
00205  * Fixed copyright notice comment.
00206  *
00207  * Revision 1.17  2000/04/13 23:09:38  craigs
00208  * Fixed problem with callerId on some systems
00209  *
00210  * Revision 1.16  2000/04/06 20:36:25  robertj
00211  * Fixed some LineJACK compatbility problems (eg DTMF detect stopping).
00212  *
00213  * Revision 1.15  2000/04/06 19:37:50  craigs
00214  * Normalised bask to HAS_IXJ
00215  *
00216  * Revision 1.14  2000/04/06 19:29:04  craigs
00217  * Removed all vestiges of the old IXJ driver
00218  *
00219  * Revision 1.13  2000/04/06 17:49:40  craigs
00220  * Removed LINUX_TELEPHONY. Again.
00221  *
00222  * Revision 1.12  2000/04/05 18:04:12  robertj
00223  * Changed caller ID code for better portability.
00224  *
00225  * Revision 1.11  2000/04/05 16:28:05  craigs
00226  * Added caller ID function
00227  *
00228  * Revision 1.10  2000/03/29 20:46:47  robertj
00229  * Added function on LID to get available codecs.
00230  *
00231  * Revision 1.9  2000/03/28 03:47:12  craigs
00232  * Added stuff to stop tone playing from going wrong
00233  *
00234  * Revision 1.8  2000/03/22 17:18:48  robertj
00235  * Changed default DTMF tone string times.
00236  *
00237  * Revision 1.7  2000/03/17 20:58:51  robertj
00238  * Fixed line count to be xJACK card dependent.
00239  *
00240  * Revision 1.6  2000/03/14 11:20:49  rogerh
00241  * Compile the ixj code on FreeBSD. This is needed for openphone support.
00242  *
00243  * Revision 1.5  2000/02/22 09:44:33  robertj
00244  * Fixed compatibility with Linux systems not yet with the Linux Telephony code.
00245  *
00246  * Revision 1.4  2000/01/07 10:01:26  robertj
00247  * GCC/Linux compatibility
00248  *
00249  * Revision 1.3  2000/01/07 08:28:09  robertj
00250  * Additions and changes to line interface device base class.
00251  *
00252  * Revision 1.2  1999/12/24 00:28:03  robertj
00253  * Changes to IXJ interface to follow LID abstraction
00254  *
00255  * Revision 1.1  1999/12/23 23:02:35  robertj
00256  * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
00257  *
00258  */
00259 
00260 #ifndef __OPAL_IXJLID_H
00261 #define __OPAL_IXJLID_H
00262 
00263 #ifdef P_USE_PRAGMA
00264 #pragma interface
00265 #endif
00266 
00267 #include "openh323buildopts.h"
00268 
00269 #ifdef HAS_IXJ
00270 
00271 #include "lid.h"
00272 #include "h323caps.h"
00273 
00274 
00275 #ifdef P_LINUX
00276 #include <linux/telephony.h>
00277 #include <linux/ixjuser.h>
00278 #endif
00279 
00280 #ifdef P_FREEBSD
00281 #include <sys/telephony.h>
00282 #include <sys/ixjuser.h>
00283 #endif
00284 
00285 
00286 
00288 
00291 class OpalIxJDevice : public OpalLineInterfaceDevice
00292 {
00293   PCLASSINFO(OpalIxJDevice, OpalLineInterfaceDevice);
00294 
00295   enum { MaxIxjDevices = 10 };
00296 
00297   public:
00300     OpalIxJDevice();
00301 
00305     ~OpalIxJDevice() { Close(); }
00306 
00309     virtual BOOL Open(
00310       const PString & device  
00311     );
00312 
00315     virtual BOOL Close();
00316 
00319     virtual PString GetName() const;
00320 
00321 
00322     enum {
00323       POTSLine,
00324       PSTNLine,
00325       NumLines
00326     };
00327 
00330     virtual unsigned GetLineCount();
00331 
00332 
00335     virtual BOOL IsLineTerminal(
00336       unsigned line   
00337     ) { return line == POTSLine; }
00338 
00339 
00342     virtual BOOL IsLinePresent(
00343       unsigned line,      
00344       BOOL force = FALSE  
00345     );
00346 
00347 
00352     virtual BOOL IsLineOffHook(
00353       unsigned line   
00354     );
00355 
00359     virtual BOOL SetLineOffHook(
00360       unsigned line,        
00361       BOOL newState = TRUE  
00362     );
00363 
00364 
00367     virtual BOOL IsLineRinging(
00368       unsigned line,          
00369       DWORD * cadence = NULL  
00370     );
00371 
00375     virtual BOOL RingLine(
00376       unsigned line,    
00377       DWORD cadence     
00378     );
00379 
00394     virtual BOOL RingLine(
00395       unsigned line,     
00396       PINDEX nCadence,   
00397       unsigned * pattern 
00398     );
00399 
00400 
00403     virtual BOOL IsLineDisconnected(
00404       unsigned line,   
00405       BOOL checkForWink = TRUE
00406     );
00407 
00408 
00411     BOOL SetLineToLineDirect(
00412       unsigned line1,   
00413       unsigned line2,   
00414       BOOL connect      
00415     );
00416 
00419     BOOL IsLineToLineDirect(
00420       unsigned line1,   
00421       unsigned line2    
00422     );
00423 
00424 
00427     virtual OpalMediaFormat::List GetMediaFormats() const;
00428 
00431     virtual BOOL SetReadFormat(
00432       unsigned line,    
00433       const OpalMediaFormat & mediaFormat   
00434     );
00435 
00438     virtual BOOL SetWriteFormat(
00439       unsigned line,    
00440       const OpalMediaFormat & mediaFormat   
00441     );
00442 
00445     virtual OpalMediaFormat GetReadFormat(
00446       unsigned line    
00447     );
00448 
00451     virtual OpalMediaFormat GetWriteFormat(
00452       unsigned line    
00453     );
00454 
00465     virtual BOOL SetRawCodec(
00466       unsigned line    
00467     );
00468 
00471     virtual BOOL StopRawCodec(
00472       unsigned line   
00473     );
00474 
00477     virtual BOOL StopReadCodec(
00478       unsigned line   
00479     );
00480 
00483     virtual BOOL StopWriteCodec(
00484       unsigned line   
00485     );
00486 
00490     virtual PINDEX GetReadFrameSize(
00491       unsigned line   
00492     );
00493 
00494     virtual BOOL SetReadFrameSize(unsigned, PINDEX);
00495 
00499     virtual PINDEX GetWriteFrameSize(
00500       unsigned line   
00501     );
00502 
00503     virtual BOOL SetWriteFrameSize(unsigned, PINDEX);
00504 
00507     virtual BOOL ReadFrame(
00508       unsigned line,    
00509       void * buf,       
00510       PINDEX & count    
00511     );
00512 
00515     virtual BOOL WriteFrame(
00516       unsigned line,    
00517       const void * buf, 
00518       PINDEX count,     
00519       PINDEX & written  
00520     );
00521 
00524     virtual unsigned GetAverageSignalLevel(
00525       unsigned line,  
00526       BOOL playback   
00527     );
00528 
00529 
00532     virtual BOOL EnableAudio(
00533       unsigned line,      
00534       BOOL enable = TRUE
00535     );
00536 
00539     virtual BOOL IsAudioEnabled(
00540       unsigned line      
00541     );
00542 
00543 
00548     virtual BOOL SetRecordVolume(
00549       unsigned line,    
00550       unsigned volume   
00551     );
00552 
00557     virtual BOOL SetPlayVolume(
00558       unsigned line,    
00559       unsigned volume   
00560     );
00561 
00566     virtual BOOL GetRecordVolume(
00567       unsigned line,      
00568       unsigned & volume   
00569     );
00570 
00575     virtual BOOL GetPlayVolume(
00576       unsigned line,      
00577       unsigned & volume   
00578     );
00579 
00582     AECLevels GetAEC(
00583       unsigned line    
00584     );
00585 
00588     BOOL SetAEC(
00589       unsigned line,    
00590       AECLevels level   
00591     );
00592 
00596     unsigned GetWinkDuration(
00597       unsigned line    
00598     );
00599 
00603     BOOL SetWinkDuration(
00604       unsigned line,        
00605       unsigned winkDuration 
00606     );
00607 
00611     virtual BOOL GetVAD(
00612       unsigned line    
00613     );
00614 
00618     virtual BOOL SetVAD(
00619       unsigned line,    
00620       BOOL enable       
00621     );
00622 
00623 
00631     virtual BOOL GetCallerID(
00632       unsigned line,      
00633       PString & idString, 
00634       BOOL full = FALSE   
00635     );
00636 
00645     virtual BOOL SetCallerID(
00646       unsigned line,            
00647       const PString & idString  
00648     );
00649 
00652     virtual BOOL SendCallerIDOnCallWaiting(
00653       unsigned line,            
00654       const PString & idString  
00655     );
00656 
00659     virtual BOOL SendVisualMessageWaitingIndicator(
00660       unsigned line,            
00661       BOOL on
00662     );
00663 
00664 
00665 
00669     virtual BOOL PlayDTMF(
00670       unsigned line,            
00671       const char * digits,      
00672       DWORD onTime = DefaultDTMFOnTime,  
00673       DWORD offTime = DefaultDTMFOffTime 
00674     );
00675 
00681     virtual char ReadDTMF(
00682       unsigned line   
00683     );
00684 
00689     virtual BOOL GetRemoveDTMF(
00690       unsigned line            
00691     );
00692 
00697     virtual BOOL SetRemoveDTMF(
00698       unsigned line,            
00699       BOOL removeTones   
00700     );
00701 
00702 
00705     virtual unsigned IsToneDetected(
00706       unsigned line   
00707     );
00708 
00714     virtual BOOL SetToneFilterParameters(
00715       unsigned line,            
00716       CallProgressTones tone,   
00717       unsigned lowFrequency,    
00718       unsigned highFrequency,   
00719       PINDEX numCadences,       
00720       const unsigned * onTimes, 
00721       const unsigned * offTimes 
00722     );
00723 
00726     virtual BOOL PlayTone(
00727       unsigned line,          
00728       CallProgressTones tone  
00729     );
00730 
00733     virtual BOOL IsTonePlaying(
00734       unsigned line   
00735     );
00736 
00739     virtual BOOL StopTone(
00740       unsigned line   
00741     );
00742 
00745     virtual BOOL HasHookFlash(unsigned line);
00746 
00752     virtual BOOL SetCountryCode(
00753       T35CountryCodes country   
00754     );
00755 
00756 
00759     virtual DWORD GetSerialNumber();
00760 
00761     enum CardTypes {
00762       PhoneJACK = 1,
00763       LineJACK = 3,
00764       PhoneJACK_Lite,
00765       PhoneJACK_PCI,
00766       PhoneCARD,
00767       PhoneJACK_PCI_TJ
00768     };
00769 
00772     DWORD GetCardType() const { return dwCardType; }
00773 
00774 
00777     static PStringArray GetDeviceNames();
00778 
00779 
00780   protected:
00781 
00782     PINDEX    LogScaleVolume(unsigned line, PINDEX volume, BOOL isPlay);
00783 
00784     PString   deviceName;
00785     DWORD     dwCardType;
00786     PMutex    readMutex, writeMutex;
00787     BOOL      readStopped, writeStopped;
00788     PINDEX    readFrameSize, writeFrameSize;
00789     PINDEX    readCodecType, writeCodecType;
00790     BOOL      lastHookState, currentHookState;
00791     PTimer    hookTimeout;
00792     BOOL      inRawMode;
00793     unsigned  enabledAudioLine;
00794     BOOL      exclusiveAudioMode;
00795 
00796 #if defined(WIN32)
00797     BOOL InternalSetVolume(BOOL record, unsigned id, int volume, int mute);
00798     BOOL InternalPlayTone(unsigned line,
00799                           DWORD toneIndex,
00800                           DWORD onTime, DWORD offTime,
00801                           BOOL synchronous);
00802     BOOL IoControl(DWORD dwIoControlCode,
00803                    DWORD inParam = 0,
00804                    DWORD * outParam = NULL);
00805     BOOL IoControl(DWORD dwIoControlCode,
00806                    LPVOID lpInBuffer,
00807                    DWORD nInBufferSize,
00808                    LPVOID lpOutBuffer,
00809                    DWORD nOutBufferSize,
00810                    LPDWORD lpdwBytesReturned,
00811                    PWin32Overlapped * overlap = NULL);
00812 
00813     HANDLE        hDriver;
00814     DWORD         driverVersion;
00815     PTimer        ringTimeout;
00816     DWORD         lastDTMFDigit;
00817     DWORD         lastFlashState;
00818     PTimeInterval toneSendCompletionTime;
00819     BOOL          vadEnabled;
00820     HANDLE        hReadEvent, hWriteEvent;
00821 
00822 #elif defined(HAS_IXJ)
00823 
00824   public:
00825     class ExceptionInfo {
00826       public:
00827         int fd;
00828 
00829         BOOL hasRing;
00830         BOOL hookState;
00831         BOOL hasWink;
00832         BOOL hasFlash;
00833         char dtmf[16];
00834         int dtmfIn;
00835         int dtmfOut;
00836 #ifdef IXJCTL_VMWI
00837         BOOL hasCid;
00838         PHONE_CID cid;
00839 #endif
00840         BOOL filter[4];
00841         BOOL cadence[4];
00842         telephony_exception data;
00843         timeval lastHookChange;
00844     };
00845 
00846     static void SignalHandler(int sig);
00847     ExceptionInfo * GetException();
00848     int GetOSHandle() { return os_handle; }
00849 
00850   protected:
00851     BOOL ConvertOSError(int err);
00852 
00853     static ExceptionInfo exceptionInfo[MaxIxjDevices];
00854     static PMutex        exceptionMutex;
00855     static BOOL          exceptionInit;
00856 
00857     AECLevels aecLevel;
00858     BOOL removeDTMF;
00859     PMutex toneMutex;
00860     BOOL tonePlaying;
00861     PTimer lastRingTime;
00862     BOOL pstnIsOffHook;
00863     BOOL gotWink;
00864     int  userPlayVol, userRecVol;
00865 
00866     int  savedPlayVol, savedRecVol;
00867     AECLevels savedAEC;
00868 
00869 #ifdef IXJCTL_VMWI
00870     PHONE_CID callerIdInfo;
00871 #endif
00872 
00873 #endif
00874 };
00875 
00876 
00877 #endif // HAS_IXJ
00878 
00879 #endif // __OPAL_IXJLID_H
00880 
00881