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

📄 vojxtacallcontrol.java

📁 Myjxta的源代码 基于JXTA的P2P即时通信系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }    /**     * 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.     * <p/>     * basic order of operations:     * SessionInviteRequest -->     * <-- SessionInviteAccept     * CallStartRequest -->     * <-- CallStartAccept     * CallHangupRequest -->     * <-- CallHangupAccept     * SessionEndRequest -->     * <-- SessionEndAccept     * <p/>     * 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 (Logging.SHOW_INFO && LOG.isLoggable(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 (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_DISCONNECTED - got " + command);                }            }        } else if (COMMAND_VOJXTA_INVITE_ACCEPT.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(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 (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_INVITE_REQUEST_SENT - got " +                            command);                }            }        } else if (COMMAND_VOJXTA_START_REQUEST.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(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 (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSIONVOJXTA_INVITE_ACCEPT_SENT - got " +                            command);                }            }        } else if (COMMAND_VOJXTA_START_ACCEPT.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(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 (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_START_REQUEST_SENT - got " +                            command);                }            }        } else if (COMMAND_VOJXTA_HOLD_REQUEST.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(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 (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_INCALL - got " + command);                }            }        } else if (COMMAND_VOJXTA_HOLD_ACCEPT.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(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 (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_HOLD_REQUEST_SENT - got " +                            command);                }            }        } else if (COMMAND_VOJXTA_RESUME_REQUEST.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(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 {                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_HOLDING - got " + command);                }            }        } else if (COMMAND_VOJXTA_RESUME_ACCEPT.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                LOG.info("callControl : " + this.COMMAND_VOJXTA_RESUME_ACCEPT +                        " received");            }            if (getProtocolState() == this.SESSION_VOJXTA_RESUME_REQUEST_SENT) {                updateAckThread(command);                setProtocolState(this.SESSION_VOJXTA_RESUME_ACCEPT_RECEIVED);                // resume call                localActionResumeCall();                setProtocolState(this.SESSION_VOJXTA_INCALL);            } else {                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_RESUME_REQUEST_SENT - got " +                            command);                }            }        } else if (COMMAND_VOJXTA_HANGUP_REQUEST.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                LOG.info("callControl : " + this.COMMAND_VOJXTA_HANGUP_REQUEST +                        " received");            }            if (getProtocolState() == this.SESSION_VOJXTA_INCALL) {                setProtocolState(this.SESSION_VOJXTA_HANGUP_REQUEST_RECEIVED);                sendCommand(this.COMMAND_VOJXTA_HANGUP_ACCEPT, null);                setProtocolState(this.SESSION_VOJXTA_HANGUP_ACCEPT_SENT);                // hangup call - stop transfering data                localActionEndCall();                setProtocolState(this.SESSION_VOJXTA_ENDED);            } else {                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_INCALL - got " + command);                }            }        } else if (COMMAND_VOJXTA_HANGUP_ACCEPT.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                LOG.info("callControl : " + this.COMMAND_VOJXTA_HANGUP_ACCEPT +                        " received");            }            if (getProtocolState() == this.SESSION_VOJXTA_HANGUP_REQUEST_SENT) {                updateAckThread(command);                setProtocolState(this.SESSION_VOJXTA_HANGUP_ACCEPT_RECEIVED);                //hang up call                localActionEndCall();                sendCommand(this.COMMAND_VOJXTA_DISCONNECT_REQUEST, this.COMMAND_VOJXTA_DISCONNECT_ACCEPT);                setProtocolState(this.SESSION_VOJXTA_ENDED);            } else {                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_HANGUP_REQUEST_SENT - got " +                            command);                }            }        } else if (COMMAND_VOJXTA_DISCONNECT_REQUEST.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                LOG.info("callControl : " +                        this.COMMAND_VOJXTA_DISCONNECT_REQUEST + " received");            }            if (getProtocolState() == this.SESSION_VOJXTA_ENDED) {                setProtocolState(this.SESSION_VOJXTA_DISCONNECT_REQUEST_RECEIVED);                sendCommand(this.COMMAND_VOJXTA_DISCONNECT_ACCEPT, null);                setProtocolState(this.SESSION_VOJXTA_DISCONNECT_ACCEPT_SENT);                //disconnect from host - close window no more calls from this tab                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("Disconnecting");                }                localActionEndSession();                setProtocolState(this.SESSION_VOJXTA_DISCONNECTED);            } else {                // the other side is going down... kill session                // this is the non graceful shutdown withthe protocol being in any state                setProtocolState(this.SESSION_VOJXTA_DISCONNECT_REQUEST_RECEIVED);                sendCommand(this.COMMAND_VOJXTA_DISCONNECT_ACCEPT, null);                setProtocolState(this.SESSION_VOJXTA_DISCONNECT_ACCEPT_SENT);                //disconnect from host - close window no more calls from this tab                localActionEndSession();                setProtocolState(this.SESSION_VOJXTA_DISCONNECTED);                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_ENDED - got " + command);                    LOG.info("Ungraceful disconnect received...Going Down");                }            }        } else if (COMMAND_VOJXTA_DISCONNECT_ACCEPT.equals(command)) {            if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                LOG.info("callControl : " +                        this.COMMAND_VOJXTA_DISCONNECT_ACCEPT + " received");            }            if (getProtocolState() == this.SESSION_VOJXTA_ENDED) {                updateAckThread(command);                setProtocolState(this.SESSION_VOJXTA_DISCONNECT_ACCEPT_RECEIVED);                //disconnect from host - close window no more calls from this tab                localActionEndSession();                setProtocolState(this.SESSION_VOJXTA_DISCONNECTED);            } else {                // the other side is going down... kill session                // TODO:                if (Logging.SHOW_INFO && LOG.isLoggable(Level.INFO)) {                    LOG.info("expected SESSION_VOJXTA_ENDED - got " + command);                }            }        }    }//call control    /**     * message has been received... determine if its the correct response     */    protected void updateAckThread(String command) {        LOG.info("Checking AckThread");        if (messageAckThread != null) {            messageAckThread.setMessageAcknowledged(command);            if (messageAckThread.isThreadEnded()) {                messageAckThread = null;            }        } else {            LOG.info("MessageAckThread is null!!");        }    }    /**     * these methods offer an interface to audio controls. volume, mute etc     */    public boolean isMicGainSupported() {        return micControl.isGainControlSupported();    }    public float getMicGainValue() {        return micControl.getGainValue();    }    /**     * Control state accessor

⌨️ 快捷键说明

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