Skip to content

Commit

Permalink
Bug 1085186. Don't readahead more than 30s of media data per resource…
Browse files Browse the repository at this point in the history
… on mobile/B2G. r=cpearce
  • Loading branch information
rocallahan committed Oct 20, 2014
1 parent 0a2bfbc commit 214e874
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 5 additions & 0 deletions b2g/app/b2g.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ pref("dom.indexedDB.warningQuota", 5);
pref("media.preload.default", 1); // default to preload none
pref("media.preload.auto", 2); // preload metadata if preload=auto
pref("media.cache_size", 4096); // 4MB media cache
// Try to save battery by not resuming reading from a connection until we fall
// below 10s of buffered data.
pref("media.cache_resume_threshold", 10);
pref("media.cache_readahead_limit", 30);

#ifdef MOZ_FMP4
// Enable/Disable Gonk Decoder Module
pref("media.fragmented-mp4.gonk.enabled", false);
Expand Down
13 changes: 8 additions & 5 deletions dom/media/MediaCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ static const uint32_t REPLAY_PENALTY_FACTOR = 3;
// can.
static const uint32_t FREE_BLOCK_SCAN_LIMIT = 16;

// Try to save power by not resuming paused reads if the stream won't need new
// data within this time interval in the future
static const uint32_t CACHE_POWERSAVE_WAKEUP_LOW_THRESHOLD_MS = 10000;

#ifdef DEBUG
// Turn this on to do very expensive cache state validation
// #define DEBUG_VERIFY_CACHE
Expand Down Expand Up @@ -1164,6 +1160,9 @@ MediaCache::Update()
}
}

int32_t resumeThreshold = Preferences::GetInt("media.cache_resume_threshold", 10);
int32_t readaheadLimit = Preferences::GetInt("media.cache_readahead_limit", 30);

for (uint32_t i = 0; i < mStreams.Length(); ++i) {
actions.AppendElement(NONE);

Expand Down Expand Up @@ -1245,10 +1244,14 @@ MediaCache::Update()
TimeDuration predictedNewDataUse = PredictNextUseForIncomingData(stream);

if (stream->mCacheSuspended &&
predictedNewDataUse.ToMilliseconds() > CACHE_POWERSAVE_WAKEUP_LOW_THRESHOLD_MS) {
predictedNewDataUse.ToSeconds() > resumeThreshold) {
// Don't need data for a while, so don't bother waking up the stream
CACHE_LOG(PR_LOG_DEBUG, ("Stream %p avoiding wakeup since more data is not needed", stream));
enableReading = false;
} else if (predictedNewDataUse.ToSeconds() > readaheadLimit) {
// Don't read ahead more than this much
CACHE_LOG(PR_LOG_DEBUG, ("Stream %p throttling to avoid reading ahead too far", stream));
enableReading = false;
} else if (freeBlockCount > 0) {
// Free blocks in the cache, so keep reading
CACHE_LOG(PR_LOG_DEBUG, ("Stream %p reading since there are free blocks", stream));
Expand Down
5 changes: 5 additions & 0 deletions mobile/android/app/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ pref("dom.indexedDB.warningQuota", 5);
// prevent video elements from preloading too much data
pref("media.preload.default", 1); // default to preload none
pref("media.preload.auto", 2); // preload metadata if preload=auto
pref("media.cache_size", 32768); // 32MB media cache
// Try to save battery by not resuming reading from a connection until we fall
// below 10s of buffered data.
pref("media.cache_resume_threshold", 10);
pref("media.cache_readahead_limit", 30);

// Number of video frames we buffer while decoding video.
// On Android this is decided by a similar value which varies for
Expand Down
7 changes: 7 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ pref("print.shrink-to-fit.scale-limit-percent", 20);

// Media cache size in kilobytes
pref("media.cache_size", 512000);
// When a network connection is suspended, don't resume it until the
// amount of buffered data falls below this threshold (in seconds).
pref("media.cache_resume_threshold", 999999);
// Stop reading ahead when our buffered data is this many seconds ahead
// of the current playback position. This limit can stop us from using arbitrary
// amounts of network bandwidth prefetching huge videos.
pref("media.cache_readahead_limit", 999999);

// Master HTML5 media volume scale.
pref("media.volume_scale", "1.0");
Expand Down

0 comments on commit 214e874

Please sign in to comment.