Single RTP packet successfull

This commit is contained in:
Tim 2019-08-16 15:17:34 +02:00
parent 23a96b64eb
commit 41ddd21e34
5 changed files with 574 additions and 381 deletions

View File

@ -17,6 +17,7 @@ import logger.OhmLogger;
import model.SIPmodel; import model.SIPmodel;
import java.lang.String; import java.lang.String;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import model.RTPSendSingleString;
/** /**
* *
@ -48,21 +49,7 @@ public class CommandInvite implements CommandInterface {
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
} }
callDemo();
System.out.println("Starte RTP Session");
//String[] s = null;
SoundSenderDemo aDemo = null;
try {
aDemo = new SoundSenderDemo(true);
} catch (UnknownHostException | InterruptedException ex) {
Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
}
try {
aDemo.SendDemo(null);
} catch (UnknownHostException | InterruptedException ex) {
Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Beende RTP Session");
} }
@Override @Override
@ -74,4 +61,25 @@ public class CommandInvite implements CommandInterface {
public Boolean isundoable() { public Boolean isundoable() {
return false; return false;
} }
public void callDemo(){
System.out.println("Starte RTP Session");
String[] s = null;
SoundSenderDemo aDemo = new SoundSenderDemo();
try {
aDemo.SendDemo(s);
} catch (UnknownHostException | InterruptedException ex) {
Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Beende RTP Session");
}
public void callUnicastDemo(){
System.out.println("Starte RTP Unicast Session");
String[] s = null;
RTPSendSingleString aDemo = new RTPSendSingleString();
aDemo.main(s);
System.out.println("Beende RTP Unicast Session");
}
} }

View File

@ -0,0 +1,133 @@
/**
* Java RTP Library (jlibrtp)
* Copyright (C) 2006 Arne Kepp
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package model;
import java.net.DatagramSocket;
import jlibrtp.*;
/**
* <p>
* This is an example of how to set up a Unicast session.</p>
* <p>
* It does not accept any input arguments and is therefore of limited practical
* value, but it shows the basics.</p>
*
* <p>
* The class has to implement RTPAppIntf.</p>
*
* @author Arne Kepp
*/
public class RTPSendSingleString implements RTPAppIntf {
/**
* Holds a RTPSession instance
*/
RTPSession rtpSession = null;
public RTPSendSingleString() {
}
/**
* A minimal constructor
*/
public RTPSendSingleString(RTPSession rtpSession) {
this.rtpSession = rtpSession;
}
// RTPAppIntf All of the following are documented in the JavaDocs
/**
* Used to receive data from the RTP Library. We expect no data
*/
public void receiveData(DataFrame frame, Participant p) {
/**
* This concatenates all received packets for a single timestamp into a
* single byte[]
*/
byte[] data = frame.getConcatenatedData();
/**
* This returns the CNAME, if any, associated with the SSRC that was
* provided in the RTP packets received.
*/
String cname = p.getCNAME();
System.out.println("Received data from " + cname);
System.out.println(new String(data));
}
/**
* Used to communicate updates to the user database through RTCP
*/
public void userEvent(int type, Participant[] participant) {
//Do nothing
}
/**
* How many packets make up a complete frame for the payload type?
*/
public int frameSize(int payloadType) {
return 1;
}
// RTPAppIntf/
public static void main(String[] args) {
// 1. Create sockets for the RTPSession
DatagramSocket rtpSocket = null;
DatagramSocket rtcpSocket = null;
try {
rtpSocket = new DatagramSocket(5004);
rtcpSocket = new DatagramSocket(5005);
} catch (Exception e) {
System.out.println(e);
System.out.println("RTPSession failed to obtain port");
}
// 2. Create the RTP session
RTPSession rtpSession = new RTPSession(rtpSocket, rtcpSocket);
// 3. Instantiate the application object
RTPSendSingleString uex = new RTPSendSingleString(rtpSession);
// 4. Add participants we want to notify upon registration
// a. Hopefully nobody is listening on this port.
Participant part = new Participant("192.168.100.11", 5004, 5005);
rtpSession.addParticipant(part);
// 5. Register the callback interface, this launches RTCP threads too
// The two null parameters are for the RTCP and debug interfaces, not use here
rtpSession.RTPSessionRegister(uex, null, null);
// Wait 2500 ms, because of the initial RTCP wait
try {
Thread.sleep(2000);
} catch (Exception e) {
System.out.println(e);
}
// Note: The wait is optional, but insures SDES packets
// receive participants before continuing
// 6. Send some data
String str = "Hi there!";
rtpSession.sendData(str.getBytes());
// 7. Terminate the session, takes a few ms to kill threads in order.
rtpSession.endSession();
//This may result in "Sleep interrupted" messages, ignore them
}
}

