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

[bug] Cannot render more than a few video streams on web with overlayed participant names. #358

Open
jezell opened this issue Sep 12, 2023 · 6 comments

Comments

@jezell
Copy link
Contributor

jezell commented Sep 12, 2023

If you try to render more than 8 participants in web, each with a label rendered on top for it's name, the flutter web renderer will break due to using too many platform views.

A new change has landed in flutter designed to address this:

flutter/engine#45256

The web renderer should be modified so that it uses createImageBitmap to render each frame so that apps can render more than 8 video feeds without crashing the flutter renderer.

@wanjm
Copy link

wanjm commented Sep 13, 2023

how to use createImageBitmap? do we need to create one timer.interval to refresh the videos;

@jezell
Copy link
Contributor Author

jezell commented Sep 13, 2023

createImageBitmap allows you to render a texture in flutter based off of a DOM media element (for example an img or video element can be used as a source). Under the covers, it ties into the browser APIs that exist to allow videos and images to be loaded and rendered into WebGL textures, so the performance is as optimized as possible in the browser.

timer.interval probably isn't the best approach as it can have a bit of latency in browser implementations, scheduleFrameCallback should provide a tighter update interval that aligns to frame boundaries.

Having done something similar in the past with javascript and livekit and pixi.js, there might be a little work to get the browser to always render the frames. In our experience, the browser would skip rendering video frames if it thought the video was off screen. When we did this with pixi.js + webgl a year ago, we had to use alpha:0, pointer-events:none, on the video element so that the browser didn't stop rendering it (rather than display none or not putting it into the DOM at all).

@jezell
Copy link
Contributor Author

jezell commented Sep 13, 2023

@eyebrowsoffire may be able to provide some additional guidance on the proper API usage for video elements.

@jezell
Copy link
Contributor Author

jezell commented Sep 13, 2023

Calling scheduleFrameCallback in a loop of course could result in the texture getting updated a lot faster than the framerate of the video, here's an example of how it's done in pixi.js:

https://github.com/pixijs/pixijs/blob/6b480827aecbacb57a6f6b162131772bb1931d55/packages/core/src/textures/resources/VideoResource.ts#L27

While it checks if a frame is due on every frame tick, it does limit the FPS of the GPU updates so that it only updates when a new frame is due. Note they make use of the video specific call here for requestVideoFrameCallback which notifies when the next video frame update is available.

@wanjm
Copy link

wanjm commented Sep 13, 2023

thanks.

@jezell
Copy link
Contributor Author

jezell commented Mar 8, 2024

@wanjm

flutter/packages#6286

See here for a PR I did for video_player_web to fix the same problem. Not too many lines of code.

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

2 participants