Repository navigation
media: apple: avd: h264: support frame-based Annex-B stateless decode - #3358
Conversation
Enable V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED paired with V4L2_STATELESS_H264_START_CODE_ANNEX_B alongside the existing SLICE_BASED + START_CODE_NONE path so frame-based stateless clients (such as Chromium's V4L2VideoDecoderDelegateH264) can decode H.264 natively on Apple AVD without breaking FFmpeg, GStreamer, or libva-v4l2-request. - Relax V4L2_CID_STATELESS_H264_DECODE_MODE (SLICE_BASED..FRAME_BASED, default SLICE_BASED) and V4L2_CID_STATELESS_H264_START_CODE (NONE..ANNEX_B, default NONE) without rejecting updates while streaming, and validate mode/start-code pairing per frame in avd_h264_run(). - Tighten avd_h264_validate_sps() to bound log2_max_frame_num_minus4, pic_order_cnt_type, and log2_max_pic_order_cnt_lsb_minus4 while keeping avd_h264_validate_sps_fmt() permissive for pre-streaming format negotiation. - Add a standalone Annex-B NALU scanner and ITU-T H.264 7.3.3 slice header parser (avd-h264-parse.c/h) with EBSP->RBSP emulation prevention byte handling, ref_pic_list_modification(), pred_weight_table(), dec_ref_pic_marking(), and exact CABAC/CAVLC slice_data() offset computation. - Submit frame-based slices zero-copy directly from the OUTPUT DMA buffer via avd_h264_run_frame(), rejecting HOLD_CAPTURE_BUF and aborting any stale held slice-based bank on mode switch. - Add KUnit coverage for SPS bounds, Annex-B scanning, EBSP/RBSP bitreading, slice header fields, reference list modification, prediction weights, reference marking, and real libx264 Annex-B bitstreams, and update the host test harness accordingly. Signed-off-by: Erik Bourget <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
There was a problem hiding this comment.
FRAME_BASED accepts the START_CODE_NONE setting but unconditionally invokes the Annex-B scanner, which rejects a buffer without a start code. The V4L2 stateless-codec documentation defines NONE as slices without a start code. Enforce a supported mode/framing combination or implement the advertised one. If Chromium requires compatibility behavior, explain how that is reconciled with the ABI and test both each supported combination and its error path. Keep the non-M1 regression row open.
|
Regression row at Setup: the PR head's
* The J413 1080p differences come from GStreamer 1.28.8's NV12 → I420 conversion on that Mac's Fedora 44 stack, not from AVD. A direct NV12 dump of the same decode matches the reference byte for byte (
|
…te mode pairs Validate H.264 decode-mode and start-code pairings in avd_h264_mode_supported() and implement framing dispatch in avd_h264_next_frame_nalu(): - SLICE_BASED accepts START_CODE_NONE only and rejects START_CODE_ANNEX_B with -EINVAL. - FRAME_BASED + START_CODE_ANNEX_B requires Annex-B start codes and rejects unprefixed buffers with -EINVAL. - FRAME_BASED + START_CODE_NONE parses a single unprefixed ITU-T H.264 7.3.1 VCL slice NALU (no start code, rejecting non-VCL types, forbidden_zero_bit, and embedded start codes), while dispatching buffers beginning with a leading Annex-B start code to the Annex-B scanner for clients (such as Chromium's V4L2VideoDecoderDelegateH264) that select FRAME_BASED without writing START_CODE and leave it at this driver's START_CODE_NONE default. Because no valid unprefixed 7.3.1 NALU starts with 0x00, leading Annex-B start codes cannot collide with valid START_CODE_NONE payloads. - Add KUnit coverage for the mode/start-code matrix, both FRAME_BASED framing paths, Chromium's default-control path, and malformed/unsupported inputs. Signed-off-by: Erik Bourget <[email protected]>
|
Addressed in
|
There was a problem hiding this comment.
Verdict: HOLD for hosted CI and frame-based hardware qualification. The framing code addresses my earlier change request.
Checked: Both frame scans now use the selected framing. FRAME_BASED/NONE accepts an unprefixed VCL unit and explicitly retains Annex-B autodetection for clients that leave the default control. FRAME_BASED/ANNEX_B takes the Annex-B scanner, while the slice-based mode still requires NONE. The new KUnit fixture covers the raw and compatibility branches. The prior J700 and J413 rows exercised slice-based decode. Please attach current-head frame-based outputs, including raw and Annex-B, before landing.
|
Code-owner review requested from @aurora-silicon/core for |
|
J413 M2 Air hardware row at
The four successful captures had luma SHA-256 |
|
J316s M1 Pro regression at Candidate runtime smoke: DRM reported the headless setup, SPI keyboard and trackpad registered, ALSA built-in cards present, gateway ICMP 3/3, and Apple M1 Pro G13S completed 32 EGL clear/readback cycles with GL error 0. Restored the stock driver on the same saved fleet89 boot. Next entry empty, Enforcing, zero failed units, staging removed. |
|
Boot-time regression at
The J473 paired GPU timestamp stress passed queue depth 1 and timed out at depth 16 in both arms, including the same nightly Image booted with the original signed AVD module. That symptom reproduced independently of the AVD overlay. J413’s 13.5 live-module row is above and used no reboot. |
|
The frame-based modes accept raw and Annex-B requests, and the existing slice mode still matches stock output. Hosted checks at If decoding regresses after merge, revert this merge with |
|
Merged as |
What: Enable
V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASEDstateless H.264 decoding in the Apple AVD V4L2 driver alongside existingSLICE_BASEDdecoding, supporting bothSTART_CODE_ANNEX_Band unprefixed 7.3.1START_CODE_NONEframing (plus Chromium's default-control Annex-B compatibility path) so frame-based stateless clients such as Chromium'sV4L2VideoDecoderDelegateH264decode H.264 natively on/dev/video11(follow-up to #3073).Tested: J313 M1 MacBook Air (
ewb-m1,7.3.0-j313daily5-ewb342+) atc2656bf7c627: live/dev/video11decode matrix passes 5/5 with byte-identical NV12 luma output acrossFRAME_BASED + ANNEX_B,FRAME_BASED + NONE(unprefixed 7.3.1 NALU), andFRAME_BASED + NONE(Chromium-style Annex-B), whileFRAME_BASED + ANNEX_Bwith raw NALU andSLICE_BASED + ANNEX_Bboth returnV4L2_BUF_FLAG_ERROR; 188/188 arm64 QEMU KUnit (apple-avd*) pass;program-test.pypasses; earlier at0569550b8352, Chromium H.264 Baseline (652/652 frames @ 60 fps), High+B (-228.9 mWmean /-214.7 mWmedian Heatpipe vs SW), and 4-slice High+B (-268.5 mWmean /-243.4 mWmedian Heatpipe vs SW) decoded via AVD andmpv --hwdec=vaapi(SLICE_BASED) passed with 0 errors.Risk: two-way door · all Apple Silicon Macs with Apple AVD (M1–M4).
Not yet: non-M1 (M2/M3/M4) AVD hardware regression testing.
Details
avd-v4l2.c,avd-h264.c,avd-h264-parse.c):V4L2_CID_STATELESS_H264_DECODE_MODE(SLICE_BASED..FRAME_BASED, defaultSLICE_BASED) andV4L2_CID_STATELESS_H264_START_CODE(NONE..ANNEX_B, defaultNONE) so existing slice-based defaults remain unchanged.(decode_mode, start_code)inavd_h264_mode_supported():SLICE_BASEDacceptsSTART_CODE_NONEonly (rejectingSTART_CODE_ANNEX_Bwith-EINVAL);FRAME_BASEDaccepts bothSTART_CODE_ANNEX_BandSTART_CODE_NONE.avd_h264_next_frame_nalu():FRAME_BASED + START_CODE_ANNEX_B: requires Annex-B start codes (00 00 01/00 00 00 01) and rejects unprefixed buffers with-EINVAL.FRAME_BASED + START_CODE_NONE: parses a single unprefixed ITU-T H.264 §7.3.1 VCL slice NALU (no start code, rejectingforbidden_zero_bit, non-VCL/unsupported NAL types, and embedded00 00 01sequences). For clients such as Chromium'sV4L2VideoDecoderDelegateH264— which writesDECODE_MODE=FRAME_BASED, never writesV4L2_CID_STATELESS_H264_START_CODE(leaving it at theSTART_CODE_NONEdefault; V4L2 also skipss_ctrlfor default-valued writes), and unconditionally prepends00 00 01inSubmitSlice()— buffers beginning with an Annex-B start code (00 00 ... 01) are dispatched to the Annex-B scanner. Because no valid unprefixed §7.3.1 NALU begins with0x00(nal_unit_type == 0is invalid), leading Annex-B start codes cannot collide with validSTART_CODE_NONEpayloads.avd-h264-parse.c,avd-h264-parse.h): Scans Annex-B NALUs (00 00 01/00 00 00 01), handles EBSP→RBSP emulation-prevention bytes (00 00 03), parses slice headers includingref_pic_list_modification(),pred_weight_table(), anddec_ref_pic_marking(), and computes exact CABAC/CAVLCslice_data()offsets.avd-h264.c): Submits each VCL slice directly from the VB2 OUTPUT DMA buffer (run->base.coded_in + nalu.off + slice_data_off) viaavd_h264_run_frame(), rejectsV4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUFin frame-based mode, and aborts any stale held slice-based bank on mode transitions.avd-h264.c): Boundslog2_max_frame_num_minus4,pic_order_cnt_type, andlog2_max_pic_order_cnt_lsb_minus4inavd_h264_validate_sps()while keepingavd_h264_validate_sps_fmt()permissive for pre-streaming format negotiation.Evidence
c2656bf7c627(added on top of0569550b8352)arm64 LLVM=1 W=1 KCFLAGS=-Werror): 0 errors, 0 warnings acrossavd-h264.o,avd-h264-parse.o, andavd-h264-test.o../tools/testing/kunit/kunit.py run --kunitconfig=drivers/media/platform/apple/avd/tests/.kunitconfig --arch=arm64 --make_options=LLVM=1 'apple-avd*'):188/188passed (0 failed, 0 skipped), includingavd_frame_mode_framing_testcovering all(decode_mode, start_code)pairs,FRAME_BASED + START_CODE_ANNEX_Bvalid/error paths,FRAME_BASED + START_CODE_NONEraw 7.3.1 NALU + Chromium Annex-B + malformed/non-VCL/embedded-start-code error paths.python3 drivers/media/platform/apple/avd/tests/program-test.py): PASS.scripts/checkpatch.pl --strict): 0 errors, 0 warnings, 0 checks onc2656bf7c627.ewb-m1,7.3.0-j313daily5-ewb342+@786ad8d1e498containingc2656bf7c627):/dev/video11+/dev/media0V4L2 Request API matrix on a real 64x64libx264Main CABAC IDR frame:FRAME_BASED + START_CODE_ANNEX_B(Annex-B):err=0,y_sum=346256(PASS)FRAME_BASED + START_CODE_NONE(unprefixed 7.3.1 NALU):err=0,y_sum=346256, NV12 luma byte-identical toANNEX_Breference (PASS)FRAME_BASED + START_CODE_NONE(Chromium-style Annex-B):err=0,y_sum=346256, NV12 luma byte-identical toANNEX_Breference (PASS)FRAME_BASED + START_CODE_ANNEX_B(raw NALU without start code):err=1(V4L2_BUF_FLAG_ERROR) (PASS)SLICE_BASED + START_CODE_ANNEX_B:err=1(V4L2_BUF_FLAG_ERROR) (PASS)mpvJ313 measurements at0569550b8352:--ignore-gpu-blocklist --enable-features=AcceleratedVideoDecoder, 1080p60): Baseline 652/652 frames @ 60 fps, High+B-228.9 mWmean /-214.7 mWmedian Heatpipe vs SW, 4-slice High+B-268.5 mWmean /-243.4 mWmedian vs SW, 0 AVD errors;mpv --hwdec=vaapi(SLICE_BASED) unaffected.