Supports running an Agent without any remote candidates.

This commit is contained in:
boris 2015-01-22 16:12:07 +00:00
parent d9e14a6ba7
commit 50dd346aaf
3 changed files with 49 additions and 15 deletions

View File

@ -535,18 +535,40 @@ public class Agent
*/ */
private void pruneNonMatchedStreams() private void pruneNonMatchedStreams()
{ {
// The previous behavior allows users of ice4j to run an Agent with
// remote candidates for only some of the streams/components, in which
// case the component without remote candidates are removed here, and
// so they do not cause an ICE failure if they fail to connect.
// In order to allow operation without remote candidates, we only prune
// if we detect that there is at least one component with some remote
// candidates.
boolean prune = false;
for (IceMediaStream stream : getStreams()) for (IceMediaStream stream : getStreams())
{ {
for(Component cmp : stream.getComponents()) for (Component component : stream.getComponents())
{ {
if(cmp.getRemoteCandidateCount() == 0) if (component.getRemoteCandidateCount() > 0)
stream.removeComponent(cmp); prune = true;
if (prune)
break;
}
}
if (prune)
{
for (IceMediaStream stream : getStreams())
{
for (Component component : stream.getComponents())
{
if (component.getRemoteCandidateCount() == 0)
stream.removeComponent(component);
} }
if (stream.getComponentCount() == 0) if (stream.getComponentCount() == 0)
removeStream(stream); removeStream(stream);
} }
} }
}
/** /**
* Indicates whether this {@link Agent} is currently in the process of * Indicates whether this {@link Agent} is currently in the process of
@ -681,13 +703,17 @@ public class Agent
//first init the check list. //first init the check list.
List<IceMediaStream> streams List<IceMediaStream> streams
= getStreamsWithPendingConnectivityEstablishment(); = getStreamsWithPendingConnectivityEstablishment();
int streamCount = streams.size();
//init the maximum number of check list entries per stream. //init the maximum number of check list entries per stream.
int maxCheckListSize = Integer.getInteger( int maxCheckListSize = Integer.getInteger(
StackProperties.MAX_CHECK_LIST_SIZE, StackProperties.MAX_CHECK_LIST_SIZE,
DEFAULT_MAX_CHECK_LIST_SIZE); DEFAULT_MAX_CHECK_LIST_SIZE);
int maxPerStreamSize = maxCheckListSize / streams.size(); int maxPerStreamSize =
streamCount == 0
? 0
: maxCheckListSize / streamCount;
for(IceMediaStream stream : streams) for(IceMediaStream stream : streams)
{ {
@ -697,6 +723,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
if (streamCount > 0)
streams.get(0).getCheckList().computeInitialCheckListPairStates(); streams.get(0).getCheckList().computeInitialCheckListPairStates();
} }

View File

@ -76,14 +76,21 @@ class ConnectivityCheckClient
*/ */
public void startChecks() public void startChecks()
{ {
CheckList firstCheckList List<IceMediaStream> streamsWithPendingConnectivityEstablishment
= parentAgent = parentAgent.getStreamsWithPendingConnectivityEstablishment();
.getStreamsWithPendingConnectivityEstablishment()
.get(0)
.getCheckList();
if (streamsWithPendingConnectivityEstablishment.size() > 0)
{
logger.info("Start connectivity checks!"); logger.info("Start connectivity checks!");
startChecks(firstCheckList); startChecks(
streamsWithPendingConnectivityEstablishment
.get(0).getCheckList());
}
else
{
logger.info("Not starting any checks, because there are no pending "
+ "streams.");
}
} }
/** /**

View File

@ -296,7 +296,7 @@ public class IceMediaStream
* same as when freeing the components inside the synchronized block * same as when freeing the components inside the synchronized block
* because in the latter case an exception thrown by Component#free() * because in the latter case an exception thrown by Component#free()
* will leave subsequent components in IceMediaStream#componenets. But * will leave subsequent components in IceMediaStream#componenets. But
* there is no idication that such behaviour is expected. * there is no indication that such behaviour is expected.
*/ */
for (Component component : components) for (Component component : components)
component.free(); component.free();