Bug 1399751. P2 - pass a block index to FindBlockForIncomingData() so it doesn't depend on mChannelOffset. r=gerald
authorJW Wang <jwwang@mozilla.com>
Thu, 14 Sep 2017 10:42:54 +0800
changeset 433031 f85b473c49649a55da330e9bffefa90ca0344923
parent 433030 22dbe1bf55a0c34901cc837dccc44d6153f7f713
child 433032 9f86654073e285d5af2a7250873c7701b53ce22c
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1399751
milestone57.0a1
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 1399751. P2 - pass a block index to FindBlockForIncomingData() so it doesn't depend on mChannelOffset. r=gerald MozReview-Commit-ID: 7VltaDyxndl
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -299,17 +299,19 @@ protected:
     NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
 
     MOZ_COUNT_DTOR(MediaCache);
   }
 
   // Find a free or reusable block and return its index. If there are no
   // free blocks and no reusable blocks, add a new block to the cache
   // and return it. Can return -1 on OOM.
-  int32_t FindBlockForIncomingData(TimeStamp aNow, MediaCacheStream* aStream);
+  int32_t FindBlockForIncomingData(TimeStamp aNow,
+                                   MediaCacheStream* aStream,
+                                   int32_t aStreamBlockIndex);
   // Find a reusable block --- a free block, if there is one, otherwise
   // the reusable block with the latest predicted-next-use, or -1 if
   // there aren't any freeable blocks. Only block indices less than
   // aMaxSearchBlockIndex are considered. If aForStream is non-null,
   // then aForStream and aForStreamBlock indicate what media data will
   // be placed; FindReusableBlock will favour returning free blocks
   // near other blocks for that point in the stream.
   int32_t FindReusableBlock(TimeStamp aNow,
@@ -774,25 +776,23 @@ OffsetInBlock(int64_t aOffset)
   // Still check for allowed range in debug builds, to catch out-of-range
   // issues early during development.
   MOZ_ASSERT(IsOffsetAllowed(aOffset));
   return int32_t(aOffset % MediaCache::BLOCK_SIZE);
 }
 
 int32_t
 MediaCache::FindBlockForIncomingData(TimeStamp aNow,
-                                       MediaCacheStream* aStream)
+                                     MediaCacheStream* aStream,
+                                     int32_t aStreamBlockIndex)
 {
   mReentrantMonitor.AssertCurrentThreadIn();
 
   int32_t blockIndex =
-    FindReusableBlock(aNow,
-                      aStream,
-                      OffsetToBlockIndexUnchecked(aStream->mChannelOffset),
-                      INT32_MAX);
+    FindReusableBlock(aNow, aStream, aStreamBlockIndex, INT32_MAX);
 
   if (blockIndex < 0 || !IsBlockFree(blockIndex)) {
     // The block returned is already allocated.
     // Don't reuse it if a) there's room to expand the cache or
     // b) the data we're going to store in the free block is not higher
     // priority than the data already stored in the free block.
     // The latter can lead us to go over the cache limit a bit.
     if ((mIndex.Length() < uint32_t(mBlockCache->GetMaxBlocks()) ||
@@ -1603,17 +1603,18 @@ MediaCache::AllocateAndWriteBlock(MediaC
           aStreamBlockIndex * BLOCK_SIZE);
       RemoveBlockOwner(globalBlockIndex, stream);
     }
   }
 
   // Extend the mBlocks array as necessary
 
   TimeStamp now = TimeStamp::Now();
-  int32_t blockIndex = FindBlockForIncomingData(now, aStream);
+  int32_t blockIndex =
+    FindBlockForIncomingData(now, aStream, aStreamBlockIndex);
   if (blockIndex >= 0) {
     FreeBlock(blockIndex);
 
     Block* block = &mIndex[blockIndex];
     LOG("Allocated block %d to stream %p block %d(%" PRId64 ")",
         blockIndex,
         aStream,
         aStreamBlockIndex,