View File

@ -26,8 +26,9 @@ public class SIPSessionDescription
private String codsRTP[]; //[RTP-Notation] private String codsRTP[]; //[RTP-Notation]
private String codecs[]; //[Codec/SampelRate] private String codecs[]; //[Codec/SampelRate]
private static final Logger lgSessionDescription = OhmLogger.getLogger(); private static final Logger lgSessionDescription = OhmLogger.getLogger();
public SIPSessionDescription(String myName, String myIPAddress,
public SIPSessionDescription(String myName, String myIPAddress, int myRTPPort,
RequestEvent requestEvent, Boolean anfrage) RequestEvent requestEvent, Boolean anfrage)
{ {
//Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate] //Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate]
@ -55,7 +56,7 @@ public class SIPSessionDescription
//Media Bod //Media Bod
if (anfrage == true) if (anfrage == true)
{ {
mediavec.add(sdpFactory.createMediaDescription("audio", 5004, 1, "RTP/AVP", codsRTP)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) mediavec.add(sdpFactory.createMediaDescription("audio", myRTPPort, 1, "RTP/AVP", codsRTP)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); mediavec.add(sdpFactory.createAttribute("sendrecv", null));
for (int i = 0; i < codsRTP.length; i++) for (int i = 0; i < codsRTP.length; i++)
{ {
@ -86,7 +87,7 @@ public class SIPSessionDescription
position++; position++;
} }
String[] tempArray = tempList.toArray(new String[tempList.size()]); String[] tempArray = tempList.toArray(new String[tempList.size()]);
mediavec.add(sdpFactory.createMediaDescription("audio", 5004, 1, "RTP/AVP", tempArray)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) mediavec.add(sdpFactory.createMediaDescription("audio", myRTPPort, 1, "RTP/AVP", tempArray)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
mediavec.add(sdpFactory.createAttribute("sendrecv", null)); mediavec.add(sdpFactory.createAttribute("sendrecv", null));
} }
sessionDescription.setAttributes(mediavec); sessionDescription.setAttributes(mediavec);
@ -105,4 +106,4 @@ public class SIPSessionDescription
{ {
return sessionDescription; return sessionDescription;
} }
} }

View File

@ -5,10 +5,12 @@
*/ */
package model; package model;
import controller.commands.CommandInvite;
import gov.nist.javax.sip.DialogTimeoutEvent; import gov.nist.javax.sip.DialogTimeoutEvent;
import gov.nist.javax.sip.SipListenerExt; import gov.nist.javax.sip.SipListenerExt;
import gui.Hauptfenster; import gui.Hauptfenster;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
@ -37,381 +39,416 @@ import logger.OhmLogger;
* Response/Request eigene Klasse oder Interface da es langsam unübersichtlich * Response/Request eigene Klasse oder Interface da es langsam unübersichtlich
* wird :( ACK schicken muss noch ergänzt werden BYE muss noch ergänzt werden. * wird :( ACK schicken muss noch ergänzt werden BYE muss noch ergänzt werden.
*/ */
public class SIPmodel implements SipListenerExt public class SIPmodel implements SipListenerExt {
{ //Stringhilfen zum erzeugen von RandomString (Branch)
private static final String TEST = "0123456789abcdefghijklmnopqrstuvwxyz";//für Random String
private static final SecureRandom RANDOM = new SecureRandom(); //für Random String
Hauptfenster view; //später entfernen wegen Zugriff private static final String TEST = "0123456789abcdefghijklmnopqrstuvwxyz";//für Random String
public static final Logger lg = OhmLogger.getLogger(); private static final SecureRandom RANDOM = new SecureRandom(); //für Random String
public SipFactory sipFactory; // Used to access the SIP API. //Verbindungskonstanten
public SipStack sipStack; // The SIP stack. private static final int MYSIPPORT = 5060;
public SipProvider sipProvider; // Used to send SIP messages. private static final int MYRTPPORT = 5004;
public MessageFactory messageFactory; // Used to create SIP message factory. private static final int MYRTCPPORT = 5005;
public HeaderFactory headerFactory; // Used to create SIP headers. private static final String PROTOCOLTYP = "UDP";
public AddressFactory addressFactory; // Used to create SIP URIs.
public ListeningPoint listeningPoint; // SIP listening IP address/port.
public Properties properties; // Other properties.
private AudioRinging audioRinging; Hauptfenster view; //später entfernen wegen Zugriff
public static final Logger lg = OhmLogger.getLogger();
private int myPort = 5060; public SipFactory sipFactory; // Used to access the SIP API.
private String myName = "129"; public SipStack sipStack; // The SIP stack.
public String protocolTyp = "UDP"; public SipProvider sipProvider; // Used to send SIP messages.
public String myIPAddress = "192.168.100.30"; public MessageFactory messageFactory; // Used to create SIP message factory.
public String proxyAddress; public HeaderFactory headerFactory; // Used to create SIP headers.
public CallIdHeader callID; public AddressFactory addressFactory; // Used to create SIP URIs.
public ListeningPoint listeningPoint; // SIP listening IP address/port.
public Properties properties; // Other properties.
Boolean anrufer; //Hilfsvariable ob ich selbst anrufer bin private AudioRinging audioRinging;
Boolean anrufAngenommen;
Boolean anrufCancel;
//Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren
Boolean werdeAngerufen;
private long cSequenz; //Hilfsbooleans
private String proxyTag; private Boolean anrufer; //Hilfsvariable ob ich selbst anrufer bin
private String myTag; private Boolean anrufAngenommen;
private String branch; private Boolean anrufCancel;
private String line; private Boolean werdeAngerufen;
private Address contactAddress;
private ContactHeader contactHeader;
public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten //Variablen die im Laufe des Gespräches ermittelt werden
{ //Eigene Daten
this.view = view; private String myIPAddress;
anrufer = false; private String myName = "129";
anrufAngenommen = false; private String myTag;
anrufCancel = false; private Address contactAddress;
proxyAddress = ""; private ContactHeader contactHeader;
proxyTag = ""; //ProxyServer
line = ""; public String proxyAddress;
cSequenz = 1; private int proxyRTPPort;
werdeAngerufen = false; private String proxyTag;
//CallDaten
audioRinging = new AudioRinging(); private String branch;
myTag = createString(8); //erzeugt Random Tag mit Länge 8 public CallIdHeader callID;
branch = createString(18);//erzeugt Random branch mit Länge 18 private long cSequenz;
private String RTPCodec;
try public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten
{ {
//wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren this.view = view;
//this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); anrufer = false;
this.sipFactory = SipFactory.getInstance(); anrufAngenommen = false;
this.sipFactory.setPathName("gov.nist"); anrufCancel = false;
this.properties = new Properties(); proxyAddress = "";
this.properties.setProperty("javax.sip.STACK_NAME", "stack"); proxyTag = "";
this.sipStack = this.sipFactory.createSipStack(this.properties); cSequenz = 1;
this.messageFactory = this.sipFactory.createMessageFactory(); werdeAngerufen = false;
this.headerFactory = this.sipFactory.createHeaderFactory();
this.addressFactory = this.sipFactory.createAddressFactory(); audioRinging = new AudioRinging();
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp); myTag = createString(8); //erzeugt Random Tag mit Länge 8
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint); branch = createString(18);//erzeugt Random branch mit Länge 18
this.sipProvider.addSipListener(this); try {
this.contactAddress = this.addressFactory.createAddress("sip:" + this.myName + "@" + this.myIPAddress + ":" + this.myPort); //wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren
this.contactHeader = this.headerFactory.createContactHeader(contactAddress); this.myIPAddress = InetAddress.getLocalHost().getHostAddress();
this.sipFactory = SipFactory.getInstance();
this.sipFactory.setPathName("gov.nist");
this.properties = new Properties();
this.properties.setProperty("javax.sip.STACK_NAME", "stack");
this.sipStack = this.sipFactory.createSipStack(this.properties);
this.messageFactory = this.sipFactory.createMessageFactory();
this.headerFactory = this.sipFactory.createHeaderFactory();
this.addressFactory = this.sipFactory.createAddressFactory();
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.MYSIPPORT, this.PROTOCOLTYP);
this.sipProvider = this.sipStack.createSipProvider(this.listeningPoint);
this.sipProvider.addSipListener(this);
this.contactAddress = this.addressFactory.createAddress("sip:" + this.myName + "@" + this.myIPAddress + ":" + this.MYSIPPORT);
this.contactHeader = this.headerFactory.createContactHeader(contactAddress);
} catch (Exception e) {
System.out.println("Fehler bei Initialisierung eigener Addresse");
System.exit(-1);
}
} }
catch (Exception e)
private String createString(int anzahl) //Erzeugt Random String in bestimmter länge für branch und Tag
{ {
System.out.println("Fehler bei Initialisierung eigener Addresse"); StringBuilder sb = new StringBuilder();
System.exit(-1); for (int i = 0; i < anzahl; i++) {
sb.append(TEST.charAt(RANDOM.nextInt(TEST.length())));
}
return sb.toString();
} }
}
private String createString(int anzahl) public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException {
{ proxyAddress = serverIP + ":" + serverPort;
StringBuilder sb = new StringBuilder(); SIPRegister register = new SIPRegister(proxyAddress, myTag, myIPAddress, MYSIPPORT, branch, addressFactory, headerFactory, messageFactory, contactHeader, sipProvider.getNewCallId());
for (int i = 0; i < anzahl; i++) sipProvider.sendRequest(register.getRequest());
{ lg.info("Erfolgreiches Senden der Registrierung");
sb.append(TEST.charAt(RANDOM.nextInt(TEST.length())));
} }
return sb.toString();
}
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException public void sendInvitation(String sipaddresse, String proxyaddresse,
{ int serverPort) throws SipException { //ServerPort wird nicht verwendet?
proxyAddress = serverIP + ":" + serverPort; resetCallParameter();
SIPRegister register = new SIPRegister(proxyAddress, myTag, myIPAddress, myPort, branch, addressFactory, headerFactory, messageFactory, contactHeader, sipProvider.getNewCallId()); anrufer = true;
sipProvider.sendRequest(register.getRequest()); callID = sipProvider.getNewCallId();
lg.info("Erfolgreiches Senden der Registrierung"); SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, getMYRTPPORT(), null, anrufer);
} SIPInvite sipinvite = new SIPInvite(sipaddresse, proxyaddresse, myIPAddress, MYSIPPORT, myTag, branch, callID, cSequenz, addressFactory, sdp.getSessionDescription(), headerFactory, messageFactory, contactHeader);
sipProvider.sendRequest(sipinvite.getInviterequest());
public void sendInvitation(String sipaddresse, String proxyaddresse, lg.info("Erfolgreiches Senden der Invitation");
int serverPort) throws SipException
{ //ServerPort wird nicht verwendet?
resetCallParameter();
anrufer = true;
callID = sipProvider.getNewCallId();
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, null, anrufer);
SIPInvite sipinvite = new SIPInvite(sipaddresse, proxyaddresse, myIPAddress, myPort, myTag, branch, callID, cSequenz, addressFactory, sdp.getSessionDescription(), headerFactory, messageFactory, contactHeader);
sipProvider.sendRequest(sipinvite.getInviterequest());
lg.info("Erfolgreiches Senden der Invitation");
}
@Override
public void processRequest(RequestEvent requestEvent)
{
lg.info("Bekomme Anfrage");
if ((Request.OPTIONS).equals(requestEvent.getRequest().getMethod())) //Options Anfrage von Server nach erfolgreicher Registrierung
{
lg.info("Option Request von Server, erstellen 200 OK zu Server");
try
{
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
this.sipProvider.sendResponse(tempOk.getResponse());
view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n");
lg.info("Erfolgreiches senden des 200Ok-Headers");
}
catch (SipException ex)
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
} }
//Aktive Kommunikation
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer
{
resetCallParameter();
anrufer = false;
//Falls Anruf ankommt, wichtige Variablen Zwischenspeichern (Branch, Cseq, CallID, proxyTag)
branch = ((ViaHeader) requestEvent.getRequest().getHeader("Via")).getBranch();
cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber();
proxyTag = ((FromHeader) requestEvent.getRequest().getHeader("From")).getTag();
callID = ((CallIdHeader) requestEvent.getRequest().getHeader("CallID"));
//Standartabfolge sobald man angerufen wird
try
{
//Trying Response erzeugen und abschicken
SIP100Trying tempTrying = new SIP100Trying(messageFactory, requestEvent, headerFactory);
sipProvider.sendResponse(tempTrying.getTryResponse());
view.getTxtArea().append("Trying geschickt\n");
lg.info("Trying ist raus");
//Ringing Response erzeugen und abschicken noch Schleife mit "Anruf annehmen" @Override
SIP180Ringing tempRinging = new SIP180Ringing(requestEvent, myTag, contactHeader, headerFactory, messageFactory); public void processRequest(RequestEvent requestEvent) {
Timer timer = new Timer(); lg.info("Bekomme Anfrage");
timer.scheduleAtFixedRate(new TimerTask() if ((Request.OPTIONS).equals(requestEvent.getRequest().getMethod())) //Options Anfrage von Server nach erfolgreicher Registrierung
{ {
@Override lg.info("Option Request von Server, erstellen 200 OK zu Server");
public void run() try {
{ SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
try this.sipProvider.sendResponse(tempOk.getResponse());
{ view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n");
if (anrufAngenommen != true) //Falls man nicht abnimmt, klingeln + Ringing schicken lg.info("Erfolgreiches senden des 200Ok-Headers");
{ } catch (SipException ex) {
sipProvider.sendResponse(tempRinging.getResponseRing()); lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
audioRinging.startRinging();
}
else if(anrufAngenommen==true) //bei annehmen, klingeln aufhören, OK mit SDP schicken
{
audioRinging.endRinging();
SIP200Ok respcall = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, requestEvent, anrufer);
respcall.addSDP(sdp.getSessionDescription(), myTag);
sipProvider.sendResponse(respcall.getResponse());
view.getTxtArea().append("Telefonat beginnt\n");
timer.cancel();
}
} }
catch (SipException ex) } //Aktive Kommunikation
{ else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer
{
resetCallParameter();
anrufer = false;
//Falls Anruf ankommt, wichtige Variablen Zwischenspeichern (Branch, Cseq, CallID, proxyTag)
branch = ((ViaHeader) requestEvent.getRequest().getHeader("Via")).getBranch();
cSequenz = ((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")).getSeqNumber();
proxyTag = ((FromHeader) requestEvent.getRequest().getHeader("From")).getTag();
callID = ((CallIdHeader) requestEvent.getRequest().getHeader("CallID"));
//Standartabfolge sobald man angerufen wird
try {
//Trying Response erzeugen und abschicken
SIP100Trying tempTrying = new SIP100Trying(messageFactory, requestEvent, headerFactory);
sipProvider.sendResponse(tempTrying.getTryResponse());
view.getTxtArea().append("Trying geschickt\n");
lg.info("Trying ist raus");
//Ringing Response erzeugen und abschicken noch Schleife mit "Anruf annehmen"
SIP180Ringing tempRinging = new SIP180Ringing(requestEvent, myTag, contactHeader, headerFactory, messageFactory);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
int counter = 0;
@Override
public void run() {
try {
if (anrufAngenommen != true && counter % 4 == 0) //Falls man nicht abnimmt, klingeln + Ringing schicken
{
sipProvider.sendResponse(tempRinging.getResponseRing());
audioRinging.startRinging();
} else if (anrufAngenommen == true) //bei annehmen, klingeln aufhören, OK mit SDP schicken
{
audioRinging.endRinging();
audioRinging.endRinging();
SIP200Ok respcall = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
SIPSessionDescription sdp = new SIPSessionDescription(myName, myIPAddress, getMYRTPPORT(), requestEvent, anrufer);
respcall.addSDP(sdp.getSessionDescription(), myTag);
sipProvider.sendResponse(respcall.getResponse());
view.getTxtArea().append("Telefonat beginnt\n");
timer.cancel();
} else if (anrufCancel == true) {
timer.cancel();
}
counter++;
} catch (SipException ex) {
}
}
}, 0, 1000);
} catch (SipException ex) {
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
} }
} } else if ((Request.ACK).equals(requestEvent.getRequest().getMethod())) {
}, 0, 1000);
}
catch (SipException ex)
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
} } else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod())) {
else if ((Request.ACK).equals(requestEvent.getRequest().getMethod())) System.out.println("Anruf cancel");
{ view.getTxtArea().append("Anruf wurde gecancelt");
try {
} //Cancel Request -> Response 200 Ok + Response 487 Request Terminated
else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod())) //200 Ok
{ anrufCancel = true;
view.getTxtArea().append("Anruf wurde gecancelt"); SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
try sipProvider.sendResponse(tempOk.getResponse());
{ view.getTxtArea().append("Anrufender canceld Anfrage\n");
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage");
//200 Ok //487 Request Terminated
anrufCancel = true; } catch (SipException ex) {
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory); Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
this.sipProvider.sendResponse(tempOk.getResponse()); }
view.getTxtArea().append("Anrufender canceld Anfrage\n"); } else if ((Request.BYE).equals(requestEvent.getRequest().getMethod())) {
lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage"); try {
//487 Request Terminated SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
} this.sipProvider.sendResponse(tempOk.getResponse());
catch (SipException ex) } catch (SipException ex) {
{ Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex); }
} }
}
else if ((Request.BYE).equals(requestEvent.getRequest().getMethod()))
{
try
{
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
this.sipProvider.sendResponse(tempOk.getResponse());
}
catch (SipException ex)
{
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
@Override
public void processResponse(ResponseEvent responseEvent)
{
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED)
{
try
{
cSequenz += 1L;
branch += 10;
SIPUnauthReq req2 = new SIPUnauthReq(myName, proxyAddress, myTag, myIPAddress, branch, cSequenz, myPort, contactHeader, addressFactory, headerFactory, responseEvent, messageFactory);
sipProvider.sendRequest(req2.getUnauthReq());
view.getTxtArea().append("Erfolgreich registriert\n");
}
catch (SipException ex)
{
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if (responseEvent.getResponse().getStatusCode() == Response.OK)
{
lg.info("Erfolgreichen Response (200 OK) bekommen");
}
else if (responseEvent.getResponse().getStatusCode() == Response.RINGING)
{
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To");
proxyTag = temp.getTag();
} }
} @Override
public void processResponse(ResponseEvent responseEvent) {
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED) {
try {
cSequenz += 1L;
branch += 10;
SIPUnauthReq req2 = new SIPUnauthReq(myName, proxyAddress, myTag, myIPAddress, branch, cSequenz, MYSIPPORT, contactHeader, addressFactory, headerFactory, responseEvent, messageFactory);
sipProvider.sendRequest(req2.getUnauthReq());
view.getTxtArea().append("Erfolgreich registriert\n");
} catch (SipException ex) {
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (responseEvent.getResponse().getStatusCode() == Response.OK) {
//Überprüfen ob Ok Header mit SDP ist
if ((((ContentTypeHeader) responseEvent.getResponse().getHeader("Content-Type")).getContentSubType()).equals("sdp")) {
lg.info("Erfolgreichen Response 200 OK mit SDP bekommen");
getRTPParameters(responseEvent);
// SIPACK ack = new SIPACK();
// sipProvider.sendResponse(rspns);
/*
System.out.println("Starte RTP Session");
//String[] s = null;
SoundSenderDemo aDemo = null;
// try {
// aDemo = new SoundSenderDemo(true);
// } catch (UnknownHostException | InterruptedException ex) {
// Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
// }
try {
aDemo.SendDemo(null);
} catch (UnknownHostException | InterruptedException ex) {
Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Beende RTP Session");
*/
} else {
lg.info("Erfolgreichen Response (200 OK) bekommen");
}
} else if (responseEvent.getResponse().getStatusCode() == Response.RINGING) {
ToHeader temp = (ToHeader) responseEvent.getResponse().getHeader("To");
proxyTag = temp.getTag();
}
public void byecall(String calluser) throws ParseException, InvalidArgumentException, SipException }
{
cSequenz++;
SIPBye tempBye = new SIPBye(calluser, proxyAddress, myName, myIPAddress, myTag, proxyTag, myPort, branch, callID, cSequenz, messageFactory, contactHeader, addressFactory, headerFactory);
sipProvider.sendRequest(tempBye.getByeRequest());
lg.info("Erfolgreiches Senden des BYE Headers");
}
public void resetCallParameter() public void byecall(String calluser) throws ParseException, InvalidArgumentException, SipException {
{ cSequenz++;
anrufAngenommen = false; SIPBye tempBye = new SIPBye(calluser, proxyAddress, myName, myIPAddress, myTag, proxyTag, MYSIPPORT, branch, callID, cSequenz, messageFactory, contactHeader, addressFactory, headerFactory);
anrufer = false; sipProvider.sendRequest(tempBye.getByeRequest());
} lg.info("Erfolgreiches Senden des BYE Headers");
}
public void anrufAnnehmen() public void getRTPParameters(ResponseEvent responseEvent) {
{ int identifier = 0;
anrufAngenommen = true; String[] reqbody = (responseEvent.getResponse()).toString().split("\\s|" + System.getProperty("line.seperator"));
} for (String req : reqbody) {
if (identifier == 1) {
proxyRTPPort = Integer.valueOf(req);
identifier = 0;
} else if (identifier == 2) {
RTPCodec = req;
identifier = 0;
}
if (req.startsWith("m=audio")) {
identifier = 1;
} else if (req.startsWith("a=rtpmap:")) {
identifier = 2;
}
}
}
//Get Methoden falls man mal die Parameter braucht public void resetCallParameter() {
public String getmyName() anrufAngenommen = false;
{ anrufer = false;
return myName; }
}
public Integer getMyPort() public void anrufAnnehmen() {
{ anrufAngenommen = true;
return myPort; }
}
public String getMyIPAdress() //Get Methoden falls man mal die Parameter braucht
{ public String getmyName() {
return myIPAddress; return myName;
} }
// Herausfinden bei welchen Events die unteren Funktionen aufgerufen werden -> evtl brauchbar public Integer getMyPort() {
@Override return MYSIPPORT;
public void processTimeout(TimeoutEvent timeoutEvent) }
{
//view.getTxtArea().append("processTimeout\n");
}
@Override public String getMyIPAdress() {
public void processIOException(IOExceptionEvent exceptionEvent) return myIPAddress;
{ }
//view.getTxtArea().append("processIOException\n");
}
@Override // Herausfinden bei welchen Events die unteren Funktionen aufgerufen werden -> evtl brauchbar
public void processTransactionTerminated( @Override
TransactionTerminatedEvent transactionTerminatedEvent) public void processTimeout(TimeoutEvent timeoutEvent) {
{ //view.getTxtArea().append("processTimeout\n");
//view.getTxtArea().append("processTransactionTerminated\n"); }
}
@Override @Override
public void processDialogTerminated( public void processIOException(IOExceptionEvent exceptionEvent) {
DialogTerminatedEvent dialogTerminatedEvent) //view.getTxtArea().append("processIOException\n");
{ }
//view.getTxtArea().append("processDialogTerminated\n");
}
@Override @Override
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) public void processTransactionTerminated(
{ TransactionTerminatedEvent transactionTerminatedEvent) {
//view.getTxtArea().append("processDialogTerminated\n"); //view.getTxtArea().append("processTransactionTerminated\n");
} }
/** @Override
* @param myPort the myPort to set public void processDialogTerminated(
*/ DialogTerminatedEvent dialogTerminatedEvent) {
public void setMyPort(int myPort) //view.getTxtArea().append("processDialogTerminated\n");
{ }
this.myPort = myPort;
}
/** @Override
* @return the myName public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) {
*/ //view.getTxtArea().append("processDialogTerminated\n");
public String getMyName() }
{
return myName;
}
/** /**
* @return the proxyTag * @param myPort the MYSIPPORT to set
*/ */
public String getProxyTag() /**
{ * @return the myName
return proxyTag; */
} public String getMyName() {
return myName;
}
/** /**
* @param proxyTag the proxyTag to set * @return the proxyTag
*/ */
public void setProxyTag(String proxyTag) public String getProxyTag() {
{ return proxyTag;
this.proxyTag = proxyTag; }
}
/** /**
* @return the myTag * @param proxyTag the proxyTag to set
*/ */
public String getMyTag() public void setProxyTag(String proxyTag) {
{ this.proxyTag = proxyTag;
return myTag; }
}
/** /**
* @param myTag the myTag to set * @return the myTag
*/ */
public void setMyTag(String myTag) public String getMyTag() {
{ return myTag;
this.myTag = myTag; }
}
/** /**
* @return the branch * @param myTag the myTag to set
*/ */
public String getBranch() public void setMyTag(String myTag) {
{ this.myTag = myTag;
return branch; }
}
/**
* @return the branch
*/
public String getBranch() {
return branch;
}
/**
* @param proxyRTPPort the proxyRTPPort to set
*/
public void setProxyRTPPort(int proxyRTPPort) {
this.proxyRTPPort = proxyRTPPort;
}
/**
* @param RTPCodec the RTPCodec to set
*/
public void setRTPCodec(String RTPCodec) {
this.RTPCodec = RTPCodec;
}
/**
* @return the proxyRTPPort
*/
public int getProxyRTPPort() {
return proxyRTPPort;
}
/**
* @return the RTPCodec
*/
public String getRTPCodec() {
return RTPCodec;
}
/**
* @return the MYRTPPORT
*/
public static int getMYRTPPORT() {
return MYRTPPORT;
}
/**
* @return the MYRTCPPORT
*/
public static int getMYRTCPPORT() {
return MYRTCPPORT;
}
} }

