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 | 3e2f8ff | 2014-10-15 15:01:11 +0000 | [diff] [blame] | 23 | this.asyncCreateTurnConfig(function(config) { |
| 24 | this.createPeerConnection(config, done, test.fail); |
| 25 | }.bind(this), test.fail); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 26 | } |
| 27 | |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 28 | function onPeerConnectionCreated(pc1, pc2) { |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 29 | test.log("RTC Peers created."); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 30 | pc1.addEventListener('addstream', test.fail); |
| 31 | pc2.addEventListener('addstream', onAddStream); |
| 32 | pc1.addEventListener('icecandidate', onIceCandidate.bind(pc2)); |
| 33 | pc2.addEventListener('icecandidate', onIceCandidate.bind(pc1)); |
| 34 | |
| 35 | bot1.getUserMedia({video:true, audio:true}, onUserMediaSuccess, test.fail); |
| 36 | |
| 37 | function onUserMediaSuccess(stream) { |
| 38 | test.log("User has granted access to local media."); |
| 39 | pc1.addStream(stream); |
| 40 | bot1.showStream(stream.id, true, true); |
| 41 | |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 42 | createOfferAndAnswer(pc1, pc2); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | function onAddStream(event) { |
| 47 | test.log("On Add stream."); |
| 48 | bot2.showStream(event.stream.id, true, false); |
| 49 | } |
| 50 | |
| 51 | function onIceCandidate(event) { |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 52 | if(event.candidate) { |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 53 | test.log(event.candidate.candidate); |
| 54 | this.addIceCandidate(event.candidate, |
| 55 | onAddIceCandidateSuccess, test.fail); |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 56 | } |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 57 | |
| 58 | function onAddIceCandidateSuccess() { |
| 59 | test.log("Candidate added successfully"); |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 60 | } |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 61 | } |
| 62 | |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 63 | function createOfferAndAnswer(pc1, pc2) { |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 64 | test.log("Creating offer."); |
| 65 | pc1.createOffer(gotOffer, test.fail); |
| 66 | |
| 67 | function gotOffer(offer) { |
| 68 | test.log("Got offer"); |
| 69 | pc1.setLocalDescription(offer, onSetSessionDescriptionSuccess, test.fail); |
| 70 | pc2.setRemoteDescription(offer, onSetSessionDescriptionSuccess, |
| 71 | test.fail); |
| 72 | test.log("Creating answer"); |
| 73 | pc2.createAnswer(gotAnswer, test.fail); |
| 74 | } |
| 75 | |
| 76 | function gotAnswer(answer) { |
| 77 | test.log("Got answer"); |
| 78 | pc2.setLocalDescription(answer, onSetSessionDescriptionSuccess, |
| 79 | test.fail); |
| 80 | pc1.setRemoteDescription(answer, onSetSessionDescriptionSuccess, |
| 81 | test.fail); |
houssainy@google.com | d0bb586 | 2014-09-30 15:20:15 +0000 | [diff] [blame] | 82 | collectStats(); |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | function onSetSessionDescriptionSuccess() { |
| 86 | test.log("Set session description success."); |
| 87 | } |
houssainy@google.com | d0bb586 | 2014-09-30 15:20:15 +0000 | [diff] [blame] | 88 | |
| 89 | function collectStats() { |
| 90 | report.collectStatsFromPeerConnection("bot1", pc1); |
| 91 | report.collectStatsFromPeerConnection("bot2", pc2); |
| 92 | |
| 93 | setTimeout(function() { |
| 94 | report.finish(test.done); |
| 95 | }, 10000); |
| 96 | } |
houssainy@google.com | 07ca949 | 2014-09-22 13:52:39 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
houssainy@google.com | c221db6 | 2014-10-17 09:13:43 +0000 | [diff] [blame] | 100 | registerBotTest('testOneWayVideo/chrome-chrome', |
andresp@webrtc.org | 458c2c3 | 2014-10-16 07:36:37 +0000 | [diff] [blame] | 101 | testOneWayVideo, ['chrome', 'chrome']); |