blob: d0a7bd5dad484ad40a444b27777aa886112d99aa [file] [log] [blame]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing basic video exchange from offerer to receiver</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<video id="video" autoplay=""></video>
<canvas id="canvas" width="640" height="480"></canvas>
<script src ="routines.js"></script>
<script>
video = document.getElementById("video");
canvas = document.getElementById("canvas");
async function getOutboundRTPStatsNumberOfEncodedFrames(connection)
{
var report = await connection.getStats();
var framesEncoded;
report.forEach((statItem) => {
if (statItem.type === "outbound-rtp") {
framesEncoded = statItem.framesEncoded;
}
});
return framesEncoded;
}
async function testFrameEncodedStarted(connection, count, previousFramesNumber)
{
var framesEncodedNumber = await getOutboundRTPStatsNumberOfEncodedFrames(connection);
if (previousFramesNumber && framesEncodedNumber > previousFramesNumber)
return;
if (count === undefined)
count = 0;
if (count >= 20)
return Promise.reject("test increasing frame encoded timed out");
await waitFor(100);
return testFrameEncodedStarted(connection, ++count, framesEncodedNumber);
}
async function testFrameEncodedStopped(connection, count, previousFramesNumber)
{
var framesEncodedNumber = await getOutboundRTPStatsNumberOfEncodedFrames(connection);
if (previousFramesNumber && framesEncodedNumber === previousFramesNumber)
return;
if (count === undefined)
count = 0;
if (count === 20)
return Promise.reject("test that number of encoded frames stopped increasing timed out");
await waitFor(100);
return testFrameEncodedStopped(connection, ++count, framesEncodedNumber);
}
promise_test((test) => {
if (window.testRunner)
testRunner.setUserMediaPermission(true);
var sender;
var frontStream;
var connection;
return navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
frontStream = stream;
}).then(() => {
return new Promise((resolve, reject) => {
createConnections((firstConnection) => {
connection = firstConnection;
sender = firstConnection.addTrack(frontStream.getVideoTracks()[0], frontStream);
}, (secondConnection) => {
secondConnection.ontrack = (trackEvent) => {
resolve(trackEvent.streams[0]);
};
});
setTimeout(() => reject("Test timed out"), 5000);
});
}).then((remoteStream) => {
video.srcObject = remoteStream;
return video.play();
}).then(() => {
return testFrameEncodedStarted(connection);
}).then(() => {
}).then(() => {
promise = sender.replaceTrack(null);
assert_true(!!sender.track);
return promise;
}).then(() => {
return testFrameEncodedStopped(connection);
});
}, "Stopping sending video using replaceTrack");
</script>
</body>
</html>