AppRTCDemo(android): don't send local SDP until it's set.

This fixes a race condition where the remote participant could receive the
offer, create & set its answer locally, send it back, and then try to set the
answer before the local set completed.  Observed intermittently in loopback
calls when setLocalDescription is intentionally delayed (debugging something
else).

R=henrike@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/9249004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5625 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org 2014-03-01 00:02:27 +00:00
parent b898ce9227
commit bcfc1670d6

View File

@ -438,18 +438,24 @@ public class AppRTCDemoActivity extends Activity
@Override public void onCreateSuccess(final SessionDescription origSdp) {
runOnUiThread(new Runnable() {
public void run() {
logAndToast("Sending " + origSdp.type);
SessionDescription sdp = new SessionDescription(
origSdp.type, preferISAC(origSdp.description));
JSONObject json = new JSONObject();
jsonPut(json, "type", sdp.type.canonicalForm());
jsonPut(json, "sdp", sdp.description);
sendMessage(json);
pc.setLocalDescription(sdpObserver, sdp);
}
});
}
// Helper for sending local SDP (offer or answer, depending on role) to the
// other participant.
private void sendLocalDescription(PeerConnection pc) {
SessionDescription sdp = pc.getLocalDescription();
logAndToast("Sending " + sdp.type);
JSONObject json = new JSONObject();
jsonPut(json, "type", sdp.type.canonicalForm());
jsonPut(json, "sdp", sdp.description);
sendMessage(json);
}
@Override public void onSetSuccess() {
runOnUiThread(new Runnable() {
public void run() {
@ -458,6 +464,9 @@ public class AppRTCDemoActivity extends Activity
// We've set our local offer and received & set the remote
// answer, so drain candidates.
drainRemoteCandidates();
} else {
// We've just set our local description so time to send it.
sendLocalDescription(pc);
}
} else {
if (pc.getLocalDescription() == null) {
@ -465,8 +474,9 @@ public class AppRTCDemoActivity extends Activity
logAndToast("Creating answer");
pc.createAnswer(SDPObserver.this, sdpMediaConstraints);
} else {
// Sent our answer and set it as local description; drain
// Answer now set as local description; send it and drain
// candidates.
sendLocalDescription(pc);
drainRemoteCandidates();
}
}