I am developing module for video calling website that modifies facial featues. Essentially, I get video stream (MediaStream) and I return modified stream.
Currently I am using "canvas.captureStream()" to generate updated stream. I use "requestAnimationFrame" to invoke transformation function that draws on canvas and eventually pushes to output MediaStram. To receive frames from incoming stream, I am attaching it to video.
This setup is working fine as long as user is active on page.
But if user switches to another tab or another application, browser optimization kicks in and "requestAnimationFrame" are paused.
I tried other alternatives, to no avail:
- setTimeout - browser optimization reduces timeout to "1S" for inactive tab
- Web worker - not working for me as I have GL processing that cannot be done in worker thread.
- WebRTC stream transform classes - Restricted to Chrome only.
Kindly provide any alternatives that could solve my problem - transforming incoming video stream and generate output stream that other apps can consume. Receive sort of callback on which I can perform processing even in inactive tabs.
I am open to other input/output options as well.
Would be glad to provide additional information if needed.
You're trying to break the browser power consumption model - those limitations are made exactly to prevent such activities.