Bug 932621 - Make sure the latency does not grow up in ScriptProcessorNode. r=ehsan

This commit is contained in:
Paul Adenot 2013-12-13 18:21:05 +01:00
parent c0ac5df382
commit 3236595731

View File

@ -111,15 +111,24 @@ public:
// interval will be very short. |latency - bufferDuration| will be
// negative, effectively moving back mLatency to a smaller and smaller
// value, until it crosses zero, at which point we stop dropping buffers
// and resume normal operation.
// and resume normal operation. This does not work if at the same time,
// the MSG thread was also slowed down, so if the latency on the MSG
// thread is normal, and we are still dropping buffers, and mLatency is
// still more than twice the duration of a buffer, we reset it and stop
// dropping buffers.
float latency = (now - mLastEventTime).ToSeconds();
float bufferDuration = aBufferSize / mSampleRate;
mLatency += latency - bufferDuration;
mLastEventTime = now;
if (mLatency > MAX_LATENCY_S || (mDroppingBuffers && mLatency > 0.0)) {
if (mLatency > MAX_LATENCY_S ||
(mDroppingBuffers && mLatency > 0.0 &&
abs(latency - bufferDuration) < bufferDuration)) {
mDroppingBuffers = true;
return;
} else {
if (mDroppingBuffers) {
mLatency = 0;
}
mDroppingBuffers = false;
}
}