mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-23 06:42:05 +01:00
Echo Cancel Fixed
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7035 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
85387aa360
commit
a5a6697496
2 changed files with 59 additions and 38 deletions
|
@ -81,7 +81,7 @@ import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract Jingle session.
|
* An abstract Jingle session.
|
||||||
*
|
* <p/>
|
||||||
* This class contains some basic properties of every Jingle session. However,
|
* This class contains some basic properties of every Jingle session. However,
|
||||||
* the concrete implementation can be found in subclasses.
|
* the concrete implementation can be found in subclasses.
|
||||||
*
|
*
|
||||||
|
@ -116,7 +116,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
|
|
||||||
protected JingleMediaSession jingleMediaSession = null;
|
protected JingleMediaSession jingleMediaSession = null;
|
||||||
|
|
||||||
static int ccc=0;
|
static int ccc = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full featured JingleSession constructor
|
* Full featured JingleSession constructor
|
||||||
|
@ -128,7 +128,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
* @param jingleMediaManager the jingleMediaManager
|
* @param jingleMediaManager the jingleMediaManager
|
||||||
*/
|
*/
|
||||||
protected JingleSession(XMPPConnection conn, String initiator, String responder,
|
protected JingleSession(XMPPConnection conn, String initiator, String responder,
|
||||||
String sessionid, JingleMediaManager jingleMediaManager) {
|
String sessionid, JingleMediaManager jingleMediaManager) {
|
||||||
super(conn);
|
super(conn);
|
||||||
|
|
||||||
this.mediaNeg = null;
|
this.mediaNeg = null;
|
||||||
|
@ -344,21 +344,25 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (invalidState()) {
|
if (invalidState()) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Illegal state in dispatch packet in Session manager.");
|
"Illegal state in dispatch packet in Session manager.");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (iq == null) {
|
if (iq == null) {
|
||||||
// If there is no input packet, then we must be inviting...
|
// If there is no input packet, then we must be inviting...
|
||||||
jout = getState().eventInvite();
|
jout = getState().eventInvite();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (iq.getType().equals(IQ.Type.ERROR)) {
|
if (iq.getType().equals(IQ.Type.ERROR)) {
|
||||||
// Process errors
|
// Process errors
|
||||||
getState().eventError(iq);
|
getState().eventError(iq);
|
||||||
} else if (iq.getType().equals(IQ.Type.RESULT)) {
|
}
|
||||||
|
else if (iq.getType().equals(IQ.Type.RESULT)) {
|
||||||
// Process ACKs
|
// Process ACKs
|
||||||
if (isExpectedId(iq.getPacketID())) {
|
if (isExpectedId(iq.getPacketID())) {
|
||||||
jout = getState().eventAck(iq);
|
jout = getState().eventAck(iq);
|
||||||
removeExpectedId(iq.getPacketID());
|
removeExpectedId(iq.getPacketID());
|
||||||
}
|
}
|
||||||
} else if (iq instanceof Jingle) {
|
}
|
||||||
|
else if (iq instanceof Jingle) {
|
||||||
// It is not an error: it is a Jingle packet...
|
// It is not an error: it is a Jingle packet...
|
||||||
Jingle jin = (Jingle) iq;
|
Jingle jin = (Jingle) iq;
|
||||||
Jingle.Action action = jin.getAction();
|
Jingle.Action action = jin.getAction();
|
||||||
|
@ -366,16 +370,21 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
if (action.equals(Jingle.Action.SESSIONACCEPT)) {
|
if (action.equals(Jingle.Action.SESSIONACCEPT)) {
|
||||||
jout = getState().eventAccept(jin);
|
jout = getState().eventAccept(jin);
|
||||||
} else if (action.equals(Jingle.Action.SESSIONINFO)) {
|
}
|
||||||
|
else if (action.equals(Jingle.Action.SESSIONINFO)) {
|
||||||
jout = getState().eventInfo(jin);
|
jout = getState().eventInfo(jin);
|
||||||
} else if (action.equals(Jingle.Action.SESSIONINITIATE)) {
|
}
|
||||||
|
else if (action.equals(Jingle.Action.SESSIONINITIATE)) {
|
||||||
jout = getState().eventInitiate(jin);
|
jout = getState().eventInitiate(jin);
|
||||||
} else if (action.equals(Jingle.Action.SESSIONREDIRECT)) {
|
}
|
||||||
|
else if (action.equals(Jingle.Action.SESSIONREDIRECT)) {
|
||||||
jout = getState().eventRedirect(jin);
|
jout = getState().eventRedirect(jin);
|
||||||
} else if (action.equals(Jingle.Action.SESSIONTERMINATE)) {
|
}
|
||||||
|
else if (action.equals(Jingle.Action.SESSIONTERMINATE)) {
|
||||||
jout = getState().eventTerminate(jin);
|
jout = getState().eventTerminate(jin);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
jout = errorMalformedStanza(iq);
|
jout = errorMalformedStanza(iq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,7 +470,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
* @return the new Jingle packet
|
* @return the new Jingle packet
|
||||||
*/
|
*/
|
||||||
private Jingle sendJingleParts(IQ iq, Jingle jSes, Jingle jDesc,
|
private Jingle sendJingleParts(IQ iq, Jingle jSes, Jingle jDesc,
|
||||||
Jingle jTrans) {
|
Jingle jTrans) {
|
||||||
Jingle response = null;
|
Jingle response = null;
|
||||||
|
|
||||||
if (jSes != null) {
|
if (jSes != null) {
|
||||||
|
@ -469,7 +478,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
jSes.addTransports(jTrans.getTransportsList());
|
jSes.addTransports(jTrans.getTransportsList());
|
||||||
|
|
||||||
response = sendFormattedJingle(iq, jSes);
|
response = sendFormattedJingle(iq, jSes);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// If we don't have a valid session message, then we must send
|
// If we don't have a valid session message, then we must send
|
||||||
// separated messages for transport and jmf...
|
// separated messages for transport and jmf...
|
||||||
if (jDesc != null) {
|
if (jDesc != null) {
|
||||||
|
@ -534,7 +544,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (jout.getTo() == null) {
|
if (jout.getTo() == null) {
|
||||||
if (iq != null) {
|
if (iq != null) {
|
||||||
jout.setTo(iq.getFrom());
|
jout.setTo(iq.getFrom());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
jout.setTo(other);
|
jout.setTo(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -542,7 +553,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (jout.getFrom() == null) {
|
if (jout.getFrom() == null) {
|
||||||
if (iq != null) {
|
if (iq != null) {
|
||||||
jout.setFrom(iq.getTo());
|
jout.setFrom(iq.getTo());
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
jout.setFrom(me);
|
jout.setFrom(me);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,7 +647,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (jda.size() > 1) {
|
if (jda.size() > 1) {
|
||||||
throw new XMPPException(
|
throw new XMPPException(
|
||||||
"Unsupported feature: the number of accepted content descriptions is greater than 1.");
|
"Unsupported feature: the number of accepted content descriptions is greater than 1.");
|
||||||
} else if (jda.size() == 1) {
|
}
|
||||||
|
else if (jda.size() == 1) {
|
||||||
JingleContentDescription jd = (JingleContentDescription) jda.get(0);
|
JingleContentDescription jd = (JingleContentDescription) jda.get(0);
|
||||||
if (jd.getJinglePayloadTypesCount() > 1) {
|
if (jd.getJinglePayloadTypesCount() > 1) {
|
||||||
throw new XMPPException(
|
throw new XMPPException(
|
||||||
|
@ -667,13 +680,15 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (jta.size() > 1) {
|
if (jta.size() > 1) {
|
||||||
throw new XMPPException(
|
throw new XMPPException(
|
||||||
"Unsupported feature: the number of accepted transports is greater than 1.");
|
"Unsupported feature: the number of accepted transports is greater than 1.");
|
||||||
} else if (jta.size() == 1) {
|
}
|
||||||
|
else if (jta.size() == 1) {
|
||||||
org.jivesoftware.smackx.packet.JingleTransport jt = (org.jivesoftware.smackx.packet.JingleTransport) jta.get(0);
|
org.jivesoftware.smackx.packet.JingleTransport jt = (org.jivesoftware.smackx.packet.JingleTransport) jta.get(0);
|
||||||
|
|
||||||
if (jt.getCandidatesCount() > 1) {
|
if (jt.getCandidatesCount() > 1) {
|
||||||
throw new XMPPException(
|
throw new XMPPException(
|
||||||
"Unsupported feature: the number of accepted transport candidates is greater than 1.");
|
"Unsupported feature: the number of accepted transport candidates is greater than 1.");
|
||||||
} else if (jt.getCandidatesCount() == 1) {
|
}
|
||||||
|
else if (jt.getCandidatesCount() == 1) {
|
||||||
JingleTransportCandidate jtc = (JingleTransportCandidate) jt
|
JingleTransportCandidate jtc = (JingleTransportCandidate) jt
|
||||||
.getCandidatesList().get(0);
|
.getCandidatesList().get(0);
|
||||||
acceptedLocalCandidate = jtc.getMediaTransport();
|
acceptedLocalCandidate = jtc.getMediaTransport();
|
||||||
|
@ -717,7 +732,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (other.initiator != null) {
|
if (other.initiator != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!initiator.equals(other.initiator)) {
|
}
|
||||||
|
else if (!initiator.equals(other.initiator)) {
|
||||||
//Todo check behavior
|
//Todo check behavior
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
|
@ -726,7 +742,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (other.responder != null) {
|
if (other.responder != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!responder.equals(other.responder)) {
|
}
|
||||||
|
else if (!responder.equals(other.responder)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,7 +751,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
if (other.sid != null) {
|
if (other.sid != null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!sid.equals(other.sid)) {
|
}
|
||||||
|
else if (!sid.equals(other.sid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +865,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
public boolean accept(Packet packet) {
|
public boolean accept(Packet packet) {
|
||||||
|
|
||||||
final int cc = ccc++;
|
final int cc = ccc++;
|
||||||
System.out.println("filter:"+cc);
|
System.out.println("filter:" + cc);
|
||||||
|
|
||||||
if (packet instanceof IQ) {
|
if (packet instanceof IQ) {
|
||||||
IQ iq = (IQ) packet;
|
IQ iq = (IQ) packet;
|
||||||
|
@ -880,12 +898,14 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
System.out.println("Ignored Jingle(INI): " + iq.toXML());
|
System.out.println("Ignored Jingle(INI): " + iq.toXML());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// We accept some non-Jingle IQ packets: ERRORs and ACKs
|
// We accept some non-Jingle IQ packets: ERRORs and ACKs
|
||||||
if (iq.getType().equals(IQ.Type.SET)) {
|
if (iq.getType().equals(IQ.Type.SET)) {
|
||||||
System.out.println("Ignored Jingle(TYPE): " + iq.toXML());
|
System.out.println("Ignored Jingle(TYPE): " + iq.toXML());
|
||||||
return false;
|
return false;
|
||||||
} else if (iq.getType().equals(IQ.Type.GET)) {
|
}
|
||||||
|
else if (iq.getType().equals(IQ.Type.GET)) {
|
||||||
System.out.println("Ignored Jingle(TYPE): " + iq.toXML());
|
System.out.println("Ignored Jingle(TYPE): " + iq.toXML());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -977,7 +997,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
JingleListener li = (JingleListener) iter.next();
|
JingleListener li = (JingleListener) iter.next();
|
||||||
if (li instanceof JingleSessionListener) {
|
if (li instanceof JingleSessionListener) {
|
||||||
JingleSessionListener sli = (JingleSessionListener) li;
|
JingleSessionListener sli = (JingleSessionListener) li;
|
||||||
sli.sessionClosedOnError(exc,this);
|
sli.sessionClosedOnError(exc, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (jingleMediaSession != null) {
|
if (jingleMediaSession != null) {
|
||||||
|
@ -990,17 +1010,18 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
* Trigger a session established event.
|
* Trigger a session established event.
|
||||||
*/
|
*/
|
||||||
protected void triggerSessionEstablished(PayloadType pt,
|
protected void triggerSessionEstablished(PayloadType pt,
|
||||||
TransportCandidate rc, TransportCandidate lc) {
|
TransportCandidate rc, TransportCandidate lc) {
|
||||||
ArrayList listeners = getListenersList();
|
ArrayList listeners = getListenersList();
|
||||||
Iterator iter = listeners.iterator();
|
Iterator iter = listeners.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
JingleListener li = (JingleListener) iter.next();
|
JingleListener li = (JingleListener) iter.next();
|
||||||
if (li instanceof JingleSessionListener) {
|
if (li instanceof JingleSessionListener) {
|
||||||
JingleSessionListener sli = (JingleSessionListener) li;
|
JingleSessionListener sli = (JingleSessionListener) li;
|
||||||
sli.sessionEstablished(pt, rc, lc,this);
|
sli.sessionEstablished(pt, rc, lc, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lc.getCandidateEcho().cancel();
|
if (lc.getCandidateEcho() != null)
|
||||||
|
lc.removeCandidateEcho();
|
||||||
if (jingleMediaManager != null) {
|
if (jingleMediaManager != null) {
|
||||||
jingleMediaSession = jingleMediaManager.createMediaSession(pt, rc, lc);
|
jingleMediaSession = jingleMediaManager.createMediaSession(pt, rc, lc);
|
||||||
if (jingleMediaSession != null) {
|
if (jingleMediaSession != null) {
|
||||||
|
@ -1021,7 +1042,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
JingleListener li = (JingleListener) iter.next();
|
JingleListener li = (JingleListener) iter.next();
|
||||||
if (li instanceof JingleSessionListener) {
|
if (li instanceof JingleSessionListener) {
|
||||||
JingleSessionListener sli = (JingleSessionListener) li;
|
JingleSessionListener sli = (JingleSessionListener) li;
|
||||||
sli.sessionRedirected(arg,this);
|
sli.sessionRedirected(arg, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1057,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
JingleListener li = (JingleListener) iter.next();
|
JingleListener li = (JingleListener) iter.next();
|
||||||
if (li instanceof JingleSessionListener) {
|
if (li instanceof JingleSessionListener) {
|
||||||
JingleSessionListener sli = (JingleSessionListener) li;
|
JingleSessionListener sli = (JingleSessionListener) li;
|
||||||
sli.sessionDeclined(reason,this);
|
sli.sessionDeclined(reason, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1063,7 +1084,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
sendFormattedJingle(jout);
|
sendFormattedJingle(jout);
|
||||||
triggerSessionClosed("Closed Locally");
|
triggerSessionClosed("Closed Locally");
|
||||||
close();
|
close();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new IllegalStateException("Session Not Started");
|
throw new IllegalStateException("Session Not Started");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1091,7 +1113,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
* @return The created IQ packet.
|
* @return The created IQ packet.
|
||||||
*/
|
*/
|
||||||
public static IQ createIQ(String ID, String to, String from,
|
public static IQ createIQ(String ID, String to, String from,
|
||||||
IQ.Type type) {
|
IQ.Type type) {
|
||||||
IQ iqPacket = new IQ() {
|
IQ iqPacket = new IQ() {
|
||||||
public String getChildElementXML() {
|
public String getChildElementXML() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -1117,7 +1139,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
||||||
* @return The created IQ packet.
|
* @return The created IQ packet.
|
||||||
*/
|
*/
|
||||||
public static IQ createError(String ID, String to, String from,
|
public static IQ createError(String ID, String to, String from,
|
||||||
int errCode, String errStr) {
|
int errCode, String errStr) {
|
||||||
|
|
||||||
IQ iqError = createIQ(ID, to, from, IQ.Type.ERROR);
|
IQ iqError = createIQ(ID, to, from, IQ.Type.ERROR);
|
||||||
XMPPError error = new XMPPError(new XMPPError.Condition(errStr));
|
XMPPError error = new XMPPError(new XMPPError.Condition(errStr));
|
||||||
|
|
|
@ -147,7 +147,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
|
|
||||||
for (TransportCandidate candidate : offeredCandidates)
|
for (TransportCandidate candidate : offeredCandidates)
|
||||||
if (candidate.getCandidateEcho() != null)
|
if (candidate.getCandidateEcho() != null)
|
||||||
candidate.getCandidateEcho().cancel();
|
candidate.removeCandidateEcho();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,11 +851,10 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
||||||
for (TransportCandidate candidate : localCandidates) {
|
for (TransportCandidate candidate : localCandidates) {
|
||||||
TransportCandidate.CandidateEcho echo = candidate.getCandidateEcho();
|
TransportCandidate.CandidateEcho echo = candidate.getCandidateEcho();
|
||||||
if (echo != null) {
|
if (echo != null) {
|
||||||
if (echo.test(InetAddress.getByName(ice.getId()), ice.getPort(), 300))
|
if (echo.test(InetAddress.getByName(ice.getIp()), ice.getPort(), 500))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InetAddress.getByName(tc.getIp()).isReachable(3000);
|
InetAddress.getByName(tc.getIp()).isReachable(3000);
|
||||||
DatagramSocket socket = new DatagramSocket(0);
|
DatagramSocket socket = new DatagramSocket(0);
|
||||||
socket.connect(InetAddress.getByName(tc.getIp()), tc.getPort());
|
socket.connect(InetAddress.getByName(tc.getIp()), tc.getPort());
|
||||||
|
|
Loading…
Reference in a new issue