Chromium Code Reviews| 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 detectVideoIn('local-view', stopVideoTrack); | |
|
phoglund_chromium
2013/11/14 09:01:18
This doesn't read very intuitively since IMO it lo
perkj_chrome
2013/11/14 13:29:07
Done.
| |
| 44 } | 45 } |
| 45 | 46 |
| 46 function displayAndWaitForAndAnalyzeVideo(stream) { | 47 function displayAndWaitForAndAnalyzeVideo(stream) { |
| 47 gLocalStream = stream; | 48 gLocalStream = stream; |
| 48 var localStreamUrl = webkitURL.createObjectURL(stream); | 49 var localStreamUrl = webkitURL.createObjectURL(stream); |
| 49 $('local-view').src = localStreamUrl; | 50 $('local-view').src = localStreamUrl; |
| 50 analyzeVideo(); | 51 analyzeVideo(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 function createAndRenderClone(stream) { | 54 function createAndRenderClone(stream) { |
| 54 gLocalStream = stream; | 55 gLocalStream = stream; |
| 55 // TODO(perkj): --use-fake-device-for-media-stream do not currently | 56 // TODO(perkj): --use-fake-device-for-media-stream do not currently |
| 56 // work with audio devices and not all bots has a microphone. | 57 // work with audio devices and not all bots has a microphone. |
| 57 new_stream = new webkitMediaStream(); | 58 new_stream = new webkitMediaStream(); |
| 58 new_stream.addTrack(stream.getVideoTracks()[0]); | 59 new_stream.addTrack(stream.getVideoTracks()[0]); |
| 59 expectEquals(new_stream.getVideoTracks().length, 1); | 60 expectEquals(new_stream.getVideoTracks().length, 1); |
| 60 if (stream.getAudioTracks().length > 0) { | 61 if (stream.getAudioTracks().length > 0) { |
| 61 new_stream.addTrack(stream.getAudioTracks()[0]); | 62 new_stream.addTrack(stream.getAudioTracks()[0]); |
| 62 expectEquals(new_stream.getAudioTracks().length, 1); | 63 expectEquals(new_stream.getAudioTracks().length, 1); |
| 63 new_stream.removeTrack(new_stream.getAudioTracks()[0]); | 64 new_stream.removeTrack(new_stream.getAudioTracks()[0]); |
| 64 expectEquals(new_stream.getAudioTracks().length, 0); | 65 expectEquals(new_stream.getAudioTracks().length, 0); |
| 65 } | 66 } |
| 66 | 67 |
| 67 var newStreamUrl = webkitURL.createObjectURL(new_stream); | 68 var newStreamUrl = webkitURL.createObjectURL(new_stream); |
| 68 $('local-view').src = newStreamUrl; | 69 $('local-view').src = newStreamUrl; |
| 69 waitForVideo('local-view'); | 70 waitForVideo('local-view'); |
| 70 } | 71 } |
| 71 | 72 |
| 73 function stopVideoTrack() { | |
| 74 waitForVideoToStop('local-view'); | |
|
phoglund_chromium
2013/11/14 09:01:18
You should be able to swap this statement and the
perkj_chrome
2013/11/14 13:29:07
Done.
| |
| 75 gLocalStream.getVideoTracks()[0].stop(); | |
| 76 } | |
| 77 | |
| 72 function analyzeVideo() { | 78 function analyzeVideo() { |
| 73 document.title = 'Waiting for video...'; | 79 document.title = 'Waiting for video...'; |
| 74 addExpectedEvent(); | 80 addExpectedEvent(); |
| 75 detectAspectRatio(function(aspectRatio) { | 81 detectAspectRatio(function(aspectRatio) { |
| 76 document.title = aspectRatio; | 82 document.title = aspectRatio; |
| 77 eventOccured(); | 83 eventOccured(); |
| 78 }); | 84 }); |
| 79 } | 85 } |
| 80 | 86 |
| 81 </script> | 87 </script> |
| 82 </head> | 88 </head> |
| 83 <body> | 89 <body> |
| 84 <table border="0"> | 90 <table border="0"> |
| 85 <tr> | 91 <tr> |
| 86 <td>Local Preview</td> | 92 <td>Local Preview</td> |
| 87 </tr> | 93 </tr> |
| 88 <tr> | 94 <tr> |
| 89 <td><video width="320" height="240" id="local-view" | 95 <td><video width="320" height="240" id="local-view" |
| 90 autoplay="autoplay"></video></td> | 96 autoplay="autoplay"></video></td> |
| 91 <!-- Canvases are named after their corresponding video elements. --> | 97 <!-- Canvases are named after their corresponding video elements. --> |
| 92 <td><canvas width="320" height="240" id="local-view-canvas" | 98 <td><canvas width="320" height="240" id="local-view-canvas" |
| 93 style="display:none"></canvas></td> | 99 style="display:none"></canvas></td> |
| 94 </tr> | 100 </tr> |
| 95 </table> | 101 </table> |
| 96 </body> | 102 </body> |
| 97 </html> | 103 </html> |
| OLD | NEW |