Takes into account the configuration property net.java.sip.communicator.service.protocol.MIN_MEDIA_PORT_NUMBER for the purposes of ICE.

cusax-fix
Lyubomir Marinov 14 years ago
parent c46aae0cbe
commit 95be6b19ee

@ -628,7 +628,7 @@ private IceMediaStream createIceStream(String media)
{
//the following call involves STUN processing so it may take a while
stream = getNetAddrMgr().createIceStream(
nextMediaPortToTry, media, iceAgent);
getNextMediaPortToTry(), media, iceAgent);
}
catch (Exception ex)
{
@ -644,9 +644,14 @@ private IceMediaStream createIceStream(String media)
//would simply include one more bind retry.
try
{
nextMediaPortToTry = stream.getComponent(Component.RTCP)
.getLocalCandidates().get(0)
.getTransportAddress().getPort() + 1;
setNextMediaPortToTry(
1
+ stream
.getComponent(Component.RTCP)
.getLocalCandidates()
.get(0)
.getTransportAddress()
.getPort());
}
catch(Throwable t)
{

@ -842,7 +842,7 @@ private IceMediaStream createIceStream(String media, boolean rtcp)
{
//the following call involves STUN processing so it may take a while
stream = iceAgent.createMediaStream(media);
int rtpPort = nextMediaPortToTry;
int rtpPort = getNextMediaPortToTry();
//rtp
iceAgent.createComponent(stream, Transport.UDP, rtpPort, rtpPort,
@ -866,10 +866,14 @@ private IceMediaStream createIceStream(String media, boolean rtcp)
//would simply include one more bind retry.
try
{
nextMediaPortToTry = stream.getComponent(rtcp ? Component.RTCP :
Component.RTP)
.getLocalCandidates().get(0)
.getTransportAddress().getPort() + 1;
setNextMediaPortToTry(
1
+ stream
.getComponent(rtcp ? Component.RTCP : Component.RTP)
.getLocalCandidates()
.get(0)
.getTransportAddress()
.getPort());
}
catch(Throwable t)
{

@ -36,19 +36,28 @@ public abstract class TransportManager<U extends MediaAwareCallPeer<?, ?, ?>>
/**
* The minimum port number that we'd like our RTP sockets to bind upon.
* <p>
* Initialized by {@link #initializePortNumbers()}.
* </p>
*/
private static int minMediaPort = 5000;
private static int minMediaPort = -1;
/**
* The maximum port number that we'd like our RTP sockets to bind upon.
* <p>
* Initialized by {@link #initializePortNumbers()}.
* </p>
*/
private static int maxMediaPort = 6000;
private static int maxMediaPort = -1;
/**
* The port that we should try to bind our next media stream's RTP socket
* to.
* <p>
* Initialized by {@link #initializePortNumbers()}.
* </p>
*/
protected static int nextMediaPortToTry = minMediaPort;
private static int nextMediaPortToTry = -1;
/**
* The {@link MediaAwareCallPeer} whose traffic we will be taking care of.
@ -226,7 +235,7 @@ protected StreamConnector createStreamConnector(MediaType mediaType)
//make sure that next time we don't try to bind on occupied ports
nextMediaPortToTry = rtcpSocket.getLocalPort() + 1;
if (nextMediaPortToTry > maxMediaPort -1)// take RTCP into account.
if (nextMediaPortToTry > maxMediaPort - 1)// take RTCP into account.
nextMediaPortToTry = minMediaPort;
return new DefaultStreamConnector(rtpSocket, rtcpSocket);
@ -236,7 +245,7 @@ protected StreamConnector createStreamConnector(MediaType mediaType)
* (Re)Sets the <tt>minPortNumber</tt> and <tt>maxPortNumber</tt> to their
* defaults or to the values specified in the <tt>ConfigurationService</tt>.
*/
protected void initializePortNumbers()
protected static void initializePortNumbers()
{
//first reset to default values
minMediaPort = 5000;
@ -283,6 +292,17 @@ protected void initializePortNumbers()
ex);
}
}
/*
* Make sure that nextMediaPortToTry is within the range of minMediaPort
* and maxMediaPort as
* NetworkAddressManagerServiceImpl#createDatagramSocket(InetAddress,
* int, int, int) does.
*/
if ((minMediaPort <= maxMediaPort)
&& ((nextMediaPortToTry < minMediaPort)
|| (nextMediaPortToTry > maxMediaPort)))
nextMediaPortToTry = minMediaPort;
}
/**
@ -388,4 +408,30 @@ public U getCallPeer()
{
return callPeer;
}
/**
* Gets the port that we should try to bind our next media stream's RTP
* socket to.
*
* @return the port that we should try to bind our next media stream's RTP
* socket to
*/
protected static int getNextMediaPortToTry()
{
if (nextMediaPortToTry == -1)
initializePortNumbers();
return nextMediaPortToTry;
}
/**
* Sets the port that we should try to bind our next media stream's RTP
* socket to
*
* @param nextMediaPortToTry the port that we should try to bind our next
* media stream's RTP socket to
*/
protected static void setNextMediaPortToTry(int nextMediaPortToTry)
{
TransportManager.nextMediaPortToTry = nextMediaPortToTry;
}
}

Loading…
Cancel
Save