mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-27 00:32:07 +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,7 +27,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides necessary Jingle Session jmf methods and behavior.
|
* 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.
|
* 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.
|
* 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.
|
||||||
|
@ -43,6 +43,15 @@ public abstract class JingleMediaManager {
|
||||||
*/
|
*/
|
||||||
public abstract List<PayloadType> getPayloads();
|
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
|
* Create a Media Session Implementation
|
||||||
*
|
*
|
||||||
|
|
|
@ -211,8 +211,14 @@ public class MediaNegotiator extends JingleNegotiator {
|
||||||
|
|
||||||
if (!commonAudioPtsHere.isEmpty() && !commonAudioPtsThere.isEmpty()) {
|
if (!commonAudioPtsHere.isEmpty() && !commonAudioPtsThere.isEmpty()) {
|
||||||
|
|
||||||
|
if (session.getInitiator().equals(session.getConnection().getUser())) {
|
||||||
PayloadType.Audio bestPtHere = null;
|
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)
|
if (bestPtHere == null)
|
||||||
for (PayloadType payloadType : commonAudioPtsHere)
|
for (PayloadType payloadType : commonAudioPtsHere)
|
||||||
|
@ -221,6 +227,9 @@ public class MediaNegotiator extends JingleNegotiator {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = bestPtHere;
|
||||||
|
}
|
||||||
|
else {
|
||||||
PayloadType.Audio bestPtThere = null;
|
PayloadType.Audio bestPtThere = null;
|
||||||
for (PayloadType payloadType : commonAudioPtsThere)
|
for (PayloadType payloadType : commonAudioPtsThere)
|
||||||
if (payloadType instanceof PayloadType.Audio) {
|
if (payloadType instanceof PayloadType.Audio) {
|
||||||
|
@ -228,12 +237,10 @@ public class MediaNegotiator extends JingleNegotiator {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.getInitiator().equals(session.getConnection().getUser()))
|
|
||||||
result = bestPtHere;
|
|
||||||
else
|
|
||||||
result = bestPtThere;
|
result = bestPtThere;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class MultiMediaManager extends JingleMediaManager {
|
||||||
|
|
||||||
private List<JingleMediaManager> managers = new ArrayList<JingleMediaManager>();
|
private List<JingleMediaManager> managers = new ArrayList<JingleMediaManager>();
|
||||||
|
|
||||||
|
private PayloadType preferredPayloadType = null;
|
||||||
|
|
||||||
public MultiMediaManager() {
|
public MultiMediaManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +58,10 @@ public class MultiMediaManager extends JingleMediaManager {
|
||||||
*/
|
*/
|
||||||
public List<PayloadType> getPayloads() {
|
public List<PayloadType> getPayloads() {
|
||||||
List<PayloadType> list = new ArrayList<PayloadType>();
|
List<PayloadType> list = new ArrayList<PayloadType>();
|
||||||
|
if (preferredPayloadType != null) list.add(preferredPayloadType);
|
||||||
for (JingleMediaManager manager : managers) {
|
for (JingleMediaManager manager : managers) {
|
||||||
for (PayloadType payloadType : manager.getPayloads()) {
|
for (PayloadType payloadType : manager.getPayloads()) {
|
||||||
if (!list.contains(payloadType))
|
if (!list.contains(payloadType) && !payloadType.equals(preferredPayloadType))
|
||||||
list.add(payloadType);
|
list.add(payloadType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,4 +84,14 @@ public class MultiMediaManager extends JingleMediaManager {
|
||||||
}
|
}
|
||||||
return null;
|
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() {
|
public boolean isNull() {
|
||||||
if (ip == null) {
|
if (ip == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (ip.length() == 0) {
|
||||||
else if (ip.length() == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (port < 0) {
|
||||||
else if (port < 0) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,8 +346,7 @@ public abstract class TransportCandidate {
|
||||||
if (other.getIp() != null) {
|
if (other.getIp() != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (!getIp().equals(other.getIp())) {
|
||||||
else if (!getIp().equals(other.getIp())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,8 +358,7 @@ public abstract class TransportCandidate {
|
||||||
if (other.getName() != null) {
|
if (other.getName() != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (!getName().equals(other.getName())) {
|
||||||
else if (!getName().equals(other.getName())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getPort() != other.getPort()) {
|
if (getPort() != other.getPort()) {
|
||||||
|
@ -507,20 +502,15 @@ public abstract class TransportCandidate {
|
||||||
value = value.toLowerCase();
|
value = value.toLowerCase();
|
||||||
if (value.equals("udp")) {
|
if (value.equals("udp")) {
|
||||||
return UDP;
|
return UDP;
|
||||||
}
|
} else if (value.equals("tcp")) {
|
||||||
else if (value.equals("tcp")) {
|
|
||||||
return TCP;
|
return TCP;
|
||||||
}
|
} else if (value.equals("tcp-act")) {
|
||||||
else if (value.equals("tcp-act")) {
|
|
||||||
return TCPACT;
|
return TCPACT;
|
||||||
}
|
} else if (value.equals("tcp-pass")) {
|
||||||
else if (value.equals("tcp-pass")) {
|
|
||||||
return TCPPASS;
|
return TCPPASS;
|
||||||
}
|
} else if (value.equals("ssltcp")) {
|
||||||
else if (value.equals("ssltcp")) {
|
|
||||||
return SSLTCP;
|
return SSLTCP;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return UDP;
|
return UDP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,8 +535,7 @@ public abstract class TransportCandidate {
|
||||||
if (other.value != null) {
|
if (other.value != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (!value.equals(other.value)) {
|
||||||
else if (!value.equals(other.value)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -560,11 +549,9 @@ public abstract class TransportCandidate {
|
||||||
public boolean isNull() {
|
public boolean isNull() {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (value.length() == 0) {
|
||||||
else if (value.length() == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -599,11 +586,9 @@ public abstract class TransportCandidate {
|
||||||
value = value.toLowerCase();
|
value = value.toLowerCase();
|
||||||
if (value.equals("myrtpvoice")) {
|
if (value.equals("myrtpvoice")) {
|
||||||
return MYRTPVOICE;
|
return MYRTPVOICE;
|
||||||
}
|
} else if (value.equals("tcp")) {
|
||||||
else if (value.equals("tcp")) {
|
|
||||||
return MYRTCPVOICE;
|
return MYRTCPVOICE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return MYRTPVOICE;
|
return MYRTPVOICE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -628,8 +613,7 @@ public abstract class TransportCandidate {
|
||||||
if (other.value != null) {
|
if (other.value != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (!value.equals(other.value)) {
|
||||||
else if (!value.equals(other.value)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -643,11 +627,9 @@ public abstract class TransportCandidate {
|
||||||
public boolean isNull() {
|
public boolean isNull() {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (value.length() == 0) {
|
||||||
else if (value.length() == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -687,8 +669,7 @@ public abstract class TransportCandidate {
|
||||||
|
|
||||||
this.send = local.getBytes("UTF-8");
|
this.send = local.getBytes("UTF-8");
|
||||||
this.receive = remote.getBytes("UTF-8");
|
this.receive = remote.getBytes("UTF-8");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.receive = local.getBytes("UTF-8");
|
this.receive = local.getBytes("UTF-8");
|
||||||
this.send = remote.getBytes("UTF-8");
|
this.send = remote.getBytes("UTF-8");
|
||||||
}
|
}
|
||||||
|
@ -798,6 +779,7 @@ public abstract class TransportCandidate {
|
||||||
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
public boolean datagramReceived(DatagramPacket datagramPacket) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
System.out.println("Content Received: " + new String(datagramPacket.getData(), "UTF-8"));
|
||||||
String str[] = new String(datagramPacket.getData(), "UTF-8").split(";");
|
String str[] = new String(datagramPacket.getData(), "UTF-8").split(";");
|
||||||
String pass = str[0];
|
String pass = str[0];
|
||||||
String addr[] = str[1].split(":");
|
String addr[] = str[1].split(":");
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class JingleMediaTest extends SmackTestCase {
|
||||||
XMPPConnection x0 = getConnection(0);
|
XMPPConnection x0 = getConnection(0);
|
||||||
XMPPConnection x1 = getConnection(1);
|
XMPPConnection x1 = getConnection(1);
|
||||||
|
|
||||||
for(int i=0;i<3;i++)
|
for (int i = 0; i < 3; i++)
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
|
ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
|
||||||
|
@ -128,19 +128,21 @@ public class JingleMediaTest extends SmackTestCase {
|
||||||
|
|
||||||
jm0.addCreationListener(icetm0);
|
jm0.addCreationListener(icetm0);
|
||||||
jm1.addCreationListener(icetm1);
|
jm1.addCreationListener(icetm1);
|
||||||
/*
|
|
||||||
|
|
||||||
|
/*
|
||||||
final JingleManager jm0 = new JingleManager(
|
final JingleManager jm0 = new JingleManager(
|
||||||
x0, new BasicTransportManager());
|
x0, new BasicTransportManager());
|
||||||
final JingleManager jm1 = new JingleManager(
|
final JingleManager jm1 = new JingleManager(
|
||||||
x1, new BasicTransportManager());
|
x1, new BasicTransportManager());
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MultiMediaManager jingleMediaManager0 = new MultiMediaManager();
|
MultiMediaManager jingleMediaManager0 = new MultiMediaManager();
|
||||||
jingleMediaManager0.addMediaManager(new SpeexMediaManager());
|
|
||||||
jingleMediaManager0.addMediaManager(new JmfMediaManager());
|
jingleMediaManager0.addMediaManager(new JmfMediaManager());
|
||||||
|
jingleMediaManager0.addMediaManager(new SpeexMediaManager());
|
||||||
MultiMediaManager jingleMediaManager1 = new MultiMediaManager();
|
MultiMediaManager jingleMediaManager1 = new MultiMediaManager();
|
||||||
jingleMediaManager1.addMediaManager(new JmfMediaManager());
|
jingleMediaManager1.addMediaManager(new JmfMediaManager());
|
||||||
jingleMediaManager1.addMediaManager(new SpeexMediaManager());
|
jingleMediaManager1.addMediaManager(new SpeexMediaManager());
|
||||||
|
jingleMediaManager1.setPreferredPayloadType(jingleMediaManager1.getPayloads().get(2));
|
||||||
|
|
||||||
jm0.setMediaManager(jingleMediaManager0);
|
jm0.setMediaManager(jingleMediaManager0);
|
||||||
jm1.setMediaManager(jingleMediaManager1);
|
jm1.setMediaManager(jingleMediaManager1);
|
||||||
|
|
Loading…
Reference in a new issue