Skip to content

media: apple: ave: 26B123: per-frame bit rate and forced keyframes - #3827

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/ave-26b123-dyn-rc
Dec 2, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/ave-26b123-dyn-rc

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What

Add the macOS 27.2 (26B123) Process command offsets for mid-stream rate control and forced keyframes (.bitrate, .limits, .limit_bytes, .limit_secs, .force_key, .force_type) for both H.264 (0x1338..0x1370, 0x29d8) and HEVC (+0x7a8: 0x1ae0..0x1b18, 0x3180), matching the 9003.78.0 spacing relative to fps_int and the 0xffffffff picture-management sentinel.

Without these offsets, ave_build_process() returns -EOPNOTSUPP (-95) on any mid-stream V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME or V4L2_CID_MPEG_VIDEO_BITRATE update, blocking real-time encoders (WebRTC/screen share) on 26B123 firmware.

Also fix two mid-stream rate-control bugs in ave_build_process() / ave_sess_cbr_fill():

  • Scale per-frame VBR limit_bytes by * 8 on counted layouts (bits/s, matching ave_start_config()) and recalculate it when bitrate changes mid-stream so raising VBR bitrate is not capped by the start-time 2x peak.
  • Record each slot's requested bitrate in ave_cmd_process() so ave_sess_cbr_fill() tracks live CBR bit-rate updates.
  • Leave ave_layout_26a428 (dyn_rc = 0) unchanged until verified on M5 hardware.
  • Add KUnit (ave_26b123_process_dyn_rc) and host-harness (tests/test.c) coverage for both codecs.

Tested

At 30fca3e8056936fa44ab4c033b4c4e877bbd7849, J413 (M2, T8112) and J615 (M3, T8122) both passed on AVE firmware 26B123. Direct V4L2-M2M encoding delivered keyframes at frames 0, 25 and 75 and tracked live bit-rate changes in H.264 and HEVC, in both VBR and CBR. Every stream decoded 120/120 frames, with zero AVE, DART or firmware faults. J413 results, J615 results.

At 30fca3e8056936fa44ab4c033b4c4e877bbd7849, hosted Apple build, AVE KUnit (including ave_9003_byte_equality), and host tests passed.

