Demo of multi-pass encode - used for testing limits.
This demo creates a sequence of PeerConnections, and passes a videostream through all of them. This allows one to test how many PeerConnections and how many encodes/decodes the implementation will support before breaking down or slowing down enough to be unusable. BUG= R=fischman@webrtc.org, hta@webrtc.org Review URL: https://webrtc-codereview.appspot.com/8479004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5557 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
98
samples/js/demos/html/multiple-relay.html
Normal file
98
samples/js/demos/html/multiple-relay.html
Normal file
@@ -0,0 +1,98 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>PeerConnection Demo 1</title>
|
||||
<!-- Load the polyfill to switch-hit between Chrome and Firefox -->
|
||||
<script src="../../base/adapter.js"></script>
|
||||
<script src="../js/videopipe.js"></script>
|
||||
<style>
|
||||
video {
|
||||
border:5px solid black;
|
||||
width:480px;
|
||||
height:360px;
|
||||
}
|
||||
button {
|
||||
font: 18px sans-serif;
|
||||
padding: 8px;
|
||||
}
|
||||
textarea {
|
||||
font-family: monospace;
|
||||
margin: 2px;
|
||||
width:480px;
|
||||
height:640px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<video id="vid1" autoplay></video>
|
||||
<video id="vid2" autoplay></video>
|
||||
<br>
|
||||
<button id="btn1" onclick="start()">Start</button>
|
||||
<button id="btn2" onclick="call()">Call</button>
|
||||
<button id="btn3" onclick="addrelay()">Insert relay</button>
|
||||
<button id="btn4" onclick="hangup()">Hang Up</button>
|
||||
<br>
|
||||
<xtextarea id="ta1"></textarea>
|
||||
<script>
|
||||
btn1.disabled = false;
|
||||
btn2.disabled = true;
|
||||
btn3.disabled = true;
|
||||
btn4.disabled = true;
|
||||
var pipes = new Array();
|
||||
|
||||
var localstream;
|
||||
var remotestream;
|
||||
|
||||
function gotStream(stream){
|
||||
trace("Received local stream");
|
||||
attachMediaStream(vid1, stream);
|
||||
localstream = stream;
|
||||
btn2.disabled = false;
|
||||
}
|
||||
|
||||
function gotRemoteStream(stream){
|
||||
remotestream = stream;
|
||||
attachMediaStream(vid2, stream);
|
||||
trace("Received remote stream");
|
||||
trace(pipes.length + ' elements in chain');
|
||||
ta1.textContent = pipes.length + ' elements in chain';
|
||||
btn3.disabled = false;
|
||||
}
|
||||
|
||||
function start() {
|
||||
trace("Requesting local stream");
|
||||
btn1.disabled = true;
|
||||
getUserMedia({audio:false, video:true},
|
||||
gotStream,
|
||||
function() {
|
||||
alert('getUserMedia failed');
|
||||
});
|
||||
}
|
||||
|
||||
function call() {
|
||||
btn2.disabled = true;
|
||||
btn3.disabled = false;
|
||||
btn4.disabled = false;
|
||||
trace("Starting call");
|
||||
pipes.push(new VideoPipe(localstream, gotRemoteStream));
|
||||
}
|
||||
|
||||
function addrelay() {
|
||||
pipes.push(new VideoPipe(remotestream, gotRemoteStream));
|
||||
btn3.disabled = true;
|
||||
}
|
||||
|
||||
function hangup() {
|
||||
trace("Ending call");
|
||||
while (pipes.length > 0) {
|
||||
var pipe = pipes.pop()
|
||||
pipe.close();
|
||||
}
|
||||
btn3.disabled = true;
|
||||
btn4.disabled = true;
|
||||
btn2.disabled = false;
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
68
samples/js/demos/js/videopipe.js
Normal file
68
samples/js/demos/js/videopipe.js
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// A "videopipe" abstraction on top of WebRTC.
|
||||
//
|
||||
// The usage of this abstraction:
|
||||
// var pipe = new VideoPipe(mediastream, handlerFunction);
|
||||
// handlerFunction = function(mediastream) {
|
||||
// do_something
|
||||
// }
|
||||
// pipe.close();
|
||||
//
|
||||
// The VideoPipe will set up 2 PeerConnections, connect them to each
|
||||
// other, and call HandlerFunction when the stream is available in the
|
||||
// second PeerConnection.
|
||||
//
|
||||
|
||||
function errorHandler(context) {
|
||||
return function(error) {
|
||||
trace('Failure in ' + context + ': ' + error.toString);
|
||||
}
|
||||
}
|
||||
|
||||
function successHandler(context) {
|
||||
return function() {
|
||||
trace('Success in ' + context);
|
||||
}
|
||||
}
|
||||
|
||||
function noAction() {
|
||||
}
|
||||
|
||||
|
||||
function VideoPipe(stream, handler) {
|
||||
var servers = null;
|
||||
var pc1 = new RTCPeerConnection(servers);
|
||||
var pc2 = new RTCPeerConnection(servers);
|
||||
|
||||
pc1.addStream(stream);
|
||||
pc1.onicecandidate = function(event) {
|
||||
if (event.candidate) {
|
||||
pc2.addIceCandidate(new RTCIceCandidate(event.candidate),
|
||||
noAction, errorHandler('AddIceCandidate'));
|
||||
}
|
||||
}
|
||||
pc2.onicecandidate = function(event) {
|
||||
if (event.candidate) {
|
||||
pc1.addIceCandidate(new RTCIceCandidate(event.candidate),
|
||||
noAction, errorHandler('AddIceCandidate'));
|
||||
}
|
||||
}
|
||||
pc2.onaddstream = function(e) {
|
||||
handler(e.stream);
|
||||
}
|
||||
pc1.createOffer(function(desc) {
|
||||
pc1.setLocalDescription(desc);
|
||||
pc2.setRemoteDescription(desc);
|
||||
pc2.createAnswer(function(desc2) {
|
||||
pc2.setLocalDescription(desc2);
|
||||
pc1.setRemoteDescription(desc2);
|
||||
}, errorHandler('pc2.createAnswer'));
|
||||
}, errorHandler('pc1.createOffer'));
|
||||
this.pc1 = pc1;
|
||||
this.pc2 = pc2;
|
||||
}
|
||||
|
||||
VideoPipe.prototype.close = function() {
|
||||
this.pc1.close();
|
||||
this.pc2.close();
|
||||
}
|
Reference in New Issue
Block a user