OpenH323 1.18.0
vblasterlid.h
Go to the documentation of this file.
00001 /*
00002  * vblasterlid.h
00003  *
00004  * Creative Labs VOIP Blaster codec interface
00005  *
00006  * Open H323 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  * Contributor(s): ______________________________________.
00025  *
00026  * $Log: vblasterlid.h,v $
00027  * Revision 1.8  2005/11/30 13:05:01  csoutheren
00028  * Changed tags for Doxygen
00029  *
00030  * Revision 1.7  2003/12/03 06:58:30  csoutheren
00031  * More vblaster implementation
00032  *
00033  * Revision 1.6  2003/11/10 12:37:46  csoutheren
00034  * Additional fixes for Fobbit Windows driver
00035  *
00036  * Revision 1.5  2002/09/16 01:14:15  robertj
00037  * Added #define so can select if #pragma interface/implementation is used on
00038  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00039  *
00040  * Revision 1.4  2002/09/03 06:19:37  robertj
00041  * Normalised the multi-include header prevention ifdef/define symbol.
00042  *
00043  * Revision 1.3  2002/08/05 10:03:47  robertj
00044  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00045  *
00046  * Revision 1.2  2002/01/15 07:23:24  craigs
00047  * Added IsDevicePresent command
00048  *
00049  * Revision 1.1  2002/01/15 04:16:32  craigs
00050  * Initial version
00051  *
00052  *
00053  */
00054 
00055 #ifndef __OPAL_VBLASTERLID_H
00056 #define __OPAL_VBLASTERLID_H
00057 
00058 #ifdef P_USE_PRAGMA
00059 #pragma interface
00060 #endif
00061 
00062 
00063 #define HAS_VBLASTER
00064 
00065 #include "lid.h"
00066 #include "h323caps.h"
00067 
00068 #include <ptclib/delaychan.h>
00069 
00070 
00071 
00073 
00074 class VoipBlasterInterface : public PObject
00075 {
00076   PCLASSINFO(VoipBlasterInterface, PObject)
00077   public:
00078     enum Command {
00079       Command_PHONE_OFF  = 0x01, // drop loop current
00080       Command_PHONE_ON   = 0x02, // used on startup
00081       Command_RING_ON    = 0x03, // start ringing
00082       Command_RING_OFF   = 0x04, // used on startup & to stop ringing
00083       Command_VOUT_START = 0x05, // start audio output
00084       Command_VOUT_STOP  = 0x06, // stop audio output
00085       Command_VINP_START = 0x07, // start audio input
00086       Command_VINP_STOP  = 0x08, // stop audio input
00087       Command_UNKNOWN_1  = 0x09, // Unknown (TESTSTART)
00088       Command_UNKNOWN_2  = 0x0a, // Unknown (TESTSTOP)
00089       Command_UNKNOWN_3  = 0x0b, // Unknown (SENDFAXTONE)
00090       Command_HS_OFFHOOK = 0x0c, // Go offhook for headset
00091       Command_HS_ONHOOK  = 0x0d, // Go onhook for headset
00092       Command_SETUP_MODE = 0x0e, // Unknown(goto setup mode)
00093       Command_VOUT_DONE  = 0x0f, // voice in/out off, report output drained
00094       Command_0x10       = 0x10, // Unknown (used in file output, seems ok without)
00095       Command_0x11       = 0x11, // Unknown (used in file output, seems ok without)
00096       Command_MUTE_ON    = 0x12, // Audio mute on
00097       Command_MUTE_OFF   = 0x13, // Audio mute off
00098       Command_VOL_0      = 0x34, // Set volume (min)
00099       Command_VOL_1      = 0x35, // Set volume
00100       Command_VOL_2      = 0x36, // Set volume
00101       Command_VOL_3      = 0x37, // Set volume (default)
00102       Command_VOL_4      = 0x38, // Set volume
00103       Command_VOL_5      = 0x39, // Set volume
00104       Command_VOL_6      = 0x3a, // Set volume (max)
00105     };
00106 
00107     enum Status {
00108       //Status_NONE        = 0x00, // No status
00109       Status_HOOK_OFF    = 0x01, // Offhook
00110       Status_HOOK_ON     = 0x02, // Onhook
00111       //Status_DEBUG       = 0x03, // Not used (DEBUG)
00112       //Status_RINGDETECT  = 0x04, // Not used (RINGDETECT)
00113       Status_RINGING_ON  = 0x05, // Ring started 
00114       Status_RINGING_OFF = 0x06, // Ring stopped
00115       Status_HEADSET_IN  = 0x08, // Headset plugged in
00116       Status_HEADSET_OUT = 0x09, // Headset unplugged
00117       Status_0x0a        = 0x0a, // Unknown (setup accepted?)
00118       Status_VOUT_DONE   = 0x0c, // Voice output done
00119       Status_Empty
00120     };
00121 
00122     VoipBlasterInterface();
00123 
00124     BOOL IsDevicePresent(PINDEX deviceIndex);
00125 
00126     BOOL OpenCommand(PINDEX deviceIndex);
00127     BOOL WriteCommand(Command cmd);
00128     Status ReadStatus(const PTimeInterval dur = 0);
00129     BOOL CloseCommand();
00130 
00131     BOOL OpenData();
00132     BOOL WriteData(const void * data, PINDEX len);
00133     int  ReadData (void * data,       PINDEX len, const PTimeInterval dur = 0);
00134     void Flush(const PTimeInterval wait = 500);
00135     BOOL CloseData();
00136 
00137     PDECLARE_NOTIFIER(PTimer, VoipBlasterInterface, CloseTimeout);
00138 
00139   protected:
00140     PINDEX deviceIndex;
00141 
00142 // Linux specific defines are included here
00143 #ifdef P_LINUX
00144 #endif
00145 
00146 // Windows specific defines are included here
00147 #ifdef _WIN32
00148     enum Pipe {
00149       VoiceOutPipe = 0,
00150       VoiceInPipe  = 1,
00151       CommandPipe  = 2,
00152       StatusPipe   = 3,
00153       NumPipes
00154     };
00155 
00156   protected:
00157     int WritePipe(HANDLE fd, const void *bp, DWORD len);
00158     int ReadPipe (HANDLE fd, void *bp,       DWORD len, const PTimeInterval dur = 0);
00159     BOOL OpenVOIPPipe(Pipe pipeIndex);
00160 
00161     HANDLE pipes[4];
00162 #endif
00163 };
00164 
00166 
00169 class OpalVoipBlasterDevice : public OpalLineInterfaceDevice
00170 {
00171   PCLASSINFO(OpalVoipBlasterDevice, OpalLineInterfaceDevice);
00172 
00173   public:
00174 
00175     enum { DTMFQueueSize = 10 };
00176 
00177     class ByteQueue : public PObject {
00178       PCLASSINFO(ByteQueue, PObject);
00179       public:
00180         ByteQueue(PINDEX size);
00181         int Dequeue();
00182         BOOL Enqueue(BYTE ch);
00183 
00184       protected:
00185         PBYTEArray queue;
00186         PINDEX qLen, qOut, qMax;
00187         PMutex mutex;
00188     };
00189 
00192     OpalVoipBlasterDevice();
00193 
00197     ~OpalVoipBlasterDevice();
00198 
00201     virtual BOOL Open(
00202       const PString & device  
00203     );
00204 
00207     virtual BOOL Close();
00208 
00211     virtual PString GetName() const;
00212 
00215     virtual unsigned GetLineCount()
00216       { return 1; }
00217 
00220     virtual BOOL IsLineTerminal(
00221       unsigned /*line*/   
00222     ) { return TRUE; }
00223 
00224 
00227     virtual BOOL IsLinePresent(
00228       unsigned /*line*/,      
00229       BOOL /*force*/ = FALSE  
00230     )
00231       { return FALSE; }
00232 
00233 
00238     virtual BOOL IsLineOffHook(
00239       unsigned line   
00240     );
00241 
00245     virtual BOOL SetLineOffHook(
00246       unsigned line,        
00247       BOOL newState = TRUE  
00248     );
00249 
00250 
00253     virtual BOOL IsLineRinging(
00254       unsigned line,          
00255       DWORD * cadence = NULL  
00256     );
00257 
00261     virtual BOOL RingLine(
00262       unsigned line,    
00263       DWORD cadence     
00264     );
00265 
00266 
00269     virtual BOOL IsLineDisconnected(
00270       unsigned line,   
00271       BOOL checkForWink = TRUE
00272     );
00273 
00274 
00277     BOOL SetLineToLineDirect(
00278       unsigned line1,   
00279       unsigned line2,   
00280       BOOL connect      
00281     );
00282 
00285     BOOL IsLineToLineDirect(
00286       unsigned line1,   
00287       unsigned line2    
00288     );
00289 
00290 
00293     virtual OpalMediaFormat::List GetMediaFormats() const;
00294 
00297     virtual BOOL SetReadFormat(
00298       unsigned line,    
00299       const OpalMediaFormat & mediaFormat   
00300     );
00301 
00304     virtual BOOL SetWriteFormat(
00305       unsigned line,    
00306       const OpalMediaFormat & mediaFormat   
00307     );
00308 
00311     virtual OpalMediaFormat GetReadFormat(
00312       unsigned line    
00313     );
00314 
00317     virtual OpalMediaFormat GetWriteFormat(
00318       unsigned line    
00319     );
00320 
00331     virtual BOOL SetRawCodec(
00332       unsigned line    
00333     );
00334 
00337     virtual BOOL StopRawCodec(
00338       unsigned line   
00339     );
00340 
00343     virtual BOOL StopReadCodec(
00344       unsigned line   
00345     );
00346 
00349     virtual BOOL StopWriteCodec(
00350       unsigned line   
00351     );
00352 
00356     virtual PINDEX GetReadFrameSize(
00357       unsigned line   
00358     );
00359 
00360     virtual BOOL SetReadFrameSize(unsigned, PINDEX);
00361 
00365     virtual PINDEX GetWriteFrameSize(
00366       unsigned line   
00367     );
00368 
00369     virtual BOOL SetWriteFrameSize(unsigned, PINDEX);
00370 
00373     virtual BOOL ReadFrame(
00374       unsigned line,    
00375       void * buf,       
00376       PINDEX & count    
00377     );
00378 
00381     virtual BOOL WriteFrame(
00382       unsigned line,    
00383       const void * buf, 
00384       PINDEX count,     
00385       PINDEX & written  
00386     );
00387 
00390     virtual unsigned GetAverageSignalLevel(
00391       unsigned line,  
00392       BOOL playback   
00393     );
00394 
00395 
00398     virtual BOOL EnableAudio(
00399       unsigned line,      
00400       BOOL enable = TRUE
00401     );
00402 
00403 
00408     virtual BOOL SetRecordVolume(
00409       unsigned line,    
00410       unsigned volume   
00411     );
00412 
00417     virtual BOOL SetPlayVolume(
00418       unsigned line,    
00419       unsigned volume   
00420     );
00421 
00426     virtual BOOL GetRecordVolume(
00427       unsigned line,      
00428       unsigned & volume   
00429     );
00430 
00435     virtual BOOL GetPlayVolume(
00436       unsigned line,      
00437       unsigned & volume   
00438     );
00439 
00440 
00443     AECLevels GetAEC(
00444       unsigned line    
00445     );
00446 
00449     BOOL SetAEC(
00450       unsigned line,    
00451       AECLevels level  
00452     );
00453 
00454 
00458     virtual BOOL GetVAD(
00459       unsigned line    
00460     );
00461 
00465     virtual BOOL SetVAD(
00466       unsigned line,    
00467       BOOL enable       
00468     );
00469 
00470 
00478     virtual BOOL GetCallerID(
00479       unsigned line,      
00480       PString & idString, 
00481       BOOL full = FALSE   
00482     );
00483 
00492     virtual BOOL SetCallerID(
00493       unsigned line,            
00494       const PString & idString  
00495     );
00496 
00499     virtual BOOL SendCallerIDOnCallWaiting(
00500       unsigned line,            
00501       const PString & idString  
00502     );
00503 
00506     virtual BOOL SendVisualMessageWaitingIndicator(
00507       unsigned line,            
00508       BOOL on
00509     );
00510 
00511 
00512 
00516     virtual BOOL PlayDTMF(
00517       unsigned line,            
00518       const char * digits,      
00519       DWORD onTime = DefaultDTMFOnTime,  
00520       DWORD offTime = DefaultDTMFOffTime 
00521     );
00522 
00528     virtual char ReadDTMF(
00529       unsigned line   
00530     );
00531 
00536     virtual BOOL GetRemoveDTMF(
00537       unsigned line            
00538     );
00539 
00544     virtual BOOL SetRemoveDTMF(
00545       unsigned line,            
00546       BOOL removeTones   
00547     );
00548 
00549 
00552     virtual unsigned IsToneDetected(
00553       unsigned line   
00554     );
00555 
00558     virtual BOOL PlayTone(
00559       unsigned line,          
00560       CallProgressTones tone  
00561     );
00562 
00565     virtual BOOL IsTonePlaying(
00566       unsigned line   
00567     );
00568 
00571     virtual BOOL StopTone(
00572       unsigned line   
00573     );
00574 
00577     virtual BOOL HasHookFlash(unsigned line);
00578 
00584     virtual BOOL SetCountryCode(
00585       T35CountryCodes country   
00586     );
00587 
00588 
00591     virtual DWORD GetSerialNumber();
00592 
00595     static PStringArray GetDeviceNames();
00596 
00600     PDECLARE_NOTIFIER(PThread, OpalVoipBlasterDevice, StatusHandler);
00601 
00602   protected:
00603     void HandleStatus(int status);
00604 
00605     PThread * statusThread;
00606     BOOL statusRunning;
00607     BOOL hookState;
00608     BOOL headset;
00609     BOOL ringOn;
00610     BOOL firstTime;
00611 
00612     ByteQueue dtmfQueue;
00613 
00614     PAdaptiveDelay writeDelay;
00615     PAdaptiveDelay readDelay;
00616 
00617     PString   deviceName;
00618     PMutex    readMutex, writeMutex;
00619     BOOL      readStopped, writeStopped;
00620     PINDEX    readFrameSize, writeFrameSize;
00621     PINDEX    readCodecType, writeCodecType;
00622     BOOL      lastHookStatus;
00623 
00624     PMutex               vbMutex;
00625     VoipBlasterInterface vBlaster;
00626 };
00627 
00628 
00629 #endif // __OPAL_VBLASTERLID_H
00630 
00631