зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1181073
- Relax setTimeout throttling for background tabs using web audio, r=bkelly
This commit is contained in:
Родитель
5cb6cd1b79
Коммит
b0efb7ddb3
|
@ -307,6 +307,16 @@ static int32_t gMinBackgroundTimeoutValue;
|
|||
inline int32_t
|
||||
nsGlobalWindow::DOMMinTimeoutValue() const {
|
||||
bool isBackground = !mOuterWindow || mOuterWindow->IsBackground();
|
||||
if (isBackground) {
|
||||
// Don't use the background timeout value when there are audio contexts with
|
||||
// active nodes, so that background audio can keep running smoothly.
|
||||
for (const AudioContext* ctx : mAudioContexts) {
|
||||
if (ctx->ActiveNodeCount() > 0) {
|
||||
isBackground = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
std::max(isBackground ? gMinBackgroundTimeoutValue : gMinTimeoutValue, 0);
|
||||
}
|
||||
|
|
|
@ -696,6 +696,12 @@ AudioContext::MaxChannelCount() const
|
|||
return mIsOffline ? mNumberOfChannels : CubebUtils::MaxNumberOfChannels();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
AudioContext::ActiveNodeCount() const
|
||||
{
|
||||
return mActiveNodes.Count();
|
||||
}
|
||||
|
||||
MediaStreamGraph*
|
||||
AudioContext::Graph() const
|
||||
{
|
||||
|
|
|
@ -300,6 +300,8 @@ public:
|
|||
|
||||
uint32_t MaxChannelCount() const;
|
||||
|
||||
uint32_t ActiveNodeCount() const;
|
||||
|
||||
void Mute() const;
|
||||
void Unmute() const;
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@ MOCHITEST_MANIFESTS += [
|
|||
'test/mochitest.ini',
|
||||
]
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += [
|
||||
'test/browser.ini',
|
||||
]
|
||||
|
||||
TEST_HARNESS_FILES.testing.mochitest.tests.dom.media.webaudio.test.blink += [
|
||||
'test/blink/audio-testing.js',
|
||||
'test/blink/convolution-testing.js',
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
[browser_bug1181073.js]
|
|
@ -0,0 +1,65 @@
|
|||
add_task(function*() {
|
||||
// Make the min_background_timeout_value very high to avoid problems on slow machines
|
||||
yield new Promise(resolve => SpecialPowers.pushPrefEnv({
|
||||
'set': [['dom.min_background_timeout_value', 3000]]
|
||||
}, resolve));
|
||||
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "https://example.com");
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
// Make the tab a background tab, so that setInterval will be throttled.
|
||||
yield BrowserTestUtils.openNewForegroundTab(gBrowser);
|
||||
|
||||
let time = yield ContentTask.spawn(browser, null, function () {
|
||||
return new Promise(resolve => {
|
||||
let start = content.performance.now();
|
||||
let id = content.window.setInterval(function() {
|
||||
let end = content.performance.now();
|
||||
content.window.clearInterval(id);
|
||||
resolve(end - start);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
ok(time > 2000, "Interval is throttled with no webaudio (" + time + " ms)");
|
||||
|
||||
time = yield ContentTask.spawn(browser, null, function () {
|
||||
return new Promise(resolve => {
|
||||
// Start playing audio, save it on the window so it doesn't get GCed
|
||||
let audioCtx = content.window.audioCtx = new content.window.AudioContext();
|
||||
let oscillator = audioCtx.createOscillator();
|
||||
oscillator.type = 'square';
|
||||
oscillator.frequency.value = 3000;
|
||||
oscillator.start();
|
||||
|
||||
let start = content.performance.now();
|
||||
let id = content.window.setInterval(function() {
|
||||
let end = content.performance.now();
|
||||
content.window.clearInterval(id);
|
||||
oscillator.stop();
|
||||
resolve(end - start);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
ok(time < 1000, "Interval is not throttled with audio playing (" + time + " ms)");
|
||||
|
||||
// Destroy the oscillator, but not the audio context
|
||||
yield new Promise(resolve => SpecialPowers.exactGC(browser.contentWindow, resolve));
|
||||
|
||||
time = yield ContentTask.spawn(browser, null, function () {
|
||||
return new Promise(resolve => {
|
||||
let start = content.performance.now();
|
||||
let id = content.window.setInterval(function() {
|
||||
let end = content.performance.now();
|
||||
content.window.clearInterval(id);
|
||||
resolve(end - start);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
ok(time > 2000, "Interval is throttled with audio stopped (" + time + " ms)");
|
||||
|
||||
while (gBrowser.tabs.length > 1)
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
Загрузка…
Ссылка в новой задаче