Files
Carlos Santos b0789b5743 rtc: pick screen share layers from the sizes measured in the video (#5127)
* rtc: pick screen share layers from the sizes measured in the video

The layer sent to a viewer was chosen from the sizes the sharer announced
when it started publishing. When the shared window shrank, the server kept
believing the small layer was bigger than it was and sent it upscaled.

A screen share track now takes its sizes from the video it receives, like a
track in one-shot signalling mode already does, and updates them when they
change. The sizes are only replaced once every announced layer has been
measured, so codecs that report fewer sizes (VP9 with spatial layers) keep
the announced ones.

* rtc: keep the legacy video layers in sync with the measured sizes

UpdateVideoSize only rewrote the codec layers, so the top-level layers
sent to clients kept the announced sizes after a resize.

* rtc: read the measured video sizes under the track lock

The size callbacks of each simulcast layer run in their own goroutine.
Each one took a snapshot of the receiver sizes and then waited for the
track lock, so a delayed callback could overwrite the sizes written by a
later one with an older snapshot. UpdateVideoSize now receives the
getter and reads the sizes once it holds the lock.

Assisted-by: Claude

* rtc: get the video sizes from the track receiver in UpdateVideoSize

UpdateVideoSize looks up the receiver of the codec itself and reads its
sizes while holding the track lock, so the size callback no longer has
to pass a getter.

Assisted-by: Claude

* rtc: check the track lock from another goroutine in TestUpdateVideoSize

The CI runs the tests with go-deadlock, which reports TryLock from the
goroutine that already holds the lock as a recursive lock.

Assisted-by: Claude
2026-12-02 19:33:42 +08:00
..
2025-08-28 05:20:25 -07:00