| 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 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 constraints, displayDetectAndAnalyzeVideo, failedCallback); | 57 constraints, displayDetectAndAnalyzeVideo, failedCallback); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // This test that a MediaStream can be cloned and that the clone can | 60 // This test that a MediaStream can be cloned and that the clone can |
| 61 // be rendered. | 61 // be rendered. |
| 62 function getUserMediaAndClone() { | 62 function getUserMediaAndClone() { |
| 63 navigator.webkitGetUserMedia({video: true, audio: true}, | 63 navigator.webkitGetUserMedia({video: true, audio: true}, |
| 64 createAndRenderClone, failedCallback); | 64 createAndRenderClone, failedCallback); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Creates two MediaStream and renders them locally. When the video of both |
| 68 // streams are detected to be rolling, we stop the local stream. Since both |
| 69 // streams have the same source, both video streams should stop. If they do, |
| 70 // the test succeeds. |
| 71 function twoGetUserMediaAndStop(constraints) { |
| 72 document.title = 'Calling Two GetUserMedia'; |
| 73 navigator.webkitGetUserMedia( |
| 74 constraints, |
| 75 function(stream) { |
| 76 displayAndDetectVideo(stream, requestSecondGetUserMedia); |
| 77 }, |
| 78 failedCallback); |
| 79 var requestSecondGetUserMedia = function() { |
| 80 navigator.webkitGetUserMedia( |
| 81 constraints, |
| 82 function(stream) { |
| 83 displayIntoVideoElement(stream, |
| 84 stopStreamAndVerifyAllLocalViewsDontPlayVideo, 'local-view-2'); |
| 85 }, |
| 86 failedCallback); |
| 87 }; |
| 88 |
| 89 var stopStreamAndVerifyAllLocalViewsDontPlayVideo = function() { |
| 90 gLocalStream.getVideoTracks()[0].stop(); |
| 91 |
| 92 // Since local-view and local-view-2 are playing the video from the same |
| 93 // source, both of them should stop. |
| 94 waitForVideoToStop('local-view'); |
| 95 waitForVideoToStop('local-view-2'); |
| 96 }; |
| 97 } |
| 98 |
| 67 function failedCallback(error) { | 99 function failedCallback(error) { |
| 68 document.title = 'GetUserMedia call failed with code ' + error.code; | 100 document.title = 'GetUserMedia call failed with code ' + error.code; |
| 69 sendValueToTest(document.title); | 101 sendValueToTest(document.title); |
| 70 } | 102 } |
| 71 | 103 |
| 72 function plugStreamIntoLocalView(stream) { | 104 function plugStreamIntoVideoElement(stream, videoElement) { |
| 73 gLocalStream = stream; | 105 gLocalStream = stream; |
| 74 var localStreamUrl = URL.createObjectURL(stream); | 106 var localStreamUrl = URL.createObjectURL(stream); |
| 75 $('local-view').src = localStreamUrl; | 107 $(videoElement).src = localStreamUrl; |
| 108 } |
| 109 |
| 110 function displayIntoVideoElement(stream, callback, videoElement) { |
| 111 plugStreamIntoVideoElement(stream, videoElement); |
| 112 document.title = 'Waiting for video...'; |
| 113 detectVideoPlaying(videoElement, callback); |
| 76 } | 114 } |
| 77 | 115 |
| 78 function displayAndDetectVideo(stream, callback) { | 116 function displayAndDetectVideo(stream, callback) { |
| 79 plugStreamIntoLocalView(stream); | 117 displayIntoVideoElement(stream, callback, 'local-view'); |
| 80 document.title = 'Waiting for video...'; | |
| 81 detectVideoPlaying('local-view', callback); | |
| 82 } | 118 } |
| 83 | 119 |
| 84 function displayDetectAndAnalyzeVideo(stream) { | 120 function displayDetectAndAnalyzeVideo(stream) { |
| 85 plugStreamIntoLocalView(stream); | 121 plugStreamIntoVideoElement(stream, 'local-view'); |
| 86 analyzeVideo(); | 122 analyzeVideo(); |
| 87 } | 123 } |
| 88 | 124 |
| 89 function createAndRenderClone(stream) { | 125 function createAndRenderClone(stream) { |
| 90 gLocalStream = stream; | 126 gLocalStream = stream; |
| 91 // TODO(perkj): --use-fake-device-for-media-stream do not currently | 127 // TODO(perkj): --use-fake-device-for-media-stream do not currently |
| 92 // work with audio devices and not all bots has a microphone. | 128 // work with audio devices and not all bots has a microphone. |
| 93 new_stream = new webkitMediaStream(); | 129 new_stream = new webkitMediaStream(); |
| 94 new_stream.addTrack(stream.getVideoTracks()[0]); | 130 new_stream.addTrack(stream.getVideoTracks()[0]); |
| 95 expectEquals(new_stream.getVideoTracks().length, 1); | 131 expectEquals(new_stream.getVideoTracks().length, 1); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 </script> | 163 </script> |
| 128 </head> | 164 </head> |
| 129 <body> | 165 <body> |
| 130 <table border="0"> | 166 <table border="0"> |
| 131 <tr> | 167 <tr> |
| 132 <td>Local Preview</td> | 168 <td>Local Preview</td> |
| 133 </tr> | 169 </tr> |
| 134 <tr> | 170 <tr> |
| 135 <td><video width="320" height="240" id="local-view" | 171 <td><video width="320" height="240" id="local-view" |
| 136 autoplay="autoplay"></video></td> | 172 autoplay="autoplay"></video></td> |
| 173 <td><canvas width="320" height="240" id="local-view-canvas" |
| 174 style="display:none"></canvas></td> |
| 175 </tr> |
| 176 <tr> |
| 177 <td>Local Preview 2</td> |
| 178 </tr> |
| 179 <tr> |
| 180 <td><video width="320" height="240" id="local-view-2" |
| 181 autoplay="autoplay"></video></td> |
| 137 <!-- Canvases are named after their corresponding video elements. --> | 182 <!-- Canvases are named after their corresponding video elements. --> |
| 138 <td><canvas width="320" height="240" id="local-view-canvas" | 183 <td><canvas width="320" height="240" id="local-view-2-canvas" |
| 139 style="display:none"></canvas></td> | 184 style="display:none"></canvas></td> |
| 140 </tr> | 185 </tr> |
| 141 </table> | 186 </table> |
| 142 </body> | 187 </body> |
| 143 </html> | 188 </html> |
| OLD | NEW |