Fixes issues with ICE processing in a basic use case
This commit is contained in:
parent
7da2ab5222
commit
ef7a75fcc4
@ -1018,10 +1018,12 @@ public class Agent
|
|||||||
|
|
||||||
parentStream.addValidPair(validPair);
|
parentStream.addValidPair(validPair);
|
||||||
|
|
||||||
System.out.println("valid pair was nominated " + validPair);
|
if(!validPair.isNominated())
|
||||||
validPair.nominate();
|
{
|
||||||
validPair.getParentComponent().getParentStream()
|
validPair.nominate();
|
||||||
|
validPair.getParentComponent().getParentStream()
|
||||||
.getCheckList().scheduleTriggeredCheck(validPair);
|
.getCheckList().scheduleTriggeredCheck(validPair);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1029,19 +1031,19 @@ System.out.println("valid pair was nominated " + validPair);
|
|||||||
* contained the <tt>USE-CANDIDATE</tt> attribute or was triggered by an
|
* contained the <tt>USE-CANDIDATE</tt> attribute or was triggered by an
|
||||||
* incoming request that did.
|
* incoming request that did.
|
||||||
*
|
*
|
||||||
* @param pairToNominate the {@link CandidatePair} whose nomination has
|
* @param nominatedPair the {@link CandidatePair} whose nomination has
|
||||||
* just been confirmed.
|
* just been confirmed.
|
||||||
*/
|
*/
|
||||||
protected void nominationConfirmed(CandidatePair pairToNominate)
|
protected void nominationConfirmed(CandidatePair nominatedPair)
|
||||||
{
|
{
|
||||||
pairToNominate.nominate();
|
nominatedPair.nominate();
|
||||||
System.out.println("pair nomination confirmed");
|
|
||||||
Component parentComponent = pairToNominate.getParentComponent();
|
Component parentComponent = nominatedPair.getParentComponent();
|
||||||
IceMediaStream parentStream = parentComponent.getParentStream();
|
IceMediaStream parentStream = parentComponent.getParentStream();
|
||||||
CheckList checkList = parentStream.getCheckList();
|
CheckList checkList = parentStream.getCheckList();
|
||||||
|
|
||||||
if( checkList.getState() == CheckListState.RUNNING )
|
if( checkList.getState() == CheckListState.RUNNING )
|
||||||
checkList.handleNomination(pairToNominate);
|
checkList.handleNomination(nominatedPair);
|
||||||
|
|
||||||
//Once there is at least one nominated pair in the valid list for
|
//Once there is at least one nominated pair in the valid list for
|
||||||
//every component of the media stream and the state of the
|
//every component of the media stream and the state of the
|
||||||
@ -1052,7 +1054,6 @@ System.out.println("pair nomination confirmed");
|
|||||||
//The agent MUST change the state of processing for its check
|
//The agent MUST change the state of processing for its check
|
||||||
//list for that media stream to Completed.
|
//list for that media stream to Completed.
|
||||||
checkList.setState(CheckListState.COMPLETED);
|
checkList.setState(CheckListState.COMPLETED);
|
||||||
System.out.println("checklist " + checkList.getName() + " became " + checkList.getState());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1241,9 +1242,10 @@ System.out.println("checklist " + checkList.getName() + " became " + checkList.g
|
|||||||
private void scheduleTermination()
|
private void scheduleTermination()
|
||||||
{
|
{
|
||||||
if (terminationThread == null)
|
if (terminationThread == null)
|
||||||
|
{
|
||||||
terminationThread = new TerminationThread(this);
|
terminationThread = new TerminationThread(this);
|
||||||
|
terminationThread.start();
|
||||||
terminationThread.start();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1280,7 +1282,7 @@ System.out.println("checklist " + checkList.getName() + " became " + checkList.g
|
|||||||
* interval the user has specified) and then moves this <tt>Agent</tt>
|
* interval the user has specified) and then moves this <tt>Agent</tt>
|
||||||
* into the terminated state and frees all non-nominated candidates.
|
* into the terminated state and frees all non-nominated candidates.
|
||||||
*/
|
*/
|
||||||
public void run()
|
public synchronized void run()
|
||||||
{
|
{
|
||||||
long waitFor = Integer.getInteger(
|
long waitFor = Integer.getInteger(
|
||||||
StackProperties.TERMINATION_DELAY,
|
StackProperties.TERMINATION_DELAY,
|
||||||
@ -1289,11 +1291,12 @@ System.out.println("checklist " + checkList.getName() + " became " + checkList.g
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
wait(waitFor);
|
wait(waitFor);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.log(Level.FINEST,
|
logger.log(Level.FINEST, "Interrupted while waiting. Will "
|
||||||
"Interrupted while waiting. Will speed up termination", e);
|
+"speed up termination", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
parentAgent.terminate();
|
parentAgent.terminate();
|
||||||
@ -1308,6 +1311,8 @@ System.out.println("checklist " + checkList.getName() + " became " + checkList.g
|
|||||||
{
|
{
|
||||||
// free candidates
|
// free candidates
|
||||||
// stop listening for checks
|
// stop listening for checks
|
||||||
|
connCheckClient.stop();
|
||||||
|
connCheckServer.stop();
|
||||||
|
|
||||||
setState(IceProcessingState.TERMINATED);
|
setState(IceProcessingState.TERMINATED);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -316,6 +316,9 @@ public class CheckList
|
|||||||
protected synchronized void handleNomination(CandidatePair nominatedPair)
|
protected synchronized void handleNomination(CandidatePair nominatedPair)
|
||||||
{
|
{
|
||||||
Component cmp = nominatedPair.getParentComponent();
|
Component cmp = nominatedPair.getParentComponent();
|
||||||
|
|
||||||
|
cmp.setSelectedPair(nominatedPair);
|
||||||
|
|
||||||
Iterator<CandidatePair> pairsIter = iterator();
|
Iterator<CandidatePair> pairsIter = iterator();
|
||||||
while(pairsIter.hasNext())
|
while(pairsIter.hasNext())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -648,6 +648,17 @@ public class Component
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link CandidatePair} selected for use by ICE processing and
|
||||||
|
* that the application would use.
|
||||||
|
*
|
||||||
|
* @param pair the {@link CandidatePair} selected for use by ICE processing.
|
||||||
|
*/
|
||||||
|
protected void setSelectedPair(CandidatePair pair)
|
||||||
|
{
|
||||||
|
this.selectedPair = pair;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link CandidatePair} selected for use by ICE processing or
|
* Returns the {@link CandidatePair} selected for use by ICE processing or
|
||||||
* <tt>null</tt> if no pair has been selected so far or if ICE processing
|
* <tt>null</tt> if no pair has been selected so far or if ICE processing
|
||||||
@ -661,4 +672,21 @@ public class Component
|
|||||||
{
|
{
|
||||||
return selectedPair;
|
return selectedPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a human readable name that can be used in debug logs associated
|
||||||
|
* with this component.
|
||||||
|
*
|
||||||
|
* @return "RTP" if the component ID is 1, "RTCP" if the component id is 2
|
||||||
|
* and the compoent id itself otherwise.
|
||||||
|
*/
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
if (componentID == RTP)
|
||||||
|
return "RTP";
|
||||||
|
else if(componentID == RTCP)
|
||||||
|
return "RTCP";
|
||||||
|
else
|
||||||
|
return Integer.toString(componentID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -372,7 +372,8 @@ class ConnectivityCheckClient
|
|||||||
validRemoteCandidate);
|
validRemoteCandidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
parentAgent.validatePair(validPair);
|
if(! validPair.isValid())
|
||||||
|
parentAgent.validatePair(validPair);
|
||||||
|
|
||||||
//The agent sets the state of the pair that *generated* the check to
|
//The agent sets the state of the pair that *generated* the check to
|
||||||
//Succeeded. Note that, the pair which *generated* the check may be
|
//Succeeded. Note that, the pair which *generated* the check may be
|
||||||
@ -532,9 +533,8 @@ class ConnectivityCheckClient
|
|||||||
CandidatePair pair = ((CandidatePair)event.getTransactionID()
|
CandidatePair pair = ((CandidatePair)event.getTransactionID()
|
||||||
.getApplicationData());
|
.getApplicationData());
|
||||||
logger.fine("timeout for pair=" + pair);
|
logger.fine("timeout for pair=" + pair);
|
||||||
System.out.println("timeout for pair=" + pair);
|
|
||||||
pair.setStateFailed();
|
|
||||||
|
|
||||||
|
pair.setStateFailed();
|
||||||
updateCheckListAndTimerStates(pair);
|
updateCheckListAndTimerStates(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,7 +611,6 @@ System.out.println("timeout for pair=" + pair);
|
|||||||
while(isRunning)
|
while(isRunning)
|
||||||
{
|
{
|
||||||
long waitFor = getNextWaitInterval();
|
long waitFor = getNextWaitInterval();
|
||||||
System.out.println("will wait for " + waitFor + " active clist cound="+parentClient.parentAgent.getActiveCheckListCount());
|
|
||||||
|
|
||||||
if(waitFor > 0)
|
if(waitFor > 0)
|
||||||
{
|
{
|
||||||
@ -636,32 +635,20 @@ System.out.println("will wait for " + waitFor + " active clist cound="+parentCli
|
|||||||
//if there are no triggered checks, go for an ordinary one.
|
//if there are no triggered checks, go for an ordinary one.
|
||||||
if(pairToCheck == null)
|
if(pairToCheck == null)
|
||||||
{
|
{
|
||||||
System.out.println("checklist " + checkList.getName() + " did not return triggered check");
|
|
||||||
pairToCheck = checkList.getNextOrdinaryPairToCheck();
|
pairToCheck = checkList.getNextOrdinaryPairToCheck();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
System.out.println("checklist " + checkList.getName() + " returned triggered check");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(pairToCheck != null)
|
if(pairToCheck != null)
|
||||||
{
|
{
|
||||||
System.out.println("checklist " + checkList.getName() + " returned regular check in state " + pairToCheck.getState());
|
|
||||||
transactionID = parentClient.startCheckForPair(pairToCheck);
|
transactionID = parentClient.startCheckForPair(pairToCheck);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.fine("checklist " + checkList.getName() + " ran out of checks");
|
|
||||||
//we are done sending checks for this list. we'll set its
|
//we are done sending checks for this list. we'll set its
|
||||||
//final state in either the processResponse()
|
//final state in either the processResponse()
|
||||||
//processTimeout() or processFailure() method.
|
//processTimeout() or processFailure() method.
|
||||||
|
|
||||||
logger.finest("finished a checklist");
|
logger.finest("will skip a check beat.");
|
||||||
//maybe do this if the list is in the completed state.
|
|
||||||
//isRunning = false;
|
|
||||||
//break;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,4 +662,28 @@ logger.fine("checklist " + checkList.getName() + " ran out of checks");
|
|||||||
parentClient.paceMakers.remove(this);
|
parentClient.paceMakers.remove(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops and removes all PaceMakers.
|
||||||
|
*/
|
||||||
|
public void stop()
|
||||||
|
{
|
||||||
|
synchronized (paceMakers)
|
||||||
|
{
|
||||||
|
Iterator<PaceMaker> paceMakersIter = paceMakers.iterator();
|
||||||
|
while(paceMakersIter.hasNext())
|
||||||
|
{
|
||||||
|
PaceMaker paceMaker = paceMakersIter.next();
|
||||||
|
|
||||||
|
paceMaker.isRunning = false;
|
||||||
|
synchronized(paceMaker)
|
||||||
|
{
|
||||||
|
|
||||||
|
paceMaker.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
paceMakersIter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -354,4 +354,12 @@ class ConnectivityCheckServer
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops this server.
|
||||||
|
*/
|
||||||
|
public void stop()
|
||||||
|
{
|
||||||
|
StunStack.getInstance().removeRequestListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -557,7 +557,8 @@ public class IceMediaStream
|
|||||||
synchronized (validList)
|
synchronized (validList)
|
||||||
{
|
{
|
||||||
pair.validate();
|
pair.validate();
|
||||||
validList.add(pair);
|
if(!validList.contains(pair))
|
||||||
|
validList.add(pair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,11 +28,6 @@ public class Ice
|
|||||||
*/
|
*/
|
||||||
static long startTime;
|
static long startTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* Our local agent.
|
|
||||||
*/
|
|
||||||
static Agent localAgent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the test
|
* Runs the test
|
||||||
* @param args command line arguments
|
* @param args command line arguments
|
||||||
@ -43,7 +38,7 @@ public class Ice
|
|||||||
{
|
{
|
||||||
startTime = System.currentTimeMillis();
|
startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
localAgent = createAgent(9090);
|
Agent localAgent = createAgent(9090);
|
||||||
Agent remotePeer = createAgent(6060);
|
Agent remotePeer = createAgent(6060);
|
||||||
|
|
||||||
localAgent.addStateChangeListener(new IceProcessingListener());
|
localAgent.addStateChangeListener(new IceProcessingListener());
|
||||||
@ -103,9 +98,30 @@ public class Ice
|
|||||||
if(evt.getNewValue() == IceProcessingState.COMPLETED
|
if(evt.getNewValue() == IceProcessingState.COMPLETED
|
||||||
|| evt.getNewValue() == IceProcessingState.FAILED)
|
|| evt.getNewValue() == IceProcessingState.FAILED)
|
||||||
{
|
{
|
||||||
System.out.println("Total execution time: "
|
System.out.println("Total ICE processing time: "
|
||||||
+ (processingEndTime - startTime) + "ms");
|
+ (processingEndTime - startTime) + "ms");
|
||||||
//IceMediaStream mediaStream = localAgent.
|
Agent agent = (Agent)evt.getSource();
|
||||||
|
List<IceMediaStream> streams = agent.getStreams();
|
||||||
|
|
||||||
|
for(IceMediaStream stream : streams)
|
||||||
|
{
|
||||||
|
String streamName = stream.getName();
|
||||||
|
System.out.println("Pairs selected for stream: "
|
||||||
|
+ streamName);
|
||||||
|
List<Component> components = stream.getComponents();
|
||||||
|
|
||||||
|
for(Component cmp : components)
|
||||||
|
{
|
||||||
|
String cmpName = cmp.getName();
|
||||||
|
System.out.println(cmpName + ": "
|
||||||
|
+ cmp.getSelectedPair());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(evt.getNewValue() == IceProcessingState.TERMINATED)
|
||||||
|
{
|
||||||
|
System.out.println("ICE Agent was terminated.");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user