Home | History | Annotate | Download | only in media
      1 <html>
      2 <head>
      3   <script type="text/javascript" src="webrtc_test_utilities.js"></script>
      4   <script type="text/javascript">
      5   $ = function(id) {
      6     return document.getElementById(id);
      7   };
      8   
      9   var gLocalStream = null;
     10     
     11   setAllEventsOccuredHandler(function() {
     12     gLocalStream.stop();
     13     document.title = 'OK';      
     14   });
     15   
     16   // This test that a MediaStream can be created and a local preview 
     17   // rendered.
     18   function getUserMedia(constraints) {
     19     navigator.webkitGetUserMedia(constraints, displayAndWaitForVideo,
     20         failedCallback);
     21   }
     22   
     23   // This test that a MediaStream can be cloned and that the clone can 
     24   // be rendered.
     25   function getUserMediaAndClone() {
     26     navigator.webkitGetUserMedia({video: true, audio: true},
     27         createAndRenderClone, failedCallback);
     28   }
     29     
     30   function failedCallback(error) {
     31     document.title = 'GetUserMedia call failed with code ' + error.code;
     32   }
     33 
     34   function displayAndWaitForVideo(stream) {
     35     gLocalStream = stream;
     36     var localStreamUrl = webkitURL.createObjectURL(stream);
     37     $('local-view').src = localStreamUrl;
     38     waitForVideo('local-view');   
     39   }
     40   
     41   function createAndRenderClone(stream) {
     42     gLocalStream = stream;
     43     // TODO(perkj):  --use-fake-device-for-media-stream do not currently
     44     // work with audio devices and not all bots has a microphone.    
     45     new_stream = new webkitMediaStream();
     46     new_stream.addTrack(stream.getVideoTracks()[0]);
     47     expectEquals(new_stream.getVideoTracks().length, 1);
     48     if (stream.getAudioTracks().length > 0) {
     49       new_stream.addTrack(stream.getAudioTracks()[0]);
     50       expectEquals(new_stream.getAudioTracks().length, 1);
     51       new_stream.removeTrack(new_stream.getAudioTracks()[0]);
     52       expectEquals(new_stream.getAudioTracks().length, 0);
     53     }
     54     
     55     var newStreamUrl = webkitURL.createObjectURL(new_stream);
     56     $('local-view').src = newStreamUrl;  
     57     waitForVideo('local-view');
     58   }
     59   
     60   </script>  
     61 </head>
     62 <body>
     63   <table border="0">
     64     <tr>
     65       <td>Local Preview</td>
     66     </tr>
     67     <tr>
     68       <td><video width="320" height="240" id="local-view"
     69           autoplay="autoplay"></video></td>      
     70       <!-- Canvases are named after their corresponding video elements. -->
     71       <td><canvas width="320" height="240" id="local-view-canvas"
     72           style="display:none"></canvas></td>
     73     </tr>
     74   </table>
     75 </body>
     76 </html>