File: vblasterlid.h

package info (click to toggle)
openh323 1.18.0.dfsg-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,616 kB
  • ctags: 26,979
  • sloc: cpp: 178,986; ansic: 33,179; sh: 3,483; makefile: 937
file content (632 lines) | stat: -rw-r--r-- 18,749 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/*
 * vblasterlid.h
 *
 * Creative Labs VOIP Blaster codec interface
 *
 * Open H323 Library
 *
 * Copyright (c) 2001 Equivalence Pty. Ltd.
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 *
 * The Original Code is Open H323 Library.
 *
 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
 *
 * Contributor(s): ______________________________________.
 *
 * $Log: vblasterlid.h,v $
 * Revision 1.8  2005/11/30 13:05:01  csoutheren
 * Changed tags for Doxygen
 *
 * Revision 1.7  2003/12/03 06:58:30  csoutheren
 * More vblaster implementation
 *
 * Revision 1.6  2003/11/10 12:37:46  csoutheren
 * Additional fixes for Fobbit Windows driver
 *
 * Revision 1.5  2002/09/16 01:14:15  robertj
 * Added #define so can select if #pragma interface/implementation is used on
 *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
 *
 * Revision 1.4  2002/09/03 06:19:37  robertj
 * Normalised the multi-include header prevention ifdef/define symbol.
 *
 * Revision 1.3  2002/08/05 10:03:47  robertj
 * Cosmetic changes to normalise the usage of pragma interface/implementation.
 *
 * Revision 1.2  2002/01/15 07:23:24  craigs
 * Added IsDevicePresent command
 *
 * Revision 1.1  2002/01/15 04:16:32  craigs
 * Initial version
 *
 *
 */

#ifndef __OPAL_VBLASTERLID_H
#define __OPAL_VBLASTERLID_H

#ifdef P_USE_PRAGMA
#pragma interface
#endif


#define HAS_VBLASTER

#include "lid.h"
#include "h323caps.h"

#include <ptclib/delaychan.h>



///////////////////////////////////////////////////////////////////////////////

class VoipBlasterInterface : public PObject
{
  PCLASSINFO(VoipBlasterInterface, PObject)
  public:
    enum Command {
      Command_PHONE_OFF  = 0x01, // drop loop current
      Command_PHONE_ON   = 0x02, // used on startup
      Command_RING_ON    = 0x03, // start ringing
      Command_RING_OFF   = 0x04, // used on startup & to stop ringing
      Command_VOUT_START = 0x05, // start audio output
      Command_VOUT_STOP  = 0x06, // stop audio output
      Command_VINP_START = 0x07, // start audio input
      Command_VINP_STOP  = 0x08, // stop audio input
      Command_UNKNOWN_1  = 0x09, // Unknown (TESTSTART)
      Command_UNKNOWN_2  = 0x0a, // Unknown (TESTSTOP)
      Command_UNKNOWN_3  = 0x0b, // Unknown (SENDFAXTONE)
      Command_HS_OFFHOOK = 0x0c, // Go offhook for headset
      Command_HS_ONHOOK  = 0x0d, // Go onhook for headset
      Command_SETUP_MODE = 0x0e, // Unknown(goto setup mode)
      Command_VOUT_DONE  = 0x0f, // voice in/out off, report output drained
      Command_0x10       = 0x10, // Unknown (used in file output, seems ok without)
      Command_0x11       = 0x11, // Unknown (used in file output, seems ok without)
      Command_MUTE_ON    = 0x12, // Audio mute on
      Command_MUTE_OFF   = 0x13, // Audio mute off
      Command_VOL_0      = 0x34, // Set volume (min)
      Command_VOL_1      = 0x35, // Set volume
      Command_VOL_2      = 0x36, // Set volume
      Command_VOL_3      = 0x37, // Set volume (default)
      Command_VOL_4      = 0x38, // Set volume
      Command_VOL_5      = 0x39, // Set volume
      Command_VOL_6      = 0x3a, // Set volume (max)
    };

