1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

Jingle Media Manager for Multiple Media Managers.

JIngle Media Manager Refactoring.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7361 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Thiago Camargo 2007-03-02 20:32:21 +00:00 committed by thiago
parent 18c14f70d4
commit 945561242a
8 changed files with 180 additions and 242 deletions

View file

@ -36,42 +36,17 @@ import java.util.List;
*/ */
public abstract class JingleMediaManager { public abstract class JingleMediaManager {
private List<PayloadType> payloads = new ArrayList<PayloadType>();
/** /**
* Return all supported Payloads for this Manager * Return all supported Payloads for this Manager
* *
* @return The Payload List * @return The Payload List
*/ */
public List<PayloadType> getPayloads() { public abstract List<PayloadType> 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);
}
/** /**
* Get the preferred Payload Type * Get the preferred Payload Type
*/ */
public PayloadType getPreferredPayloadType() { public abstract PayloadType getPreferredPayloadType();
//TODO a better way to choose the preferred Payload
return payloads.size() > 0 ? payloads.get(0) : null;
}
/** /**
* Create a Media Session Implementation * Create a Media Session Implementation

View file

@ -74,6 +74,7 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
/** /**
* Test the Jingle extension using the high level API * Test the Jingle extension using the high level API
@ -706,33 +707,7 @@ public class JingleManagerTest extends SmackTestCase {
// JingleManager jm1 = new JingleSessionManager( // JingleManager jm1 = new JingleSessionManager(
// x1, new ICEResolver()); // x1, new ICEResolver());
JingleMediaManager jingleMediaManager = new JingleMediaManager() { JingleMediaManager jingleMediaManager = new JmfMediaManager();
// 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));
jm0.setMediaManager(jingleMediaManager); jm0.setMediaManager(jingleMediaManager);
jm1.setMediaManager(jingleMediaManager); jm1.setMediaManager(jingleMediaManager);
@ -746,32 +721,27 @@ public class JingleManagerTest extends SmackTestCase {
session.addListener(new JingleSessionListener() { session.addListener(new JingleSessionListener() {
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) { public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
//To change body of implemented methods use File | Settings | File Templates.
incCounter(); incCounter();
System.out.println("Establish In"); System.out.println("Establish In");
} }
public void sessionDeclined(String reason, JingleSession jingleSession) { 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) { 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) { 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) { public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
//To change body of implemented methods use File | Settings | File Templates.
} }
}); });
session.start(); session.start();
} }
catch (XMPPException e) { 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<PayloadType> getPayloads() {
return new ArrayList();
}
public PayloadType getPreferredPayloadType() {
return null;
}
};
jm0.setMediaManager(jingleMediaManager); jm0.setMediaManager(jingleMediaManager);
jm1.setMediaManager(jingleMediaManager); jm1.setMediaManager(jingleMediaManager);
@ -891,7 +869,7 @@ public class JingleManagerTest extends SmackTestCase {
session.start(request); session.start(request);
} }
catch (XMPPException e) { catch (XMPPException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. e.printStackTrace();
} }
} }

View file

@ -65,106 +65,6 @@ public class BridgedResolverTest extends SmackTestCase {
assertTrue(valCounter() == 3); 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() { protected int getMaxConnections() {
return 1; return 1;
} }

View file

@ -38,7 +38,6 @@ import java.net.ServerSocket;
* To receive you MUST transmit. So the only implemented and functionally methods are startTransmit() and stopTransmit() * To receive you MUST transmit. So the only implemented and functionally methods are startTransmit() and stopTransmit()
* *
* @author Thiago Camargo * @author Thiago Camargo
*
*/ */
public class AudioMediaSession extends JingleMediaSession { public class AudioMediaSession extends JingleMediaSession {
@ -130,7 +129,8 @@ public class AudioMediaSession extends JingleMediaSession {
* Stops transmission and for NAT Traversal reasons stop receiving also. * Stops transmission and for NAT Traversal reasons stop receiving also.
*/ */
public void stopTrasmit() { public void stopTrasmit() {
audioChannel.stop(); if (audioChannel != null)
audioChannel.stop();
} }
/** /**

View file

@ -28,6 +28,8 @@ import org.jivesoftware.jingleaudio.JMFInit;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
/** /**
* Implements a jingleMediaManager using JMF based API. * Implements a jingleMediaManager using JMF based API.
@ -38,6 +40,8 @@ import java.io.IOException;
*/ */
public class JmfMediaManager extends JingleMediaManager { public class JmfMediaManager extends JingleMediaManager {
private List<PayloadType> payloads = new ArrayList<PayloadType>();
/** /**
* Creates a Media Manager instance * Creates a Media Manager instance
*/ */
@ -62,8 +66,25 @@ public class JmfMediaManager extends JingleMediaManager {
* Setup API supported Payloads * Setup API supported Payloads
*/ */
private void setupPayloads() { private void setupPayloads() {
this.addPayloadType(new PayloadType.Audio(3, "gsm")); payloads.add(new PayloadType.Audio(3, "gsm"));
this.addPayloadType(new PayloadType.Audio(4, "g723")); payloads.add(new PayloadType.Audio(4, "g723"));
}
/**
* Return all supported Payloads for this Manager
*
* @return The Payload List
*/
public List<PayloadType> 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. * devices are properly detected and initialized by JMF.
*/ */
public static void setupJMF() { 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 if (!jmfDir.exists())
// by JMF. if the directory does not exist or it does not contain jmfDir.mkdir();
// 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()) File jmfProperties = new File(jmfDir, "jmf.properties");
jmfDir.mkdir();
File jmfProperties = new File(jmfDir, "jmf.properties"); if (!jmfProperties.exists()) {
try {
if (!jmfProperties.exists()) { jmfProperties.createNewFile();
try { }
jmfProperties.createNewFile(); catch (IOException ex) {
} System.out.println("Failed to create jmf.properties");
catch (IOException ex) { ex.printStackTrace();
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);
//}
} }

View file

@ -170,7 +170,8 @@ public class AudioMediaSession extends JingleMediaSession implements MediaSessio
* Stops transmission and for NAT Traversal reasons stop receiving also. * Stops transmission and for NAT Traversal reasons stop receiving also.
*/ */
public void stopTrasmit() { 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) { public void newStreamIdentified(StreamPlayer streamPlayer) {
//To change body of implemented methods use File | Settings | File Templates.
} }
public void senderReportReceived(SenderReport report) { public void senderReportReceived(SenderReport report) {
//To change body of implemented methods use File | Settings | File Templates.
} }
public void streamClosed(StreamPlayer stream, boolean timeout) { public void streamClosed(StreamPlayer stream, boolean timeout) {
//To change body of implemented methods use File | Settings | File Templates.
} }
/** /**

View file

@ -27,6 +27,8 @@ import org.jivesoftware.jingleaudio.JMFInit;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
/** /**
* Implements a jingleMediaManager using JMF based API and JSpeex. * Implements a jingleMediaManager using JMF based API and JSpeex.
@ -37,6 +39,8 @@ import java.io.IOException;
*/ */
public class SpeexMediaManager extends JingleMediaManager { public class SpeexMediaManager extends JingleMediaManager {
private List<PayloadType> payloads = new ArrayList<PayloadType>();
public SpeexMediaManager() { public SpeexMediaManager() {
setupPayloads(); setupPayloads();
setupJMF(); setupJMF();
@ -50,7 +54,23 @@ public class SpeexMediaManager extends JingleMediaManager {
* Setup API supported Payloads * Setup API supported Payloads
*/ */
private void setupPayloads() { 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<PayloadType> 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. * devices are properly detected and initialized by JMF.
*/ */
public static void setupJMF() { 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 if (!jmfDir.exists())
// by JMF. if the directory does not exist or it does not contain jmfDir.mkdir();
// 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()) File jmfProperties = new File(jmfDir, "jmf.properties");
jmfDir.mkdir();
File jmfProperties = new File(jmfDir, "jmf.properties"); if (!jmfProperties.exists()) {
try {
if (!jmfProperties.exists()) { jmfProperties.createNewFile();
try {
jmfProperties.createNewFile();
}
catch (IOException ex) {
System.out.println("Failed to create jmf.properties");
ex.printStackTrace();
}
} }
catch (IOException ex) {
// if we're running on linux checkout that libjmutil.so is where it System.out.println("Failed to create jmf.properties");
// should be and put it there. ex.printStackTrace();
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);
} }
} }

View file

@ -2,6 +2,7 @@ import junit.framework.TestCase;
import org.jivesoftware.jingleaudio.jmf.AudioChannel; import org.jivesoftware.jingleaudio.jmf.AudioChannel;
import org.jivesoftware.jingleaudio.jmf.JmfMediaManager; import org.jivesoftware.jingleaudio.jmf.JmfMediaManager;
import org.jivesoftware.jingleaudio.jspeex.SpeexMediaManager; import org.jivesoftware.jingleaudio.jspeex.SpeexMediaManager;
import org.jivesoftware.jingleaudio.multi.MultiMediaManager;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.test.SmackTestCase; 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() { public void testCompleteSpeex() {
try { try {
@ -224,7 +284,7 @@ public class JingleMediaTest extends SmackTestCase {
Thread.sleep(250000); Thread.sleep(250000);
} }
catch (InterruptedException e) { catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -276,7 +336,7 @@ public class JingleMediaTest extends SmackTestCase {
Thread.sleep(3000); Thread.sleep(3000);
js0 = jm0.createOutgoingJingleSession(x1.getUser()); js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.start(); js0.start();