From bcfc1670d6454e547a79b983162e363a3a54f1dd Mon Sep 17 00:00:00 2001 From: "fischman@webrtc.org" Date: Sat, 1 Mar 2014 00:02:27 +0000 Subject: [PATCH] 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 --- .../appspot/apprtc/AppRTCDemoActivity.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java b/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java index f75c7c9659..46b61696a3 100644 --- a/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java +++ b/talk/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java @@ -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(); } }