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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 cods[];
  25. private String[][] codecs;
  26. private static final Logger lgSessionDescription = OhmLogger.getLogger();
  27. public SIPSessionDescription(String myName, String myIPAddress,
  28. RequestEvent requestEvent, Boolean anfrage)
  29. {
  30. codecs = new String[4][2]; // Alle unterstützen Codecs eintragen
  31. codecs[0][0] = "0";
  32. codecs[0][1] = "PCMU/8000";
  33. codecs[1][0] = "4";
  34. codecs[1][1] = "G723/8000";
  35. codecs[2][0] = "8";
  36. codecs[2][1] = "PCMA/8000";
  37. codecs[3][0] = "18";
  38. codecs[3][1] = "G729/8000";
  39. cods = new String[codecs.length];
  40. for (int i = 0; i < cods.length; i++)//Übertragung der RTP-Values in neues Array
  41. {
  42. cods[i] = codecs[i][0];
  43. }
  44. mediavec = new Vector();
  45. try
  46. {
  47. sdpFactory = SdpFactory.getInstance();
  48. sessionDescription = sdpFactory.createSessionDescription();
  49. sessionDescription.setOrigin(sdpFactory.createOrigin(myName, 8000, 8000, "IN", "IP4", myIPAddress));
  50. sessionDescription.setSessionName(sdpFactory.createSessionName("SIP Call"));
  51. sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress));
  52. //Media Body
  53. mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", cods)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
  54. mediavec.add(sdpFactory.createAttribute("sendrecv", null));
  55. if (anfrage = true)
  56. {
  57. for (int i = 0; i == codecs[0].length; i++)
  58. {
  59. System.out.println("Codecs: " + codecs[i][0] + " " + codecs[i][1]);
  60. mediavec.add(sdpFactory.createAttribute("rtpmap", codecs[i][0] + " " + codecs[i][1]));
  61. }
  62. }
  63. else//Vergleich von eigenen Codecs mit Codecs der anruft -> Rückgabe entsprechend wählen
  64. {
  65. //herausfiltern der zulässigen bei Nachrichtenanfrage
  66. String[] reqbody = (requestEvent.getRequest()).toString().split("\\s|" + System.getProperty("line.seperator"));
  67. ArrayList<String> reqSDP = new ArrayList<>();
  68. for (String req : reqbody)
  69. {
  70. if (req.startsWith("a=rtpmap"))
  71. {
  72. reqSDP.add(req.replace("a=rtpmap:", ""));
  73. System.out.println(reqSDP);
  74. }
  75. }
  76. boolean temp = true; //evtl noch was besseres da so erster Codec nicht bester verwendet wird
  77. for (int i = 0; i == codecs[0].length; i++)
  78. {
  79. if (codecs[i][1].equals(reqSDP) && temp == true)
  80. {
  81. mediavec.add(sdpFactory.createAttribute("rtpmap", "8 G711a/8000"));
  82. temp = false;
  83. }
  84. }
  85. }
  86. sessionDescription.setAttributes(mediavec);
  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. System.out.println(sessionDescription);
  99. return sessionDescription;
  100. }
  101. }