📄 voice.java
字号:
// Voice: Dialogic voice devices
// $Id: Voice.java,v 1.12 2003/11/13 11:54:45 cgm8 Exp $
/*
* Copyright (c) 1999 Carlos G Mendioroz.
*
* This file is part of D4J.
*
* D4J is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* D4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Report problems and direct all questions to:
*
* tron@acm.org
*/
package local.dialogic;
public class Voice extends Device
{
// Class varialbles
static Object toneLock = new Object(); // serialize tone making
// Variables
protected int physio; // low level malloc() memory
private IOTT iott; // reference to current IOTT being used,
// to delay IOTT closing before end of play/rec
private XPB xpb; // same for XPB
private boolean GC = false;// Device managed by GC
/** Open a dx device */
public Voice(Channel ch, String name)
{
super(ch, name);
physio = 0;
device = Dialogic.dx_open(name, 0);
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice open: " + name + " (" + device + ")");
Dialogic.dx_deltones(device);
Dialogic.dx_setdigtyp(device, Dialogic.DM_DTMF|Dialogic.DM_DPD);
register();
}
// create a Voice object from an open handle
public Voice(Channel ch, int handle)
{
super(ch, "Device"+handle);
physio = 0;
device = handle;
GC = true;
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice open from handle (" + device + ")");
register();
}
public void close()
{
if (device != 0) {
Dialogic.dx_close(this);
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice close (" + device + ")");
super.close();
device = 0; // just in case
physio = 0;
}
}
public void waitIdle() {
boolean idle = false;
boolean guard = false;
synchronized(this) {
idle = (Dialogic.ATDX_STATE(device) == Dialogic.CS_IDLE);
}
try {
while (!idle) {
if (!channel.inService()) {
guard = true;
channel.beginService();
}
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice waitIdle (" + device + ")");
try {
channel.serviceWaitEvent();
} catch (ChannelException ce) {
stop();
throw ce;
}
synchronized(this) {
idle = (Dialogic.ATDX_STATE(device) == Dialogic.CS_IDLE);
}
}
} finally {
if (guard) channel.endService();
}
channel.flush();
iott = null;
xpb = null;
}
public synchronized void setHook(boolean hook) {
boolean guard = false;
try {
if (!channel.inService()) {
guard = true;
channel.beginService();
}
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice sethook " + hook + " (" + device + ")");
if (hook)
Dialogic.dx_sethook(device, Dialogic.DX_OFFHOOK, Dialogic.EV_ASYNC);
else
Dialogic.dx_sethook(device, Dialogic.DX_ONHOOK, Dialogic.EV_ASYNC);
EVT evt = channel.serviceWaitEvent();
// should check it is a hook confirmation...
} finally {
if (guard) channel.endService();
}
}
public synchronized void waitRings(int nRings) {
EVT evt;
try {
channel.beginService();
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice waitRings " + nRings + " (" + device + ")");
Dialogic.dx_setevtmsk(device, Dialogic.DM_RINGS|Dialogic.DM_RNGOFF);
Dialogic.dx_setparm(device, Dialogic.DXCH_RINGCNT, nRings);
int linest = Dialogic.ATDX_LINEST(device);
if ((linest & Dialogic.RLS_HOOK) == 0) {
Dialogic.dx_sethook(device, Dialogic.DX_ONHOOK, Dialogic.EV_ASYNC);
waitIdle();
}
do {
evt = channel.serviceWaitEvent();
} while (evt.type != EVT.TDX_CST || evt.cstevt != EVT.DE_RINGS);
} finally {
channel.endService();
}
}
/** Play smth */
public synchronized void play(IOTT iott, TPT tpt, int mode) {
if (iott == null || tpt == null)
throw new RuntimeException("Bad parameter value");
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice play (" + device + ")");
Dialogic.dx_play(this, iott, tpt, mode|Dialogic.EV_ASYNC);
this.iott = iott;
}
/** Play tone */
public synchronized void playtone(TNGEN tn, TPT tpt) {
if (tn == null || tpt == null)
throw new RuntimeException("Bad parameter value");
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice playtone (" + device + ")");
Dialogic.dx_playtone(this, tn, tpt, Dialogic.EV_ASYNC);
}
/** Record smth */
public synchronized void record(IOTT iott, TPT tpt, int mode) {
if (iott == null || tpt == null)
throw new RuntimeException("Bad parameter value");
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice record (" + device + ")");
Dialogic.dx_rec(this, iott, tpt, mode|Dialogic.EV_ASYNC);
this.iott = iott;
}
/** Play smth maybe wav */
public synchronized void playiottdata(IOTT iott, TPT tpt, XPB xpb, int mode) {
if (iott == null || tpt == null || xpb == null)
throw new RuntimeException("Bad parameter value");
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"IOTTdata play (" + device + ")");
Dialogic.dx_playiottdata(this, iott, tpt, xpb, mode|Dialogic.EV_ASYNC);
this.iott = iott;
this.xpb = xpb;
}
/** Record smth maybe wav */
public synchronized void recordiottdata(IOTT iott, TPT tpt, XPB xpb, int mode) {
if (iott == null || tpt == null || xpb == null)
throw new RuntimeException("Bad parameter value");
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"IOTTdata record (" + device + ")");
Dialogic.dx_reciottdata(this, iott, tpt, xpb, mode|Dialogic.EV_ASYNC);
this.iott = iott;
this.xpb = xpb;
}
/** Record smth maybe wav from 2 sources*/
public synchronized void recordiottdata(IOTT iott, TPT tpt, XPB xpb, int mode, int ts1, int ts2) {
if (iott == null || tpt == null || xpb == null)
throw new RuntimeException("Bad parameter value");
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"IOTTdata record 2 (" + device + ")");
Dialogic.dx_mreciottdata(this, iott, tpt, xpb, mode|Dialogic.EV_ASYNC, ts1, ts2);
this.iott = iott;
this.xpb = xpb;
}
/** Get last transfer count (# of bytes played/recorded) */
public synchronized int trcount() {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Get transfer count()");
return Dialogic.ATDX_TRCOUNT(device);
}
/** Set Xfer size for UIO */
public synchronized void setBufSize(int size) {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Set buffer size (" + device + "," + size + ")");
Dialogic.dx_setparm(device,Dialogic.DXCH_XFERBUFSIZE, size);
}
/** Read Xfer size */
public synchronized int getBufSize() {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Get buffer size ()");
return Dialogic.dx_getparm(device,Dialogic.DXCH_XFERBUFSIZE);
}
/** Set ANI (analog caller-ID) enabling */
public synchronized void setCallerIdEnabled(boolean enable) {
int param = enable ? Dialogic.DX_CALLIDENABLE : Dialogic.DX_CALLIDDISABLE;
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"enable CallerId (" + device + "," + enable + ")");
Dialogic.dx_setparm(device, Dialogic.DXCH_CALLID, param);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -