OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> | 3 <script type="text/javascript" src="webrtc_test_utilities.js"></script> |
4 <script type="text/javascript"> | 4 <script type="text/javascript"> |
5 $ = function(id) { | 5 $ = function(id) { |
6 return document.getElementById(id); | 6 return document.getElementById(id); |
7 }; | 7 }; |
8 | 8 |
9 var gLocalStream = null; | 9 var gLocalStream = null; |
10 | 10 |
11 setAllEventsOccuredHandler(function() { | 11 setAllEventsOccuredHandler(function() { |
12 gLocalStream.stop(); | 12 gLocalStream.stop(); |
13 document.title = 'OK'; | 13 document.title = 'OK'; |
14 }); | 14 }); |
15 | 15 |
16 // This test that a MediaStream can be created and a local preview | 16 // This test that a MediaStream can be created and a local preview |
17 // rendered. | 17 // rendered. |
18 function getUserMedia(constraints) { | 18 function getUserMedia(constraints) { |
19 navigator.webkitGetUserMedia(constraints, displayAndWaitForVideo, | 19 navigator.webkitGetUserMedia(constraints, |
20 failedCallback); | 20 displayAndWaitForVideoToStartAndStop, failedCallback); |
21 } | 21 } |
22 | 22 |
23 function getUserMediaWithAnalysis(constraints) { | 23 function getUserMediaWithAnalysis(constraints) { |
24 navigator.webkitGetUserMedia( | 24 navigator.webkitGetUserMedia( |
25 constraints, displayAndWaitForAndAnalyzeVideo, failedCallback); | 25 constraints, displayAndWaitForAndAnalyzeVideo, failedCallback); |
26 } | 26 } |
27 | 27 |
28 // This test that a MediaStream can be cloned and that the clone can | 28 // This test that a MediaStream can be cloned and that the clone can |
29 // be rendered. | 29 // be rendered. |
30 function getUserMediaAndClone() { | 30 function getUserMediaAndClone() { |
31 navigator.webkitGetUserMedia({video: true, audio: true}, | 31 navigator.webkitGetUserMedia({video: true, audio: true}, |
32 createAndRenderClone, failedCallback); | 32 createAndRenderClone, failedCallback); |
33 } | 33 } |
34 | 34 |
35 function failedCallback(error) { | 35 function failedCallback(error) { |
36 document.title = 'GetUserMedia call failed with code ' + error.code; | 36 document.title = 'GetUserMedia call failed with code ' + error.code; |
37 } | 37 } |
38 | 38 |
39 function displayAndWaitForVideo(stream) { | 39 function displayAndWaitForVideoToStartAndStop(stream) { |
40 gLocalStream = stream; | 40 gLocalStream = stream; |
41 var localStreamUrl = webkitURL.createObjectURL(stream); | 41 var localStreamUrl = webkitURL.createObjectURL(stream); |
42 $('local-view').src = localStreamUrl; | 42 $('local-view').src = localStreamUrl; |
43 waitForVideo('local-view'); | 43 document.title = 'Waiting for video...'; |
| 44 // Wait for video to play, then stop the track and wait for video to stop |
| 45 // playing. |
| 46 detectVideoPlaying('local-view', stopVideoTrack); |
44 } | 47 } |
45 | 48 |
46 function displayAndWaitForAndAnalyzeVideo(stream) { | 49 function displayAndWaitForAndAnalyzeVideo(stream) { |
47 gLocalStream = stream; | 50 gLocalStream = stream; |
48 var localStreamUrl = webkitURL.createObjectURL(stream); | 51 var localStreamUrl = webkitURL.createObjectURL(stream); |
49 $('local-view').src = localStreamUrl; | 52 $('local-view').src = localStreamUrl; |
50 analyzeVideo(); | 53 analyzeVideo(); |
51 } | 54 } |
52 | 55 |
53 function createAndRenderClone(stream) { | 56 function createAndRenderClone(stream) { |
54 gLocalStream = stream; | 57 gLocalStream = stream; |
55 // TODO(perkj): --use-fake-device-for-media-stream do not currently | 58 // TODO(perkj): --use-fake-device-for-media-stream do not currently |
56 // work with audio devices and not all bots has a microphone. | 59 // work with audio devices and not all bots has a microphone. |
57 new_stream = new webkitMediaStream(); | 60 new_stream = new webkitMediaStream(); |
58 new_stream.addTrack(stream.getVideoTracks()[0]); | 61 new_stream.addTrack(stream.getVideoTracks()[0]); |
59 expectEquals(new_stream.getVideoTracks().length, 1); | 62 expectEquals(new_stream.getVideoTracks().length, 1); |
60 if (stream.getAudioTracks().length > 0) { | 63 if (stream.getAudioTracks().length > 0) { |
61 new_stream.addTrack(stream.getAudioTracks()[0]); | 64 new_stream.addTrack(stream.getAudioTracks()[0]); |
62 expectEquals(new_stream.getAudioTracks().length, 1); | 65 expectEquals(new_stream.getAudioTracks().length, 1); |
63 new_stream.removeTrack(new_stream.getAudioTracks()[0]); | 66 new_stream.removeTrack(new_stream.getAudioTracks()[0]); |
64 expectEquals(new_stream.getAudioTracks().length, 0); | 67 expectEquals(new_stream.getAudioTracks().length, 0); |
65 } | 68 } |
66 | 69 |
67 var newStreamUrl = webkitURL.createObjectURL(new_stream); | 70 var newStreamUrl = webkitURL.createObjectURL(new_stream); |
68 $('local-view').src = newStreamUrl; | 71 $('local-view').src = newStreamUrl; |
69 waitForVideo('local-view'); | 72 waitForVideo('local-view'); |
70 } | 73 } |
71 | 74 |
| 75 function stopVideoTrack() { |
| 76 gLocalStream.getVideoTracks()[0].stop(); |
| 77 waitForVideoToStop('local-view'); |
| 78 } |
| 79 |
72 function analyzeVideo() { | 80 function analyzeVideo() { |
73 document.title = 'Waiting for video...'; | 81 document.title = 'Waiting for video...'; |
74 addExpectedEvent(); | 82 addExpectedEvent(); |
75 detectAspectRatio(function(aspectRatio) { | 83 detectAspectRatio(function(aspectRatio) { |
76 document.title = aspectRatio; | 84 document.title = aspectRatio; |
77 eventOccured(); | 85 eventOccured(); |
78 }); | 86 }); |
79 } | 87 } |
80 | 88 |
81 </script> | 89 </script> |
82 </head> | 90 </head> |
83 <body> | 91 <body> |
84 <table border="0"> | 92 <table border="0"> |
85 <tr> | 93 <tr> |
86 <td>Local Preview</td> | 94 <td>Local Preview</td> |
87 </tr> | 95 </tr> |
88 <tr> | 96 <tr> |
89 <td><video width="320" height="240" id="local-view" | 97 <td><video width="320" height="240" id="local-view" |
90 autoplay="autoplay"></video></td> | 98 autoplay="autoplay"></video></td> |
91 <!-- Canvases are named after their corresponding video elements. --> | 99 <!-- Canvases are named after their corresponding video elements. --> |
92 <td><canvas width="320" height="240" id="local-view-canvas" | 100 <td><canvas width="320" height="240" id="local-view-canvas" |
93 style="display:none"></canvas></td> | 101 style="display:none"></canvas></td> |
94 </tr> | 102 </tr> |
95 </table> | 103 </table> |
96 </body> | 104 </body> |
97 </html> | 105 </html> |
OLD | NEW |