From f7821ba18416d91aa780d21624b4406451c1f43a Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 30 Sep 2015 09:31:54 +0800 Subject: [PATCH] Bug 1170958 - Destroy track-locked MediaInputPorts when the track ends. r=roc This is needed to make tests pass until we have bug 1208316 implemented. --HG-- extra : commitid : GPSNwBVyD4j extra : rebase_source : b7cb9cb1678a582fbf85b729b8f43508889f5c78 --- dom/media/DOMMediaStream.cpp | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/dom/media/DOMMediaStream.cpp b/dom/media/DOMMediaStream.cpp index 0176d25e6383..7781cb446880 100644 --- a/dom/media/DOMMediaStream.cpp +++ b/dom/media/DOMMediaStream.cpp @@ -88,6 +88,14 @@ protected: } public: + void DestroyInputPort() + { + if (mInputPort) { + mInputPort->Destroy(); + mInputPort = nullptr; + } + } + /** * Returns the source stream of the input port. */ @@ -225,12 +233,26 @@ public: nsRefPtr track = mStream->FindPlaybackDOMTrack(aInputStream, aInputTrackID); - if (track) { - LOG(LogLevel::Debug, ("DOMMediaStream %p Playback track; notifying stream listeners.", - mStream)); - mStream->NotifyTrackRemoved(track); - } else { + if (!track) { LOG(LogLevel::Debug, ("DOMMediaStream %p Not a playback track.", mStream)); + return; + } + + LOG(LogLevel::Debug, ("DOMMediaStream %p Playback track; notifying stream listeners.", + mStream)); + mStream->NotifyTrackRemoved(track); + + nsRefPtr endedPort = mStream->FindPlaybackTrackPort(*track); + NS_ASSERTION(endedPort, "Playback track should have a TrackPort"); + if (endedPort && + endedPort->GetSourceTrackId() != TRACK_ANY && + endedPort->GetSourceTrackId() != TRACK_INVALID && + endedPort->GetSourceTrackId() != TRACK_NONE) { + // If a track connected to a locked-track input port ends, we destroy the + // port to allow our playback stream to finish. + // XXX (bug 1208316) This should not be necessary when MediaStreams don't + // finish but instead become inactive. + endedPort->DestroyInputPort(); } }