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 b9785bf5fbe88b670d96ecd3a73c2ef3200b1270..81fdec3ee530f7b241bf13ed8023fa1abff16887 100644 |
--- a/content/test/data/media/webrtc_test_audio.js |
+++ b/content/test/data/media/webrtc_test_audio.js |
@@ -7,6 +7,33 @@ |
// GetStats reports audio output energy in the [0, 32768] range. |
var MAX_AUDIO_OUTPUT_ENERGY = 32768; |
+// Queries WebRTC stats on |peerConnection| to find out whether audio is playing |
+// on the connection. Note this does not necessarily mean the audio is actually |
+// playing out (for instance if there's a bug in the WebRTC web media player). |
+// If |beLenient| is true, we assume we're on a slow and unreliable bot and that |
+// we should do a minimum of checking. |
+function ensureAudioPlaying(peerConnection, beLenient) { |
+ addExpectedEvent(); |
+ |
+ // Gather 50 samples per second for 2 seconds. |
+ gatherAudioLevelSamples(peerConnection, 100, 50, function(samples) { |
+ identifyFakeDeviceSignal_(samples, beLenient); |
+ eventOccured(); |
+ }); |
+} |
+ |
+// Queries WebRTC stats on |peerConnection| to find out whether audio is muted |
+// on the connection. |
+function ensureSilence(peerConnection) { |
+ addExpectedEvent(); |
+ setTimeout(function() { |
+ gatherAudioLevelSamples(peerConnection, 100, 50, function(samples) { |
+ identifySilence_(samples); |
+ eventOccured(); |
+ }); |
+ }, 500); |
+} |
+ |
// 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, |
@@ -34,15 +61,19 @@ function gatherAudioLevelSamples(peerConnection, numSamples, frequency, |
}, 1000 / frequency); |
} |
-// 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). |
-// |
-// If |beLenient| is specified, we assume we're running on a slow device or |
-// or under TSAN, and relax the checks quite a bit. |
-function verifyAudioIsPlaying(samples, beLenient) { |
+/** |
+* 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). |
+* |
+* If |beLenient| is specified, we assume we're running on a slow device or |
+* or under TSAN, and relax the checks quite a bit. |
+* |
+* @private |
+*/ |
+function identifyFakeDeviceSignal_(samples, beLenient) { |
var numPeaks = 0; |
var threshold = MAX_AUDIO_OUTPUT_ENERGY * 0.7; |
if (beLenient) |
@@ -69,12 +100,15 @@ function verifyAudioIsPlaying(samples, beLenient) { |
samples + '"'); |
} |
-// If silent (like when muted), we should get very near zero audio level. |
-function verifyIsSilent(samples) { |
+/** |
+ * @private |
+ */ |
+function identifySilence_(samples) { |
var average = 0; |
for (var i = 0; i < samples.length; ++i) |
average += samples[i] / samples.length; |
+ // If silent (like when muted), we should get very near zero audio level. |
console.log('Average audio level: ' + average); |
if (average > 500) |
failTest('Expected silence, but avg audio level was ' + average); |