[PATCH 4/4] media: tegra-vde: reject CABAC in the H.264 PPS control
From: Jerome Berclaz via B4 Relay
Date: Thu Nov 26 2026 - 19:56:04 EST
From: Jerome Berclaz <jerome.berclaz@xxxxxxxxx>
The hardware cannot decode CABAC. tegra-vde notices only when the decode
job runs, and then completes the buffers with an error. Stateless
decoders in userspace (FFmpeg's V4L2 request hwaccel, for one) queue the
job asynchronously and do not look at the buffer error flag, so a CABAC
stream plays as broken frames.
Validate the PPS in a try_ctrl handler, as other stateless drivers do for
features they lack, so that setting the controls fails right away. Players
that handle that error fall back to software decoding (mpv does after a
few frames).
Signed-off-by: Jerome Berclaz <jerome.berclaz@xxxxxxxxx>
---
drivers/media/platform/nvidia/tegra-vde/v4l2.c | 30 +++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/nvidia/tegra-vde/v4l2.c b/drivers/media/platform/nvidia/tegra-vde/v4l2.c
index 3269ca75593f..e59172d27b94 100644
--- a/drivers/media/platform/nvidia/tegra-vde/v4l2.c
+++ b/drivers/media/platform/nvidia/tegra-vde/v4l2.c
@@ -18,10 +18,38 @@
#include "vde.h"
+static int tegra_try_ctrl(struct v4l2_ctrl *ctrl)
+{
+ const struct v4l2_ctrl_h264_pps *pps;
+
+ switch (ctrl->id) {
+ case V4L2_CID_STATELESS_H264_PPS:
+ pps = ctrl->p_new.p_h264_pps;
+
+ /*
+ * CABAC is not supported by the hardware. Reject it here
+ * rather than failing the decode job later, so that
+ * userspace gets an error and can fall back to software.
+ */
+ if (pps->flags & V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE)
+ return -EINVAL;
+ break;
+ }
+
+ return 0;
+}
+
+static const struct v4l2_ctrl_ops tegra_ctrl_ops = {
+ .try_ctrl = tegra_try_ctrl,
+};
+
static const struct v4l2_ctrl_config ctrl_cfgs[] = {
{ .id = V4L2_CID_STATELESS_H264_DECODE_PARAMS, },
{ .id = V4L2_CID_STATELESS_H264_SPS, },
- { .id = V4L2_CID_STATELESS_H264_PPS, },
+ {
+ .id = V4L2_CID_STATELESS_H264_PPS,
+ .ops = &tegra_ctrl_ops,
+ },
{
.id = V4L2_CID_STATELESS_H264_DECODE_MODE,
.min = V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED,
--
2.53.0