📄 vojxtacallcontrol.java
字号:
/** * Returns the average time it takes to encode raw bytes from audio in. */ public int getAverageEncodeTime () { return micControl.getAverageEncodeTime (); } /** * Returns the average time it takes to decode encoded bytes from pipe in */ public long getAverageDecodeTime () { return speakerControl.getAverageDecodeTime (); } /** * Returns a string formated to represent hours:minutes:seconds of the time * elapsed since call start. */ protected String formatElapsedTime (long elapsedTime) { long tmp = elapsedTime; long hours = tmp / HOUR; tmp = tmp - (hours * HOUR); long minutes = tmp / MINUTE; tmp = tmp - (minutes * MINUTE); long seconds = tmp / SECOND; String timeString = null; if(hours < 10) { timeString = "0"; } timeString = String.valueOf (hours) + this.TIME_SEPARATOR;; if(minutes < 10) { timeString = timeString + "0"; } timeString = timeString + String.valueOf (minutes) + this.TIME_SEPARATOR; if(seconds < 10) { timeString = timeString + "0"; } timeString = timeString + String.valueOf (seconds); return timeString; } /** * Sets the size of the outgoing buffer holding encoded audio blocks. This * Should be adjusted along with the encoded message size or a buffer * overflow could occur. */ public void setOutgoingEncodedBufferSize (int bufferSize) { micControl.setEncodedBufferSize (bufferSize); } /** * Sets the size of the incoming buffer holding encoded audio blocks. This * should be adjusted along with the encoded message size or a buffer * overflow could occur. */ public void setIncomingEncodedBufferSize (int bufferSize) { speakerControl.setEncodedBufferSize (bufferSize); } /** * Returns the size of the outgoing buffer holding the encoded audio * blocks. */ public int getOutgoingEncodedBufferSize () { return micControl.getEncodedBufferSize (); } /** * Returns the size of the incoming buffer holding the encoded audio * blocks */ public int getIncomingEncodedBufferSize () { return speakerControl.getEncodedBufferSize (); } /** * Sets the size of the block sent to source data line (speaker). This * value can affect latency of audio messages. Possibly create choppyness */ public void setIncomingEncodedMessageSize (int messageSize) { //speakerControl.setEncodedMessageSize (messageSize); } /** * Sets the number of encoded bytes per message sent to the remote peer on * this pipe */ public void setOutgoingEncodedMessageSize (int messageSize) { //micControl.setEncodedMessageSize (messageSize); } /** * Returns the number of bytes taken from the buffer to be player on the * source data line (speaker) */ public int getIncomingEncodedMessageSize () { return speakerControl.getEncodedMessageSize (); } /** * Returns the number of bytes of encoded audio data per message sent on * this pipe. */ public int getOutgoingEncodedMessageSize () { return micControl.getEncodedMessageSize (); } /** * Returns the size in bytes of raw audio read from target line (mic) */ public int getAudioBlockSize () { return micControl.getAudioBlockSize (); } /** * Returns the basic block size in bytes of encoded audio. */ public int getEncodedBlockSize () { return micControl.getEncodedBlockSize (); } /** * Returns a string representing the name of the remote peer */ public String getRemoteParticipant () { return new String ("Remote"); } /** * Returns the Dialog that this module is attched. */ public Dialog getDialog () { return this.vojxtaDialog; } /** * Called on session end. Closes all open audio resources. */ public void destroy () { if(micControl != null) { micControl.endMic (); micControl.releaseHardware (); } micControl = null; if(speakerControl != null) { speakerControl.endSpeaker (); speakerControl.releaseHardware (); } speakerControl = null; } /** * Returns the audio out control. */ public VoiceSpeakerOutput getSpeakerControl () { return this.speakerControl; } /** * Returns the audio input control. */ public VoiceMicrophoneInput getMicControl () { return this.micControl; } protected void initAudioSystem() { micControl.obtainHardware (); speakerControl.obtainHardware (); } /** * Executes the session protocol logic. * * basic order of operations: * SessionInviteRequest --> * <-- SessionInviteAccept * CallStartRequest --> * <-- CallStartAccept * CallHangupRequest --> * <-- CallHangupAccept * SessionEndRequest --> * <-- SessionEndAccept * * The Peer to Send an invitation controls the session start and call start. * After this either peer may place the call on hold. Once on hold only the * peer to place the call on hold may resume the call. CallHangup may be * performed by either peer. Quality elements are added to startcall * commands. Voice data messages are not squenced and do not require ack's. * Session logic is limited to two peers. Protocol state is used as an * event notification mechanism and to determine protocol command order. * This is not an adaptive protocol. Strict order of operations is observed */ public void callControl (String command, DialogMessage msg) { LOG.setLevel (Level.INFO); if(COMMAND_VOJXTA_INVITE_REQUEST.equals (command) ) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_INVITE_REQUEST+" received"); } if (getProtocolState () == this.SESSION_VOJXTA_DISCONNECTED) { setProtocolState (this.SESSION_VOJXTA_INVITE_REQUEST_RECEIVED); }else{ if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("expected SESSION_DISCONNECTED - got "+command); } } }else if(COMMAND_VOJXTA_INVITE_ACCEPT.equals (command) ) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_INVITE_ACCEPT+" received"); } if (getProtocolState () == this.SESSION_VOJXTA_INVITE_REQUEST_SENT) { updateAckThread (command); setProtocolState (this.SESSION_VOJXTA_INVITE_ACCEPT_RECEIVED); localActionSendStartRequest (); }else{ if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("expected SESSION_VOJXTA_INVITE_REQUEST_SENT - got "+command); } } }else if(COMMAND_VOJXTA_START_REQUEST.equals (command) ) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_START_REQUEST+" received"); } initAudioSystem(); if (getProtocolState () == this.SESSION_VOJXTA_INVITE_ACCEPT_SENT) { setProtocolState (this.SESSION_VOJXTA_START_REQUEST_RECEIVED); localActionStartRequestReceived (msg); localActionStartVoiceTransmision (); setProtocolState (this.SESSION_VOJXTA_INCALL); }else{ if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("expected SESSIONVOJXTA_INVITE_ACCEPT_SENT - got "+command); } } }else if(COMMAND_VOJXTA_START_ACCEPT.equals (command) ) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_START_ACCEPT+" received"); } initAudioSystem(); if (getProtocolState () == this.SESSION_VOJXTA_START_REQUEST_SENT) { updateAckThread (command); setProtocolState (this.SESSION_VOJXTA_START_ACCEPT_RECEIVED); localActionStartAcceptReceived (msg); // this is the last command received before starting voice // transmission/reception. signal thread to start sending vojxtadata localActionStartVoiceTransmision (); setProtocolState (this.SESSION_VOJXTA_INCALL); }else{ if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("expected SESSION_VOJXTA_START_REQUEST_SENT - got "+command); } } }else if (COMMAND_VOJXTA_HOLD_REQUEST.equals (command)) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_HOLD_REQUEST+" received"); } if(getProtocolState () == this.SESSION_VOJXTA_INCALL) { setProtocolState (this.SESSION_VOJXTA_HOLD_REQUEST_RECEIVED); sendCommand (this.COMMAND_VOJXTA_HOLD_ACCEPT, null); setProtocolState (this.SESSION_VOJXTA_HOLD_ACCEPT_SENT); //place call on hold - we did not initiate the hold localActionHoldCall (false); setProtocolState (this.SESSION_VOJXTA_HOLDING); }else{ if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("expected SESSION_VOJXTA_INCALL - got "+command); } } }else if(COMMAND_VOJXTA_HOLD_ACCEPT.equals (command) ) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_HOLD_ACCEPT+" received"); } if(getProtocolState () == this.SESSION_VOJXTA_HOLD_REQUEST_SENT) { updateAckThread (command); setProtocolState (this.SESSION_VOJXTA_HOLD_ACCEPT_RECEIVED); //place call on hold - we initiate the hold localActionHoldCall (true); setProtocolState (this.SESSION_VOJXTA_HOLDING); }else{ if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("expected SESSION_VOJXTA_HOLD_REQUEST_SENT - got "+command); } } }else if(COMMAND_VOJXTA_RESUME_REQUEST.equals (command)) { if (LOG.isEnabledFor (Level.INFO)) { LOG.info ("callControl : "+this.COMMAND_VOJXTA_RESUME_REQUEST+" received"); } if(getProtocolState () == this.SESSION_VOJXTA_HOLDING) { setProtocolState (this.SESSION_VOJXTA_RESUME_REQUEST_RECEIVED); sendCommand (this.COMMAND_VOJXTA_RESUME_ACCEPT, null); setProtocolState (this.SESSION_VOJXTA_RESUME_ACCEPT_SENT); // resume call localActionResumeCall (); setProtocolState (this.SESSION_VOJXTA_INCALL); }else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -