Bug 687972. More logging.
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 09 Dec 2011 17:48:40 +1300
changeset 84002 947f145ec0e7aaebe94149404e20f1f41cd8f3fb
parent 84001 1cdb116ae0b97106a2ccb4fb8e0c104cd535476f
child 84003 ee420d0f03df7b7446ce15d8acc365ad4fa61627
push idunknown
push userunknown
push dateunknown
bugs687972
milestone11.0a1
Bug 687972. More logging.
content/media/nsBuiltinDecoder.cpp
content/media/nsMediaCache.cpp
content/media/nsMediaCache.h
content/media/nsMediaStream.cpp
content/media/nsMediaStream.h
--- a/content/media/nsBuiltinDecoder.cpp
+++ b/content/media/nsBuiltinDecoder.cpp
@@ -639,18 +639,20 @@ void nsBuiltinDecoder::UpdatePlaybackRat
   mStream->SetPlaybackRate(rate);
 }
 
 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
     mElement->NotifyAutoplayDataReady();
   }
 }
 
 void nsBuiltinDecoder::NotifyBytesDownloaded()
--- a/content/media/nsMediaCache.cpp
+++ b/content/media/nsMediaCache.cpp
@@ -1903,23 +1903,30 @@ nsMediaCacheStream::SetSeekable(bool aIs
 bool
 nsMediaCacheStream::IsSeekable()
 {
   ReentrantMonitorAutoEnter mon(gMediaCache->GetReentrantMonitor());
   return mIsSeekable;
 }
 
 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;
 }
 
 void
 nsMediaCacheStream::Close()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
--- a/content/media/nsMediaCache.h
+++ b/content/media/nsMediaCache.h
@@ -38,17 +38,19 @@
 
 #ifndef nsMediaCache_h_
 #define nsMediaCache_h_
 
 #include "nsTArray.h"
 #include "nsIPrincipal.h"
 #include "nsCOMPtr.h"
 
+class nsMediaStream;
 class nsByteRange;
+
 namespace mozilla {
 class ReentrantMonitorAutoEnter;
 }
 
 /**
  * Media applications want fast, "on demand" random access to media data,
  * for pausing, seeking, etc. But we are primarily interested
  * in transporting media data using HTTP over the Internet, which has
@@ -349,17 +351,19 @@ public:
   // because it doesn't know when the decoder was paused, buffering, etc.
   // Do not pass zero.
   void SetPlaybackRate(PRUint32 aBytesPerSecond);
   // Returns the last set value of SetSeekable.
   bool IsSeekable();
 
   // 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
   // stream.
   // This can fail when aWhence is NS_SEEK_END and no stream length
   // is known.
   nsresult Seek(PRInt32 aWhence, PRInt64 aOffset);
   PRInt64 Tell();
--- a/content/media/nsMediaStream.cpp
+++ b/content/media/nsMediaStream.cpp
@@ -826,19 +826,19 @@ nsMediaChannelStream::IsDataCachedToEndO
 
 void
 nsMediaChannelStream::EnsureCacheUpToDate()
 {
   mCacheStream.EnsureCacheUpdate();
 }
 
 bool
-nsMediaChannelStream::IsSuspendedByCache()
+nsMediaChannelStream::IsSuspendedByCache(nsMediaStream** aActiveStream)
 {
-  return mCacheStream.AreAllStreamsForResourceSuspended();
+  return mCacheStream.AreAllStreamsForResourceSuspended(aActiveStream);
 }
 
 bool
 nsMediaChannelStream::IsSuspended()
 {
   MutexAutoLock lock(mLock);
   return mSuspendCount > 0;
 }
@@ -944,17 +944,23 @@ public:
   }
   virtual PRInt64 GetLength() { return mSize; }
   virtual PRInt64 GetNextCachedData(PRInt64 aOffset)
   {
     return (aOffset < mSize) ? aOffset : -1;
   }
   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<nsByteRange>& aRanges);
 
 private:
   // The file size, or -1 if not known. Immutable after Open().
   PRInt64 mSize;
 
--- a/content/media/nsMediaStream.h
+++ b/content/media/nsMediaStream.h
@@ -267,17 +267,19 @@ public:
   virtual bool IsDataCachedToEndOfStream(PRInt64 aOffset) = 0;
   // Returns true if this stream is suspended by the cache because the
   // cache is full. If true then the decoder should try to start consuming
   // data, otherwise we may not be able to make progress.
   // nsMediaDecoder::NotifySuspendedStatusChanged is called when this
   // 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
   // any data which overlaps uncached data, or if aCount bytes otherwise can't
   // be read, this function will return failure. This function be called from
   // any thread, and it is the only read operation which is safe to call on
   // the main thread, since it's guaranteed to be non blocking.
   virtual nsresult ReadFromCache(char* aBuffer,
@@ -399,17 +401,17 @@ public:
   // Any thread
   virtual void    Pin();
   virtual void    Unpin();
   virtual double  GetDownloadRate(bool* aIsReliable);
   virtual PRInt64 GetLength();
   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,
                    public nsIInterfaceRequestor,
                    public nsIChannelEventSink
   {
   public:
     Listener(nsMediaChannelStream* aStream) : mStream(aStream) {}