    enum Status {
      //Status_NONE        = 0x00, // No status
      Status_HOOK_OFF    = 0x01, // Offhook
      Status_HOOK_ON     = 0x02, // Onhook
      //Status_DEBUG       = 0x03, // Not used (DEBUG)
      //Status_RINGDETECT  = 0x04, // Not used (RINGDETECT)
      Status_RINGING_ON  = 0x05, // Ring started 
      Status_RINGING_OFF = 0x06, // Ring stopped
      Status_HEADSET_IN  = 0x08, // Headset plugged in
      Status_HEADSET_OUT = 0x09, // Headset unplugged
      Status_0x0a        = 0x0a, // Unknown (setup accepted?)
      Status_VOUT_DONE   = 0x0c, // Voice output done
      Status_Empty
    };

    VoipBlasterInterface();

    BOOL IsDevicePresent(PINDEX deviceIndex);

    BOOL OpenCommand(PINDEX deviceIndex);
    BOOL WriteCommand(Command cmd);
    Status ReadStatus(const PTimeInterval dur = 0);
    BOOL CloseCommand();

    BOOL OpenData();
    BOOL WriteData(const void * data, PINDEX len);
    int  ReadData (void * data,       PINDEX len, const PTimeInterval dur = 0);
    void Flush(const PTimeInterval wait = 500);
    BOOL CloseData();

    PDECLARE_NOTIFIER(PTimer, VoipBlasterInterface, CloseTimeout);

  protected:
    PINDEX deviceIndex;

// Linux specific defines are included here
#ifdef P_LINUX
#endif

// Windows specific defines are included here
#ifdef _WIN32
    enum Pipe {
      VoiceOutPipe = 0,
      VoiceInPipe  = 1,
      CommandPipe  = 2,
      StatusPipe   = 3,
      NumPipes
    };

  protected:
    int WritePipe(HANDLE fd, const void *bp, DWORD len);
    int ReadPipe (HANDLE fd, void *bp,       DWORD len, const PTimeInterval dur = 0);
    BOOL OpenVOIPPipe(Pipe pipeIndex);

    HANDLE pipes[4];
#endif
};

///////////////////////////////////////////////////////////////////////////////

/**This class describes the VoIPBlaster line interface device.
 */
class OpalVoipBlasterDevice : public OpalLineInterfaceDevice
{
  PCLASSINFO(OpalVoipBlasterDevice, OpalLineInterfaceDevice);

  public:

    enum { DTMFQueueSize = 10 };

    class ByteQueue : public PObject {
      PCLASSINFO(ByteQueue, PObject);
      public:
        ByteQueue(PINDEX size);
        int Dequeue();
        BOOL Enqueue(BYTE ch);

      protected:
        PBYTEArray queue;
        PINDEX qLen, qOut, qMax;
        PMutex mutex;
    };

    /**Create a new, closed, device for a VoipBlaster device.
      */
    OpalVoipBlasterDevice();

    /**Destroy line interface device.
       This calls Close() on the device.
      */
    ~OpalVoipBlasterDevice();

    /**Open the VoIPBlaster device.
      */
    virtual BOOL Open(
      const PString & device  ///<  Device identifier name.
    );

    /**Close the VoIPBlaster device.
      */
    virtual BOOL Close();

    /**Get the device name.
      */
    virtual PString GetName() const;

    /**Get the total number of lines supported by this device.
      */
    virtual unsigned GetLineCount()
      { return 1; }

    /**Get the type of the line.
      */
    virtual BOOL IsLineTerminal(
      unsigned /*line*/   ///<  Number of line
    ) { return TRUE; }


    /**Determine if a physical line is present on the logical line.
      */
    virtual BOOL IsLinePresent(
      unsigned /*line*/,      ///<  Number of line
      BOOL /*force*/ = FALSE  ///<  Force test, do not optimise
    )
      { return FALSE; }


