Repository navigation
media: apple: avd: allow pre-streaming H.264/HEVC format-negotiation SPS - #3073
Conversation
Stateless V4L2 decoders such as Chromium's V4L2VideoDecoder::SetExtCtrlsInit() issue VIDIOC_S_EXT_CTRLS before STREAMON with minimal H.264 and HEVC SPS controls carrying only chroma_format_idc, bit depth, and (for HEVC) picture dimensions so the driver can narrow CAPTURE pixel formats (NV12 vs P010). In that pre-streaming init call, H.264 leaves flags == 0 (without V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY) and HEVC leaves CTB size fields zeroed (log2_min_luma_coding_block_size_minus3 == 0, log2_diff_max_min_luma_coding_block_size == 0). avd_h264_try_ctrl() and avd_hevc_try_ctrl() previously rejected both with -EINVAL, breaking Chromium hardware H.264 and HEVC initialization before CAPTURE format negotiation. Split format validation (dimensions, chroma format, bit depth) into avd_h264_validate_sps_fmt() and avd_hevc_validate_sps_fmt(). Use the format check for pre-streaming try_ctrl (and avd_h264_start), while streaming try_ctrl and per-frame avd_h264_run()/avd_hevc_run() continue to enforce full SPS validation (rejecting interlaced H.264 and unsupported HEVC CTB sizes). Add KUnit coverage in avd-h264-test.c and avd-hevc-test.c. Signed-off-by: Ryan Murray <[email protected]>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: HOLD at 1b53a0870eab
Blockers:
drivers/media/platform/apple/avd/avd-h264.c:816,drivers/media/platform/apple/avd/avd-h264.c:1279-1290: pre-streamingavd_h264_try_ctrl()andavd_h264_start()unconditionally skip theV4L2_H264_SPS_FLAG_FRAME_MBS_ONLYcheck, so a real parsed interlaced H.264 SPS (with populatedpic_width_in_mbs_minus1/pic_height_in_map_units_minus1or flags likeV4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD) is now accepted during pre-streaming negotiation andSTREAMON, only failing frame-by-frame at decode time instead of returning-EINVALupfront so clients such as FFmpeg (v4l2request) and GStreamer (v4l2slh264dec) can fall back to software decode. Fix: mirroravd_hevc_try_ctrl()'s narrow gate by only deferringFRAME_MBS_ONLYwhen!sps->flags && !sps->pic_width_in_mbs_minus1 && !sps->pic_height_in_map_units_minus1(keeping fullavd_h264_validate_sps()active for populated SPS structs), and cover a populated interlaced SPS inavd-h264-test.c.- §5 evidence: add regression-run numbers at the new head (0 SELinux denials, 0 failed units, 0 new kernel errors) plus an H.264/HEVC decode no-regression check (current J616s row decodes VP9 frames and only exercises
SetExtCtrlsInitfor H.264/HEVC), add a no-regression hardware row on a second Apple AVD Mac generation (M1/M2/M3) since this code is shared across M1–M4, and wait for exact-head CI (host-tests,pr-text,readiness) to turn green.
Checked: §1–§4 and §6 pass (1b53a0870eab: no model gates, no cmdline/module params, full SPS validation retained in avd_h264_run()/avd_hevc_run(), human author/committer + DCO Signed-off-by only, zero attribution issues, clean naming, MERGEABLE on main); §5 incomplete and CI still running/queued.
Evidence
- Head:
1b53a0870eaba68b6d2f35081cb39d77798bca66(OPEN, non-draft,MERGEABLEagainstmain037f7bca6822). - Diff audit:
avd-hevc.c:avd_hevc_try_ctrl()narrows pre-streaming relaxation to zeroed CTB fields (!log2_min_luma_coding_block_size_minus3 && !log2_diff_max_min_luma_coding_block_size) while still checking non-zero dimensions<= coded_fmt, chroma format, and bit depth; streamingtry_ctrl()andavd_hevc_run()continue to enforceavd_hevc_validate_sps()(includingavd_hevc_check_sps_geometry()). Safe against nullm2m_ctxand concurrent control updates (controls copied underv4l2_ctrl_lock()beforeavd_hevc_run()validates).avd-h264.c:avd_h264_validate_sps_fmt()andavd_h264_run()full validation are sound andavd_h264_start_slices()handles zeroed dimensions safely (1initial slot, grown viaavd_h264_realloc_slices()), butavd_h264_try_ctrl()andavd_h264_start()do not gate theFRAME_MBS_ONLYrelaxation on a minimal/zeroed init SPS as HEVC does for CTB fields, regressing pre-streaming interlaced H.264 rejection.avd.h/ KUnit tests:VISIBLE_IF_KUNIT/EXPORT_SYMBOL_IF_KUNITdeclarations are properly guarded by#if IS_ENABLED(CONFIG_KUNIT); non-blocking note: consider adding a KUnit case exercisingtry_ctrldirectly across pre-streaming vs streaming queue states.
- Commits & PR hygiene: single commit
1b53a0870eabbyRyan Murray <[email protected]>with matching humanSigned-off-by; PR body followsWhat/Tested/Risk/Not yetstructure. - CI at review time (
1b53a0870eab):host-testsIN_PROGRESS,pr-textQUEUED (prior run SUCCESS),readinessPENDING/QUEUED.
Address review feedback and CI host-tests on pre-streaming SPS validation: - Narrow H.264 pre-streaming FRAME_MBS_ONLY deferral to minimal init SPS controls (!flags && !pic_width_in_mbs_minus1 && !pic_height_in_map_units_minus1) via avd_h264_validate_sps_ctrl(), keeping populated interlaced SPS structs rejected upfront with -EINVAL in both avd_h264_try_ctrl() and avd_h264_start() so FFmpeg/GStreamer fall back to software decode cleanly. - Extend avd_sps_fmt_init_test in avd-h264-test.c to cover pre-streaming vs streaming ctrl validation and populated interlaced SPS rejection. - Extract avd_h264_validate_sps_fmt and avd_hevc_validate_sps_fmt in drivers/media/platform/apple/avd/tests/program-test.py so avd-codec-tail-tests builds cleanly. Signed-off-by: Ryan Murray <[email protected]>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH at 7c49bb1eb91d
Blockers: none (awaiting exact-head CI completion: host-tests IN_PROGRESS, pr-text / pr-text SUCCESS, readiness / readiness PENDING)
Checked: Interdiff 1b53a0870eab..7c49bb1eb91d resolves all prior code and §5 hardware/regression evidence blockers; §1–§6 pass (no model gates, default cmdline, per-frame validation retained, zero attribution issues, human author/committer + DCO Signed-off-by only, clean naming, MERGEABLE on main); waiting only on exact-head CI (host-tests, readiness / readiness) to finish green before approving.
Evidence
- Head:
7c49bb1eb91d35bbd916361ffb58692f4a8208d9(OPEN, non-draft,MERGEABLEagainstmain037f7bca6822). - Interdiff
1b53a0870eab..7c49bb1eb91d:drivers/media/platform/apple/avd/avd-h264.c:avd_h264_sps_is_fmt_init()+avd_h264_validate_sps_ctrl(ctx, sps, streaming)restricts pre-streamingV4L2_H264_SPS_FLAG_FRAME_MBS_ONLYdeferral to minimal init SPS structs (!sps->flags && !sps->pic_width_in_mbs_minus1 && !sps->pic_height_in_map_units_minus1) in bothavd_h264_try_ctrl()andavd_h264_start(); populated interlaced SPS structs continue to fail upfront with-EINVAL, and streamingtry_ctrl()plusavd_h264_run()enforce fullavd_h264_validate_sps().drivers/media/platform/apple/avd/avd-h264-test.c:avd_sps_fmt_init_testcovers pre-streaming vs streamingavd_h264_validate_sps_ctrl(), populated interlaced SPS rejection,V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELDrejection, and unsupported chroma/bit-depth formats.drivers/media/platform/apple/avd/tests/program-test.py: extractsavd_h264_validate_sps_fmtandavd_hevc_validate_sps_fmtfor host regression builds.
- §5 evidence at exact
7c49bb1eb91d: J316s (M1 Pro) and J616s (M4 Pro) on7.3.0-aurora-fleet87— GStreamerv4l2slh264dec,v4l2slh265dec,v4l2slvp9dechardware decode PASS on both Macs (Enforcing,FAILED_UNITS=0,NEW_AVCS=0, 0 new/AVD kernel errors); ChromiumSetExtCtrlsInit()fixed from-EINVAL (22)toSetupOutputFormat(): candidate: NV12for H.264/HEVC with VP9 40/40 frames PASS; KUnitapple-avd-h*76/76 PASS;tools/asahi/avd-codec-tail-tests.pyPASS;scripts/checkpatch.pl0 errors / 0 warnings. - Commits & PR hygiene: both commits (
1b53a0870eab,7c49bb1eb91d) byRyan Murray <[email protected]>with matching human DCOSigned-off-byonly; zero AI attribution across commits, PR title, body, and comments. - Exact-head CI (
7c49bb1eb91d):host-testsIN_PROGRESS,pr-text / pr-textSUCCESS,readiness / readinessPENDING.
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 7c49bb1eb91d once the exact-head host-tests run is green
Blockers: none
Checked: the narrowed gate holds, and I found nothing past Dj's FINISH above.
avd_h264_validate_sps_ctrl()skips theFRAME_MBS_ONLYcheck only for a pre-streaming SPS withflags,pic_width_in_mbs_minus1andpic_height_in_map_units_minus1all zero. A populated interlaced SPS is still refused attry_ctrland atSTREAMON.- Every frame still goes through the full
avd_h264_validate_sps()/avd_hevc_validate_sps()inrun(). - The zero-dimension init SPS cannot under-size anything at
STREAMON. Inavd_h264_start(),avd_h264_alloc_bufs()and the scratch rows are sized fromctx->image_fmt(the negotiated format), not from the SPS.avd_h264_start_slices()starts at 1 slot and grows. - HEVC:
avd_hevc_validate_sps_fmt()keeps a zero-dimension check, the coded-format bound, and the chroma and depth checks. Only the CTB geometry check is deferred, and only while the OUTPUT queue is not streaming. v4l2_m2m_get_vq()is guarded against a NULLm2m_ctx. The unlockedvb2_is_streaming()read intry_ctrlis harmless, becauserun()validates again.- No gates, no parameters.
Evidence
- Diff at
7c49bb1eb91d(6 files, +214/-11). - Read
avd_h264_start()and theavd_hevc_try_ctrl()/avd_hevc_run()validate call sites at head. - CI when posted:
pr-textpass,host-testspending.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 7c49bb1e
Blockers: none
Checked: All checks at 7c49bb1eb91d are now green (pr-text, host-tests, readiness). Code, KUnit/program-test coverage, §1–§6 policy hygiene, and exact-head J316s + J616s hardware decode/regression rows were verified in the prior pass on this same head.
Evidence
- Exact head:
7c49bb1eb91d35bbd916361ffb58692f4a8208d9(MERGEABLEontomain). - CI at head:
pr-textPASS (15:00:53Z),host-testsPASS (15:08:07Z),readinessPASS (15:10:33Z); earlier cancelled runs were superseded duplicates from PR body edits. - Prior review: All code and §5 evidence items were cleared in review #6041756286; promoting from
FINISHtoMERGEnow that CI is green.
What: Allow minimal pre-streaming H.264 and HEVC format-negotiation SPS controls (
!flags && !pic_width_in_mbs_minus1 && !pic_height_in_map_units_minus1for H.264; zeroed CTB size fields for HEVC) inapple-avdtry_ctrlwhile keeping full SPS validation on populated interlaced SPS structs, streamingtry_ctrl, and everyrun(), fixing ChromiumV4L2VideoDecoder::SetExtCtrlsInit()-EINVALfailures before CAPTURE format negotiation.Tested: J316s (M1 Pro,
7.3.0-aurora-fleet87) and J616s (M4 Pro,7.3.0-aurora-fleet87) at exact7c49bb1eb91d: GStreamerv4l2slh264dec,v4l2slh265dec, andv4l2slvp9dechardware decode PASS on both Macs (0 SELinux denials, 0 failed units, 0 new kernel errors); ChromiumSetExtCtrlsInit()improved from-EINVAL (22)(stockapple_avd) toSetupOutputFormat(): candidate: NV12for both H.264 and HEVC on both Macs with VP9 40/40 hardware frames PASS;tools/asahi/avd-codec-tail-tests.pyPASS; KUnitapple-avd-h*76/76 PASS;scripts/checkpatch.pl0 errors / 0 warnings.Risk: two-way door · all Macs with Apple AVD (M1–M4)
Not yet: Chromium H.264
V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED(-ERANGEinSubmitDecode()) and HEVC bitstream start-code handling are separate follow-up work; awaiting exact-head CI completion (host-tests,pr-text,readiness).Details
Stateless V4L2 clients following the V4L2 stateless decoder initialization sequence (including Chromium's
V4L2VideoDecoder::SetExtCtrlsInit()) issueVIDIOC_S_EXT_CTRLSbeforeSTREAMONwith minimal H.264 and HEVC SPS structs carryingchroma_format_idc, bit depth, and (for HEVC) picture dimensions so the driver can narrow CAPTURE pixel formats (NV12vsP010).avd_h264_validate_sps_fmt()andavd_hevc_validate_sps_fmt().avd_h264_validate_sps_ctrl(ctx, sps, streaming)which defersV4L2_H264_SPS_FLAG_FRAME_MBS_ONLYonly for non-streaming minimal init SPS structs (!sps->flags && !sps->pic_width_in_mbs_minus1 && !sps->pic_height_in_map_units_minus1). Populated interlaced SPS structs (e.g. from FFmpegv4l2requestor GStreamerv4l2slh264dec) continue to return-EINVALupfront during pre-streamingtry_ctrlandSTREAMON, preserving software fallback.avd_hevc_try_ctrl()mirrors the same narrow gate for zeroed CTB size fields (!log2_min_luma_coding_block_size_minus3 && !log2_diff_max_min_luma_coding_block_size) while non-streaming.try_ctrl()and per-frameavd_h264_run()/avd_hevc_run()continue to enforce fullavd_h264_validate_sps()andavd_hevc_validate_sps().avd-h264-test.c(avd_sps_fmt_init_test, covering pre-streaming vs streaming and populated interlaced SPS rejection) andavd-hevc-test.c(avd_hevc_sps_fmt_init_test), and extractavd_h264_validate_sps_fmt/avd_hevc_validate_sps_fmtindrivers/media/platform/apple/avd/tests/program-test.py.Evidence
7c49bb1eb91d35(7c49bb1eb91d)scripts/checkpatch.pl:0 errors, 0 warningspython3 tools/asahi/avd-codec-tail-tests.py: PASS (program-test.py+dispatch-test.py+vp9-test.py+av1-test.py+recovery-test.py)./tools/testing/kunit/kunit.py run --kunitconfig drivers/media/platform/apple/avd/tests/.kunitconfig 'apple-avd-h*'):Testing complete. Ran 76 tests: passed: 767.3.0-aurora-fleet87,apple-avd.kobuilt from7c49bb1eb91d):v4l2slh264decPASS,v4l2slh265decPASS,v4l2slvp9decPASS (Enforcing,FAILED_UNITS=0,NEW_AVCS=0, 0 AVD kernel errors)apple_avd): H.264 & HEVCSetExtCtrlsInit()->VIDIOC_S_EXT_CTRLS: Invalid argument (22)7c49bb1eb91d): H.264 & HEVCSetExtCtrlsInit()->SetupOutputFormat(): Output (CAPTURE queue) candidate: NV12; VP9NV12, P010(40/40 frames)7.3.0-aurora-fleet87,apple-avd.kobuilt from7c49bb1eb91d):v4l2slh264decPASS,v4l2slh265decPASS,v4l2slvp9decPASS (Enforcing,FAILED_UNITS=0,NEW_AVCS=0, 0 AVD kernel errors)7c49bb1eb91d): H.264 & HEVCSetExtCtrlsInit()->SetupOutputFormat(): Output (CAPTURE queue) candidate: NV12; VP9NV12, P010(40/40 frames)