3 <script type=
"text/javascript" src=
"webrtc_test_utilities.js"></script>
4 <script type=
"text/javascript">
6 return document
.getElementById(id
);
9 var gLocalStream
= null;
11 setAllEventsOccuredHandler(function() {
13 document
.title
= 'OK';
16 // This test that a MediaStream can be created and a local preview
18 function getUserMedia(constraints
) {
19 navigator
.webkitGetUserMedia(constraints
,
20 displayAndWaitForVideoToStartAndStop
, failedCallback
);
23 function getUserMediaWithAnalysis(constraints
) {
24 navigator
.webkitGetUserMedia(
25 constraints
, displayAndWaitForAndAnalyzeVideo
, failedCallback
);
28 // This test that a MediaStream can be cloned and that the clone can
30 function getUserMediaAndClone() {
31 navigator
.webkitGetUserMedia({video
: true, audio
: true},
32 createAndRenderClone
, failedCallback
);
35 function failedCallback(error
) {
36 document
.title
= 'GetUserMedia call failed with code ' + error
.code
;
39 function displayAndWaitForVideoToStartAndStop(stream
) {
40 gLocalStream
= stream
;
41 var localStreamUrl
= webkitURL
.createObjectURL(stream
);
42 $('local-view').src
= localStreamUrl
;
43 document
.title
= 'Waiting for video...';
44 // Wait for video to play, then stop the track and wait for video to stop
46 detectVideoPlaying('local-view', stopVideoTrack
);
49 function displayAndWaitForAndAnalyzeVideo(stream
) {
50 gLocalStream
= stream
;
51 var localStreamUrl
= webkitURL
.createObjectURL(stream
);
52 $('local-view').src
= localStreamUrl
;
56 function createAndRenderClone(stream
) {
57 gLocalStream
= stream
;
58 // TODO(perkj): --use-fake-device-for-media-stream do not currently
59 // work with audio devices and not all bots has a microphone.
60 new_stream
= new webkitMediaStream();
61 new_stream
.addTrack(stream
.getVideoTracks()[0]);
62 expectEquals(new_stream
.getVideoTracks().length
, 1);
63 if (stream
.getAudioTracks().length
> 0) {
64 new_stream
.addTrack(stream
.getAudioTracks()[0]);
65 expectEquals(new_stream
.getAudioTracks().length
, 1);
66 new_stream
.removeTrack(new_stream
.getAudioTracks()[0]);
67 expectEquals(new_stream
.getAudioTracks().length
, 0);
70 var newStreamUrl
= webkitURL
.createObjectURL(new_stream
);
71 $('local-view').src
= newStreamUrl
;
72 waitForVideo('local-view');
75 function stopVideoTrack() {
76 gLocalStream
.getVideoTracks()[0].stop();
77 waitForVideoToStop('local-view');
80 function analyzeVideo() {
81 document
.title
= 'Waiting for video...';
83 detectAspectRatio(function(aspectRatio
) {
84 document
.title
= aspectRatio
;
94 <td>Local Preview
</td>
97 <td><video width=
"320" height=
"240" id=
"local-view"
98 autoplay=
"autoplay"></video></td>
99 <!-- Canvases are named after their corresponding video elements. -->
100 <td><canvas width=
"320" height=
"240" id=
"local-view-canvas"
101 style=
"display:none"></canvas></td>