blob: 2f029a786015b2b0320e156da43c2f02f0cd9ff6 [file] [log] [blame]
<html>
<head>
<script type="text/javascript" src="webrtc_test_utilities.js"></script>
<script type="text/javascript">
$ = function(id) {
return document.getElementById(id);
};
var gLocalStream = null;
setAllEventsOccuredHandler(function() {
gLocalStream.stop();
document.title = 'OK';
});
// Creates a MediaStream and renders it locally. When the video is detected to
// be rolling, the title is changed and the stream should be stopped.
function getUserMediaAndStop(constraints) {
navigator.webkitGetUserMedia(
constraints,
function(stream) { displayAndDetectVideo(stream, stopVideoTrack); },
failedCallback);
}
// Creates a MediaStream and renders it locally. When the video is detected to
// be rolling, the title should be changed and the stream is let roll for a
// number |waitTimeInSeconds| and then it should be stopped.
function getUserMediaAndWaitAndStop(constraints, waitTimeInSeconds) {
navigator.webkitGetUserMedia(
constraints,
function(stream) {
displayAndDetectVideo(
stream,
function() {
waitAndStopVideoTrack(waitTimeInSeconds);
});
},
failedCallback);
}
function getUserMediaAndAnalyseAndStop(constraints) {
navigator.webkitGetUserMedia(
constraints, displayDetectAndAnalyzeVideo, failedCallback);
}
// This test that a MediaStream can be cloned and that the clone can
// be rendered.
function getUserMediaAndClone() {
navigator.webkitGetUserMedia({video: true, audio: true},
createAndRenderClone, failedCallback);
}
function failedCallback(error) {
document.title = 'GetUserMedia call failed with code ' + error.code;
}
function plugStreamIntoLocalView(stream) {
gLocalStream = stream;
var localStreamUrl = webkitURL.createObjectURL(stream);
$('local-view').src = localStreamUrl;
}
function displayAndDetectVideo(stream, callback) {
plugStreamIntoLocalView(stream);
document.title = 'Waiting for video...';
detectVideoPlaying('local-view', callback);
}
function displayDetectAndAnalyzeVideo(stream) {
plugStreamIntoLocalView(stream);
analyzeVideo();
}
function createAndRenderClone(stream) {
gLocalStream = stream;
// TODO(perkj): --use-fake-device-for-media-stream do not currently
// work with audio devices and not all bots has a microphone.
new_stream = new webkitMediaStream();
new_stream.addTrack(stream.getVideoTracks()[0]);
expectEquals(new_stream.getVideoTracks().length, 1);
if (stream.getAudioTracks().length > 0) {
new_stream.addTrack(stream.getAudioTracks()[0]);
expectEquals(new_stream.getAudioTracks().length, 1);
new_stream.removeTrack(new_stream.getAudioTracks()[0]);
expectEquals(new_stream.getAudioTracks().length, 0);
}
var newStreamUrl = webkitURL.createObjectURL(new_stream);
$('local-view').src = newStreamUrl;
waitForVideo('local-view');
}
function stopVideoTrack() {
gLocalStream.getVideoTracks()[0].stop();
waitForVideoToStop('local-view');
}
function waitAndStopVideoTrack(waitTimeInSeconds) {
document.title = 'Running...';
setTimeout(stopVideoTrack, waitTimeInSeconds * 1000);
}
function analyzeVideo() {
document.title = 'Waiting for video...';
addExpectedEvent();
detectAspectRatio(function(aspectRatio) {
document.title = aspectRatio;
eventOccured();
});
}
</script>
</head>
<body>
<table border="0">
<tr>
<td>Local Preview</td>
</tr>
<tr>
<td><video width="320" height="240" id="local-view"
autoplay="autoplay"></video></td>
<!-- Canvases are named after their corresponding video elements. -->
<td><canvas width="320" height="240" id="local-view-canvas"
style="display:none"></canvas></td>
</tr>
</table>
</body>
</html>