Bug 585864 - Increase media cache block size from 4kB to 32kB. r=roc a=roc
authorMatthew Gregan <kinetik@flim.org>
Fri, 13 Aug 2010 12:41:47 +1200
changeset 50369 edbc3ebfd63c5ffaafbd5f39099d8ce54451ec7f
parent 50368 96de52e4a44203a33165281dbbdef1063f50a2d8
child 50370 245b36903bfb795c46c36f65bc0b64d1b7a468e0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, roc
bugs585864
milestone2.0b4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 585864 - Increase media cache block size from 4kB to 32kB. r=roc a=roc
content/media/nsMediaCache.cpp
content/media/nsMediaCache.h
content/media/nsMediaStream.cpp
content/media/nsMediaStream.h
--- a/content/media/nsMediaCache.cpp
+++ b/content/media/nsMediaCache.cpp
@@ -1199,21 +1199,23 @@ nsMediaCache::Update()
             stream, predictedNewDataUse.ToSeconds(), latestNextUse.ToSeconds()));
         enableReading = predictedNewDataUse < latestNextUse;
       }
 
       if (enableReading) {
         for (PRUint32 j = 0; j < i; ++j) {
           nsMediaCacheStream* other = mStreams[j];
           if (other->mResourceID == stream->mResourceID &&
-              !other->mCacheSuspended &&
+              !other->mClient->IsSuspended() &&
               other->mChannelOffset/BLOCK_SIZE == desiredOffset/BLOCK_SIZE) {
             // This block is already going to be read by the other stream.
             // So don't try to read it from this stream as well.
             enableReading = PR_FALSE;
+            LOG(PR_LOG_DEBUG, ("Stream %p waiting on same block (%lld) from stream %p",
+                               stream, desiredOffset/BLOCK_SIZE, other));
             break;
           }
         }
       }
 
       if (stream->mChannelOffset != desiredOffset && enableReading) {
         // We need to seek now.
         NS_ASSERTION(stream->mIsSeekable || desiredOffset == 0,
@@ -1446,16 +1448,19 @@ void
 nsMediaCache::OpenStream(nsMediaCacheStream* aStream)
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   nsAutoMonitor mon(mMonitor);
   LOG(PR_LOG_DEBUG, ("Stream %p opened", aStream));
   mStreams.AppendElement(aStream);
   aStream->mResourceID = mNextResourceID++;
+
+  // Queue an update since a new stream has been opened.
+  gMediaCache->QueueUpdate();
 }
 
 void
 nsMediaCache::ReleaseStream(nsMediaCacheStream* aStream)
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   nsAutoMonitor mon(mMonitor);
--- a/content/media/nsMediaCache.h
+++ b/content/media/nsMediaCache.h
@@ -205,17 +205,17 @@ class nsMediaChannelStream;
  * methods of this class can assume gMediaCache is non-null.
  * 
  * This class can be directly embedded as a value.
  */
 class nsMediaCacheStream {
 public:
   enum {
     // This needs to be a power of two
-    BLOCK_SIZE = 4096
+    BLOCK_SIZE = 32768
   };
   enum ReadMode {
     MODE_METADATA,
     MODE_PLAYBACK
   };
 
   // aClient provides the underlying transport that cache will use to read
   // data for this stream.
--- a/content/media/nsMediaStream.cpp
+++ b/content/media/nsMediaStream.cpp
@@ -799,16 +799,23 @@ nsMediaChannelStream::IsDataCachedToEndO
 
 PRBool
 nsMediaChannelStream::IsSuspendedByCache()
 {
   nsAutoLock lock(mLock);
   return mCacheSuspendCount > 0;
 }
 
+PRBool
+nsMediaChannelStream::IsSuspended()
+{
+  nsAutoLock lock(mLock);
+  return mSuspendCount > 0;
+}
+
 void
 nsMediaChannelStream::SetReadMode(nsMediaCacheStream::ReadMode aMode)
 {
   mCacheStream.SetReadMode(aMode);
 }
 
 void
 nsMediaChannelStream::SetPlaybackRate(PRUint32 aBytesPerSecond)
@@ -886,16 +893,17 @@ public:
   virtual PRInt64 GetLength() { return mSize; }
   virtual PRInt64 GetNextCachedData(PRInt64 aOffset)
   {
     return (aOffset < mSize) ? aOffset : -1;
   }
   virtual PRInt64 GetCachedDataEnd(PRInt64 aOffset) { return PR_MAX(aOffset, mSize); }
   virtual PRBool  IsDataCachedToEndOfStream(PRInt64 aOffset) { return PR_TRUE; }
   virtual PRBool  IsSuspendedByCache() { return PR_FALSE; }
+  virtual PRBool  IsSuspended() { return PR_FALSE; }
 
 private:
   // The file size, or -1 if not known. Immutable after Open().
   PRInt64 mSize;
 
   // This lock handles synchronisation between calls to Close() and
   // the Read, Seek, etc calls. Close must not be called while a
   // Read or Seek is in progress since it resets various internal
--- a/content/media/nsMediaStream.h
+++ b/content/media/nsMediaStream.h
@@ -246,16 +246,18 @@ public:
   // is in cache. If the end of the stream is not known, we return false.
   virtual PRBool 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.
   virtual PRBool IsSuspendedByCache() = 0;
+  // Returns true if this stream has been suspended.
+  virtual PRBool 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,
                                  PRInt64 aOffset,
                                  PRUint32 aCount) = 0;
@@ -361,16 +363,17 @@ public:
   virtual void    Pin();
   virtual void    Unpin();
   virtual double  GetDownloadRate(PRPackedBool* aIsReliable);
   virtual PRInt64 GetLength();
   virtual PRInt64 GetNextCachedData(PRInt64 aOffset);
   virtual PRInt64 GetCachedDataEnd(PRInt64 aOffset);
   virtual PRBool  IsDataCachedToEndOfStream(PRInt64 aOffset);
   virtual PRBool  IsSuspendedByCache();
+  virtual PRBool  IsSuspended();
 
   class Listener : public nsIStreamListener,
                    public nsIInterfaceRequestor,
                    public nsIChannelEventSink
   {
   public:
     Listener(nsMediaChannelStream* aStream) : mStream(aStream) {}