Skip to content

8f4de91

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 29 Nov 05:45

fix(pixelflux): Convert the shared framebuffer in place for software HEVC

On a screen the images' Xvfb shares from system memory, an x265 or
kvazaar session still had each frame's tiles copied into a pool surface
(copy_tiles on the pixelflux-fbcopy threads) and then converted the
whole surface into the picture its library encodes, which libvpx
sessions no longer do.

It takes the planes the capture converts in place too
(HevcEncoder::host_planes: 8-bit 4:2:0 with even sides, I420 at BT.709
as its own conversion gives). HevcEncoder::encode_planes copies them
into the picture it converts a packed frame into, in bands of rows on
the conversion's pool as that conversion runs (Planes::copy_into):
x265's own layout in one of the session's two pictures, which a patched
x265 reads across encodes, or the plain planes an unpatched one copies
from; kvazaar's picture. The surface returns to the pool when the
encode returns, as for libvpx, and x265 never reads a pool surface:
handing it the surfaces themselves, as x264 takes its NV12, would need
each laid out as the open encoder's frame, margins it pads in place
included, and held out of the pool until x265 lets it go, which neither
its API nor the patches give a call for.

The stream test of the in-place planes covers H.265: an x265 session
handed them codes the same packets as one handed the copied pixels (50
of 50 runs on 4 pinned cores, 50 of 50 unpinned), and differs on the first
frame when the planes are converted at the other matrix or a band of
the copy starts a row off; a build without gpl codes kvazaar's the same
way (10 of 10).

In process, a full-screen change at 1280x720 took 0.53-0.54 ms of CPU
to convert in place and copy into x265's picture where the copy and its
conversion took 0.70-0.73, the capture's part 0.13-0.14 ms of wall time
where it took 0.14-0.15 and the encode thread's 0.06-0.07 where it took
0.10-0.12; at 2560x1600 3.25-3.36 ms of CPU against 3.94-4.30, 0.66-0.78
ms against 0.96-1.08 and 0.54-0.58 against 0.63-0.69 (three rounds of
200 frames, 7 bands). A copy on the encode thread alone took 0.97-1.01
ms there.

H.265 at 1280x720 and a 57 fps cap on the shared framebuffer over
WebSockets, local builds of main and of this change, servers on the
same 8 cores, 12 interleaved runs an arm (Chrome here decodes no H.265,
so frames are those the page received, and WebRTC brings up no video):
x265 holds the stream at 40-56 fps on a full-screen animation at about
95 ms of CPU a frame, so server CPU (406.7 and 404.7 % of a core) and
frame rate (43.0 and 42.3 fps, the change lower in 6 of 12 pairs and
higher in 5) do not resolve a saving of 0.2 ms; CPU of the
pixelflux-csc and pixelflux-fbcopy threads 6.0 to 5.6 %, lower in 10
of 12 pairs, pixelflux-fbcopy's 2.4 % gone.

The numbers ran on conda's x265 3.5, which carries none of the patches
and takes the plain planes. The stream test passes on it and on the
patched x265 crates/pixelflux/scripts/build-x265.sh builds, as CI links
it, which takes x265's own layout.