Skip to content

Can one JS document hose a browser's camera capturing ability? #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jan-ivar opened this issue May 18, 2021 · 3 comments
Closed

Can one JS document hose a browser's camera capturing ability? #37

jan-ivar opened this issue May 18, 2021 · 3 comments

Comments

@jan-ivar
Copy link
Member

If I understand correctly, if JS doesn't .close() a VideoFrame, and it's in the GPU, can it cause the browser to run out of frames in its GPU buffer pool, and might this stall capture in all sinks in all documents, blowing up mediacapture or WebGPU?

@jan-ivar jan-ivar mentioned this issue May 18, 2021
@aboba
Copy link
Contributor

aboba commented May 18, 2021

On the receive side,MediaStreamTrackGenerator provides an automatic close() in going from VideoFrame -> track (e.g. for rendering). Section 3.2.3 says:

"When a frame is written to writable, the frame’s close() method is automatically invoked, so that its internal resources are no longer accessible from JavaScript."

However, applications might render using an API other than MediaStreamTrackGenerator such as Canvas, WebGL or WebGPU. Do those alternatives also invoke VideoFrame.close() automatically?

On the send side, a VideoFrame is provided to WebCodecs encode() method, which provides an encodedVideoChunk. However, encode() does not invoke VideoFrame.close() automatically.

Also, there may be use cases (e.g. funny hats, machine learning) where an application could call MediaStreamTrackProcessor to get access to raw media, then process the media. If this processing created intermediate VideoFrame objects that were not passed to MediaStreamTrackGenerator then close() wouldn't be automatically invoked.

@guidou
Copy link
Contributor

guidou commented Jun 18, 2021

To answer the original question, the answer is: not necessarily.
The UA can drop all incoming frames for the stream if it detects that the document using the stream has several open frames and is not closing them.

@guidou
Copy link
Contributor

guidou commented Jun 18, 2021

The spec now explicitly mentions this case and potential mitigations, so closing this issue.

@guidou guidou closed this as completed Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants