Bug 1072388 - Part 1: Allow createOffer to be called in have-local-offer, and allow repeated setting of offers. r=mjf
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 10 Apr 2019 15:56:20 +0000
changeset 469500 d9429bdabd04
parent 469499 eb773d96778e
child 469501 ec0a1e5ad360
push id35873
push userccoroiu@mozilla.com
push dateMon, 15 Apr 2019 21:36:26 +0000
treeherdermozilla-central@b8f49a14c458 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmjf
bugs1072388
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1072388 - Part 1: Allow createOffer to be called in have-local-offer, and allow repeated setting of offers. r=mjf Depends on D26779 Differential Revision: https://phabricator.services.mozilla.com/D26780
media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
--- a/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
+++ b/media/webrtc/signaling/src/jsep/JsepSessionImpl.cpp
@@ -345,17 +345,17 @@ nsresult JsepSessionImpl::GetRemoteIds(c
 
   return rv;
 }
 
 JsepSession::Result JsepSessionImpl::CreateOffer(
     const JsepOfferOptions& options, std::string* offer) {
   mLastError.clear();
 
-  if (mState != kJsepStateStable) {
+  if (mState != kJsepStateStable && mState != kJsepStateHaveLocalOffer) {
     JSEP_SET_ERROR("Cannot create offer in state " << GetStateStr(mState));
     // Spec doesn't seem to say this is an error. It probably should.
     return dom::PCError::InvalidStateError;
   }
 
   // This is one of those places where CreateOffer sets some state.
   SetIceRestarting(options.mIceRestart.isSome() && *(options.mIceRestart));
 
@@ -637,16 +637,21 @@ JsepSession::Result JsepSessionImpl::Set
       if (!mGeneratedOffer) {
         JSEP_SET_ERROR(
             "Cannot set local offer when createOffer has not been called.");
         return dom::PCError::InvalidModificationError;
       }
       if (sdp.empty()) {
         sdp = mGeneratedOffer->ToString();
       }
+      if (mState == kJsepStateHaveLocalOffer) {
+        // Rollback previous offer before applying the new one.
+        SetLocalDescription(kJsepSdpRollback, "");
+        MOZ_ASSERT(mState == kJsepStateStable);
+      }
       break;
     case kJsepSdpAnswer:
     case kJsepSdpPranswer:
       if (!mGeneratedAnswer) {
         JSEP_SET_ERROR(
             "Cannot set local answer when createAnswer has not been called.");
         return dom::PCError::InvalidModificationError;
       }
@@ -785,16 +790,22 @@ nsresult JsepSessionImpl::SetLocalDescri
 JsepSession::Result JsepSessionImpl::SetRemoteDescription(
     JsepSdpType type, const std::string& sdp) {
   mLastError.clear();
 
   MOZ_MTLOG(ML_DEBUG, "[" << mName << "]: SetRemoteDescription type=" << type
                           << "\nSDP=\n"
                           << sdp);
 
+  if (mState == kJsepStateHaveRemoteOffer && type == kJsepSdpOffer) {
+    // Rollback previous offer before applying the new one.
+    SetRemoteDescription(kJsepSdpRollback, "");
+    MOZ_ASSERT(mState == kJsepStateStable);
+  }
+
   if (type == kJsepSdpRollback) {
     if (mState != kJsepStateHaveRemoteOffer) {
       JSEP_SET_ERROR("Cannot rollback remote description in "
                      << GetStateStr(mState));
       return dom::PCError::InvalidStateError;
     }
 
     mPendingRemoteDescription.reset();