Earlier commit 8db6a90b1561d3caba3e1a3a94405ae393c32d0e exercised the same 26B123 VBR and forced-keyframe behavior:

  • Host tests (tools/asahi/run-host-tests.py --only ave): 11/11 passed (ASan + UBSan), including new H.264 and HEVC 26B123 forced-keyframe and mid-stream bitrate byte assertions.
  • Build: arm64 W=1 KCFLAGS="-Werror" clean on drivers/media/platform/apple/ave/ and arm64 KUnit (drivers/media/platform/apple/ave/.kunitconfig) compiled clean.
  • Hardware PASS at 8db6a90b1561 (MacBook Pro 16" M4 Max, J616C / T6041, macOS 27.2 26B123, tested on both ave0 /dev/video14 and ave1 /dev/video15):
    • FFmpeg VA-API (h264_vaapi and hevc_vaapi, 1280x720, 30 fps, VBR, no B-frames, dmabuf zero-copy) with -force_key_frames 'expr:eq(n,15)+eq(n,45)+eq(n,75)': exact keyframes [0 15 45 75] verified via ffprobe, clean ffmpeg decode.
    • Direct V4L2-M2M (1280x720, 30 fps, VBR, no B-frames) on both ave0 and ave1: forced keyframes at frames 25 and 75 emit V4L2_BUF_FLAG_KEYFRAME + Annex-B IDR NAL units; live V4L2_CID_MPEG_VIDEO_BITRATE updates (2M -> 10M -> 500k) scale steady-state output (H.264: 1820 -> 2505 -> 678 kbps, HEVC: 2036 -> 2615 -> 651 kbps, forced IDR size jumping to 64-70 KB at 10M), clean ffmpeg decode, 0 -95 errors, 0 DART/firmware faults.

Risk

Risk: two-way · The rate-control offsets are enabled for 26B123. 9003.78.0 retains its existing VBR limit and byte units. CBR filler now uses each submitted picture’s bit rate.

Not yet

  • 26A428 keeps dyn_rc = 0.
  • Hardware verification on other 26B123 SoCs (T8132 and T8103).

@AxxzyWasTaken
AxxzyWasTaken requested review from a team as code owners December 1, 2026 18:35
@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 30fca3e8: not ready yet

Check Detail
CI at head ok 13 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA 30fca3e8, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · The rate-control offsets are enabled for 26B123. 9003.78.0 retains its existing VBR limit and byte units. CBR filler now uses each submitted picture’s bit rate.

Areas: area:media

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

DjDeveloperr
DjDeveloperr previously approved these changes Dec 1, 2026

@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.

Reviewed the 26B123 H.264 and HEVC Process fields, the counted-layout rate conversion, and passing the submitted picture's bit rate to CBR fill. The J616C report covers both engines and both codecs at this head. Before merging, run hosted Apple build, AVE KUnit and host tests, and cover a second generation, including the changed live VBR behavior on 9003.78.0.

@github-actions github-actions Bot added door:two-way Revertible or not, from Merge risk (bot) ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 1, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

The hosted AVE KUnit run found a regression at 8db6a90b1561: ave_9003_byte_equality fails on the 9003.78.0 Process packets. The fixture submits a 9 Mbit/s picture against an 8 Mbit/s session with a 2,000,000 B/s limit. The new shared VBR branch in ave_build_process() recomputes that limit as 2,250,000 B/s, changing the legacy packet. The new 26B123 case passed.

Keep the existing 9003 Process limit for this 26B123 change, or update the 9003 contract with a live VBR run that demonstrates the intended behavior on that firmware.

Hosted AVE KUnit result

Add the 26B123 Process command offsets for dynamic rate control and forced keyframes (bitrate, limits, limit_bytes, limit_secs, force_key, and force_type) for both H.264 and HEVC, matching the 9003.78.0 field offsets relative to fps_int and the 0xffffffff picture-management sentinel.

Scale per-frame VBR limit_bytes to bits/s on counted layouts (matching Start) and recompute it when bitrate changes mid-stream; track the per-slot requested bit rate so CBR filler stays aligned with live bit-rate updates.

Add KUnit and host-harness coverage for 26B123 forced keyframes and mid-stream bit-rate changes.

Tested on MacBook Pro 16" M4 Max (J616C / T6041, macOS 27.2 26B123) on both ave0 and ave1: 1280x720 30 fps VBR no-B-frames H.264 and HEVC forced keyframes via FFmpeg VA-API (frames 0, 15, 45, 75) and direct V4L2-M2M (frames 25, 75) emit decodable IDR NAL units, and mid-stream V4L2_CID_MPEG_VIDEO_BITRATE updates (2M -> 10M -> 500k) scale encoded frame sizes up and down with clean ffmpeg decode and zero DART or firmware errors.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) and removed ci-failing A check failed at the PR head (bot) labels Dec 1, 2026
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Updated head to 30fca3e80569: scoped per-frame VBR limit_bytes recalculation to counted layouts (fw->counted), keeping 9003.78.0 byte-identical to ave_reference_process so ave_9003_byte_equality passes.

@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.

The new guard keeps the 9003.78.0 VBR limit unchanged and preserves the 26B123 behavior exercised on J616C. The hosted AVE KUnit run now passes. The PR description still describes the superseded 9003 VBR behavior. Host tests and second-generation hardware coverage remain open.

Update at 30fca3e80569. Apple build, AVE KUnit and host tests passed. The J413 result covers live bit-rate changes and forced keyframes in H.264 and HEVC, in both VBR and CBR. All four streams decoded 120/120 frames with zero AVE, DART or firmware faults.

For the second AVE generation, refresh the J616C test at this head with the same H.264 and HEVC live-rate sequence in CBR. The earlier J616C run covered VBR on 8db6a90b1561. The current 9003.78.0 packet-byte regression test passes.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 1, 2026
@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member

Row: 30fca3e80569 + MacBook Air 13" M2 (J413 / T8112, macOS 27.2 26B123 stub, apple-ave 267100000.video-codec: firmware build 26B123 (TEXT 0x11c000 CRC 077a3444, DATA 0x128000), default kernel command line) + PASS:

Direct V4L2-M2M (1280x720, 30 fps, NV12, video_b_frames=0, video_gop_size=300, 120 frames from ffmpeg testsrc2, forced keyframes at frames 25 and 75 via V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME, live mid-stream V4L2_CID_MPEG_VIDEO_BITRATE updates 2M -> 10M at frame 40 and 10M -> 500k at frame 80):

  • H.264 VBR: V4L2_BUF_FLAG_KEYFRAME and Annex-B IDR NALs at exact frames [0, 25, 75]; forced IDR size 24101 -> 31955 B; steady-state bitrate 1977 -> 2798 -> 665 kbps; ffmpeg decode clean (120/120 frames).
  • H.264 CBR: exact keyframes [0, 25, 75]; forced IDR size 24101 -> 44836 B; steady-state bitrate 1977 -> 6506 -> 662 kbps; ffmpeg decode clean (120/120 frames).
  • HEVC VBR: exact keyframes [0, 25, 75]; forced IDR size 21736 -> 27439 B; steady-state bitrate 1958 -> 2749 -> 525 kbps; ffmpeg decode clean (120/120 frames).
  • HEVC CBR: exact keyframes [0, 25, 75]; forced IDR size 21736 -> 56026 B; steady-state bitrate 1958 -> 8913 -> 474 kbps; ffmpeg decode clean (120/120 frames).
  • Regression / health: 0 -EOPNOTSUPP (-95) errors, 0 AVE/DART/firmware faults, 0 new kernel errors (dmesg -l err,crit,alert,emerg delta 0), 0 failed systemd units.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Row: 30fca3e80569 + MacBook Air 13" M3 (J615 / T8122, macOS 27.2 26B123 stub, AVE firmware 26B123), one-shot 7.3.0-mrows3827 built from this exact head (fleet/edge config), default command line, Enforcing + PASS. Covers the T8122 item in "Not yet".

Direct V4L2-M2M encode, using the same stream as the J413 row: 1280x720 NV12 testsrc2, 120 frames, B_FRAMES=0, GOP_SIZE=300, FORCE_KEY_FRAME at frames 25 and 75, BITRATE 2M, then 10M at frame 40, then 500k at frame 80. The pipeline is drained before each control change.

V4L2 KEYFRAME flags / bitstream IDRs forced IDR (frame 25) steady kbps 2M / 10M / 500k decode
H.264 VBR [0, 25, 75] / [0, 25, 75] 24101 B (frame 24: 8013 B) 1944 / 2719 / 666 120/120 clean
H.264 CBR [0, 25, 75] / [0, 25, 75] 24101 B 1944 / 6489 / 666 120/120 clean
HEVC VBR [0, 25, 75] / [0, 25, 75] 21755 B (frame 24: 7810 B) 1916 / 2679 / 513 120/120 clean
HEVC CBR [0, 25, 75] / [0, 25, 75] 21755 B 1916 / 9178 / 454 120/120 clean

Health on the PR kernel: 0 -95, 0 AVE/DART/firmware faults, dmesg -l err,crit,alert,emerg delta 0, 0 failed units.

Controls on the saved kernels, same harness, without this PR:

  • J615 on aurora-edge-933f8226, and J713 MacBook Air M4 (T8132, firmware 26B123) on fleet91. Plain encodes with no control changes are fine: 120/120 frames decode clean for all four combos. Any FORCE_KEY_FRAME instead gives apple-ave: encoding failed: -95, and the session ends with EIO after 18 frames. This PR fixes exactly that.
  • T8132 (J713) is a control only. The one-shot is not run yet because J713's /boot has no room for a trial kernel.

Harness and bitstreams: traces/codec/20261202-mac-rows-3827/ on the lab store (ave-enc-row.py, stdlib ctypes; decode checks run with a full ffmpeg).

@DjDeveloperr
DjDeveloperr merged commit 1e212c9 into aurora-silicon:main Dec 2, 2026
23 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:media Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants