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   // Creates a MediaStream and renders it locally. When the video is detected to
     17   // be rolling, the title is changed and the stream should be stopped.
     18   function getUserMediaAndStop(constraints) {
     19     navigator.webkitGetUserMedia(
     20         constraints,
     21         function(stream) { displayAndDetectVideo(stream, stopVideoTrack); },
     22         failedCallback);
     23   }
     24 
     25   // Creates a MediaStream and renders it locally. When the video is detected to
     26   // be rolling, the title should be changed and the stream is let roll for a
     27   // number |waitTimeInSeconds| and then it should be stopped.
     28   function getUserMediaAndWaitAndStop(constraints, waitTimeInSeconds) {
     29     navigator.webkitGetUserMedia(
     30         constraints,
     31         function(stream) {
     32           displayAndDetectVideo(
     33             stream,
     34             function() {
     35               waitAndStopVideoTrack(waitTimeInSeconds);
     36             });
     37         },
     38         failedCallback);
     39   }
     40 
     41   function getUserMediaAndAnalyseAndStop(constraints) {
     42     navigator.webkitGetUserMedia(
     43         constraints, displayDetectAndAnalyzeVideo, failedCallback);
     44   }
     45 
     46   // This test that a MediaStream can be cloned and that the clone can
     47   // be rendered.
     48   function getUserMediaAndClone() {
     49     navigator.webkitGetUserMedia({video: true, audio: true},
     50         createAndRenderClone, failedCallback);
     51   }
     52 
     53   function failedCallback(error) {
     54     document.title = 'GetUserMedia call failed with code ' + error.code;
     55   }
     56 
     57   function plugStreamIntoLocalView(stream) {
     58     gLocalStream = stream;
     59     var localStreamUrl = webkitURL.createObjectURL(stream);
     60     $('local-view').src = localStreamUrl;
     61   }
     62 
     63   function displayAndDetectVideo(stream, callback) {
     64     plugStreamIntoLocalView(stream);
     65     document.title = 'Waiting for video...';
     66     detectVideoPlaying('local-view', callback);
     67   }
     68 
     69   function displayDetectAndAnalyzeVideo(stream) {
     70     plugStreamIntoLocalView(stream);
     71     analyzeVideo();
     72   }
     73 
     74   function createAndRenderClone(stream) {
     75     gLocalStream = stream;
     76     // TODO(perkj):  --use-fake-device-for-media-stream do not currently
     77     // work with audio devices and not all bots has a microphone.
     78     new_stream = new webkitMediaStream();
     79     new_stream.addTrack(stream.getVideoTracks()[0]);
     80     expectEquals(new_stream.getVideoTracks().length, 1);
     81     if (stream.getAudioTracks().length > 0) {
     82       new_stream.addTrack(stream.getAudioTracks()[0]);
     83       expectEquals(new_stream.getAudioTracks().length, 1);
     84       new_stream.removeTrack(new_stream.getAudioTracks()[0]);
     85       expectEquals(new_stream.getAudioTracks().length, 0);
     86     }
     87 
     88     var newStreamUrl = webkitURL.createObjectURL(new_stream);
     89     $('local-view').src = newStreamUrl;
     90     waitForVideo('local-view');
     91   }
     92 
     93   function stopVideoTrack() {
     94     gLocalStream.getVideoTracks()[0].stop();
     95     waitForVideoToStop('local-view');
     96   }
     97 
     98   function waitAndStopVideoTrack(waitTimeInSeconds) {
     99     document.title = 'Running...';
    100     setTimeout(stopVideoTrack, waitTimeInSeconds * 1000);
    101   }
    102 
    103   function analyzeVideo() {
    104     document.title = 'Waiting for video...';
    105     addExpectedEvent();
    106     detectAspectRatio(function(aspectRatio) {
    107       document.title = aspectRatio;
    108       eventOccured();
    109     });
    110   }
    111 
    112   </script>
    113 </head>
    114 <body>
    115   <table border="0">
    116     <tr>
    117       <td>Local Preview</td>
    118     </tr>
    119     <tr>
    120       <td><video width="320" height="240" id="local-view"
    121           autoplay="autoplay"></video></td>
    122       <!-- Canvases are named after their corresponding video elements. -->
    123       <td><canvas width="320" height="240" id="local-view-canvas"
    124           style="display:none"></canvas></td>
    125     </tr>
    126   </table>
    127 </body>
    128 </html>
    129