Search in sources :

Example 1 with MediaInfo

use of com.sun.voip.MediaInfo in project Openfire by igniterealtime.

the class SipTPCCallAgent method handleCallParticipantInvited.

/**
     * handles the INVITED state.
     * @param response the response
     * @param clientTransaction the client transaction
     * @throws SipException SIP stack related error
     */
private void handleCallParticipantInvited(Response response, ClientTransaction clientTransaction) throws ParseException, SipException, InvalidArgumentException {
    FromHeader fromHeader = (FromHeader) response.getHeader(FromHeader.NAME);
    String displayName = fromHeader.getAddress().getDisplayName();
    int statusCode = response.getStatusCode();
    Logger.println("handleCallParticipantInvited " + cp + " status " + statusCode + " " + response.getReasonPhrase());
    Logger.println("handleCallParticipantInvited , displayname " + displayName);
    CallIdHeader callIdHeader = (CallIdHeader) response.getHeader(CallIdHeader.NAME);
    if (sipCallId.equals(callIdHeader.getCallId()) && displayName.equals(cp.getDisplayName()) && (statusCode == Response.OK || statusCode == Response.SESSION_PROGRESS) && ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod().equals(Request.INVITE)) {
        if (statusCode == Response.SESSION_PROGRESS) {
            if (cp.getHandleSessionProgress() == false) {
                Logger.writeFile("Call " + cp + " Ignoring SESSION_PROGRESS");
                return;
            }
            Logger.writeFile("Call " + cp + " Treating SESSION_PROGRESS as OK");
        }
        if (response.getRawContent() == null) {
            Logger.error("Call " + cp + " no SDP in OK Response!");
            cancelRequest("SIP error!  no SDP in OK Response!");
            return;
        }
        this.clientTransaction = clientTransaction;
        if (statusCode == Response.OK) {
            gotOk = true;
            Logger.writeFile("Call " + cp + " Got OK, call answered\n" + response);
        }
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        if (statusCode == Response.OK) {
            sipUtil.sendAck(clientTransaction);
            ackSent = true;
        }
        if (callAnswered) {
            Logger.writeFile("Call " + cp + " done processing OK");
            return;
        }
        /*
			 * Remember the IP and port of where to send data to
			 * the CallParticipant.
			 */
        sdpBody = new String(response.getRawContent());
        SdpInfo sdpInfo;
        try {
            sdpInfo = sipUtil.getSdpInfo(sdpBody, false);
        } catch (ParseException e) {
            Logger.error("Call " + cp + " Invalid SDP in OK Response! " + e.getMessage());
            cancelRequest("SIP error!  Invalid SDP in OK Response!");
            return;
        }
        MediaInfo mediaInfo = sdpInfo.getMediaInfo();
        InetSocketAddress isa = new InetSocketAddress(sdpInfo.getRemoteHost(), sdpInfo.getRemotePort());
        InetSocketAddress rtcpAddress = sdpInfo.getRtcpAddress();
        setEndpointAddress(isa, mediaInfo.getPayload(), sdpInfo.getTransmitMediaInfo().getPayload(), sdpInfo.getTelephoneEventPayload(), rtcpAddress);
        /*
			 * The CallParticipant has answered.
			 * If join confirmation is required, we remain in the
			 * INVITED state.  We set the callAnswered flag so that
			 * if the join confirmation times out we know to
			 * send a BYE rather than a CANCEL.
			 */
        callAnswered = true;
        if (cp.getJoinConfirmationTimeout() == 0) {
            setState(CallState.ANSWERED);
        }
        /*
			 * Start treatment if any and wait for it to finish.
			 * When the treatment finishes, notification will
			 * be delivered to our parent which will indicate
			 * we're ready for the conference.
			 *
			 * If there's no treatment to be played, we're ready now
			 * unless we're waiting for join confirmation..
			 */
        initializeCallAnsweredTreatment();
        if (callAnsweredTreatment != null) {
            startCallAnsweredTreatment();
        } else {
            if (cp.getJoinConfirmationTimeout() == 0) {
                setState(CallState.ESTABLISHED);
            }
        }
    } else {
        Logger.writeFile("Call " + cp + " Ignoring response: " + response.getReasonPhrase());
        if (Logger.logLevel >= Logger.LOG_SIP) {
            Logger.println("Call " + cp + " Response: " + response);
        }
    }
}
Also used : MediaInfo(com.sun.voip.MediaInfo) InetSocketAddress(java.net.InetSocketAddress) SdpInfo(com.sun.voip.SdpInfo) ParseException(java.text.ParseException)

