diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 23:10:19 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 23:10:19 +0000 |
commit | c243e3bfac1f725ba2a8c29ce8924c09ff9c684d (patch) | |
tree | 111567576ac601403612f31f9f46abe658b140a0 | |
parent | 2e3ad4f042dbdb2bdf784d328ea53b190d408bb6 (diff) | |
download | chromium_src-c243e3bfac1f725ba2a8c29ce8924c09ff9c684d.zip chromium_src-c243e3bfac1f725ba2a8c29ce8924c09ff9c684d.tar.gz chromium_src-c243e3bfac1f725ba2a8c29ce8924c09ff9c684d.tar.bz2 |
Revert 238953 "Adding an audio-level WebRTC test to verify mutin..."
> Adding an audio-level WebRTC test to verify muting and playback.
>
> This test uses the stats API to measure the audioOutputLevel. Since the
> content browsertests always uses fake devices we can adapt the test to
> look for that particular signal.
>
> This test is primarily intended to run on Android but will work on
> desktop as well. Tested by running manually on a Nexus 7 device
> at my workstation.
>
> BUG=325164
>
> Review URL: https://codereview.chromium.org/101773002
TBR=phoglund@chromium.org
BUG=326338
Review URL: https://codereview.chromium.org/107443002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239065 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/media/webrtc_browsertest.cc | 41 | ||||
-rw-r--r-- | content/test/data/media/peerconnection-call.html | 60 | ||||
-rw-r--r-- | content/test/data/media/webrtc_test_audio.js | 74 |
3 files changed, 2 insertions, 173 deletions
diff --git a/content/browser/media/webrtc_browsertest.cc b/content/browser/media/webrtc_browsertest.cc index f76a215..e63207d 100644 --- a/content/browser/media/webrtc_browsertest.cc +++ b/content/browser/media/webrtc_browsertest.cc @@ -21,14 +21,6 @@ #include "base/win/windows_version.h" #endif -const char kForceIsac16K[] = -#ifdef OS_ANDROID - // The default audio codec, Opus, doesn't work on Android. - "true"; -#else - "false"; -#endif - namespace { static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; @@ -566,37 +558,4 @@ IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, AddTwoMediaStreamsToOnePC) { ExpectTitle("OK"); } -IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, - EstablishAudioVideoCallAndMeasureOutputLevel) { - ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); - ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( - switches::kUseFakeDeviceForMediaStream)) - << "Must run with fake devices since the test will explicitly look " - << "for the fake device signal."; - - GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html")); - NavigateToURL(shell(), url); - - EXPECT_TRUE(ExecuteJavascript( - base::StringPrintf("callAndEnsureAudioIsPlaying(%s);", kForceIsac16K))); - ExpectTitle("OK"); -} - -IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, - EstablishAudioVideoCallAndVerifyMutingWorks) { - ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); - ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch( - switches::kUseFakeDeviceForMediaStream)) - << "Must run with fake devices since the test will explicitly look " - << "for the fake device signal."; - - GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html")); - NavigateToURL(shell(), url); - - EXPECT_TRUE(ExecuteJavascript( - base::StringPrintf("callAndEnsureAudioMutingWorks(%s);", - kForceIsac16K))); - ExpectTitle("OK"); -} - } // namespace content diff --git a/content/test/data/media/peerconnection-call.html b/content/test/data/media/peerconnection-call.html index 3b9b053..3793dc4 100644 --- a/content/test/data/media/peerconnection-call.html +++ b/content/test/data/media/peerconnection-call.html @@ -1,7 +1,6 @@ <html> <head> <script type="text/javascript" src="webrtc_test_utilities.js"></script> - <script type="text/javascript" src="webrtc_test_audio.js"></script> <script type="text/javascript"> $ = function(id) { return document.getElementById(id); @@ -248,56 +247,6 @@ detectVideoPlaying('remote-view-2', onCallEstablished); } - //TODO(phoglund): do this for all tests on android if this works on bots. - /** @private */ - function forceIsac16k_(sdp) { - // Remove all other codecs (not the video codecs though). - sdp = sdp.replace(/m=audio (\d+) RTP\/SAVPF.*\r\n/g, - 'm=audio $1 RTP/SAVPF 103\r\n'); - sdp = sdp.replace('a=fmtp:111 minptime=10', 'a=fmtp:103 minptime=10'); - sdp = sdp.replace(/a=rtpmap:(?!103)\d{1,3} (?!VP8|red|ulpfec).*\r\n/g, ''); - return sdp; - } - - function callAndEnsureAudioIsPlaying(force_isac_16k) { - if (force_isac_16k) - transformSdp = forceIsac16k_; - createConnections(null); - navigator.webkitGetUserMedia({audio: true, video: true}, - addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); - - // Wait until we have gathered samples and can conclude if audio is playing. - addExpectedEvent(); - var onCallEstablished = function() { - gatherAudioLevelSamples(gSecondConnection, 300, 100, - function(samples) { - verifyAudioIsPlaying(samples); - eventOccured(); - }); - }; - - detectVideoPlaying('remote-view-2', onCallEstablished); - } - - function callAndEnsureAudioMutingWorks() { - callAndEnsureAudioIsPlaying(); - setAllEventsOccuredHandler(function() { - var audioTrack = - gSecondConnection.getRemoteStreams()[0].getAudioTracks()[0]; - - // Call is up, now mute the track and check everything goes silent (give - // it a small delay though, we don't expect it to happen instantly). - audioTrack.enabled = false; - - setTimeout(function() { - gatherAudioLevelSamples(gSecondConnection, 200, 100, function(samples) { - verifyIsSilent(samples); - document.title = 'OK'; - }); - }, 500); - }); - } - // Test call with a new Video MediaStream that has been created based on a // stream generated by getUserMedia. function callWithNewVideoMediaStream() { @@ -501,15 +450,10 @@ gLocalStream = localStream; } - + // Called if getUserMedia fails. function printGetUserMediaError(error) { - document.title = 'getUserMedia request failed:'; - if (error.constraintName) - document.title += ' could not satisfy constraint ' + error.constraintName; - else - document.title += ' devices not working/user denied access.'; - console.log(document.title); + document.title = 'getUserMedia request failed with code ' + error.code; } // Called if getUserMedia succeeds and we want to send from both connections. diff --git a/content/test/data/media/webrtc_test_audio.js b/content/test/data/media/webrtc_test_audio.js deleted file mode 100644 index d0a8ed4..0000000 --- a/content/test/data/media/webrtc_test_audio.js +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Audio test utilities. - -// 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) { - var audioLevelSamples = [] - var gatherSamples = setInterval(function() { - peerConnection.getStats(function(response) { - audioLevelSamples.push(getAudioLevelFromStats_(response)); - if (audioLevelSamples.length == numSamples) { - clearInterval(gatherSamples); - callback(audioLevelSamples); - } - }); - }, 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. -function verifyAudioIsPlaying(samples) { - var average = 0; - for (var i = 0; i < samples.length; ++i) - average += samples[i] / samples.length; - - var largest = 0; - for (var i = 0; i < samples.length; ++i) - largest = Math.max(largest, samples[i]); - - console.log('Average audio level: ' + average + ', largest: ' + largest); - - // 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) - throw 'Unexpected avg audio level: got ' + average + ', expected it ' + - 'to be 4000 < avg < 8000.' - if (largest < 30000) - throw 'Too low max audio level: got ' + largest + ', expected > 30000.'; -}; - -// If silent (like when muted), we should get very near zero audio level. -function verifyIsSilent(samples) { - var average = 0; - for (var i = 0; i < samples.length; ++i) - average += samples[i] / samples.length; - - console.log('Average audio level: ' + average); - if (average > 10) - throw 'Expected silence, but avg audio level was ' + average; -} - -/** - * @private - */ -function getAudioLevelFromStats_(response) { - var reports = response.result(); - var audioOutputLevels = []; - for (var i = 0; i < reports.length; ++i) { - var report = reports[i]; - if (report.names().indexOf('audioOutputLevel') != -1) { - audioOutputLevels.push(report.stat('audioOutputLevel')); - } - } - // Should only be one audio level reported, otherwise we get confused. - expectEquals(1, audioOutputLevels.length); - - return audioOutputLevels[0]; -}
\ No newline at end of file |