From adf481a046f6bded1bb48e0abf0c901bdf3d963d Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Mon, 9 Jan 2017 19:10:48 +0100 Subject: [PATCH] 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 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 2f5c24c0aeb5..f639c98ef44e 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -3150,6 +3150,12 @@ HTMLMediaElement::AddCaptureMediaTrackToOutputStream(MediaTrack* aTrack, } 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");