From 40a0c3a03e5980a749df21c9c10f3bfa8a24923e Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 1 May 2010 21:35:02 +0000 Subject: [PATCH] Adds support for computing initial check list states. (sections 5.7.4., 7.1.3.2.3, 7.1.3. of 5245 --- src/org/ice4j/ice/Agent.java | 11 +++-- src/org/ice4j/ice/CheckList.java | 85 ++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index c629ce1..50f0941 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -583,8 +583,7 @@ public class Agent Collection 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 streams = getStreams(); diff --git a/src/org/ice4j/ice/CheckList.java b/src/org/ice4j/ice/CheckList.java index 0b020e7..7247522 100644 --- a/src/org/ice4j/ice/CheckList.java +++ b/src/org/ice4j/ice/CheckList.java @@ -143,6 +143,43 @@ public class CheckList return highestPriorityFrozenPair; //return even if null } + /** + * Determines whether this CheckList 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 true if this list is active and false + * otherwise. + */ + public synchronized boolean isActive() + { + for (CandidatePair pair : this) + { + if (pair.getState() == CandidatePairState.WAITING) + return true; + } + return false; + } + + /** + * Determines whether this CheckList can be considered frozen. + * RFC 5245 says: a check list with all pairs Frozen is called a frozen + * check list. + * + * @return true if all pairs in this list are frozen and + * false otherwise. + */ + public synchronized boolean isFrozen() + { + for (CandidatePair pair : this) + { + if (pair.getState() != CandidatePairState.FROZEN) + return false; + } + + return true; + } + /** * Returns a String representation of this check list. It * consists of a list of the CandidatePairs 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. + *

+ * If the check list is not frozen, this method has no effect. + */ + public synchronized void computeInitialStates() + { + if(!isFrozen()) + return; + + Map foundationPairs + = new Hashtable(); + + 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 ); + } + } }