mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-23 02:58:00 +01:00
Preferred Codec Added to Media Manager and Media Negotiator
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7585 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
c0ce7dd783
commit
cb2df91084
5 changed files with 115 additions and 102 deletions
|
@ -27,15 +27,15 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* This class provides necessary Jingle Session jmf methods and behavior.
|
||||
*
|
||||
* <p/>
|
||||
* The goal of this class is to provide a flexible way to make JingleManager control jmf streaming APIs without implement them.
|
||||
* For instance you can implement a file transfer using java sockets or a VOIP Media Manager using JMF.
|
||||
* You can implement many JingleMediaManager according to you necessity.
|
||||
* You can implement many JingleMediaManager according to you necessity.
|
||||
*
|
||||
* @author Thiago Camargo
|
||||
*/
|
||||
public abstract class JingleMediaManager {
|
||||
|
||||
|
||||
/**
|
||||
* Return all supported Payloads for this Manager
|
||||
*
|
||||
|
@ -43,6 +43,15 @@ public abstract class JingleMediaManager {
|
|||
*/
|
||||
public abstract List<PayloadType> getPayloads();
|
||||
|
||||
/**
|
||||
* Returns the Preferred PayloadType of the Media Manager
|
||||
*
|
||||
* @return The PayloadType
|
||||
*/
|
||||
public PayloadType getPreferredPayloadType() {
|
||||
return getPayloads().size() > 0 ? getPayloads().get(0) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Media Session Implementation
|
||||
*
|
||||
|
|
|
@ -211,27 +211,34 @@ public class MediaNegotiator extends JingleNegotiator {
|
|||
|
||||
if (!commonAudioPtsHere.isEmpty() && !commonAudioPtsThere.isEmpty()) {
|
||||
|
||||
PayloadType.Audio bestPtHere = null;
|
||||
|
||||
if (session.getInitiator().equals(session.getConnection().getUser())) {
|
||||
PayloadType.Audio bestPtHere = null;
|
||||
|
||||
if (bestPtHere == null)
|
||||
for (PayloadType payloadType : commonAudioPtsHere)
|
||||
PayloadType payload = this.session.getMediaManager().getPreferredPayloadType();
|
||||
|
||||
if (payload != null && payload instanceof PayloadType.Audio)
|
||||
if (commonAudioPtsHere.contains(payload))
|
||||
bestPtHere = (PayloadType.Audio) payload;
|
||||
|
||||
if (bestPtHere == null)
|
||||
for (PayloadType payloadType : commonAudioPtsHere)
|
||||
if (payloadType instanceof PayloadType.Audio) {
|
||||
bestPtHere = (PayloadType.Audio) payloadType;
|
||||
break;
|
||||
}
|
||||
|
||||
result = bestPtHere;
|
||||
}
|
||||
else {
|
||||
PayloadType.Audio bestPtThere = null;
|
||||
for (PayloadType payloadType : commonAudioPtsThere)
|
||||
if (payloadType instanceof PayloadType.Audio) {
|
||||
bestPtHere = (PayloadType.Audio) payloadType;
|
||||
bestPtThere = (PayloadType.Audio) payloadType;
|
||||
break;
|
||||
}
|
||||
|
||||
PayloadType.Audio bestPtThere = null;
|
||||
for (PayloadType payloadType : commonAudioPtsThere)
|
||||
if (payloadType instanceof PayloadType.Audio) {
|
||||
bestPtThere = (PayloadType.Audio) payloadType;
|
||||
break;
|
||||
}
|
||||
|
||||
if (session.getInitiator().equals(session.getConnection().getUser()))
|
||||
result = bestPtHere;
|
||||
else
|
||||
result = bestPtThere;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ public class MultiMediaManager extends JingleMediaManager {
|
|||
|
||||
private List<JingleMediaManager> managers = new ArrayList<JingleMediaManager>();
|
||||
|
||||
private PayloadType preferredPayloadType = null;
|
||||
|
||||
public MultiMediaManager() {
|
||||
}
|
||||
|
||||
|
@ -56,9 +58,10 @@ public class MultiMediaManager extends JingleMediaManager {
|
|||
*/
|
||||
public List<PayloadType> getPayloads() {
|
||||
List<PayloadType> list = new ArrayList<PayloadType>();
|
||||
if (preferredPayloadType != null) list.add(preferredPayloadType);
|
||||
for (JingleMediaManager manager : managers) {
|
||||
for (PayloadType payloadType : manager.getPayloads()) {
|
||||
if (!list.contains(payloadType))
|
||||
if (!list.contains(payloadType) && !payloadType.equals(preferredPayloadType))
|
||||
list.add(payloadType);
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +72,8 @@ public class MultiMediaManager extends JingleMediaManager {
|
|||
* Returns a new JingleMediaSession
|
||||
*
|
||||
* @param payloadType payloadType
|
||||
* @param remote remote Candidate
|
||||
* @param local local Candidate
|
||||
* @param remote remote Candidate
|
||||
* @param local local Candidate
|
||||
* @return JingleMediaSession JingleMediaSession
|
||||
*/
|
||||
public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local) {
|
||||
|
@ -81,4 +84,14 @@ public class MultiMediaManager extends JingleMediaManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PayloadType getPreferredPayloadType() {
|
||||
if (preferredPayloadType != null) return preferredPayloadType;
|
||||
return super.getPreferredPayloadType();
|
||||
}
|
||||
|
||||
public void setPreferredPayloadType(PayloadType preferredPayloadType) {
|
||||
this.preferredPayloadType = preferredPayloadType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -259,14 +259,11 @@ public abstract class TransportCandidate {
|
|||
public boolean isNull() {
|
||||
if (ip == null) {
|
||||
return true;
|
||||
}
|
||||
else if (ip.length() == 0) {
|
||||
} else if (ip.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
else if (port < 0) {
|
||||
} else if (port < 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -349,8 +346,7 @@ public abstract class TransportCandidate {
|
|||
if (other.getIp() != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!getIp().equals(other.getIp())) {
|
||||
} else if (!getIp().equals(other.getIp())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -362,8 +358,7 @@ public abstract class TransportCandidate {
|
|||
if (other.getName() != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!getName().equals(other.getName())) {
|
||||
} else if (!getName().equals(other.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (getPort() != other.getPort()) {
|
||||
|
@ -507,20 +502,15 @@ public abstract class TransportCandidate {
|
|||
value = value.toLowerCase();
|
||||
if (value.equals("udp")) {
|
||||
return UDP;
|
||||
}
|
||||
else if (value.equals("tcp")) {
|
||||
} else if (value.equals("tcp")) {
|
||||
return TCP;
|
||||
}
|
||||
else if (value.equals("tcp-act")) {
|
||||
} else if (value.equals("tcp-act")) {
|
||||
return TCPACT;
|
||||
}
|
||||
else if (value.equals("tcp-pass")) {
|
||||
} else if (value.equals("tcp-pass")) {
|
||||
return TCPPASS;
|
||||
}
|
||||
else if (value.equals("ssltcp")) {
|
||||
} else if (value.equals("ssltcp")) {
|
||||
return SSLTCP;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return UDP;
|
||||
}
|
||||
}
|
||||
|
@ -545,8 +535,7 @@ public abstract class TransportCandidate {
|
|||
if (other.value != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!value.equals(other.value)) {
|
||||
} else if (!value.equals(other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -560,11 +549,9 @@ public abstract class TransportCandidate {
|
|||
public boolean isNull() {
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
else if (value.length() == 0) {
|
||||
} else if (value.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -599,11 +586,9 @@ public abstract class TransportCandidate {
|
|||
value = value.toLowerCase();
|
||||
if (value.equals("myrtpvoice")) {
|
||||
return MYRTPVOICE;
|
||||
}
|
||||
else if (value.equals("tcp")) {
|
||||
} else if (value.equals("tcp")) {
|
||||
return MYRTCPVOICE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return MYRTPVOICE;
|
||||
}
|
||||
}
|
||||
|
@ -628,8 +613,7 @@ public abstract class TransportCandidate {
|
|||
if (other.value != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!value.equals(other.value)) {
|
||||
} else if (!value.equals(other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -643,11 +627,9 @@ public abstract class TransportCandidate {
|
|||
public boolean isNull() {
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
else if (value.length() == 0) {
|
||||
} else if (value.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -687,8 +669,7 @@ public abstract class TransportCandidate {
|
|||
|
||||
this.send = local.getBytes("UTF-8");
|
||||
this.receive = remote.getBytes("UTF-8");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.receive = local.getBytes("UTF-8");
|
||||
this.send = remote.getBytes("UTF-8");
|
||||
}
|
||||
|
@ -798,6 +779,7 @@ public abstract class TransportCandidate {
|
|||
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
||||
|
||||
try {
|
||||
System.out.println("Content Received: " + new String(datagramPacket.getData(), "UTF-8"));
|
||||
String str[] = new String(datagramPacket.getData(), "UTF-8").split(";");
|
||||
String pass = str[0];
|
||||
String addr[] = str[1].split(":");
|
||||
|
|
|
@ -56,57 +56,57 @@ public class JingleMediaTest extends SmackTestCase {
|
|||
XMPPConnection x0 = getConnection(0);
|
||||
XMPPConnection x1 = getConnection(1);
|
||||
|
||||
for(int i=0;i<3;i++)
|
||||
try {
|
||||
for (int i = 0; i < 3; i++)
|
||||
try {
|
||||
|
||||
ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
|
||||
ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478);
|
||||
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);
|
||||
final JingleManager jm0 = new JingleManager(
|
||||
x0, icetm0);
|
||||
final JingleManager jm1 = new JingleManager(
|
||||
x1, icetm1);
|
||||
|
||||
jm0.addCreationListener(icetm0);
|
||||
jm1.addCreationListener(icetm1);
|
||||
jm0.addCreationListener(icetm0);
|
||||
jm1.addCreationListener(icetm1);
|
||||
|
||||
JingleMediaManager jingleMediaManager0 = new JmfMediaManager();
|
||||
JingleMediaManager jingleMediaManager1 = new JmfMediaManager();
|
||||
JingleMediaManager jingleMediaManager0 = new JmfMediaManager();
|
||||
JingleMediaManager jingleMediaManager1 = new JmfMediaManager();
|
||||
|
||||
jm0.setMediaManager(jingleMediaManager0);
|
||||
jm1.setMediaManager(jingleMediaManager1);
|
||||
jm0.setMediaManager(jingleMediaManager0);
|
||||
jm1.setMediaManager(jingleMediaManager1);
|
||||
|
||||
JingleSessionRequestListener jingleSessionRequestListener = new JingleSessionRequestListener() {
|
||||
public void sessionRequested(final JingleSessionRequest request) {
|
||||
JingleSessionRequestListener jingleSessionRequestListener = new JingleSessionRequestListener() {
|
||||
public void sessionRequested(final JingleSessionRequest request) {
|
||||
|
||||
try {
|
||||
IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads());
|
||||
session.start(request);
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
IncomingJingleSession session = request.accept(jm1.getMediaManager().getPayloads());
|
||||
session.start(request);
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
};
|
||||
jm1.addJingleSessionRequestListener(jingleSessionRequestListener);
|
||||
|
||||
jm1.addJingleSessionRequestListener(jingleSessionRequestListener);
|
||||
OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
|
||||
|
||||
OutgoingJingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
|
||||
js0.start();
|
||||
|
||||
js0.start();
|
||||
Thread.sleep(50000);
|
||||
js0.terminate();
|
||||
|
||||
Thread.sleep(50000);
|
||||
js0.terminate();
|
||||
jm1.removeJingleSessionRequestListener(jingleSessionRequestListener);
|
||||
|
||||
jm1.removeJingleSessionRequestListener(jingleSessionRequestListener);
|
||||
Thread.sleep(6000);
|
||||
|
||||
Thread.sleep(6000);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -128,19 +128,21 @@ public class JingleMediaTest extends SmackTestCase {
|
|||
|
||||
jm0.addCreationListener(icetm0);
|
||||
jm1.addCreationListener(icetm1);
|
||||
/*
|
||||
|
||||
final JingleManager jm0 = new JingleManager(
|
||||
x0, new BasicTransportManager());
|
||||
final JingleManager jm1 = new JingleManager(
|
||||
x1, new BasicTransportManager());
|
||||
*/
|
||||
/*
|
||||
final JingleManager jm0 = new JingleManager(
|
||||
x0, new BasicTransportManager());
|
||||
final JingleManager jm1 = new JingleManager(
|
||||
x1, new BasicTransportManager());
|
||||
*/
|
||||
|
||||
MultiMediaManager jingleMediaManager0 = new MultiMediaManager();
|
||||
jingleMediaManager0.addMediaManager(new SpeexMediaManager());
|
||||
jingleMediaManager0.addMediaManager(new JmfMediaManager());
|
||||
jingleMediaManager0.addMediaManager(new SpeexMediaManager());
|
||||
MultiMediaManager jingleMediaManager1 = new MultiMediaManager();
|
||||
jingleMediaManager1.addMediaManager(new JmfMediaManager());
|
||||
jingleMediaManager1.addMediaManager(new SpeexMediaManager());
|
||||
jingleMediaManager1.setPreferredPayloadType(jingleMediaManager1.getPayloads().get(2));
|
||||
|
||||
jm0.setMediaManager(jingleMediaManager0);
|
||||
jm1.setMediaManager(jingleMediaManager1);
|
||||
|
|
Loading…
Reference in a new issue