Adds functions to get the host/reflexive/relayed address of the selected candidate pair.
This commit is contained in:
parent
8f51251658
commit
e4c70ba522
@ -1306,7 +1306,7 @@ public class Agent
|
|||||||
useCandidate = pair2.useCandidateReceived();
|
useCandidate = pair2.useCandidateReceived();
|
||||||
}
|
}
|
||||||
|
|
||||||
ufrag = ((RemoteCandidate)pair.getRemoteCandidate()).getUfrag();
|
ufrag = pair.getRemoteCandidate().getUfrag();
|
||||||
}
|
}
|
||||||
remoteCandidate = new RemoteCandidate(
|
remoteCandidate = new RemoteCandidate(
|
||||||
remoteAddress,
|
remoteAddress,
|
||||||
@ -2102,4 +2102,70 @@ public class Agent
|
|||||||
}
|
}
|
||||||
logger.info("KeepAliveThread ends");
|
logger.info("KeepAliveThread ends");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the selected pair for this Agent.
|
||||||
|
*
|
||||||
|
* @param streamName The stream name (AUDIO, VIDEO);
|
||||||
|
*
|
||||||
|
* @return The selected pair for this Agent. Null if no pair is selected.
|
||||||
|
*/
|
||||||
|
private CandidatePair getSelectedPair(String streamName)
|
||||||
|
{
|
||||||
|
List<IceMediaStream> iceMediaStreams = this.getStreams();
|
||||||
|
for(int i = 0; i < iceMediaStreams.size(); ++i)
|
||||||
|
{
|
||||||
|
if(iceMediaStreams.get(i).getName().equals(streamName))
|
||||||
|
{
|
||||||
|
List<org.ice4j.ice.Component> components =
|
||||||
|
iceMediaStreams.get(i).getComponents();
|
||||||
|
for(int j = 0; j < components.size(); ++j)
|
||||||
|
{
|
||||||
|
Component component = components.get(i);
|
||||||
|
if(component.getComponentID()
|
||||||
|
== org.ice4j.ice.Component.RTP)
|
||||||
|
{
|
||||||
|
return component.getSelectedPair();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the selected local candidate for this Agent.
|
||||||
|
*
|
||||||
|
* @param streamName The stream name (AUDIO, VIDEO);
|
||||||
|
*
|
||||||
|
* @return The selected local candidate for this Agent. Null if no pair is
|
||||||
|
* selected.
|
||||||
|
*/
|
||||||
|
public LocalCandidate getSelectedLocalCandidate(String streamName)
|
||||||
|
{
|
||||||
|
CandidatePair candidatePair = this.getSelectedPair(streamName);
|
||||||
|
if(candidatePair != null)
|
||||||
|
{
|
||||||
|
return candidatePair.getLocalCandidate();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the selected remote candidate for this Agent.
|
||||||
|
*
|
||||||
|
* @param streamName The stream name (AUDIO, VIDEO);
|
||||||
|
*
|
||||||
|
* @return The selected remote candidate for this Agent. Null if no pair is
|
||||||
|
* selected.
|
||||||
|
*/
|
||||||
|
public RemoteCandidate getSelectedRemoteCandidate(String streamName)
|
||||||
|
{
|
||||||
|
CandidatePair candidatePair = this.getSelectedPair(streamName);
|
||||||
|
if(candidatePair != null)
|
||||||
|
{
|
||||||
|
return candidatePair.getRemoteCandidate();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class CandidatePair
|
|||||||
/**
|
/**
|
||||||
* The remote candidate of this pair.
|
* The remote candidate of this pair.
|
||||||
*/
|
*/
|
||||||
private Candidate remoteCandidate;
|
private RemoteCandidate remoteCandidate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Priority of the candidate-pair
|
* Priority of the candidate-pair
|
||||||
@ -96,7 +96,7 @@ public class CandidatePair
|
|||||||
* @param remoteCandidate the remote candidate of the pair.
|
* @param remoteCandidate the remote candidate of the pair.
|
||||||
*/
|
*/
|
||||||
public CandidatePair(LocalCandidate localCandidate,
|
public CandidatePair(LocalCandidate localCandidate,
|
||||||
Candidate remoteCandidate)
|
RemoteCandidate remoteCandidate)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.localCandidate = localCandidate;
|
this.localCandidate = localCandidate;
|
||||||
@ -150,7 +150,7 @@ public class CandidatePair
|
|||||||
*
|
*
|
||||||
* @return the remote <tt>Candidate</tt> of this <tt>CandidatePair</tt>.
|
* @return the remote <tt>Candidate</tt> of this <tt>CandidatePair</tt>.
|
||||||
*/
|
*/
|
||||||
public Candidate getRemoteCandidate()
|
public RemoteCandidate getRemoteCandidate()
|
||||||
{
|
{
|
||||||
return remoteCandidate;
|
return remoteCandidate;
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ public class CandidatePair
|
|||||||
* @param remoteCnd the local <tt>Candidate</tt> of this
|
* @param remoteCnd the local <tt>Candidate</tt> of this
|
||||||
* <tt>CandidatePair</tt>.
|
* <tt>CandidatePair</tt>.
|
||||||
*/
|
*/
|
||||||
protected void setRemoteCandidate( Candidate remoteCnd)
|
protected void setRemoteCandidate(RemoteCandidate remoteCnd)
|
||||||
{
|
{
|
||||||
this.remoteCandidate = remoteCnd;
|
this.remoteCandidate = remoteCnd;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,14 +78,15 @@ public class Component
|
|||||||
/**
|
/**
|
||||||
* The list of candidates that the peer agent sent for this stream.
|
* The list of candidates that the peer agent sent for this stream.
|
||||||
*/
|
*/
|
||||||
private List<Candidate> remoteCandidates = new LinkedList<Candidate>();
|
private List<RemoteCandidate> remoteCandidates
|
||||||
|
= new LinkedList<RemoteCandidate>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of candidates that the peer agent sent for this stream after
|
* The list of candidates that the peer agent sent for this stream after
|
||||||
* connectivity establishment.
|
* connectivity establishment.
|
||||||
*/
|
*/
|
||||||
private List<Candidate> remoteUpdateCandidates =
|
private List<RemoteCandidate> remoteUpdateCandidates =
|
||||||
new LinkedList<Candidate>();
|
new LinkedList<RemoteCandidate>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>Comparator</tt> that we use for sorting <tt>Candidate</tt>s by
|
* A <tt>Comparator</tt> that we use for sorting <tt>Candidate</tt>s by
|
||||||
@ -208,7 +209,7 @@ public class Component
|
|||||||
*
|
*
|
||||||
* @param candidate the <tt>Candidate</tt> instance to add.
|
* @param candidate the <tt>Candidate</tt> instance to add.
|
||||||
*/
|
*/
|
||||||
public void addRemoteCandidate(Candidate candidate)
|
public void addRemoteCandidate(RemoteCandidate candidate)
|
||||||
{
|
{
|
||||||
logger.info("Add remote candidate for " + toShortString() + ": " +
|
logger.info("Add remote candidate for " + toShortString() + ": " +
|
||||||
candidate.getTransportAddress());
|
candidate.getTransportAddress());
|
||||||
@ -225,7 +226,7 @@ public class Component
|
|||||||
*
|
*
|
||||||
* @param candidate new <tt>Candidate</tt> to add.
|
* @param candidate new <tt>Candidate</tt> to add.
|
||||||
*/
|
*/
|
||||||
public void addUpdateRemoteCandidate(Candidate candidate)
|
public void addUpdateRemoteCandidate(RemoteCandidate candidate)
|
||||||
{
|
{
|
||||||
logger.info("Update remote candidate for " + toShortString() + ": " +
|
logger.info("Update remote candidate for " + toShortString() + ": " +
|
||||||
candidate.getTransportAddress());
|
candidate.getTransportAddress());
|
||||||
@ -356,7 +357,7 @@ public class Component
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Candidate remoteCnd : remoteUpdateCandidates)
|
for(RemoteCandidate remoteCnd : remoteUpdateCandidates)
|
||||||
{
|
{
|
||||||
if(localCnd.canReach(remoteCnd))
|
if(localCnd.canReach(remoteCnd))
|
||||||
{
|
{
|
||||||
@ -372,8 +373,8 @@ public class Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidatePair pair = new CandidatePair(localCnd,
|
CandidatePair pair
|
||||||
remoteCnd);
|
= new CandidatePair(localCnd, remoteCnd);
|
||||||
logger.info("new Pair added: " + pair.toShortString());
|
logger.info("new Pair added: " + pair.toShortString());
|
||||||
checkList.add(pair);
|
checkList.add(pair);
|
||||||
}
|
}
|
||||||
@ -410,11 +411,11 @@ public class Component
|
|||||||
* @return Returns a copy of the list containing all remote candidates
|
* @return Returns a copy of the list containing all remote candidates
|
||||||
* currently registered in this <tt>Component</tt>.
|
* currently registered in this <tt>Component</tt>.
|
||||||
*/
|
*/
|
||||||
public List<Candidate> getRemoteCandidates()
|
public List<RemoteCandidate> getRemoteCandidates()
|
||||||
{
|
{
|
||||||
synchronized(remoteCandidates)
|
synchronized(remoteCandidates)
|
||||||
{
|
{
|
||||||
return new ArrayList<Candidate>(remoteCandidates);
|
return new ArrayList<RemoteCandidate>(remoteCandidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +438,7 @@ public class Component
|
|||||||
* @param candidates the <tt>List</tt> of <tt>Candidate</tt>s reported by
|
* @param candidates the <tt>List</tt> of <tt>Candidate</tt>s reported by
|
||||||
* the remote agent for this component.
|
* the remote agent for this component.
|
||||||
*/
|
*/
|
||||||
public void addRemoteCandidates(List<Candidate> candidates)
|
public void addRemoteCandidates(List<RemoteCandidate> candidates)
|
||||||
{
|
{
|
||||||
synchronized(remoteCandidates)
|
synchronized(remoteCandidates)
|
||||||
{
|
{
|
||||||
@ -539,7 +540,7 @@ public class Component
|
|||||||
+ getDefaultRemoteCandidate());
|
+ getDefaultRemoteCandidate());
|
||||||
synchronized(remoteCandidates)
|
synchronized(remoteCandidates)
|
||||||
{
|
{
|
||||||
for (Candidate cand : remoteCandidates)
|
for (RemoteCandidate cand : remoteCandidates)
|
||||||
{
|
{
|
||||||
buff.append("\n" + cand.toString());
|
buff.append("\n" + cand.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,7 +177,7 @@ class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
/* Google Talk ICE dialect just need the username */
|
/* Google Talk ICE dialect just need the username */
|
||||||
String localUserName = parentAgent.generateLocalUserName(
|
String localUserName = parentAgent.generateLocalUserName(
|
||||||
(RemoteCandidate)candidatePair.getRemoteCandidate(),
|
candidatePair.getRemoteCandidate(),
|
||||||
candidatePair.getLocalCandidate());
|
candidatePair.getLocalCandidate());
|
||||||
|
|
||||||
UsernameAttribute unameAttr =
|
UsernameAttribute unameAttr =
|
||||||
@ -531,7 +531,7 @@ class ConnectivityCheckClient
|
|||||||
.findLocalCandidate(mappedAddress);
|
.findLocalCandidate(mappedAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
Candidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
||||||
|
|
||||||
// RFC 5245: The agent checks the mapped address from the STUN
|
// RFC 5245: The agent checks the mapped address from the STUN
|
||||||
// response. If the transport address does not match any of the
|
// response. If the transport address does not match any of the
|
||||||
|
|||||||
@ -351,7 +351,7 @@ public class IceMediaStream
|
|||||||
final List<CandidatePair> checkList)
|
final List<CandidatePair> checkList)
|
||||||
{
|
{
|
||||||
List<LocalCandidate> localCnds = component.getLocalCandidates();
|
List<LocalCandidate> localCnds = component.getLocalCandidates();
|
||||||
List<Candidate> remoteCnds = component.getRemoteCandidates();
|
List<RemoteCandidate> remoteCnds = component.getRemoteCandidates();
|
||||||
LocalCandidate upnpBase = null;
|
LocalCandidate upnpBase = null;
|
||||||
|
|
||||||
for(LocalCandidate lc : localCnds)
|
for(LocalCandidate lc : localCnds)
|
||||||
@ -368,7 +368,7 @@ public class IceMediaStream
|
|||||||
if(localCnd == upnpBase)
|
if(localCnd == upnpBase)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for(Candidate remoteCnd : remoteCnds)
|
for(RemoteCandidate remoteCnd : remoteCnds)
|
||||||
{
|
{
|
||||||
if(localCnd.canReach(remoteCnd))
|
if(localCnd.canReach(remoteCnd))
|
||||||
{
|
{
|
||||||
@ -377,7 +377,7 @@ public class IceMediaStream
|
|||||||
CompatibilityMode.GTALK)
|
CompatibilityMode.GTALK)
|
||||||
{
|
{
|
||||||
final LocalCandidate loc = localCnd;
|
final LocalCandidate loc = localCnd;
|
||||||
final Candidate remot = remoteCnd;
|
final RemoteCandidate remot = remoteCnd;
|
||||||
|
|
||||||
new Thread()
|
new Thread()
|
||||||
{
|
{
|
||||||
@ -625,8 +625,7 @@ public class IceMediaStream
|
|||||||
for( CandidatePair pair : checkList)
|
for( CandidatePair pair : checkList)
|
||||||
{
|
{
|
||||||
LocalCandidate local = pair.getLocalCandidate();
|
LocalCandidate local = pair.getLocalCandidate();
|
||||||
RemoteCandidate remote =
|
RemoteCandidate remote = pair.getRemoteCandidate();
|
||||||
(RemoteCandidate)pair.getRemoteCandidate();
|
|
||||||
|
|
||||||
if(local.getUfrag().equals(remoteUFrag) &&
|
if(local.getUfrag().equals(remoteUFrag) &&
|
||||||
remote.getUfrag().equals(localUFrag))
|
remote.getUfrag().equals(localUFrag))
|
||||||
|
|||||||
@ -348,4 +348,78 @@ public abstract class LocalCandidate
|
|||||||
{
|
{
|
||||||
this.extendedType = extendedType;
|
this.extendedType = extendedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this candidate host address.
|
||||||
|
*
|
||||||
|
* @return This candidate host address.
|
||||||
|
*/
|
||||||
|
public TransportAddress getHostAddress()
|
||||||
|
{
|
||||||
|
switch (getType())
|
||||||
|
{
|
||||||
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
|
if(getBase() != null)
|
||||||
|
{
|
||||||
|
return getBase().getTransportAddress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
|
if(getBase() != null)
|
||||||
|
{
|
||||||
|
return getBase().getTransportAddress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
case RELAYED_CANDIDATE:
|
||||||
|
if(getBase() != null)
|
||||||
|
{
|
||||||
|
return getBase().getTransportAddress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
default: //host candidate
|
||||||
|
return getTransportAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this candidate reflexive address.
|
||||||
|
*
|
||||||
|
* @return This candidate reflexive address. Null if this candidate
|
||||||
|
* does not use a peer/server reflexive address.
|
||||||
|
*/
|
||||||
|
public TransportAddress getReflexiveAddress()
|
||||||
|
{
|
||||||
|
switch (getType())
|
||||||
|
{
|
||||||
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
|
return getTransportAddress();
|
||||||
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
|
return getTransportAddress();
|
||||||
|
case RELAYED_CANDIDATE:
|
||||||
|
return getMappedAddress();
|
||||||
|
default: //host candidate
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this candidate relayed address.
|
||||||
|
*
|
||||||
|
* @return This candidate relayed address. Null if this candidate
|
||||||
|
* does not use a relay.
|
||||||
|
*/
|
||||||
|
public TransportAddress getRelayedAddress()
|
||||||
|
{
|
||||||
|
switch (getType())
|
||||||
|
{
|
||||||
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
|
return null;
|
||||||
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
|
return null;
|
||||||
|
case RELAYED_CANDIDATE:
|
||||||
|
return getTransportAddress();
|
||||||
|
default: //host candidate
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,13 +43,15 @@ public class RemoteCandidate
|
|||||||
* @param priority the <tt>RemoteCandidate</tt>'s priority as reported
|
* @param priority the <tt>RemoteCandidate</tt>'s priority as reported
|
||||||
* by the session description protocol.
|
* by the session description protocol.
|
||||||
*/
|
*/
|
||||||
public RemoteCandidate(TransportAddress transportAddress,
|
public RemoteCandidate(
|
||||||
|
TransportAddress transportAddress,
|
||||||
Component parentComponent,
|
Component parentComponent,
|
||||||
CandidateType type,
|
CandidateType type,
|
||||||
String foundation,
|
String foundation,
|
||||||
long priority)
|
long priority)
|
||||||
{
|
{
|
||||||
this(transportAddress,
|
this(
|
||||||
|
transportAddress,
|
||||||
parentComponent,
|
parentComponent,
|
||||||
type,
|
type,
|
||||||
foundation,
|
foundation,
|
||||||
@ -72,7 +74,8 @@ public class RemoteCandidate
|
|||||||
* by the session description protocol.
|
* by the session description protocol.
|
||||||
* @param ufrag ufrag for the remote candidate
|
* @param ufrag ufrag for the remote candidate
|
||||||
*/
|
*/
|
||||||
public RemoteCandidate(TransportAddress transportAddress,
|
public RemoteCandidate(
|
||||||
|
TransportAddress transportAddress,
|
||||||
Component parentComponent,
|
Component parentComponent,
|
||||||
CandidateType type,
|
CandidateType type,
|
||||||
String foundation,
|
String foundation,
|
||||||
@ -160,4 +163,78 @@ public class RemoteCandidate
|
|||||||
{
|
{
|
||||||
return ufrag;
|
return ufrag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this candidate host address.
|
||||||
|
*
|
||||||
|
* @return This candidate host address.
|
||||||
|
*/
|
||||||
|
public TransportAddress getHostAddress()
|
||||||
|
{
|
||||||
|
switch (getType())
|
||||||
|
{
|
||||||
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
|
if(getBase() != null)
|
||||||
|
{
|
||||||
|
return getBase().getTransportAddress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
|
if(getBase() != null)
|
||||||
|
{
|
||||||
|
return getBase().getTransportAddress();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
case RELAYED_CANDIDATE:
|
||||||
|
// If we are able to find the base address of the mapped
|
||||||
|
// address, it will be a great enhancement.
|
||||||
|
// i.e. but not working
|
||||||
|
// getMappedAddress().getBase().getTransportAddress();
|
||||||
|
return null;
|
||||||
|
default: //host candidate
|
||||||
|
return getTransportAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this candidate reflexive address.
|
||||||
|
*
|
||||||
|
* @return This candidate reflexive address. Null if this candidate
|
||||||
|
* does not use a peer/server reflexive address.
|
||||||
|
*/
|
||||||
|
public TransportAddress getReflexiveAddress()
|
||||||
|
{
|
||||||
|
switch (getType())
|
||||||
|
{
|
||||||
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
|
return getTransportAddress();
|
||||||
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
|
return getTransportAddress();
|
||||||
|
case RELAYED_CANDIDATE:
|
||||||
|
return getMappedAddress();
|
||||||
|
default: //host candidate
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns this candidate relayed address.
|
||||||
|
*
|
||||||
|
* @return This candidate relayed address. Null if this candidate
|
||||||
|
* does not use a relay.
|
||||||
|
*/
|
||||||
|
public TransportAddress getRelayedAddress()
|
||||||
|
{
|
||||||
|
switch (getType())
|
||||||
|
{
|
||||||
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
|
return null;
|
||||||
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
|
return null;
|
||||||
|
case RELAYED_CANDIDATE:
|
||||||
|
return getTransportAddress();
|
||||||
|
default: //host candidate
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user