Bug 1329075 - Avoid an infinite event loop spin. r=jesup, a=jcristau
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 09 Jan 2017 19:10:48 +0100
changeset 353524 c1748b934c3714bd81a4b7622d650b2682fcdf13
parent 353523 99745f6d10aa44d85b1d3f8765c07b8de62f2fb9
child 353525 bc41a634b3895fe95519e6951ac9b63f2cf1f6fa
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, jcristau
bugs1329075
milestone52.0a2
Bug 1329075 - Avoid an infinite event loop spin. r=jesup, a=jcristau Because we add tracks to the output streams async, it's possible to switch the mSrcStream of a media element and *then* get a notification of an added track, when this track originated from the old mSrcStream. If the new mSrcStream is an output stream of the media element, this would again add a new track async, which on the next event loop spin would show up on mSrcStream, and the loop continues. MozReview-Commit-ID: HmKgXLYmubh
dom/html/HTMLMediaElement.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2581,16 +2581,22 @@ HTMLMediaElement::AddCaptureMediaTrackTo
                                                      bool aAsyncAddtrack)
 {
   if (aOutputStream.mCapturingDecoder) {
     MOZ_ASSERT(!aOutputStream.mCapturingMediaStream);
     return;
   }
   aOutputStream.mCapturingMediaStream = true;
 
+  if (aOutputStream.mStream == mSrcStream) {
+    // Cycle detected. This can happen since tracks are added async.
+    // We avoid forwarding it to the output here or we'd get into an infloop.
+    return;
+  }
+
   MediaStream* outputSource = aOutputStream.mStream->GetInputStream();
   if (!outputSource) {
     NS_ERROR("No output source stream");
     return;
   }
 
   ProcessedMediaStream* processedOutputSource =
     outputSource->AsProcessedStream();