You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SIPSessionDescription.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package model;
  7. import java.util.ArrayList;
  8. import java.util.Vector;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.sdp.SdpFactory;
  12. import javax.sdp.SessionDescription;
  13. import javax.sip.RequestEvent;
  14. import logger.OhmLogger;
  15. /**
  16. *
  17. * @author Jan
  18. */
  19. public class SIPSessionDescription
  20. {
  21. private SdpFactory sdpFactory;
  22. private SessionDescription sessionDescription;
  23. private Vector mediavec;
  24. private String codsRTP[]; //[RTP-Notation]
  25. private String codecs[]; //[Codec/SampelRate]
  26. private static final Logger lgSessionDescription = OhmLogger.getLogger();
  27. public SIPSessionDescription(String myName, String myIPAddress, int myRTPPort,
  28. RequestEvent requestEvent, Boolean anfrage)
  29. {
  30. //Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate]
  31. codsRTP = new String[4];
  32. codsRTP[0]= "0";
  33. codsRTP[1] ="4";
  34. codsRTP[2]= "8";
  35. codsRTP[3]= "18";
  36. codecs = new String[4];
  37. codecs[0] = "PCMU/8000";
  38. codecs[1] = "G723/8000";
  39. codecs[2]= "PCMA/8000";
  40. codecs[3]= "G729/8000";
  41. mediavec = new Vector();
  42. try
  43. {
  44. sdpFactory = SdpFactory.getInstance();
  45. sessionDescription = sdpFactory.createSessionDescription();
  46. sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress));
  47. sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call"));
  48. sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress));
  49. //Media Bod
  50. if (anfrage == true)
  51. {
  52. mediavec.add(sdpFactory.createMediaDescription("audio", myRTPPort, 1, "RTP/AVP", codsRTP)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
  53. mediavec.add(sdpFactory.createAttribute("sendrecv", null));
  54. for (int i = 0; i < codsRTP.length; i++)
  55. {
  56. mediavec.add(sdpFactory.createAttribute("rtpmap", codsRTP[i] + " " + codecs[i]));
  57. }
  58. }
  59. else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen
  60. {
  61. String[] reqbody = (requestEvent.getRequest()).toString().split("\\s|" + System.getProperty("line.seperator"));
  62. ArrayList<String> reqSDP = new ArrayList<>();
  63. for (String req : reqbody)
  64. {
  65. if (req.startsWith("a=rtpmap"))
  66. {
  67. reqSDP.add(req.replace("a=rtpmap:", ""));
  68. }
  69. }
  70. int position = 0;
  71. ArrayList<String> tempList = new ArrayList<>();
  72. for (String stcodec : codsRTP)
  73. {
  74. if (reqSDP.contains(stcodec))
  75. {
  76. tempList.add(stcodec);
  77. mediavec.add(sdpFactory.createAttribute("rtpmap", codsRTP[position] + " " + codecs[position]));
  78. }
  79. position++;
  80. }
  81. String[] tempArray = tempList.toArray(new String[tempList.size()]);
  82. mediavec.add(sdpFactory.createMediaDescription("audio", myRTPPort, 1, "RTP/AVP", tempArray)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
  83. mediavec.add(sdpFactory.createAttribute("sendrecv", null));
  84. }
  85. sessionDescription.setAttributes(mediavec);
  86. lgSessionDescription.info("SDP Header erstellt");
  87. }
  88. catch (Exception ex)
  89. {
  90. lgSessionDescription.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
  91. }
  92. }
  93. /**
  94. * @return the sessionDescription
  95. */
  96. public SessionDescription getSessionDescription()
  97. {
  98. return sessionDescription;
  99. }
  100. }