blob: db08a7837e083443a0c1c744ce9bc200691fbad7 [file] [log] [blame]
houssainy@google.com07ca9492014-09-22 13:52:39 +00001// 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.comd0bb5862014-09-30 15:20:15 +000010// The test succeeds after collecting stats for 10 seconds from both bots
11// and then write these stats to a file.
houssainy@google.com07ca9492014-09-22 13:52:39 +000012//
13// Note: the source of the video and audio stream is getUserMedia().
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000014function testOneWayVideo(test, bot1, bot2) {
houssainy@google.comd0bb5862014-09-30 15:20:15 +000015 var report = test.createStatisticsReport("webrtc_video_streaming");
16
houssainy@google.com07ca9492014-09-22 13:52:39 +000017 test.wait([
18 createPeerConnection.bind(bot1),
19 createPeerConnection.bind(bot2) ],
20 onPeerConnectionCreated);
21
22 function createPeerConnection(done) {
houssainy@google.com3e2f8ff2014-10-15 15:01:11 +000023 this.asyncCreateTurnConfig(function(config) {
24 this.createPeerConnection(config, done, test.fail);
25 }.bind(this), test.fail);
houssainy@google.com07ca9492014-09-22 13:52:39 +000026 }
27
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000028 function onPeerConnectionCreated(pc1, pc2) {
houssainy@google.com07ca9492014-09-22 13:52:39 +000029 test.log("RTC Peers created.");
houssainy@google.com07ca9492014-09-22 13:52:39 +000030 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.org458c2c32014-10-16 07:36:37 +000042 createOfferAndAnswer(pc1, pc2);
houssainy@google.com07ca9492014-09-22 13:52:39 +000043 }
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.org458c2c32014-10-16 07:36:37 +000052 if(event.candidate) {
houssainy@google.com07ca9492014-09-22 13:52:39 +000053 test.log(event.candidate.candidate);
54 this.addIceCandidate(event.candidate,
55 onAddIceCandidateSuccess, test.fail);
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000056 }
houssainy@google.com07ca9492014-09-22 13:52:39 +000057
58 function onAddIceCandidateSuccess() {
59 test.log("Candidate added successfully");
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000060 }
houssainy@google.com07ca9492014-09-22 13:52:39 +000061 }
62
andresp@webrtc.org458c2c32014-10-16 07:36:37 +000063 function createOfferAndAnswer(pc1, pc2) {
houssainy@google.com07ca9492014-09-22 13:52:39 +000064 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.comd0bb5862014-09-30 15:20:15 +000082 collectStats();
houssainy@google.com07ca9492014-09-22 13:52:39 +000083 }
84
85 function onSetSessionDescriptionSuccess() {
86 test.log("Set session description success.");
87 }
houssainy@google.comd0bb5862014-09-30 15:20:15 +000088
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.com07ca9492014-09-22 13:52:39 +000097 }
98}
99
houssainy@google.comc221db62014-10-17 09:13:43 +0000100registerBotTest('testOneWayVideo/chrome-chrome',
andresp@webrtc.org458c2c32014-10-16 07:36:37 +0000101 testOneWayVideo, ['chrome', 'chrome']);