From 1ff391f994688cfe852ef9727fdf4efc7d3c0b2f Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 1 May 2010 21:35:24 +0000 Subject: [PATCH] Adds support for computing of initial CandidatePair states in check lists. (section 5.7.4. of 5245 --- src/org/ice4j/ice/Agent.java | 2 +- src/org/ice4j/ice/CheckList.java | 69 +++++++++++++++------------ src/org/ice4j/ice/IceMediaStream.java | 3 +- 3 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 4e62cec..4c57712 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -352,7 +352,7 @@ public class Agent } //init the states of the first media stream as per 5245 - streams.get(0).getCheckList().computeInitialStates(); + streams.get(0).getCheckList().computeInitialCheckListPairStates(); } diff --git a/src/org/ice4j/ice/CheckList.java b/src/org/ice4j/ice/CheckList.java index 7247522..7f85331 100644 --- a/src/org/ice4j/ice/CheckList.java +++ b/src/org/ice4j/ice/CheckList.java @@ -205,50 +205,59 @@ public class CheckList } /** - * 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. - *

- * If the check list is not frozen, this method has no effect. + * Computes and resets states of all pairs in this check list. For all pairs + * with the same foundation, we set 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. */ - public synchronized void computeInitialStates() + public synchronized void computeInitialCheckListPairStates() { - if(!isFrozen()) - return; + Map pairsToWait + = new Hashtable(); - Map foundationPairs - = new Hashtable(); - - for (CandidatePair pair : this) + //first, determine the pairs that we'd need to put in the waiting state. + for(CandidatePair pair : this) { - CandidatePair pairToUnfreeze - = foundationPairs.get(pair.getFoundation()); + //we need to check whether the pair is already in the wait list. if + //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 { if(pair.getParentComponent().getComponentID() - < pairToUnfreeze.getParentComponent().getComponentID()) + < prevPair.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; + //need to replace the pair in the list. + pairsToWait.put(pair.getFoundation(), pair); } } + } - foundationPairs.put(pairToUnfreeze.getFoundation(), - pairToUnfreeze ); + //now put the pairs we've selected in the Waiting state. + Iterator pairsIter = pairsToWait.values().iterator(); + + while(pairsIter.hasNext()) + { + pairsIter.next().setState(CandidatePairState.WAITING, null); } } } diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index 562f735..59dbf49 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -276,7 +276,6 @@ public class IceMediaStream orderCheckList(); pruneCheckList(); - computeInitialCheckListPairStates(); logger.finest("Checklist initialized."); } } @@ -442,7 +441,7 @@ public class IceMediaStream while(pairsIter.hasNext()) { - pairsIter.next().setState(CandidatePairState.WAITING); + pairsIter.next().setState(CandidatePairState.WAITING, null); } }