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 2.9  2005/11/30 13:35:26  csoutheren
00028  * Changed tags for Doxygen
00029  *
00030  * Revision 2.8  2004/10/06 13:03:41  rjongbloed
00031  * Added "configure" support for known LIDs
00032  * Changed LID GetName() function to be normalised against the GetAllNames()
00033  *   return values and fixed the pre-factory registration system.
00034  * Added a GetDescription() function to do what the previous GetName() did.
00035  *
00036  * Revision 2.7  2004/02/19 10:46:44  rjongbloed
00037  * Merged OpenH323 version 1.13.1 changes.
00038  *
00039  * Revision 2.6  2003/03/24 07:18:29  robertj
00040  * Added registration system for LIDs so can work with various LID types by
00041  *   name instead of class instance.
00042  *
00043  * Revision 2.5  2002/11/10 11:33:17  robertj
00044  * Updated to OpenH323 v1.10.3
00045  *
00046  * Revision 2.4  2002/09/16 02:52:34  robertj
00047  * Added #define so can select if #pragma interface/implementation is used on
00048  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00049  *
00050  * Revision 2.3  2002/09/06 07:20:14  robertj
00051  * Fixed previous update, did not port properly.
00052  *
00053  * Revision 2.2  2002/09/04 06:01:47  robertj
00054  * Updated to OpenH323 v1.9.6
00055  *
00056  * Revision 2.1  2002/01/22 06:28:43  robertj
00057  * Added voice blaster support
00058  *
00059  * Revision 1.7  2003/12/03 06:58:30  csoutheren
00060  * More vblaster implementation
00061  *
00062  * Revision 1.6  2003/11/10 12:37:46  csoutheren
00063  * Additional fixes for Fobbit Windows driver
00064  *
00065  * Revision 1.5  2002/09/16 01:14:15  robertj
00066  * Added #define so can select if #pragma interface/implementation is used on
00067  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00068  *
00069  * Revision 1.4  2002/09/03 06:19:37  robertj
00070  * Normalised the multi-include header prevention ifdef/define symbol.
00071  *
00072  * Revision 1.3  2002/08/05 10:03:47  robertj
00073  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00074  *
00075  * Revision 1.2  2002/01/15 07:23:24  craigs
00076  * Added IsDevicePresent command
00077  *
00078  * Revision 1.1  2002/01/15 04:16:32  craigs
00079  * Initial version
00080  *
00081  *
00082  */
00083 
00084 #ifndef __OPAL_VBLASTERLID_H
00085 #define __OPAL_VBLASTERLID_H
00086 
00087 #ifdef P_USE_PRAGMA
00088 #pragma interface
00089 #endif
00090 
00091 
00092 #include <opal/buildopts.h>
00093 
00094 #ifdef HAS_VBLASTER
00095 
00096 #include <lids/lid.h>
00097 #include <ptclib/delaychan.h>
00098 
00099 
00100 
00102 
00103 class VoipBlasterInterface : public PObject
00104 {
00105   PCLASSINFO(VoipBlasterInterface, PObject)
00106   public:
00107     enum Command {
00108       Command_PHONE_OFF  = 0x01, // drop loop current
00109       Command_PHONE_ON   = 0x02, // used on startup
00110       Command_RING_ON    = 0x03, // start ringing
00111       Command_RING_OFF   = 0x04, // used on startup & to stop ringing
00112       Command_VOUT_START = 0x05, // start audio output
00113       Command_VOUT_STOP  = 0x06, // stop audio output
00114       Command_VINP_START = 0x07, // start audio input
00115       Command_VINP_STOP  = 0x08, // stop audio input
00116       Command_UNKNOWN_1  = 0x09, // Unknown (TESTSTART)
00117       Command_UNKNOWN_2  = 0x0a, // Unknown (TESTSTOP)
00118       Command_UNKNOWN_3  = 0x0b, // Unknown (SENDFAXTONE)
00119       Command_HS_OFFHOOK = 0x0c, // Go offhook for headset
00120       Command_HS_ONHOOK  = 0x0d, // Go onhook for headset
00121       Command_SETUP_MODE = 0x0e, // Unknown(goto setup mode)
00122       Command_VOUT_DONE  = 0x0f, // voice in/out off, report output drained
00123       Command_0x10       = 0x10, // Unknown (used in file output, seems ok without)
00124       Command_0x11       = 0x11, // Unknown (used in file output, seems ok without)
00125       Command_MUTE_ON    = 0x12, // Audio mute on
00126       Command_MUTE_OFF   = 0x13, // Audio mute off
00127       Command_VOL_0      = 0x34, // Set volume (min)
00128       Command_VOL_1      = 0x35, // Set volume
00129       Command_VOL_2      = 0x36, // Set volume
00130       Command_VOL_3      = 0x37, // Set volume (default)
00131       Command_VOL_4      = 0x38, // Set volume
00132       Command_VOL_5      = 0x39, // Set volume
00133       Command_VOL_6      = 0x3a, // Set volume (max)
00134     };
00135 
00136     enum Status {
00137       //Status_NONE        = 0x00, // No status
00138       Status_HOOK_OFF    = 0x01, // Offhook
00139       Status_HOOK_ON     = 0x02, // Onhook
00140       //Status_DEBUG       = 0x03, // Not used (DEBUG)
00141       //Status_RINGDETECT  = 0x04, // Not used (RINGDETECT)
00142       Status_RINGING_ON  = 0x05, // Ring started 
00143       Status_RINGING_OFF = 0x06, // Ring stopped
00144       Status_HEADSET_IN  = 0x08, // Headset plugged in
00145       Status_HEADSET_OUT = 0x09, // Headset unplugged
00146       Status_0x0a        = 0x0a, // Unknown (setup accepted?)
00147       Status_VOUT_DONE   = 0x0c, // Voice output done
00148       Status_Empty
00149     };
00150 
00151     VoipBlasterInterface();
00152 
00153     BOOL IsDevicePresent(PINDEX deviceIndex);
00154 
00155     BOOL OpenCommand(PINDEX deviceIndex);
00156     BOOL WriteCommand(Command cmd);
00157     Status ReadStatus(const PTimeInterval dur = 0);
00158     BOOL CloseCommand();
00159 
00160     BOOL OpenData();
00161     BOOL WriteData(const void * data, PINDEX len);
00162     int  ReadData (void * data,       PINDEX len, const PTimeInterval dur = 0);
00163     void Flush(const PTimeInterval wait = 500);
00164     BOOL CloseData();
00165 
00166     PDECLARE_NOTIFIER(PTimer, VoipBlasterInterface, CloseTimeout);
00167 
00168   protected:
00169     PINDEX deviceIndex;
00170 
00171 // Linux specific defines are included here
00172 #ifdef P_LINUX
00173 #endif
00174 
00175 // Windows specific defines are included here
00176 #ifdef _WIN32
00177     enum Pipe {
00178       VoiceOutPipe = 0,
00179       VoiceInPipe  = 1,
00180       CommandPipe  = 2,
00181       StatusPipe   = 3,
00182       NumPipes
00183     };
00184 
00185   protected:
00186     int WritePipe(HANDLE fd, const void *bp, DWORD len);
00187     int ReadPipe (HANDLE fd, void *bp,       DWORD len, const PTimeInterval dur = 0);
00188     BOOL OpenVOIPPipe(Pipe pipeIndex);
00189 
00190     HANDLE pipes[4];
00191 #endif
00192 };
00193 
00195 
00198 class OpalVoipBlasterDevice : public OpalLineInterfaceDevice
00199 {
00200   PCLASSINFO(OpalVoipBlasterDevice, OpalLineInterfaceDevice);
00201 
00202   public:
00203 
00204     enum { DTMFQueueSize = 10 };
00205 
00206     class ByteQueue : public PObject {
00207       PCLASSINFO(ByteQueue, PObject);
00208       public:
00209         ByteQueue(PINDEX size);
00210         int Dequeue();
00211         BOOL Enqueue(BYTE ch);
00212 
00213       protected:
00214         PBYTEArray queue;
00215         PINDEX qLen, qOut, qMax;
00216         PMutex mutex;
00217     };
00218 
00221     OpalVoipBlasterDevice();
00222 
00226     ~OpalVoipBlasterDevice();
00227 
00230     virtual BOOL Open(
00231       const PString & device  
00232     );
00233 
00236     virtual BOOL Close();
00237 
00241     virtual PString GetDeviceType() const;
00242 
00245     virtual PString GetDeviceName() const;
00246 
00249     virtual PStringArray GetAllNames() const;
00250 
00253     virtual PString GetDescription() const;
00254 
00255 
00258     virtual unsigned GetLineCount()
00259       { return 1; }
00260 
00263     virtual BOOL IsLineTerminal(
00264       unsigned /*line*/   
00265     ) { return TRUE; }
00266 
00267 
00270     virtual BOOL IsLinePresent(
00271       unsigned /*line*/,      
00272       BOOL /*force*/ = FALSE  
00273     )
00274       { return FALSE; }
00275 
00276 
00281     virtual BOOL IsLineOffHook(
00282       unsigned line   
00283     );
00284 
00288     virtual BOOL SetLineOffHook(
00289       unsigned line,        
00290       BOOL newState = TRUE  
00291     );
00292 
00293 
00296     virtual BOOL IsLineRinging(
00297       unsigned line,          
00298       DWORD * cadence = NULL  
00299     );
00300 
00304     virtual BOOL RingLine(
00305       unsigned line,    
00306       DWORD cadence     
00307     );
00308 
00309 
00312     virtual BOOL IsLineDisconnected(
00313       unsigned line,   
00314       BOOL checkForWink = TRUE
00315     );
00316 
00317 
00320     BOOL SetLineToLineDirect(
00321       unsigned line1,   
00322       unsigned line2,   
00323       BOOL connect      
00324     );
00325 
00328     BOOL IsLineToLineDirect(
00329       unsigned line1,   
00330       unsigned line2    
00331     );
00332 
00333 
00336     virtual OpalMediaFormatList GetMediaFormats() const;
00337 
00340     virtual BOOL SetReadFormat(
00341       unsigned line,    
00342       const OpalMediaFormat & mediaFormat   
00343     );
00344 
00347     virtual BOOL SetWriteFormat(
00348       unsigned line,    
00349       const OpalMediaFormat & mediaFormat   
00350     );
00351 
00354     virtual OpalMediaFormat GetReadFormat(
00355       unsigned line    
00356     );
00357 
00360     virtual OpalMediaFormat GetWriteFormat(
00361       unsigned line    
00362     );
00363 
00374     virtual BOOL SetRawCodec(
00375       unsigned line    
00376     );
00377 
00380     virtual BOOL StopRawCodec(
00381       unsigned line   
00382     );
00383 
00386     virtual BOOL StopReadCodec(
00387       unsigned line   
00388     );
00389 
00392     virtual BOOL StopWriteCodec(
00393       unsigned line   
00394     );
00395 
00399     virtual PINDEX GetReadFrameSize(
00400       unsigned line   
00401     );
00402 
00403     virtual BOOL SetReadFrameSize(unsigned, PINDEX);
00404 
00408     virtual PINDEX GetWriteFrameSize(
00409       unsigned line   
00410     );
00411 
00412     virtual BOOL SetWriteFrameSize(unsigned, PINDEX);
00413 
00416     virtual BOOL ReadFrame(
00417       unsigned line,    
00418       void * buf,       
00419       PINDEX & count    
00420     );
00421 
00424     virtual BOOL WriteFrame(
00425       unsigned line,    
00426       const void * buf, 
00427       PINDEX count,     
00428       PINDEX & written  
00429     );
00430 
00433     virtual unsigned GetAverageSignalLevel(
00434       unsigned line,  
00435       BOOL playback   
00436     );
00437 
00438 
00441     virtual BOOL EnableAudio(
00442       unsigned line,      
00443       BOOL enable = TRUE
00444     );
00445 
00446 
00451     virtual BOOL SetRecordVolume(
00452       unsigned line,    
00453       unsigned volume   
00454     );
00455 
00460     virtual BOOL SetPlayVolume(
00461       unsigned line,    
00462       unsigned volume   
00463     );
00464 
00469     virtual BOOL GetRecordVolume(
00470       unsigned line,      
00471       unsigned & volume   
00472     );
00473 
00478     virtual BOOL GetPlayVolume(
00479       unsigned line,      
00480       unsigned & volume   
00481     );
00482 
00483 
00486     AECLevels GetAEC(
00487       unsigned line    
00488     );
00489 
00492     BOOL SetAEC(
00493       unsigned line,    
00494       AECLevels level  
00495     );
00496 
00497 
00501     virtual BOOL GetVAD(
00502       unsigned line    
00503     );
00504 
00508     virtual BOOL SetVAD(
00509       unsigned line,    
00510       BOOL enable       
00511     );
00512 
00513 
00521     virtual BOOL GetCallerID(
00522       unsigned line,      
00523       PString & idString, 
00524       BOOL full = FALSE   
00525     );
00526 
00535     virtual BOOL SetCallerID(
00536       unsigned line,            
00537       const PString & idString  
00538     );
00539 
00542     virtual BOOL SendCallerIDOnCallWaiting(
00543       unsigned line,            
00544       const PString & idString  
00545     );
00546 
00549     virtual BOOL SendVisualMessageWaitingIndicator(
00550       unsigned line,            
00551       BOOL on
00552     );
00553 
00554 
00555 
00559     virtual BOOL PlayDTMF(
00560       unsigned line,            
00561       const char * digits,      
00562       DWORD onTime = DefaultDTMFOnTime,  
00563       DWORD offTime = DefaultDTMFOffTime 
00564     );
00565 
00571     virtual char ReadDTMF(
00572       unsigned line   
00573     );
00574 
00579     virtual BOOL GetRemoveDTMF(
00580       unsigned line            
00581     );
00582 
00587     virtual BOOL SetRemoveDTMF(
00588       unsigned line,            
00589       BOOL removeTones   
00590     );
00591 
00592 
00595     virtual unsigned IsToneDetected(
00596       unsigned line   
00597     );
00598 
00601     virtual BOOL PlayTone(
00602       unsigned line,          
00603       CallProgressTones tone  
00604     );
00605 
00608     virtual BOOL IsTonePlaying(
00609       unsigned line   
00610     );
00611 
00614     virtual BOOL StopTone(
00615       unsigned line   
00616     );
00617 
00620     virtual BOOL HasHookFlash(unsigned line);
00621 
00627     virtual BOOL SetCountryCode(
00628       T35CountryCodes country   
00629     );
00630 
00631 
00634     virtual DWORD GetSerialNumber();
00635 
00638     static PStringArray GetDeviceNames();
00639 
00643     PDECLARE_NOTIFIER(PThread, OpalVoipBlasterDevice, StatusHandler);
00644 
00645   protected:
00646     void HandleStatus(int status);
00647 
00648     PThread * statusThread;
00649     BOOL statusRunning;
00650     BOOL hookState;
00651     BOOL headset;
00652     BOOL ringOn;
00653     BOOL firstTime;
00654 
00655     ByteQueue dtmfQueue;
00656 
00657     PAdaptiveDelay writeDelay;
00658     PAdaptiveDelay readDelay;
00659 
00660     PString   deviceName;
00661     PMutex    readMutex, writeMutex;
00662     BOOL      readStopped, writeStopped;
00663     PINDEX    readFrameSize, writeFrameSize;
00664     PINDEX    readCodecType, writeCodecType;
00665     BOOL      lastHookStatus;
00666 
00667     PMutex               vbMutex;
00668     VoipBlasterInterface vBlaster;
00669 };
00670 
00671 
00672 #define OPAL_VBLASTER_TYPE_NAME  "VoIPBlaster"
00673 #define OPAL_REGISTER_VBLASTER() OPAL_REGISTER_LID(OpalVoipBlasterDevice, OPAL_VBLASTER_TYPE_NAME)
00674 
00675 #else // HAS_VBLASTER
00676 
00677 #define OPAL_REGISTER_VBLASTER()
00678 
00679 #endif // HAS_VBLASTER
00680 
00681 #endif // __OPAL_VBLASTERLID_H
00682 
00683 

Generated on Mon Sep 25 16:20:12 2006 for OPAL by  doxygen 1.4.7