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

Side by Side Diff: content/test/data/media/webrtc_test_audio.js

Issue 252703003: Wrote a test which exercises audio-only WebRTC calls. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/test/data/media/peerconnection-call.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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...');
15 var audioLevelSamples = [] 15 var audioLevelSamples = []
16 var gatherSamples = setInterval(function() { 16 var gatherSamples = setInterval(function() {
17 peerConnection.getStats(function(response) { 17 peerConnection.getStats(function(response) {
18 audioLevelSamples.push(getAudioLevelFromStats_(response)); 18 audioOutputLevels = getAudioLevelFromStats_(response);
19 if (audioOutputLevels.length == 0) {
20 // The call probably isn't up yet.
21 return;
22 }
23
24 // If more than one audio level is reported we get confused.
25 assertEquals(1, audioOutputLevels.length);
26 audioLevelSamples.push(audioOutputLevels[0]);
27
19 if (audioLevelSamples.length == numSamples) { 28 if (audioLevelSamples.length == numSamples) {
20 console.log('Gathered all samples.'); 29 console.log('Gathered all samples.');
21 clearInterval(gatherSamples); 30 clearInterval(gatherSamples);
22 callback(audioLevelSamples); 31 callback(audioLevelSamples);
23 } 32 }
24 }); 33 });
25 }, 1000 / frequency); 34 }, 1000 / frequency);
26 } 35 }
27 36
28 // Tries to identify the beep-every-half-second signal generated by the fake 37 // 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
76 */ 85 */
77 function getAudioLevelFromStats_(response) { 86 function getAudioLevelFromStats_(response) {
78 var reports = response.result(); 87 var reports = response.result();
79 var audioOutputLevels = []; 88 var audioOutputLevels = [];
80 for (var i = 0; i < reports.length; ++i) { 89 for (var i = 0; i < reports.length; ++i) {
81 var report = reports[i]; 90 var report = reports[i];
82 if (report.names().indexOf('audioOutputLevel') != -1) { 91 if (report.names().indexOf('audioOutputLevel') != -1) {
83 audioOutputLevels.push(report.stat('audioOutputLevel')); 92 audioOutputLevels.push(report.stat('audioOutputLevel'));
84 } 93 }
85 } 94 }
86 // Should only be one audio level reported, otherwise we get confused. 95 return audioOutputLevels;
87 assertEquals(1, audioOutputLevels.length);
88
89 return audioOutputLevels[0];
90 } 96 }
OLDNEW
« no previous file with comments | « content/test/data/media/peerconnection-call.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698