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();
|
||||
}
|
||||
|
||||
ufrag = ((RemoteCandidate)pair.getRemoteCandidate()).getUfrag();
|
||||
ufrag = pair.getRemoteCandidate().getUfrag();
|
||||
}
|
||||
remoteCandidate = new RemoteCandidate(
|
||||
remoteAddress,
|
||||
@ -2102,4 +2102,70 @@ public class Agent
|
||||
}
|
||||
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.
|
||||
*/
|
||||
private Candidate remoteCandidate;
|
||||
private RemoteCandidate remoteCandidate;
|
||||
|
||||
/**
|
||||
* Priority of the candidate-pair
|
||||
@ -96,7 +96,7 @@ public class CandidatePair
|
||||
* @param remoteCandidate the remote candidate of the pair.
|
||||
*/
|
||||
public CandidatePair(LocalCandidate localCandidate,
|
||||
Candidate remoteCandidate)
|
||||
RemoteCandidate remoteCandidate)
|
||||
{
|
||||
|
||||
this.localCandidate = localCandidate;
|
||||
@ -150,7 +150,7 @@ public class CandidatePair
|
||||
*
|
||||
* @return the remote <tt>Candidate</tt> of this <tt>CandidatePair</tt>.
|
||||
*/
|
||||
public Candidate getRemoteCandidate()
|
||||
public RemoteCandidate getRemoteCandidate()
|
||||
{
|
||||
return remoteCandidate;
|
||||
}
|
||||
@ -161,7 +161,7 @@ public class CandidatePair
|
||||
* @param remoteCnd the local <tt>Candidate</tt> of this
|
||||
* <tt>CandidatePair</tt>.
|
||||
*/
|
||||
protected void setRemoteCandidate( Candidate remoteCnd)
|
||||
protected void setRemoteCandidate(RemoteCandidate remoteCnd)
|
||||
{
|
||||
this.remoteCandidate = remoteCnd;
|
||||
}
|
||||
|
||||
@ -78,14 +78,15 @@ public class Component
|
||||
/**
|
||||
* 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
|
||||
* connectivity establishment.
|
||||
*/
|
||||
private List<Candidate> remoteUpdateCandidates =
|
||||
new LinkedList<Candidate>();
|
||||
private List<RemoteCandidate> remoteUpdateCandidates =
|
||||
new LinkedList<RemoteCandidate>();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void addRemoteCandidate(Candidate candidate)
|
||||
public void addRemoteCandidate(RemoteCandidate candidate)
|
||||
{
|
||||
logger.info("Add remote candidate for " + toShortString() + ": " +
|
||||
candidate.getTransportAddress());
|
||||
@ -225,7 +226,7 @@ public class Component
|
||||
*
|
||||
* @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() + ": " +
|
||||
candidate.getTransportAddress());
|
||||
@ -356,7 +357,7 @@ public class Component
|
||||
continue;
|
||||
}
|
||||
|
||||
for(Candidate remoteCnd : remoteUpdateCandidates)
|
||||
for(RemoteCandidate remoteCnd : remoteUpdateCandidates)
|
||||
{
|
||||
if(localCnd.canReach(remoteCnd))
|
||||
{
|
||||
@ -372,8 +373,8 @@ public class Component
|
||||
}
|
||||
}
|
||||
|
||||
CandidatePair pair = new CandidatePair(localCnd,
|
||||
remoteCnd);
|
||||
CandidatePair pair
|
||||
= new CandidatePair(localCnd, remoteCnd);
|
||||
logger.info("new Pair added: " + pair.toShortString());
|
||||
checkList.add(pair);
|
||||
}
|
||||
@ -410,11 +411,11 @@ public class Component
|
||||
* @return Returns a copy of the list containing all remote candidates
|
||||
* currently registered in this <tt>Component</tt>.
|
||||
*/
|
||||
public List<Candidate> getRemoteCandidates()
|
||||
public List<RemoteCandidate> getRemoteCandidates()
|
||||
{
|
||||
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
|
||||
* the remote agent for this component.
|
||||
*/
|
||||
public void addRemoteCandidates(List<Candidate> candidates)
|
||||
public void addRemoteCandidates(List<RemoteCandidate> candidates)
|
||||
{
|
||||
synchronized(remoteCandidates)
|
||||
{
|
||||
@ -539,7 +540,7 @@ public class Component
|
||||
+ getDefaultRemoteCandidate());
|
||||
synchronized(remoteCandidates)
|
||||
{
|
||||
for (Candidate cand : remoteCandidates)
|
||||
for (RemoteCandidate cand : remoteCandidates)
|
||||
{
|
||||
buff.append("\n" + cand.toString());
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ class ConnectivityCheckClient
|
||||
{
|
||||
/* Google Talk ICE dialect just need the username */
|
||||
String localUserName = parentAgent.generateLocalUserName(
|
||||
(RemoteCandidate)candidatePair.getRemoteCandidate(),
|
||||
candidatePair.getRemoteCandidate(),
|
||||
candidatePair.getLocalCandidate());
|
||||
|
||||
UsernameAttribute unameAttr =
|
||||
@ -531,7 +531,7 @@ class ConnectivityCheckClient
|
||||
.findLocalCandidate(mappedAddress);
|
||||
}
|
||||
|
||||
Candidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
||||
RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
||||
|
||||
// RFC 5245: The agent checks the mapped address from the STUN
|
||||
// response. If the transport address does not match any of the
|
||||
|
||||
@ -351,7 +351,7 @@ public class IceMediaStream
|
||||
final List<CandidatePair> checkList)
|
||||
{
|
||||
List<LocalCandidate> localCnds = component.getLocalCandidates();
|
||||
List<Candidate> remoteCnds = component.getRemoteCandidates();
|
||||
List<RemoteCandidate> remoteCnds = component.getRemoteCandidates();
|
||||
LocalCandidate upnpBase = null;
|
||||
|
||||
for(LocalCandidate lc : localCnds)
|
||||
@ -368,7 +368,7 @@ public class IceMediaStream
|
||||
if(localCnd == upnpBase)
|
||||
continue;
|
||||
|
||||
for(Candidate remoteCnd : remoteCnds)
|
||||
for(RemoteCandidate remoteCnd : remoteCnds)
|
||||
{
|
||||
if(localCnd.canReach(remoteCnd))
|
||||
{
|
||||
@ -377,7 +377,7 @@ public class IceMediaStream
|
||||
CompatibilityMode.GTALK)
|
||||
{
|
||||
final LocalCandidate loc = localCnd;
|
||||
final Candidate remot = remoteCnd;
|
||||
final RemoteCandidate remot = remoteCnd;
|
||||
|
||||
new Thread()
|
||||
{
|
||||
@ -625,8 +625,7 @@ public class IceMediaStream
|
||||
for( CandidatePair pair : checkList)
|
||||
{
|
||||
LocalCandidate local = pair.getLocalCandidate();
|
||||
RemoteCandidate remote =
|
||||
(RemoteCandidate)pair.getRemoteCandidate();
|
||||
RemoteCandidate remote = pair.getRemoteCandidate();
|
||||
|
||||
if(local.getUfrag().equals(remoteUFrag) &&
|
||||
remote.getUfrag().equals(localUFrag))
|
||||
|
||||
@ -348,4 +348,78 @@ public abstract class LocalCandidate
|
||||
{
|
||||
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
|
||||
* by the session description protocol.
|
||||
*/
|
||||
public RemoteCandidate(TransportAddress transportAddress,
|
||||
Component parentComponent,
|
||||
CandidateType type,
|
||||
String foundation,
|
||||
long priority)
|
||||
public RemoteCandidate(
|
||||
TransportAddress transportAddress,
|
||||
Component parentComponent,
|
||||
CandidateType type,
|
||||
String foundation,
|
||||
long priority)
|
||||
{
|
||||
this(transportAddress,
|
||||
this(
|
||||
transportAddress,
|
||||
parentComponent,
|
||||
type,
|
||||
foundation,
|
||||
@ -72,12 +74,13 @@ public class RemoteCandidate
|
||||
* by the session description protocol.
|
||||
* @param ufrag ufrag for the remote candidate
|
||||
*/
|
||||
public RemoteCandidate(TransportAddress transportAddress,
|
||||
Component parentComponent,
|
||||
CandidateType type,
|
||||
String foundation,
|
||||
long priority,
|
||||
String ufrag)
|
||||
public RemoteCandidate(
|
||||
TransportAddress transportAddress,
|
||||
Component parentComponent,
|
||||
CandidateType type,
|
||||
String foundation,
|
||||
long priority,
|
||||
String ufrag)
|
||||
{
|
||||
super(transportAddress, parentComponent, type);
|
||||
setFoundation(foundation);
|
||||
@ -160,4 +163,78 @@ public class RemoteCandidate
|
||||
{
|
||||
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