From 4db24fa288ca2c8ed5e79720dbb5f54ccb44b153 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Sun, 10 May 2015 12:26:03 +0800 Subject: [PATCH] Bug 1163497. Part 2 - Remove MediaDecoder::DestroyDecodedStream(). r=roc. --- dom/media/DecodedStream.cpp | 29 ++++++++++++++++++++++++++++ dom/media/MediaDecoder.cpp | 38 ++----------------------------------- dom/media/MediaDecoder.h | 5 ----- 3 files changed, 31 insertions(+), 41 deletions(-) diff --git a/dom/media/DecodedStream.cpp b/dom/media/DecodedStream.cpp index 893a9ca05fab..ae1980da29d2 100644 --- a/dom/media/DecodedStream.cpp +++ b/dom/media/DecodedStream.cpp @@ -195,6 +195,33 @@ DecodedStream::DestroyData() { MOZ_ASSERT(NS_IsMainThread()); GetReentrantMonitor().AssertCurrentThreadIn(); + + // Avoid the redundant blocking to output stream. + if (!mData) { + return; + } + + // All streams are having their SourceMediaStream disconnected, so they + // need to be explicitly blocked again. + auto& outputStreams = OutputStreams(); + for (int32_t i = outputStreams.Length() - 1; i >= 0; --i) { + OutputStreamData& os = outputStreams[i]; + // Explicitly remove all existing ports. + // This is not strictly necessary but it's good form. + MOZ_ASSERT(os.mPort, "Double-delete of the ports!"); + os.mPort->Destroy(); + os.mPort = nullptr; + // During cycle collection, nsDOMMediaStream can be destroyed and send + // its Destroy message before this decoder is destroyed. So we have to + // be careful not to send any messages after the Destroy(). + if (os.mStream->IsDestroyed()) { + // Probably the DOM MediaStream was GCed. Clean up. + outputStreams.RemoveElementAt(i); + } else { + os.mStream->ChangeExplicitBlockerCount(1); + } + } + mData = nullptr; } @@ -223,6 +250,8 @@ DecodedStream::GetReentrantMonitor() void DecodedStream::Connect(OutputStreamData* aStream) { + MOZ_ASSERT(NS_IsMainThread()); + GetReentrantMonitor().AssertCurrentThreadIn(); NS_ASSERTION(!aStream->mPort, "Already connected?"); // The output stream must stay in sync with the decoded stream, so if diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index b2c707bf29fc..1940e05e2393 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -303,40 +303,6 @@ void MediaDecoder::UpdateDecodedStream() } } -void MediaDecoder::DestroyDecodedStream() -{ - MOZ_ASSERT(NS_IsMainThread()); - GetReentrantMonitor().AssertCurrentThreadIn(); - - // Avoid the redundant blocking to output stream. - if (!GetDecodedStream()) { - return; - } - - // All streams are having their SourceMediaStream disconnected, so they - // need to be explicitly blocked again. - auto& outputStreams = OutputStreams(); - for (int32_t i = outputStreams.Length() - 1; i >= 0; --i) { - OutputStreamData& os = outputStreams[i]; - // Explicitly remove all existing ports. - // This is not strictly necessary but it's good form. - MOZ_ASSERT(os.mPort, "Double-delete of the ports!"); - os.mPort->Destroy(); - os.mPort = nullptr; - // During cycle collection, nsDOMMediaStream can be destroyed and send - // its Destroy message before this decoder is destroyed. So we have to - // be careful not to send any messages after the Destroy(). - if (os.mStream->IsDestroyed()) { - // Probably the DOM MediaStream was GCed. Clean up. - outputStreams.RemoveElementAt(i); - } else { - os.mStream->ChangeExplicitBlockerCount(1); - } - } - - mDecodedStream.DestroyData(); -} - void MediaDecoder::UpdateStreamBlockingForStateMachinePlaying() { GetReentrantMonitor().AssertCurrentThreadIn(); @@ -369,8 +335,8 @@ void MediaDecoder::RecreateDecodedStream(int64_t aStartTimeUSecs, if (!aGraph) { aGraph = GetDecodedStream()->mStream->Graph(); } - DestroyDecodedStream(); + mDecodedStream.DestroyData(); mDecodedStream.RecreateData(aStartTimeUSecs, aGraph->CreateSourceStream(nullptr)); // Note that the delay between removing ports in DestroyDecodedStream @@ -562,7 +528,7 @@ MediaDecoder::~MediaDecoder() // Don't destroy the decoded stream until destructor in order to keep the // invariant that the decoded stream is always available in capture mode. ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); - DestroyDecodedStream(); + mDecodedStream.DestroyData(); } MediaMemoryTracker::RemoveMediaDecoder(this); UnpinForSeek(); diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index cc1be9de52eb..d156ab02d0d9 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -397,11 +397,6 @@ public: void UpdateDecodedStream(); - /** - * Disconnects mDecodedStream->mStream from all outputs and clears - * mDecodedStream. - */ - void DestroyDecodedStream(); /** * Recreates mDecodedStream. Call this to create mDecodedStream at first, * and when seeking, to ensure a new stream is set up with fresh buffers.