Files
VoelinClient/crates/voelin-android
selikhovandClaude Opus 5.5 c79bb7dd07 Android: share the screen into the encoder without a copy
Screen sharing went MediaProjection -> ImageReader -> an owned Vec per
frame -> RGBA to NV12 on the CPU -> MediaCodec's input buffers: two
copies and a conversion of every frame on a phone's CPU.

Now, while it is the only MediaCodec encoder in the process (one
simulcast layer, one codec), an encoder takes GpuFrames: for the first
it starts a codec with an input surface (COLOR_FormatSurface,
max-fps-to-encoder at the stream's rate, repeat-previous-frame-after so
a still screen answers keyframe requests) and publishes it, and the
capture points its virtual display at that surface, resized to the
layer's size. The compositor renders the screen into the encoder; a
ticker at the stream's rate hands the sink GpuFrames that only collect
what the codec encoded, on the capture's timeline.

Simulcast keeps working by falling back: a second encoder (another
layer, or another codec a viewer chose) turns the path off for every
encoder and the display goes back to the reader, until it is the only
one again. One display can only render into one surface, and a GL
fan-out to several encoder surfaces is a lot of code for a case phones
rarely need. An encoder whose surface fails stays on frames in memory.

The fallback path no longer copies either: the provider's start_sink
hands the reader's buffer to the stream's sink borrowed. A frame-rate
change restarts the surface codec (its cap is fixed when it starts),
and the display is detached while it is resized, so neither consumer
sees a picture of the other's size.

Compiled for aarch64-linux-android only: there is no device here, so
frames per second and CPU use are not measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 19:51:39 +03:00
..