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

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

Issue 216523003: Tighten up webrtc audio tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further tweaks to combat flakes on Android. Created 6 years, 9 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 | « content/test/data/media/peerconnection-call.html ('k') | media/video/capture/fake_video_capture_device.cc » ('j') | 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 40668c6d38180c9e3b96f1de13d26f8a5ae6a41c..52c7d3897daf7e508c6545315e0263069ce72417 100644
--- a/content/test/data/media/webrtc_test_audio.js
+++ b/content/test/data/media/webrtc_test_audio.js
@@ -4,6 +4,9 @@
// Audio test utilities.
+// GetStats reports audio output energy in the [0, 32768] range.
+var MAX_AUDIO_OUTPUT_ENERGY = 32768;
+
// 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,
@@ -22,28 +25,29 @@ function gatherAudioLevelSamples(peerConnection, numSamples, frequency,
}, 1000 / frequency);
}
-// Tries to identify the beep-every-second signal generated by the fake audio
-// media/audio/fake_audio_input_stream.cc. Fails the test if we can't see a
-// signal.
+// Tries to identify the beep-every-half-second signal generated by the fake
+// audio device in media/video/capture/fake_video_capture_device.cc. Fails the
+// test if we can't see a signal. The samples should have been gathered over at
+// least two seconds since we expect to see at least three "peaks" in there
+// (we should see either 3 or 4 depending on how things line up).
function verifyAudioIsPlaying(samples) {
- var average = 0;
- for (var i = 0; i < samples.length; ++i)
- average += samples[i] / samples.length;
+ var numPeaks = 0;
+ var threshold = MAX_AUDIO_OUTPUT_ENERGY * 0.7;
+ var currentlyOverThreshold = false;
- var largest = 0;
- for (var i = 0; i < samples.length; ++i)
- largest = Math.max(largest, samples[i]);
+ // 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.
+ for (var i = 0; i < samples.length; ++i) {
+ if (currentlyOverThreshold && samples[i] < threshold)
+ numPeaks++;
+ currentlyOverThreshold = samples[i] >= threshold;
+ }
- console.log('Average audio level: ' + average + ', largest: ' + largest);
+ console.log('Number of peaks identified: ' + numPeaks);
- // TODO(phoglund): Make a more sophisticated curve-fitting algorithm. We want
- // to see a number of peaks with relative silence between them. The following
- // seems to work fine on a nexus 7.
- if (average < 3000 || average > 8000)
- failTest('Unexpected avg audio level: got ' + average + ', expected it ' +
- 'to be 4000 < avg < 8000.');
- if (largest < 25000)
- failTest('Too low max audio level: got ' + largest + ', expected > 30000.');
+ if (numPeaks < 2)
+ failTest('Expected to see at least two peaks in audio signal, got ' +
+ numPeaks + '. Dumping samples for analysis: "' + samples + '"');
}
// If silent (like when muted), we should get very near zero audio level.
« no previous file with comments | « content/test/data/media/peerconnection-call.html ('k') | media/video/capture/fake_video_capture_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698