Adds support for computing initial check list states. (sections 5.7.4., 7.1.3.2.3, 7.1.3. of 5245
This commit is contained in:
parent
8d69aab45b
commit
40a0c3a03e
@ -583,8 +583,7 @@ public class Agent
|
||||
Collection<IceMediaStream> streams = mediaStreams.values();
|
||||
for (IceMediaStream stream : streams)
|
||||
{
|
||||
if (stream.getCheckList().getState()
|
||||
== CheckListState.RUNNING)
|
||||
if (stream.getCheckList().isActive())
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -602,10 +601,12 @@ public class Agent
|
||||
{
|
||||
StringBuffer buff = new StringBuffer("ICE Agent (stream-count=");
|
||||
|
||||
buff.append(getStreamCount()).append(" ice-pwd:").append(getLocalPassword());
|
||||
buff.append(getStreamCount()).append(" ice-pwd:")
|
||||
.append(getLocalPassword());
|
||||
buff.append(getStreamCount()).append(" ice-ufrag:")
|
||||
.append(getLocalUfrag());
|
||||
buff.append(getStreamCount()).append(" tie-breaker:" + getTieBreaker());
|
||||
.append(getLocalUfrag());
|
||||
buff.append(getStreamCount()).append(" tie-breaker:")
|
||||
.append(getTieBreaker());
|
||||
buff.append("):\n");
|
||||
|
||||
List<IceMediaStream> streams = getStreams();
|
||||
|
||||
@ -143,6 +143,43 @@ public class CheckList
|
||||
return highestPriorityFrozenPair; //return even if null
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this <tt>CheckList</tt> can be considered active.
|
||||
* RFC 5245 says: A check list with at least one pair that is Waiting is
|
||||
* called an active check list.
|
||||
*
|
||||
* @return <tt>true</tt> if this list is active and <tt>false</tt>
|
||||
* otherwise.
|
||||
*/
|
||||
public synchronized boolean isActive()
|
||||
{
|
||||
for (CandidatePair pair : this)
|
||||
{
|
||||
if (pair.getState() == CandidatePairState.WAITING)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether this <tt>CheckList</tt> can be considered frozen.
|
||||
* RFC 5245 says: a check list with all pairs Frozen is called a frozen
|
||||
* check list.
|
||||
*
|
||||
* @return <tt>true</tt> if all pairs in this list are frozen and
|
||||
* <tt>false</tt> otherwise.
|
||||
*/
|
||||
public synchronized boolean isFrozen()
|
||||
{
|
||||
for (CandidatePair pair : this)
|
||||
{
|
||||
if (pair.getState() != CandidatePairState.FROZEN)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <tt>String</tt> representation of this check list. It
|
||||
* consists of a list of the <tt>CandidatePair</tt>s in the order they
|
||||
@ -166,4 +203,52 @@ public class CheckList
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* If this check list {@link #isFrozen}, computes the state of each pair in
|
||||
* it. To do so, the method groups together all of the pairs with the same
|
||||
* foundation, and for each group, sets the state of the pair with the
|
||||
* lowest component ID to Waiting. If there is more than one such pair,
|
||||
* the one with the highest priority is used.
|
||||
* <p>
|
||||
* If the check list is not frozen, this method has no effect.
|
||||
*/
|
||||
public synchronized void computeInitialStates()
|
||||
{
|
||||
if(!isFrozen())
|
||||
return;
|
||||
|
||||
Map<String, CandidatePair> foundationPairs
|
||||
= new Hashtable<String, CandidatePair>();
|
||||
|
||||
for (CandidatePair pair : this)
|
||||
{
|
||||
CandidatePair pairToUnfreeze
|
||||
= foundationPairs.get(pair.getFoundation());
|
||||
|
||||
if( pairToUnfreeze == null)
|
||||
{
|
||||
pairToUnfreeze = pair;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pair.getParentComponent().getComponentID()
|
||||
< pairToUnfreeze.getParentComponent().getComponentID())
|
||||
{
|
||||
//prefer the lower component ID.
|
||||
pairToUnfreeze = pair;
|
||||
}
|
||||
else if (pair.getParentComponent().getComponentID()
|
||||
== pairToUnfreeze.getParentComponent().getComponentID())
|
||||
{
|
||||
//for equal component IDs prefer the higher priority
|
||||
if(pair.getPriority() > pairToUnfreeze.getPriority())
|
||||
pairToUnfreeze = pair;
|
||||
}
|
||||
}
|
||||
|
||||
foundationPairs.put(pairToUnfreeze.getFoundation(),
|
||||
pairToUnfreeze );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user