    /**Determine if line is currently off hook.
       This returns TRUE if GetLineState() is a state that implies the line is
       off hook (eg OffHook or LineBusy).
      */
    virtual BOOL IsLineOffHook(
      unsigned line   ///<  Number of line
    );

    /**Set the state of the line.
       Note that not be possible on a given line.
      */
    virtual BOOL SetLineOffHook(
      unsigned line,        ///<  Number of line
      BOOL newState = TRUE  ///<  New state to set
    );


    /**Determine if line is ringing.
      */
    virtual BOOL IsLineRinging(
      unsigned line,          ///<  Number of line
      DWORD * cadence = NULL  ///<  Cadence of incoming ring
    );

    /**Begin ringing local phone set with specified cadence.
       If cadence is zero then stops ringing.
      */
    virtual BOOL RingLine(
      unsigned line,    ///<  Number of line
      DWORD cadence     ///<  Cadence bit map for ring pattern
    );


    /**Determine if line has been disconnected from a call.
      */
    virtual BOOL IsLineDisconnected(
      unsigned line,   ///<  Number of line
      BOOL checkForWink = TRUE
    );


    /**Directly connect the two lines.
      */
    BOOL SetLineToLineDirect(
      unsigned line1,   ///<  Number of first line
      unsigned line2,   ///<  Number of second line
      BOOL connect      ///<  Flag for connect/disconnect
    );

    /**Determine if the two lines are directly connected.
      */
    BOOL IsLineToLineDirect(
      unsigned line1,   ///<  Number of first line
      unsigned line2    ///<  Number of second line
    );


    /**Get the media formats this device is capable of using.
      */
    virtual OpalMediaFormat::List GetMediaFormats() const;

    /**Set the VoIPBlaster codec for reading.
      */
    virtual BOOL SetReadFormat(
      unsigned line,    ///<  Number of line
      const OpalMediaFormat & mediaFormat   ///<  Codec type
    );

    /**Set the VoIPBlaster codec for writing.
      */
    virtual BOOL SetWriteFormat(
      unsigned line,    ///<  Number of line
      const OpalMediaFormat & mediaFormat   ///<  Codec type
    );

    /**Get the media format (codec) for reading on the specified line.
      */
    virtual OpalMediaFormat GetReadFormat(
      unsigned line    ///<  Number of line
    );

    /**Get the media format (codec) for writing on the specified line.
      */
    virtual OpalMediaFormat GetWriteFormat(
      unsigned line    ///<  Number of line
    );

    /**Set the line codec for reading/writing raw PCM data.
       A descendent may use this to do anything special to the device before
       beginning special PCM output. For example disabling AEC and set
       volume levels to standard values. This can then be used for generating
       standard tones using PCM if the driver is not capable of generating or
       detecting them directly.

       The default behaviour simply does a SetReadCodec and SetWriteCodec for
       PCM data.
      */
    virtual BOOL SetRawCodec(
      unsigned line    ///<  Number of line
    );

    /**Stop the raw PCM mode codec.
      */
    virtual BOOL StopRawCodec(
      unsigned line   ///<  Number of line
    );

    /**Stop the read codec.
      */
    virtual BOOL StopReadCodec(
      unsigned line   ///<  Number of line
    );

    /**Stop the write codec.
      */
    virtual BOOL StopWriteCodec(
      unsigned line   ///<  Number of line
    );

    /**Get the read frame size in bytes.
       All calls to ReadFrame() will return this number of bytes.
      */
    virtual PINDEX GetReadFrameSize(
      unsigned line   ///<  Number of line
    );

    virtual BOOL SetReadFrameSize(unsigned, PINDEX);

    /**Get the write frame size in bytes.
       All calls to WriteFrame() must be this number of bytes.
      */
    virtual PINDEX GetWriteFrameSize(
      unsigned line   ///<  Number of line
    );

