Bug 1258673. Part 2 - since mStreamOffset is not updated until the end of MediaCacheStream::Read(), we have to pass stream offset to MediaCache::NoteBlockUsage explicitly to avoid hitting the assertion. r=jya. a=ritu
authorJW Wang <jwwang@mozilla.com>
Thu, 24 Mar 2016 14:59:33 +0800
changeset 323688 4852e88b04f3ff5ea79adf95a49000f819fd7d4e
parent 323687 1fbeb5120d66c87a748eb835d088b5d54b4fe9b1
child 323689 9cf1d97ed35bf8494c47dc03b05dc9ef67e4fd68
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, ritu
bugs1258673
milestone47.0a2
Bug 1258673. Part 2 - since mStreamOffset is not updated until the end of MediaCacheStream::Read(), we have to pass stream offset to MediaCache::NoteBlockUsage explicitly to avoid hitting the assertion. r=jya. a=ritu MozReview-Commit-ID: 3LRM9PTIuaP
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -176,16 +176,17 @@ public:
   void NoteSeek(MediaCacheStream* aStream, int64_t aOldOffset);
   // Notify the cache that a block has been read from. This is used
   // to update last-use times. The block may not actually have a
   // cache entry yet since Read can read data from a stream's
   // in-memory mPartialBlockBuffer while the block is only partly full,
   // and thus hasn't yet been committed to the cache. The caller will
   // call QueueUpdate().
   void NoteBlockUsage(MediaCacheStream* aStream, int32_t aBlockIndex,
+                      int64_t aStreamOffset,
                       MediaCacheStream::ReadMode aMode, TimeStamp aNow);
   // Mark aStream as having the block, adding it as an owner.
   void AddBlockOwnerAsReadahead(int32_t aBlockIndex, MediaCacheStream* aStream,
                                 int32_t aStreamBlockIndex);
 
   // This queues a call to Update() on the main thread.
   void QueueUpdate();
 
@@ -1617,35 +1618,35 @@ MediaCache::Truncate()
     // to have a cross-platform API for doing that. At least when all
     // streams are closed we shut down the cache, which erases the
     // file at that point.
   }
 }
 
 void
 MediaCache::NoteBlockUsage(MediaCacheStream* aStream, int32_t aBlockIndex,
-                             MediaCacheStream::ReadMode aMode,
-                             TimeStamp aNow)
+                           int64_t aStreamOffset,
+                           MediaCacheStream::ReadMode aMode, TimeStamp aNow)
 {
   mReentrantMonitor.AssertCurrentThreadIn();
 
   if (aBlockIndex < 0) {
     // this block is not in the cache yet
     return;
   }
 
   BlockOwner* bo = GetBlockOwner(aBlockIndex, aStream);
   if (!bo) {
     // this block is not in the cache yet
     return;
   }
 
   // The following check has to be <= because the stream offset has
   // not yet been updated for the data read from this block
-  NS_ASSERTION(bo->mStreamBlock*BLOCK_SIZE <= bo->mStream->mStreamOffset,
+  NS_ASSERTION(bo->mStreamBlock*BLOCK_SIZE <= aStreamOffset,
                "Using a block that's behind the read position?");
 
   GetListForBlock(bo)->RemoveBlock(aBlockIndex);
   bo->mClass =
     (aMode == MediaCacheStream::MODE_METADATA || bo->mClass == METADATA_BLOCK)
     ? METADATA_BLOCK : PLAYED_BLOCK;
   // Since this is just being used now, it can definitely be at the front
   // of mMetadataBlocks or mPlayedBlocks
@@ -1668,18 +1669,18 @@ MediaCache::NoteSeek(MediaCacheStream* a
       std::min<int64_t>((aStream->mStreamOffset + BLOCK_SIZE - 1)/BLOCK_SIZE,
              aStream->mBlocks.Length());
     TimeStamp now = TimeStamp::Now();
     while (blockIndex < endIndex) {
       int32_t cacheBlockIndex = aStream->mBlocks[blockIndex];
       if (cacheBlockIndex >= 0) {
         // Marking the block used may not be exactly what we want but
         // it's simple
-        NoteBlockUsage(aStream, cacheBlockIndex, MediaCacheStream::MODE_PLAYBACK,
-                       now);
+        NoteBlockUsage(aStream, cacheBlockIndex, aStream->mStreamOffset,
+                       MediaCacheStream::MODE_PLAYBACK, now);
       }
       ++blockIndex;
     }
   } else {
     // We seeked backward. Convert from played to readahead.
     // Any played block that is entirely after the start of the seeked-over
     // range must be converted.
     int32_t blockIndex =
@@ -2278,17 +2279,17 @@ MediaCacheStream::Read(char* aBuffer, ui
       if (mClosed) {
         // We may have successfully read some data, but let's just throw
         // that out.
         return NS_ERROR_FAILURE;
       }
       continue;
     }
 
-    gMediaCache->NoteBlockUsage(this, cacheBlock, mCurrentMode, TimeStamp::Now());
+    gMediaCache->NoteBlockUsage(this, cacheBlock, streamOffset, mCurrentMode, TimeStamp::Now());
 
     int64_t offset = cacheBlock*BLOCK_SIZE + offsetInStreamBlock;
     int32_t bytes;
     MOZ_ASSERT(size >= 0 && size <= INT32_MAX, "Size out of range.");
     nsresult rv = gMediaCache->ReadCacheFile(offset, aBuffer + count, int32_t(size), &bytes);
     if (NS_FAILED(rv)) {
       if (count == 0)
         return rv;