Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(832)

Unified Diff: content/test/data/media/webrtc_test_audio.js

Issue 1132483003: Rewriting WebRTC output level tests to be more reliable under load. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/data/media/webrtc_test_audio.js
diff --git a/content/test/data/media/webrtc_test_audio.js b/content/test/data/media/webrtc_test_audio.js
index 1e69211d961dd1c7c69e5ab6fe5a3fc6e189eae1..836862d069f1deedf9d1744f26e1eff94dec7505 100644
--- a/content/test/data/media/webrtc_test_audio.js
+++ b/content/test/data/media/webrtc_test_audio.js
@@ -15,8 +15,7 @@ var MAX_AUDIO_OUTPUT_ENERGY = 32768;
function ensureAudioPlaying(peerConnection, beLenient) {
addExpectedEvent();
- // Gather 50 samples per second for 2 seconds.
- gatherAudioLevelSamples(peerConnection, 100, 50, function(samples) {
+ gatherAudioLevelSamples(peerConnection, 3 * 1000, function(samples) {
identifyFakeDeviceSignal_(samples, beLenient);
eventOccured();
});
@@ -27,7 +26,7 @@ function ensureAudioPlaying(peerConnection, beLenient) {
function ensureSilence(peerConnection) {
addExpectedEvent();
setTimeout(function() {
- gatherAudioLevelSamples(peerConnection, 100, 50, function(samples) {
+ gatherAudioLevelSamples(peerConnection, 1 * 1000, function(samples) {
identifySilence_(samples);
eventOccured();
});
@@ -48,32 +47,38 @@ function workAroundSeveralReportsIssue(audioOutputLevels) {
return Math.max(audioOutputLevels[0], audioOutputLevels[1]);
}
-// Gathers |numSamples| samples at |frequency| number of times per second and
-// calls back |callback| with an array with numbers in the [0, 32768] range.
-function gatherAudioLevelSamples(peerConnection, numSamples, frequency,
- callback) {
- console.log('Gathering ' + numSamples + ' audio samples...');
+// Gathers samples from WebRTC stats as fast as possible for |durationMs|
+// milliseconds and calls back |callback| with an array with numbers in the
+// [0, 32768] range. There are no guarantees for how often we will be able to
+// collect values, but this function deliberately avoids setTimeout calls in
+// order be as insensitive as possible to starvation (particularly when this
+// code runs in parallel with other tests on a heavily loaded bot).
+function gatherAudioLevelSamples(peerConnection, durationMs, callback) {
+ console.log('Gathering audio samples for ' + durationMs + ' milliseconds...');
var audioLevelSamples = []
// If this times out and never found any audio output levels, the call
// probably doesn't have an audio stream.
- var gatherSamples = setInterval(function() {
- peerConnection.getStats(function(response) {
- audioOutputLevels = getAudioLevelFromStats_(response);
- if (audioOutputLevels.length == 0) {
- // The call probably isn't up yet.
- return;
- }
- var outputLevel = workAroundSeveralReportsIssue(audioOutputLevels);
- audioLevelSamples.push(outputLevel);
-
- if (audioLevelSamples.length == numSamples) {
- console.log('Gathered all samples.');
- clearInterval(gatherSamples);
- callback(audioLevelSamples);
- }
- });
- }, 1000 / frequency);
+ var startTime = new Date();
+ var gotStats = function(response) {
+ audioOutputLevels = getAudioLevelFromStats_(response);
+ if (audioOutputLevels.length == 0) {
+ // The call probably isn't up yet.
+ peerConnection.getStats(gotStats);
+ return;
+ }
+ var outputLevel = workAroundSeveralReportsIssue(audioOutputLevels);
+ audioLevelSamples.push(outputLevel);
+
+ var elapsed = new Date() - startTime;
+ if (elapsed > durationMs) {
+ console.log('Gathered all samples.');
+ callback(audioLevelSamples);
+ return;
+ }
+ peerConnection.getStats(gotStats);
+ }
+ peerConnection.getStats(gotStats);
}
/**
@@ -96,7 +101,7 @@ function identifyFakeDeviceSignal_(samples, beLenient) {
var currentlyOverThreshold = false;
// Detect when we have been been over the threshold and is going back again
- // (i.e. count peaks). We should see about one peak per second.
+ // (i.e. count peaks). We should see about two peaks per second.
for (var i = 0; i < samples.length; ++i) {
if (currentlyOverThreshold && samples[i] < threshold)
numPeaks++;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698