Example 2 with MediaInfo

use of com.sun.voip.MediaInfo in project Openfire by igniterealtime.

the class SipUtil method getSdpInfo.

public SdpInfo getSdpInfo(String sdpBody, boolean isRequest) throws ParseException {
    SdpInfo remoteSdpInfo = sdpManager.parseSdp(sdpBody);
    MediaInfo myPreferredMediaInfo = sdpManager.getPreferredMediaInfo();
    byte payload;
    Logger.writeFile("My preferred media " + myPreferredMediaInfo);
    /*
	 * If this is a remote SIP REQUEST and the remote side supports our
	 * preferred mediaInfo, we will reply selecting our preferred media.
	 * Otherwise, we reply using the remote's media choice, which is
	 * either the remote's preferred or the "best" choice.
	 */
    if (isRequest && remoteSdpInfo.isSupported(myPreferredMediaInfo)) {
        payload = myPreferredMediaInfo.getPayload();
        remoteSdpInfo.setMediaInfo(myPreferredMediaInfo);
        Logger.println("My preferred payload being used " + payload);
    } else {
        if (isRequest) {
            Logger.writeFile("My preferred media " + myPreferredMediaInfo + " not supported...");
        }
        try {
            payload = remoteSdpInfo.getMediaInfo().getPayload();
            remoteSdpInfo.setMediaInfo(sdpManager.findMediaInfo(payload));
            Logger.writeFile("media setting is " + remoteSdpInfo.getMediaInfo());
        } catch (ParseException e) {
            remoteSdpInfo.setMediaInfo(new MediaInfo((byte) 0, RtpPacket.PCMU_ENCODING, 8000, 1, false));
        }
    }
    return remoteSdpInfo;
}
Also used : MediaInfo(com.sun.voip.MediaInfo) SdpInfo(com.sun.voip.SdpInfo) ParseException(java.text.ParseException)

Example 3 with MediaInfo

use of com.sun.voip.MediaInfo in project Openfire by igniterealtime.

the class SipUtil method initialize.

/**
     * Static initializer.
     */
