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);
}
}
}
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;
}
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;
}
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;
}
}
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();
}
}
Aggregations