Bug 1399751. P2 - pass a block index to FindBlockForIncomingData() so it doesn't depend on mChannelOffset.
MozReview-Commit-ID: 7VltaDyxndl
--- 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,