houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 1 | // Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style license |
| 4 | // that can be found in the LICENSE file in the root of the source |
| 5 | // tree. An additional intellectual property rights grant can be found |
| 6 | // in the file PATENTS. All contributing project authors may |
| 7 | // be found in the AUTHORS file in the root of the source tree. |
| 8 | // |
| 9 | // A unidirectional video and audio flowing test from bot 1 to bot 2. |
houssainy@google.com | d0bb586 | 2014-09-30 15:20:15 +0000 | [diff] [blame] | 10 | // The test succeeds after collecting stats for 10 seconds from both bots |
| 11 | // and then write these stats to a file. |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 12 | // |
| 13 | // Note: the source of the video and audio stream is getUserMedia(). |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 14 | function testOneWayVideo(test, bot1, bot2) { |
houssainy@google.com | d0bb586 | 2014-09-30 15:20:15 +0000 | [diff] [blame] | 15 | var report = test.createStatisticsReport("webrtc_video_streaming"); |
| 16 | |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 17 | test.wait([ |
| 18 | createPeerConnection.bind(bot1), |
| 19 | createPeerConnection.bind(bot2) ], |
| 20 | onPeerConnectionCreated); |
| 21 | |
| 22 | function createPeerConnection(done) { |
houssainy@google.com | 3382059 | 2014-10-22 17:17:15 +0000 | [diff] [blame] | 23 | test.createTurnConfig(onTurnConfig.bind(this), test.fail); |
houssainy@google.com | 0371a37 | 2014-10-17 16:43:50 +0000 | [diff] [blame] | 24 | |
| 25 | function onTurnConfig(config) { |
houssainy@google.com | 3e2f8ff | 2014-10-15 15:01:11 +0000 | [diff] [blame] | 26 | this.createPeerConnection(config, done, test.fail); |
houssainy@google.com | 0371a37 | 2014-10-17 16:43:50 +0000 | [diff] [blame] | 27 | }; |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 28 | } |
| 29 | |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 30 | function onPeerConnectionCreated(pc1, pc2) { |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 31 | test.log("RTC Peers created."); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 32 | pc1.addEventListener('addstream', test.fail); |
| 33 | pc2.addEventListener('addstream', onAddStream); |
| 34 | pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2)); |
| 35 | pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1)); |
| 36 | |
| 37 | bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail); |
| 38 | |
| 39 | function onUserMediaSuccess(stream) { |
| 40 | test.log("User has granted access to local media."); |
| 41 | pc1.addStream(stream); |
| 42 | bot1.showStream(stream.id, true, true); |
| 43 | |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 44 | createOfferAndAnswer(pc1, pc2); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | function onAddStream(event) { |
| 49 | test.log("On Add stream."); |
| 50 | bot2.showStream(event.stream.id, true, false); |
| 51 | } |
| 52 | |
| 53 | function onIceCandidate(event) { |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 54 | if(event.candidate) { |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 55 | test.log(event.candidate.candidate); |
| 56 | this.addIceCandidate(event.candidate, |
| 57 | onAddIceCandidateSuccess, test.fail); |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 58 | } |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 59 | |
| 60 | function onAddIceCandidateSuccess() { |
| 61 | test.log("Candidate added successfully"); |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 62 | } |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 63 | } |
| 64 | |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 65 | function createOfferAndAnswer(pc1, pc2) { |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 66 | test.log("Creating offer."); |
| 67 | pc1.createOffer(gotOffer, test.fail); |
| 68 | |
| 69 | function gotOffer(offer) { |
| 70 | test.log("Got offer"); |
| 71 | pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail); |
| 72 | pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess, |
| 73 | test.fail); |
| 74 | test.log("Creating answer"); |
| 75 | pc2.createAnswer(gotAnswer, test.fail); |
| 76 | } |
| 77 | |
| 78 | function gotAnswer(answer) { |
| 79 | test.log("Got answer"); |
| 80 | pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess, |
| 81 | test.fail); |
| 82 | pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess, |
| 83 | test.fail); |
houssainy@google.com | d0bb586 | 2014-09-30 15:20:15 +0000 | [diff] [blame] | 84 | collectStats(); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | function onSetSessionDescriptionSuccess() { |
| 88 | test.log("Set session description success."); |
| 89 | } |
houssainy@google.com | d0bb586 | 2014-09-30 15:20:15 +0000 | [diff] [blame] | 90 | |
| 91 | function collectStats() { |
| 92 | report.collectStatsFromPeerConnection("bot1", pc1); |
| 93 | report.collectStatsFromPeerConnection("bot2", pc2); |
| 94 | |
| 95 | setTimeout(function() { |
| 96 | report.finish(test.done); |
| 97 | }, 10000); |
| 98 | } |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
houssainy@google.com | c221db6 | 2014-10-17 09:13:43 +0000 | [diff] [blame] | 102 | registerBotTest('testOneWayVideo/chrome-chrome', |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 103 | testOneWayVideo, ['chrome', 'chrome']); |