OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / lib / libopenh323 / include / opalusbdevice.h
1 /*
2  * opalusbdevice.h
3  *
4  * Virteos HID Implementation for the OpenH323 Project.
5  *
6  * Virteos is a Trade Mark of ISVO (Asia) Pte Ltd.
7  *
8  * Copyright (c) 2005 ISVO (Asia) Pte Ltd. All Rights Reserved.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
21  *
22  *
23  * Contributor(s): ______________________________________.
24  *
25  * $Log: opalusbdevice.h,v $
26  * Revision 1.1  2005/08/23 08:11:59  shorne
27  * renamed file to lower case
28  *
29  *
30  *
31 */
32
33 #if _MSC_VER > 1000
34 #pragma once
35 #endif // _MSC_VER > 1000
36
37 #include "openh323buildopts.h"
38
39 #include <lid.h>
40 #include <opalplugin.h>
41
42
43 #ifdef _MSC_VER
44 #pragma warning(disable:4100)
45 #endif
46
47 /* Line Interface device Implementation for USB Plugin devices.
48 */
49 class OpalUSBDevice : public OpalLineInterfaceDevice
50 {
51
52    PCLASSINFO(OpalUSBDevice, OpalLineInterfaceDevice);
53
54 public:
55
56         class SoundTones : public PSound
57         {
58         public:
59                 SoundTones(unsigned channels,
60                unsigned samplesPerSecond,
61                unsigned bitsPerSample,
62                PINDEX   bufferSize,
63                const BYTE * buffer);
64
65                 void RunContinuous(OpalUSBDevice * dev) const;
66         };
67
68     /**Create a new, closed, device for a USB Hardware device.
69       */
70         OpalUSBDevice();
71
72         OpalUSBDevice(PluginHID_Definition * hid);
73
74         ~OpalUSBDevice() { Close(); };
75
76     /**Open and detect USB device.
77       */
78     virtual BOOL Open(
79       const PString & device  /// Device identifier name.
80     );
81
82     /**Determine if the line interface device is plugged in.
83       */
84     virtual BOOL IsOpen() const;
85
86     /**Close the USB device.
87       */
88     virtual BOOL Close();
89
90     /**Get the device name.
91       */
92     virtual PString GetName() const;
93
94     /**Get the type of the line.
95       */
96     virtual BOOL IsLineTerminal(
97       unsigned line   /// Number of line
98     );
99
100     enum {
101       POTSLine,
102       PSTNLine,
103       NumLines
104     };
105
106     /**Determine if a physical line is present on the logical line.
107       */
108     virtual BOOL IsLinePresent(
109       unsigned line,      /// Number of line
110       BOOL force = FALSE  /// Force test, do not optimise
111     );
112
113
114     /**Determine if line is currently off hook.
115        This returns TRUE if GetLineState() is a state that implies the line is
116        off hook (eg OffHook or LineBusy).
117       */
118     virtual BOOL IsLineOffHook(
119       unsigned line   /// Number of line
120     );
121
122     /**Set the state of the line.
123        Note that not be possible on a given line.
124       */
125     virtual BOOL SetLineOffHook(
126       unsigned line,        /// Number of line
127       BOOL newState = TRUE  /// New state to set
128     );
129
130
131     /**Determine if line is ringing.
132       */
133     virtual BOOL IsLineRinging(
134       unsigned line,          /// Number of line
135       DWORD * cadence = NULL  /// Cadence of incoming ring
136     );
137
138     /**Begin ringing local phone set with specified cadence.
139        If cadence is zero then stops ringing.
140       */
141     virtual BOOL RingLine(
142       unsigned line,    /// Number of line
143       DWORD cadence     /// Cadence bit map for ring pattern
144     );
145
146     /**Determine if line has been disconnected from a call.
147       */
148     virtual BOOL IsLineDisconnected(
149       unsigned line,   /// Number of line
150       BOOL checkForWink = TRUE
151     );
152
153     /**Get the read frame size in bytes.
154        All calls to ReadFrame() will return this number of bytes.
155       */
156     virtual PINDEX GetReadFrameSize(
157       unsigned line   /// Number of line
158     );
159
160     virtual BOOL SetReadFrameSize(unsigned, PINDEX);
161
162     /**Get the write frame size in bytes.
163        All calls to WriteFrame() must be this number of bytes.
164       */
165     virtual PINDEX GetWriteFrameSize(
166       unsigned line   /// Number of line
167     );
168
169     virtual BOOL SetWriteFrameSize(unsigned, PINDEX);
170
171
172     /**Low level read of a frame from the device.
173      */
174     virtual BOOL ReadFrame(
175       unsigned line,    /// Number of line
176       void * buf,       /// Pointer to a block of memory to receive data.
177       PINDEX & count    /// Number of bytes read, <= GetReadFrameSize()
178     );
179
180     /**Low level write frame to the device.
181      */
182     virtual BOOL WriteFrame(
183       unsigned line,    /// Number of line
184       const void * buf, /// Pointer to a block of memory to write.
185       PINDEX count,     /// Number of bytes to write, <= GetWriteFrameSize()
186       PINDEX & written  /// Number of bytes written, <= GetWriteFrameSize()
187     );
188
189    /**Set volume level for recording.
190        A value of 100 is the maximum volume possible for the hardware.
191        A value of 0 is the minimum volume possible for the hardware.
192       */
193     virtual BOOL SetRecordVolume(
194       unsigned line,    /// Number of line
195       unsigned volume   /// Volume level from 0 to 100%
196     );
197
198     /**Set volume level for playing.
199        A value of 100 is the maximum volume possible for the hardware.
200        A value of 0 is the minimum volume possible for the hardware.
201       */
202     virtual BOOL SetPlayVolume(
203       unsigned line,    /// Number of line
204       unsigned volume   /// Volume level from 0 to 100%
205     );
206
207     /**Get volume level for recording.
208        A value of 100 is the maximum volume possible for the hardware.
209        A value of 0 is the minimum volume possible for the hardware.
210       */
211     virtual BOOL GetRecordVolume(
212       unsigned line,      /// Number of line
213       unsigned & volume   /// Volume level from 0 to 100%
214     );
215
216     /**Set volume level for playing.
217        A value of 100 is the maximum volume possible for the hardware.
218        A value of 0 is the minimum volume possible for the hardware.
219       */
220     virtual BOOL GetPlayVolume(
221       unsigned line,      /// Number of line
222       unsigned & volume   /// Volume level from 0 to 100%
223     );
224
225     /**Play a DTMF digit.
226        Any characters that are not in the set 0-9, A-D, * or # will be ignored.
227       */
228     virtual BOOL PlayDTMF(
229       unsigned line,            /// Number of line
230       const char * digits,      /// DTMF digits to be played
231       DWORD onTime = DefaultDTMFOnTime,  /// Number of milliseconds to play each DTMF digit
232       DWORD offTime = DefaultDTMFOffTime /// Number of milliseconds between digits
233     );
234
235
236     /**Read a DTMF digit detected.
237        This may be characters from the set 0-9, A-D, * or #. A null ('\0')
238        character indicates that there are no tones in the queue.
239
240       */
241     virtual char ReadDTMF(
242       unsigned line   /// Number of line
243     );
244
245     /**Play a tone.
246       */
247     virtual BOOL PlayTone(
248       unsigned line,          /// Number of line
249       CallProgressTones tone  /// Tone to be played
250     );
251
252     /**Determine if a tone is still playing
253       */
254     virtual BOOL IsTonePlaying(
255       unsigned line   /// Number of line
256     );
257
258     /**Stop playing a tone.
259       */
260     virtual BOOL StopTone(
261       unsigned line   /// Number of line
262     );
263
264     /**Get Caller ID from the last incoming ring.
265        The idString parameter is either simply the "number" field of the caller
266        ID data, or if full is TRUE, all of the fields in the caller ID data.
267
268        The full data of the caller ID string consists of the number field, the
269        time/date and the name field separated by tabs ('\t').
270       */
271     virtual BOOL GetCallerID(
272       unsigned line,      /// Number of line
273       PString & idString, /// ID string returned
274       BOOL full = FALSE   /// Get full information in idString
275     );
276
277     /**Set Caller ID for use in next RingLine() call.
278        The full data of the caller ID string consists of the number field, the
279        time/date and the name field separated by tabs ('\t').
280
281        If the date field is missing (two consecutive tabs) then the current
282        time and date is used. Using an empty string will clear the caller ID
283        so that no caller ID is sent on the next RingLine() call.
284       */
285     virtual BOOL SetCallerID(
286       unsigned line,            /// Number of line
287       const PString & idString  /// ID string to use
288     );
289
290         /** Get Line Count. At resent this returns 0
291           */
292         virtual unsigned GetLineCount();
293
294         /** GetMedia Formats
295           */
296         virtual OpalMediaFormat::List GetMediaFormats() const;
297
298         /** Set Read Frame size
299           */
300         virtual BOOL SetReadFormat(unsigned line, const OpalMediaFormat &mediaFormat);
301
302         /** Set write Frame size
303           */
304         virtual SetWriteFormat(unsigned line,const OpalMediaFormat &mediaFormat);
305
306         /** Get the Read format
307           */
308         virtual OpalMediaFormat GetReadFormat(unsigned line);
309
310         /** Get the Write Format
311           */
312         virtual OpalMediaFormat GetWriteFormat(unsigned line);
313
314     /**Stop the read codec.
315       */
316     virtual BOOL StopReadCodec(
317       unsigned line   /// Number of line
318     );
319
320     /**Stop the write codec.
321       */
322     virtual BOOL StopWriteCodec(
323       unsigned line   /// Number of line
324     );
325
326         /** Get Device Type
327           */
328     virtual OpalLineInterfaceDevice::DeviceType GetDeviceType();
329
330     PString soundDev;                                                                   /// Sound DeviceName
331         BOOL exitTone;                                                                          /// Exit Tone Thread Flag
332
333 protected:
334
335         /** Interpret input received from the HID
336           */
337         void InterpretInput(unsigned int ret);
338
339         /* Create the Sound Device (Usually a specific soundcard ie "USB Audio Device")
340          */
341         BOOL CreateSoundDevice(BOOL IsEncoder,
342                                const PString & device, 
343                                PINDEX rate = 8000,
344                                PINDEX samples = 1
345                                );
346
347         OpalMediaFormat MediaFormat;
348
349         /* Invoke a message to the USB HID
350          */
351         unsigned int InvokeMessage(unsigned msg,unsigned val=0);
352
353         PluginHID_Definition * HID;                                                     /// HID Definition from the Plugin
354
355         PThread  *  MonitorThread;                                                      /// Monitor Thread. 
356         PSyncPoint monitorTickle;                                                       /// Poll wait
357     PDECLARE_NOTIFIER(PThread, OpalUSBDevice, Monitor); /// Declaration of the Thread
358         BOOL exitFlag;                                                                          /// Exit Thread Monitor Flag
359
360         BOOL PluggedIn;                                                                         /// Device plugged in
361         unsigned int InputData;                                                         /// Data sent to the USB Phone  
362         PString digitbuffer;                                                            /// Digit Buffer from USB Phone
363         BOOL OffHookState;                                                                      /// Hook state  
364         BOOL isRinging;                                                                         /// Whether the device is ringing                       
365
366         //Sound Channels & Settings
367         BOOL useSound;                                                                          /// Flag to specify is Regular Sound device
368         PSoundChannel * RecSound;                                                       /// Sound Record Channel
369         PSoundChannel * PlaySound;                                                      /// Sound Play Channel
370         PINDEX soundChannelBuffers;                                                     /// Sound Channel Buffers
371         PINDEX vol;                                                                                     /// Current Speaker volume
372
373         // Tone Generator
374         BOOL useTones;                                                                          /// Tones required.
375         CallProgressTones CurTone;                                                      /// Current Tone to Play
376         PThread  *  ToneThread;                                                     /// Tone Thread. 
377     PDECLARE_NOTIFIER(PThread, OpalUSBDevice, TonePlay); /// Declaration of the ToneThread
378         PMutex vbMutex;                                                                         /// Mute
379
380         // Gateway
381         BOOL hasPSTN;
382
383         // behaviour
384         BOOL isCell;
385
386 };
387
388
389 //#endif