Skip to content

media: apple: avd: apply request controls the capture buffers fit - #1511

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:integration/aurorafrom
IronsideXXVI:avd-request-controls
Nov 11, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:integration/aurorafrom
IronsideXXVI:avd-request-controls

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Chromium's V4L2 stateless decoder (V4L2VideoDecoder) shows green frames on the AVD, while ffmpeg/libva on the same machine decode correctly. This fixes it.

What goes wrong

Chromium allocates its CAPTURE buffers before it queues its first request. At that point the driver's picture-format control (the one that sets ctx->image_fmt) has only ever been set to its default. The control framework skips a set to the current value, so s_ctrl never ran and ctx->image_fmt stayed AVD_IMG_FMT_ANY.

The first request then carries the real picture format, which the driver sees as a format change. CAPTURE is already allocated, so s_ctrl returns -EBUSY and v4l2_ctrl_request_setup() fails with -16. The driver ignored that result and decoded with the controls left over from probing (1x1). Parameter validation then failed, the context was marked broken, and every later buffer completed with an error. The user sees a green video.

ffmpeg/libva are not affected because they set the controls before allocating CAPTURE.

What the patch does

  • s_ctrl accepts a picture format when the CAPTURE buffers that are already allocated suit it: same pixel format for that picture format, and the same layout of the compressed reference area after the picture. A format the buffers cannot hold still returns -EBUSY.
  • The result of the request setup is kept in struct avd_run. A failed setup is logged and fails that frame for H.264, HEVC, VP9 and AV1, instead of decoding with stale controls.

Tested

All on a MacBook Pro 14-inch M4 (J604, T8132), our kernel = integration/aurora 7.3 plus the J604 series:

  • Cause traced on our 1.731 kernel with kprobes and trial modules: the request setup returned -16 on the first request, then -EINVAL from parameter validation and a broken context.
  • Without the patch (1.732): Chromium VP9 1080p60 decodes green. A frame grab compared with software decode measured 3.95 dB, there were 0 AVD interrupts, and the stream stopped after one failed frame.
  • With the patch (trial build on 1.732, then in every kernel we installed since 1.734), Chromium with --enable-features=AcceleratedVideoDecoder:
    • VP9 and AV1, 1080p60 and 4K60, decode on the AVD (V4L2VideoDecoder, platform decoder, AVD interrupts counted).
    • A frame grab compared with software decode of the same clip: VP9 55.23 dB, AV1 54.95 dB.
    • CPU time was 0.2-0.4 s per 6 s window, against 2.3-2.8 s in software.
    • Repeated on later kernels with the same results (1.736, 1.802, 1.805), including after one s2idle cycle.
  • ffmpeg VA-API (libva-v4l2-request) VP9, AV1 and H.264 1080p stay bit-exact against software (600/600 frames), before and after.
  • No AVD error lines in the kernel log during these runs.
  • On this base (integration/aurora 451dc70): the driver change is a straight cherry-pick with no conflicts; drivers/media/platform/apple/avd builds with W=1 and no warnings; the AVD host tests pass (tools/asahi/run-host-tests.py --only avd, 12 of 12); checkpatch --strict reports 0 errors, 0 warnings, 0 checks. The measurements above are from our tree, not from a kernel built from this exact base.
  • The first push of this PR failed host-tests: struct avd_run gains a member, and two host tests build the codec code against their own copy of that struct (tests/program-test.py, tools/asahi/avd-av1-tail-tests.py). The commit now adds the member to both.

Not tested

  • Only on T8132. Not run on M1, M2 or M3 machines, or on other M4 or M5 variants.
  • HEVC through Chromium does not decode yet, for a separate reason: Chromium submits HEVC frames without slice parameters, and the driver's HEVC path needs them. This patch does not change that. HEVC was tested through ffmpeg/libva only.
  • H.264 through Chromium needs frame-based decode mode, which is a separate change. This patch alone was measured with VP9 and AV1 in Chromium.
  • A client that changes resolution or bit depth mid-stream without reallocating CAPTURE still gets -EBUSY, as before (by design).

IronsideXXVI added a commit to IronsideXXVI/omarchy-j604 that referenced this pull request Nov 11, 2026
The video decoder fix that Chromium needs on the hardware decoder
(kernel patch 0218) is open upstream as aurora-silicon/linux#1511.
The J604 results on omacom/linux-aurora#432 have an update for 1.836.

Signed-off-by: Dylan Ironside <[email protected]>
A stateless client that allocates CAPTURE buffers before its first
request (Chromium's V4L2VideoDecoder does) never moved the picture
format control off its default: the control framework skips a set to
the current value, so s_ctrl did not run and ctx->image_fmt stayed ANY.
The first request then carries the real picture format, which counts
as a change; CAPTURE is busy, so s_ctrl returned -EBUSY and
v4l2_ctrl_request_setup() failed. The driver ignored that result and
decoded with the controls left over from probing (1x1), parameter
validation failed, the context was marked broken and every later
buffer came back with an error.

Accept the format when the allocated CAPTURE buffers already suit it:
the negotiated pixel format is the one for that picture format and the
compressed reference area after the picture is laid out the same. Keep
-EBUSY for a format the buffers cannot hold.

Also stop decoding with stale controls: keep the request setup result
in struct avd_run, log it, and fail the frame for H.264, HEVC, VP9 and
AV1.

The host tests build the codec code against their own struct avd_run;
give the two that define one the new member.

Signed-off-by: Dylan Ironside <[email protected]>
Assisted-by: LLM

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex (GPT-6.1 Sol), reviewing on @DjDeveloperr’s behalf.

No blocking findings. Accepting a request's image format requires the negotiated fourcc and compressed-reference size/offset layout to match the allocated CAPTURE buffers; incompatible changes still return EBUSY. avd_run_preamble zero-initializes the base run, so setup_err is defined even without a request. The setup error propagates before codec submission for H264/HEVC/VP9/AV1, with existing cleanup paths retained, and the two copied host fixture structs were updated. Host CI is green; the reported J604 Chromium VP9/AV1 and bit-exact ffmpeg controls are substantive hardware evidence, with exact-base build/12 AV D host checks reported separately. This does not claim Chromium HEVC slice-parameter or H264-mode support.

@DjDeveloperr
DjDeveloperr merged commit c630323 into aurora-silicon:integration/aurora Nov 11, 2026
1 check passed
IronsideXXVI added a commit to IronsideXXVI/omarchy-j604 that referenced this pull request Nov 11, 2026
The video decoder fix (our kernel patch 0218) was merged into
aurora-silicon/linux integration/aurora on 2026-11-11 at 15:25 UTC.
The omarchy-mac Chromium item now links it as merged.

Signed-off-by: Dylan Ironside <[email protected]>
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.

2 participants