The camera is captured to a MediaStreamTrack, which is turned into a WHATWG Stream of ImageData objects by means of a canvas, and a red square is added.
The stream is sent to a Worker, which returns a new stream containing the same video data.
This is then mapped back to a MediaStream using another canvas.
The chief purpose of the demo is to demonstrate that this is doable, but that performance can be improved significantly.
NOTE: This works only on Chrome 76 and above with experimental Web features enabled, since it depends on transferable Streams.
A similar demo, without the worker process, is on the canvas filter demo.
View source on GitHub