Adds support for computing of initial CandidatePair states in check lists. (section 5.7.4. of 5245

This commit is contained in:
emcho 2010-05-01 21:35:24 +00:00
parent af8a7345a6
commit 1ff391f994
3 changed files with 41 additions and 33 deletions

View File

@ -352,7 +352,7 @@ public class Agent
} }
//init the states of the first media stream as per 5245 //init the states of the first media stream as per 5245
streams.get(0).getCheckList().computeInitialStates(); streams.get(0).getCheckList().computeInitialCheckListPairStates();
} }

View File

@ -205,50 +205,59 @@ public class CheckList
} }
/** /**
* If this check list {@link #isFrozen}, computes the state of each pair in * Computes and resets states of all pairs in this check list. For all pairs
* it. To do so, the method groups together all of the pairs with the same * with the same foundation, we set the state of the pair with the lowest
* foundation, and for each group, sets the state of the pair with the * component ID to Waiting. If there is more than one such pair, the one
* lowest component ID to Waiting. If there is more than one such pair, * with the highest priority is used.
* 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() public synchronized void computeInitialCheckListPairStates()
{ {
if(!isFrozen()) Map<String, CandidatePair> pairsToWait
return; = new Hashtable<String, CandidatePair>();
Map<String, CandidatePair> foundationPairs //first, determine the pairs that we'd need to put in the waiting state.
= new Hashtable<String, CandidatePair>(); for(CandidatePair pair : this)
for (CandidatePair pair : this)
{ {
CandidatePair pairToUnfreeze //we need to check whether the pair is already in the wait list. if
= foundationPairs.get(pair.getFoundation()); //so we'll compare it with this one and determine which of the two
//needs to stay.
CandidatePair prevPair = pairsToWait.get(pair.getFoundation());
if( pairToUnfreeze == null) if(prevPair == null)
{ {
pairToUnfreeze = pair; //first pair with this foundation.
pairsToWait.put(pair.getFoundation(), pair);
continue;
}
//we already have a pair with the same foundation. determine which
//of the two has the lower component id and higher priority and
//keep that one in the list.
if( prevPair.getParentComponent() == pair.getParentComponent())
{
if(pair.getPriority() > prevPair.getPriority())
{
//need to replace the pair in the list.
pairsToWait.put(pair.getFoundation(), pair);
}
} }
else else
{ {
if(pair.getParentComponent().getComponentID() if(pair.getParentComponent().getComponentID()
< pairToUnfreeze.getParentComponent().getComponentID()) < prevPair.getParentComponent().getComponentID())
{ {
//prefer the lower component ID. //need to replace the pair in the list.
pairToUnfreeze = pair; pairsToWait.put(pair.getFoundation(), 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(), //now put the pairs we've selected in the Waiting state.
pairToUnfreeze ); Iterator<CandidatePair> pairsIter = pairsToWait.values().iterator();
while(pairsIter.hasNext())
{
pairsIter.next().setState(CandidatePairState.WAITING, null);
} }
} }
} }

View File

@ -276,7 +276,6 @@ public class IceMediaStream
orderCheckList(); orderCheckList();
pruneCheckList(); pruneCheckList();
computeInitialCheckListPairStates();
logger.finest("Checklist initialized."); logger.finest("Checklist initialized.");
} }
} }
@ -442,7 +441,7 @@ public class IceMediaStream
while(pairsIter.hasNext()) while(pairsIter.hasNext())
{ {
pairsIter.next().setState(CandidatePairState.WAITING); pairsIter.next().setState(CandidatePairState.WAITING, null);
} }
} }