Bug 1329075 - Avoid an infinite event loop spin. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 09 Jan 2017 19:10:48 +0100
changeset 457699 60812e5fd30459e9b9ff10cf2d545e4414cfdd75
parent 457698 581a12ab6d7d6a988e64802ea3389034b09db8c6
child 541569 f23d9624e091b6fd5022d6c8d4bb5edfab7c9179
push id40870
push userbmo:pehrson@telenordigital.com
push dateMon, 09 Jan 2017 18:13:44 +0000
reviewersjesup
bugs1329075
milestone53.0a1
Bug 1329075 - Avoid an infinite event loop spin. r?jesup 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
@@ -3142,16 +3142,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();