adaptation of old eclipse code to Intellij
This commit is contained in:
@@ -6,7 +6,7 @@ import com.sun.jna.*;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface Bass extends Library {
|
public interface Bass extends Library {
|
||||||
|
|
||||||
Bass Instance = (Bass) Native.load("bass", Bass.class);
|
Bass Instance = Native.load("bass", Bass.class);
|
||||||
int BASSVERSION = 0x204; // API version
|
int BASSVERSION = 0x204; // API version
|
||||||
String BASSVERSIONTEXT = "2.4";
|
String BASSVERSIONTEXT = "2.4";
|
||||||
|
|
||||||
@@ -802,6 +802,7 @@ public interface Bass extends Library {
|
|||||||
// gak bisa
|
// gak bisa
|
||||||
int BASS_StreamCreate(int freq, int chans, int flags, int proc, Pointer user);
|
int BASS_StreamCreate(int freq, int chans, int flags, int proc, Pointer user);
|
||||||
|
|
||||||
|
@SuppressWarnings("DataFlowIssue")
|
||||||
default String GetBassError(String function, int err) {
|
default String GetBassError(String function, int err) {
|
||||||
if (err==0)
|
if (err==0)
|
||||||
return function+": SUCCESS";
|
return function+": SUCCESS";
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ import com.sun.jna.Pointer;
|
|||||||
* @author rdkartono
|
* @author rdkartono
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings({"unused", "UnusedReturnValue"})
|
||||||
interface BassEnc extends Library {
|
interface BassEnc extends Library {
|
||||||
BassEnc Instance = (BassEnc) Native.load("bassenc", BassEnc.class);
|
BassEnc Instance = Native.load("bassenc", BassEnc.class);
|
||||||
|
|
||||||
interface ENCODEPROC extends Callback
|
interface ENCODEPROC extends Callback
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Audio.BassEnc.ENCODEPROCEX;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface BassEncAAC extends Library {
|
public interface BassEncAAC extends Library {
|
||||||
|
|
||||||
BassEncAAC Instance = (BassEncAAC) Native.load("bassenc_aac",BassEncAAC.class);
|
BassEncAAC Instance = Native.load("bassenc_aac",BassEncAAC.class);
|
||||||
int BASS_Encode_AAC_GetVersion();
|
int BASS_Encode_AAC_GetVersion();
|
||||||
|
|
||||||
int BASS_Encode_AAC_Start(int handle, String options, int flags, ENCODEPROCEX proc, Pointer user);
|
int BASS_Encode_AAC_Start(int handle, String options, int flags, ENCODEPROCEX proc, Pointer user);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Audio.BassEnc.ENCODEPROCEX;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface BassEncMP3 extends Library{
|
public interface BassEncMP3 extends Library{
|
||||||
BassEncMP3 Instance = (BassEncMP3) Native.load("bassenc_mp3",BassEncMP3.class);
|
BassEncMP3 Instance = Native.load("bassenc_mp3",BassEncMP3.class);
|
||||||
|
|
||||||
int BASS_Encode_MP3_GetVersion();
|
int BASS_Encode_MP3_GetVersion();
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Audio.BassEnc.ENCODEPROC;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface BassEncOGG extends Library {
|
public interface BassEncOGG extends Library {
|
||||||
BassEncOGG Instance = (BassEncOGG) Native.load("bassenc_ogg",BassEncOGG.class);
|
BassEncOGG Instance = Native.load("bassenc_ogg",BassEncOGG.class);
|
||||||
int BASS_Encode_OGG_GetVersion();
|
int BASS_Encode_OGG_GetVersion();
|
||||||
|
|
||||||
int BASS_Encode_OGG_Start(int handle, String options, int flags, ENCODEPROC proc, Pointer user);
|
int BASS_Encode_OGG_Start(int handle, String options, int flags, ENCODEPROC proc, Pointer user);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Audio.BassEnc.ENCODEPROC;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface BassEncOPUS extends Library{
|
public interface BassEncOPUS extends Library{
|
||||||
BassEncOPUS BASSENC_OPUS = (BassEncOPUS) Native.load("bassenc_opus",BassEncOPUS.class);
|
BassEncOPUS BASSENC_OPUS = Native.load("bassenc_opus",BassEncOPUS.class);
|
||||||
interface Constant{
|
interface Constant{
|
||||||
// BASS_Encode_OPUS_NewStream flags
|
// BASS_Encode_OPUS_NewStream flags
|
||||||
int BASS_ENCODE_OPUS_RESET = 0x1000000;
|
int BASS_ENCODE_OPUS_RESET = 0x1000000;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Audio.Bass.SYNCPROC;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface BassMix extends Library {
|
public interface BassMix extends Library {
|
||||||
BassMix Instance = (BassMix) Native.load("bassmix",BassMix.class);
|
BassMix Instance = Native.load("bassmix",BassMix.class);
|
||||||
|
|
||||||
interface Constant{
|
interface Constant{
|
||||||
// Additional BASS_SetConfig options
|
// Additional BASS_SetConfig options
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Audio.Bass.DOWNLOADPROC;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public interface BassOPUS extends Library {
|
public interface BassOPUS extends Library {
|
||||||
BassOPUS Instance = (BassOPUS) Native.load("bassopus",BassOPUS.class);
|
BassOPUS Instance = Native.load("bassopus",BassOPUS.class);
|
||||||
interface Constant{
|
interface Constant{
|
||||||
// BASS_CHANNELINFO type
|
// BASS_CHANNELINFO type
|
||||||
int BASS_CTYPE_STREAM_OPUS = 0x11200;
|
int BASS_CTYPE_STREAM_OPUS = 0x11200;
|
||||||
|
|||||||
@@ -24,30 +24,31 @@ import java.net.InetAddress;
|
|||||||
import peers.media.MediaMode;
|
import peers.media.MediaMode;
|
||||||
import peers.sip.syntaxencoding.SipURI;
|
import peers.sip.syntaxencoding.SipURI;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public interface Config {
|
public interface Config {
|
||||||
|
|
||||||
public void save();
|
void save();
|
||||||
public InetAddress getLocalInetAddress();
|
InetAddress getLocalInetAddress();
|
||||||
public InetAddress getPublicInetAddress();
|
InetAddress getPublicInetAddress();
|
||||||
public String getUserPart();
|
String getUserPart();
|
||||||
public String getDomain();
|
String getDomain();
|
||||||
public String getPassword();
|
String getPassword();
|
||||||
public SipURI getOutboundProxy();
|
SipURI getOutboundProxy();
|
||||||
public int getSipPort();
|
int getSipPort();
|
||||||
public MediaMode getMediaMode();
|
MediaMode getMediaMode();
|
||||||
public boolean isMediaDebug();
|
boolean isMediaDebug();
|
||||||
public String getMediaFile();
|
String getMediaFile();
|
||||||
public int getRtpPort();
|
int getRtpPort();
|
||||||
public void setLocalInetAddress(InetAddress inetAddress);
|
void setLocalInetAddress(InetAddress inetAddress);
|
||||||
public void setPublicInetAddress(InetAddress inetAddress);
|
void setPublicInetAddress(InetAddress inetAddress);
|
||||||
public void setUserPart(String userPart);
|
void setUserPart(String userPart);
|
||||||
public void setDomain(String domain);
|
void setDomain(String domain);
|
||||||
public void setPassword(String password);
|
void setPassword(String password);
|
||||||
public void setOutboundProxy(SipURI outboundProxy);
|
void setOutboundProxy(SipURI outboundProxy);
|
||||||
public void setSipPort(int sipPort);
|
void setSipPort(int sipPort);
|
||||||
public void setMediaMode(MediaMode mediaMode);
|
void setMediaMode(MediaMode mediaMode);
|
||||||
public void setMediaDebug(boolean mediaDebug);
|
void setMediaDebug(boolean mediaDebug);
|
||||||
public void setMediaFile(String mediaFile);
|
void setMediaFile(String mediaFile);
|
||||||
public void setRtpPort(int rtpPort);
|
void setRtpPort(int rtpPort);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.net.InetAddress;
|
|||||||
import peers.media.MediaMode;
|
import peers.media.MediaMode;
|
||||||
import peers.sip.syntaxencoding.SipURI;
|
import peers.sip.syntaxencoding.SipURI;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class JavaConfig implements Config {
|
public class JavaConfig implements Config {
|
||||||
|
|
||||||
private InetAddress localInetAddress;
|
private InetAddress localInetAddress;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package peers.media;
|
package peers.media;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public abstract class AbstractSoundManager implements SoundSource {
|
public abstract class AbstractSoundManager implements SoundSource {
|
||||||
|
|
||||||
public final static String MEDIA_DIR = "media";
|
public final static String MEDIA_DIR = "media";
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ public class Capture implements Runnable {
|
|||||||
public static final int SAMPLE_SIZE = 16;
|
public static final int SAMPLE_SIZE = 16;
|
||||||
public static final int BUFFER_SIZE = SAMPLE_SIZE * 20;
|
public static final int BUFFER_SIZE = SAMPLE_SIZE * 20;
|
||||||
|
|
||||||
private PipedOutputStream rawData;
|
private final PipedOutputStream rawData;
|
||||||
private boolean isStopped;
|
private boolean isStopped;
|
||||||
private SoundSource soundSource;
|
private final SoundSource soundSource;
|
||||||
|
|
||||||
private CountDownLatch latch;
|
private final CountDownLatch latch;
|
||||||
|
|
||||||
public Capture(PipedOutputStream rawData, SoundSource soundSource,
|
public Capture(PipedOutputStream rawData, SoundSource soundSource,
|
||||||
CountDownLatch latch) {
|
CountDownLatch latch) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.io.PipedOutputStream;
|
|||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
import peers.rtp.RFC3551;
|
import peers.rtp.RFC3551;
|
||||||
import peers.rtp.RtpSession;
|
import peers.rtp.RtpSession;
|
||||||
@@ -36,10 +37,10 @@ public class CaptureRtpSender {
|
|||||||
|
|
||||||
public static final int PIPE_SIZE = 4096;
|
public static final int PIPE_SIZE = 4096;
|
||||||
|
|
||||||
private RtpSession rtpSession;
|
private final RtpSession rtpSession;
|
||||||
private Capture capture;
|
private Capture capture;
|
||||||
private Encoder encoder;
|
private Encoder encoder;
|
||||||
private RtpSender rtpSender;
|
@Getter private RtpSender rtpSender;
|
||||||
|
|
||||||
public CaptureRtpSender(RtpSession rtpSession, SoundSource soundSource,
|
public CaptureRtpSender(RtpSession rtpSession, SoundSource soundSource,
|
||||||
boolean mediaDebug, Codec codec, String peersHome)
|
boolean mediaDebug, Codec codec, String peersHome)
|
||||||
@@ -123,8 +124,4 @@ public class CaptureRtpSender {
|
|||||||
return rtpSession;
|
return rtpSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RtpSender getRtpSender() {
|
|
||||||
return rtpSender;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import peers.rtp.RtpPacket;
|
|||||||
public class DtmfFactory {
|
public class DtmfFactory {
|
||||||
|
|
||||||
public List<RtpPacket> createDtmfPackets(char digit) {
|
public List<RtpPacket> createDtmfPackets(char digit) {
|
||||||
List<RtpPacket> packets = new ArrayList<RtpPacket>();
|
List<RtpPacket> packets = new ArrayList<>();
|
||||||
byte[] data = new byte[4];
|
byte[] data = new byte[4];
|
||||||
// RFC4733
|
// RFC4733
|
||||||
if (digit == '*') {
|
if (digit == '*') {
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ public class Echo implements Runnable {
|
|||||||
|
|
||||||
public static final int BUFFER_SIZE = 2048;
|
public static final int BUFFER_SIZE = 2048;
|
||||||
|
|
||||||
private DatagramSocket datagramSocket;
|
private final DatagramSocket datagramSocket;
|
||||||
private InetAddress remoteAddress;
|
private final InetAddress remoteAddress;
|
||||||
private int remotePort;
|
private final int remotePort;
|
||||||
private boolean isRunning;
|
private boolean isRunning;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,15 +36,15 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
|
|
||||||
public abstract class Encoder implements Runnable {
|
public abstract class Encoder implements Runnable {
|
||||||
|
|
||||||
private PipedInputStream rawData;
|
private final PipedInputStream rawData;
|
||||||
private PipedOutputStream encodedData;
|
private final PipedOutputStream encodedData;
|
||||||
private boolean isStopped;
|
private boolean isStopped;
|
||||||
private FileOutputStream encoderOutput;
|
private FileOutputStream encoderOutput;
|
||||||
private FileOutputStream encoderInput;
|
private FileOutputStream encoderInput;
|
||||||
private boolean mediaDebug;
|
private final boolean mediaDebug;
|
||||||
|
|
||||||
private String peersHome;
|
private final String peersHome;
|
||||||
private CountDownLatch latch;
|
private final CountDownLatch latch;
|
||||||
|
|
||||||
public Encoder(PipedInputStream rawData, PipedOutputStream encodedData,
|
public Encoder(PipedInputStream rawData, PipedOutputStream encodedData,
|
||||||
boolean mediaDebug, String peersHome,
|
boolean mediaDebug, String peersHome,
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import java.io.IOException;
|
|||||||
//
|
//
|
||||||
// Validate
|
// Validate
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class FileReader implements SoundSource {
|
public class FileReader implements SoundSource {
|
||||||
|
|
||||||
public final static int BUFFER_SIZE = 256;
|
public final static int BUFFER_SIZE = 256;
|
||||||
@@ -76,7 +77,7 @@ public class FileReader implements SoundSource {
|
|||||||
if (fileInputStream == null) {
|
if (fileInputStream == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
byte buffer[] = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
try {
|
try {
|
||||||
if (fileInputStream.read(buffer) >= 0) {
|
if (fileInputStream.read(buffer) >= 0) {
|
||||||
Thread.sleep(15);
|
Thread.sleep(15);
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ import peers.sdp.Codec;
|
|||||||
|
|
||||||
public class IncomingRtpReader implements RtpListener {
|
public class IncomingRtpReader implements RtpListener {
|
||||||
|
|
||||||
private RtpSession rtpSession;
|
private final RtpSession rtpSession;
|
||||||
private AbstractSoundManager soundManager;
|
private final AbstractSoundManager soundManager;
|
||||||
private Decoder decoder;
|
private final Decoder decoder;
|
||||||
|
|
||||||
public IncomingRtpReader(RtpSession rtpSession,
|
public IncomingRtpReader(RtpSession rtpSession,
|
||||||
AbstractSoundManager soundManager, Codec codec)
|
AbstractSoundManager soundManager, Codec codec)
|
||||||
|
|||||||
@@ -27,25 +27,28 @@ import java.util.List;
|
|||||||
|
|
||||||
import Audio.BassFileReader;
|
import Audio.BassFileReader;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
import peers.rtp.RtpPacket;
|
import peers.rtp.RtpPacket;
|
||||||
import peers.rtp.RtpSession;
|
import peers.rtp.RtpSession;
|
||||||
import peers.sdp.Codec;
|
import peers.sdp.Codec;
|
||||||
import peers.sip.core.useragent.UserAgent;
|
import peers.sip.core.useragent.UserAgent;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class MediaManager {
|
public class MediaManager {
|
||||||
|
|
||||||
public static final int DEFAULT_CLOCK = 8000; // Hz
|
public static final int DEFAULT_CLOCK = 8000; // Hz
|
||||||
|
|
||||||
private UserAgent userAgent;
|
private final UserAgent userAgent;
|
||||||
private CaptureRtpSender captureRtpSender;
|
private CaptureRtpSender captureRtpSender;
|
||||||
private IncomingRtpReader incomingRtpReader;
|
private IncomingRtpReader incomingRtpReader;
|
||||||
private RtpSession rtpSession;
|
private RtpSession rtpSession;
|
||||||
private DtmfFactory dtmfFactory;
|
private final DtmfFactory dtmfFactory;
|
||||||
|
|
||||||
private DatagramSocket datagramSocket;
|
@Getter @Setter private DatagramSocket datagramSocket;
|
||||||
//private FileReader fileReader;
|
//private FileReader fileReader;
|
||||||
private BassFileReader fileReader;
|
@Getter private BassFileReader fileReader;
|
||||||
|
|
||||||
public MediaManager(UserAgent userAgent) {
|
public MediaManager(UserAgent userAgent) {
|
||||||
this.userAgent = userAgent;
|
this.userAgent = userAgent;
|
||||||
@@ -236,30 +239,23 @@ public class MediaManager {
|
|||||||
|
|
||||||
public void updateRemote(String destAddress, int destPort, Codec codec) {
|
public void updateRemote(String destAddress, int destPort, Codec codec) {
|
||||||
switch (userAgent.getMediaMode()) {
|
switch (userAgent.getMediaMode()) {
|
||||||
case captureAndPlayback:
|
case file:
|
||||||
try {
|
case captureAndPlayback:
|
||||||
InetAddress inetAddress = InetAddress.getByName(destAddress);
|
try {
|
||||||
rtpSession.setRemoteAddress(inetAddress);
|
InetAddress inetAddress = InetAddress.getByName(destAddress);
|
||||||
} catch (UnknownHostException e) {
|
rtpSession.setRemoteAddress(inetAddress);
|
||||||
Logger.error("unknown host: " + destAddress, e);
|
} catch (UnknownHostException e) {
|
||||||
}
|
Logger.error("unknown host: " + destAddress, e);
|
||||||
rtpSession.setRemotePort(destPort);
|
}
|
||||||
break;
|
rtpSession.setRemotePort(destPort);
|
||||||
case echo:
|
break;
|
||||||
//TODO update echo socket
|
case echo:
|
||||||
break;
|
//TODO update echo socket
|
||||||
case file:
|
break;
|
||||||
try {
|
|
||||||
InetAddress inetAddress = InetAddress.getByName(destAddress);
|
|
||||||
rtpSession.setRemoteAddress(inetAddress);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
Logger.error("unknown host: " + destAddress, e);
|
|
||||||
}
|
|
||||||
rtpSession.setRemotePort(destPort);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -317,19 +313,10 @@ public class MediaManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDatagramSocket(DatagramSocket datagramSocket) {
|
|
||||||
this.datagramSocket = datagramSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatagramSocket getDatagramSocket() {
|
|
||||||
return datagramSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public FileReader getFileReader() {
|
// public FileReader getFileReader() {
|
||||||
// return fileReader;
|
// return fileReader;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public BassFileReader getFileReader() {
|
|
||||||
return fileReader;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ package peers.media;
|
|||||||
|
|
||||||
public class PcmaDecoder extends Decoder {
|
public class PcmaDecoder extends Decoder {
|
||||||
|
|
||||||
private static short aLawDecompressTable[] = new short[]{
|
private static final short aLawDecompressTable[] = new short[]{
|
||||||
-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
|
-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
|
||||||
-7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
|
-7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
|
||||||
-2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
|
-2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
public class PcmaEncoder extends Encoder {
|
public class PcmaEncoder extends Encoder {
|
||||||
|
|
||||||
private final static int cClip = 32635;
|
private final static int cClip = 32635;
|
||||||
private static byte aLawCompressTable[] = new byte[]{
|
private final static byte[] aLawCompressTable = new byte[]{
|
||||||
1, 1, 2, 2, 3, 3, 3, 3,
|
1, 1, 2, 2, 3, 3, 3, 3,
|
||||||
4, 4, 4, 4, 4, 4, 4, 4,
|
4, 4, 4, 4, 4, 4, 4, 4,
|
||||||
5, 5, 5, 5, 5, 5, 5, 5,
|
5, 5, 5, 5, 5, 5, 5, 5,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class PcmuDecoder extends Decoder {
|
|||||||
// private final static int SEG_SHIFT = 4;
|
// private final static int SEG_SHIFT = 4;
|
||||||
// private final static int SEG_MASK = 0x70;
|
// private final static int SEG_MASK = 0x70;
|
||||||
// private final static int SIGN_BIT = 0x80;
|
// private final static int SIGN_BIT = 0x80;
|
||||||
private static short muLawDecompressTable[] = new short[]{
|
private final static short[] muLawDecompressTable = new short[]{
|
||||||
-32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
|
-32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
|
||||||
-23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
|
-23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
|
||||||
-15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
|
-15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("SameParameterValue")
|
||||||
public class PcmuEncoder extends Encoder {
|
public class PcmuEncoder extends Encoder {
|
||||||
|
|
||||||
private final static int cBias = 0x84;
|
private final static int cBias = 0x84;
|
||||||
private final static short seg_end[] = new short[]{0xFF, 0x1FF, 0x3FF, 0x7FF,
|
private final static short[] seg_end = new short[]{0xFF, 0x1FF, 0x3FF, 0x7FF,
|
||||||
0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
|
0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -40,16 +40,16 @@ import peers.sdp.Codec;
|
|||||||
|
|
||||||
public class RtpSender implements Runnable {
|
public class RtpSender implements Runnable {
|
||||||
|
|
||||||
private PipedInputStream encodedData;
|
private final PipedInputStream encodedData;
|
||||||
private RtpSession rtpSession;
|
private final RtpSession rtpSession;
|
||||||
private boolean isStopped;
|
private boolean isStopped;
|
||||||
private FileOutputStream rtpSenderInput;
|
private FileOutputStream rtpSenderInput;
|
||||||
private boolean mediaDebug;
|
private final boolean mediaDebug;
|
||||||
private Codec codec;
|
private final Codec codec;
|
||||||
private List<RtpPacket> pushedPackets;
|
private final List<RtpPacket> pushedPackets;
|
||||||
|
|
||||||
private String peersHome;
|
private final String peersHome;
|
||||||
private CountDownLatch latch;
|
private final CountDownLatch latch;
|
||||||
|
|
||||||
public RtpSender(PipedInputStream encodedData, RtpSession rtpSession,
|
public RtpSender(PipedInputStream encodedData, RtpSession rtpSession,
|
||||||
boolean mediaDebug, Codec codec, String peersHome,
|
boolean mediaDebug, Codec codec, String peersHome,
|
||||||
@@ -62,7 +62,7 @@ public class RtpSender implements Runnable {
|
|||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
isStopped = false;
|
isStopped = false;
|
||||||
pushedPackets = Collections.synchronizedList(
|
pushedPackets = Collections.synchronizedList(
|
||||||
new ArrayList<RtpPacket>());
|
new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -96,7 +96,7 @@ public class RtpSender implements Runnable {
|
|||||||
int timestamp = 0;
|
int timestamp = 0;
|
||||||
int numBytesRead;
|
int numBytesRead;
|
||||||
int tempBytesRead;
|
int tempBytesRead;
|
||||||
long sleepTime = 0;
|
long sleepTime ;
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
long lastSentTime = System.nanoTime();
|
long lastSentTime = System.nanoTime();
|
||||||
// indicate if its the first time that we send a packet (dont wait)
|
// indicate if its the first time that we send a packet (dont wait)
|
||||||
@@ -130,7 +130,7 @@ public class RtpSender implements Runnable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pushedPackets.size() > 0) {
|
if (!pushedPackets.isEmpty()) {
|
||||||
RtpPacket pushedPacket = pushedPackets.remove(0);
|
RtpPacket pushedPacket = pushedPackets.remove(0);
|
||||||
rtpPacket.setMarker(pushedPacket.isMarker());
|
rtpPacket.setMarker(pushedPacket.isMarker());
|
||||||
rtpPacket.setPayloadType(pushedPacket.getPayloadType());
|
rtpPacket.setPayloadType(pushedPacket.getPayloadType());
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ public interface SoundSource {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* read raw data linear PCM 8kHz, 16 bits signed, mono-channel, little endian
|
* read raw data linear PCM 8kHz, 16 bits signed, mono-channel, little endian
|
||||||
* @return
|
* @return raw data
|
||||||
*/
|
*/
|
||||||
public byte[] readData();
|
byte[] readData();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.net.InetAddress;
|
|||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import java.net.DatagramSocket;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
@@ -32,25 +34,22 @@ import org.w3c.dom.NodeList;
|
|||||||
|
|
||||||
public class PeerManager extends Thread {
|
public class PeerManager extends Thread {
|
||||||
|
|
||||||
private InetAddress localAddress;
|
private final InetAddress localAddress;
|
||||||
private int localPort;
|
private final int localPort;
|
||||||
private Document document;
|
@Setter private Document document;
|
||||||
|
|
||||||
public PeerManager(InetAddress localAddress, int localPort) {
|
public PeerManager(InetAddress localAddress, int localPort) {
|
||||||
this.localAddress = localAddress;
|
this.localAddress = localAddress;
|
||||||
this.localPort = localPort;
|
this.localPort = localPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDocument(Document document) {
|
|
||||||
this.document = document;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
DatagramSocket datagramSocket;
|
DatagramSocket datagramSocket;
|
||||||
try {
|
try {
|
||||||
datagramSocket = new DatagramSocket(localPort, localAddress);
|
datagramSocket = new DatagramSocket(localPort, localAddress);
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
e.printStackTrace();
|
Logger.error(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// UDPReceiver udpReceiver = new UDPReceiver(datagramSocket);
|
// UDPReceiver udpReceiver = new UDPReceiver(datagramSocket);
|
||||||
@@ -67,7 +66,7 @@ public class PeerManager extends Thread {
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
Logger.error(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,15 +102,14 @@ public class PeerManager extends Thread {
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
Logger.error(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//datagramSocket.close();
|
//datagramSocket.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
Logger.error(e.getMessage());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,16 @@
|
|||||||
|
|
||||||
package peers.nat;
|
package peers.nat;
|
||||||
|
|
||||||
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class UDPReceiver extends Thread {
|
public class UDPReceiver extends Thread {
|
||||||
|
|
||||||
private DatagramSocket datagramSocket;
|
private final DatagramSocket datagramSocket;
|
||||||
|
|
||||||
public UDPReceiver(DatagramSocket datagramSocket) {
|
public UDPReceiver(DatagramSocket datagramSocket) {
|
||||||
super();
|
super();
|
||||||
@@ -43,7 +46,7 @@ public class UDPReceiver extends Thread {
|
|||||||
+ new String(packet.getData()));
|
+ new String(packet.getData()));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
Logger.error(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
package peers.nat.api;
|
package peers.nat.api;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public interface DataReceiver {
|
public interface DataReceiver {
|
||||||
|
|
||||||
public void dataReceived(byte[] data, String peerId);
|
void dataReceived(byte[] data, String peerId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package peers.nat.api;
|
package peers.nat.api;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public abstract class PeersClient {
|
public abstract class PeersClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
|
|
||||||
package peers.nat.api;
|
package peers.nat.api;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public interface Transport {
|
public interface Transport {
|
||||||
|
|
||||||
public void sendData(byte[] data);
|
void sendData(byte[] data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
|
|
||||||
package peers.rtp;
|
package peers.rtp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
public class RtpPacket {
|
public class RtpPacket {
|
||||||
|
|
||||||
private int version;
|
private int version;
|
||||||
@@ -33,92 +37,4 @@ public class RtpPacket {
|
|||||||
private long[] csrcList;
|
private long[] csrcList;
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
|
||||||
public int getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(int version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPadding() {
|
|
||||||
return padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPadding(boolean padding) {
|
|
||||||
this.padding = padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExtension() {
|
|
||||||
return extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExtension(boolean extension) {
|
|
||||||
this.extension = extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCsrcCount() {
|
|
||||||
return csrcCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCsrcCount(int csrcCount) {
|
|
||||||
this.csrcCount = csrcCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMarker() {
|
|
||||||
return marker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMarker(boolean marker) {
|
|
||||||
this.marker = marker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPayloadType() {
|
|
||||||
return payloadType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayloadType(int payloadType) {
|
|
||||||
this.payloadType = payloadType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSequenceNumber() {
|
|
||||||
return sequenceNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSequenceNumber(int sequenceNumber) {
|
|
||||||
this.sequenceNumber = sequenceNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimestamp(long timestamp) {
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSsrc() {
|
|
||||||
return ssrc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSsrc(long ssrc) {
|
|
||||||
this.ssrc = ssrc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long[] getCsrcList() {
|
|
||||||
return csrcList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCsrcList(long[] csrcList) {
|
|
||||||
this.csrcList = csrcList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(byte[] data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,32 +34,32 @@ public class RtpParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
RtpPacket rtpPacket = new RtpPacket();
|
RtpPacket rtpPacket = new RtpPacket();
|
||||||
int b = (int)(packet[0] & 0xff);
|
int b = (packet[0] & 0xff);
|
||||||
rtpPacket.setVersion((b & 0xc0) >> 6);
|
rtpPacket.setVersion((b & 0xc0) >> 6);
|
||||||
rtpPacket.setPadding((b & 0x20) != 0);
|
rtpPacket.setPadding((b & 0x20) != 0);
|
||||||
rtpPacket.setExtension((b & 0x10) != 0);
|
rtpPacket.setExtension((b & 0x10) != 0);
|
||||||
rtpPacket.setCsrcCount(b & 0x0f);
|
rtpPacket.setCsrcCount(b & 0x0f);
|
||||||
b = (int)(packet[1] & 0xff);
|
b = (packet[1] & 0xff);
|
||||||
rtpPacket.setMarker((b & 0x80) != 0);
|
rtpPacket.setMarker((b & 0x80) != 0);
|
||||||
rtpPacket.setPayloadType(b & 0x7f);
|
rtpPacket.setPayloadType(b & 0x7f);
|
||||||
b = (int)(packet[2] & 0xff);
|
b = (packet[2] & 0xff);
|
||||||
rtpPacket.setSequenceNumber(b * 256 + (int)(packet[3] & 0xff));
|
rtpPacket.setSequenceNumber(b * 256 + (packet[3] & 0xff));
|
||||||
b = (int)(packet[4] & 0xff);
|
b = (packet[4] & 0xff);
|
||||||
rtpPacket.setTimestamp(b * 256 * 256 * 256
|
rtpPacket.setTimestamp((long) b * 256 * 256 * 256
|
||||||
+ (int)(packet[5] & 0xff) * 256 * 256
|
+ (packet[5] & 0xff) * 256 * 256
|
||||||
+ (int)(packet[6] & 0xff) * 256
|
+ (packet[6] & 0xff) * 256
|
||||||
+ (int)(packet[7] & 0xff));
|
+ (packet[7] & 0xff));
|
||||||
b = (int)(packet[8] & 0xff);
|
b = (packet[8] & 0xff);
|
||||||
rtpPacket.setSsrc(b * 256 * 256 * 256
|
rtpPacket.setSsrc((long) b * 256 * 256 * 256
|
||||||
+ (int)(packet[9] & 0xff) * 256 * 256
|
+ (packet[9] & 0xff) * 256 * 256
|
||||||
+ (int)(packet[10] & 0xff) * 256
|
+ (packet[10] & 0xff) * 256
|
||||||
+ (int)(packet[11] & 0xff));
|
+ (packet[11] & 0xff));
|
||||||
long[] csrcList = new long[rtpPacket.getCsrcCount()];
|
long[] csrcList = new long[rtpPacket.getCsrcCount()];
|
||||||
for (int i = 0; i < csrcList.length; ++i)
|
for (int i = 0; i < csrcList.length; ++i)
|
||||||
csrcList[i] = (int)(packet[12 + i] & 0xff) << 24
|
csrcList[i] = (long) (packet[12 + i] & 0xff) << 24
|
||||||
+ (int)(packet[12 + i + 1] & 0xff) << 16
|
+ (packet[12 + i + 1] & 0xff) << 16
|
||||||
+ (int)(packet[12 + i + 2] & 0xff) << 8
|
+ (packet[12 + i + 2] & 0xff) << 8
|
||||||
+ (int)(packet[12 + i + 3] & 0xff);
|
+ (packet[12 + i + 3] & 0xff);
|
||||||
rtpPacket.setCsrcList(csrcList);
|
rtpPacket.setCsrcList(csrcList);
|
||||||
int dataOffset = 12 + csrcList.length * 4;
|
int dataOffset = 12 + csrcList.length * 4;
|
||||||
int dataLength = packet.length - dataOffset;
|
int dataLength = packet.length - dataOffset;
|
||||||
|
|||||||
@@ -19,29 +19,16 @@
|
|||||||
|
|
||||||
package peers.sdp;
|
package peers.sdp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import peers.media.MediaManager;
|
import peers.media.MediaManager;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
public class Codec {
|
public class Codec {
|
||||||
|
|
||||||
private int payloadType;
|
private int payloadType;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public int getPayloadType() {
|
|
||||||
return payloadType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayloadType(int payloadType) {
|
|
||||||
this.payloadType = payloadType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof Codec)) {
|
if (!(obj instanceof Codec)) {
|
||||||
|
|||||||
@@ -19,12 +19,16 @@
|
|||||||
|
|
||||||
package peers.sdp;
|
package peers.sdp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
public class MediaDescription {
|
public class MediaDescription {
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
@@ -34,49 +38,9 @@ public class MediaDescription {
|
|||||||
private int port;
|
private int port;
|
||||||
private List<Codec> codecs;
|
private List<Codec> codecs;
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hashtable<String, String> getAttributes() {
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAttributes(Hashtable<String, String> attributes) {
|
|
||||||
this.attributes = attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getIpAddress() {
|
|
||||||
return ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIpAddress(InetAddress ipAddress) {
|
|
||||||
this.ipAddress = ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPort(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Codec> getCodecs() {
|
|
||||||
return codecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodecs(List<Codec> codecs) {
|
|
||||||
this.codecs = codecs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append(RFC4566.TYPE_MEDIA).append(RFC4566.SEPARATOR);
|
buf.append(RFC4566.TYPE_MEDIA).append(RFC4566.SEPARATOR);
|
||||||
buf.append(type).append(" ").append(port);
|
buf.append(type).append(" ").append(port);
|
||||||
buf.append(" RTP/AVP");
|
buf.append(" RTP/AVP");
|
||||||
@@ -106,7 +70,7 @@ public class MediaDescription {
|
|||||||
buf.append(RFC4566.TYPE_ATTRIBUTE).append(RFC4566.SEPARATOR);
|
buf.append(RFC4566.TYPE_ATTRIBUTE).append(RFC4566.SEPARATOR);
|
||||||
buf.append(attributeName);
|
buf.append(attributeName);
|
||||||
String attributeValue = attributes.get(attributeName);
|
String attributeValue = attributes.get(attributeName);
|
||||||
if (attributeValue != null && !"".equals(attributeValue.trim())) {
|
if (attributeValue != null && !attributeValue.trim().isEmpty()) {
|
||||||
buf.append(":").append(attributeValue);
|
buf.append(":").append(attributeValue);
|
||||||
}
|
}
|
||||||
buf.append("\r\n");
|
buf.append("\r\n");
|
||||||
|
|||||||
@@ -19,34 +19,14 @@
|
|||||||
|
|
||||||
package peers.sdp;
|
package peers.sdp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
public class MediaDestination {
|
public class MediaDestination {
|
||||||
|
|
||||||
private String destination;
|
private String destination;
|
||||||
private int port;
|
private int port;
|
||||||
private Codec codec;
|
private Codec codec;
|
||||||
|
|
||||||
public String getDestination() {
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDestination(String destination) {
|
|
||||||
this.destination = destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPort(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Codec getCodec() {
|
|
||||||
return codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodec(Codec codec) {
|
|
||||||
this.codec = codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package peers.sdp;
|
package peers.sdp;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class RFC4566 {
|
public class RFC4566 {
|
||||||
|
|
||||||
public static final char VERSION = '0';
|
public static final char VERSION = '0';
|
||||||
|
|||||||
@@ -35,17 +35,17 @@ import peers.sip.core.useragent.UserAgent;
|
|||||||
|
|
||||||
public class SDPManager {
|
public class SDPManager {
|
||||||
|
|
||||||
private SdpParser sdpParser;
|
private final SdpParser sdpParser;
|
||||||
private UserAgent userAgent;
|
private final UserAgent userAgent;
|
||||||
private List<Codec> supportedCodecs;
|
private final List<Codec> supportedCodecs;
|
||||||
private Random random;
|
private final Random random;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public SDPManager(UserAgent userAgent) {
|
public SDPManager(UserAgent userAgent) {
|
||||||
this.userAgent = userAgent;
|
this.userAgent = userAgent;
|
||||||
sdpParser = new SdpParser();
|
sdpParser = new SdpParser();
|
||||||
supportedCodecs = new ArrayList<Codec>();
|
supportedCodecs = new ArrayList<>();
|
||||||
random = new Random();
|
random = new Random();
|
||||||
//TODO retrieve codecs from configuration file
|
//TODO retrieve codecs from configuration file
|
||||||
Codec codec = new Codec();
|
Codec codec = new Codec();
|
||||||
@@ -116,12 +116,12 @@ public class SDPManager {
|
|||||||
}
|
}
|
||||||
sessionDescription.setIpAddress(inetAddress);
|
sessionDescription.setIpAddress(inetAddress);
|
||||||
sessionDescription.setName("-");
|
sessionDescription.setName("-");
|
||||||
sessionDescription.setAttributes(new Hashtable<String, String>());
|
sessionDescription.setAttributes(new Hashtable<>());
|
||||||
List<Codec> codecs;
|
List<Codec> codecs;
|
||||||
if (offer == null) {
|
if (offer == null) {
|
||||||
codecs = supportedCodecs;
|
codecs = supportedCodecs;
|
||||||
} else {
|
} else {
|
||||||
codecs = new ArrayList<Codec>();
|
codecs = new ArrayList<>();
|
||||||
for (MediaDescription mediaDescription:
|
for (MediaDescription mediaDescription:
|
||||||
offer.getMediaDescriptions()) {
|
offer.getMediaDescriptions()) {
|
||||||
if (RFC4566.MEDIA_AUDIO.equals(mediaDescription.getType())) {
|
if (RFC4566.MEDIA_AUDIO.equals(mediaDescription.getType())) {
|
||||||
@@ -134,14 +134,14 @@ public class SDPManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MediaDescription mediaDescription = new MediaDescription();
|
MediaDescription mediaDescription = new MediaDescription();
|
||||||
Hashtable<String, String> attributes = new Hashtable<String, String>();
|
Hashtable<String, String> attributes = new Hashtable<>();
|
||||||
attributes.put(RFC4566.ATTR_SENDRECV, "");
|
attributes.put(RFC4566.ATTR_SENDRECV, "");
|
||||||
mediaDescription.setAttributes(attributes);
|
mediaDescription.setAttributes(attributes);
|
||||||
mediaDescription.setType(RFC4566.MEDIA_AUDIO);
|
mediaDescription.setType(RFC4566.MEDIA_AUDIO);
|
||||||
mediaDescription.setPort(localRtpPort);
|
mediaDescription.setPort(localRtpPort);
|
||||||
mediaDescription.setCodecs(codecs);
|
mediaDescription.setCodecs(codecs);
|
||||||
List<MediaDescription> mediaDescriptions =
|
List<MediaDescription> mediaDescriptions =
|
||||||
new ArrayList<MediaDescription>();
|
new ArrayList<>();
|
||||||
mediaDescriptions.add(mediaDescription);
|
mediaDescriptions.add(mediaDescription);
|
||||||
sessionDescription.setMediaDescriptions(mediaDescriptions);
|
sessionDescription.setMediaDescriptions(mediaDescriptions);
|
||||||
return sessionDescription;
|
return sessionDescription;
|
||||||
|
|||||||
@@ -19,20 +19,11 @@
|
|||||||
|
|
||||||
package peers.sdp;
|
package peers.sdp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
public class SdpLine {
|
public class SdpLine {
|
||||||
private char type;
|
private char type;
|
||||||
private String value;
|
private String value;
|
||||||
public char getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
public void setType(char type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,81 +19,30 @@
|
|||||||
|
|
||||||
package peers.sdp;
|
package peers.sdp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
public class SessionDescription {
|
public class SessionDescription {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
private long version;
|
private long version;
|
||||||
private String name;
|
private String name;
|
||||||
private String username;
|
private String username;
|
||||||
private InetAddress ipAddress;
|
|
||||||
|
private InetAddress ipAddress;
|
||||||
private List<MediaDescription> mediaDescriptions;
|
private List<MediaDescription> mediaDescriptions;
|
||||||
private Hashtable<String, String> attributes;
|
private Hashtable<String, String> attributes;
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getIpAddress() {
|
|
||||||
return ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIpAddress(InetAddress ipAddress) {
|
|
||||||
this.ipAddress = ipAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MediaDescription> getMediaDescriptions() {
|
|
||||||
return mediaDescriptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMediaDescriptions(List<MediaDescription> mediaDescriptions) {
|
|
||||||
this.mediaDescriptions = mediaDescriptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(long version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hashtable<String, String> getAttributes() {
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAttributes(Hashtable<String, String> attributes) {
|
|
||||||
this.attributes = attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("v=0\r\n");
|
buf.append("v=0\r\n");
|
||||||
buf.append("o=").append(username).append(" ").append(id);
|
buf.append("o=").append(username).append(" ").append(id);
|
||||||
buf.append(" ").append(version);
|
buf.append(" ").append(version);
|
||||||
@@ -115,7 +64,7 @@ public class SessionDescription {
|
|||||||
for (String attributeName: attributes.keySet()) {
|
for (String attributeName: attributes.keySet()) {
|
||||||
String attributeValue = attributes.get(attributeName);
|
String attributeValue = attributes.get(attributeName);
|
||||||
buf.append("a=").append(attributeName);
|
buf.append("a=").append(attributeName);
|
||||||
if (attributeValue != null && !"".equals(attributeValue.trim())) {
|
if (attributeValue != null && !attributeValue.trim().isEmpty()) {
|
||||||
buf.append(":");
|
buf.append(":");
|
||||||
buf.append(attributeValue);
|
buf.append(attributeValue);
|
||||||
buf.append("\r\n");
|
buf.append("\r\n");
|
||||||
|
|||||||
@@ -32,12 +32,11 @@ public abstract class AbstractState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void log(AbstractState state) {
|
public void log(AbstractState state) {
|
||||||
StringBuffer buf = new StringBuffer();
|
String buf = "SM " + id + " [" +
|
||||||
buf.append("SM ").append(id).append(" [");
|
JavaUtils.getShortClassName(this.getClass()) + " -> " +
|
||||||
buf.append(JavaUtils.getShortClassName(this.getClass())).append(" -> ");
|
JavaUtils.getShortClassName(state.getClass()) + "] " +
|
||||||
buf.append(JavaUtils.getShortClassName(state.getClass())).append("] ");
|
new Exception().getStackTrace()[1].getMethodName();
|
||||||
buf.append(new Exception().getStackTrace()[1].getMethodName());
|
Logger.debug(buf);
|
||||||
Logger.debug(buf.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ import peers.sip.syntaxencoding.SipHeaderFieldValue;
|
|||||||
import peers.sip.syntaxencoding.SipHeaders;
|
import peers.sip.syntaxencoding.SipHeaders;
|
||||||
import peers.sip.transport.SipMessage;
|
import peers.sip.transport.SipMessage;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static final String PEERSHOME_SYSTEM_PROPERTY = "peers.home";
|
public static final String PEERSHOME_SYSTEM_PROPERTY = "peers.home";
|
||||||
public static final String DEFAULT_PEERS_HOME = ".";
|
public static final String DEFAULT_PEERS_HOME = ".";
|
||||||
|
|
||||||
public final static SipHeaderFieldValue getTopVia(SipMessage sipMessage) {
|
public static SipHeaderFieldValue getTopVia(SipMessage sipMessage) {
|
||||||
SipHeaders sipHeaders = sipMessage.getSipHeaders();
|
SipHeaders sipHeaders = sipMessage.getSipHeaders();
|
||||||
SipHeaderFieldName viaName = new SipHeaderFieldName(RFC3261.HDR_VIA);
|
SipHeaderFieldName viaName = new SipHeaderFieldName(RFC3261.HDR_VIA);
|
||||||
SipHeaderFieldValue via = sipHeaders.get(viaName);
|
SipHeaderFieldValue via = sipHeaders.get(viaName);
|
||||||
@@ -45,40 +45,37 @@ public class Utils {
|
|||||||
return via;
|
return via;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String generateTag() {
|
public static String generateTag() {
|
||||||
return randomString(8);
|
return randomString(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String generateCallID(InetAddress inetAddress) {
|
public static String generateCallID(InetAddress inetAddress) {
|
||||||
//TODO make a hash using current time millis, public ip @, private @, and a random string
|
//TODO make a hash using current time millis, public ip @, private @, and a random string
|
||||||
StringBuffer buf = new StringBuffer();
|
return randomString(8) +
|
||||||
buf.append(randomString(8));
|
'-' +
|
||||||
buf.append('-');
|
System.currentTimeMillis() +
|
||||||
buf.append(String.valueOf(System.currentTimeMillis()));
|
'@' +
|
||||||
buf.append('@');
|
inetAddress.getHostName();
|
||||||
buf.append(inetAddress.getHostName());
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String generateBranchId() {
|
public static String generateBranchId() {
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
buf.append(RFC3261.BRANCHID_MAGIC_COOKIE);
|
|
||||||
//TODO must be unique across space and time...
|
//TODO must be unique across space and time...
|
||||||
buf.append(randomString(9));
|
return RFC3261.BRANCHID_MAGIC_COOKIE +
|
||||||
return buf.toString();
|
//TODO must be unique across space and time...
|
||||||
|
randomString(9);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String getMessageCallId(SipMessage sipMessage) {
|
public static String getMessageCallId(SipMessage sipMessage) {
|
||||||
SipHeaderFieldValue callId = sipMessage.getSipHeaders().get(
|
SipHeaderFieldValue callId = sipMessage.getSipHeaders().get(
|
||||||
new SipHeaderFieldName(RFC3261.HDR_CALLID));
|
new SipHeaderFieldName(RFC3261.HDR_CALLID));
|
||||||
return callId.getValue();
|
return callId.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String randomString(int length) {
|
public static String randomString(int length) {
|
||||||
String chars = "abcdefghijklmnopqrstuvwxyz" +
|
String chars = "abcdefghijklmnopqrstuvwxyz" +
|
||||||
"ABCDEFGHIFKLMNOPRSTUVWXYZ" +
|
"ABCDEFGHIFKLMNOPRSTUVWXYZ" +
|
||||||
"0123456789";
|
"0123456789";
|
||||||
StringBuffer buf = new StringBuffer(length);
|
StringBuilder buf = new StringBuilder(length);
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
int pos = (int)Math.round(Math.random() * (chars.length() - 1));
|
int pos = (int)Math.round(Math.random() * (chars.length() - 1));
|
||||||
buf.append(chars.charAt(pos));
|
buf.append(chars.charAt(pos));
|
||||||
@@ -86,7 +83,7 @@ public class Utils {
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static void copyHeader(SipMessage src, SipMessage dst, String name) {
|
public static void copyHeader(SipMessage src, SipMessage dst, String name) {
|
||||||
SipHeaderFieldName sipHeaderFieldName = new SipHeaderFieldName(name);
|
SipHeaderFieldName sipHeaderFieldName = new SipHeaderFieldName(name);
|
||||||
SipHeaderFieldValue sipHeaderFieldValue = src.getSipHeaders().get(sipHeaderFieldName);
|
SipHeaderFieldValue sipHeaderFieldValue = src.getSipHeaders().get(sipHeaderFieldName);
|
||||||
if (sipHeaderFieldValue != null) {
|
if (sipHeaderFieldValue != null) {
|
||||||
@@ -94,7 +91,7 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String getUserPart(String sipUri) {
|
public static String getUserPart(String sipUri) {
|
||||||
int start = sipUri.indexOf(RFC3261.SCHEME_SEPARATOR);
|
int start = sipUri.indexOf(RFC3261.SCHEME_SEPARATOR);
|
||||||
int end = sipUri.indexOf(RFC3261.AT);
|
int end = sipUri.indexOf(RFC3261.AT);
|
||||||
return sipUri.substring(start + 1, end);
|
return sipUri.substring(start + 1, end);
|
||||||
@@ -102,9 +99,9 @@ public class Utils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* adds Max-Forwards Supported and Require headers
|
* adds Max-Forwards Supported and Require headers
|
||||||
* @param headers
|
* @param headers the headers to add to
|
||||||
*/
|
*/
|
||||||
public final static void addCommonHeaders(SipHeaders headers) {
|
public static void addCommonHeaders(SipHeaders headers) {
|
||||||
//Max-Forwards
|
//Max-Forwards
|
||||||
|
|
||||||
headers.add(new SipHeaderFieldName(RFC3261.HDR_MAX_FORWARDS),
|
headers.add(new SipHeaderFieldName(RFC3261.HDR_MAX_FORWARDS),
|
||||||
@@ -114,8 +111,8 @@ public class Utils {
|
|||||||
//TODO Supported and Require
|
//TODO Supported and Require
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String generateAllowHeader() {
|
public static String generateAllowHeader() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
for (String supportedMethod: UAS.SUPPORTED_METHODS) {
|
for (String supportedMethod: UAS.SUPPORTED_METHODS) {
|
||||||
buf.append(supportedMethod);
|
buf.append(supportedMethod);
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
|
|||||||
@@ -23,5 +23,5 @@ import peers.sip.transport.SipMessage;
|
|||||||
|
|
||||||
public interface MessageInterceptor {
|
public interface MessageInterceptor {
|
||||||
|
|
||||||
public void postProcess(SipMessage sipMessage);
|
void postProcess(SipMessage sipMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,28 +19,24 @@
|
|||||||
|
|
||||||
package peers.sip.core.useragent;
|
package peers.sip.core.useragent;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import peers.sip.transport.SipMessage;
|
import peers.sip.transport.SipMessage;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class SipEvent {
|
public class SipEvent {
|
||||||
|
|
||||||
public enum EventType {
|
public enum EventType {
|
||||||
ERROR, RINGING, INCOMING_CALL, CALLEE_PICKUP;
|
ERROR, RINGING, INCOMING_CALL, CALLEE_PICKUP
|
||||||
}
|
}
|
||||||
|
|
||||||
private EventType eventType;
|
@Getter private final EventType eventType;
|
||||||
private SipMessage sipMessage;
|
@Getter private final SipMessage sipMessage;
|
||||||
|
|
||||||
public SipEvent(EventType type, SipMessage sipMessage) {
|
public SipEvent(EventType type, SipMessage sipMessage) {
|
||||||
this.eventType = type;
|
this.eventType = type;
|
||||||
this.sipMessage = sipMessage;
|
this.sipMessage = sipMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SipMessage getSipMessage() {
|
|
||||||
return sipMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventType getEventType() {
|
|
||||||
return eventType;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,20 +25,20 @@ import peers.sip.transport.SipResponse;
|
|||||||
|
|
||||||
public interface SipListener {
|
public interface SipListener {
|
||||||
|
|
||||||
public void registering(SipRequest sipRequest);
|
void registering(SipRequest sipRequest);
|
||||||
|
|
||||||
public void registerSuccessful(SipResponse sipResponse);
|
void registerSuccessful(SipResponse sipResponse);
|
||||||
|
|
||||||
public void registerFailed(SipResponse sipResponse);
|
void registerFailed(SipResponse sipResponse);
|
||||||
|
|
||||||
public void incomingCall(SipRequest sipRequest, SipResponse provResponse);
|
void incomingCall(SipRequest sipRequest, SipResponse provResponse);
|
||||||
|
|
||||||
public void remoteHangup(SipRequest sipRequest);
|
void remoteHangup(SipRequest sipRequest);
|
||||||
|
|
||||||
public void ringing(SipResponse sipResponse);
|
void ringing(SipResponse sipResponse);
|
||||||
|
|
||||||
public void calleePickup(SipResponse sipResponse);
|
void calleePickup(SipResponse sipResponse);
|
||||||
|
|
||||||
public void error(SipResponse sipResponse);
|
void error(SipResponse sipResponse);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package peers.sip.syntaxencoding;
|
package peers.sip.syntaxencoding;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class RunnableSipParser implements Runnable {
|
public class RunnableSipParser implements Runnable {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -19,10 +19,14 @@
|
|||||||
|
|
||||||
package peers.sip.syntaxencoding;
|
package peers.sip.syntaxencoding;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class SipHeader {
|
public class SipHeader {
|
||||||
|
|
||||||
private SipHeaderFieldName name;
|
private final SipHeaderFieldName name;
|
||||||
private SipHeaderFieldValue value;
|
private @Setter SipHeaderFieldValue value;
|
||||||
|
|
||||||
SipHeader(SipHeaderFieldName name, SipHeaderFieldValue value) {
|
SipHeader(SipHeaderFieldName name, SipHeaderFieldValue value) {
|
||||||
super();
|
super();
|
||||||
@@ -39,16 +43,4 @@ public class SipHeader {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SipHeaderFieldName getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SipHeaderFieldValue getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(SipHeaderFieldValue value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,13 @@
|
|||||||
|
|
||||||
package peers.sip.syntaxencoding;
|
package peers.sip.syntaxencoding;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SipHeaderFieldMultiValue extends SipHeaderFieldValue {
|
public class SipHeaderFieldMultiValue extends SipHeaderFieldValue {
|
||||||
|
|
||||||
private List<SipHeaderFieldValue> values;
|
@Getter private final List<SipHeaderFieldValue> values;
|
||||||
|
|
||||||
private static String toString(List<SipHeaderFieldValue> list) {
|
private static String toString(List<SipHeaderFieldValue> list) {
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
@@ -38,9 +40,6 @@ public class SipHeaderFieldMultiValue extends SipHeaderFieldValue {
|
|||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SipHeaderFieldValue> getValues() {
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -19,12 +19,14 @@
|
|||||||
|
|
||||||
package peers.sip.syntaxencoding;
|
package peers.sip.syntaxencoding;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class SipHeaderFieldName {
|
public class SipHeaderFieldName {
|
||||||
|
|
||||||
private final static SipHeadersTable SIP_HEADER_TABLE =
|
private final static SipHeadersTable SIP_HEADER_TABLE =
|
||||||
new SipHeadersTable();
|
new SipHeadersTable();
|
||||||
|
|
||||||
private String name;
|
@Getter private final String name;
|
||||||
|
|
||||||
public SipHeaderFieldName(String name) {
|
public SipHeaderFieldName(String name) {
|
||||||
super();
|
super();
|
||||||
@@ -41,10 +43,7 @@ public class SipHeaderFieldName {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String objName = ((SipHeaderFieldName)obj).getName();
|
String objName = ((SipHeaderFieldName)obj).getName();
|
||||||
if (name.equalsIgnoreCase(objName)) {
|
return name.equalsIgnoreCase(objName);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,10 +51,6 @@ public class SipHeaderFieldName {
|
|||||||
return name.hashCode();
|
return name.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
@@ -21,14 +21,16 @@ package peers.sip.syntaxencoding;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
|
|
||||||
|
|
||||||
public class SipHeaderFieldValue {
|
public class SipHeaderFieldValue {
|
||||||
|
|
||||||
private String value;
|
@Getter @Setter private String value;
|
||||||
|
|
||||||
private HashMap<SipHeaderParamName, String> params;
|
private final HashMap<SipHeaderParamName, String> params;
|
||||||
|
|
||||||
public SipHeaderFieldValue(String value) {
|
public SipHeaderFieldValue(String value) {
|
||||||
int startPos = value.indexOf(RFC3261.RIGHT_ANGLE_BRACKET);
|
int startPos = value.indexOf(RFC3261.RIGHT_ANGLE_BRACKET);
|
||||||
@@ -46,7 +48,7 @@ public class SipHeaderFieldValue {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
paramsString = "";
|
paramsString = "";
|
||||||
}
|
}
|
||||||
params = new HashMap<SipHeaderParamName, String>();
|
params = new HashMap<>();
|
||||||
if (paramsString.contains(RFC3261.PARAM_SEPARATOR)) {
|
if (paramsString.contains(RFC3261.PARAM_SEPARATOR)) {
|
||||||
String[] arr = paramsString.split(RFC3261.PARAM_SEPARATOR);
|
String[] arr = paramsString.split(RFC3261.PARAM_SEPARATOR);
|
||||||
if (arr.length > 1) {
|
if (arr.length > 1) {
|
||||||
@@ -76,24 +78,18 @@ public class SipHeaderFieldValue {
|
|||||||
params.remove(name);
|
params.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (params == null || params.isEmpty()) {
|
if (params == null || params.isEmpty()) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
StringBuffer buf = new StringBuffer(value);
|
StringBuilder buf = new StringBuilder(value);
|
||||||
for (SipHeaderParamName name: params.keySet()) {
|
for (SipHeaderParamName name: params.keySet()) {
|
||||||
buf.append(RFC3261.PARAM_SEPARATOR).append(name);
|
buf.append(RFC3261.PARAM_SEPARATOR).append(name);
|
||||||
String value = params.get(name);
|
String value = params.get(name);
|
||||||
if (!"".equals(value.trim())) {
|
if (!value.trim().isEmpty()) {
|
||||||
buf.append(RFC3261.PARAM_ASSIGNMENT).append(value);
|
buf.append(RFC3261.PARAM_ASSIGNMENT).append(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,19 +19,17 @@
|
|||||||
|
|
||||||
package peers.sip.syntaxencoding;
|
package peers.sip.syntaxencoding;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class SipHeaderParamName {
|
public class SipHeaderParamName {
|
||||||
|
|
||||||
private String name;
|
@Getter private String name;
|
||||||
|
|
||||||
public SipHeaderParamName(String name) {
|
public SipHeaderParamName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
|
|||||||
@@ -24,19 +24,19 @@ import java.util.ArrayList;
|
|||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class SipHeaders {
|
public class SipHeaders {
|
||||||
|
|
||||||
private ArrayList<SipHeader> headers;
|
private final ArrayList<SipHeader> headers;
|
||||||
|
|
||||||
public SipHeaders() {
|
public SipHeaders() {
|
||||||
headers = new ArrayList<SipHeader>();
|
headers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name SipHeaderFieldName
|
||||||
* @param value
|
* @param value SipHeaderFieldValue
|
||||||
* @param index -1 to add at the end
|
* @param index -1 to add at the end
|
||||||
*/
|
*/
|
||||||
public void add(SipHeaderFieldName name, SipHeaderFieldValue value, int index) {
|
public void add(SipHeaderFieldName name, SipHeaderFieldValue value, int index) {
|
||||||
@@ -49,7 +49,7 @@ public class SipHeaders {
|
|||||||
SipHeaderFieldMultiValue oldMultiVal = (SipHeaderFieldMultiValue) oldValue;
|
SipHeaderFieldMultiValue oldMultiVal = (SipHeaderFieldMultiValue) oldValue;
|
||||||
oldMultiVal.getValues().add(value);
|
oldMultiVal.getValues().add(value);
|
||||||
} else {
|
} else {
|
||||||
ArrayList<SipHeaderFieldValue> arr = new ArrayList<SipHeaderFieldValue>();
|
ArrayList<SipHeaderFieldValue> arr = new ArrayList<>();
|
||||||
arr.add(oldValue);
|
arr.add(oldValue);
|
||||||
arr.add(value);
|
arr.add(value);
|
||||||
header.setValue(new SipHeaderFieldMultiValue(arr));
|
header.setValue(new SipHeaderFieldMultiValue(arr));
|
||||||
@@ -90,7 +90,7 @@ public class SipHeaders {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
for (SipHeader header : headers) {
|
for (SipHeader header : headers) {
|
||||||
buf.append(header.getName().toString());
|
buf.append(header.getName().toString());
|
||||||
buf.append(": ");
|
buf.append(": ");
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ import peers.sip.RFC3261;
|
|||||||
|
|
||||||
public class SipHeadersTable {
|
public class SipHeadersTable {
|
||||||
|
|
||||||
private HashMap<Character, String> headers;
|
private final HashMap<Character, String> headers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* should be instanciated only once, it was a singleton.
|
* should be instanciated only once, it was a singleton.
|
||||||
*/
|
*/
|
||||||
public SipHeadersTable() {
|
public SipHeadersTable() {
|
||||||
headers = new HashMap<Character, String>();
|
headers = new HashMap<>();
|
||||||
//RFC 3261 Section 10
|
//RFC 3261 Section 10
|
||||||
headers.put(RFC3261.COMPACT_HDR_CALLID, RFC3261.HDR_CALLID);
|
headers.put(RFC3261.COMPACT_HDR_CALLID, RFC3261.HDR_CALLID);
|
||||||
headers.put(RFC3261.COMPACT_HDR_CONTACT, RFC3261.HDR_CONTACT);
|
headers.put(RFC3261.COMPACT_HDR_CONTACT, RFC3261.HDR_CONTACT);
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ public class SipParser {
|
|||||||
|
|
||||||
private final static int BUFF_SIZE = 1024;
|
private final static int BUFF_SIZE = 1024;
|
||||||
|
|
||||||
private List<SipHeaderFieldName> singleValueHeaders;
|
private final List<SipHeaderFieldName> singleValueHeaders;
|
||||||
|
|
||||||
public SipParser() {
|
public SipParser() {
|
||||||
singleValueHeaders = new ArrayList<SipHeaderFieldName>();
|
singleValueHeaders = new ArrayList<>();
|
||||||
singleValueHeaders.add(new SipHeaderFieldName(
|
singleValueHeaders.add(new SipHeaderFieldName(
|
||||||
RFC3261.HDR_WWW_AUTHENTICATE));
|
RFC3261.HDR_WWW_AUTHENTICATE));
|
||||||
singleValueHeaders.add(new SipHeaderFieldName(
|
singleValueHeaders.add(new SipHeaderFieldName(
|
||||||
@@ -63,7 +63,7 @@ public class SipParser {
|
|||||||
reader = new BufferedReader(inputStreamReader);
|
reader = new BufferedReader(inputStreamReader);
|
||||||
|
|
||||||
String startLine = reader.readLine();
|
String startLine = reader.readLine();
|
||||||
while (startLine == null || startLine.equals("")) {
|
while (startLine == null || startLine.isEmpty()) {
|
||||||
startLine = reader.readLine();
|
startLine = reader.readLine();
|
||||||
}
|
}
|
||||||
SipMessage sipMessage;
|
SipMessage sipMessage;
|
||||||
@@ -83,7 +83,7 @@ public class SipParser {
|
|||||||
if (params.length != 3) {
|
if (params.length != 3) {
|
||||||
throw new SipParserException("invalid request line");
|
throw new SipParserException("invalid request line");
|
||||||
}
|
}
|
||||||
if (!RFC3261.DEFAULT_SIP_VERSION.equals(params[2].toUpperCase())) {
|
if (!RFC3261.DEFAULT_SIP_VERSION.equalsIgnoreCase(params[2])) {
|
||||||
throw new SipParserException("unsupported SIP version");
|
throw new SipParserException("unsupported SIP version");
|
||||||
}
|
}
|
||||||
SipURI requestUri;
|
SipURI requestUri;
|
||||||
@@ -100,10 +100,10 @@ public class SipParser {
|
|||||||
if (params.length < 3) {
|
if (params.length < 3) {
|
||||||
throw new SipParserException("incorrect status line");
|
throw new SipParserException("incorrect status line");
|
||||||
}
|
}
|
||||||
if (!RFC3261.DEFAULT_SIP_VERSION.equals(params[0].toUpperCase())) {
|
if (!RFC3261.DEFAULT_SIP_VERSION.equalsIgnoreCase(params[0])) {
|
||||||
throw new SipParserException("unsupported SIP version");
|
throw new SipParserException("unsupported SIP version");
|
||||||
}
|
}
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
for (int i = 2; i < params.length; ++i) {
|
for (int i = 2; i < params.length; ++i) {
|
||||||
buf.append(params[i]).append(" ");
|
buf.append(params[i]).append(" ");
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ public class SipParser {
|
|||||||
String nextLine = reader.readLine();
|
String nextLine = reader.readLine();
|
||||||
if (nextLine != null &&
|
if (nextLine != null &&
|
||||||
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))) {
|
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))) {
|
||||||
StringBuffer buf = new StringBuffer(headerLine);
|
StringBuilder buf = new StringBuilder(headerLine);
|
||||||
while (nextLine != null &&
|
while (nextLine != null &&
|
||||||
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))) {
|
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))) {
|
||||||
buf.append(' ');
|
buf.append(' ');
|
||||||
@@ -142,10 +142,10 @@ public class SipParser {
|
|||||||
String value = headerLine.substring(columnPos + 1).trim();
|
String value = headerLine.substring(columnPos + 1).trim();
|
||||||
SipHeaderFieldValue sipHeaderValue;
|
SipHeaderFieldValue sipHeaderValue;
|
||||||
if (!singleValueHeaders.contains(sipHeaderName) &&
|
if (!singleValueHeaders.contains(sipHeaderName) &&
|
||||||
value.indexOf(RFC3261.HEADER_SEPARATOR) > -1) {
|
value.contains(RFC3261.HEADER_SEPARATOR)) {
|
||||||
String[] values = value.split(RFC3261.HEADER_SEPARATOR);
|
String[] values = value.split(RFC3261.HEADER_SEPARATOR);
|
||||||
List<SipHeaderFieldValue> list =
|
List<SipHeaderFieldValue> list =
|
||||||
new ArrayList<SipHeaderFieldValue>();
|
new ArrayList<>();
|
||||||
for (String s: values) {
|
for (String s: values) {
|
||||||
list.add(new SipHeaderFieldValue(s));
|
list.add(new SipHeaderFieldValue(s));
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ public class SipParser {
|
|||||||
sipMessage.setSipHeaders(sipHeaders);
|
sipMessage.setSipHeaders(sipHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseBody(SipMessage sipMessage) throws IOException, SipParserException {
|
public void parseBody(SipMessage sipMessage) throws IOException {
|
||||||
SipHeaderFieldValue contentLengthValue =
|
SipHeaderFieldValue contentLengthValue =
|
||||||
sipMessage.getSipHeaders().get(new SipHeaderFieldName(
|
sipMessage.getSipHeaders().get(new SipHeaderFieldName(
|
||||||
RFC3261.HDR_CONTENT_LENGTH));
|
RFC3261.HDR_CONTENT_LENGTH));
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package peers.sip.syntaxencoding;
|
package peers.sip.syntaxencoding;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class SipParserException extends Exception {
|
public class SipParserException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package peers.sip.syntaxencoding;
|
|||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,24 +30,24 @@ public class SipURI {
|
|||||||
|
|
||||||
public final static int DEFAULT_PORT = -1;
|
public final static int DEFAULT_PORT = -1;
|
||||||
|
|
||||||
private String stringRepresentation;
|
private final String stringRepresentation;
|
||||||
/**
|
/**
|
||||||
* telephone-subscriber and optional port are not managed
|
* telephone-subscriber and optional port are not managed
|
||||||
*/
|
*/
|
||||||
private String userinfo;
|
@Getter private String userinfo;
|
||||||
private String host;
|
@Getter private final String host;
|
||||||
private int port = DEFAULT_PORT;
|
@Getter private int port = DEFAULT_PORT;
|
||||||
/**
|
/**
|
||||||
* Use empty strings in value if the parameter has no value
|
* Use empty strings in value if the parameter has no value
|
||||||
*/
|
*/
|
||||||
private Hashtable<String, String> uriParameters;
|
@Getter private Hashtable<String, String> uriParameters;
|
||||||
//headers not implemented
|
//headers not implemented
|
||||||
//private Hashtable<String, String> headers;
|
//private Hashtable<String, String> headers;
|
||||||
|
|
||||||
public SipURI(String sipUri)
|
public SipURI(String sipUri)
|
||||||
throws SipUriSyntaxException {
|
throws SipUriSyntaxException {
|
||||||
stringRepresentation = sipUri;
|
stringRepresentation = sipUri;
|
||||||
StringBuffer buf = new StringBuffer(sipUri);
|
StringBuilder buf = new StringBuilder(sipUri);
|
||||||
String scheme = RFC3261.SIP_SCHEME + RFC3261.SCHEME_SEPARATOR;
|
String scheme = RFC3261.SIP_SCHEME + RFC3261.SCHEME_SEPARATOR;
|
||||||
if (!sipUri.startsWith(scheme)) {
|
if (!sipUri.startsWith(scheme)) {
|
||||||
throw new SipUriSyntaxException("SIP URI must start with " + scheme);
|
throw new SipUriSyntaxException("SIP URI must start with " + scheme);
|
||||||
@@ -87,7 +88,7 @@ public class SipURI {
|
|||||||
if (buf.length() <= 0) {
|
if (buf.length() <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uriParameters = new Hashtable<String, String>();
|
uriParameters = new Hashtable<>();
|
||||||
while (buf.length() > 0) {
|
while (buf.length() > 0) {
|
||||||
buf.deleteCharAt(0);//delete the first ';'
|
buf.deleteCharAt(0);//delete the first ';'
|
||||||
int nextSemicolon = buf.indexOf(";");
|
int nextSemicolon = buf.indexOf(";");
|
||||||
@@ -117,20 +118,4 @@ public class SipURI {
|
|||||||
return stringRepresentation;
|
return stringRepresentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hashtable<String, String> getUriParameters() {
|
|
||||||
return uriParameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserinfo() {
|
|
||||||
return userinfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ package peers.sip.transaction;
|
|||||||
import peers.sip.transport.SipResponse;
|
import peers.sip.transport.SipResponse;
|
||||||
|
|
||||||
public interface ClientTransactionUser {
|
public interface ClientTransactionUser {
|
||||||
public void transactionTimeout(ClientTransaction clientTransaction);
|
void transactionTimeout(ClientTransaction clientTransaction);
|
||||||
public void provResponseReceived(SipResponse sipResponse, Transaction transaction);
|
void provResponseReceived(SipResponse sipResponse, Transaction transaction);
|
||||||
//TODO eventually pass transaction to the transaction user
|
//TODO eventually pass transaction to the transaction user
|
||||||
public void errResponseReceived(SipResponse sipResponse);//3XX is considered as an error response
|
void errResponseReceived(SipResponse sipResponse);//3XX is considered as an error response
|
||||||
public void successResponseReceived(SipResponse sipResponse, Transaction transaction);
|
void successResponseReceived(SipResponse sipResponse, Transaction transaction);
|
||||||
public void transactionTransportError();
|
void transactionTransportError();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import peers.sip.transport.SipResponse;
|
|||||||
|
|
||||||
public interface ServerTransaction {
|
public interface ServerTransaction {
|
||||||
|
|
||||||
public void start();
|
void start();
|
||||||
|
|
||||||
public void receivedRequest(SipRequest sipRequest);
|
void receivedRequest(SipRequest sipRequest);
|
||||||
|
|
||||||
public void sendReponse(SipResponse sipResponse);
|
void sendReponse(SipResponse sipResponse);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ package peers.sip.transaction;
|
|||||||
|
|
||||||
public interface ServerTransactionUser {
|
public interface ServerTransactionUser {
|
||||||
|
|
||||||
public void transactionFailure();
|
void transactionFailure();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,14 @@
|
|||||||
|
|
||||||
package peers.sip.transaction;
|
package peers.sip.transaction;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Getter
|
||||||
public class SipListeningPoint {
|
public class SipListeningPoint {
|
||||||
|
|
||||||
private int localPort;
|
private final int localPort;
|
||||||
private String localTransport;
|
private final String localTransport;
|
||||||
|
|
||||||
public SipListeningPoint(int localPort, String localTransport) {
|
public SipListeningPoint(int localPort, String localTransport) {
|
||||||
super();
|
super();
|
||||||
@@ -43,9 +46,7 @@ public class SipListeningPoint {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
return ":" + localPort + '/' + localTransport;
|
||||||
buf.append(':').append(localPort).append('/').append(localTransport);
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,12 +54,4 @@ public class SipListeningPoint {
|
|||||||
return toString().hashCode();
|
return toString().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getlocalPort() {
|
|
||||||
return localPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getlocalTransport() {
|
|
||||||
return localTransport;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ import peers.sip.transport.SipResponse;
|
|||||||
|
|
||||||
public class DialogManager {
|
public class DialogManager {
|
||||||
|
|
||||||
private Hashtable<String, Dialog> dialogs;
|
private final Hashtable<String, Dialog> dialogs;
|
||||||
|
|
||||||
|
|
||||||
public DialogManager() {
|
public DialogManager() {
|
||||||
dialogs = new Hashtable<String, Dialog>();
|
dialogs = new Hashtable<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,13 +100,11 @@ public class DialogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getDialogId(String callID, String localTag, String remoteTag) {
|
private String getDialogId(String callID, String localTag, String remoteTag) {
|
||||||
StringBuffer buf = new StringBuffer();
|
return callID +
|
||||||
buf.append(callID);
|
Dialog.ID_SEPARATOR +
|
||||||
buf.append(Dialog.ID_SEPARATOR);
|
localTag +
|
||||||
buf.append(localTag);
|
Dialog.ID_SEPARATOR +
|
||||||
buf.append(Dialog.ID_SEPARATOR);
|
remoteTag;
|
||||||
buf.append(remoteTag);
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Dialog> getDialogCollection() {
|
public Collection<Dialog> getDialogCollection() {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.net.InetAddress;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
import peers.Config;
|
import peers.Config;
|
||||||
|
|
||||||
@@ -36,10 +37,10 @@ public abstract class MessageSender {
|
|||||||
|
|
||||||
protected InetAddress inetAddress;
|
protected InetAddress inetAddress;
|
||||||
protected int port;
|
protected int port;
|
||||||
protected int localPort;
|
@Getter protected int localPort;
|
||||||
private Config config;
|
private final Config config;
|
||||||
private String transportName;
|
private final String transportName;
|
||||||
private Timer timer;
|
private final Timer timer;
|
||||||
|
|
||||||
public MessageSender(int localPort, InetAddress inetAddress,
|
public MessageSender(int localPort, InetAddress inetAddress,
|
||||||
int port, Config config,
|
int port, Config config,
|
||||||
@@ -61,7 +62,7 @@ public abstract class MessageSender {
|
|||||||
public abstract void sendBytes(byte[] bytes) throws IOException;
|
public abstract void sendBytes(byte[] bytes) throws IOException;
|
||||||
|
|
||||||
public String getContact() {
|
public String getContact() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
InetAddress myAddress = config.getPublicInetAddress();
|
InetAddress myAddress = config.getPublicInetAddress();
|
||||||
if (myAddress == null) {
|
if (myAddress == null) {
|
||||||
myAddress = config.getLocalInetAddress();
|
myAddress = config.getLocalInetAddress();
|
||||||
@@ -77,9 +78,7 @@ public abstract class MessageSender {
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLocalPort() {
|
|
||||||
return localPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopKeepAlives() {
|
public void stopKeepAlives() {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
package peers.sip.transport;
|
package peers.sip.transport;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public interface SipClientTransportUser {
|
public interface SipClientTransportUser {
|
||||||
|
|
||||||
public void requestTransportError(SipRequest sipRequest, Exception e);
|
void requestTransportError(SipRequest sipRequest, Exception e);
|
||||||
public void responseTransportError(Exception e);
|
void responseTransportError(Exception e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,18 @@
|
|||||||
|
|
||||||
package peers.sip.transport;
|
package peers.sip.transport;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
import peers.sip.syntaxencoding.SipHeaderFieldName;
|
import peers.sip.syntaxencoding.SipHeaderFieldName;
|
||||||
import peers.sip.syntaxencoding.SipHeaderFieldValue;
|
import peers.sip.syntaxencoding.SipHeaderFieldValue;
|
||||||
import peers.sip.syntaxencoding.SipHeaders;
|
import peers.sip.syntaxencoding.SipHeaders;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public abstract class SipMessage {
|
public abstract class SipMessage {
|
||||||
|
|
||||||
protected String sipVersion;
|
protected String sipVersion;
|
||||||
protected SipHeaders sipHeaders;
|
@Setter protected SipHeaders sipHeaders;
|
||||||
protected byte[] body;
|
protected byte[] body;
|
||||||
|
|
||||||
public SipMessage() {
|
public SipMessage() {
|
||||||
@@ -35,22 +38,6 @@ public abstract class SipMessage {
|
|||||||
sipHeaders = new SipHeaders();
|
sipHeaders = new SipHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSipVersion() {
|
|
||||||
return sipVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSipHeaders(SipHeaders sipHeaders) {
|
|
||||||
this.sipHeaders = sipHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SipHeaders getSipHeaders() {
|
|
||||||
return sipHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBody(byte[] body) {
|
public void setBody(byte[] body) {
|
||||||
SipHeaderFieldName contentLengthName =
|
SipHeaderFieldName contentLengthName =
|
||||||
new SipHeaderFieldName(RFC3261.HDR_CONTENT_LENGTH);
|
new SipHeaderFieldName(RFC3261.HDR_CONTENT_LENGTH);
|
||||||
@@ -68,7 +55,7 @@ public abstract class SipMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append(sipHeaders.toString());
|
buf.append(sipHeaders.toString());
|
||||||
buf.append(RFC3261.CRLF);
|
buf.append(RFC3261.CRLF);
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
|
|||||||
@@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
package peers.sip.transport;
|
package peers.sip.transport;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
import peers.sip.syntaxencoding.SipURI;
|
import peers.sip.syntaxencoding.SipURI;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class SipRequest extends SipMessage {
|
public class SipRequest extends SipMessage {
|
||||||
protected String method;
|
protected String method;
|
||||||
protected SipURI requestUri;
|
protected SipURI requestUri;
|
||||||
@@ -35,19 +37,9 @@ public class SipRequest extends SipMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
return method + ' ' + requestUri +
|
||||||
buf.append(method).append(' ').append(requestUri).append(
|
' ' + RFC3261.DEFAULT_SIP_VERSION + RFC3261.CRLF +
|
||||||
' ').append(RFC3261.DEFAULT_SIP_VERSION).append(RFC3261.CRLF);
|
super.toString();
|
||||||
buf.append(super.toString());
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMethod() {
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SipURI getRequestUri() {
|
|
||||||
return requestUri;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,10 @@
|
|||||||
|
|
||||||
package peers.sip.transport;
|
package peers.sip.transport;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class SipResponse extends SipMessage {
|
public class SipResponse extends SipMessage {
|
||||||
protected int statusCode;
|
protected int statusCode;
|
||||||
protected String reasonPhrase;
|
protected String reasonPhrase;
|
||||||
@@ -32,19 +34,9 @@ public class SipResponse extends SipMessage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer();
|
return RFC3261.DEFAULT_SIP_VERSION + ' ' + statusCode +
|
||||||
buf.append(RFC3261.DEFAULT_SIP_VERSION).append(' ').append(statusCode
|
' ' + reasonPhrase + RFC3261.CRLF +
|
||||||
).append(' ').append(reasonPhrase).append(RFC3261.CRLF);
|
super.toString();
|
||||||
buf.append(super.toString());
|
|
||||||
return buf.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatusCode() {
|
|
||||||
return statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReasonPhrase() {
|
|
||||||
return reasonPhrase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ package peers.sip.transport;
|
|||||||
|
|
||||||
public interface SipServerTransportUser {
|
public interface SipServerTransportUser {
|
||||||
|
|
||||||
public void messageReceived(SipMessage sipMessage);
|
void messageReceived(SipMessage sipMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,19 +21,20 @@ package peers.sip.transport;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import peers.sip.RFC3261;
|
import peers.sip.RFC3261;
|
||||||
|
|
||||||
public class SipTransportConnection {
|
public class SipTransportConnection {
|
||||||
|
|
||||||
public static final int EMPTY_PORT = -1;
|
public static final int EMPTY_PORT = -1;
|
||||||
|
|
||||||
private InetAddress localInetAddress;
|
@Getter private final InetAddress localInetAddress;
|
||||||
private int localPort = EMPTY_PORT;
|
@Getter private int localPort = EMPTY_PORT;
|
||||||
|
|
||||||
private InetAddress remoteInetAddress;
|
@Getter private final InetAddress remoteInetAddress;
|
||||||
private int remotePort = EMPTY_PORT;
|
@Getter private int remotePort = EMPTY_PORT;
|
||||||
|
|
||||||
private String transport;// UDP, TCP or SCTP
|
@Getter private final String transport;// UDP, TCP or SCTP
|
||||||
|
|
||||||
public SipTransportConnection(InetAddress localInetAddress,
|
public SipTransportConnection(InetAddress localInetAddress,
|
||||||
int localPort, InetAddress remoteInetAddress, int remotePort,
|
int localPort, InetAddress remoteInetAddress, int remotePort,
|
||||||
@@ -99,25 +100,5 @@ public class SipTransportConnection {
|
|||||||
return toString().hashCode();
|
return toString().hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetAddress getLocalInetAddress() {
|
|
||||||
return localInetAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLocalPort() {
|
|
||||||
return localPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InetAddress getRemoteInetAddress() {
|
|
||||||
return remoteInetAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRemotePort() {
|
|
||||||
return remotePort;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTransport() {
|
|
||||||
return transport;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package peers.sip.transport;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.SocketException;
|
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
@@ -36,12 +35,11 @@ import peers.sip.transaction.TransactionManager;
|
|||||||
|
|
||||||
public class UdpMessageReceiver extends MessageReceiver {
|
public class UdpMessageReceiver extends MessageReceiver {
|
||||||
|
|
||||||
private DatagramSocket datagramSocket;
|
private final DatagramSocket datagramSocket;
|
||||||
|
|
||||||
public UdpMessageReceiver(DatagramSocket datagramSocket,
|
public UdpMessageReceiver(DatagramSocket datagramSocket,
|
||||||
TransactionManager transactionManager,
|
TransactionManager transactionManager,
|
||||||
TransportManager transportManager, Config config)
|
TransportManager transportManager, Config config) {
|
||||||
throws SocketException {
|
|
||||||
super(datagramSocket.getLocalPort(), transactionManager,
|
super(datagramSocket.getLocalPort(), transactionManager,
|
||||||
transportManager, config);
|
transportManager, config);
|
||||||
this.datagramSocket = datagramSocket;
|
this.datagramSocket = datagramSocket;
|
||||||
@@ -56,8 +54,7 @@ public class UdpMessageReceiver extends MessageReceiver {
|
|||||||
final int ioException = 2;
|
final int ioException = 2;
|
||||||
// AccessController.doPrivileged added for plugin compatibility
|
// AccessController.doPrivileged added for plugin compatibility
|
||||||
int result = AccessController.doPrivileged(
|
int result = AccessController.doPrivileged(
|
||||||
new PrivilegedAction<Integer>() {
|
(PrivilegedAction<Integer>) () -> {
|
||||||
public Integer run() {
|
|
||||||
try {
|
try {
|
||||||
datagramSocket.receive(packet);
|
datagramSocket.receive(packet);
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
@@ -67,15 +64,12 @@ public class UdpMessageReceiver extends MessageReceiver {
|
|||||||
return ioException;
|
return ioException;
|
||||||
}
|
}
|
||||||
return noException;
|
return noException;
|
||||||
}
|
});
|
||||||
});
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case socketTimeoutException:
|
case socketTimeoutException:
|
||||||
return;
|
return;
|
||||||
case ioException:
|
case ioException:
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
case noException:
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,9 @@
|
|||||||
|
|
||||||
package peers.sip.transport;
|
package peers.sip.transport;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
@@ -35,31 +33,30 @@ import peers.sip.RFC3261;
|
|||||||
|
|
||||||
public class UdpMessageSender extends MessageSender {
|
public class UdpMessageSender extends MessageSender {
|
||||||
|
|
||||||
private DatagramSocket datagramSocket;
|
private final DatagramSocket datagramSocket;
|
||||||
|
|
||||||
public UdpMessageSender(InetAddress inetAddress, int port,
|
public UdpMessageSender(InetAddress inetAddress, int port,
|
||||||
DatagramSocket datagramSocket, Config config) throws SocketException {
|
DatagramSocket datagramSocket, Config config) {
|
||||||
super(datagramSocket.getLocalPort(), inetAddress, port,
|
super(datagramSocket.getLocalPort(), inetAddress, port,
|
||||||
config, RFC3261.TRANSPORT_UDP);
|
config, RFC3261.TRANSPORT_UDP);
|
||||||
this.datagramSocket = datagramSocket;
|
this.datagramSocket = datagramSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void sendMessage(SipMessage sipMessage) throws IOException {
|
public synchronized void sendMessage(SipMessage sipMessage) {
|
||||||
Logger.debug("UdpMessageSender.sendMessage");
|
Logger.debug("UdpMessageSender.sendMessage");
|
||||||
if (sipMessage == null) {
|
if (sipMessage == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
byte[] buf = sipMessage.toString().getBytes();
|
byte[] buf = sipMessage.toString().getBytes();
|
||||||
sendBytes(buf);
|
sendBytes(buf);
|
||||||
StringBuffer direction = new StringBuffer();
|
String direction = "SENT to " + inetAddress.getHostAddress() +
|
||||||
direction.append("SENT to ").append(inetAddress.getHostAddress());
|
"/" + port;
|
||||||
direction.append("/").append(port);
|
Logger.info(new String(buf), direction);
|
||||||
Logger.info(new String(buf), direction.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void sendBytes(byte[] bytes) throws IOException {
|
public synchronized void sendBytes(byte[] bytes) {
|
||||||
Logger.debug("UdpMessageSender.sendBytes");
|
Logger.debug("UdpMessageSender.sendBytes");
|
||||||
final DatagramPacket packet = new DatagramPacket(bytes, bytes.length,
|
final DatagramPacket packet = new DatagramPacket(bytes, bytes.length,
|
||||||
inetAddress, port);
|
inetAddress, port);
|
||||||
@@ -67,10 +64,7 @@ public class UdpMessageSender extends MessageSender {
|
|||||||
+ " " + inetAddress + ":" + port);
|
+ " " + inetAddress + ":" + port);
|
||||||
// AccessController.doPrivileged added for plugin compatibility
|
// AccessController.doPrivileged added for plugin compatibility
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged(
|
||||||
new PrivilegedAction<Void>() {
|
(PrivilegedAction<Void>) () -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public Void run() {
|
|
||||||
try {
|
try {
|
||||||
Logger.debug(datagramSocket.getLocalAddress().toString());
|
Logger.debug(datagramSocket.getLocalAddress().toString());
|
||||||
datagramSocket.send(packet);
|
datagramSocket.send(packet);
|
||||||
@@ -79,7 +73,6 @@ public class UdpMessageSender extends MessageSender {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Logger.debug("UdpMessageSender.sendBytes packet sent");
|
Logger.debug("UdpMessageSender.sendBytes packet sent");
|
||||||
|
|||||||
Reference in New Issue
Block a user