diff --git a/content/media/nsBuiltinDecoder.cpp b/content/media/nsBuiltinDecoder.cpp index e9ae1fd101ac..813a457ef196 100644 --- a/content/media/nsBuiltinDecoder.cpp +++ b/content/media/nsBuiltinDecoder.cpp @@ -644,8 +644,10 @@ void nsBuiltinDecoder::NotifySuspendedStatusChanged() NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); if (!mStream) return; - bool suspended = mStream->IsSuspendedByCache(); - printf("*** nsBuiltinDecoder::NotifySuspendedStatusChanged(%p), suspended=%d\n", this, suspended); + nsMediaStream* activeStream; + bool suspended = mStream->IsSuspendedByCache(&activeStream); + + printf("*** nsBuiltinDecoder::NotifySuspendedStatusChanged(%p), suspended=%d, active-stream=%p\n", this, suspended, activeStream); if (suspended && mElement) { // if this is an autoplay element, we need to kick off its autoplaying // now so we consume data and hopefully free up cache space diff --git a/content/media/nsMediaCache.cpp b/content/media/nsMediaCache.cpp index 52a5f0b2ca3c..7af430bd6a9c 100644 --- a/content/media/nsMediaCache.cpp +++ b/content/media/nsMediaCache.cpp @@ -1908,13 +1908,20 @@ nsMediaCacheStream::IsSeekable() } bool -nsMediaCacheStream::AreAllStreamsForResourceSuspended() +nsMediaCacheStream::AreAllStreamsForResourceSuspended(nsMediaStream** aActiveStream) { ReentrantMonitorAutoEnter mon(gMediaCache->GetReentrantMonitor()); nsMediaCache::ResourceStreamIterator iter(mResourceID); while (nsMediaCacheStream* stream = iter.Next()) { - if (!stream->mCacheSuspended && !stream->mChannelEnded) + if (!stream->mCacheSuspended && !stream->mChannelEnded) { + if (aActiveStream) { + *aActiveStream = stream->mClient; + } return false; + } + } + if (aActiveStream) { + *aActiveStream = nsnull; } return true; } diff --git a/content/media/nsMediaCache.h b/content/media/nsMediaCache.h index e5808f042712..784f321b320c 100644 --- a/content/media/nsMediaCache.h +++ b/content/media/nsMediaCache.h @@ -43,7 +43,9 @@ #include "nsIPrincipal.h" #include "nsCOMPtr.h" +class nsMediaStream; class nsByteRange; + namespace mozilla { class ReentrantMonitorAutoEnter; } @@ -354,7 +356,9 @@ public: // Returns true when all streams for this resource are suspended or their // channel has ended. - bool AreAllStreamsForResourceSuspended(); + // If aActiveStream is non-null, fills it with a pointer to a stream + // for this resource that is not suspended or ended. + bool AreAllStreamsForResourceSuspended(nsMediaStream** aActiveStream); // These methods must be called on a different thread from the main // thread. They should always be called on the same thread for a given diff --git a/content/media/nsMediaStream.cpp b/content/media/nsMediaStream.cpp index 65db21322d31..9993727db6c9 100644 --- a/content/media/nsMediaStream.cpp +++ b/content/media/nsMediaStream.cpp @@ -831,9 +831,9 @@ nsMediaChannelStream::EnsureCacheUpToDate() } bool -nsMediaChannelStream::IsSuspendedByCache() +nsMediaChannelStream::IsSuspendedByCache(nsMediaStream** aActiveStream) { - return mCacheStream.AreAllStreamsForResourceSuspended(); + return mCacheStream.AreAllStreamsForResourceSuspended(aActiveStream); } bool @@ -949,7 +949,13 @@ public: } virtual PRInt64 GetCachedDataEnd(PRInt64 aOffset) { return NS_MAX(aOffset, mSize); } virtual bool IsDataCachedToEndOfStream(PRInt64 aOffset) { return true; } - virtual bool IsSuspendedByCache() { return false; } + virtual bool IsSuspendedByCache(nsMediaStream** aActiveStream) + { + if (aActiveStream) { + *aActiveStream = nsnull; + } + return false; + } virtual bool IsSuspended() { return false; } nsresult GetCachedRanges(nsTArray& aRanges); diff --git a/content/media/nsMediaStream.h b/content/media/nsMediaStream.h index 66a839b5a5a0..3473210b553d 100644 --- a/content/media/nsMediaStream.h +++ b/content/media/nsMediaStream.h @@ -272,7 +272,9 @@ public: // changes. // For resources using the media cache, this returns true only when all // streams for the same resource are all suspended. - virtual bool IsSuspendedByCache() = 0; + // If aActiveStream is non-null, fills it with a pointer to a stream + // for this resource that is not suspended or ended. + virtual bool IsSuspendedByCache(nsMediaStream** aActiveStream) = 0; // Returns true if this stream has been suspended. virtual bool IsSuspended() = 0; // Reads only data which is cached in the media cache. If you try to read @@ -404,7 +406,7 @@ public: virtual PRInt64 GetNextCachedData(PRInt64 aOffset); virtual PRInt64 GetCachedDataEnd(PRInt64 aOffset); virtual bool IsDataCachedToEndOfStream(PRInt64 aOffset); - virtual bool IsSuspendedByCache(); + virtual bool IsSuspendedByCache(nsMediaStream** aActiveStream); virtual bool IsSuspended(); class Listener : public nsIStreamListener,