From 81d887f468f22cc253931ae380ec17fab6ac7da5 Mon Sep 17 00:00:00 2001 From: emcho Date: Sun, 28 Feb 2010 16:13:06 +0000 Subject: [PATCH] Adds Stream accessor methods to our ICE Agent --- src/org/ice4j/ice/Agent.java | 40 +++++++++++++++++++ src/org/ice4j/ice/Component.java | 6 ++- src/org/ice4j/ice/RemoteCandidate.java | 53 ++++++++++++++++++++++++++ test/test/Ice.java | 14 +++++-- 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 src/org/ice4j/ice/RemoteCandidate.java diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index efb719f..670e5b8 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -257,4 +257,44 @@ public class Agent return password; } + /** + * Returns the IceMediaStream with the specified name or + * null if no such stream has been registered with this + * Agent yet. + * + * @param name the name of the stream that we'd like to obtain a reference + * to. + * + * @return the IceMediaStream with the specified name or + * null if no such stream has been registered with this + * Agent yet. + */ + public IceMediaStream getMediaStream(String name) + { + return mediaStreams.get(name); + } + + /** + * Returns a List containing the names of all currently registered + * media streams. + * + * @return a List containing the names of all currently registered + * media streams. + */ + public List getMediaStreamNames() + { + return new LinkedList(mediaStreams.keySet()); + } + + /** + * Returns a List containing all IceMediaStreams currently + * registered with this agent. + * + * @return a List containing all IceMediaStreams currently + * registered with this agent. + */ + public List getMediaStreams() + { + return new LinkedList(mediaStreams.values()); + } } diff --git a/src/org/ice4j/ice/Component.java b/src/org/ice4j/ice/Component.java index 4a92b97..a12b995 100644 --- a/src/org/ice4j/ice/Component.java +++ b/src/org/ice4j/ice/Component.java @@ -108,11 +108,13 @@ public class Component } /** - * Add a local candidate to this component. + * Add a local candidate to this component. The method has package access + * because local candidates can only be created and added by the candidate + * harvesters registered with the agent. * * @param candidate the candidate object to be added */ - public void addLocalCandidate(Candidate candidate) + protected void addLocalCandidate(Candidate candidate) { synchronized(localCandidates) { diff --git a/src/org/ice4j/ice/RemoteCandidate.java b/src/org/ice4j/ice/RemoteCandidate.java new file mode 100644 index 0000000..97c4713 --- /dev/null +++ b/src/org/ice4j/ice/RemoteCandidate.java @@ -0,0 +1,53 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package org.ice4j.ice; + +import java.net.*; + +import org.ice4j.*; + +/** + * RemoteCandidates are candidates that an agent received in an offer + * or an answer from its peer, and that it would use to form candidate pairs + * after combining them with its local candidates. + * + * @author Emil Ivov + */ +public class RemoteCandidate + extends Candidate +{ + + /** + * Creates a RemoteCandidate instance for the specified transport + * address and properties. + * + * @param transportAddress the transport address that this candidate is + * encapsulating. + * @param parentComponent the Component that this candidate + * belongs to. + * @param type the CandidateType for this Candidate. + */ + public RemoteCandidate(TransportAddress transportAddress, + Component parentComponent, + CandidateType type) + { + super(transportAddress, parentComponent, type); + } + + /** + * Always returns null since remote candidates do not have a + * DatagramSocket associated with them. + * + * @return null + */ + public DatagramSocket getSocket() + { + return null; + } + +} diff --git a/test/test/Ice.java b/test/test/Ice.java index dffe741..bdcf061 100644 --- a/test/test/Ice.java +++ b/test/test/Ice.java @@ -24,11 +24,17 @@ public class Ice { /** * Runs the test - * @param args cmd line args + * @param args command line arguments * * @throws Throwable if bad stuff happens. */ public static void main(String[] args) throws Throwable + { + Agent agent1 = createAgent(9090); + } + + private static Agent createAgent(int rtpPort) + throws Throwable { Agent agent = new Agent(); @@ -49,7 +55,7 @@ public class Ice long startTime = System.currentTimeMillis(); //rtp Component rtpComp = agent.createComponent( - stream, Transport.UDP, 9090, 9090, 10000); + stream, Transport.UDP, rtpPort, rtpPort, rtpPort + 100); System.out.println("rtpComp:" + rtpComp); long endTime = System.currentTimeMillis(); System.out.println("Component created in " @@ -57,12 +63,14 @@ public class Ice startTime = endTime; //rtcpComp Component rtcpComp = agent.createComponent( - stream, Transport.UDP, 9091, 9090, 10000); + stream, Transport.UDP, rtpPort + 1, rtpPort + 1, rtpPort + 101); System.out.println("rtcpComp:" + rtcpComp); endTime = System.currentTimeMillis(); System.out.println("Component created in " + (endTime - startTime) +" ms\n"); + + return agent; } /**