1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +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:
Thiago Camargo 2007-03-17 20:13:05 +00:00 committed by thiago
parent c0ce7dd783
commit cb2df91084
5 changed files with 115 additions and 102 deletions

View file

@ -27,7 +27,7 @@ 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.
@ -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
*

View file

@ -211,8 +211,14 @@ public class MediaNegotiator extends JingleNegotiator {
if (!commonAudioPtsHere.isEmpty() && !commonAudioPtsThere.isEmpty()) {
if (session.getInitiator().equals(session.getConnection().getUser())) {
PayloadType.Audio bestPtHere = null;
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)
@ -221,6 +227,9 @@ public class MediaNegotiator extends JingleNegotiator {
break;
}
result = bestPtHere;
}
else {
PayloadType.Audio bestPtThere = null;
for (PayloadType payloadType : commonAudioPtsThere)
if (payloadType instanceof PayloadType.Audio) {
@ -228,12 +237,10 @@ public class MediaNegotiator extends JingleNegotiator {
break;
}
if (session.getInitiator().equals(session.getConnection().getUser()))
result = bestPtHere;
else
result = bestPtThere;
}
}
}
return result;
}

View file

@ -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);
}
}
@ -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;
}
}

View file

@ -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(":");

View file

@ -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());
*/
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);