public static void initialize() {
    headerFactory = SipServer.getHeaderFactory();
    addressFactory = SipServer.getAddressFactory();
    messageFactory = SipServer.getMessageFactory();
    sipProvider = SipServer.getSipProvider();
    ourIpAddress = SipServer.getSipStack().getIPAddress();
    ourSipPort = sipProvider.getListeningPoint().getPort();
    ourPublicIpAddress = ourIpAddress;
    String s = System.getProperty("com.sun.voip.server.PUBLIC_IP_ADDRESS");
    if (s != null && s.length() > 0) {
        try {
            ourPublicIpAddress = InetAddress.getByName(s).getHostAddress();
        } catch (UnknownHostException e) {
            Logger.println("Invalid public IP address, using " + ourIpAddress);
        }
    }
    Logger.println("Bridge public address:    " + ourPublicIpAddress);
    ourPublicSipPort = ourSipPort;
    s = System.getProperty("com.sun.voip.server.PUBLIC_SIP_PORT");
    if (s != null) {
        try {
            ourPublicSipPort = Integer.parseInt(s);
        } catch (NumberFormatException e) {
            Logger.println("Invalid public SIP Port, using " + ourSipPort);
        }
    }
    Logger.println("Bridge public SIP port:   " + ourSipPort);
    supportedMedia.add(new MediaInfo((byte) 0, RtpPacket.PCMU_ENCODING, 8000, 1, false));
    // supportedMedia.add(new MediaInfo(
    //     (byte)101, RtpPacket.PCM_ENCODING, 8000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 102, RtpPacket.PCM_ENCODING, 8000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 103, RtpPacket.PCM_ENCODING, 16000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 104, RtpPacket.PCM_ENCODING, 16000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 105, RtpPacket.PCM_ENCODING, 32000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 106, RtpPacket.PCM_ENCODING, 32000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 107, RtpPacket.PCM_ENCODING, 44100, 1, false));
    supportedMedia.add(new MediaInfo((byte) 108, RtpPacket.PCM_ENCODING, 44100, 2, false));
    if (false) {
        supportedMedia.add(new MediaInfo((byte) 109, RtpPacket.PCM_ENCODING, 48000, 1, false));
        supportedMedia.add(new MediaInfo((byte) 110, RtpPacket.PCM_ENCODING, 48000, 2, false));
    }
    supportedMedia.add(new MediaInfo((byte) 111, RtpPacket.PCM_ENCODING, 48000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 112, RtpPacket.PCMU_ENCODING, 16000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 113, RtpPacket.PCMU_ENCODING, 16000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 114, RtpPacket.PCMU_ENCODING, 32000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 115, RtpPacket.PCMU_ENCODING, 32000, 2, false));
    if (false) {
        supportedMedia.add(new MediaInfo((byte) 116, RtpPacket.PCMU_ENCODING, 44100, 1, false));
        supportedMedia.add(new MediaInfo((byte) 117, RtpPacket.PCMU_ENCODING, 44100, 2, false));
        supportedMedia.add(new MediaInfo((byte) 118, RtpPacket.PCMU_ENCODING, 48000, 1, false));
        supportedMedia.add(new MediaInfo((byte) 119, RtpPacket.PCMU_ENCODING, 48000, 2, false));
    }
    supportedMedia.add(new MediaInfo((byte) 120, RtpPacket.SPEEX_ENCODING, 8000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 121, RtpPacket.SPEEX_ENCODING, 8000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 122, RtpPacket.SPEEX_ENCODING, 16000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 123, RtpPacket.SPEEX_ENCODING, 16000, 2, false));
    supportedMedia.add(new MediaInfo((byte) 124, RtpPacket.SPEEX_ENCODING, 32000, 1, false));
    supportedMedia.add(new MediaInfo((byte) 125, RtpPacket.SPEEX_ENCODING, 32000, 2, false));
    SdpManager.setSupportedMedia(supportedMedia);
    initialized = true;
}
Also used : MediaInfo(com.sun.voip.MediaInfo) UnknownHostException(java.net.UnknownHostException)

Example 4 with MediaInfo

use of com.sun.voip.MediaInfo in project Openfire by igniterealtime.

the class CallSetupAgent method treatmentDoneNotification.

/**
     * Notification that a treatment has finished
     *
     * The state we are in determines what we do next.
     */
