4 * Virteos HID Implementation for the OpenH323 Project.
6 * Virteos is a Trade Mark of ISVO (Asia) Pte Ltd.
8 * Copyright (c) 2005 ISVO (Asia) Pte Ltd. All Rights Reserved.
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/
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
20 * The Initial Developer of the Original Code is ISVO (Asia) Pte Ltd.
23 * Contributor(s): ______________________________________.
25 * $Log: opalusbdevice.h,v $
26 * Revision 1.1 2005/08/23 08:11:59 shorne
27 * renamed file to lower case
35 #endif // _MSC_VER > 1000
37 #include "openh323buildopts.h"
40 #include <opalplugin.h>
44 #pragma warning(disable:4100)
47 /* Line Interface device Implementation for USB Plugin devices.
49 class OpalUSBDevice : public OpalLineInterfaceDevice
52 PCLASSINFO(OpalUSBDevice, OpalLineInterfaceDevice);
56 class SoundTones : public PSound
59 SoundTones(unsigned channels,
60 unsigned samplesPerSecond,
61 unsigned bitsPerSample,
65 void RunContinuous(OpalUSBDevice * dev) const;
68 /**Create a new, closed, device for a USB Hardware device.
72 OpalUSBDevice(PluginHID_Definition * hid);
74 ~OpalUSBDevice() { Close(); };
76 /**Open and detect USB device.
79 const PString & device /// Device identifier name.
82 /**Determine if the line interface device is plugged in.
84 virtual BOOL IsOpen() const;
86 /**Close the USB device.
90 /**Get the device name.
92 virtual PString GetName() const;
94 /**Get the type of the line.
96 virtual BOOL IsLineTerminal(
97 unsigned line /// Number of line
106 /**Determine if a physical line is present on the logical line.
108 virtual BOOL IsLinePresent(
109 unsigned line, /// Number of line
110 BOOL force = FALSE /// Force test, do not optimise
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).
118 virtual BOOL IsLineOffHook(
119 unsigned line /// Number of line
122 /**Set the state of the line.
123 Note that not be possible on a given line.
125 virtual BOOL SetLineOffHook(
126 unsigned line, /// Number of line
127 BOOL newState = TRUE /// New state to set
131 /**Determine if line is ringing.
133 virtual BOOL IsLineRinging(
134 unsigned line, /// Number of line
135 DWORD * cadence = NULL /// Cadence of incoming ring
138 /**Begin ringing local phone set with specified cadence.
139 If cadence is zero then stops ringing.
141 virtual BOOL RingLine(
142 unsigned line, /// Number of line
143 DWORD cadence /// Cadence bit map for ring pattern
146 /**Determine if line has been disconnected from a call.
148 virtual BOOL IsLineDisconnected(
149 unsigned line, /// Number of line
150 BOOL checkForWink = TRUE
153 /**Get the read frame size in bytes.
154 All calls to ReadFrame() will return this number of bytes.
156 virtual PINDEX GetReadFrameSize(
157 unsigned line /// Number of line
160 virtual BOOL SetReadFrameSize(unsigned, PINDEX);
162 /**Get the write frame size in bytes.
163 All calls to WriteFrame() must be this number of bytes.
165 virtual PINDEX GetWriteFrameSize(
166 unsigned line /// Number of line
169 virtual BOOL SetWriteFrameSize(unsigned, PINDEX);
172 /**Low level read of a frame from the device.
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()
180 /**Low level write frame to the device.
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()
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.
193 virtual BOOL SetRecordVolume(
194 unsigned line, /// Number of line
195 unsigned volume /// Volume level from 0 to 100%
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.
202 virtual BOOL SetPlayVolume(
203 unsigned line, /// Number of line
204 unsigned volume /// Volume level from 0 to 100%
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.
211 virtual BOOL GetRecordVolume(
212 unsigned line, /// Number of line
213 unsigned & volume /// Volume level from 0 to 100%
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.
220 virtual BOOL GetPlayVolume(
221 unsigned line, /// Number of line
222 unsigned & volume /// Volume level from 0 to 100%
225 /**Play a DTMF digit.
226 Any characters that are not in the set 0-9, A-D, * or # will be ignored.
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
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.
241 virtual char ReadDTMF(
242 unsigned line /// Number of line
247 virtual BOOL PlayTone(
248 unsigned line, /// Number of line
249 CallProgressTones tone /// Tone to be played
252 /**Determine if a tone is still playing
254 virtual BOOL IsTonePlaying(
255 unsigned line /// Number of line
258 /**Stop playing a tone.
260 virtual BOOL StopTone(
261 unsigned line /// Number of line
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.
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').
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
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').
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.
285 virtual BOOL SetCallerID(
286 unsigned line, /// Number of line
287 const PString & idString /// ID string to use
290 /** Get Line Count. At resent this returns 0
292 virtual unsigned GetLineCount();
296 virtual OpalMediaFormat::List GetMediaFormats() const;
298 /** Set Read Frame size
300 virtual BOOL SetReadFormat(unsigned line, const OpalMediaFormat &mediaFormat);
302 /** Set write Frame size
304 virtual SetWriteFormat(unsigned line,const OpalMediaFormat &mediaFormat);
306 /** Get the Read format
308 virtual OpalMediaFormat GetReadFormat(unsigned line);
310 /** Get the Write Format
312 virtual OpalMediaFormat GetWriteFormat(unsigned line);
314 /**Stop the read codec.
316 virtual BOOL StopReadCodec(
317 unsigned line /// Number of line
320 /**Stop the write codec.
322 virtual BOOL StopWriteCodec(
323 unsigned line /// Number of line
328 virtual OpalLineInterfaceDevice::DeviceType GetDeviceType();
330 PString soundDev; /// Sound DeviceName
331 BOOL exitTone; /// Exit Tone Thread Flag
335 /** Interpret input received from the HID
337 void InterpretInput(unsigned int ret);
339 /* Create the Sound Device (Usually a specific soundcard ie "USB Audio Device")
341 BOOL CreateSoundDevice(BOOL IsEncoder,
342 const PString & device,
347 OpalMediaFormat MediaFormat;
349 /* Invoke a message to the USB HID
351 unsigned int InvokeMessage(unsigned msg,unsigned val=0);
353 PluginHID_Definition * HID; /// HID Definition from the Plugin
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
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
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
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