Bug 1419668 - set mMaxBlocks according to MediaPrefs::MediaMemoryCacheMaxSize().
Since MemoryBlockCache is used only when the content length is smaller than
MediaPrefs::MediaMemoryCacheMaxSize() * 1024, we should set mMaxBlocks according
to the pref value to prevent blocks from being evicted unexpectedly.
MozReview-Commit-ID: BaI0A0VUbkv
--- a/dom/media/MemoryBlockCache.cpp
+++ b/dom/media/MemoryBlockCache.cpp
@@ -134,20 +134,22 @@ enum MemoryBlockCacheTelemetryErrors
MoveBlockSourceOverrun = 5,
MoveBlockDestOverflow = 6,
MoveBlockCannotGrow = 7,
};
static int32_t
CalculateMaxBlocks(int64_t aContentLength)
{
+ int64_t maxSize = int64_t(MediaPrefs::MediaMemoryCacheMaxSize()) * 1024;
+ MOZ_ASSERT(aContentLength <= maxSize);
+ MOZ_ASSERT(maxSize % MediaBlockCacheBase::BLOCK_SIZE == 0);
// Note: It doesn't matter if calculations overflow, Init() would later fail.
// We want at least enough blocks to contain the original content length.
- const int32_t requiredBlocks =
- int32_t((aContentLength - 1) / MediaBlockCacheBase::BLOCK_SIZE + 1);
+ const int32_t requiredBlocks = maxSize / MediaBlockCacheBase::BLOCK_SIZE;
// Allow at least 1s of ultra HD (25Mbps).
const int32_t workableBlocks =
25 * 1024 * 1024 / 8 / MediaBlockCacheBase::BLOCK_SIZE;
return std::max(requiredBlocks, workableBlocks);
}
MemoryBlockCache::MemoryBlockCache(int64_t aContentLength)
// Buffer whole blocks.