1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-21 19:04:49 +02: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:
Thiago Camargo 2007-02-07 04:57:23 +00:00 committed by thiago
parent 85387aa360
commit a5a6697496
2 changed files with 59 additions and 38 deletions

View file

@ -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.
* *
@ -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);
} }
} }
@ -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;
} }
@ -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;
} }
@ -1000,7 +1020,8 @@ public abstract class JingleSession extends JingleNegotiator {
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) {
@ -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");
} }
} }

View file

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