    virtual BOOL SetWriteFrameSize(unsigned, PINDEX);

    /**Low level read of a frame from the device.
     */
    virtual BOOL ReadFrame(
      unsigned line,    ///<  Number of line
      void * buf,       ///<  Pointer to a block of memory to receive data.
      PINDEX & count    ///<  Number of bytes read, <= GetReadFrameSize()
    );

    /**Low level write frame to the device.
     */
    virtual BOOL WriteFrame(
      unsigned line,    ///<  Number of line
      const void * buf, ///<  Pointer to a block of memory to write.
      PINDEX count,     ///<  Number of bytes to write, <= GetWriteFrameSize()
      PINDEX & written  ///<  Number of bytes written, <= GetWriteFrameSize()
    );

    /**Get average signal level in last frame.
      */
    virtual unsigned GetAverageSignalLevel(
      unsigned line,  ///<  Number of line
      BOOL playback   ///<  Get average playback or record level.
    );


    /**Enable audio for the line.
      */
    virtual BOOL EnableAudio(
      unsigned line,      ///<  Number of line
      BOOL enable = TRUE
    );


    /**Set volume level for recording.
       A value of 100 is the maximum volume possible for the hardware.
       A value of 0 is the minimum volume possible for the hardware.
      */
    virtual BOOL SetRecordVolume(
      unsigned line,    ///<  Number of line
      unsigned volume   ///<  Volume level from 0 to 100%
    );

    /**Set volume level for playing.
       A value of 100 is the maximum volume possible for the hardware.
       A value of 0 is the minimum volume possible for the hardware.
      */
    virtual BOOL SetPlayVolume(
      unsigned line,    ///<  Number of line
      unsigned volume   ///<  Volume level from 0 to 100%
    );

    /**Get volume level for recording.
       A value of 100 is the maximum volume possible for the hardware.
       A value of 0 is the minimum volume possible for the hardware.
      */
    virtual BOOL GetRecordVolume(
      unsigned line,      ///<  Number of line
      unsigned & volume   ///<  Volume level from 0 to 100%
    );

    /**Set volume level for playing.
       A value of 100 is the maximum volume possible for the hardware.
       A value of 0 is the minimum volume possible for the hardware.
      */
    virtual BOOL GetPlayVolume(
      unsigned line,      ///<  Number of line
      unsigned & volume   ///<  Volume level from 0 to 100%
    );


    /**Set acoustic echo cancellation.
      */
    AECLevels GetAEC(
      unsigned line    ///<  Number of line
    );

    /**Set acoustic echo cancellation.
      */
    BOOL SetAEC(
      unsigned line,    ///<  Number of line
      AECLevels level  ///<  AEC level
    );


    /**Get voice activity detection.
       Note, not all devices, or selected codecs, may support this function.
      */
    virtual BOOL GetVAD(
      unsigned line    ///<  Number of line
    );

    /**Set voice activity detection.
       Note, not all devices, or selected codecs, may support this function.
      */
    virtual BOOL SetVAD(
      unsigned line,    ///<  Number of line
      BOOL enable       ///<  Flag for enabling VAD
    );


    /**Get Caller ID from the last incoming ring.
       The idString parameter is either simply the "number" field of the caller
       ID data, or if full is TRUE, all of the fields in the caller ID data.

       The full data of the caller ID string consists of the number field, the
       time/date and the name field separated by tabs ('\t').
      */
    virtual BOOL GetCallerID(
      unsigned line,      ///<  Number of line
      PString & idString, ///<  ID string returned
      BOOL full = FALSE   ///<  Get full information in idString
    );

    /**Set Caller ID for use in next RingLine() call.
       The full data of the caller ID string consists of the number field, the
       time/date and the name field separated by tabs ('\t').

       If the date field is missing (two consecutive tabs) then the current
       time and date is used. Using an empty string will clear the caller ID
       so that no caller ID is sent on the next RingLine() call.
      */
    virtual BOOL SetCallerID(
      unsigned line,            ///<  Number of line
      const PString & idString  ///<  ID string to use
    );

