2019-07-30 15:33:56 +00:00
|
|
|
/*
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
* and open the template in the editor.
|
|
|
|
*/
|
|
|
|
package model;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Vector;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.sdp.SdpFactory;
|
|
|
|
import javax.sdp.SessionDescription;
|
|
|
|
import javax.sip.RequestEvent;
|
|
|
|
import logger.OhmLogger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Jan
|
|
|
|
*/
|
|
|
|
public class SIPSessionDescription
|
|
|
|
{
|
|
|
|
private SdpFactory sdpFactory;
|
|
|
|
private SessionDescription sessionDescription;
|
|
|
|
private Vector mediavec;
|
2019-07-30 17:18:26 +00:00
|
|
|
private String cods[]; //Hilfsarray für [RTP-Notation]
|
|
|
|
private String[][] codecs; //[RTP-Notation][Codec/SampelRate]
|
2019-07-30 15:33:56 +00:00
|
|
|
private static final Logger lgSessionDescription = OhmLogger.getLogger();
|
|
|
|
|
|
|
|
public SIPSessionDescription(String myName, String myIPAddress,
|
|
|
|
RequestEvent requestEvent, Boolean anfrage)
|
|
|
|
{
|
2019-07-30 17:18:26 +00:00
|
|
|
//Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate]
|
|
|
|
codecs = new String[4][2];
|
2019-07-30 15:33:56 +00:00
|
|
|
codecs[0][0] = "0";
|
|
|
|
codecs[0][1] = "PCMU/8000";
|
|
|
|
codecs[1][0] = "4";
|
|
|
|
codecs[1][1] = "G723/8000";
|
|
|
|
codecs[2][0] = "8";
|
|
|
|
codecs[2][1] = "PCMA/8000";
|
|
|
|
codecs[3][0] = "18";
|
|
|
|
codecs[3][1] = "G729/8000";
|
2019-07-30 17:18:26 +00:00
|
|
|
|
2019-07-30 15:33:56 +00:00
|
|
|
cods = new String[codecs.length];
|
2019-07-30 17:14:55 +00:00
|
|
|
for (int i = 0; i < 4; i++)//Übertragung der RTP-Values in neues Array
|
2019-07-30 15:33:56 +00:00
|
|
|
{
|
|
|
|
cods[i] = codecs[i][0];
|
|
|
|
}
|
|
|
|
mediavec = new Vector();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
sdpFactory = SdpFactory.getInstance();
|
|
|
|
sessionDescription = sdpFactory.createSessionDescription();
|
|
|
|
sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress));
|
|
|
|
sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call"));
|
|
|
|
sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress));
|
|
|
|
|
|
|
|
//Media Body
|
2019-07-30 17:14:55 +00:00
|
|
|
|
|
|
|
if (anfrage == true)
|
2019-07-30 15:33:56 +00:00
|
|
|
{
|
2019-07-30 17:14:55 +00:00
|
|
|
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
|
|
|
|
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
|
|
|
|
for (int i = 0; i == 4; i++)
|
2019-07-30 15:33:56 +00:00
|
|
|
{
|
|
|
|
System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]);
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen
|
|
|
|
{
|
|
|
|
String[] reqbody = (requestEvent.getRequest()).toString().split("\\s|" + System.getProperty("line.seperator"));
|
|
|
|
ArrayList<String> reqSDP = new ArrayList<>();
|
|
|
|
for (String req : reqbody)
|
|
|
|
{
|
|
|
|
if (req.startsWith("a=rtpmap"))
|
|
|
|
{
|
|
|
|
reqSDP.add(req.replace("a=rtpmap:", ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird
|
2019-07-30 17:14:55 +00:00
|
|
|
int position = 0;
|
|
|
|
for (String stcodec : cods)
|
2019-07-30 15:33:56 +00:00
|
|
|
{
|
2019-07-30 17:14:55 +00:00
|
|
|
|
|
|
|
System.out.println("------Auswahl des codecs----");
|
|
|
|
if (reqSDP.contains(stcodec) && temp == true)
|
|
|
|
{
|
|
|
|
String tempcodec[]= new String [1];
|
|
|
|
tempcodec[0] = codecs[position][1];
|
|
|
|
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", tempcodec)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
|
|
|
|
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
|
|
|
|
mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[position][0] + " " + codecs[position][1]));
|
2019-07-30 15:33:56 +00:00
|
|
|
temp = false;
|
|
|
|
}
|
2019-07-30 17:14:55 +00:00
|
|
|
position++;
|
2019-07-30 15:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sessionDescription.setAttributes(mediavec);
|
2019-07-30 17:26:19 +00:00
|
|
|
lgSessionDescription.info("SDP Header erstellt");
|
2019-07-30 15:33:56 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
lgSessionDescription.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @return the sessionDescription
|
|
|
|
*/
|
|
|
|
public SessionDescription getSessionDescription()
|
|
|
|
{
|
|
|
|
return sessionDescription;
|
|
|
|
}
|
|
|
|
}
|