public void treatmentDoneNotification(TreatmentManager treatmentManager) {
    if (Logger.logLevel >= Logger.LOG_MOREINFO) {
        Logger.println("Call " + callHandler + " treatment done notification, current state " + callState + " " + callHandler);
    }
    switch(getState()) {
        case CallState.INVITED:
            /*
             * When join confirmation is requested, we stay in the
             * CALL_PARTICIPANT_INVITED state until a dtmf key is pressed.
             * Then we change state to CALL_PARTICIPANT_ANSWERED and
             * fall through.
	     *
	     * XXX We need to make sure the treatment repeats enough times.
	     * If it finishes before we timeout, we'll treat the call as answered!
	     *
             */
            if (reasonCallTerminated != null) {
                break;
            }
            setState(CallState.ANSWERED);
        case CallState.ANSWERED:
            /*
	     * Call answered treatment is done, we're ready for the conference
	     */
            MediaInfo mediaInfo = callHandler.getConferenceManager().getMediaInfo();
            setState(CallState.ESTABLISHED, "ConferencePayload='" + mediaInfo.getPayload() + "'" + " BridgeIPAddress='" + Bridge.getPrivateHost() + "'");
            break;
        case CallState.ENDING:
            /*
	     * Call end treatment is done, time to end the call
	     */
            terminateCall();
            done();
            break;
        default:
            Logger.error("Call " + callHandler + ":  unexpected state " + callState);
            break;
    }
}
Also used : MediaInfo(com.sun.voip.MediaInfo)

Example 5 with MediaInfo

use of com.sun.voip.MediaInfo in project Openfire by igniterealtime.

the class CallSetupAgent method setState.

protected void setState(int state, String info) {
    callState = new CallState(state);
    CallEvent callEvent = new CallEvent(CallEvent.STATE_CHANGED);
    callEvent.setCallState(callState);
    String s = "";
    if (state == CallState.INVITED || state == CallState.ESTABLISHED) {
        s += "ConferenceReceiverPort='" + callHandler.getReceiveAddress().getPort() + "'";
        MediaInfo mediaInfo = callHandler.getConferenceManager().getMediaInfo();
        s += " ConferencePayload='" + mediaInfo.getPayload() + "'";
        s += " BridgeIPAddress='" + Bridge.getPrivateHost() + "'";
        s += " BridgeInfo='" + Bridge.getPrivateHost() + ":" + Bridge.getPrivateControlPort() + ":" + Bridge.getPrivateSipPort() + ":" + Bridge.getPublicHost() + ":" + Bridge.getPublicControlPort() + ":" + Bridge.getPublicSipPort() + "'";
    }
    if (info != null) {
        s = info + " " + s;
    }
    callEvent.setInfo(s);
    Logger.println("Call " + callHandler + " " + callState);
    sendCallEventNotification(callEvent);
    if (state == CallState.ESTABLISHED) {
        String treatment = cp.getCallEstablishedTreatment();
        if (treatment != null) {
            callEstablishedTreatment = initializeTreatment(treatment, 0);
            if (callEstablishedTreatment != null) {
                addTreatment(callEstablishedTreatment);
            }
        }
    }
    if (inviteTimeoutThread == null && state == CallState.INVITED) {
        inviteTimeoutThread = new Thread(this);
        // start invite timeout thread
        inviteTimeoutThread.start();
    }
}
Also used : MediaInfo(com.sun.voip.MediaInfo) CallEvent(com.sun.voip.CallEvent) CallState(com.sun.voip.CallState)

Aggregations

MediaInfo (com.sun.voip.MediaInfo)15 IOException (java.io.IOException)6 ParseException (java.text.ParseException)5 SdpInfo (com.sun.voip.SdpInfo)4 InetSocketAddress (java.net.InetSocketAddress)4 UnknownHostException (java.net.UnknownHostException)2 CallEvent (com.sun.voip.CallEvent)1 CallParticipant (com.sun.voip.CallParticipant)1 CallState (com.sun.voip.CallState)1 JitterManager (com.sun.voip.JitterManager)1 Recorder (com.sun.voip.Recorder)1 RtpReceiverPacket (com.sun.voip.RtpReceiverPacket)1 SampleRateConverter (com.sun.voip.SampleRateConverter)1 SpeechDetector (com.sun.voip.SpeechDetector)1 SpeexDecoder (com.sun.voip.SpeexDecoder)1 SpeexException (com.sun.voip.SpeexException)1 TreatmentManager (com.sun.voip.TreatmentManager)1 Point (java.awt.Point)1 SocketException (java.net.SocketException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1