Adds basic support for freeing candidates, components and streams.
This commit is contained in:
parent
48dde7ea8c
commit
c00e6de61f
@ -385,6 +385,22 @@ public class Agent
|
|||||||
this.isControlling = isControlling;
|
this.isControlling = isControlling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes <tt>stream</tt> and all its child <tt>Component</tt>s and
|
||||||
|
* <tt>Candidate</tt>s from the this agent and releases all resources that
|
||||||
|
* they had allocated (like sockets for example)
|
||||||
|
*
|
||||||
|
* @param stream the <tt>Component</tt> we'd like to remove and free.
|
||||||
|
*/
|
||||||
|
public void removeStream(IceMediaStream stream)
|
||||||
|
{
|
||||||
|
synchronized (mediaStreams)
|
||||||
|
{
|
||||||
|
mediaStreams.remove(stream.getName());
|
||||||
|
stream.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether this agent has the controlling role in an ICE
|
* Determines whether this agent has the controlling role in an ICE
|
||||||
* exchange.
|
* exchange.
|
||||||
|
|||||||
@ -65,7 +65,7 @@ public abstract class Candidate
|
|||||||
* determine the order of the connectivity checks and the relative
|
* determine the order of the connectivity checks and the relative
|
||||||
* preference for candidates.
|
* preference for candidates.
|
||||||
*/
|
*/
|
||||||
private long priority = 0;
|
protected long priority = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies whether the address associated with this candidate belongs to
|
* Specifies whether the address associated with this candidate belongs to
|
||||||
|
|||||||
@ -67,7 +67,8 @@ public class Component
|
|||||||
/**
|
/**
|
||||||
* The list locally gathered candidates for this media stream.
|
* The list locally gathered candidates for this media stream.
|
||||||
*/
|
*/
|
||||||
private List<Candidate> localCandidates = new LinkedList<Candidate>();
|
private List<LocalCandidate> localCandidates
|
||||||
|
= new LinkedList<LocalCandidate>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of candidates that the peer agent sent for this stream.
|
* The list of candidates that the peer agent sent for this stream.
|
||||||
@ -114,7 +115,7 @@ public class Component
|
|||||||
*
|
*
|
||||||
* @param candidate the candidate object to be added
|
* @param candidate the candidate object to be added
|
||||||
*/
|
*/
|
||||||
public void addLocalCandidate(Candidate candidate)
|
public void addLocalCandidate(LocalCandidate candidate)
|
||||||
{
|
{
|
||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
{
|
{
|
||||||
@ -211,7 +212,7 @@ public class Component
|
|||||||
*
|
*
|
||||||
* @param candidates a <tt>List</tt> of candidates to be added
|
* @param candidates a <tt>List</tt> of candidates to be added
|
||||||
*/
|
*/
|
||||||
public void addLocalCandidates(List<Candidate> candidates)
|
public void addLocalCandidates(List<LocalCandidate> candidates)
|
||||||
{
|
{
|
||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
{
|
{
|
||||||
@ -301,6 +302,7 @@ public class Component
|
|||||||
|
|
||||||
if(localCandidatesCount > 0)
|
if(localCandidatesCount > 0)
|
||||||
{
|
{
|
||||||
|
buff.append("\nDefault Candidate: " + getDefaultCandidate());
|
||||||
buff.append("\n" + localCandidatesCount + " local candidates:");
|
buff.append("\n" + localCandidatesCount + " local candidates:");
|
||||||
|
|
||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
@ -310,8 +312,6 @@ public class Component
|
|||||||
buff.append("\n" + cand.toString());
|
buff.append("\n" + cand.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buff.append("\nDefault Candidate: " + getDefaultCandidate());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -349,7 +349,8 @@ public class Component
|
|||||||
{
|
{
|
||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
{
|
{
|
||||||
Candidate[] candidates = new Candidate[localCandidates.size()];
|
LocalCandidate[] candidates
|
||||||
|
= new LocalCandidate[localCandidates.size()];
|
||||||
localCandidates.toArray(candidates);
|
localCandidates.toArray(candidates);
|
||||||
|
|
||||||
//first compute the actual priorities
|
//first compute the actual priorities
|
||||||
@ -363,7 +364,7 @@ public class Component
|
|||||||
|
|
||||||
//now re-add the candidates in the order they've been sorted in.
|
//now re-add the candidates in the order they've been sorted in.
|
||||||
localCandidates.clear();
|
localCandidates.clear();
|
||||||
for (Candidate cand : candidates)
|
for (LocalCandidate cand : candidates)
|
||||||
localCandidates.add(cand);
|
localCandidates.add(cand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,7 +447,8 @@ public class Component
|
|||||||
//base as cand and a lower priority.
|
//base as cand and a lower priority.
|
||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
{
|
{
|
||||||
Iterator<Candidate> localCandsIter = localCandidates.iterator();
|
Iterator<LocalCandidate> localCandsIter
|
||||||
|
= localCandidates.iterator();
|
||||||
|
|
||||||
while (localCandsIter.hasNext())
|
while (localCandsIter.hasNext())
|
||||||
{
|
{
|
||||||
@ -499,7 +501,8 @@ public class Component
|
|||||||
{
|
{
|
||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
{
|
{
|
||||||
Iterator<Candidate> localCandsIter = localCandidates.iterator();
|
Iterator<LocalCandidate> localCandsIter
|
||||||
|
= localCandidates.iterator();
|
||||||
|
|
||||||
while (localCandsIter.hasNext())
|
while (localCandsIter.hasNext())
|
||||||
{
|
{
|
||||||
@ -519,4 +522,22 @@ public class Component
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases all resources allocated by this <tt>Component</tt> and its
|
||||||
|
* <tt>Candidate</tt>s like sockets for example.
|
||||||
|
*/
|
||||||
|
protected void free()
|
||||||
|
{
|
||||||
|
synchronized (localCandidates)
|
||||||
|
{
|
||||||
|
Iterator<LocalCandidate> cndIter = localCandidates.iterator();
|
||||||
|
while( cndIter.hasNext())
|
||||||
|
{
|
||||||
|
LocalCandidate candidate = cndIter.next();
|
||||||
|
candidate.free();
|
||||||
|
cndIter.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,9 +116,7 @@ public class IceMediaStream
|
|||||||
List<Component> components = getComponents();
|
List<Component> components = getComponents();
|
||||||
for (Component cmp : components)
|
for (Component cmp : components)
|
||||||
{
|
{
|
||||||
buff.append("Component ").append(cmp.getComponentID())
|
buff.append("\n").append(cmp);
|
||||||
.append(" :\n");
|
|
||||||
buff.append(cmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return buff.toString();
|
return buff.toString();
|
||||||
@ -210,4 +208,39 @@ public class IceMediaStream
|
|||||||
{
|
{
|
||||||
return parentAgent;
|
return parentAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes this stream and all <tt>Candidate</tt>s associated with its child
|
||||||
|
* <tt>Component</tt>s.
|
||||||
|
*/
|
||||||
|
protected void free()
|
||||||
|
{
|
||||||
|
synchronized (components)
|
||||||
|
{
|
||||||
|
Iterator<Map.Entry<Integer, Component>> cmpEntries
|
||||||
|
= components.entrySet().iterator();
|
||||||
|
while (cmpEntries.hasNext())
|
||||||
|
{
|
||||||
|
Component component = cmpEntries.next().getValue();
|
||||||
|
component.free();
|
||||||
|
cmpEntries.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes <tt>component</tt> and all its <tt>Candidate</tt>s from the
|
||||||
|
* this stream and releases all associated resources that they had
|
||||||
|
* allocated (like sockets for example)
|
||||||
|
*
|
||||||
|
* @param component the <tt>Component</tt> we'd like to remove and free.
|
||||||
|
*/
|
||||||
|
public void removeComponent(Component component)
|
||||||
|
{
|
||||||
|
synchronized (components)
|
||||||
|
{
|
||||||
|
components.remove(component.getComponentID());
|
||||||
|
component.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,4 +45,13 @@ public abstract class LocalCandidate
|
|||||||
* <tt>Candidate</tt>
|
* <tt>Candidate</tt>
|
||||||
*/
|
*/
|
||||||
public abstract DatagramSocket getSocket();
|
public abstract DatagramSocket getSocket();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees resources allocated by this candidate such as its
|
||||||
|
* <tt>DatagramSocket</tt> for example.
|
||||||
|
*/
|
||||||
|
protected void free()
|
||||||
|
{
|
||||||
|
getSocket().close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import java.net.*;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,11 +29,34 @@ public class RemoteCandidate
|
|||||||
* @param parentComponent the <tt>Component</tt> that this candidate
|
* @param parentComponent the <tt>Component</tt> that this candidate
|
||||||
* belongs to.
|
* belongs to.
|
||||||
* @param type the <tt>CandidateType</tt> for this <tt>Candidate</tt>.
|
* @param type the <tt>CandidateType</tt> for this <tt>Candidate</tt>.
|
||||||
|
* @param foundation the <tt>RemoteCandidate</tt>'s foundation as reported
|
||||||
|
* by the session description protocol.
|
||||||
|
* @param priority the <tt>RemoteCandidate</tt>'s priority as reported
|
||||||
|
* by the session description protocol.
|
||||||
*/
|
*/
|
||||||
public RemoteCandidate(TransportAddress transportAddress,
|
public RemoteCandidate(TransportAddress transportAddress,
|
||||||
Component parentComponent,
|
Component parentComponent,
|
||||||
CandidateType type)
|
CandidateType type,
|
||||||
|
String foundation,
|
||||||
|
long priority)
|
||||||
{
|
{
|
||||||
super(transportAddress, parentComponent, type);
|
super(transportAddress, parentComponent, type);
|
||||||
|
super.setFoundation(foundation);
|
||||||
|
setPriority(priority);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the priority of this <tt>RemoteCandidate</tt>. Priority is a unique
|
||||||
|
* priority number that MUST be a positive integer between 1 and
|
||||||
|
* (2**32 - 1). This priority will be set and used by ICE algorithms to
|
||||||
|
* determine the order of the connectivity checks and the relative
|
||||||
|
* preference for candidates.
|
||||||
|
*
|
||||||
|
* @param priority the priority number between 1 and (2**32 - 1).
|
||||||
|
*/
|
||||||
|
public void setPriority(long priority)
|
||||||
|
{
|
||||||
|
super.priority = priority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user