CEF fps affected by <video> HTML element

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CEF fps affected by <video> HTML element

Postby danmontz » Thu May 07, 2020 3:55 pm

OS: Linux
Version: I'm currently using 76.0.3809.132

I did a diff between cefclient v76 and the latest v81 and didn't
see significant changes in the cefclient application that would
impact this functionality.

I am experiencing an issue with the CEF fps dropping from 60 fps
to 30 fps when a <video> element is included in the HTML AND the
video is playing. If I stop the video, then the fps goes back up
to 60 fps. If I start the video again, then the fps drops back down to
30 fps. If the <video> element is removed, then the fps is 60
as expected.

When the video is stopped, I am getting 1 OnPaint callback for every call
to SendExternalBeginFrame. When the video is playing, I'm getting
1 OnPaint callback for every 2 calls to SendExternalBeginFrame. The <video>
appears to be running at 60 fps, but the JS is only running at 30. This
is apparent with the counter values.

I am using OSR and external begin frame functionality.

CefSettings.windowless_rendering_enabled = 1
CefBrowserSettings.windowless_frame_rate = 60
CefWindowInfo.windowless_rendering_enabled = 1
CefWindowInfo.external_begin_frame_enabled = 1

I tried to recreate this with cefclient, but it appears that
cefclient does not truly support the external begin frame
functionality. I don't see the CefBrowserHost::SendExternalBeginFrame()
being called anywhere in the sample code. There are hints
of this functionality in the OsrRendererSettings class, but
these settings are not utilized.

This command line configures CEF fairly close to the way I am
using it (minus the external begin frame not working):
./cefclient (currently not using sandboxing)
--show-fps-counter
--url=http://10.10.55.149/GFX/gfx.dir/cef-webm/simple.html
--disable-gpu
--hide-controls
--off-screen-rendering-enabled
--off-screen-frame-rate=60
--transparent-painting-enabled
--external-begin-frame-enabled
--no-sandbox (DONE with cmake)

Here's the HTML that I am using. I can control the video playback
using the remote debugging:
var d = document.getElementById("video0");
d.play()
d.pause()

The counter is incremented every requestAnimationFrame cycle.
Code: Select all
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">       
        <title>simple</title>
        <style>
            h1 {
                color:white;
                text-align: center;
                font-size: 90px;
            }
            video {
                margin-left: auto;
                margin-right: auto;
                display: block;
                width: 480px;
                height: 270px;
            }
        </style>
    </head>
    <body>
        <h1>Simple Example</h1>
        <h1 id="counter">0</h1>
        <video id="video0" controls autoplay loop muted src="webm-in-html-480x270-30sec.webm"></video>
    </body>

    <script>

        let count = 0;
        let request;
        const performAnimation = () => {
            request = requestAnimationFrame(performAnimation);
            document.getElementById("counter").innerHTML = count.toString();
            count++;
        }

        requestAnimationFrame(performAnimation);

    </script>
</html>


Has anyone experienced this same anomoly? I am definitely
not CPU bound. Using the DevTools performance, ticks are
only taking 6-7 ms when video is playing and I have verified
that I am calling SendExternalBeginFrame() every 16.66666 ms.

Thanks in advance,
Dan
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby Czarek » Fri May 08, 2020 6:14 am

SendExternalBeginFrame is called in OsrRenderHandlerWin::TriggerBeginFrame, so it seems to be tested only on Windows.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: CEF fps affected by <video> HTML element

Postby danmontz » Fri May 08, 2020 10:04 am

Thanks for the response. I have been using the external begin frame feature on Linux for over a month now and it seems to be working quite well.

However, during our testing, we discovered the <video> issue and wanted to reach out to see if others have/are experiencing this.

I will continue to investigate and will post further information as it becomes available.

Meanwhile, if anyone has any pointers on where to start looking in the code, I would greatly appreciate the information.

Dan
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby danmontz » Fri May 08, 2020 1:23 pm

Added an attachment that shows the problem. The images are snippets from OnPaint captures.

Notice that the JavaScript steps by 1 every other frame while the <video> element appears to be updating at the correct rate, but the images are only updated every other frame.
Attachments
cef-webm.png
cef-webm.png (279.14 KiB) Viewed 6554 times
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby magreenblatt » Fri May 08, 2020 1:28 pm

I suspect that you will find this to be a detail of either the scheduler or the compositor (e.g. some intentional choice in the code when a video tag is present). Sorry I can't provide any specific guidance.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF fps affected by <video> HTML element

Postby danmontz » Fri May 08, 2020 1:40 pm

Thanks for the information. I'll start digging into the code. I must say, this sounds daunting, but maybe I can track this down.

Clearly, this is an issue with the external_begin_frame feature. If I disable this setting, then the fps is 60 fps.
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby danmontz » Fri May 08, 2020 3:56 pm

From the performance record, you can see the fps change from 16.6 to 33.3
Attachments
cef-webm-performance.png
cef-webm-performance.png (62.31 KiB) Viewed 6543 times
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby danmontz » Thu May 28, 2020 10:56 am

Finally had some time to debug this a bit. More time needed, but found something that impacts the issue.

Using the chrome://trace to capture traces for HTML with and without a <video> element, it was quite clear that the Scheduler State Machine is getting throttled due to outstanding pending submit frames. In the scheduler_state_machine.cc file, there is a kMaxPendingSubmitFrame = 1. As a test, I changed this number from 1 to 2 and now the video and JavaScript are running at 60 Hz. I know this is not a solution given the comments in the code, so the next step is to determine why the compositor frame ack (SchedulerStateMachine::DidReceiveCompositorFrameAck()) took such a long time when the <video> element is present.

With this change, the JavaScript is now running and painting at 60 Hz. The video is running at 60Hz, but is only being painted at 30Hz. Going off to better understanding the pending_submit_frame logic.

I just wanted to provide an update.
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby danmontz » Wed Jun 17, 2020 2:42 pm

Is this something that I should post on Chromium's forum?
danmontz
Techie
 
Posts: 28
Joined: Thu Apr 13, 2017 4:11 pm

Re: CEF fps affected by <video> HTML element

Postby magreenblatt » Wed Jun 17, 2020 5:21 pm

danmontz wrote:Is this something that I should post on Chromium's forum?

You can try. You’ll likely have to ask your questions in the context of Chromium code (or provide detailed background on the CEF implementation) because they won’t know the details of CEF.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 49 guests