OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
| 4 <script type="text/javascript" src="webrtc_test_common.js"></script> |
| 5 <script type="text/javascript" src="webrtc_test_audio.js"></script> |
| 6 <script type="text/javascript"> |
| 7 $ = function(id) { |
| 8 return document.getElementById(id); |
| 9 }; |
| 10 |
| 11 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { |
| 12 failTest('Error: ' + errorMsg + '\nScript: ' + url + |
| 13 '\nLine: ' + lineNumber + '\nColumn: ' + column + |
| 14 '\nStackTrace: ' + errorObj); |
| 15 } |
| 16 |
| 17 var gFirstConnection = null; |
| 18 var gSecondConnection = null; |
| 19 var gLocalStream = null; |
| 20 var gSentTones = ''; |
| 21 |
| 22 var gRemoteStreams = {}; |
| 23 |
| 24 setAllEventsOccuredHandler(reportTestSuccess); |
| 25 |
| 26 // The second set of constraints should request audio (e.g. audio:true) since |
| 27 // we expect audio to be playing after the second renegotiation. |
| 28 function callAndRenegotiateToAudio(constraints, renegotiationConstraints) { |
| 29 createConnections(null); |
| 30 navigator.webkitGetUserMedia(constraints, |
| 31 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
| 32 |
| 33 waitForConnectionToStabilize(gFirstConnection, function() { |
| 34 gFirstConnection.removeStream(gLocalStream); |
| 35 gSecondConnection.removeStream(gLocalStream); |
| 36 |
| 37 navigator.webkitGetUserMedia(renegotiationConstraints, |
| 38 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); |
| 39 |
| 40 var onCallEstablished = function() { |
| 41 ensureAudioPlaying(gSecondConnection); |
| 42 }; |
| 43 |
| 44 waitForConnectionToStabilize(gFirstConnection, onCallEstablished); |
| 45 }); |
| 46 } |
| 47 |
| 48 function callAndEnsureAudioIsPlaying(constraints) { |
| 49 createConnections(null); |
| 50 |
| 51 // Add the local stream to gFirstConnection to play one-way audio. |
| 52 navigator.webkitGetUserMedia(constraints, |
| 53 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); |
| 54 |
| 55 var onCallEstablished = function() { |
| 56 ensureAudioPlaying(gSecondConnection); |
| 57 }; |
| 58 |
| 59 waitForConnectionToStabilize(gFirstConnection, onCallEstablished); |
| 60 } |
| 61 |
| 62 function callWithIsac16KAndEnsureAudioIsPlaying(constraints) { |
| 63 setOfferSdpTransform(function(sdp) { |
| 64 sdp = sdp.replace(/m=audio (\d+) RTP\/SAVPF.*\r\n/g, |
| 65 'm=audio $1 RTP/SAVPF 103 126\r\n'); |
| 66 sdp = sdp.replace('a=fmtp:111 minptime=10', 'a=fmtp:103 minptime=10'); |
| 67 if (sdp.search('a=rtpmap:103 ISAC/16000') == -1) |
| 68 failTest('Missing iSAC 16K codec on Android; cannot force codec.'); |
| 69 |
| 70 return sdp; |
| 71 }); |
| 72 callAndEnsureAudioIsPlaying(constraints); |
| 73 } |
| 74 |
| 75 function enableRemoteVideo(peerConnection, enabled) { |
| 76 remoteStream = peerConnection.getRemoteStreams()[0]; |
| 77 remoteStream.getVideoTracks()[0].enabled = enabled; |
| 78 } |
| 79 |
| 80 function enableRemoteAudio(peerConnection, enabled) { |
| 81 remoteStream = peerConnection.getRemoteStreams()[0]; |
| 82 remoteStream.getAudioTracks()[0].enabled = enabled; |
| 83 } |
| 84 |
| 85 function enableLocalVideo(peerConnection, enabled) { |
| 86 localStream = peerConnection.getLocalStreams()[0]; |
| 87 localStream.getVideoTracks()[0].enabled = enabled; |
| 88 } |
| 89 |
| 90 function enableLocalAudio(peerConnection, enabled) { |
| 91 localStream = peerConnection.getLocalStreams()[0]; |
| 92 localStream.getAudioTracks()[0].enabled = enabled; |
| 93 } |
| 94 |
| 95 function callAndEnsureRemoteAudioTrackMutingWorks() { |
| 96 callAndEnsureAudioIsPlaying({audio: true, video: true}); |
| 97 setAllEventsOccuredHandler(function() { |
| 98 setAllEventsOccuredHandler(reportTestSuccess); |
| 99 |
| 100 // Call is up, now mute the remote track and check we stop playing out |
| 101 // audio (after a small delay, we don't expect it to happen instantly). |
| 102 enableRemoteAudio(gSecondConnection, false); |
| 103 ensureSilence(gSecondConnection); |
| 104 }); |
| 105 } |
| 106 |
| 107 function callAndEnsureLocalAudioTrackMutingWorks() { |
| 108 callAndEnsureAudioIsPlaying({audio: true, video: true}); |
| 109 setAllEventsOccuredHandler(function() { |
| 110 setAllEventsOccuredHandler(reportTestSuccess); |
| 111 |
| 112 // Call is up, now mute the local track of the sending side and ensure |
| 113 // the receiving side stops receiving audio. |
| 114 enableLocalAudio(gFirstConnection, false); |
| 115 ensureSilence(gSecondConnection); |
| 116 }); |
| 117 } |
| 118 |
| 119 function callAndEnsureAudioTrackUnmutingWorks() { |
| 120 callAndEnsureAudioIsPlaying({audio: true, video: true}); |
| 121 setAllEventsOccuredHandler(function() { |
| 122 setAllEventsOccuredHandler(reportTestSuccess); |
| 123 |
| 124 // Mute, wait a while, unmute, verify audio gets back up. |
| 125 // (Also, ensure video muting doesn't affect audio). |
| 126 enableRemoteAudio(gSecondConnection, false); |
| 127 enableRemoteVideo(gSecondConnection, false); |
| 128 |
| 129 setTimeout(function() { |
| 130 enableRemoteAudio(gSecondConnection, true); |
| 131 }, 500); |
| 132 |
| 133 setTimeout(function() { |
| 134 ensureAudioPlaying(gSecondConnection); |
| 135 }, 1500); |
| 136 }); |
| 137 } |
| 138 |
| 139 function callAndEnsureLocalVideoMutingDoesntMuteAudio() { |
| 140 callAndEnsureAudioIsPlaying({audio: true, video: true}); |
| 141 setAllEventsOccuredHandler(function() { |
| 142 setAllEventsOccuredHandler(reportTestSuccess); |
| 143 enableLocalVideo(gFirstConnection, false); |
| 144 ensureAudioPlaying(gSecondConnection); |
| 145 }); |
| 146 } |
| 147 |
| 148 function callAndEnsureRemoteVideoMutingDoesntMuteAudio() { |
| 149 callAndEnsureAudioIsPlaying({audio: true, video: true}); |
| 150 setAllEventsOccuredHandler(function() { |
| 151 setAllEventsOccuredHandler(reportTestSuccess); |
| 152 enableRemoteVideo(gSecondConnection, false); |
| 153 ensureAudioPlaying(gSecondConnection); |
| 154 }); |
| 155 } |
| 156 |
| 157 function createConnections(constraints) { |
| 158 gFirstConnection = createConnection(constraints, 'remote-view-1'); |
| 159 assertEquals('stable', gFirstConnection.signalingState); |
| 160 |
| 161 gSecondConnection = createConnection(constraints, 'remote-view-2'); |
| 162 assertEquals('stable', gSecondConnection.signalingState); |
| 163 } |
| 164 |
| 165 function createConnection(constraints, remoteView) { |
| 166 var pc = new webkitRTCPeerConnection(null, constraints); |
| 167 pc.onaddstream = function(event) { |
| 168 onRemoteStream(event, remoteView); |
| 169 } |
| 170 return pc; |
| 171 } |
| 172 |
| 173 function displayAndRemember(localStream) { |
| 174 var localStreamUrl = URL.createObjectURL(localStream); |
| 175 $('local-view').src = localStreamUrl; |
| 176 |
| 177 gLocalStream = localStream; |
| 178 } |
| 179 |
| 180 // Called if getUserMedia succeeds and we want to send from both connections. |
| 181 function addStreamToBothConnectionsAndNegotiate(localStream) { |
| 182 displayAndRemember(localStream); |
| 183 gFirstConnection.addStream(localStream); |
| 184 gSecondConnection.addStream(localStream); |
| 185 negotiate(); |
| 186 } |
| 187 |
| 188 // Called if getUserMedia succeeds when we want to send from one connection. |
| 189 function addStreamToTheFirstConnectionAndNegotiate(localStream) { |
| 190 displayAndRemember(localStream); |
| 191 gFirstConnection.addStream(localStream); |
| 192 negotiate(); |
| 193 } |
| 194 |
| 195 function negotiate() { |
| 196 negotiateBetween(gFirstConnection, gSecondConnection); |
| 197 } |
| 198 |
| 199 function onRemoteStream(e, target) { |
| 200 console.log("Receiving remote stream..."); |
| 201 gRemoteStreams[target] = e.stream; |
| 202 var remoteStreamUrl = URL.createObjectURL(e.stream); |
| 203 var remoteVideo = $(target); |
| 204 remoteVideo.src = remoteStreamUrl; |
| 205 } |
| 206 |
| 207 </script> |
| 208 </head> |
| 209 <body> |
| 210 <table border="0"> |
| 211 <tr> |
| 212 <td><video width="320" height="240" id="local-view" style="display:none" |
| 213 autoplay muted></video></td> |
| 214 <td><video width="320" height="240" id="remote-view-1" |
| 215 style="display:none" autoplay></video></td> |
| 216 <td><video width="320" height="240" id="remote-view-2" |
| 217 style="display:none" autoplay></video></td> |
| 218 <!-- Canvases are named after their corresponding video elements. --> |
| 219 <td><canvas width="320" height="240" id="remote-view-1-canvas" |
| 220 style="display:none"></canvas></td> |
| 221 <td><canvas width="320" height="240" id="remote-view-2-canvas" |
| 222 style="display:none"></canvas></td> |
| 223 </tr> |
| 224 </table> |
| 225 </body> |
| 226 </html> |
OLD | NEW |