Re: [mediacapture-main] What happens when a machine suspends? (#668)

@jan-ivar 

> Closing the lid and opening it again: it could still be capturing prior to logging in!

One workaround for the case of a `MediaStream` from `getUserMedia()` where the camera is actually on the screen side of laptop  is to check the pixels for equivalent of a "black" frame. Tested at Nightly 77
```

function checkPixels() {
  /* e.g., stream && stream.active || recorder && recorder.state === 'recording' */
  if (condition) {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
    const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
    for (let r = 0; r < imageData.data.length; r+=4) {
     // does not have to be 0,0,0,255 to be a "black" frame
     // every 4 indexes could be 0,2,0,255 or 0,2,3,255
     // if all 3 indexes (RGB) are less than 10 (test, set lower values here)
     if (imageData.data[r] + imageData.data[r+1] + imageData.data[r+2] < 10) {
       tracks.forEach(track => track.stop());
       return;
     }
   }
    // set time to analyze MediaStreamTrack through <video> here
    setTimeout(() =>  checkPixels(), 1000); 
  }
}
navigator.mediaDevices.getUserMedia({audio:true, video: true})
.then(_ => {
  stream = _;
  tracks  =  stream.getTracks();
  // Firefox does not support ImageCapture, else could capture MediaStreamTrack as ImageBitmap
  // instead of streaming content through HTMLVideoElement
  video.srcObject = stream;
  // recorder = new MediaRecorder(video.srcObject);
  // wait 1 second to avoid first frame being 0,0,0,255
  setTimeout(() =>  checkPixels(), 1000);
  // recorder.start();
})
.catch(console.error);
```
Does not address the case of external and/or camera(s) not on screen side where closing laptop lid will not impact input video stream.

Another option would be to clone the audio input stream, if any,  or create an audio stream if not present in original input or output stream, then use speech recognition (official Web SPeech API implementations or, e.g., pocketsphinx https://github.com/syl22-00/pocketsphinx.js) to execute `stop()` on each track when keywords "end session" or "logout" are included in the transcript result.

-- 
GitHub Notification of comment by guest271314
Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/668#issuecomment-622997049 using your GitHub account

Received on Saturday, 2 May 2020 18:42:46 UTC