diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/media/JingleMediaManager.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/media/JingleMediaManager.java index 59ac842f6..06c90eb1c 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/media/JingleMediaManager.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/media/JingleMediaManager.java @@ -36,42 +36,17 @@ import java.util.List; */ public abstract class JingleMediaManager { - private List payloads = new ArrayList(); - /** * Return all supported Payloads for this Manager * * @return The Payload List */ - public List getPayloads() { - return payloads; - } - - /** - * Adds a supported Payload type to Manager - * - * @param payloadType - */ - public void addPayloadType(PayloadType payloadType) { - payloads.add(payloadType); - } - - /** - * Removes a supported Payload type from Manager - * - * @param payloadType - */ - public void removePayloadType(PayloadType payloadType) { - payloads.remove(payloadType); - } + public abstract List getPayloads(); /** * Get the preferred Payload Type */ - public PayloadType getPreferredPayloadType() { - //TODO a better way to choose the preferred Payload - return payloads.size() > 0 ? payloads.get(0) : null; - } + public abstract PayloadType getPreferredPayloadType(); /** * Create a Media Session Implementation diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java index a34abc8a8..6cf3dd61f 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/JingleManagerTest.java @@ -74,6 +74,7 @@ import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.util.ArrayList; +import java.util.List; /** * Test the Jingle extension using the high level API @@ -706,33 +707,7 @@ public class JingleManagerTest extends SmackTestCase { // JingleManager jm1 = new JingleSessionManager( // x1, new ICEResolver()); - JingleMediaManager jingleMediaManager = new JingleMediaManager() { - // Media Session Implementation - public JingleMediaSession createMediaSession(final PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local) { - return new JingleMediaSession(payloadType, remote, local) { - - public void initialize() { - } - - public void startTrasmit() { - } - - public void startReceive() { - } - - public void setTrasmit(boolean active) { - } - - public void stopTrasmit() { - } - - public void stopReceive() { - } - }; - } - }; - - jingleMediaManager.addPayloadType(new PayloadType.Audio(3, "GSM", 1, 16000)); + JingleMediaManager jingleMediaManager = new JmfMediaManager(); jm0.setMediaManager(jingleMediaManager); jm1.setMediaManager(jingleMediaManager); @@ -746,32 +721,27 @@ public class JingleManagerTest extends SmackTestCase { session.addListener(new JingleSessionListener() { public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. incCounter(); System.out.println("Establish In"); } public void sessionDeclined(String reason, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. } public void sessionRedirected(String redirection, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. } public void sessionClosed(String reason, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. } public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { - //To change body of implemented methods use File | Settings | File Templates. } }); session.start(); } catch (XMPPException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); } } @@ -874,9 +844,17 @@ public class JingleManagerTest extends SmackTestCase { } }; } - }; - jingleMediaManager.addPayloadType(new PayloadType.Audio(3, "GSM", 1, 16000)); + public List getPayloads() { + return new ArrayList(); + } + + public PayloadType getPreferredPayloadType() { + return null; + } + + + }; jm0.setMediaManager(jingleMediaManager); jm1.setMediaManager(jingleMediaManager); @@ -891,7 +869,7 @@ public class JingleManagerTest extends SmackTestCase { session.start(request); } catch (XMPPException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); } } diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java index 577fc5d09..620652241 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/BridgedResolverTest.java @@ -65,106 +65,6 @@ public class BridgedResolverTest extends SmackTestCase { assertTrue(valCounter() == 3); } - public void testFullBridge() { - resetCounter(); - - try { - - //XMPPConnection.DEBUG_ENABLED = true; - - XMPPConnection x0 = new XMPPConnection("thiago"); - XMPPConnection x1 = new XMPPConnection("thiago"); - - x0.connect(); - x0.login("barata7", "barata7"); - x1.connect(); - x1.login("barata6", "barata6"); - - final JingleManager jm0 = new JingleManager( - x0, new BridgedResolver(x0)); - final JingleManager jm1 = new JingleManager( - x1, new BridgedResolver(x1)); - - JingleMediaManager jingleMediaManager = new JingleMediaManager() { - // Media Session Implementation - public JingleMediaSession createMediaSession(final PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local) { - return new JingleMediaSession(payloadType, remote, local) { - - public void initialize() { - - } - - public void startTrasmit() { - incCounter(); - - System.out.print("IPs:"); - System.out.println(local.getSymmetric().getIp()); - System.out.println(local.getIp()); - - System.out.println("Transmit"); - } - - public void startReceive() { - incCounter(); - System.out.println("Receive"); - } - - public void setTrasmit(boolean active) { - } - - public void stopTrasmit() { - incCounter(); - System.out.println("Stop Transmit"); - } - - public void stopReceive() { - incCounter(); - System.out.println("Stop Receive"); - } - }; - } - }; - - jingleMediaManager.addPayloadType(new PayloadType.Audio(3, "GSM", 1, 16000)); - - jm0.setMediaManager(jingleMediaManager); - jm1.setMediaManager(jingleMediaManager); - - jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { - public void sessionRequested(final JingleSessionRequest request) { - - try { - - IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); - - session.start(request); - } catch (XMPPException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - - } - }); - - OutgoingJingleSession js0 = jm0.createOutgoingJingleSession("barata6@thiago/Smack"); - - js0.start(); - - Thread.sleep(10000); - js0.terminate(); - - Thread.sleep(3000); - - System.out.println(valCounter()); - - assertTrue(valCounter() == 8); - //Thread.sleep(15000); - - } catch (Exception e) { - e.printStackTrace(); - } - - } - protected int getMaxConnections() { return 1; } diff --git a/jingle/media/source/org/jivesoftware/jingleaudio/jmf/AudioMediaSession.java b/jingle/media/source/org/jivesoftware/jingleaudio/jmf/AudioMediaSession.java index af163af7d..c0dfc7b2a 100644 --- a/jingle/media/source/org/jivesoftware/jingleaudio/jmf/AudioMediaSession.java +++ b/jingle/media/source/org/jivesoftware/jingleaudio/jmf/AudioMediaSession.java @@ -38,7 +38,6 @@ import java.net.ServerSocket; * To receive you MUST transmit. So the only implemented and functionally methods are startTransmit() and stopTransmit() * * @author Thiago Camargo - * */ public class AudioMediaSession extends JingleMediaSession { @@ -130,7 +129,8 @@ public class AudioMediaSession extends JingleMediaSession { * Stops transmission and for NAT Traversal reasons stop receiving also. */ public void stopTrasmit() { - audioChannel.stop(); + if (audioChannel != null) + audioChannel.stop(); } /** diff --git a/jingle/media/source/org/jivesoftware/jingleaudio/jmf/JmfMediaManager.java b/jingle/media/source/org/jivesoftware/jingleaudio/jmf/JmfMediaManager.java index 6c8167bad..d99913922 100644 --- a/jingle/media/source/org/jivesoftware/jingleaudio/jmf/JmfMediaManager.java +++ b/jingle/media/source/org/jivesoftware/jingleaudio/jmf/JmfMediaManager.java @@ -28,6 +28,8 @@ import org.jivesoftware.jingleaudio.JMFInit; import java.io.File; import java.io.IOException; +import java.util.List; +import java.util.ArrayList; /** * Implements a jingleMediaManager using JMF based API. @@ -38,6 +40,8 @@ import java.io.IOException; */ public class JmfMediaManager extends JingleMediaManager { + private List payloads = new ArrayList(); + /** * Creates a Media Manager instance */ @@ -62,8 +66,25 @@ public class JmfMediaManager extends JingleMediaManager { * Setup API supported Payloads */ private void setupPayloads() { - this.addPayloadType(new PayloadType.Audio(3, "gsm")); - this.addPayloadType(new PayloadType.Audio(4, "g723")); + payloads.add(new PayloadType.Audio(3, "gsm")); + payloads.add(new PayloadType.Audio(4, "g723")); + } + + /** + * Return all supported Payloads for this Manager + * + * @return The Payload List + */ + public List getPayloads() { + return payloads; + } + + /** + * Get the preferred Payload Type + */ + public PayloadType getPreferredPayloadType() { + //TODO a better way to choose the preferred Payload + return payloads.size() > 0 ? payloads.get(0) : null; } /** @@ -71,47 +92,40 @@ public class JmfMediaManager extends JingleMediaManager { * devices are properly detected and initialized by JMF. */ public static void setupJMF() { - try { + // .jmf is the place where we store the jmf.properties file used + // by JMF. if the directory does not exist or it does not contain + // a jmf.properties file. or if the jmf.properties file has 0 length + // then this is the first time we're running and should continue to + // with JMFInit + String homeDir = System.getProperty("user.home"); + File jmfDir = new File(homeDir, ".jmf"); + String classpath = System.getProperty("java.class.path"); + classpath += System.getProperty("path.separator") + + jmfDir.getAbsolutePath(); + System.setProperty("java.class.path", classpath); - // .jmf is the place where we store the jmf.properties file used - // by JMF. if the directory does not exist or it does not contain - // a jmf.properties file. or if the jmf.properties file has 0 length - // then this is the first time we're running and should continue to - // with JMFInit - String homeDir = System.getProperty("user.home"); - File jmfDir = new File(homeDir, ".jmf"); - String classpath = System.getProperty("java.class.path"); - classpath += System.getProperty("path.separator") - + jmfDir.getAbsolutePath(); - System.setProperty("java.class.path", classpath); + if (!jmfDir.exists()) + jmfDir.mkdir(); - if (!jmfDir.exists()) - jmfDir.mkdir(); + File jmfProperties = new File(jmfDir, "jmf.properties"); - File jmfProperties = new File(jmfDir, "jmf.properties"); - - if (!jmfProperties.exists()) { - try { - jmfProperties.createNewFile(); - } - catch (IOException ex) { - System.out.println("Failed to create jmf.properties"); - ex.printStackTrace(); - } + if (!jmfProperties.exists()) { + try { + jmfProperties.createNewFile(); + } + catch (IOException ex) { + System.out.println("Failed to create jmf.properties"); + ex.printStackTrace(); } - - // if we're running on linux checkout that libjmutil.so is where it - // should be and put it there. - runLinuxPreInstall(); - - //if (jmfProperties.length() == 0) { - JMFInit init = new JMFInit(null, false); - //} - } - finally { - } + // if we're running on linux checkout that libjmutil.so is where it + // should be and put it there. + runLinuxPreInstall(); + + //if (jmfProperties.length() == 0) { + new JMFInit(null, false); + //} } diff --git a/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/AudioMediaSession.java b/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/AudioMediaSession.java index e274247c3..5169fd127 100644 --- a/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/AudioMediaSession.java +++ b/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/AudioMediaSession.java @@ -170,7 +170,8 @@ public class AudioMediaSession extends JingleMediaSession implements MediaSessio * Stops transmission and for NAT Traversal reasons stop receiving also. */ public void stopTrasmit() { - mediaSession.close(); + if (mediaSession != null) + mediaSession.close(); } /** @@ -181,15 +182,12 @@ public class AudioMediaSession extends JingleMediaSession implements MediaSessio } public void newStreamIdentified(StreamPlayer streamPlayer) { - //To change body of implemented methods use File | Settings | File Templates. } public void senderReportReceived(SenderReport report) { - //To change body of implemented methods use File | Settings | File Templates. } public void streamClosed(StreamPlayer stream, boolean timeout) { - //To change body of implemented methods use File | Settings | File Templates. } /** diff --git a/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/SpeexMediaManager.java b/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/SpeexMediaManager.java index ceb81b690..4af896133 100644 --- a/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/SpeexMediaManager.java +++ b/jingle/media/source/org/jivesoftware/jingleaudio/jspeex/SpeexMediaManager.java @@ -27,6 +27,8 @@ import org.jivesoftware.jingleaudio.JMFInit; import java.io.File; import java.io.IOException; +import java.util.List; +import java.util.ArrayList; /** * Implements a jingleMediaManager using JMF based API and JSpeex. @@ -37,6 +39,8 @@ import java.io.IOException; */ public class SpeexMediaManager extends JingleMediaManager { + private List payloads = new ArrayList(); + public SpeexMediaManager() { setupPayloads(); setupJMF(); @@ -50,7 +54,23 @@ public class SpeexMediaManager extends JingleMediaManager { * Setup API supported Payloads */ private void setupPayloads() { - this.addPayloadType(new PayloadType.Audio(15, "speex")); + payloads.add(new PayloadType.Audio(15, "speex")); + } + + /** + * Return all supported Payloads for this Manager + * + * @return The Payload List + */ + public List getPayloads() { + return payloads; + } + + /** + * Get the preferred Payload Type + */ + public PayloadType getPreferredPayloadType() { + return payloads.size() > 0 ? payloads.get(0) : null; } /** @@ -58,46 +78,39 @@ public class SpeexMediaManager extends JingleMediaManager { * devices are properly detected and initialized by JMF. */ public static void setupJMF() { - try { + // .jmf is the place where we store the jmf.properties file used + // by JMF. if the directory does not exist or it does not contain + // a jmf.properties file. or if the jmf.properties file has 0 length + // then this is the first time we're running and should continue to + // with JMFInit + String homeDir = System.getProperty("user.home"); + File jmfDir = new File(homeDir, ".jmf"); + String classpath = System.getProperty("java.class.path"); + classpath += System.getProperty("path.separator") + + jmfDir.getAbsolutePath(); + System.setProperty("java.class.path", classpath); - // .jmf is the place where we store the jmf.properties file used - // by JMF. if the directory does not exist or it does not contain - // a jmf.properties file. or if the jmf.properties file has 0 length - // then this is the first time we're running and should continue to - // with JMFInit - String homeDir = System.getProperty("user.home"); - File jmfDir = new File(homeDir, ".jmf"); - String classpath = System.getProperty("java.class.path"); - classpath += System.getProperty("path.separator") - + jmfDir.getAbsolutePath(); - System.setProperty("java.class.path", classpath); + if (!jmfDir.exists()) + jmfDir.mkdir(); - if (!jmfDir.exists()) - jmfDir.mkdir(); + File jmfProperties = new File(jmfDir, "jmf.properties"); - File jmfProperties = new File(jmfDir, "jmf.properties"); - - if (!jmfProperties.exists()) { - try { - jmfProperties.createNewFile(); - } - catch (IOException ex) { - System.out.println("Failed to create jmf.properties"); - ex.printStackTrace(); - } + if (!jmfProperties.exists()) { + try { + jmfProperties.createNewFile(); } - - // if we're running on linux checkout that libjmutil.so is where it - // should be and put it there. - runLinuxPreInstall(); - - if (jmfProperties.length() == 0) { - JMFInit init = new JMFInit(null, false); + catch (IOException ex) { + System.out.println("Failed to create jmf.properties"); + ex.printStackTrace(); } - } - finally { + // if we're running on linux checkout that libjmutil.so is where it + // should be and put it there. + runLinuxPreInstall(); + + if (jmfProperties.length() == 0) { + new JMFInit(null, false); } } diff --git a/jingle/media/test/JingleMediaTest.java b/jingle/media/test/JingleMediaTest.java index 5e6c1d64f..faac8f5bc 100644 --- a/jingle/media/test/JingleMediaTest.java +++ b/jingle/media/test/JingleMediaTest.java @@ -2,6 +2,7 @@ import junit.framework.TestCase; import org.jivesoftware.jingleaudio.jmf.AudioChannel; import org.jivesoftware.jingleaudio.jmf.JmfMediaManager; import org.jivesoftware.jingleaudio.jspeex.SpeexMediaManager; +import org.jivesoftware.jingleaudio.multi.MultiMediaManager; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.test.SmackTestCase; @@ -101,6 +102,65 @@ public class JingleMediaTest extends SmackTestCase { } + public void testCompleteMulti() { + + try { + + XMPPConnection x0 = getConnection(0); + XMPPConnection x1 = getConnection(1); + + ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478); + ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478); + + final JingleManager jm0 = new JingleManager( + x0, icetm0); + final JingleManager jm1 = new JingleManager( + x1, icetm1); + + jm0.addCreationListener(icetm0); + jm1.addCreationListener(icetm1); + + MultiMediaManager jingleMediaManager0 = new MultiMediaManager(); + jingleMediaManager0.addMediaManager(new SpeexMediaManager()); + jingleMediaManager0.addMediaManager(new JmfMediaManager()); + JingleMediaManager jingleMediaManager1 = new JmfMediaManager(); + + jm0.setMediaManager(jingleMediaManager0); + jm1.setMediaManager(jingleMediaManager1); + + jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() { + public void sessionRequested(final JingleSessionRequest request) { + + try { + IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads()); + session.start(request); + } + catch (XMPPException e) { + e.printStackTrace(); + } + + } + }); + + OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser()); + + js0.start(); + + Thread.sleep(60000); + js0.terminate(); + + Thread.sleep(6000); + + x0.disconnect(); + x1.disconnect(); + + } + catch (Exception e) { + e.printStackTrace(); + } + + } + public void testCompleteSpeex() { try { @@ -224,7 +284,7 @@ public class JingleMediaTest extends SmackTestCase { Thread.sleep(250000); } catch (InterruptedException e) { - e.printStackTrace(); + e.printStackTrace(); } } @@ -276,7 +336,7 @@ public class JingleMediaTest extends SmackTestCase { Thread.sleep(3000); - js0 = jm0.createOutgoingJingleSession(x1.getUser()); + js0 = jm0.createOutgoingJingleSession(x1.getUser()); js0.start();