Repository navigation
Conversation
The default value of the SPS control is all zeros, and a zero pic_width_in_luma_samples is how the driver marks the SPS as not yet set (is_sps_set()). try_ctrl_sps() rejects that value though, because chroma_format_idc is 0 and the picture is 0x0, so the control's own default cannot be written back. v4l2-compliance reads the control and passes the value to VIDIOC_TRY_EXT_CTRLS, which fails: fail: v4l2-test-controls.cpp(939): try_ext_ctrls returned an error (22) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL and every attempt also logs "Chroma format (0) unsupported". Upstream commit 4f4b6a9 ("media: v4l2-ctrls: default HEVC SPS chroma format to 4:2:0") would not fix this on its own, as the 0x0 picture is still rejected. Giving the control a non-zero default size instead would make is_sps_set() true before userspace has set an SPS and change the CAPTURE format enumeration. Treat a zero width as unset and accept it without further checks. Decoding already refuses to start with "SPS never set", and the CAPTURE format code keeps offering all formats until a real SPS is set. Tested on a Pi 5 with 6.18.39 and this change built as an out-of-tree module: - v4l2-compliance -m /dev/media0: 56/57 -> 57/57 - a 4:2:2, 12-bit or 8192 wide SPS is still rejected - CAPTURE ENUM_FMT before an SPS is set is unchanged (4 formats) - ffmpeg -hwaccel drm decoding 8-bit and 10-bit 720p HEVC gives frame MD5s identical to software decoding, before and after the change The failure was found by running v4l2-compliance on a Pi 5. The analysis, the fix and this changelog were written with the help of an AI coding assistant (Claude), and the testing above was run on real hardware. Fixes: 6853a7e ("media: platform: Add Raspberry Pi HEVC decoder driver") Signed-off-by: Roy <rongh7426@gmail.com>
|
The failure is mentioned in the cover letter for V2 of the patchset upstreaming the driver - https://patchwork.linuxtv.org/project/linux-media/cover/20260304-media-rpi-hevc-dec-v6-0-93868ae6dff8@raspberrypi.com/
If upstream care (and they wish to fix Hantro and Cedrus as well), then it's worth fixing. The one bit that would be worthwhile would be squashing any log line should they try that, otherwise it's a mechanism to flood the kernel logs. |
try_ctrl_sps(), try_ctrl_pps() and try_ctrl_slice_params() print a v4l2_warn() for every value they reject. Any user who can open the device can call VIDIOC_TRY_EXT_CTRLS in a loop and fill the kernel log. Use hevc_d_dbg() at level 1 instead, so the messages are still available with the debug module parameter. Tested on a Pi 5 (6.18.39, out-of-tree module), as a normal user in the video group, with 20000 VIDIOC_TRY_EXT_CTRLS calls using a 4:2:2 SPS, counting new kernel log records with the /dev/kmsg sequence number: - before: 20000 new log records - after: 0 new log records - after, with debug=1: 20000 new log records v4l2-compliance and 8-bit and 10-bit ffmpeg -hwaccel drm decoding give the same results as before. try_ctrl_slice_params() does not exist in the 6.18.39 driver, so its 3 messages were only build tested. Suggested by Dave Stevenson in the review of this pull request. The change and this changelog were written with the help of an AI coding assistant (Claude). Signed-off-by: Roy <rongh7426@gmail.com>
|
Thanks. I added a second commit for the log flooding: the messages in try_ctrl_sps/pps/slice_params now use On the first commit: upstream took 4f4b6a9 in August for the same compliance failure in rkvdec, so it may be wanted after all, but I'm happy to drop it if you'd rather not carry it. If this conflicts with #7780 I can rebase on top of it. |
|
As you can see, #7780 is doing a load of updates to try and clean up the driver before I do the next patchset for upstream. Would you mind if I just pass this over to @jc-kynesim to add into that as he sees fit? It avoids having to consider additional potential Signed-off-by and similar tags on the patches for upstream. I think I prefer the approach taken in 4f4b6a9 to always initialise the control to something vaguely sane, rather than accepting an all-zero SPS control. Particularly if that has been accepted for rkvdec. Again I'll defer to @jc-kynesim though. |
|
Sure, fine by me, please pass it on to @jc-kynesim. If any of it gets folded in, a "Reported-by: Roy rongh7426@gmail.com" would be appreciated. One thing to watch with a non-zero default: |
The issue won't be present in the patchset sent upstream, so there's nothing to submit for a Reported-by. That's what I mean by not having to worry about SoB and other tags on the patchset. #7708 will get merged to the rpi-6.18.y branch, and can have @jc-kynesim's preferred version of your patches with Reported-by:, but it'll all just get squashed into one patch adding the hopefully bug-free driver for upstream. |
|
Yeah, dropping the SPS checks to dbg is probably worthwhile, but it is definitely worth being having a mechanism that allows you to tell what was rejected!. The whole SPS thing I'm less convinced by - yes v4l2 ctrl get/set should maybe work but in the case of SPS/PPS etc these need to be set by the user, the driver making stuff up has no value whatsoever. If I have to change this to get it accepted upstream then so be it but it is a V4L2 thing that is, for this usage, simply wrong. |
…ration It is possible to flood the log with warning messages by setting bad values in SPS, PPS etc. It is valuable to have this info when debugging so reduce the level to debug. Reported-by: Roy <rongh7426@gmail.com> Closes: raspberrypi#7796 Signed-off-by: John Cox <jc@kynesim.co.uk>
The SPS control's default value is all zeros, which is also how the driver
marks the SPS as "not yet set" (
is_sps_set()checks for a zero width).try_ctrl_sps()rejects that value (chroma_format_idc 0, 0x0 picture), sothe control's own default cannot be written back. On a Pi 5,
v4l2-compliance -m /dev/media0reports:and each attempt logs
Chroma format (0) unsupported.The change returns early from
try_ctrl_sps()when the SPS is unset. Idid not give the control a non-zero default size instead, because that would
make
is_sps_set()true before userspace has set an SPS and would change theCAPTURE format enumeration. Decoding already refuses to start with "SPS never
set".
Tested on a Pi 5 (6.18.39 with this change built as an out-of-tree module),
comparing against the stock module:
The change also applies on top of #7780 and runs before its new SPS checks, so
those checks never see the unset default.
The failure was found with v4l2-compliance. The analysis, the fix and this
description were written with help from an AI coding assistant (Claude). The
tests above were run on real hardware.