View File

@ -22,13 +22,15 @@ import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jlibrtp.*; import jlibrtp.*;
/** /**
* @author Arne Kepp * @author Arne Kepp
*/ */
public class SoundSenderDemo implements RTPAppIntf { public class SoundSenderDemo implements RTPAppIntf {
SIPmodel model;
public RTPSession rtpSession = null; public RTPSession rtpSession = null;
static int pktCount = 0; static int pktCount = 0;
static int dataCount = 0; static int dataCount = 0;
@ -41,32 +43,43 @@ public class SoundSenderDemo implements RTPAppIntf {
enum Position { enum Position {
LEFT, RIGHT, NORMAL LEFT, RIGHT, NORMAL
}; };
public SoundSenderDemo() {}
public SoundSenderDemo(boolean isLocal) throws UnknownHostException, InterruptedException { public SoundSenderDemo(boolean isLocal) throws UnknownHostException, InterruptedException {
this.model = model;
DatagramSocket rtpSocket = null; DatagramSocket rtpSocket = null;
DatagramSocket rtcpSocket = null; DatagramSocket rtcpSocket = null;
//rtpSocket.close();
// for(int i=5000; i<=6000; i++) //rtcpSocket.close();
// {
// try {
// rtpSocket = new DatagramSocket(i);
// rtpSocket.close();
// } catch (Exception e) {
// System.out.println("RTPSession failed to obtain port"+i);
// }
//
// }
InetAddress myIP = InetAddress.getByName("192.168.100.30");
// try { // try {
// rtpSocket = new DatagramSocket(5004, myIP); // rtpSocket = new DatagramSocket(model.getProxyRTPPort());
// rtcpSocket = new DatagramSocket(5005, myIP); // } catch (SocketException ex) {
// } catch (SocketException e) { // Logger.getLogger(SoundSenderDemo.class.getName()).log(Level.SEVERE, null, ex);
// System.out.println("RTPSession failed to obtain port"); // System.out.println("RTPSession failed to obtain port");
// } // }
// try {
// rtcpSocket = new DatagramSocket(model.getProxyRTPPort()+1);
// } catch (SocketException ex) {
// Logger.getLogger(SoundSenderDemo.class.getName()).log(Level.SEVERE, null, ex);
// System.out.println("RTCPSession failed to obtain port");
// }
InetAddress myIP = InetAddress.getByName("192.168.100.247");
try {
rtpSocket = new DatagramSocket(5004, myIP);
rtcpSocket = new DatagramSocket(5005, myIP);
} catch (SocketException e) {
System.out.println(e);
System.out.println("RTPSession failed to obtain port");
rtpSocket.close();
rtcpSocket.close();
}
/*
try { try {
rtpSocket = new DatagramSocket(null); rtpSocket = new DatagramSocket(null);
InetSocketAddress myInetSocketAddress = new InetSocketAddress(5004); InetSocketAddress myInetSocketAddress = new InetSocketAddress(5004);
@ -77,7 +90,7 @@ public class SoundSenderDemo implements RTPAppIntf {
rtpSocket.close(); rtpSocket.close();
rtcpSocket.close(); rtcpSocket.close();
} }
*/
rtpSession = new RTPSession(rtpSocket, rtcpSocket); rtpSession = new RTPSession(rtpSocket, rtcpSocket);
rtpSession.RTPSessionRegister(this, null, null); rtpSession.RTPSessionRegister(this, null, null);
@ -90,7 +103,7 @@ public class SoundSenderDemo implements RTPAppIntf {
*/ */
public void SendDemo(String[] args) throws UnknownHostException, InterruptedException { public void SendDemo(String[] args) throws UnknownHostException, InterruptedException {
args = new String[4]; args = new String[4];
args[1] = "192.168.100.249"; args[1] = "192.168.100.11";
args[0] = "C:\\Users\\Tim\\Desktop\\VoIP PA\\project\\VoIPProjekt\\src\\SoundDateien\\RingingPhone.wav"; args[0] = "C:\\Users\\Tim\\Desktop\\VoIP PA\\project\\VoIPProjekt\\src\\SoundDateien\\RingingPhone.wav";
args[2] = "5004"; args[2] = "5004";
args[3] = "5005"; args[3] = "5005";
@ -105,8 +118,9 @@ public class SoundSenderDemo implements RTPAppIntf {
// args[2] = "5004"; // args[2] = "5004";
// args[3] = "5005"; // args[3] = "5005";
// } // }
SoundSenderDemo aDemo = new SoundSenderDemo(false); SoundSenderDemo aDemo;
Participant p = new Participant("192.168.100.249", Integer.parseInt(args[2]), Integer.parseInt(args[2]) + 1); aDemo = new SoundSenderDemo(true);
Participant p = new Participant("192.168.100.11", Integer.parseInt(args[2]), Integer.parseInt(args[2]) + 1);
aDemo.rtpSession.addParticipant(p); aDemo.rtpSession.addParticipant(p);
aDemo.filename = args[0]; aDemo.filename = args[0];
aDemo.run(); aDemo.run();
@ -190,7 +204,7 @@ public class SoundSenderDemo implements RTPAppIntf {
if (nBytesRead >= 0) { if (nBytesRead >= 0) {
rtpSession.sendData(abData); rtpSession.sendData(abData);
//if(!this.local) { //if(!this.local) {
auline.write(abData, 0, abData.length); //auline.write(abData, 0, abData.length);
//dataCount += abData.length; //dataCount += abData.length;
//if(pktCount % 10 == 0) { //if(pktCount % 10 == 0) {