mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32:06 +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.
|
||||
*
|
||||
* <p/>
|
||||
* This class contains some basic properties of every Jingle session. However,
|
||||
* the concrete implementation can be found in subclasses.
|
||||
*
|
||||
|
@ -116,7 +116,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
|
||||
protected JingleMediaSession jingleMediaSession = null;
|
||||
|
||||
static int ccc=0;
|
||||
static int ccc = 0;
|
||||
|
||||
/**
|
||||
* Full featured JingleSession constructor
|
||||
|
@ -128,7 +128,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* @param jingleMediaManager the jingleMediaManager
|
||||
*/
|
||||
protected JingleSession(XMPPConnection conn, String initiator, String responder,
|
||||
String sessionid, JingleMediaManager jingleMediaManager) {
|
||||
String sessionid, JingleMediaManager jingleMediaManager) {
|
||||
super(conn);
|
||||
|
||||
this.mediaNeg = null;
|
||||
|
@ -344,21 +344,25 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (invalidState()) {
|
||||
throw new IllegalStateException(
|
||||
"Illegal state in dispatch packet in Session manager.");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (iq == null) {
|
||||
// If there is no input packet, then we must be inviting...
|
||||
jout = getState().eventInvite();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (iq.getType().equals(IQ.Type.ERROR)) {
|
||||
// Process errors
|
||||
getState().eventError(iq);
|
||||
} else if (iq.getType().equals(IQ.Type.RESULT)) {
|
||||
}
|
||||
else if (iq.getType().equals(IQ.Type.RESULT)) {
|
||||
// Process ACKs
|
||||
if (isExpectedId(iq.getPacketID())) {
|
||||
jout = getState().eventAck(iq);
|
||||
removeExpectedId(iq.getPacketID());
|
||||
}
|
||||
} else if (iq instanceof Jingle) {
|
||||
}
|
||||
else if (iq instanceof Jingle) {
|
||||
// It is not an error: it is a Jingle packet...
|
||||
Jingle jin = (Jingle) iq;
|
||||
Jingle.Action action = jin.getAction();
|
||||
|
@ -366,16 +370,21 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (action != null) {
|
||||
if (action.equals(Jingle.Action.SESSIONACCEPT)) {
|
||||
jout = getState().eventAccept(jin);
|
||||
} else if (action.equals(Jingle.Action.SESSIONINFO)) {
|
||||
}
|
||||
else if (action.equals(Jingle.Action.SESSIONINFO)) {
|
||||
jout = getState().eventInfo(jin);
|
||||
} else if (action.equals(Jingle.Action.SESSIONINITIATE)) {
|
||||
}
|
||||
else if (action.equals(Jingle.Action.SESSIONINITIATE)) {
|
||||
jout = getState().eventInitiate(jin);
|
||||
} else if (action.equals(Jingle.Action.SESSIONREDIRECT)) {
|
||||
}
|
||||
else if (action.equals(Jingle.Action.SESSIONREDIRECT)) {
|
||||
jout = getState().eventRedirect(jin);
|
||||
} else if (action.equals(Jingle.Action.SESSIONTERMINATE)) {
|
||||
}
|
||||
else if (action.equals(Jingle.Action.SESSIONTERMINATE)) {
|
||||
jout = getState().eventTerminate(jin);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
jout = errorMalformedStanza(iq);
|
||||
}
|
||||
}
|
||||
|
@ -461,7 +470,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* @return the new Jingle packet
|
||||
*/
|
||||
private Jingle sendJingleParts(IQ iq, Jingle jSes, Jingle jDesc,
|
||||
Jingle jTrans) {
|
||||
Jingle jTrans) {
|
||||
Jingle response = null;
|
||||
|
||||
if (jSes != null) {
|
||||
|
@ -469,7 +478,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
jSes.addTransports(jTrans.getTransportsList());
|
||||
|
||||
response = sendFormattedJingle(iq, jSes);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// If we don't have a valid session message, then we must send
|
||||
// separated messages for transport and jmf...
|
||||
if (jDesc != null) {
|
||||
|
@ -534,7 +544,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (jout.getTo() == null) {
|
||||
if (iq != null) {
|
||||
jout.setTo(iq.getFrom());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
jout.setTo(other);
|
||||
}
|
||||
}
|
||||
|
@ -542,7 +553,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (jout.getFrom() == null) {
|
||||
if (iq != null) {
|
||||
jout.setFrom(iq.getTo());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
jout.setFrom(me);
|
||||
}
|
||||
}
|
||||
|
@ -635,7 +647,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (jda.size() > 1) {
|
||||
throw new XMPPException(
|
||||
"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);
|
||||
if (jd.getJinglePayloadTypesCount() > 1) {
|
||||
throw new XMPPException(
|
||||
|
@ -667,13 +680,15 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (jta.size() > 1) {
|
||||
throw new XMPPException(
|
||||
"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);
|
||||
|
||||
if (jt.getCandidatesCount() > 1) {
|
||||
throw new XMPPException(
|
||||
"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
|
||||
.getCandidatesList().get(0);
|
||||
acceptedLocalCandidate = jtc.getMediaTransport();
|
||||
|
@ -717,7 +732,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (other.initiator != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!initiator.equals(other.initiator)) {
|
||||
}
|
||||
else if (!initiator.equals(other.initiator)) {
|
||||
//Todo check behavior
|
||||
// return false;
|
||||
}
|
||||
|
@ -726,7 +742,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (other.responder != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!responder.equals(other.responder)) {
|
||||
}
|
||||
else if (!responder.equals(other.responder)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -734,7 +751,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
if (other.sid != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!sid.equals(other.sid)) {
|
||||
}
|
||||
else if (!sid.equals(other.sid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -847,7 +865,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
public boolean accept(Packet packet) {
|
||||
|
||||
final int cc = ccc++;
|
||||
System.out.println("filter:"+cc);
|
||||
System.out.println("filter:" + cc);
|
||||
|
||||
if (packet instanceof IQ) {
|
||||
IQ iq = (IQ) packet;
|
||||
|
@ -880,12 +898,14 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
System.out.println("Ignored Jingle(INI): " + iq.toXML());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// We accept some non-Jingle IQ packets: ERRORs and ACKs
|
||||
if (iq.getType().equals(IQ.Type.SET)) {
|
||||
System.out.println("Ignored Jingle(TYPE): " + iq.toXML());
|
||||
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());
|
||||
return false;
|
||||
}
|
||||
|
@ -977,7 +997,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
JingleListener li = (JingleListener) iter.next();
|
||||
if (li instanceof JingleSessionListener) {
|
||||
JingleSessionListener sli = (JingleSessionListener) li;
|
||||
sli.sessionClosedOnError(exc,this);
|
||||
sli.sessionClosedOnError(exc, this);
|
||||
}
|
||||
}
|
||||
if (jingleMediaSession != null) {
|
||||
|
@ -990,17 +1010,18 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* Trigger a session established event.
|
||||
*/
|
||||
protected void triggerSessionEstablished(PayloadType pt,
|
||||
TransportCandidate rc, TransportCandidate lc) {
|
||||
TransportCandidate rc, TransportCandidate lc) {
|
||||
ArrayList listeners = getListenersList();
|
||||
Iterator iter = listeners.iterator();
|
||||
while (iter.hasNext()) {
|
||||
JingleListener li = (JingleListener) iter.next();
|
||||
if (li instanceof JingleSessionListener) {
|
||||
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) {
|
||||
jingleMediaSession = jingleMediaManager.createMediaSession(pt, rc, lc);
|
||||
if (jingleMediaSession != null) {
|
||||
|
@ -1021,7 +1042,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
JingleListener li = (JingleListener) iter.next();
|
||||
if (li instanceof JingleSessionListener) {
|
||||
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();
|
||||
if (li instanceof JingleSessionListener) {
|
||||
JingleSessionListener sli = (JingleSessionListener) li;
|
||||
sli.sessionDeclined(reason,this);
|
||||
sli.sessionDeclined(reason, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1063,7 +1084,8 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
sendFormattedJingle(jout);
|
||||
triggerSessionClosed("Closed Locally");
|
||||
close();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Session Not Started");
|
||||
}
|
||||
}
|
||||
|
@ -1074,7 +1096,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
public void close() {
|
||||
destroyMediaNeg();
|
||||
destroyTransportNeg();
|
||||
removePacketListener();
|
||||
removePacketListener();
|
||||
System.out.println("Negociation Closed");
|
||||
super.close();
|
||||
}
|
||||
|
@ -1091,7 +1113,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* @return The created IQ packet.
|
||||
*/
|
||||
public static IQ createIQ(String ID, String to, String from,
|
||||
IQ.Type type) {
|
||||
IQ.Type type) {
|
||||
IQ iqPacket = new IQ() {
|
||||
public String getChildElementXML() {
|
||||
return null;
|
||||
|
@ -1117,7 +1139,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* @return The created IQ packet.
|
||||
*/
|
||||
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);
|
||||
XMPPError error = new XMPPError(new XMPPError.Condition(errStr));
|
||||
|
|
|
@ -147,7 +147,7 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
|
||||
for (TransportCandidate candidate : offeredCandidates)
|
||||
if (candidate.getCandidateEcho() != null)
|
||||
candidate.getCandidateEcho().cancel();
|
||||
candidate.removeCandidateEcho();
|
||||
|
||||
}
|
||||
|
||||
|
@ -851,11 +851,10 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
for (TransportCandidate candidate : localCandidates) {
|
||||
TransportCandidate.CandidateEcho echo = candidate.getCandidateEcho();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
InetAddress.getByName(tc.getIp()).isReachable(3000);
|
||||
DatagramSocket socket = new DatagramSocket(0);
|
||||
socket.connect(InetAddress.getByName(tc.getIp()), tc.getPort());
|
||||
|
|
Loading…
Reference in a new issue