Skip to content
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

Memory management for incoming frames #6

Closed
youennf opened this issue Dec 1, 2020 · 4 comments
Closed

Memory management for incoming frames #6

youennf opened this issue Dec 1, 2020 · 4 comments

Comments

@youennf
Copy link
Contributor

youennf commented Dec 1, 2020

In some cases, MediaStreamTrack might produce more frames than the JS pipeline might be able to consume.
In that case, it seems good that frames get dropped, for instance only the last frame received by the source is actually enqueued.

MediaStreamTrack may have different sources: camera, canvas, network.
Dropping frames might be ok with a camera since it will generate frames regularly.
This might be an issue for other sources like canvas where dropping a frame is visible to JS, as well as remote tracks (with webrtc stats).

That begs the question to whether different implementations should behave the same in the way they handle cases where frames get enqueued quickly.

@aboba
Copy link
Contributor

aboba commented Dec 3, 2020

The "memory" in question can be a GPU buffer for some sources (e.g. zero copy from a camera to a GPU buffer).

@alvestrand
Copy link
Contributor

The approach pioneered by WebCodec is that the frame has a destroy() method, and an API requirement that destroy() has to be called before the frame is released; if the frame is passed to a MediaStreamTrackGenerator, this will be handled by the generator.

The practical limit on outstanding frames in the Chrome implementation seems to be somewhere larger than 3, but less than 10.

@guidou
Copy link
Contributor

guidou commented Feb 9, 2021

I think the WebCodecs VideoFrame is quite flexible in this regard, as @alvestrand points out.
cc @chcunningham of the WebCodecs team, who might be able to provide additional input.

@chcunningham
Copy link

For the case where apps are reading fast enough and simply want to drop some of the frames, Harald and Guido gave a good summary on how to release the frame. The method is now called close() (was destroy()). w3c/webrtc-encoded-transform#99 (comment) has some additional details.

Also, for the case where apps are not reading fast enough, the MediaStreamTrackProcessorInit now includes a maxBufferSize argument that gives the app control over the frame dropping behavior. The queue lives inside the MediaStreamTrackProcessor and it's oldest item is dequeued to satisfy read requests from the ReadableStream. If the arrival of a new frame would cause the queue to exceed maxBufferSize, the oldest item in the queue is dropped prior to enqueueing the newest arrival.

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

5 participants