зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1540573 - P6. Use frugal preloading of media data when on cellular, otherwise aggressive. r=jya
We're allowed to take some liberties as to what the default value and behaviour we assume for the 'preload' attribute on HTMLMediaElement by the spec. On desktop we assumed preload="metadata", while on mobile we assumed the default of preload="none" to save data. On mobile we also assumed that preload="auto" meant preload="metadata". I think it makes sense to instead of always assuming that data on Android is always expensive, we can instead detect if we're running on a cellular connection, and preload frugally then, otherwise aggressively. Differential Revision: https://phabricator.services.mozilla.com/D26235 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c957fbd2ef
Коммит
a3f9372fa2
|
@ -2455,6 +2455,27 @@ bool HTMLMediaElement::AllowedToPlay() const {
|
||||||
return AutoplayPolicy::IsAllowedToPlay(*this);
|
return AutoplayPolicy::IsAllowedToPlay(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t HTMLMediaElement::GetPreloadDefault() const {
|
||||||
|
if (mMediaSource) {
|
||||||
|
return HTMLMediaElement::PRELOAD_ATTR_METADATA;
|
||||||
|
}
|
||||||
|
if (OnCellularConnection()) {
|
||||||
|
return Preferences::GetInt("media.preload.default.cellular",
|
||||||
|
HTMLMediaElement::PRELOAD_ATTR_NONE);
|
||||||
|
}
|
||||||
|
return Preferences::GetInt("media.preload.default",
|
||||||
|
HTMLMediaElement::PRELOAD_ATTR_METADATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t HTMLMediaElement::GetPreloadDefaultAuto() const {
|
||||||
|
if (OnCellularConnection()) {
|
||||||
|
return Preferences::GetInt("media.preload.auto.cellular",
|
||||||
|
HTMLMediaElement::PRELOAD_ATTR_METADATA);
|
||||||
|
}
|
||||||
|
return Preferences::GetInt("media.preload.auto",
|
||||||
|
HTMLMediaElement::PRELOAD_ENOUGH);
|
||||||
|
}
|
||||||
|
|
||||||
void HTMLMediaElement::UpdatePreloadAction() {
|
void HTMLMediaElement::UpdatePreloadAction() {
|
||||||
PreloadAction nextAction = PRELOAD_UNDEFINED;
|
PreloadAction nextAction = PRELOAD_UNDEFINED;
|
||||||
// If autoplay is set, or we're playing, we should always preload data,
|
// If autoplay is set, or we're playing, we should always preload data,
|
||||||
|
@ -2469,13 +2490,8 @@ void HTMLMediaElement::UpdatePreloadAction() {
|
||||||
mAttrs.GetAttr(nsGkAtoms::preload, kNameSpaceID_None);
|
mAttrs.GetAttr(nsGkAtoms::preload, kNameSpaceID_None);
|
||||||
// MSE doesn't work if preload is none, so it ignores the pref when src is
|
// MSE doesn't work if preload is none, so it ignores the pref when src is
|
||||||
// from MSE.
|
// from MSE.
|
||||||
uint32_t preloadDefault =
|
uint32_t preloadDefault = GetPreloadDefault();
|
||||||
mMediaSource
|
uint32_t preloadAuto = GetPreloadDefaultAuto();
|
||||||
? HTMLMediaElement::PRELOAD_ATTR_METADATA
|
|
||||||
: Preferences::GetInt("media.preload.default",
|
|
||||||
HTMLMediaElement::PRELOAD_ATTR_METADATA);
|
|
||||||
uint32_t preloadAuto = Preferences::GetInt(
|
|
||||||
"media.preload.auto", HTMLMediaElement::PRELOAD_ENOUGH);
|
|
||||||
if (!val) {
|
if (!val) {
|
||||||
// Attribute is not set. Use the preload action specified by the
|
// Attribute is not set. Use the preload action specified by the
|
||||||
// media.preload.default pref, or just preload metadata if not present.
|
// media.preload.default pref, or just preload metadata if not present.
|
||||||
|
|
|
@ -1737,6 +1737,9 @@ class HTMLMediaElement : public nsGenericHTMLElement,
|
||||||
|
|
||||||
virtual void MaybeBeginCloningVisually(){};
|
virtual void MaybeBeginCloningVisually(){};
|
||||||
|
|
||||||
|
uint32_t GetPreloadDefault() const;
|
||||||
|
uint32_t GetPreloadDefaultAuto() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is called by AfterSetAttr and OnAttrSetButNotChanged.
|
* This function is called by AfterSetAttr and OnAttrSetButNotChanged.
|
||||||
* It will not be called if the value is being unset.
|
* It will not be called if the value is being unset.
|
||||||
|
|
|
@ -550,9 +550,6 @@ pref("browser.chrome.toolbar_tips", false);
|
||||||
// don't allow meta-refresh when backgrounded
|
// don't allow meta-refresh when backgrounded
|
||||||
pref("browser.meta_refresh_when_inactive.disabled", true);
|
pref("browser.meta_refresh_when_inactive.disabled", true);
|
||||||
|
|
||||||
// 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
|
|
||||||
// On mobile we throttle the download once the readahead_limit is hit
|
// On mobile we throttle the download once the readahead_limit is hit
|
||||||
// if we're using a cellular connection, even if the download is slow.
|
// if we're using a cellular connection, even if the download is slow.
|
||||||
// This is to preserve battery and data.
|
// This is to preserve battery and data.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче