diff --git a/src/h264.c b/src/h264.c index fb6c13a..353cfa0 100644 --- a/src/h264.c +++ b/src/h264.c @@ -559,8 +559,24 @@ int h264_set_controls(struct request_data *driver_data, } }; + /* + * PRED_WEIGHTS is conditionally required per kernel UAPI: + * V4L2_H264_CTRL_PRED_WEIGHTS_REQUIRED(pps, slice) is only + * true when explicit weighted prediction applies (P/SP slice + * with WEIGHTED_PRED flag, or B slice with weighted_bipred_idc + * == 1). Submitting it unconditionally on a frame that does + * not need it triggers EINVAL at error_idx=5 on hantro and + * other drivers that strictly enforce the spec. + * + * controls[5] is PRED_WEIGHTS (last in array); narrow the + * submission count to exclude it when not required. + */ + unsigned int num_controls = 6; + if (!V4L2_H264_CTRL_PRED_WEIGHTS_REQUIRED(&pps, &slice)) + num_controls = 5; + rc = v4l2_set_controls(driver_data->video_fd, surface->request_fd, - controls, 6); + controls, num_controls); if (rc < 0) return VA_STATUS_ERROR_OPERATION_FAILED;