⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcmediaservice.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * @return The number of milliseconds after a release call to wait incase I'm un-released.
 */
private int getFreeDelay() {
	return freeDelay;
}
/**
 * Internal lazy accessor for the Garbage Collector.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @return A new or existing Garbage collector thread.
 */
private Thread getGarbageCollector() {
	if (this.garbageCollector == null) {
		Thread t = this.garbageCollector = new Thread(new Reaper(this.getFreeDelay()));
		t.setDaemon(true);
	}
	return garbageCollector;
}
/**
 * getListeners method comment.
 */
public java.util.Iterator getListeners() {
	return this.listeners.iterator();
}
/**
 * I'm not a real MediaService...
 */
public javax.telephony.media.MediaService getMediaService() {
	return null;
}
/**
 * Return the current media playing state.
 * Creation date: (2000-05-15 11:18:29)
 * @author: Richard Deadman
 * @return int
 */
int getMediaState() {
	return this.getPrivateMediaState() & PLAY_REC;
}
/**
 * Get the media service manager
 * Creation date: (2000-05-11 15:43:30)
 * @author: Richard Deadman
 * @return The manager that maps bound media service holders to terminals
 */
private MediaMgr getMgr() {
	return mgr;
}
/**
 * Internal lazy accessor for the Player Thread.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @return A new or existing Garbage collector thread.
 */
private PlayThread getPlayerThread() {
	if (this.playerThread == null) {
		Thread t = this.playerThread = new PlayThread(this.getProv(), this.getTermConn());
		t.start();
	}
	return playerThread;
}
/**
 * Return the current media true state.
 * Creation date: (2000-05-15 11:18:29)
 * @author: Richard Deadman
 * @return int
 */
private int getPrivateMediaState() {
	return this.mediaState;
}
/**
 * Get the Framework manager.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @return The root controller for the Generic JTAPI framework
 */
private GenericProvider getProv() {
	return prov;
}
/**
 * Internal lazy accessor for the Record Thread.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @return A new or existing Record thread.
 */
private RecordThread getRecordThread() {
	if (this.recorderThread == null) {
		Thread t = this.recorderThread = new RecordThread(this.getProv(), this.getTermConn());
		t.start();
	}
	return recorderThread;
}
/**
 * Return the MediaTerminalConnection I manage media binding for.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @return A MediaTerminalConnection that has requested to use old 1.2 media calls.
 */
FreeMediaTerminalConnection getTermConn() {
	return termConn;
}
/**
 * Return the Terminal I am associated with
 */
private Terminal getTerminal() throws NotBoundException {
	return this.termConn.getTerminal();
}
/**
 * Get the name of the Terminal I am associated with.
 */
private String getTerminalName() throws NotBoundException {
	return this.getTerminal().getName();
}
/**
 * Note that the playing thread has stopped.
 * Creation date: (2000-05-11 14:28:16)
 * @author: Richard Deadman
 */
void playingStopped() {
	this.removeMediaState(MediaTerminalConnection.PLAYING);

	// see if we need to release now
	this.release();
}
/**
 * Really release the pseudo media service from the terminal.
 *
 * @author Richard Deadman
 */
private synchronized void reallyRelease() {
	if ((this.getAllocateState() == REAPING) &&
		(this.getPrivateMediaState() == MediaTerminalConnection.NOACTIVITY)) {
		// free the media
		this.getProv().getRaw().freeMedia(this.getTermConn().getTerminal().getName(),
			TelephonyProvider.MEDIA_RES_ALL);

		// unbind from the media manager
		this.getMgr().release(this.getTerminalName());

		// unbind from the TerminalConnection
		this.getTermConn().freeMediaService();

		// we should be garbage collected now, but just to be safe.
		this.setAllocateState(FREE);
	}
}
/**
 * Note that the recording thread has stopped.
 * Creation date: (2000-05-11 14:28:16)
 * @author: Richard Deadman
 */
void recordingStopped() {
	this.removeMediaState(MediaTerminalConnection.RECORDING);

	// see if we need to release now
	this.release();
}
/**
 * Release the pseudo media service from the terminal.
 *
 * <P>This launches a thread that delays the release for a couple of seconds to take care
 * of us needing the service a short time later.
 *
 * @author Richard Deadman
 */
private synchronized  void release() throws NotBoundException {
	// test current bind state
	int state = this.getAllocateState();
	if (state == FREE)
		throw new NotBoundException();

	if (state == REAPING)
		return;	// we're already releasing

	// test if we are really not doing anything
	if (this.getPrivateMediaState() == MediaTerminalConnection.NOACTIVITY) {
		this.setAllocateState(REAPING);
		this.getGarbageCollector().start();
	}
}
/**
 * Remove this state flag from the MediaState holder.
 * Creation date: (2000-05-15 13:09:53)
 * @author: Richard Deadman
 * @param removedState int
 */
private void removeMediaState(int removedState) {
	if ((this.getPrivateMediaState() & removedState) != 0) {
		this.mediaState &= (Integer.MAX_VALUE - removedState);

		// do we need to notify any call listeners
		if ((removedState & PLAY_REC) != 0) {
			((FreeCall)this.getTermConn().getConnection().getCall()).sendToObservers(new StateEv(this.getTermConn()));
		}
	}
}
/**
 * Forward the 1.2 event onto the call.  Note that 1.2 media reported events on Observers of Calls,
 * whereas in 1.3 media events are reported to Listener's of MediaServices.  Since we are a bridge
 * from a 1.2 MediaTerminalConnection media triggered events, we know that we only need to send to
 * Call Observers.
 * Creation date: (2000-05-09 16:11:06)
 * @author: Richard Deadman
 * @param ev FreeCallEvent that is a 1.2 style Observer event.
 */
