Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Audio test utilities. | 5 // Audio test utilities. |
| 6 | 6 |
| 7 // GetStats reports audio output energy in the [0, 32768] range. | 7 // GetStats reports audio output energy in the [0, 32768] range. |
| 8 var MAX_AUDIO_OUTPUT_ENERGY = 32768; | 8 var MAX_AUDIO_OUTPUT_ENERGY = 32768; |
| 9 | 9 |
| 10 // Gathers |numSamples| samples at |frequency| number of times per second and | 10 // Gathers |numSamples| samples at |frequency| number of times per second and |
| 11 // calls back |callback| with an array with numbers in the [0, 32768] range. | 11 // calls back |callback| with an array with numbers in the [0, 32768] range. |
| 12 function gatherAudioLevelSamples(peerConnection, numSamples, frequency, | 12 function gatherAudioLevelSamples(peerConnection, numSamples, frequency, |
| 13 callback) { | 13 callback) { |
| 14 console.log('Gathering ' + numSamples + ' audio samples...'); | 14 console.log('Gathering ' + numSamples + ' audio samples (waiting for call ' + |
| 15 'to get up if necessary)...'); | |
| 15 var audioLevelSamples = [] | 16 var audioLevelSamples = [] |
| 16 var gatherSamples = setInterval(function() { | 17 var gatherSamples = setInterval(function() { |
| 17 peerConnection.getStats(function(response) { | 18 peerConnection.getStats(function(response) { |
| 18 audioLevelSamples.push(getAudioLevelFromStats_(response)); | 19 audioOutputLevels = getAudioLevelFromStats_(response); |
| 20 if (audioOutputLevels.length == 0) | |
| 21 return; // The call probably isn't up yet. | |
|
no longer working on chromium
2014/06/05 09:12:32
nit, make it look more chromium:
if (audioOutputLe
phoglund_chromium
2014/06/09 06:55:36
Done.
| |
| 22 | |
| 23 // If more than one audio level is reported we get confused. | |
| 24 assertEquals(1, audioOutputLevels.length); | |
| 25 audioLevelSamples.push(audioOutputLevels[0]); | |
| 26 | |
| 19 if (audioLevelSamples.length == numSamples) { | 27 if (audioLevelSamples.length == numSamples) { |
| 20 console.log('Gathered all samples.'); | 28 console.log('Gathered all samples.'); |
| 21 clearInterval(gatherSamples); | 29 clearInterval(gatherSamples); |
| 22 callback(audioLevelSamples); | 30 callback(audioLevelSamples); |
| 23 } | 31 } |
| 24 }); | 32 }); |
| 25 }, 1000 / frequency); | 33 }, 1000 / frequency); |
| 26 } | 34 } |
| 27 | 35 |
| 28 // Tries to identify the beep-every-half-second signal generated by the fake | 36 // Tries to identify the beep-every-half-second signal generated by the fake |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 */ | 84 */ |
| 77 function getAudioLevelFromStats_(response) { | 85 function getAudioLevelFromStats_(response) { |
| 78 var reports = response.result(); | 86 var reports = response.result(); |
| 79 var audioOutputLevels = []; | 87 var audioOutputLevels = []; |
| 80 for (var i = 0; i < reports.length; ++i) { | 88 for (var i = 0; i < reports.length; ++i) { |
| 81 var report = reports[i]; | 89 var report = reports[i]; |
| 82 if (report.names().indexOf('audioOutputLevel') != -1) { | 90 if (report.names().indexOf('audioOutputLevel') != -1) { |
| 83 audioOutputLevels.push(report.stat('audioOutputLevel')); | 91 audioOutputLevels.push(report.stat('audioOutputLevel')); |
| 84 } | 92 } |
| 85 } | 93 } |
| 86 // Should only be one audio level reported, otherwise we get confused. | 94 return audioOutputLevels; |
| 87 assertEquals(1, audioOutputLevels.length); | |
| 88 | |
| 89 return audioOutputLevels[0]; | |
| 90 } | 95 } |
| OLD | NEW |