From 9f9181708848e50e7e2fa9ee3ce18044a5c47d4f Mon Sep 17 00:00:00 2001 From: JW Wang Date: Sun, 10 May 2015 11:57:46 +0800 Subject: [PATCH] Bug 1163474. Part 2 - move MediaDecoder::mOutputStreams to DecodedStream. r=roc. --- dom/media/DecodedStream.cpp | 6 ++++++ dom/media/DecodedStream.h | 4 ++++ dom/media/MediaDecoder.cpp | 14 ++++++++------ dom/media/MediaDecoder.h | 5 ++--- dom/media/omx/MediaOmxCommonDecoder.cpp | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dom/media/DecodedStream.cpp b/dom/media/DecodedStream.cpp index e3d4d26c0a8c..2a976c7730e7 100644 --- a/dom/media/DecodedStream.cpp +++ b/dom/media/DecodedStream.cpp @@ -204,4 +204,10 @@ DecodedStream::RecreateData(MediaDecoder* aDecoder, int64_t aInitialTime, mData.reset(new DecodedStreamData(aDecoder, aInitialTime, aStream)); } +nsTArray& +DecodedStream::OutputStreams() +{ + return mOutputStreams; +} + } // namespace mozilla diff --git a/dom/media/DecodedStream.h b/dom/media/DecodedStream.h index 31da7799387b..74dd93c89f7b 100644 --- a/dom/media/DecodedStream.h +++ b/dom/media/DecodedStream.h @@ -8,6 +8,7 @@ #define DecodedStream_h_ #include "nsRefPtr.h" +#include "nsTArray.h" #include "mozilla/UniquePtr.h" #include "mozilla/gfx/Point.h" @@ -101,9 +102,12 @@ public: void DestroyData(); void RecreateData(MediaDecoder* aDecoder, int64_t aInitialTime, SourceMediaStream* aStream); + nsTArray& OutputStreams(); private: UniquePtr mData; + // Data about MediaStreams that are being fed by the decoder. + nsTArray mOutputStreams; }; } // namespace mozilla diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 0a171c0fdad9..95023ee4fbe3 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -328,8 +328,9 @@ void MediaDecoder::DestroyDecodedStream() // All streams are having their SourceMediaStream disconnected, so they // need to be explicitly blocked again. - for (int32_t i = mOutputStreams.Length() - 1; i >= 0; --i) { - OutputStreamData& os = mOutputStreams[i]; + 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!"); @@ -340,7 +341,7 @@ void MediaDecoder::DestroyDecodedStream() // be careful not to send any messages after the Destroy(). if (os.mStream->IsDestroyed()) { // Probably the DOM MediaStream was GCed. Clean up. - mOutputStreams.RemoveElementAt(i); + outputStreams.RemoveElementAt(i); } else { os.mStream->ChangeExplicitBlockerCount(1); } @@ -389,8 +390,9 @@ void MediaDecoder::RecreateDecodedStream(int64_t aStartTimeUSecs, // Note that the delay between removing ports in DestroyDecodedStream // and adding new ones won't cause a glitch since all graph operations // between main-thread stable states take effect atomically. - for (int32_t i = mOutputStreams.Length() - 1; i >= 0; --i) { - OutputStreamData& os = mOutputStreams[i]; + auto& outputStreams = OutputStreams(); + for (int32_t i = outputStreams.Length() - 1; i >= 0; --i) { + OutputStreamData& os = outputStreams[i]; MOZ_ASSERT(!os.mStream->IsDestroyed(), "Should've been removed in DestroyDecodedStream()"); ConnectDecodedStreamToOutputStream(&os); @@ -417,7 +419,7 @@ void MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream, if (!GetDecodedStream()) { RecreateDecodedStream(mLogicalPosition, aStream->Graph()); } - OutputStreamData* os = mOutputStreams.AppendElement(); + OutputStreamData* os = OutputStreams().AppendElement(); os->Init(this, aStream); ConnectDecodedStreamToOutputStream(os); if (aFinishWhenEnded) { diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 8a460a8eafac..3e44343256d7 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -420,10 +420,11 @@ public: * Decoder monitor must be held. */ void UpdateStreamBlockingForStateMachinePlaying(); + nsTArray& OutputStreams() { GetReentrantMonitor().AssertCurrentThreadIn(); - return mOutputStreams; + return mDecodedStream.OutputStreams(); } DecodedStreamData* GetDecodedStream() @@ -1031,8 +1032,6 @@ private: #endif protected: - // Data about MediaStreams that are being fed by this decoder. - nsTArray mOutputStreams; // The SourceMediaStream we are using to feed the mOutputStreams. This stream // is never exposed outside the decoder. // Only written on the main thread while holding the monitor. Therefore it diff --git a/dom/media/omx/MediaOmxCommonDecoder.cpp b/dom/media/omx/MediaOmxCommonDecoder.cpp index e138b4b823a1..eed0cde50619 100644 --- a/dom/media/omx/MediaOmxCommonDecoder.cpp +++ b/dom/media/omx/MediaOmxCommonDecoder.cpp @@ -47,7 +47,7 @@ bool MediaOmxCommonDecoder::CheckDecoderCanOffloadAudio() { return (mCanOffloadAudio && !mFallbackToStateMachine && - !mOutputStreams.Length() && mPlaybackRate == 1.0); + !OutputStreams().Length() && mPlaybackRate == 1.0); } void