void send(FreeCallEvent ev) {
	((FreeCall)this.getTermConn().getConnection().getCall()).sendToObservers(ev);
}
/**
 * Set my current media allocation state.  The state machine is FREE -&gt; ALLOCATED &lt;-&gt; REAPING -&gt; FREE.
 * Creation date: (2000-05-11 15:06:28)
 * @author: Richard Deadman
 * @param newAllocateState The new state for the pseudo media service -- FREE, ALLOCATED or REAPING.
 */
private void setAllocateState(int newAllocateState) {
	allocateState = newAllocateState;
}
  /*
   * Sets the DTMF tone detection either on or off. If the boolean flag
   * argument is true, then DTMF detection is turned on, otherwise, it is
   * turned off.
   * <p>
   * @param enable If true, turns DTMF-tone detection on, if false, turns
   * DTMF-tone detection off.
   * @exception MethodNotSupportedException The implementation does not
   * support the detection of DTMF-tones.
   * @exception ResourceUnavailableException Indicates DTMF-detection cannot
   * be started because some resource is unavailable.
   * @exception InvalidStateException Indicates the TerminalConnection is not
   * in the media channel available state.
   */
public synchronized void setDtmfDetection(boolean enable) throws InvalidStateException, ResourceUnavailableException {
	if (enable) {
			// turn on signal detection
		Dictionary dict = new Hashtable();
		dict.put(SignalDetectorConstants.p_EnabledEvents, SignalDetectorConstants.ev_RetrieveSignals);
			// reallocate in order to force change in dictionary
		this.allocate(dict, true);
			// note that we are in detecting mode
		this.addMediaState(DTMF_DET);
	} else {
			// reallocate in order to force change in dictionary
		this.allocate(null, true);
			// note that we've not detecting anymore
		this.removeMediaState(DTMF_DET);
			// release media service if that's are only activity
		this.release();
	}
}
/**
 * Set the REAPING delay for the garbage collector thread.
 * Once the garbage collector is lazily created, this value is not used again and so setting
 * it will have no effect.
 * Creation date: (2000-05-11 15:27:02)
 * @author: Richard Deadman
 * @param newFreeDelay The number of milliseconds the garbage collector should wait before really
 * unbinding this pseudo media service.
 */
private void setFreeDelay(int newFreeDelay) {
	freeDelay = newFreeDelay;
}
/**
 * Set the media service manager
 * Creation date: (2000-05-11 15:43:30)
 * @author: Richard Deadman
 * @param newMgr The manager that maps bound media service holders to terminals
 */
private void setMgr(MediaMgr newMgr) {
	mgr = newMgr;
}
/**
 * Sets the root Generic JTAPI manager object.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @param newProv The root handle to the framework.
 */
private void setProv(net.sourceforge.gjtapi.GenericProvider newProv) {
	prov = newProv;
}
/**
 * Set the TerminalConnection I handle media binding for.
 * Creation date: (2000-05-11 15:24:09)
 * @author: Richard Deadman
 * @param newTermConn A 1.2 media TerminalConnection I am the pseeudo MediaService for.
 */
private void setTermConn(FreeMediaTerminalConnection newTermConn) {
	termConn = newTermConn;
}
/**
 * Start playing a URL set in the "usePlayURL()" method.
 * @author: Richard Deadman
 * @param The MediaTerminalConnection current play url.
 */
synchronized void startPlaying(String playUrl) throws ResourceUnavailableException {
	if ((this.getMediaState() & MediaTerminalConnection.PLAYING) == MediaTerminalConnection.PLAYING) {
		// we're already playing
		return;
	}

	if (playUrl == null) {
		throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "No play URL defined");
	}

		// ensure we're allocated
	this.allocate();
	this.getPlayerThread().playStream(playUrl);
	this.addMediaState(MediaTerminalConnection.PLAYING);
}
/**
 * Start playing a URL set in the "usePlayURL()" method.
 */
synchronized void startRecording(String recordUrl) throws ResourceUnavailableException {
	if ((this.getMediaState() & MediaTerminalConnection.RECORDING) == MediaTerminalConnection.RECORDING) {
		// we're already playing
		return;
	}

	if (recordUrl == null) {
		throw new ResourceUnavailableException(ResourceUnavailableException.UNKNOWN, "No record URL defined");
	}
	
		// ensure we're allocated
	this.allocate();
	this.getRecordThread().recordStream(recordUrl);
	this.addMediaState(MediaTerminalConnection.RECORDING);
}
/**
 * Tell the playing thread to stop by sending a stop RTC to the media player
 */
void stopPlaying() {
	this.getProv().getRaw().triggerRTC(this.getTerminalName(), PlayerConstants.rtca_Stop);
}
/**
 * Tell the recoding thread to stop by sending an RTC to the media recorder.
 */
void stopRecording() {
	this.getProv().getRaw().triggerRTC(this.getTerminalName(), RecorderConstants.rtca_Stop);
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -