Bug 1493689 - Defer close of old stream after ICE restart. r=mjf
authorByron Campen [:bwc] <docfaraday@gmail.com>
Thu, 04 Oct 2018 21:30:22 -0400
changeset 495466 6e67424a39d745df5adee264bd6b084cf1042adc
parent 495465 7ee4eac9ae35ab547b05e0ff600c4f26cc079144
child 495478 a7cd9a613cac1a27d38aafea2e053b7825d0130e
child 495480 423ba8ffc8d742062721bd9d2d994b4aa8de21af
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmjf
bugs1493689
milestone64.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 1493689 - Defer close of old stream after ICE restart. r=mjf Differential Revision: https://phabricator.services.mozilla.com/D7626
media/mtransport/nricemediastream.cpp
media/mtransport/nricemediastream.h
--- a/media/mtransport/nricemediastream.cpp
+++ b/media/mtransport/nricemediastream.cpp
@@ -41,16 +41,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 */
 
 
 #include <string>
 #include <vector>
 
 #include "logging.h"
 #include "nsError.h"
+#include "nsThreadUtils.h"
 
 // nICEr includes
 extern "C" {
 #include "nr_api.h"
 #include "registry.h"
 #include "async_timer.h"
 #include "ice_util.h"
 #include "transport_addr.h"
@@ -652,30 +653,38 @@ nsresult NrIceMediaStream::SendPacket(in
 
 
 void NrIceMediaStream::Ready() {
   // This function is called whenever a stream becomes ready, but it
   // gets fired multiple times when a stream gets nominated repeatedly.
   if (state_ != ICE_OPEN) {
     MOZ_MTLOG(ML_DEBUG, "Marking stream ready '" << name_ << "'");
     state_ = ICE_OPEN;
-    CloseStream(&old_stream_);
+    NS_DispatchToCurrentThread(NewRunnableMethod<nr_ice_media_stream*>(
+          "NrIceMediaStream::DeferredCloseOldStream",
+          this,
+          &NrIceMediaStream::DeferredCloseOldStream,
+          old_stream_));
     SignalReady(this);
   }
   else {
     MOZ_MTLOG(ML_DEBUG, "Stream ready callback fired again for '" << name_ << "'");
   }
 }
 
 void NrIceMediaStream::Failed() {
   if (state_ != ICE_CLOSED) {
     MOZ_MTLOG(ML_DEBUG, "Marking stream failed '" << name_ << "'");
     state_ = ICE_CLOSED;
     // We don't need the old stream anymore.
-    CloseStream(&old_stream_);
+    NS_DispatchToCurrentThread(NewRunnableMethod<nr_ice_media_stream*>(
+          "NrIceMediaStream::DeferredCloseOldStream",
+          this,
+          &NrIceMediaStream::DeferredCloseOldStream,
+          old_stream_));
     SignalFailed(this);
   }
 }
 
 void NrIceMediaStream::Close() {
   MOZ_MTLOG(ML_DEBUG, "Marking stream closed '" << name_ << "'");
   state_ = ICE_CLOSED;
 
@@ -691,9 +700,17 @@ NrIceMediaStream::CloseStream(nr_ice_med
     if (r) {
       MOZ_ASSERT(false, "Failed to remove stream");
       MOZ_MTLOG(ML_ERROR, "Failed to remove stream, error=" << r);
     }
     *stream = nullptr;
   }
 }
 
+void
+NrIceMediaStream::DeferredCloseOldStream(const nr_ice_media_stream *old)
+{
+  if (old == old_stream_) {
+    CloseStream(&old_stream_);
+  }
+}
+
 }  // close namespace
--- a/media/mtransport/nricemediastream.h
+++ b/media/mtransport/nricemediastream.h
@@ -216,16 +216,17 @@ class NrIceMediaStream {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceMediaStream)
 
  private:
   ~NrIceMediaStream();
 
   DISALLOW_COPY_ASSIGN(NrIceMediaStream);
 
   void CloseStream(nr_ice_media_stream **stream);
+  void DeferredCloseOldStream(const nr_ice_media_stream *old);
 
   State state_;
   nr_ice_ctx *ctx_;
   nr_ice_peer_ctx *ctx_peer_;
   const std::string name_;
   const size_t components_;
   nr_ice_media_stream *stream_;
   nr_ice_media_stream *old_stream_;