Bug 1142688 - Wait for actual audio data on remote side before checking audio sanity. r=jesup,padenot

This commit is contained in:
Andreas Pehrson 2015-03-16 16:32:19 +08:00
parent 705badf085
commit ba688bded0

View File

@ -17,12 +17,24 @@ createHTML({
// output side. We then sanity check the audio by comparing the frequency domain
// data from both analysers.
/*
* Use as callback to Array.reduce to get an object { value, index }
* that contains the largest element in the array.
*/
var maxWithIndex = function(a, b, i) {
if (b >= a.value) {
return { value: b, index: i };
} else {
return a;
}
};
runNetworkTest(function() {
var test = new PeerConnectionTest();
var audioContext = new AudioContext();
var inputAnalyser;
var outputAnalyser;
var inputAnalyser, outputAnalyser;
var inputData, outputData;
test.setMediaConstraints([{audio: true}], []);
test.chain.replace("PC_LOCAL_GUM", [
@ -56,45 +68,38 @@ runNetworkTest(function() {
return Promise.resolve();
}]);
test.chain.append([
function WAIT_FOR_CLEAN_AUDIO(test) {
function GET_INPUT_DATA(test) {
inputData = new Uint8Array(inputAnalyser.frequencyBinCount);
inputAnalyser.getByteFrequencyData(inputData);
return Promise.resolve();
},
function GET_OUTPUT_DATA(test) {
// We've seen completely silent output with e10s, suggesting that the
// machine is overloaded. Here we wait for the media element on the
// output side to progress a bit after all previous steps finish to
// ensure we have healthy data to check.
var wait = function(elem, startTime, resolve) {
elem.ontimeupdate = function(ev) {
info("Waiting... current: " + elem.currentTime + ", start: " + startTime);
if (elem.currentTime - startTime < 0.5) {
// machine is overloaded. Here we wait for actual audio data on the
// output side before we proceed.
return new Promise(resolve => {
is(test.pcRemote.mediaCheckers.length, 1, "One media element on remote side");
var elem = test.pcRemote.mediaCheckers[0].element;
var data = new Uint8Array(outputAnalyser.frequencyBinCount);
elem.ontimeupdate = ev => {
outputAnalyser.getByteFrequencyData(data);
if (data.reduce(maxWithIndex, { value: -1, index: -1 }).value === 0) {
info("Waiting for output data... time: " + elem.currentTime);
return;
}
elem.ontimeupdate = null;
outputData = data;
resolve();
}
};
return Promise.all(test.pcRemote.mediaCheckers.map(function(checker) {
var elem = checker.element;
var startTime = elem.currentTime;
return new Promise((y, n) => wait(elem, startTime, y));
}));
};
});
},
function CHECK_AUDIO_FLOW(test) {
// This is for sanity check only. We'll deem that the streams are working
// if the global maxima in the frequency domain for both the input and
// the output are within 10 (out of 1024) steps of each other.
var inputData = new Uint8Array(inputAnalyser.frequencyBinCount);
inputAnalyser.getByteFrequencyData(inputData);
var outputData = new Uint8Array(outputAnalyser.frequencyBinCount);
outputAnalyser.getByteFrequencyData(outputData);
is(inputData.length, outputData.length, "Equally sized datasets");
var maxWithIndex = function(a, b, i) {
if (b >= a.value) {
return { value: b, index: i };
} else {
return a;
}
};
var initialValue = { value: -1, index: -1 };
var inputMax = inputData.reduce(maxWithIndex, initialValue);
var outputMax = outputData.reduce(maxWithIndex, initialValue);