    /**Send Caller ID during call
     */
    virtual BOOL SendCallerIDOnCallWaiting(
      unsigned line,            ///<  Number of line
      const PString & idString  ///<  ID string to use
    );

    /**Send a Visual Message Waiting Indicator
      */
    virtual BOOL SendVisualMessageWaitingIndicator(
      unsigned line,            ///<  Number of line
      BOOL on
    );



    /**Play a DTMF digit.
       Any characters that are not in the set 0-9, A-D, * or # will be ignored.
      */
    virtual BOOL PlayDTMF(
      unsigned line,            ///<  Number of line
      const char * digits,      ///<  DTMF digits to be played
      DWORD onTime = DefaultDTMFOnTime,  ///<  Number of milliseconds to play each DTMF digit
      DWORD offTime = DefaultDTMFOffTime ///<  Number of milliseconds between digits
    );

    /**Read a DTMF digit detected.
       This may be characters from the set 0-9, A-D, * or #. A null ('\0')
       character indicates that there are no tones in the queue.

      */
    virtual char ReadDTMF(
      unsigned line   ///<  Number of line
    );

    /**Get DTMF removal mode.
       When set in this mode the DTMF tones detected are removed from the
       encoded data stream as returned by ReadFrame().
      */
    virtual BOOL GetRemoveDTMF(
      unsigned line            ///<  Number of line
    );

    /**Set DTMF removal mode.
       When set in this mode the DTMF tones detected are removed from the
       encoded data stream as returned by ReadFrame().
      */
    virtual BOOL SetRemoveDTMF(
      unsigned line,            ///<  Number of line
      BOOL removeTones   ///<  Flag for removing DTMF tones.
    );


    /**See if a tone is detected.
      */
    virtual unsigned IsToneDetected(
      unsigned line   ///<  Number of line
    );

    /**Play a tone.
      */
    virtual BOOL PlayTone(
      unsigned line,          ///<  Number of line
      CallProgressTones tone  ///<  Tone to be played
    );

    /**Determine if a tone is still playing
      */
    virtual BOOL IsTonePlaying(
      unsigned line   ///<  Number of line
    );

    /**Stop playing a tone.
      */
    virtual BOOL StopTone(
      unsigned line   ///<  Number of line
    );

   /**Return TRUE if a hook flash has been detected
      */
    virtual BOOL HasHookFlash(unsigned line);

    /**Set the country code set for the device.
       This may change the line analogue coefficients, ring detect, call
       disconnect detect and call progress tones to fit the countries
       telephone network.
      */
    virtual BOOL SetCountryCode(
      T35CountryCodes country   ///<  COuntry code for device
    );


    /**Get the serial number for the VoIPBlaster card.
      */
    virtual DWORD GetSerialNumber();

    /**Get all the VoIPBlaster devices.
      */
    static PStringArray GetDeviceNames();

    /**
      * entry point for status handler thread
      */
    PDECLARE_NOTIFIER(PThread, OpalVoipBlasterDevice, StatusHandler);

  protected:
    void HandleStatus(int status);

    PThread * statusThread;
    BOOL statusRunning;
    BOOL hookState;
    BOOL headset;
    BOOL ringOn;
    BOOL firstTime;

    ByteQueue dtmfQueue;

    PAdaptiveDelay writeDelay;
    PAdaptiveDelay readDelay;

    PString   deviceName;
    PMutex    readMutex, writeMutex;
    BOOL      readStopped, writeStopped;
    PINDEX    readFrameSize, writeFrameSize;
    PINDEX    readCodecType, writeCodecType;
    BOOL      lastHookStatus;

    PMutex               vbMutex;
    VoipBlasterInterface vBlaster;
};


#endif // __OPAL_VBLASTERLID_H


/////////////////////////////////////////////////////////////////////////////