Skip to content

Tighten the small-change metrics and tile comparer after review (851-4476) - #1504

Merged
pondorasti merged 3 commits into
mainfrom
alexandru/851-4476-small-change-follow-ups
Nov 27, 2026
Merged

pondorasti merged 3 commits into
mainfrom
alexandru/851-4476-small-change-follow-ups

Conversation

@pondorasti

@pondorasti pondorasti commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1484 (851-4476), from the review of b628ffe.

  1. changeEncoded timed requeued work. A refinement the encoder dropped is queued again as a change of the last encoded capture, with that capture's old capture time, so the metric recorded the capture's age. The encode request now names the tiles that repeat a capture already encoded (repeatedTiles), and the encoded tile carries it (repeatsCapture): a refinement, a refresh-only update, and a dropped refinement queued again from the same capture. changeEncoded leaves those out. A change whose first encode was dropped is not a repeat; its retry is timed from its own capture, the latency the viewer sees. The flag is kept off ScreenSharingTileUpdate, which is also the frame metadata's type.
  2. tilesChangedSmall counted requests. Renamed to smallChangeRequests (the tiles the host passed as small), and changesKeptSharp moved to where the cap is decided and the frame is known to be encoded: the VCP session counts it when an encoded frame comes out with the kept cap. A refresh, a keyframe (requested or not), a bitrate under Apple's ladder, the session's own view of its last refinement, or a skipped frame are no longer counted.
  3. Host-lab README example now uses vcp=1 (vcp=1,small=0/vcp=1/vcp=1,small=0) and says small only matters with vcp=1.
  4. One-tile fast path is back: a single candidate tile is compared inline, without concurrentPerform and the mutex.
  5. Chroma of a 420v capture: I chose to scale. Each plane is held to the limit in screen pixels, so a CbCr sample counts the 4 pixels it covers (rounded up for odd sizes), and the limit means the same area in every plane and capture format. In the product this only matters for VideoToolbox captures (420v), where the host doesn't measure at all since Keep the encoder quality cap for a small change to a sharpened tile, so typing is not 3 ms slower on the shipped encoder (851-4476) #1484; VCP captures are BGRA.

Tests

  • ScreenSharingV2HostRepeatedCaptureTests: a dropped refinement encoded again as a change is marked as a repeat and the next new capture is not; a dropped first encode of a new capture is not marked as a repeat. Each fails with its rule switched off.
  • ScreenSharingTileMetricsTests: a tile that repeats its capture is not timed. Fails without the metrics change.
  • ScreenSharingV2TileComparerTests: a CbCr change of 20 samples (80 screen pixels) is large against a 64-pixel limit, also on a 641×361 capture. Each fails without the scaling, or with the scaling rounded down.
  • ScreenSharingVCPSmallChangeTests (hardware, shipped encoder): changesKeptSharp is 1 after a small change and 0 after a large one. This does not fail without the move: forcing a session to skip, emit a keyframe or change bitrate mid-submit isn't possible on the hardware encoder in a test.
  • Not tested: the one-tile fast path (behaviour is unchanged; the comparer and host tests run both paths).

Code review (medium) of this PR

Five findings, all fixed in 01fa832:

  1. A new change whose first encode was dropped was marked as a repeat (any requeue of the last encoded capture was), so it dropped out of changeEncoded. Now only a dropped refinement repeats; tested.
  2. The chroma weight used floor division, so on odd-sized 420v captures a CbCr sample counted 1 or 2 pixels. Rounded up; tested.
  3. changesKeptSharp counted frames VCP emitted as keyframes. They are left out now.
  4. The repeat flag sat on ScreenSharingTileUpdate, which the frame metadata decodes without it. Moved to the request and the encoded tile.
  5. Plan defaulted to "repeats". Every plan now states its repeated tiles.

Ran locally (M1 Pro): ScreenSharingV2Tests without the hardware suites (163 tests) and the hardware codec suites (21 tests), all passing; the bench app builds. Proof on the minis is the PR's benchmark gate; no other runs dispatched.

Second review (at 4b87ccd), fixed in 79f3a33

  1. A plan whose encode threw requeued its repeated tiles as fresh changes. It now requeues plan.repeated as repeats. Tested (aRepeatWhoseEncodeThrowsIsStillARepeatWhenItIsEncodedAgain, fails without the fix).
  2. A dropped refinement was judged from the host's state at drop time; a newer change in flight had already cleared it, so the tile came back as a fresh change and was timed twice. The encoder's .dropped and .failed outputs now carry repeatsCapture from the submission (VCP, VideoToolbox, the fallback and the rate switch pass it on), and the host decides from that. Tested (aRefinementDroppedAfterANewerChangeStartedIsStillARepeatOfItsTile, fails without the fix). Such a tile is still encoded again from the newer capture, as before this PR; it is now just not timed.
  3. changesKeptSharp is counted before the tile is delivered, next to ScreenSharingTileMetrics.record.
  4. The capture slot compares captures by frame.timestampNs, the key the encoders use.

🤖 Generated with Claude Code

pondorasti added a commit that referenced this pull request Nov 27, 2026
…851-4476)

From the code review of #1504: requeueing after any drop marked the retry as a repeat, so
a new change whose first encode was dropped never reached changeEncoded. The request now
names the repeated tiles (a refinement, a refresh, or a dropped refinement queued again from
the same capture) and the encoded tile carries it, which also keeps the flag off the
wire-shaped update. changesKeptSharp leaves out keyframes, the chroma weight rounds up for
odd sizes, and every Plan states its repeated tiles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pondorasti and others added 2 commits November 26, 2026 22:10
- changeEncoded times only changes encoded from their own capture: an update now says
  when it repeats a capture the host already encoded (repeatsCapture), such as a dropped
  refinement queued again from the last encoded capture.
- The host's counter is renamed smallChangeRequests (what it asked for); changesKeptSharp
  counts in the VCP session when a frame comes out encoded at the kept cap.
- The tile comparer keeps an inline path for a single candidate tile.
- The small-change limit is in screen pixels in every plane: a CbCr sample of 420v counts 4.
- The host-lab README example uses vcp=1; small does nothing on VideoToolbox.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…851-4476)

From the code review of #1504: requeueing after any drop marked the retry as a repeat, so
a new change whose first encode was dropped never reached changeEncoded. The request now
names the repeated tiles (a refinement, a refresh, or a dropped refinement queued again from
the same capture) and the encoded tile carries it, which also keeps the flag off the
wire-shaped update. changesKeptSharp leaves out keyframes, the chroma weight rounds up for
odd sizes, and every Plan states its repeated tiles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4476-small-change-follow-ups branch from 01fa832 to 4b87ccd Compare November 27, 2026 06:14
From the review of #1504 at 4b87ccd:
- The encoder's drop and failure outputs carry whether the submission repeated its capture,
  and the host requeues from that instead of from its state at drop time (a newer change
  could have cleared it, and the tile was then encoded and timed twice).
- A plan whose encode throws requeues its repeated tiles as repeats.
- changesKeptSharp is counted before the tile is delivered.
- The capture slot compares captures by their timestamp, the key the encoders use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti merged commit 02b22b9 into main Nov 27, 2026
21 of 22 checks passed
@pondorasti
pondorasti deleted the alexandru/851-4476-small-change-follow-ups branch November 27, 2026 08:46
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

Successfully merging this pull request may close these issues.

1 participant