From 23a96b64eb984fc71ef59221a92df50c56e8170e Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 13 Aug 2019 17:56:52 +0200 Subject: [PATCH] --- .gitignore | 3 + nbproject/build-impl.xml | 18 ++ nbproject/genfiles.properties | 6 +- nbproject/project.properties | 46 +++- nbproject/project.xml | 10 + src/controller/commands/CommandInvite.java | 95 +++++--- src/model/AudioRinging.java | 2 +- src/model/SIPSessionDescription.java | 4 +- src/model/SIPmodel.java | 4 +- src/model/SoundSenderDemo.java | 255 +++++++++++++++++++++ 10 files changed, 386 insertions(+), 57 deletions(-) create mode 100644 .gitignore create mode 100644 src/model/SoundSenderDemo.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a568390 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/nbproject/private/ +/build/ +/dist/ \ No newline at end of file diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index cfdb0cb..a7a432f 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1079,6 +1079,15 @@ is divided into following sections: + + + + + + + + + @@ -1735,6 +1744,15 @@ is divided into following sections: + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index e197871..ae65322 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -3,6 +3,6 @@ build.xml.script.CRC32=53e451ff build.xml.stylesheet.CRC32=f85dc8f2@1.90.1.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=f69c57db -nbproject/build-impl.xml.script.CRC32=2b6978ab -nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.90.1.48 +nbproject/build-impl.xml.data.CRC32=9558f99f +nbproject/build-impl.xml.script.CRC32=4415df3d +nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.92.0.48 diff --git a/nbproject/project.properties b/nbproject/project.properties index d02eba2..1203af8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,21 +1,31 @@ #Tue Jun 11 17:15:12 CEST 2019 excludes= +file.reference.jain-sip-api-1.2.1.4.jar-1=C:\\Users\\Tim\\Desktop\\VoIP PA\\VoIPProjekt\\VoIPProjekt\\lib\\jain-sip-api-1.2.1.4.jar +file.reference.jain-sip-ri-1.2.327.jar-1=C:\\Users\\Tim\\Desktop\\VoIP PA\\VoIPProjekt\\VoIPProjekt\\lib\\jain-sip-ri-1.2.327.jar +file.reference.junit-4.12.jar-1=C:\\Users\\Tim\\Desktop\\VoIP PA\\VoIPProjekt\\VoIPProjekt\\lib\\junit-4.12.jar +file.reference.log4j-1.2.17.jar-1=C:\\Users\\Tim\\Desktop\\VoIP PA\\VoIPProjekt\\VoIPProjekt\\lib\\log4j-1.2.17.jar javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir}:\ ${libs.junit_4.classpath}:\ ${libs.hamcrest.classpath} -run.classpath=${javac.classpath}\:${build.classes.dir} -javac.processorpath=${javac.classpath} +project.rtplib=../../rtplib +reference.rtplib.jar=${project.rtplib}/dist/rtplib.jar +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.processorpath=\ + ${javac.classpath} dist.javadoc.dir=${dist.dir}/javadoc test.src.dir=test file.reference.junit-4.12.jar=lib\\junit-4.12.jar -run.modulepath=${javac.modulepath} +run.modulepath=\ + ${javac.modulepath} annotation.processing.enabled=true file.reference.jain-sip-ri-1.2.327.jar=lib\\jain-sip-ri-1.2.327.jar build.sysclasspath=ignore debug.modulepath=${run.modulepath} -javac.compilerargs= +javac.compilerargs=-g javadoc.noindex=false javadoc.private=false file.reference.log4j-1.2.17.jar=lib\\log4j-1.2.17.jar @@ -24,7 +34,7 @@ endorsed.classpath= main.class=phone.Start junit.selected.version=4 source.encoding=UTF-8 -javac.source=11 +javac.source=1.8 includes=** javadoc.use=true jar.compress=false @@ -43,9 +53,16 @@ javac.processormodulepath= run.jvmargs= jlink.additionalmodules= javadoc.encoding=${source.encoding} -javac.classpath=${file.reference.jain-sip-api-1.2.1.4.jar}\:${file.reference.jain-sip-ri-1.2.327.jar}\:${file.reference.junit-4.12.jar}\:${file.reference.log4j-1.2.17.jar} +javac.classpath=\ + ${file.reference.jain-sip-api-1.2.1.4.jar}:\ + ${file.reference.jain-sip-ri-1.2.327.jar}:\ + ${file.reference.junit-4.12.jar}:\ + ${file.reference.log4j-1.2.17.jar}:\ + ${libs.RTPLibrary.classpath}:\ + ${reference.rtplib.jar} mkdist.disabled=false -run.test.modulepath=${javac.test.modulepath} +run.test.modulepath=\ + ${javac.test.modulepath} build.classes.excludes=**/*.java,**/*.form dist.jlink.dir=${dist.dir}/jlink dist.jar=${dist.dir}/Phone.jar @@ -62,19 +79,26 @@ annotation.processing.source.output=${build.generated.sources.dir}/ap-source-out build.generated.dir=${build.dir}/generated javadoc.version=false application.title=Phone -javac.test.modulepath=${javac.modulepath} +javac.test.modulepath=\ + ${javac.modulepath} debug.test.classpath=${run.test.classpath} javac.external.vm=true -javac.target=11 +javac.target=1.8 platform.active=default_platform manifest.file=manifest.mf javadoc.html5=false javac.test.processorpath=${javac.test.classpath} meta.inf.dir=${src.dir}/META-INF -run.test.classpath=${javac.test.classpath}\:${build.test.classes.dir} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} dist.jlink.output=${dist.jlink.dir}/Phone annotation.processing.run.all.processors=true -javac.modulepath= +javac.modulepath=\ + ${file.reference.jain-sip-api-1.2.1.4.jar-1}:\ + ${file.reference.jain-sip-ri-1.2.327.jar-1}:\ + ${file.reference.junit-4.12.jar-1}:\ + ${file.reference.log4j-1.2.17.jar-1} src.dir=src jlink.additionalparam= debug.classpath=${run.classpath} diff --git a/nbproject/project.xml b/nbproject/project.xml index 10ed024..cd65826 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -11,5 +11,15 @@ + + + rtplib + jar + + jar + clean + jar + + diff --git a/src/controller/commands/CommandInvite.java b/src/controller/commands/CommandInvite.java index dc792de..a4dcda2 100644 --- a/src/controller/commands/CommandInvite.java +++ b/src/controller/commands/CommandInvite.java @@ -3,56 +3,75 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package controller.commands; import controller.CommandInterface; import gui.Hauptfenster; +import static java.lang.Thread.sleep; import java.util.logging.Level; import java.util.logging.Logger; import javax.sip.SipException; +import model.SoundSenderDemo; +//import jlibrtpDemos.SoundSenderDemo; import logger.OhmLogger; import model.SIPmodel; +import java.lang.String; +import java.net.UnknownHostException; /** * - * @author Jan - * Fehlende Ergänzungen(timer nach 10 sec für abbruchbedingung + bedingung falls angenommen wurde -> Boolean) + * @author Jan Fehlende Ergänzungen(timer nach 10 sec für abbruchbedingung + + * bedingung falls angenommen wurde -> Boolean) */ -public class CommandInvite implements CommandInterface -{ - private static final Logger lginvite = OhmLogger.getLogger(); - private SIPmodel model; - private Hauptfenster view; - public CommandInvite(SIPmodel model, Hauptfenster view) - { - this.model = model; - this.view = view; - } - - @Override - public void execute() - { - try - { - view.getTxtArea().append("Einladung an " + view.getTxtcallIP().getText() + " gesendet\n"); - model.sendInvitation(view.getTxtcallIP().getText(),view.getTxtServerIP().getText(), 5078); - } - catch (SipException ex) - { - view.getTxtArea().append("Einladung fehlgeschlagen\n"); - lginvite.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex); - } - } - @Override - public void undo() - { - - } +public class CommandInvite implements CommandInterface { - @Override - public Boolean isundoable() - { - return false; - } + private static final Logger lginvite = OhmLogger.getLogger(); + private SIPmodel model; + private Hauptfenster view; + + public CommandInvite(SIPmodel model, Hauptfenster view) { + this.model = model; + this.view = view; + } + + @Override + public void execute() { + try { + view.getTxtArea().append("Einladung an " + view.getTxtcallIP().getText() + " gesendet\n"); + model.sendInvitation(view.getTxtcallIP().getText(), view.getTxtServerIP().getText(), 5078); + } catch (SipException ex) { + view.getTxtArea().append("Einladung fehlgeschlagen\n"); + lginvite.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex); + } + try { + sleep(5000); + } catch (InterruptedException ex) { + Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex); + } + + 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 + public void undo() { + + } + + @Override + public Boolean isundoable() { + return false; + } } diff --git a/src/model/AudioRinging.java b/src/model/AudioRinging.java index 4f354cc..f26292f 100644 --- a/src/model/AudioRinging.java +++ b/src/model/AudioRinging.java @@ -34,7 +34,7 @@ public class AudioRinging { //Normalerweise so da Betriebssystemunabhängig aber ka wo der Fehler ist //String file = (File.separator+"phone"+File.separator+"SoundDateien"+ File.separator+"RingingPhone.wav"); - audioFile = new File(getClass().getResource("/SoundDateien/RingingPhone.wav").getFile()); + audioFile = new File("C:\\Users\\Tim\\Desktop\\VoIP PA\\project\\VoIPProjekt\\src\\SoundDateien\\RingingPhone.wav"); try { format = AudioSystem.getAudioInputStream(audioFile).getFormat(); diff --git a/src/model/SIPSessionDescription.java b/src/model/SIPSessionDescription.java index b76d9c4..27fc825 100644 --- a/src/model/SIPSessionDescription.java +++ b/src/model/SIPSessionDescription.java @@ -55,7 +55,7 @@ public class SIPSessionDescription //Media Bod if (anfrage == true) { - mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", codsRTP)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) + mediavec.add(sdpFactory.createMediaDescription("audio", 5004, 1, "RTP/AVP", codsRTP)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) mediavec.add(sdpFactory.createAttribute("sendrecv", null)); for (int i = 0; i < codsRTP.length; i++) { @@ -86,7 +86,7 @@ public class SIPSessionDescription position++; } String[] tempArray = tempList.toArray(new String[tempList.size()]); - mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", tempArray)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) + mediavec.add(sdpFactory.createMediaDescription("audio", 5004, 1, "RTP/AVP", tempArray)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..) mediavec.add(sdpFactory.createAttribute("sendrecv", null)); } sessionDescription.setAttributes(mediavec); diff --git a/src/model/SIPmodel.java b/src/model/SIPmodel.java index efc3aa7..5f28ed0 100644 --- a/src/model/SIPmodel.java +++ b/src/model/SIPmodel.java @@ -58,7 +58,7 @@ public class SIPmodel implements SipListenerExt private int myPort = 5060; private String myName = "129"; public String protocolTyp = "UDP"; - public String myIPAddress; + public String myIPAddress = "192.168.100.30"; public String proxyAddress; public CallIdHeader callID; @@ -95,7 +95,7 @@ public class SIPmodel implements SipListenerExt try { //wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren - this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); + //this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); this.sipFactory = SipFactory.getInstance(); this.sipFactory.setPathName("gov.nist"); this.properties = new Properties(); diff --git a/src/model/SoundSenderDemo.java b/src/model/SoundSenderDemo.java new file mode 100644 index 0000000..a546772 --- /dev/null +++ b/src/model/SoundSenderDemo.java @@ -0,0 +1,255 @@ +/* This file is based on + * http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml + * Please see the site for license information. + */ +package model; + +import java.io.File; +import java.io.IOException; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; +import javax.sound.sampled.FloatControl; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.SourceDataLine; +import javax.sound.sampled.UnsupportedAudioFileException; +import java.lang.String; +import static java.lang.Thread.sleep; +import java.net.DatagramSocket; +import java.util.Enumeration; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import jlibrtp.*; + +/** + * @author Arne Kepp + */ +public class SoundSenderDemo implements RTPAppIntf { + + public RTPSession rtpSession = null; + static int pktCount = 0; + static int dataCount = 0; + private String filename; + private final int EXTERNAL_BUFFER_SIZE = 1024; + SourceDataLine auline; + private Position curPosition; + boolean local; + + enum Position { + LEFT, RIGHT, NORMAL + }; + + public SoundSenderDemo(boolean isLocal) throws UnknownHostException, InterruptedException { + DatagramSocket rtpSocket = null; + DatagramSocket rtcpSocket = null; + +// for(int i=5000; i<=6000; i++) +// { +// 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 { +// rtpSocket = new DatagramSocket(5004, myIP); +// rtcpSocket = new DatagramSocket(5005, myIP); +// } catch (SocketException e) { +// System.out.println("RTPSession failed to obtain port"); +// } + + + try { + rtpSocket = new DatagramSocket(null); + InetSocketAddress myInetSocketAddress = new InetSocketAddress(5004); + rtpSocket.bind(myInetSocketAddress); + sleep(2000); + } catch (SocketException e) { + System.out.println("RTPSession failed to obtain port"); + rtpSocket.close(); + rtcpSocket.close(); + } + + + rtpSession = new RTPSession(rtpSocket, rtcpSocket); + rtpSession.RTPSessionRegister(this, null, null); + System.out.println("CNAME: " + rtpSession.CNAME()); + this.local = isLocal; + } + + /** + * @param args + */ + public void SendDemo(String[] args) throws UnknownHostException, InterruptedException { + args = new String[4]; + args[1] = "192.168.100.249"; + args[0] = "C:\\Users\\Tim\\Desktop\\VoIP PA\\project\\VoIPProjekt\\src\\SoundDateien\\RingingPhone.wav"; + args[2] = "5004"; + args[3] = "5005"; + for (int i = 0; i < args.length; i++) { + System.out.println("args[" + i + "]" + args[i]); + } + +// if (args.length == 0) { +// args = new String[4]; +// args[1] = "192.168.100.249"; +// args[0] = "C:\\Users\\Tim\\Desktop\\VoIP PA\\project\\VoIPProjekt\\src\\SoundDateien\\RingingPhone.wav"; +// args[2] = "5004"; +// args[3] = "5005"; +// } + SoundSenderDemo aDemo = new SoundSenderDemo(false); + Participant p = new Participant("192.168.100.249", Integer.parseInt(args[2]), Integer.parseInt(args[2]) + 1); + aDemo.rtpSession.addParticipant(p); + aDemo.filename = args[0]; + aDemo.run(); + System.out.println("pktCount: " + pktCount); + } + + public void receiveData(DataFrame dummy1, Participant dummy2) { + // We don't expect any data. + } + + public void userEvent(int type, Participant[] participant) { + //Do nothing + } + + public int frameSize(int payloadType) { + return 1; + } + + public void run() { + if (RTPSession.rtpDebugLevel > 1) { + System.out.println("-> Run()"); + } + File soundFile = new File(filename); + if (!soundFile.exists()) { + System.err.println("Wave file not found: " + filename); + return; + } + + AudioInputStream audioInputStream = null; + try { + audioInputStream = AudioSystem.getAudioInputStream(soundFile); + } catch (UnsupportedAudioFileException e1) { + e1.printStackTrace(); + return; + } catch (IOException e1) { + e1.printStackTrace(); + return; + } + + //AudioFormat format = audioInputStream.getFormat(); + AudioFormat.Encoding encoding = new AudioFormat.Encoding("PCM_SIGNED"); + AudioFormat format = new AudioFormat(encoding, ((float) 8000.0), 16, 1, 2, ((float) 8000.0), false); + System.out.println(format.toString()); + + if (!this.local) { + // To time the output correctly, we also play at the input: + auline = null; + DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); + + try { + auline = (SourceDataLine) AudioSystem.getLine(info); + auline.open(format); + } catch (LineUnavailableException e) { + e.printStackTrace(); + return; + } catch (Exception e) { + e.printStackTrace(); + return; + } + + if (auline.isControlSupported(FloatControl.Type.PAN)) { + FloatControl pan = (FloatControl) auline + .getControl(FloatControl.Type.PAN); + if (this.curPosition == Position.RIGHT) { + pan.setValue(1.0f); + } else if (this.curPosition == Position.LEFT) { + pan.setValue(-1.0f); + } + } + + auline.start(); + } + + int nBytesRead = 0; + byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; + long start = System.currentTimeMillis(); + try { + while (nBytesRead != -1 && pktCount < 200) { + nBytesRead = audioInputStream.read(abData, 0, abData.length); + + if (nBytesRead >= 0) { + rtpSession.sendData(abData); + //if(!this.local) { + auline.write(abData, 0, abData.length); + + //dataCount += abData.length; + //if(pktCount % 10 == 0) { + // System.out.println("pktCount:" + pktCount + " dataCount:" + dataCount); + // + // long test = 0; + // for(int i=0; i iter = this.rtpSession.getParticipants(); + System.out.println("iter " + iter.hasMoreElements()); + Participant p = null; + + //while (iter.hasMoreElements()) { + p = iter.nextElement(); + + String name = "name"; + byte[] nameBytes = name.getBytes(); + String data = "abcd"; + byte[] dataBytes = data.getBytes(); + + int ret = rtpSession.sendRTCPAppPacket(p.getSSRC(), 0, nameBytes, dataBytes); + System.out.println("!!!!!!!!!!!! ADDED APPLICATION SPECIFIC " + ret); + continue; + //} +// if (p == null) { +// System.out.println("No participant with SSRC available :("); +// } + } + } + } catch (IOException e) { + e.printStackTrace(); + return; + } + System.out.println("Time: " + (System.currentTimeMillis() - start) / 1000 + " s"); + + try { + Thread.sleep(200); + } catch (Exception e) { + } + + this.rtpSession.endSession(); + + try { + Thread.sleep(2000); + } catch (Exception e) { + } + if (RTPSession.rtpDebugLevel > 1) { + System.out.println("<- Run()"); + } + } + +}