mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-09 12:31:08 +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:
parent
18c14f70d4
commit
945561242a
8 changed files with 180 additions and 242 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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<PayloadType> payloads = new ArrayList<PayloadType>();
|
||||
|
||||
/**
|
||||
* 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<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.
|
||||
*/
|
||||
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);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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<PayloadType> payloads = new ArrayList<PayloadType>();
|
||||
|
||||
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<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.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue