Single RTP packet successfull
This commit is contained in:
parent
23a96b64eb
commit
41ddd21e34
@ -17,6 +17,7 @@ import logger.OhmLogger;
|
||||
import model.SIPmodel;
|
||||
import java.lang.String;
|
||||
import java.net.UnknownHostException;
|
||||
import model.RTPSendSingleString;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -48,21 +49,7 @@ public class CommandInvite implements CommandInterface {
|
||||
} 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");
|
||||
callDemo();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,4 +61,25 @@ public class CommandInvite implements CommandInterface {
|
||||
public Boolean isundoable() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
133
src/model/RTPSendSingleString.java
Normal file
133
src/model/RTPSendSingleString.java
Normal 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
|
||||
}
|
||||
}
|
@ -27,7 +27,8 @@ public class SIPSessionDescription
|
||||
private String codecs[]; //[Codec/SampelRate]
|
||||
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)
|
||||
{
|
||||
//Hier alle unterstützen Codecs eintragen [RTP-Notation][Codec/SampelRate]
|
||||
@ -55,7 +56,7 @@ public class SIPSessionDescription
|
||||
//Media Bod
|
||||
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));
|
||||
for (int i = 0; i < codsRTP.length; i++)
|
||||
{
|
||||
@ -86,7 +87,7 @@ public class SIPSessionDescription
|
||||
position++;
|
||||
}
|
||||
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));
|
||||
}
|
||||
sessionDescription.setAttributes(mediavec);
|
||||
|
@ -5,10 +5,12 @@
|
||||
*/
|
||||
package model;
|
||||
|
||||
import controller.commands.CommandInvite;
|
||||
import gov.nist.javax.sip.DialogTimeoutEvent;
|
||||
import gov.nist.javax.sip.SipListenerExt;
|
||||
import gui.Hauptfenster;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
@ -37,10 +39,16 @@ import logger.OhmLogger;
|
||||
* 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.
|
||||
*/
|
||||
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
|
||||
//Verbindungskonstanten
|
||||
private static final int MYSIPPORT = 5060;
|
||||
private static final int MYRTPPORT = 5004;
|
||||
private static final int MYRTCPPORT = 5005;
|
||||
private static final String PROTOCOLTYP = "UDP";
|
||||
|
||||
Hauptfenster view; //später entfernen wegen Zugriff
|
||||
public static final Logger lg = OhmLogger.getLogger();
|
||||
@ -55,26 +63,28 @@ public class SIPmodel implements SipListenerExt
|
||||
|
||||
private AudioRinging audioRinging;
|
||||
|
||||
private int myPort = 5060;
|
||||
//Hilfsbooleans
|
||||
private Boolean anrufer; //Hilfsvariable ob ich selbst anrufer bin
|
||||
private Boolean anrufAngenommen;
|
||||
private Boolean anrufCancel;
|
||||
private Boolean werdeAngerufen;
|
||||
|
||||
//Variablen die im Laufe des Gespräches ermittelt werden
|
||||
//Eigene Daten
|
||||
private String myIPAddress;
|
||||
private String myName = "129";
|
||||
public String protocolTyp = "UDP";
|
||||
public String myIPAddress = "192.168.100.30";
|
||||
public String proxyAddress;
|
||||
public CallIdHeader callID;
|
||||
|
||||
Boolean anrufer; //Hilfsvariable ob ich selbst anrufer bin
|
||||
Boolean anrufAngenommen;
|
||||
Boolean anrufCancel;
|
||||
//Hilfsvariablen wenn ich angerufen werde. evtl. noch optimieren
|
||||
Boolean werdeAngerufen;
|
||||
|
||||
private long cSequenz;
|
||||
private String proxyTag;
|
||||
private String myTag;
|
||||
private String branch;
|
||||
private String line;
|
||||
private Address contactAddress;
|
||||
private ContactHeader contactHeader;
|
||||
//ProxyServer
|
||||
public String proxyAddress;
|
||||
private int proxyRTPPort;
|
||||
private String proxyTag;
|
||||
//CallDaten
|
||||
private String branch;
|
||||
public CallIdHeader callID;
|
||||
private long cSequenz;
|
||||
private String RTPCodec;
|
||||
|
||||
public SIPmodel(Hauptfenster view) //Konstruktor für eigene Daten
|
||||
{
|
||||
@ -84,18 +94,15 @@ public class SIPmodel implements SipListenerExt
|
||||
anrufCancel = false;
|
||||
proxyAddress = "";
|
||||
proxyTag = "";
|
||||
line = "";
|
||||
cSequenz = 1;
|
||||
werdeAngerufen = false;
|
||||
|
||||
audioRinging = new AudioRinging();
|
||||
myTag = createString(8); //erzeugt Random Tag mit Länge 8
|
||||
branch = createString(18);//erzeugt Random branch mit Länge 18
|
||||
|
||||
try
|
||||
{
|
||||
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();
|
||||
@ -104,69 +111,59 @@ public class SIPmodel implements SipListenerExt
|
||||
this.messageFactory = this.sipFactory.createMessageFactory();
|
||||
this.headerFactory = this.sipFactory.createHeaderFactory();
|
||||
this.addressFactory = this.sipFactory.createAddressFactory();
|
||||
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp);
|
||||
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.myPort);
|
||||
this.contactAddress = this.addressFactory.createAddress("sip:" + this.myName + "@" + this.myIPAddress + ":" + this.MYSIPPORT);
|
||||
this.contactHeader = this.headerFactory.createContactHeader(contactAddress);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
System.out.println("Fehler bei Initialisierung eigener Addresse");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private String createString(int anzahl)
|
||||
private String createString(int anzahl) //Erzeugt Random String in bestimmter länge für branch und Tag
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < anzahl; i++)
|
||||
{
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
sb.append(TEST.charAt(RANDOM.nextInt(TEST.length())));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException
|
||||
{
|
||||
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException {
|
||||
proxyAddress = serverIP + ":" + serverPort;
|
||||
SIPRegister register = new SIPRegister(proxyAddress, myTag, myIPAddress, myPort, branch, addressFactory, headerFactory, messageFactory, contactHeader, sipProvider.getNewCallId());
|
||||
SIPRegister register = new SIPRegister(proxyAddress, myTag, myIPAddress, MYSIPPORT, branch, addressFactory, headerFactory, messageFactory, contactHeader, sipProvider.getNewCallId());
|
||||
sipProvider.sendRequest(register.getRequest());
|
||||
lg.info("Erfolgreiches Senden der Registrierung");
|
||||
}
|
||||
|
||||
public void sendInvitation(String sipaddresse, String proxyaddresse,
|
||||
int serverPort) throws SipException
|
||||
{ //ServerPort wird nicht verwendet?
|
||||
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);
|
||||
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());
|
||||
lg.info("Erfolgreiches Senden der Invitation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processRequest(RequestEvent requestEvent)
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
{
|
||||
} catch (SipException ex) {
|
||||
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
//Aktive Kommunikation
|
||||
} //Aktive Kommunikation
|
||||
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer
|
||||
{
|
||||
resetCallParameter();
|
||||
@ -177,8 +174,7 @@ public class SIPmodel implements SipListenerExt
|
||||
proxyTag = ((FromHeader) requestEvent.getRequest().getHeader("From")).getTag();
|
||||
callID = ((CallIdHeader) requestEvent.getRequest().getHeader("CallID"));
|
||||
//Standartabfolge sobald man angerufen wird
|
||||
try
|
||||
{
|
||||
try {
|
||||
//Trying Response erzeugen und abschicken
|
||||
SIP100Trying tempTrying = new SIP100Trying(messageFactory, requestEvent, headerFactory);
|
||||
sipProvider.sendResponse(tempTrying.getTryResponse());
|
||||
@ -188,230 +184,271 @@ public class SIPmodel implements SipListenerExt
|
||||
//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()
|
||||
{
|
||||
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
int counter = 0;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (anrufAngenommen != true) //Falls man nicht abnimmt, klingeln + Ringing schicken
|
||||
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
|
||||
} 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, requestEvent, anrufer);
|
||||
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();
|
||||
}
|
||||
}
|
||||
catch (SipException ex)
|
||||
{
|
||||
counter++;
|
||||
} catch (SipException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
catch (SipException ex)
|
||||
{
|
||||
} catch (SipException ex) {
|
||||
lg.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} else if ((Request.ACK).equals(requestEvent.getRequest().getMethod())) {
|
||||
|
||||
}
|
||||
else if ((Request.ACK).equals(requestEvent.getRequest().getMethod()))
|
||||
{
|
||||
|
||||
}
|
||||
else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod()))
|
||||
{
|
||||
} else if ((Request.CANCEL).equals(requestEvent.getRequest().getMethod())) {
|
||||
System.out.println("Anruf cancel");
|
||||
view.getTxtArea().append("Anruf wurde gecancelt");
|
||||
try
|
||||
{
|
||||
try {
|
||||
//Cancel Request -> Response 200 Ok + Response 487 Request Terminated
|
||||
//200 Ok
|
||||
anrufCancel = true;
|
||||
SIP200Ok tempOk = new SIP200Ok(messageFactory, requestEvent, contactHeader, headerFactory);
|
||||
this.sipProvider.sendResponse(tempOk.getResponse());
|
||||
sipProvider.sendResponse(tempOk.getResponse());
|
||||
view.getTxtArea().append("Anrufender canceld Anfrage\n");
|
||||
lg.info("Erfolgreiches senden des 200 OkHeaders auf CancelAnfrage");
|
||||
//487 Request Terminated
|
||||
}
|
||||
catch (SipException ex)
|
||||
{
|
||||
} catch (SipException ex) {
|
||||
Logger.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
else if ((Request.BYE).equals(requestEvent.getRequest().getMethod()))
|
||||
{
|
||||
try
|
||||
{
|
||||
} 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)
|
||||
{
|
||||
} 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
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
} 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);
|
||||
}
|
||||
else if (responseEvent.getResponse().getStatusCode() == Response.OK)
|
||||
{
|
||||
System.out.println("Beende RTP Session");
|
||||
*/
|
||||
} else {
|
||||
lg.info("Erfolgreichen Response (200 OK) bekommen");
|
||||
}
|
||||
else if (responseEvent.getResponse().getStatusCode() == Response.RINGING)
|
||||
{
|
||||
} 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
|
||||
{
|
||||
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);
|
||||
SIPBye tempBye = new SIPBye(calluser, proxyAddress, myName, myIPAddress, myTag, proxyTag, MYSIPPORT, branch, callID, cSequenz, messageFactory, contactHeader, addressFactory, headerFactory);
|
||||
sipProvider.sendRequest(tempBye.getByeRequest());
|
||||
lg.info("Erfolgreiches Senden des BYE Headers");
|
||||
}
|
||||
|
||||
public void resetCallParameter()
|
||||
{
|
||||
public void getRTPParameters(ResponseEvent responseEvent) {
|
||||
int identifier = 0;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCallParameter() {
|
||||
anrufAngenommen = false;
|
||||
anrufer = false;
|
||||
}
|
||||
|
||||
public void anrufAnnehmen()
|
||||
{
|
||||
public void anrufAnnehmen() {
|
||||
anrufAngenommen = true;
|
||||
}
|
||||
|
||||
//Get Methoden falls man mal die Parameter braucht
|
||||
public String getmyName()
|
||||
{
|
||||
public String getmyName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public Integer getMyPort()
|
||||
{
|
||||
return myPort;
|
||||
public Integer getMyPort() {
|
||||
return MYSIPPORT;
|
||||
}
|
||||
|
||||
public String getMyIPAdress()
|
||||
{
|
||||
public String getMyIPAdress() {
|
||||
return myIPAddress;
|
||||
}
|
||||
|
||||
// Herausfinden bei welchen Events die unteren Funktionen aufgerufen werden -> evtl brauchbar
|
||||
@Override
|
||||
public void processTimeout(TimeoutEvent timeoutEvent)
|
||||
{
|
||||
public void processTimeout(TimeoutEvent timeoutEvent) {
|
||||
//view.getTxtArea().append("processTimeout\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processIOException(IOExceptionEvent exceptionEvent)
|
||||
{
|
||||
public void processIOException(IOExceptionEvent exceptionEvent) {
|
||||
//view.getTxtArea().append("processIOException\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTransactionTerminated(
|
||||
TransactionTerminatedEvent transactionTerminatedEvent)
|
||||
{
|
||||
TransactionTerminatedEvent transactionTerminatedEvent) {
|
||||
//view.getTxtArea().append("processTransactionTerminated\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processDialogTerminated(
|
||||
DialogTerminatedEvent dialogTerminatedEvent)
|
||||
{
|
||||
DialogTerminatedEvent dialogTerminatedEvent) {
|
||||
//view.getTxtArea().append("processDialogTerminated\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent)
|
||||
{
|
||||
public void processDialogTimeout(DialogTimeoutEvent timeoutEvent) {
|
||||
//view.getTxtArea().append("processDialogTerminated\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myPort the myPort to set
|
||||
* @param myPort the MYSIPPORT to set
|
||||
*/
|
||||
public void setMyPort(int myPort)
|
||||
{
|
||||
this.myPort = myPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the myName
|
||||
*/
|
||||
public String getMyName()
|
||||
{
|
||||
public String getMyName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the proxyTag
|
||||
*/
|
||||
public String getProxyTag()
|
||||
{
|
||||
public String getProxyTag() {
|
||||
return proxyTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param proxyTag the proxyTag to set
|
||||
*/
|
||||
public void setProxyTag(String proxyTag)
|
||||
{
|
||||
public void setProxyTag(String proxyTag) {
|
||||
this.proxyTag = proxyTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the myTag
|
||||
*/
|
||||
public String getMyTag()
|
||||
{
|
||||
public String getMyTag() {
|
||||
return myTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param myTag the myTag to set
|
||||
*/
|
||||
public void setMyTag(String myTag)
|
||||
{
|
||||
public void setMyTag(String myTag) {
|
||||
this.myTag = myTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the branch
|
||||
*/
|
||||
public String getBranch()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,15 @@ import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import jlibrtp.*;
|
||||
|
||||
/**
|
||||
* @author Arne Kepp
|
||||
*/
|
||||
public class SoundSenderDemo implements RTPAppIntf {
|
||||
|
||||
SIPmodel model;
|
||||
public RTPSession rtpSession = null;
|
||||
static int pktCount = 0;
|
||||
static int dataCount = 0;
|
||||
@ -42,31 +44,42 @@ public class SoundSenderDemo implements RTPAppIntf {
|
||||
LEFT, RIGHT, NORMAL
|
||||
};
|
||||
|
||||
public SoundSenderDemo() {}
|
||||
|
||||
public SoundSenderDemo(boolean isLocal) throws UnknownHostException, InterruptedException {
|
||||
this.model = model;
|
||||
|
||||
DatagramSocket rtpSocket = null;
|
||||
DatagramSocket rtcpSocket = null;
|
||||
|
||||
// for(int i=5000; i<=6000; i++)
|
||||
// {
|
||||
//rtpSocket.close();
|
||||
//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 {
|
||||
// rtpSocket = new DatagramSocket(5004, myIP);
|
||||
// rtcpSocket = new DatagramSocket(5005, myIP);
|
||||
// } catch (SocketException e) {
|
||||
// rtpSocket = new DatagramSocket(model.getProxyRTPPort());
|
||||
// } catch (SocketException ex) {
|
||||
// Logger.getLogger(SoundSenderDemo.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// 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 {
|
||||
rtpSocket = new DatagramSocket(null);
|
||||
InetSocketAddress myInetSocketAddress = new InetSocketAddress(5004);
|
||||
@ -77,7 +90,7 @@ public class SoundSenderDemo implements RTPAppIntf {
|
||||
rtpSocket.close();
|
||||
rtcpSocket.close();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
rtpSession = new RTPSession(rtpSocket, rtcpSocket);
|
||||
rtpSession.RTPSessionRegister(this, null, null);
|
||||
@ -90,7 +103,7 @@ public class SoundSenderDemo implements RTPAppIntf {
|
||||
*/
|
||||
public void SendDemo(String[] args) throws UnknownHostException, InterruptedException {
|
||||
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[2] = "5004";
|
||||
args[3] = "5005";
|
||||
@ -105,8 +118,9 @@ public class SoundSenderDemo implements RTPAppIntf {
|
||||
// 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);
|
||||
SoundSenderDemo aDemo;
|
||||
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.filename = args[0];
|
||||
aDemo.run();
|
||||
@ -190,7 +204,7 @@ public class SoundSenderDemo implements RTPAppIntf {
|
||||
if (nBytesRead >= 0) {
|
||||
rtpSession.sendData(abData);
|
||||
//if(!this.local) {
|
||||
auline.write(abData, 0, abData.length);
|
||||
//auline.write(abData, 0, abData.length);
|
||||
|
||||
//dataCount += abData.length;
|
||||
//if(pktCount % 10 == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user