OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
4 <script type="text/javascript" src="webrtc_test_common.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"> | 5 <script type="text/javascript"> |
7 $ = function(id) { | 6 $ = function(id) { |
8 return document.getElementById(id); | 7 return document.getElementById(id); |
9 }; | 8 }; |
10 | 9 |
11 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { | 10 window.onerror = function(errorMsg, url, lineNumber, column, errorObj) { |
12 failTest('Error: ' + errorMsg + '\nScript: ' + url + | 11 failTest('Error: ' + errorMsg + '\nScript: ' + url + |
13 '\nLine: ' + lineNumber + '\nColumn: ' + column + | 12 '\nLine: ' + lineNumber + '\nColumn: ' + column + |
14 '\nStackTrace: ' + errorObj); | 13 '\nStackTrace: ' + errorObj); |
15 } | 14 } |
16 | 15 |
17 var gFirstConnection = null; | 16 var gFirstConnection = null; |
18 var gSecondConnection = null; | 17 var gSecondConnection = null; |
19 var gTestWithoutMsid = false; | 18 var gTestWithoutMsid = false; |
20 var gLocalStream = null; | 19 var gLocalStream = null; |
21 var gSentTones = ''; | 20 var gSentTones = ''; |
22 | 21 |
23 var gRemoteStreams = {}; | 22 var gRemoteStreams = {}; |
24 | 23 |
25 | |
26 setAllEventsOccuredHandler(reportTestSuccess); | 24 setAllEventsOccuredHandler(reportTestSuccess); |
27 | 25 |
28 // Test that we can setup a call with an audio and video track (must request | 26 // Test that we can setup a call with an audio and video track (must request |
29 // video in this call since we expect video to be playing). | 27 // video in this call since we expect video to be playing). |
30 function call(constraints) { | 28 function call(constraints) { |
31 createConnections(null); | 29 createConnections(null); |
32 navigator.webkitGetUserMedia(constraints, | 30 navigator.webkitGetUserMedia(constraints, |
33 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 31 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
34 waitForVideo('remote-view-1'); | 32 waitForVideo('remote-view-1'); |
35 waitForVideo('remote-view-2'); | 33 waitForVideo('remote-view-2'); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 gFirstConnection.removeStream(gLocalStream); | 90 gFirstConnection.removeStream(gLocalStream); |
93 gSecondConnection.removeStream(gLocalStream); | 91 gSecondConnection.removeStream(gLocalStream); |
94 | 92 |
95 navigator.webkitGetUserMedia(renegotiationConstraints, | 93 navigator.webkitGetUserMedia(renegotiationConstraints, |
96 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 94 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
97 waitForVideo('remote-view-1'); | 95 waitForVideo('remote-view-1'); |
98 waitForVideo('remote-view-2'); | 96 waitForVideo('remote-view-2'); |
99 }); | 97 }); |
100 } | 98 } |
101 | 99 |
102 // The second set of constraints should request audio (e.g. audio:true) since | |
103 // we expect audio to be playing after the second renegotiation. | |
104 function callAndRenegotiateToAudio(constraints, renegotiationConstraints) { | |
105 createConnections(null); | |
106 navigator.webkitGetUserMedia(constraints, | |
107 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | |
108 | |
109 waitForConnectionToStabilize(gFirstConnection, function() { | |
110 gFirstConnection.removeStream(gLocalStream); | |
111 gSecondConnection.removeStream(gLocalStream); | |
112 | |
113 navigator.webkitGetUserMedia(renegotiationConstraints, | |
114 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); | |
115 | |
116 var onCallEstablished = function() { | |
117 ensureAudioPlaying(gSecondConnection); | |
118 }; | |
119 | |
120 waitForConnectionToStabilize(gFirstConnection, onCallEstablished); | |
121 }); | |
122 } | |
123 | |
124 // First makes a call between pc1 and pc2 where a stream is sent from pc1 to | 100 // First makes a call between pc1 and pc2 where a stream is sent from pc1 to |
125 // pc2. The stream sent from pc1 to pc2 is cloned from the stream received on | 101 // pc2. The stream sent from pc1 to pc2 is cloned from the stream received on |
126 // pc2 to test that cloning of remote video tracks works as intended and is | 102 // pc2 to test that cloning of remote video tracks works as intended and is |
127 // sent back to pc1. | 103 // sent back to pc1. |
128 function callAndForwardRemoteStream(constraints) { | 104 function callAndForwardRemoteStream(constraints) { |
129 createConnections(null); | 105 createConnections(null); |
130 navigator.webkitGetUserMedia(constraints, | 106 navigator.webkitGetUserMedia(constraints, |
131 addStreamToTheFirstConnectionAndNegotiate, | 107 addStreamToTheFirstConnectionAndNegotiate, |
132 printGetUserMediaError); | 108 printGetUserMediaError); |
133 var onRemoteStream2 = function() { | 109 var onRemoteStream2 = function() { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 function(offer) { | 239 function(offer) { |
264 assertEquals(-1, offer.sdp.search('m=audio')); | 240 assertEquals(-1, offer.sdp.search('m=audio')); |
265 assertNotEquals(-1, offer.sdp.search('m=video')); | 241 assertNotEquals(-1, offer.sdp.search('m=video')); |
266 | 242 |
267 reportTestSuccess(); | 243 reportTestSuccess(); |
268 }, | 244 }, |
269 function(error) { failTest(error); }, | 245 function(error) { failTest(error); }, |
270 offerOptions); | 246 offerOptions); |
271 } | 247 } |
272 | 248 |
273 function callAndEnsureAudioIsPlaying(constraints) { | |
274 createConnections(null); | |
275 | |
276 // Add the local stream to gFirstConnection to play one-way audio. | |
277 navigator.webkitGetUserMedia(constraints, | |
278 addStreamToTheFirstConnectionAndNegotiate, printGetUserMediaError); | |
279 | |
280 var onCallEstablished = function() { | |
281 ensureAudioPlaying(gSecondConnection); | |
282 }; | |
283 | |
284 waitForConnectionToStabilize(gFirstConnection, onCallEstablished); | |
285 } | |
286 | |
287 function callWithIsac16KAndEnsureAudioIsPlaying(constraints) { | |
288 setOfferSdpTransform(function(sdp) { | |
289 sdp = sdp.replace(/m=audio (\d+) RTP\/SAVPF.*\r\n/g, | |
290 'm=audio $1 RTP/SAVPF 103 126\r\n'); | |
291 sdp = sdp.replace('a=fmtp:111 minptime=10', 'a=fmtp:103 minptime=10'); | |
292 if (sdp.search('a=rtpmap:103 ISAC/16000') == -1) | |
293 failTest('Missing iSAC 16K codec on Android; cannot force codec.'); | |
294 | |
295 return sdp; | |
296 }); | |
297 callAndEnsureAudioIsPlaying(constraints); | |
298 } | |
299 | |
300 function enableRemoteVideo(peerConnection, enabled) { | 249 function enableRemoteVideo(peerConnection, enabled) { |
301 remoteStream = peerConnection.getRemoteStreams()[0]; | 250 remoteStream = peerConnection.getRemoteStreams()[0]; |
302 remoteStream.getVideoTracks()[0].enabled = enabled; | 251 remoteStream.getVideoTracks()[0].enabled = enabled; |
303 } | 252 } |
304 | 253 |
305 function enableRemoteAudio(peerConnection, enabled) { | 254 function enableRemoteAudio(peerConnection, enabled) { |
306 remoteStream = peerConnection.getRemoteStreams()[0]; | 255 remoteStream = peerConnection.getRemoteStreams()[0]; |
307 remoteStream.getAudioTracks()[0].enabled = enabled; | 256 remoteStream.getAudioTracks()[0].enabled = enabled; |
308 } | 257 } |
309 | 258 |
310 function enableLocalVideo(peerConnection, enabled) { | |
311 localStream = peerConnection.getLocalStreams()[0]; | |
312 localStream.getVideoTracks()[0].enabled = enabled; | |
313 } | |
314 | |
315 function enableLocalAudio(peerConnection, enabled) { | |
316 localStream = peerConnection.getLocalStreams()[0]; | |
317 localStream.getAudioTracks()[0].enabled = enabled; | |
318 } | |
319 | |
320 function callAndEnsureRemoteAudioTrackMutingWorks() { | |
321 callAndEnsureAudioIsPlaying({audio: true, video: true}); | |
322 setAllEventsOccuredHandler(function() { | |
323 setAllEventsOccuredHandler(reportTestSuccess); | |
324 | |
325 // Call is up, now mute the remote track and check we stop playing out | |
326 // audio (after a small delay, we don't expect it to happen instantly). | |
327 enableRemoteAudio(gSecondConnection, false); | |
328 ensureSilence(gSecondConnection); | |
329 }); | |
330 } | |
331 | |
332 function callAndEnsureLocalAudioTrackMutingWorks() { | |
333 callAndEnsureAudioIsPlaying({audio: true, video: true}); | |
334 setAllEventsOccuredHandler(function() { | |
335 setAllEventsOccuredHandler(reportTestSuccess); | |
336 | |
337 // Call is up, now mute the local track of the sending side and ensure | |
338 // the receiving side stops receiving audio. | |
339 enableLocalAudio(gFirstConnection, false); | |
340 ensureSilence(gSecondConnection); | |
341 }); | |
342 } | |
343 | |
344 function callAndEnsureAudioTrackUnmutingWorks() { | |
345 callAndEnsureAudioIsPlaying({audio: true, video: true}); | |
346 setAllEventsOccuredHandler(function() { | |
347 setAllEventsOccuredHandler(reportTestSuccess); | |
348 | |
349 // Mute, wait a while, unmute, verify audio gets back up. | |
350 // (Also, ensure video muting doesn't affect audio). | |
351 enableRemoteAudio(gSecondConnection, false); | |
352 enableRemoteVideo(gSecondConnection, false); | |
353 | |
354 setTimeout(function() { | |
355 enableRemoteAudio(gSecondConnection, true); | |
356 }, 500); | |
357 | |
358 setTimeout(function() { | |
359 ensureAudioPlaying(gSecondConnection); | |
360 }, 1500); | |
361 }); | |
362 } | |
363 | |
364 function callAndEnsureLocalVideoMutingDoesntMuteAudio() { | |
365 callAndEnsureAudioIsPlaying({audio: true, video: true}); | |
366 setAllEventsOccuredHandler(function() { | |
367 setAllEventsOccuredHandler(reportTestSuccess); | |
368 enableLocalVideo(gFirstConnection, false); | |
369 ensureAudioPlaying(gSecondConnection); | |
370 }); | |
371 } | |
372 | |
373 function callAndEnsureRemoteVideoMutingDoesntMuteAudio() { | |
374 callAndEnsureAudioIsPlaying({audio: true, video: true}); | |
375 setAllEventsOccuredHandler(function() { | |
376 setAllEventsOccuredHandler(reportTestSuccess); | |
377 enableRemoteVideo(gSecondConnection, false); | |
378 ensureAudioPlaying(gSecondConnection); | |
379 }); | |
380 } | |
381 | |
382 function callAndEnsureVideoTrackMutingWorks() { | 259 function callAndEnsureVideoTrackMutingWorks() { |
383 createConnections(null); | 260 createConnections(null); |
384 navigator.webkitGetUserMedia({audio: true, video: true}, | 261 navigator.webkitGetUserMedia({audio: true, video: true}, |
385 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); | 262 addStreamToBothConnectionsAndNegotiate, printGetUserMediaError); |
386 | 263 |
387 addExpectedEvent(); | 264 addExpectedEvent(); |
388 detectVideoPlaying('remote-view-2', function() { | 265 detectVideoPlaying('remote-view-2', function() { |
389 // Disable the receiver's remote media stream. Video should stop. | 266 // Disable the receiver's remote media stream. Video should stop. |
390 // (Also, ensure muting audio doesn't affect video). | 267 // (Also, ensure muting audio doesn't affect video). |
391 enableRemoteVideo(gSecondConnection, false); | 268 enableRemoteVideo(gSecondConnection, false); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 'b=AS:16\r\n'); | 580 'b=AS:16\r\n'); |
704 offerSdp = offerSdp.replace('a=mid:video\r\n', 'a=mid:video\r\n'+ | 581 offerSdp = offerSdp.replace('a=mid:video\r\n', 'a=mid:video\r\n'+ |
705 'b=AS:512\r\n'); | 582 'b=AS:512\r\n'); |
706 return offerSdp; | 583 return offerSdp; |
707 } | 584 } |
708 | 585 |
709 function removeBundle(sdp) { | 586 function removeBundle(sdp) { |
710 return sdp.replace(/a=group:BUNDLE .*\r\n/g, ''); | 587 return sdp.replace(/a=group:BUNDLE .*\r\n/g, ''); |
711 } | 588 } |
712 | 589 |
713 | |
714 function onRemoteStream(e, target) { | 590 function onRemoteStream(e, target) { |
715 console.log("Receiving remote stream..."); | 591 console.log("Receiving remote stream..."); |
716 if (gTestWithoutMsid && e.stream.id != "default") { | 592 if (gTestWithoutMsid && e.stream.id != "default") { |
717 failTest('a default remote stream was expected but instead ' + | 593 failTest('a default remote stream was expected but instead ' + |
718 e.stream.id + ' was received.'); | 594 e.stream.id + ' was received.'); |
719 } | 595 } |
720 gRemoteStreams[target] = e.stream; | 596 gRemoteStreams[target] = e.stream; |
721 var remoteStreamUrl = URL.createObjectURL(e.stream); | 597 var remoteStreamUrl = URL.createObjectURL(e.stream); |
722 var remoteVideo = $(target); | 598 var remoteVideo = $(target); |
723 remoteVideo.src = remoteStreamUrl; | 599 remoteVideo.src = remoteStreamUrl; |
(...skipping 20 matching lines...) Expand all Loading... |
744 <td><canvas width="320" height="240" id="remote-view-2-canvas" | 620 <td><canvas width="320" height="240" id="remote-view-2-canvas" |
745 style="display:none"></canvas></td> | 621 style="display:none"></canvas></td> |
746 <td><canvas width="320" height="240" id="remote-view-3-canvas" | 622 <td><canvas width="320" height="240" id="remote-view-3-canvas" |
747 style="display:none"></canvas></td> | 623 style="display:none"></canvas></td> |
748 <td><canvas width="320" height="240" id="remote-view-4-canvas" | 624 <td><canvas width="320" height="240" id="remote-view-4-canvas" |
749 style="display:none"></canvas></td> | 625 style="display:none"></canvas></td> |
750 </tr> | 626 </tr> |
751 </table> | 627 </table> |
752 </body> | 628 </body> |
753 </html> | 629 </html> |
OLD | NEW |